use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutTeams 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;
}
Aggregations