Java Code Examples for protocolsupport.protocol.serializer.StringSerializer

The following examples show how to use protocolsupport.protocol.serializer.StringSerializer. These examples are extracted from open source projects. 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
@Override
protected void readServerData(ByteBuf serverdata) {
	player = NetworkEntity.createPlayer(serverdata.readInt());
	int gmdata = serverdata.readByte();
	gamemodeCurrent = GameMode.getById(gmdata & 0xFFFFFFF7);
	hardcore = (gmdata & 0x8) == 0x8;
	gamemodePrevious = GameMode.getById(serverdata.readByte());
	worlds = ArraySerializer.readVarIntVarIntUTF8StringArray(serverdata);
	dimensions = ItemStackSerializer.readDirectTag(serverdata);
	dimension = StringSerializer.readVarIntUTF8String(serverdata);
	world = StringSerializer.readVarIntUTF8String(serverdata);
	hashedSeed = serverdata.readLong();
	serverdata.readByte();
	maxplayers = TabAPI.getMaxTabSize();
	renderDistance = VarNumberSerializer.readVarInt(serverdata);
	reducedDebugInfo = serverdata.readBoolean();
	respawnScreenEnabled = serverdata.readBoolean();
	worldDebug = serverdata.readBoolean();
	worldFlat = serverdata.readBoolean();
}
 
Example 2
@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 3
@Override
protected void readServerData(ByteBuf serverdata) {
	action = MiscSerializer.readVarIntEnum(serverdata, Action.CONSTANT_LOOKUP);
	switch (action) {
		case SET_TITLE:
		case SET_SUBTITLE:
		case SET_ACTION_BAR: {
			message = ChatAPI.fromJSON(StringSerializer.readVarIntUTF8String(serverdata), true);
			break;
		}
		case SET_TIMES: {
			fadeIn = serverdata.readInt();
			stay = serverdata.readInt();
			fadeOut = serverdata.readInt();
			break;
		}
		case HIDE:
		case RESET: {
			break;
		}
	}
}
 
Example 4
public static void transformAndWriteStructureBlock(PacketDataCodec codec, ByteBuf data) {
	Position position = PositionSerializer.readLegacyPositionI(data);
	MiddleUpdateStructureBlock.Action action = MiddleUpdateStructureBlock.Action.CONSTANT_LOOKUP.getByOrdinal(data.readByte() - 1);
	MiddleUpdateStructureBlock.Mode mode = MiddleUpdateStructureBlock.Mode.valueOf(StringSerializer.readVarIntUTF8String(data, Short.MAX_VALUE));
	String name = StringSerializer.readVarIntUTF8String(data, Short.MAX_VALUE);
	byte offsetX = (byte) data.readInt();
	byte offsetY = (byte) data.readInt();
	byte offsetZ = (byte) data.readInt();
	byte sizeX = (byte) data.readInt();
	byte sizeY = (byte) data.readInt();
	byte sizeZ = (byte) data.readInt();
	MiddleUpdateStructureBlock.Mirror mirror = MiddleUpdateStructureBlock.Mirror.valueOf(StringSerializer.readVarIntUTF8String(data, Short.MAX_VALUE));
	MiddleUpdateStructureBlock.Rotation rotation = MiddleUpdateStructureBlock.Rotation.valueOf(StringSerializer.readVarIntUTF8String(data, Short.MAX_VALUE));
	String metadata = StringSerializer.readVarIntUTF8String(data, Short.MAX_VALUE);
	int ignoreEntities = data.readBoolean() ? 0x01 : 0;
	int showAir = data.readBoolean() ? 0x02 : 0;
	int showBoundingBox = data.readBoolean() ? 0x04 : 0;
	float integrity = data.readFloat();
	long seed = VarNumberSerializer.readVarLong(data);
	byte flags = (byte) (ignoreEntities | showAir | showBoundingBox);
	codec.read(MiddleUpdateStructureBlock.create(
		position, action, mode, name,
		offsetX, offsetY, offsetZ, sizeX, sizeY, sizeZ,
		mirror, rotation, metadata, integrity, seed, flags
	));
}
 
Example 5
public static ServerBoundPacketData create(Position position, Action action, Mode mode, String name,
	byte offsetX, byte offsetY, byte offsetZ, byte sizeX, byte sizeY, byte sizeZ,
	Mirror mirror, Rotation rotation, String metadata, float integrity, long seed, byte flags
) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_UPDATE_STRUCTURE_BLOCK);
	PositionSerializer.writePosition(creator, position);
	MiscSerializer.writeVarIntEnum(creator, action);
	MiscSerializer.writeVarIntEnum(creator, mode);
	StringSerializer.writeVarIntUTF8String(creator, name);
	creator.writeByte(offsetX);
	creator.writeByte(offsetY);
	creator.writeByte(offsetZ);
	creator.writeByte(sizeX);
	creator.writeByte(sizeY);
	creator.writeByte(sizeZ);
	MiscSerializer.writeVarIntEnum(creator, mirror);
	MiscSerializer.writeVarIntEnum(creator, rotation);
	StringSerializer.writeVarIntUTF8String(creator, metadata);
	creator.writeFloat(integrity);
	VarNumberSerializer.writeVarLong(creator, seed);
	creator.writeByte(flags);
	return creator;
}
 
Example 6
public static void transformAndWriteAutoCommandBlockEdit(PacketDataCodec codec, ByteBuf data) {
	Position position = PositionSerializer.readLegacyPositionI(data);
	String command = StringSerializer.readVarIntUTF8String(data, Short.MAX_VALUE);
	int trackOutput = data.readByte();
	MiddleUpdateCommandBlock.Mode mode = null;
	switch (StringSerializer.readVarIntUTF8String(data, 16)) {
		case "SEQUENCE": {
			mode = MiddleUpdateCommandBlock.Mode.SEQUENCE;
			break;
		}
		case "AUTO": {
			mode = MiddleUpdateCommandBlock.Mode.AUTO;
			break;
		}
		case "REDSTONE": {
			mode = MiddleUpdateCommandBlock.Mode.REDSTONE;
			break;
		}
	}
	int conditional = data.readByte();
	int auto = data.readByte();
	codec.read(MiddleUpdateCommandBlock.create(
		position, command, mode,
		BitUtils.createIBitMaskFromBits(auto_command_block_bits, new int[] {trackOutput, conditional, auto})
	));
}
 
Example 7
@Override
protected void writeToServer() {
	ServerBoundPacketData recipebookdata = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_RECIPE_BOOK_DATA);
	MiscSerializer.writeVarIntEnum(recipebookdata, type);
	switch (type) {
		case DISPLAYED_RECIPE: {
			StringSerializer.writeVarIntUTF8String(recipebookdata, recipeId);
			break;
		}
		case RECIPE_BOOK_STATUS: {
			recipebookdata.writeBoolean(craftRecipeBookOpen);
			recipebookdata.writeBoolean(craftRecipeBookFiltering);
			recipebookdata.writeBoolean(smeltingRecipeBookOpen);
			recipebookdata.writeBoolean(smeltingRecipeBookFiltering);
			recipebookdata.writeBoolean(blastingRecipeBookOpen);
			recipebookdata.writeBoolean(blastingRecipeBookFiltering);
			recipebookdata.writeBoolean(smokingRecipeBookOpen);
			recipebookdata.writeBoolean(smokingRecipeBookFiltering);
			break;
		}
	}
	codec.read(recipebookdata);
}
 
Example 8
protected static void writeAdvanvement(ByteBuf to, ProtocolVersion version, String locale, Advancement advancement) {
	if (advancement.parentId != null) {
		to.writeBoolean(true);
		StringSerializer.writeVarIntUTF8String(to, advancement.parentId);
	} else {
		to.writeBoolean(false);
	}
	if (advancement.display != null) {
		to.writeBoolean(true);
		writeAdvancementDisplay(to, version, locale, advancement.display);
	} else {
		to.writeBoolean(false);
	}
	ArraySerializer.writeVarIntVarIntUTF8StringArray(to, advancement.criteria);
	ArraySerializer.writeVarIntTArray(to, advancement.requirements, ArraySerializer::writeVarIntVarIntUTF8StringArray);
}
 
Example 9
@Override
protected void writeToClient() {
	ClientBoundPacketData combatevent = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_COMBAT_EVENT);
	MiscSerializer.writeVarIntEnum(combatevent, type);
	switch (type) {
		case ENTER_COMBAT: {
			break;
		}
		case END_COMBAT: {
			VarNumberSerializer.writeVarInt(combatevent, duration);
			combatevent.writeInt(entityId);
			break;
		}
		case ENTITY_DEAD: {
			VarNumberSerializer.writeVarInt(combatevent, playerId);
			combatevent.writeInt(entityId);
			StringSerializer.writeVarIntUTF8String(combatevent, message);
			break;
		}
	}
}
 
Example 10
@Override
protected void writeToClient() {
	ClientBoundPacketData serializer = ClientBoundPacketData.create(PacketType.CLIENTBOUND_LOGIN_SUCCESS);
	UUIDSerializer.writeUUID4I(serializer, uuid);
	StringSerializer.writeVarIntUTF8String(serializer, name);
	codec.write(serializer);
}
 
Example 11
@Override
protected void writeToClient() {
	ClientBoundPacketData advanvementstab = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_ADVANCEMENTS_TAB);
	if (identifier != null) {
		advanvementstab.writeBoolean(true);
		StringSerializer.writeVarIntUTF8String(advanvementstab, identifier);
	} else {
		advanvementstab.writeBoolean(false);
	}
	codec.write(advanvementstab);
}
 
Example 12
@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 13
Source Project: ProtocolSupport   Source File: Chat.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static ClientBoundPacketData create(MessagePosition position, BaseComponent message, UUID sender) {
	ClientBoundPacketData chat = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHAT);
	StringSerializer.writeVarIntUTF8String(chat, ChatAPI.toJSON(message));
	MiscSerializer.writeByteEnum(chat, position);
	UUIDSerializer.writeUUID2L(chat, sender);
	return chat;
}
 
Example 14
@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 15
@Override
protected void writeToClient() {
	ClientBoundPacketData updatemap = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_UPDATE_MAP);
	VarNumberSerializer.writeVarInt(updatemap, id);
	updatemap.writeByte(scale);
	updatemap.writeBoolean(showIcons);
	ArraySerializer.writeVarIntTArray(updatemap, icons, (to, icon) -> {
		VarNumberSerializer.writeVarInt(to, icon.type);
		to.writeByte(icon.x);
		to.writeByte(icon.z);
		to.writeByte(icon.direction);
		to.writeBoolean(icon.displayName != null);
		if (icon.displayName != null) {
			StringSerializer.writeVarIntUTF8String(to, icon.displayName);
		}
	});
	updatemap.writeByte(columns);
	if (columns > 0) {
		ArrayBasedIdRemappingTable colorRemapper = MapColorRemapper.REMAPPER.getTable(version);
		for (int i = 0; i < colors.length; i++) {
			colors[i] = (byte) colorRemapper.getRemap(colors[i] & 0xFF);
		}
		updatemap.writeByte(rows);
		updatemap.writeByte(xstart);
		updatemap.writeByte(zstart);
		ArraySerializer.writeVarIntByteArray(updatemap, colors);
	}
	codec.write(updatemap);
}
 
Example 16
@Override
protected void writeToClient() {
	ClientBoundPacketData startgame = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_START_GAME);
	startgame.writeInt(player.getId());
	StringSerializer.writeShortUTF16BEString(startgame, "default");
	startgame.writeByte(gamemodeCurrent.getId() | (hardcore ? 0x8 : 0));
	startgame.writeByte(LegacyDimension.getId(dimension));
	MiscSerializer.writeByteEnum(startgame, Difficulty.HARD);
	startgame.writeByte(0);
	startgame.writeByte(maxplayers);
	codec.write(startgame);
}
 
Example 17
@Override
protected void readClientData(ByteBuf clientdata) {
	PositionSerializer.readPositionTo(clientdata, position);
	for (int i = 0; i < lines.length; i++) {
		String rawline = StringSerializer.readVarIntUTF8String(clientdata, Short.MAX_VALUE);
		lines[i] = version.isAfter(ProtocolVersion.MINECRAFT_1_8) ? rawline : ChatAPI.fromJSON(rawline).toLegacyText(cache.getClientCache().getLocale());
	}
}
 
Example 18
@Override
protected void readServerData(ByteBuf serverdata) {
	id = StringSerializer.readVarIntUTF8String(serverdata);
	category = MiscSerializer.readVarIntEnum(serverdata, SoundCategory.CONSTANT_LOOKUP);
	x = serverdata.readInt();
	y = serverdata.readInt();
	z = serverdata.readInt();
	volume = serverdata.readFloat();
	pitch = serverdata.readFloat();
}
 
Example 19
@Override
protected void writeToServer() {
	ServerBoundPacketData tabcomplete = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_TAB_COMPLETE);
	VarNumberSerializer.writeVarInt(tabcomplete, id);
	StringSerializer.writeVarIntUTF8String(tabcomplete, string);
	codec.read(tabcomplete);
}
 
Example 20
@Override
protected void readClientData(ByteBuf clientdata) {
	locale = StringSerializer.readShortUTF16BEString(clientdata, 16);
	viewDist = clientdata.readByte();
	int chatState = clientdata.readByte();
	chatMode = ChatMode.CONSTANT_LOOKUP.getByOrdinal(chatState & 7);
	chatColors = (chatState & 8) == 8;
	clientdata.readByte();
	clientdata.readBoolean();
	skinFlags = 255;
	mainHand = MainHand.RIGHT;
}
 
Example 21
public static ServerBoundPacketData create(Position position, String command, Mode mode, int flags) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_UPDATE_COMMAND_BLOCK);
	PositionSerializer.writePosition(creator, position);
	StringSerializer.writeVarIntUTF8String(creator, command);
	MiscSerializer.writeVarIntEnum(creator, mode);
	creator.writeByte(flags);
	return creator;
}
 
Example 22
@Override
protected void read0(ByteBuf from) {
	itemName = StringSerializer.readShortUTF16BEString(from);
	action = from.readByte();
	if (action != 1) {
		scoreName = StringSerializer.readShortUTF16BEString(from);
		value = from.readInt();
	}
}
 
Example 23
@Override
protected void writeToClient() {
	ClientBoundPacketData resourcepack = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_RESOURCE_PACK);
	StringSerializer.writeVarIntUTF8String(resourcepack, url);
	StringSerializer.writeVarIntUTF8String(resourcepack, hash);
	codec.write(resourcepack);
}
 
Example 24
@Override
protected void readClientData(ByteBuf clientdata) {
	locale = StringSerializer.readVarIntUTF8String(clientdata, 16);
	viewDist = clientdata.readByte();
	chatMode = MiscSerializer.readByteEnum(clientdata, ChatMode.CONSTANT_LOOKUP);
	chatColors = clientdata.readBoolean();
	clientdata.readByte();
	clientdata.readBoolean();
	skinFlags = 255;
	mainHand = MainHand.RIGHT;
}
 
Example 25
@Override
protected void writeToClient() {
	ClientBoundPacketData tabcomplete = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_TAB_COMPLETE);
	VarNumberSerializer.writeVarInt(tabcomplete, id);
	VarNumberSerializer.writeVarInt(tabcomplete, start);
	VarNumberSerializer.writeVarInt(tabcomplete, length);
	ArraySerializer.writeVarIntTArray(tabcomplete, matches, (to, match) -> {
		StringSerializer.writeVarIntUTF8String(to, match.getMatch());
		to.writeBoolean(match.hasTooltip());
		if (match.hasTooltip()) {
			StringSerializer.writeVarIntUTF8String(to, match.getTooltip());
		}
	});
	codec.write(tabcomplete);
}
 
Example 26
@Override
protected void read0(ByteBuf from) {
	locale = StringSerializer.readShortUTF16BEString(from);
	viewDistance = from.readByte();
	byte chatState = from.readByte();
	chatFlags = (byte) (chatState & 7);
	chatColours = ((chatState & 8) == 8);
	difficulty = from.readByte();
	from.readBoolean();
}
 
Example 27
@Override
protected void writeToClient() {
	ClientBoundPacketData resourcepack = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CUSTOM_PAYLOAD);
	StringSerializer.writeVarIntUTF8String(resourcepack, "MC|RPack");
	ArraySerializer.writeShortByteArray(resourcepack, to -> ByteBufUtil.writeUtf8(to, url));
	codec.write(resourcepack);
}
 
Example 28
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboardobjective = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_OBJECTIVE);
	StringSerializer.writeVarIntUTF8String(scoreboardobjective, name);
	MiscSerializer.writeByteEnum(scoreboardobjective, mode);
	if (mode != Mode.REMOVE) {
		StringSerializer.writeVarIntUTF8String(scoreboardobjective, LegacyChat.clampLegacyText(value.toLegacyText(cache.getClientCache().getLocale()), 32));
		StringSerializer.writeVarIntUTF8String(scoreboardobjective, getTypeString(type));
	}
	codec.write(scoreboardobjective);
}
 
Example 29
@Override
protected void readServerData(ByteBuf serverdata) {
	name = StringSerializer.readVarIntUTF8String(serverdata);
	mode = MiscSerializer.readByteEnum(serverdata, Mode.CONSTANT_LOOKUP);
	if (mode != Mode.REMOVE) {
		value = ChatAPI.fromJSON(StringSerializer.readVarIntUTF8String(serverdata), true);
		type = MiscSerializer.readVarIntEnum(serverdata, Type.CONSTANT_LOOKUP);
	}

	switch (mode) {
		case CREATE: {
			if (!objectives.add(name)) {
				throw CancelMiddlePacketException.INSTANCE;
			}
			break;
		}
		case REMOVE: {
			if (!objectives.remove(name)) {
				throw CancelMiddlePacketException.INSTANCE;
			}
			break;
		}
		default: {
			if (!objectives.contains(name)) {
				throw CancelMiddlePacketException.INSTANCE;
			}
			break;
		}
	}
}
 
Example 30
public static ServerBoundPacketData create(String locale, int viewDist, ChatMode chatMode, boolean chatColors, int skinFlags, MainHand mainHand) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_SETTINGS);
	StringSerializer.writeVarIntUTF8String(creator, locale);
	creator.writeByte(viewDist);
	MiscSerializer.writeVarIntEnum(creator, chatMode);
	creator.writeBoolean(chatColors);
	creator.writeByte(skinFlags);
	MiscSerializer.writeVarIntEnum(creator, mainHand);
	return creator;
}