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

The following examples show how to use protocolsupport.protocol.serializer.StringSerializer#writeString() . 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: BlockTileUpdate.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
public static ClientBoundPacketData create(ProtocolVersion version, String locale, TileEntity tile) {
	TileEntityType type = tile.getType();
	if (type == TileEntityType.SIGN) {
		ClientBoundPacketData blocksignupdate = ClientBoundPacketData.create(PacketType.CLIENTBOUND_LEGACY_PLAY_UPDATE_SIGN);
		PositionSerializer.writeLegacyPositionS(blocksignupdate, tile.getPosition());
		for (String line : CommonNBT.getSignLines(tile.getNBT())) {
			StringSerializer.writeString(blocksignupdate, version, LegacyChat.clampLegacyText(ChatAPI.fromJSON(line, true).toLegacyText(locale), 15));
		}
		return blocksignupdate;
	} else {
		ClientBoundPacketData blocktileupdate = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_BLOCK_TILE);
		PositionSerializer.writeLegacyPositionS(blocktileupdate, tile.getPosition());
		blocktileupdate.writeByte(type.getNetworkId());
		ItemStackSerializer.writeShortTag(blocktileupdate, tile.getNBT());
		return blocktileupdate;
	}
}
 
Example 2
Source File: WorldCustomSound.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
public static ClientBoundPacketData create(
	ProtocolVersion version,
	int x, int y, int z,
	String sound, float volume, float pitch
) {
	ClientBoundPacketData worldcustomsound = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WORLD_CUSTOM_SOUND);
	sound = SoundRemapper.getSoundName(version, sound);
	if (version.isBeforeOrEq(ProtocolVersion.MINECRAFT_1_5_2)) {
		sound = Utils.clampString(sound, 32);
	}
	StringSerializer.writeString(worldcustomsound, version, sound);
	worldcustomsound.writeInt(x);
	worldcustomsound.writeInt(y);
	worldcustomsound.writeInt(z);
	worldcustomsound.writeFloat(volume);
	worldcustomsound.writeByte((int) (pitch * 63.5));
	return worldcustomsound;
}
 
Example 3
Source File: ScoreboardTeam.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboardteam = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_TEAM);
	StringSerializer.writeString(scoreboardteam, version, name);
	MiscSerializer.writeByteEnum(scoreboardteam, mode);
	if ((mode == Mode.CREATE) || (mode == Mode.UPDATE)) {
		StringSerializer.writeString(scoreboardteam, version, LegacyChat.clampLegacyText(displayName.toLegacyText(clientCache.getLocale()), 32));
		Any<String, String> nfix = formatPrefixSuffix();
		StringSerializer.writeString(scoreboardteam, version, nfix.getObj1());
		StringSerializer.writeString(scoreboardteam, version, nfix.getObj2());
		scoreboardteam.writeByte(friendlyFire);
	}
	if ((mode == Mode.CREATE) || (mode == Mode.PLAYERS_ADD) || (mode == Mode.PLAYERS_REMOVE)) {
		ArraySerializer.writeShortTArray(scoreboardteam, players, (to, element) -> StringSerializer.writeString(to, version, Utils.clampString(element, 16)));
	}
	codec.write(scoreboardteam);
}
 
Example 4
Source File: SpawnEntityPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	VarNumberSerializer.writeSVarLong(serializer, entityId); // entity ID
	VarNumberSerializer.writeVarLong(serializer, entityId); // runtime ID
	VarNumberSerializer.writeVarInt(serializer, entityType); // boss bar entity id
	serializer.writeFloatLE(x); // x
	serializer.writeFloatLE(y); // y
	serializer.writeFloatLE(z); // z
	serializer.writeFloatLE(motionX); // motx
	serializer.writeFloatLE(motionY); // moty
	serializer.writeFloatLE(motionZ); // motz
	serializer.writeFloatLE(pitch); // pitch
	serializer.writeFloatLE(yaw); // yaw
	// We can't use SetAttributePackets#encodeAttributes because MCPE uses an different format in SpawnEntityPacket (why mojang?)
	VarNumberSerializer.writeVarInt(serializer, attributes.size());
	for (SetAttributesPacket.Attribute attribute : attributes) {
		StringSerializer.writeString(serializer, connection.getVersion(), attribute.getName());
		serializer.writeFloatLE(attribute.getMinimum());
		serializer.writeFloatLE(attribute.getValue());
		serializer.writeFloatLE(attribute.getMaximum());
	}
	//TODO: fix
	VarNumberSerializer.writeVarInt(serializer, 0);
	//EntityMetadata.encodeMeta(serializer, connection.getVersion(), I18NData.DEFAULT_LOCALE, metadata);
	VarNumberSerializer.writeVarInt(serializer, 0); //links, not used
}
 
Example 5
Source File: SetAttributesPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void encodeAttributes(Connection connection, ByteBuf serializer, List<Attribute> attributes) {
	VarNumberSerializer.writeVarInt(serializer, attributes.size());
	for (Attribute attribute : attributes) {
		serializer.writeFloatLE(attribute.getMinimum());
		serializer.writeFloatLE(attribute.getMaximum());
		serializer.writeFloatLE(attribute.getValue());
		serializer.writeFloatLE(attribute.getDefaultValue()); //default value
		StringSerializer.writeString(serializer, connection.getVersion(), attribute.getName());
	}
}
 
Example 6
Source File: ResourcePackChunkDataPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	StringSerializer.writeString(serializer, ProtocolVersionsHelper.LATEST_PE, packId);
	serializer.writeIntLE(chunkIdx);
	serializer.writeLongLE(CHUNK_SIZE * chunkIdx);
	serializer.writeIntLE(packChunk.length);
	serializer.writeBytes(packChunk);
}
 
Example 7
Source File: PlayerListSetEntry.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
protected static ClientBoundPacketData create(PacketDataCodec codec, ProtocolVersion version, String name, boolean addOrUpdate, short ping) {
	ClientBoundPacketData playerinfo = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_PLAYER_INFO);
	StringSerializer.writeString(playerinfo, version, LegacyChat.clampLegacyText(name, 16));
	playerinfo.writeBoolean(addOrUpdate);
	playerinfo.writeShort(ping);
	return playerinfo;
}
 
Example 8
Source File: ResourcePackDataInfoPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	StringSerializer.writeString(serializer, ProtocolVersionsHelper.LATEST_PE, pack.getPackId());
	serializer.writeIntLE(ResourcePackChunkDataPacket.CHUNK_SIZE); //max chunk size 1MB
	serializer.writeIntLE((int) Math.ceil(pack.getPackSize() / ResourcePackChunkDataPacket.CHUNK_SIZE)); //chunk count
	serializer.writeLongLE(pack.getPackSize()); //res pack size
	byte[] hash = pack.getSha256();
	ArraySerializer.writeVarIntByteArray(serializer, hash);
}
 
Example 9
Source File: SkinPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	ProtocolVersion version = connection.getVersion();
	MiscSerializer.writePEUUID(serializer, uuid);
	StringSerializer.writeString(serializer, version, skinId);
	StringSerializer.writeString(serializer, version, skinName);
	StringSerializer.writeString(serializer, version, previousName);
	ArraySerializer.writeVarIntByteArray(serializer, skinData);
	ArraySerializer.writeVarIntByteArray(serializer, capeData);
	StringSerializer.writeString(serializer, version, geometryId);
	StringSerializer.writeString(serializer, version, geometryData);
	serializer.writeBoolean(false); //premium skin
}
 
Example 10
Source File: SpawnPlayerPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	MiscSerializer.writePEUUID(serializer, uuid);
	StringSerializer.writeString(serializer, connection.getVersion(), name);
	StringSerializer.writeString(serializer, connection.getVersion(), ""); //ThirdPartyName :F
	VarNumberSerializer.writeVarInt(serializer, 0); //Platform
	VarNumberSerializer.writeSVarLong(serializer, entityId); // entity ID
	VarNumberSerializer.writeVarLong(serializer, entityId); // runtime ID
	StringSerializer.writeString(serializer, connection.getVersion(), ""); //Chat :F
	serializer.writeFloatLE(x); // x
	serializer.writeFloatLE(y); // y
	serializer.writeFloatLE(z); // z
	serializer.writeFloatLE(motionX); // motx
	serializer.writeFloatLE(motionY); // moty
	serializer.writeFloatLE(motionZ); // motz
	serializer.writeFloatLE(pitch); // pitch
	serializer.writeFloatLE(headYaw); // yaw
	serializer.writeFloatLE(yaw); // yaw
	//ItemStackSerializer.writeItemStack(serializer, connection.getVersion(), connection.getCache().getAttributesCache().getLocale(), NetworkItemStack.NULL, true); //held item.
	ItemStackSerializer.writeItemStack(serializer,NetworkItemStack.NULL);
	//TODO Fix!
	VarNumberSerializer.writeVarInt(serializer, 0);
	//EntityMetadata.encodeMeta(serializer, connection.getVersion(), connection.getCache().getAttributesCache().getLocale(), metadata);
	//adventure settings
	VarNumberSerializer.writeVarInt(serializer, 0);
	VarNumberSerializer.writeVarInt(serializer, 0);
	VarNumberSerializer.writeVarInt(serializer, 0);
	VarNumberSerializer.writeVarInt(serializer, 0);
	VarNumberSerializer.writeVarInt(serializer, 0);
	serializer.writeLongLE(0); //?
	VarNumberSerializer.writeSVarInt(serializer, 0); //links, not used
}
 
Example 11
Source File: InventoryOpen.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void writeData(ClientBoundPacketData to, ProtocolVersion version, int windowId, int type, String title, int slots) {
	to.writeByte(windowId);
	to.writeByte(type);
	StringSerializer.writeString(to, version, LegacyChat.clampLegacyText(title, 32));
	to.writeByte(slots);
	to.writeBoolean(true); //use provided title
}
 
Example 12
Source File: ScoreboardScore.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboardscore = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_SCORE);
	StringSerializer.writeString(scoreboardscore, version, Utils.clampString(name, 16));
	scoreboardscore.writeByte(mode);
	if (mode != 1) {
		StringSerializer.writeString(scoreboardscore, version, objectiveName);
		scoreboardscore.writeInt(value);
	}
	codec.write(scoreboardscore);
}
 
Example 13
Source File: ScoreboardDisplay.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboarddisplay = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_DISPLAY_SLOT);
	scoreboarddisplay.writeByte(position);
	StringSerializer.writeString(scoreboarddisplay, version, name);
	codec.write(scoreboarddisplay);
}
 
Example 14
Source File: ScoreboardObjective.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboardobjective = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_OBJECTIVE);
	StringSerializer.writeString(scoreboardobjective, version, name);
	StringSerializer.writeString(
		scoreboardobjective, version,
		mode == Mode.REMOVE ? "" : LegacyChat.clampLegacyText(value.toLegacyText(cache.getClientCache().getLocale()), 32)
	);
	MiscSerializer.writeByteEnum(scoreboardobjective, mode);
	codec.write(scoreboardobjective);
}
 
Example 15
Source File: CustomPayload.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ClientBoundPacketData create(ProtocolVersion version, String tag, ByteBuf data) {
	ClientBoundPacketData custompayload = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CUSTOM_PAYLOAD);
	StringSerializer.writeString(custompayload, version, tag);
	ArraySerializer.writeShortByteArray(custompayload, data);
	return custompayload;
}
 
Example 16
Source File: NetworkEntityMetadataObjectString.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void writeToStream(ByteBuf to, ProtocolVersion version, String locale) {
	StringSerializer.writeString(to, version, value);
}
 
Example 17
Source File: DisconnectPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	serializer.writeBoolean(hide);
	StringSerializer.writeString(serializer, connection.getVersion(), reason);
}
 
Example 18
Source File: ModalRequestPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	VarNumberSerializer.writeVarInt(serializer, modalId);
	StringSerializer.writeString(serializer, connection.getVersion(), modalJSON);
}
 
Example 19
Source File: ModalResponsePacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	VarNumberSerializer.writeVarInt(serializer, modalId);
	StringSerializer.writeString(serializer, connection.getVersion(), modalJSON);
}
 
Example 20
Source File: TransferPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	StringSerializer.writeString(serializer, connection.getVersion(), address);
	serializer.writeShortLE(port);
}