Java Code Examples for protocolsupport.protocol.serializer.StringSerializer#writeShortUTF16BEString()

The following examples show how to use protocolsupport.protocol.serializer.StringSerializer#writeShortUTF16BEString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientSettingsPacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void write(ByteBuf data, ClientSettings packet) {
	StringSerializer.writeShortUTF16BEString(data, packet.getLocale());
	data.writeByte(packet.getViewDistance());
	data.writeByte(packet.getChatFlags());
	data.writeByte(packet.getDifficulty());
	data.writeBoolean(((packet.getSkinParts() >> 0x01) & 1) == 1);
}
 
Example 2
Source File: Chat.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	if (position == MessagePosition.HOTBAR) {
		return;
	}

	ClientBoundPacketData chat = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHAT);
	StringSerializer.writeShortUTF16BEString(chat, message.toLegacyText(clientCache.getLocale()));
	codec.write(chat);
}
 
Example 3
Source File: SpawnNamed.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData spawnnamed = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_NAMED);
	spawnnamed.writeInt(entity.getId());
	PlayerListEntry entry = playerlistCache.getEntry(entity.getUUID());
	StringSerializer.writeShortUTF16BEString(spawnnamed, entry != null ? Utils.clampString(entry.getUserName(), 16) : "UNKNOWN");
	spawnnamed.writeInt((int) (x * 32));
	spawnnamed.writeInt((int) (y * 32));
	spawnnamed.writeInt((int) (z * 32));
	spawnnamed.writeByte(yaw);
	spawnnamed.writeByte(pitch);
	spawnnamed.writeShort(0);
	NetworkEntityMetadataSerializer.writeLegacyData(spawnnamed, version, I18NData.DEFAULT_LOCALE, NetworkEntityMetadataList.EMPTY);
	codec.write(spawnnamed);
}
 
Example 4
Source File: ServerInfo.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData serverinfo = ClientBoundPacketData.create(PacketType.CLIENTBOUND_STATUS_SERVER_INFO);
	String response = new StringJoiner("\u0000")
	.add("ยง1")
	.add(String.valueOf(ping.getProtocolData().getVersion()))
	.add(ping.getProtocolData().getName())
	.add(ping.getMotd().toLegacyText(cache.getClientCache().getLocale()))
	.add(String.valueOf(ping.getPlayers().getOnline()))
	.add(String.valueOf(ping.getPlayers().getMax()))
	.toString();
	StringSerializer.writeShortUTF16BEString(serverinfo, response);
	codec.write(serverinfo);
}
 
Example 5
Source File: InventoryOpen.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient0() {
	LegacyWindowData wdata = LegacyWindowType.getData(windowRemapper.toClientWindowType(type));
	ClientBoundPacketData windowopen = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WINDOW_OPEN);
	windowopen.writeByte(windowId);
	windowopen.writeByte(wdata.getIntId());
	StringSerializer.writeShortUTF16BEString(windowopen, LegacyChat.clampLegacyText(title.toLegacyText(clientCache.getLocale()), 32));
	windowopen.writeByte(windowRemapper.toClientSlots(0));
	codec.write(windowopen);
}
 
Example 6
Source File: StartGamePacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void write(ByteBuf data, Login packet) {
	data.writeInt(packet.getEntityId());
	StringSerializer.writeShortUTF16BEString(data, packet.getLevelType());
	data.writeByte(packet.getGameMode());
	data.writeByte(packet.getDimension());
	data.writeByte(packet.getDifficulty());
	data.writeByte(0);
	data.writeByte(packet.getMaxPlayers());
}
 
Example 7
Source File: RespawnPacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void write(ByteBuf data, Respawn packet) {
	data.writeInt(packet.getDimension());
	data.writeByte(packet.getDifficulty());
	data.writeByte(packet.getGameMode());
	data.writeShort(256);
	StringSerializer.writeShortUTF16BEString(data, packet.getLevelType());
}
 
Example 8
Source File: PlayerListItemPacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Collection<ByteBuf> toData(PlayerListItem packet) {
	ArrayList<ByteBuf> packets = new ArrayList<>();
	for (Item item : packet.getItems()) {
		ByteBuf data = Allocator.allocateBuffer();
		data.writeByte(LegacyPacketId.Clientbound.PLAY_PLAYER_LIST);
           StringSerializer.writeShortUTF16BEString(data, getDisplayName(item));
           data.writeBoolean(packet.getAction() != Action.REMOVE_PLAYER);
           data.writeShort(item.getPing());
           packets.add(data);
	}
	return packets;
}
 
Example 9
Source File: ChangeDimension.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData changedimension = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_RESPAWN);
	changedimension.writeInt(LegacyDimension.getId(dimension));
	MiscSerializer.writeByteEnum(changedimension, Difficulty.HARD);
	changedimension.writeByte(gamemodeCurrent.getId());
	changedimension.writeShort(256);
	StringSerializer.writeShortUTF16BEString(changedimension, "default");
	codec.write(changedimension);
}
 
Example 10
Source File: SpawnPainting.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	switch (direction) {
		case 0: {
			position.modifyZ(-1);
			break;
		}
		case 1: {
			position.modifyX(1);
			break;
		}
		case 2: {
			position.modifyZ(1);
			break;
		}
		case 3: {
			position.modifyX(-1);
			break;
		}
	}
	ClientBoundPacketData spawnpainting = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_PAINTING);
	spawnpainting.writeInt(entity.getId());
	StringSerializer.writeShortUTF16BEString(spawnpainting, LegacyPainting.getName(type));
	PositionSerializer.writeLegacyPositionI(spawnpainting, position);
	spawnpainting.writeInt(direction);
	codec.write(spawnpainting);
}
 
Example 11
Source File: TabComplete.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	String prefix = start <= 1 ? "/" : "";
	ClientBoundPacketData tabcomplete = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_TAB_COMPLETE);
	StringSerializer.writeShortUTF16BEString(tabcomplete, Utils.clampString(String.join("\u0000", Arrays.stream(matches).map(input -> prefix + input.getMatch()).collect(Collectors.toList())), Short.MAX_VALUE));
	codec.write(tabcomplete);
}
 
Example 12
Source File: Chat.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	if (position == MessagePosition.HOTBAR) {
		return;
	}

	ClientBoundPacketData chat = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHAT);
	StringSerializer.writeShortUTF16BEString(chat, encode(message.toLegacyText(clientCache.getLocale())));
	codec.write(chat);
}
 
Example 13
Source File: LoginRequestServerHandshakePacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void write(ByteBuf data, LoginRequest packet) {
	data.writeByte(connection.getVersion().getId());
	StringSerializer.writeShortUTF16BEString(data, packet.getData());
	StringSerializer.writeShortUTF16BEString(data, cache.getServerHandshake().getHost());
	data.writeInt(cache.getServerHandshake().getPort());
}
 
Example 14
Source File: EncryptionRequestPacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void write(ByteBuf data, EncryptionRequest packet) {
	StringSerializer.writeShortUTF16BEString(data, packet.getServerId());
	ArraySerializer.writeShortLengthByteArray(data, packet.getPublicKey());
	ArraySerializer.writeShortLengthByteArray(data, packet.getVerifyToken());
}
 
Example 15
Source File: PluginMessagePacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void write(ByteBuf data, PluginMessage packet) {
	StringSerializer.writeShortUTF16BEString(data, packet.getTag());
	ArraySerializer.writeShortLengthByteArray(data, packet.getData());
}
 
Example 16
Source File: TabCompleteResponsePacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void write(ByteBuf data, TabCompleteResponse packet) {
	StringSerializer.writeShortUTF16BEString(data, String.join("\u0000", packet.getCommands()));
}
 
Example 17
Source File: ScoreboardObjectivePacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void write(ByteBuf data, ScoreboardObjective packet) {
	StringSerializer.writeShortUTF16BEString(data, packet.getName());
	StringSerializer.writeShortUTF16BEString(data, packet.getValue());
	data.writeByte(packet.getAction());
}
 
Example 18
Source File: ScoreboardDisplayPacket.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void write(ByteBuf data, ScoreboardDisplay packet) {
	data.writeByte(packet.getPosition());
	StringSerializer.writeShortUTF16BEString(data, packet.getName());
}
 
Example 19
Source File: LoginDisconnect.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData logindisconnect = ClientBoundPacketData.create(PacketType.CLIENTBOUND_LOGIN_DISCONNECT);
	StringSerializer.writeShortUTF16BEString(logindisconnect, message.toLegacyText(cache.getClientCache().getLocale()));
	codec.write(logindisconnect);
}
 
Example 20
Source File: LoginDisconnect.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData serializer = ClientBoundPacketData.create(PacketType.CLIENTBOUND_LOGIN_DISCONNECT);
	StringSerializer.writeShortUTF16BEString(serializer, message.toLegacyText(cache.getClientCache().getLocale()));
	codec.write(serializer);
}