use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutStatistics method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutStatistics message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer();
Set<Entry> entries = message.getEntries();
buf.writeVarInt(entries.size());
for (Entry entry : entries) {
buf.writeString(entry.getName());
buf.writeVarInt(entry.getValue());
}
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutTabListEntries method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTabListEntries message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer();
List<Entry> entries = message.getEntries();
int type = this.typeLookup.get(entries.get(0).getClass());
buf.writeVarInt(type);
buf.writeVarInt(entries.size());
for (Entry entry : entries) {
buf.writeUniqueId(entry.getGameProfile().getUniqueId());
switch(type) {
case ADD:
buf.writeString(entry.getGameProfile().getName().orElse("unknown"));
Collection<ProfileProperty> properties = entry.getGameProfile().getPropertyMap().values();
buf.writeVarInt(properties.size());
for (ProfileProperty property : properties) {
buf.writeString(property.getName());
buf.writeString(property.getValue());
Optional<String> signature = property.getSignature();
boolean flag = signature.isPresent();
buf.writeBoolean(flag);
if (flag) {
buf.writeString(signature.get());
}
}
buf.writeVarInt(((LanternGameMode) entry.getGameMode()).getInternalId());
buf.writeVarInt(entry.getPing());
Text displayName = entry.getDisplayName();
boolean flag = displayName != null;
buf.writeBoolean(flag);
if (flag) {
buf.write(Types.TEXT, displayName);
}
break;
case UPDATE_GAME_MODE:
buf.writeVarInt(((LanternGameMode) entry.getGameMode()).getInternalId());
break;
case UPDATE_LATENCY:
buf.writeVarInt(entry.getPing());
break;
case UPDATE_DISPLAY_NAME:
Text displayName0 = entry.getDisplayName();
boolean flag0 = displayName0 != null;
buf.writeBoolean(flag0);
if (flag0) {
buf.write(Types.TEXT, displayName0);
}
break;
case REMOVE:
break;
}
}
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutTeams method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTeams message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeString(message.getTeamName());
if (message instanceof MessagePlayOutTeams.CreateOrUpdate) {
buf.writeByte((byte) (message instanceof MessagePlayOutTeams.Create ? 0 : 2));
final MessagePlayOutTeams.CreateOrUpdate message1 = (MessagePlayOutTeams.CreateOrUpdate) message;
buf.writeString(message1.getDisplayName());
buf.writeString(message1.getPrefix());
buf.writeString(message1.getSuffix());
int flags = 0;
if (message1.getFriendlyFire()) {
flags |= 0x01;
}
if (message1.getSeeFriendlyInvisibles()) {
flags |= 0x02;
}
buf.writeByte((byte) flags);
buf.writeString(message1.getNameTagVisibility().getId());
buf.writeString(message1.getCollisionRule().getName());
final TextColor c = message1.getColor();
buf.writeByte((byte) (c == TextColors.NONE || c == TextColors.RESET ? -1 : FormattingCodeTextSerializer.FORMATS_TO_CODE.getChar(c)));
} else {
buf.writeByte((byte) (message instanceof MessagePlayOutTeams.Remove ? 1 : message instanceof MessagePlayOutTeams.AddPlayers ? 3 : 4));
}
if (message instanceof MessagePlayOutTeams.Players) {
final List<String> players = ((MessagePlayOutTeams.Players) message).getPlayers();
buf.writeVarInt(players.size());
players.forEach(buf::writeString);
}
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutTitle method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTitle message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
if (message instanceof MessagePlayOutTitle.Clear) {
buf.writeVarInt(CLEAR);
} else if (message instanceof MessagePlayOutTitle.Reset) {
buf.writeVarInt(RESET);
} else if (message instanceof MessagePlayOutTitle.SetTitle) {
buf.writeVarInt(SET_TITLE);
buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetTitle) message).getTitle());
} else if (message instanceof MessagePlayOutTitle.SetSubtitle) {
buf.writeVarInt(SET_SUBTITLE);
buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetSubtitle) message).getTitle());
} else if (message instanceof MessagePlayOutTitle.SetActionbarTitle) {
buf.writeVarInt(SET_ACTIONBAR_TITLE);
buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetActionbarTitle) message).getTitle());
} else {
final MessagePlayOutTitle.SetTimes message0 = (MessagePlayOutTitle.SetTimes) message;
buf.writeVarInt(SET_TIMES);
buf.writeInteger(message0.getFadeIn());
buf.writeInteger(message0.getStay());
buf.writeInteger(message0.getFadeOut());
}
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutUnlockRecipes method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutUnlockRecipes message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
if (message instanceof MessagePlayOutUnlockRecipes.Remove) {
buf.writeVarInt((short) 2);
} else if (message instanceof MessagePlayOutUnlockRecipes.Add) {
buf.writeVarInt((short) 1);
} else if (message instanceof MessagePlayOutUnlockRecipes.Init) {
buf.writeVarInt((short) 0);
} else {
throw new EncoderException();
}
buf.writeBoolean(message.hasOpenCraftingBook());
buf.writeBoolean(message.hasCraftingFilter());
IntList recipeIds = message.getRecipeIds();
buf.writeVarInt(recipeIds.size());
recipeIds.forEach(buf::writeVarInt);
if (message instanceof MessagePlayOutUnlockRecipes.Init) {
recipeIds = ((MessagePlayOutUnlockRecipes.Init) message).getRecipeIdsToBeDisplayed();
buf.writeVarInt(recipeIds.size());
recipeIds.forEach(buf::writeVarInt);
}
return buf;
}
Aggregations