use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload in project LanternServer by LanternPowered.
the class CodecPlayInOutCustomPayload method decode0.
@Override
protected Message decode0(CodecContext context, String channel, ByteBuffer content) throws CodecException {
if ("MC|ItemName".equals(channel)) {
return new MessagePlayInChangeItemName(content.readString());
} else if ("MC|TrSel".equals(channel)) {
return new MessagePlayInChangeOffer(content.readInteger());
} else if ("MC|Brand".equals(channel)) {
return new MessagePlayInOutBrand(content.readString());
} else if ("MC|Beacon".equals(channel)) {
final PotionEffectType primary = PotionEffectTypeRegistryModule.get().getByInternalId(content.readInteger()).orElse(null);
final PotionEffectType secondary = PotionEffectTypeRegistryModule.get().getByInternalId(content.readInteger()).orElse(null);
return new MessagePlayInAcceptBeaconEffects(primary, secondary);
} else if ("MC|AdvCdm".equals(channel)) {
final byte type = content.readByte();
Vector3i pos = null;
int entityId = 0;
if (type == 0) {
int x = content.readInteger();
int y = content.readInteger();
int z = content.readInteger();
pos = new Vector3i(x, y, z);
} else if (type == 1) {
entityId = content.readInteger();
} else {
throw new CodecException("Unknown modify command message type: " + type);
}
final String command = content.readString();
final boolean shouldTrackOutput = content.readBoolean();
if (pos != null) {
return new MessagePlayInEditCommandBlock.Block(pos, command, shouldTrackOutput);
} else {
return new MessagePlayInEditCommandBlock.Entity(entityId, command, shouldTrackOutput);
}
} else if ("MC|AutoCmd".equals(channel)) {
final int x = content.readInteger();
final int y = content.readInteger();
final int z = content.readInteger();
final String command = content.readString();
final boolean shouldTrackOutput = content.readBoolean();
final MessagePlayInEditCommandBlock.AdvancedBlock.Mode mode = MessagePlayInEditCommandBlock.AdvancedBlock.Mode.valueOf(content.readString());
final boolean conditional = content.readBoolean();
final boolean automatic = content.readBoolean();
return new MessagePlayInEditCommandBlock.AdvancedBlock(new Vector3i(x, y, z), command, shouldTrackOutput, mode, conditional, automatic);
} else if ("MC|BSign".equals(channel)) {
final RawItemStack rawItemStack = content.read(Types.RAW_ITEM_STACK);
// noinspection ConstantConditions
if (rawItemStack == null) {
throw new CodecException("Signed book may not be null!");
}
final DataView dataView = rawItemStack.getDataView();
if (dataView == null) {
throw new CodecException("Signed book data view (nbt tag) may not be null!");
}
final String author = dataView.getString(AUTHOR).orElseThrow(() -> new CodecException("Signed book author missing!"));
final String title = dataView.getString(TITLE).orElseThrow(() -> new CodecException("Signed book title missing!"));
final List<String> pages = dataView.getStringList(PAGES).orElseThrow(() -> new CodecException("Signed book pages missing!"));
return new MessagePlayInSignBook(author, title, pages);
} else if ("MC|BEdit".equals(channel)) {
final RawItemStack rawItemStack = content.read(Types.RAW_ITEM_STACK);
// noinspection ConstantConditions
if (rawItemStack == null) {
throw new CodecException("Edited book may not be null!");
}
final DataView dataView = rawItemStack.getDataView();
if (dataView == null) {
throw new CodecException("Edited book data view (nbt tag) may not be null!");
}
final List<String> pages = dataView.getStringList(PAGES).orElseThrow(() -> new CodecException("Edited book pages missing!"));
return new MessagePlayInEditBook(pages);
} else if ("MC|Struct".equals(channel)) {
// Something related to structure placing in minecraft 1.9,
// seems like it's something mojang doesn't want to share with use,
// they used this channel to build and save structures
} else if ("MC|PickItem".equals(channel)) {
return new MessagePlayInPickItem(content.readVarInt());
} else if ("FML|HS".equals(channel)) {
throw new CodecException("Received and unexpected message with channel: " + channel);
} else if ("FML".equals(channel)) {
// Fml channel
} else if (channel.startsWith("FML")) {
// A unknown/ignored fml channel
} else {
return new MessagePlayInOutChannelPayload(channel, content);
}
return NullMessage.INSTANCE;
}
use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload in project LanternServer by LanternPowered.
the class ProcessorForgeHandshakeOutRegistryData method process.
@Override
public void process(CodecContext context, MessageForgeHandshakeOutRegistryData message, List<Message> output) throws CodecException {
final Iterator<Entry> it = message.getEntries().iterator();
if (!it.hasNext()) {
throw new CodecException("There must be at least one entry present!");
}
while (it.hasNext()) {
final Entry entry = it.next();
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeByte((byte) CodecPlayInOutCustomPayload.FML_HANDSHAKE_REGISTRY_DATA);
buf.writeBoolean(it.hasNext());
buf.writeString(entry.getName());
final Map<String, Integer> ids = entry.getIds();
buf.writeVarInt(ids.size());
for (Map.Entry<String, Integer> en : ids.entrySet()) {
buf.writeString(en.getKey());
buf.writeVarInt(en.getValue());
}
final List<String> substitutions = entry.getSubstitutions();
buf.writeVarInt(substitutions.size());
substitutions.forEach(buf::writeString);
output.add(new MessagePlayInOutChannelPayload("FML|HS", buf));
}
}
use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload in project LanternServer by LanternPowered.
the class AbstractCodecPlayInOutCustomPayload method encode.
@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
final String channel;
final ByteBuffer content;
if (message instanceof MessagePlayInOutChannelPayload) {
final MessagePlayInOutChannelPayload message1 = (MessagePlayInOutChannelPayload) message;
content = message1.getContent();
channel = message1.getChannel();
} else if (message instanceof MessagePlayInOutRegisterChannels) {
content = encodeChannels(((MessagePlayInOutRegisterChannels) message).getChannels());
channel = "REGISTER";
} else if (message instanceof MessagePlayInOutUnregisterChannels) {
content = encodeChannels(((MessagePlayInOutUnregisterChannels) message).getChannels());
channel = "UNREGISTER";
} else {
final MessageResult result = encode0(context, message);
channel = result.channel;
content = result.byteBuf;
}
buf.writeString(channel);
buf.writeBytes(content);
return buf;
}
use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload in project LanternServer by LanternPowered.
the class LanternChannelRegistrar method sendPayload.
void sendPayload(Player player, String channel, Consumer<ByteBuffer> payload) {
checkNotNull(player, "player");
checkNotNull(payload, "payload");
final NetworkSession session = ((LanternPlayer) player).getConnection();
if (session.getRegisteredChannels().contains(channel)) {
final ByteBuffer buf = ByteBufferAllocator.unpooled().buffer();
payload.accept(buf);
session.send(new MessagePlayInOutChannelPayload(channel, buf));
}
}
use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload in project LanternServer by LanternPowered.
the class LanternChannelRegistrar method sendPayloadToAll.
void sendPayloadToAll(String channel, Consumer<ByteBuffer> payload) {
checkNotNull(payload, "payload");
final Iterator<Player> players = this.server.getOnlinePlayers().stream().filter(player -> ((LanternPlayer) player).getConnection().getRegisteredChannels().contains(channel)).iterator();
if (players.hasNext()) {
final ByteBuffer buf = ByteBufferAllocator.unpooled().buffer();
payload.accept(buf);
final Message msg = new MessagePlayInOutChannelPayload(channel, buf);
players.forEachRemaining(player -> ((LanternPlayer) player).getConnection().send(msg));
}
}
Aggregations