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

The following examples show how to use protocolsupport.protocol.serializer.StringSerializer#writeVarIntUTF8String() . 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: 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.writeVarIntUTF8String(scoreboardteam, name);
	MiscSerializer.writeByteEnum(scoreboardteam, mode);
	if ((mode == Mode.CREATE) || (mode == Mode.UPDATE)) {
		StringSerializer.writeVarIntUTF8String(scoreboardteam, LegacyChat.clampLegacyText(displayName.toLegacyText(clientCache.getLocale()), 32));
		Any<String, String> nfix = formatPrefixSuffix();
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nfix.getObj1());
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nfix.getObj2());
		scoreboardteam.writeByte(friendlyFire);
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nameTagVisibility);
		StringSerializer.writeVarIntUTF8String(scoreboardteam, collisionRule);
		scoreboardteam.writeByte(format.isColor() ? format.ordinal() : -1);
	}
	if ((mode == Mode.CREATE) || (mode == Mode.PLAYERS_ADD) || (mode == Mode.PLAYERS_REMOVE)) {
		ArraySerializer.writeVarIntVarIntUTF8StringArray(scoreboardteam, players);
	}
	codec.write(scoreboardteam);
}
 
Example 2
Source File: MiddleUpdateStructureBlock.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
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 3
Source File: Advancements.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
protected static void writeAdvancementDisplay(ByteBuf to, ProtocolVersion version, String locale, AdvancementDisplay display) {
	StringSerializer.writeVarIntUTF8String(to, ChatAPI.toJSON(LegacyChatJson.convert(version, locale, display.title)));
	StringSerializer.writeVarIntUTF8String(to, ChatAPI.toJSON(LegacyChatJson.convert(version, locale, display.description)));
	ItemStackSerializer.writeItemStack(to, version, locale, display.icon);
	MiscSerializer.writeVarIntEnum(to, display.frametype);
	to.writeInt(display.flags);
	if ((display.flags & AdvancementDisplay.flagHasBackgroundOffset) != 0) {
		StringSerializer.writeVarIntUTF8String(to, display.background);
	}
	to.writeFloat(display.x);
	to.writeFloat(display.y);
}
 
Example 4
Source File: WorldCustomSound.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ClientBoundPacketData create(
	ProtocolVersion version,
	int x, int y, int z,
	String sound, SoundCategory category, float volume, float pitch
) {
	ClientBoundPacketData worldcustomsound = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WORLD_CUSTOM_SOUND);
	StringSerializer.writeVarIntUTF8String(worldcustomsound, SoundRemapper.getSoundName(version, sound));
	MiscSerializer.writeVarIntEnum(worldcustomsound, category);
	worldcustomsound.writeInt(x);
	worldcustomsound.writeInt(y);
	worldcustomsound.writeInt(z);
	worldcustomsound.writeFloat(volume);
	worldcustomsound.writeByte((int) (pitch * 63.5));
	return worldcustomsound;
}
 
Example 5
Source File: AbstractDeclareRecipes.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeRecipeData(ByteBuf to, ProtocolVersion version, ShapedRecipe recipe) {
	VarNumberSerializer.writeVarInt(to, recipe.getWidth());
	VarNumberSerializer.writeVarInt(to, recipe.getHeight());
	StringSerializer.writeVarIntUTF8String(to, recipe.getGroup());
	for (RecipeIngredient ingredient : recipe.getIngredients()) {
		writeIngredient(to, version, ingredient);
	}
	ItemStackSerializer.writeItemStack(to, version, I18NData.DEFAULT_LOCALE, recipe.getResult());
}
 
Example 6
Source File: LoginCustomPayload.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData logincustompayload = ClientBoundPacketData.create(PacketType.CLIENTBOUND_LOGIN_CUSTOM_PAYLOAD);
	VarNumberSerializer.writeVarInt(logincustompayload, id);
	StringSerializer.writeVarIntUTF8String(logincustompayload, tag);
	logincustompayload.writeBytes(data);
	codec.write(logincustompayload);
}
 
Example 7
Source File: MiddleClientSettings.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: MiddleJigsawUpdate.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToServer() {
	ServerBoundPacketData jigsawupdate = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_JIGSAW_UPDATE);
	PositionSerializer.writePosition(jigsawupdate, position);
	StringSerializer.writeVarIntUTF8String(jigsawupdate, name);
	StringSerializer.writeVarIntUTF8String(jigsawupdate, target);
	StringSerializer.writeVarIntUTF8String(jigsawupdate, pool);
	StringSerializer.writeVarIntUTF8String(jigsawupdate, finalState);
	StringSerializer.writeVarIntUTF8String(jigsawupdate, jointType);
	codec.read(jigsawupdate);
}
 
Example 9
Source File: Title.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	if (action != Action.SET_ACTION_BAR) {
		ClientBoundPacketData title = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_TITLE);
		int actionId = action.ordinal();
		VarNumberSerializer.writeVarInt(title, actionId > 2 ? actionId - 1 : actionId);
		switch (action) {
			case SET_TITLE:
			case SET_SUBTITLE: {
				StringSerializer.writeVarIntUTF8String(title, ChatAPI.toJSON(LegacyChatJson.convert(version, clientCache.getLocale(), message)));
				break;
			}
			case SET_TIMES: {
				title.writeInt(fadeIn);
				title.writeInt(stay);
				title.writeInt(fadeOut);
				break;
			}
			case HIDE:
			case RESET: {
				break;
			}
			default: {
				throw new EncoderException("Should not reach here");
			}
		}
		codec.write(title);
	} else {
		codec.write(Chat.create(MessagePosition.HOTBAR, LegacyChatJson.convert(version, clientCache.getLocale(), message)));
	}
}
 
Example 10
Source File: AbstractDeclareRecipes.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeRecipeData(ByteBuf to, ProtocolVersion version, SmeltingRecipe recipe) {
	StringSerializer.writeVarIntUTF8String(to, recipe.getGroup());
	writeIngredient(to, version, recipe.getIngredient());
	ItemStackSerializer.writeItemStack(to, version, I18NData.DEFAULT_LOCALE, recipe.getResult());
	to.writeFloat(recipe.getExp());
	VarNumberSerializer.writeVarInt(to, recipe.getTime());
}
 
Example 11
Source File: ClientLogin.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToServer() {
	ServerBoundPacketData setprotocol = ServerBoundPacketData.create(PacketType.SERVERBOUND_HANDSHAKE_START);
	VarNumberSerializer.writeVarInt(setprotocol, ProtocolVersionsHelper.LATEST_PC.getId());
	StringSerializer.writeVarIntUTF8String(setprotocol, hostname);
	setprotocol.writeShort(port);
	VarNumberSerializer.writeVarInt(setprotocol, 2);
	codec.read(setprotocol);

	ServerBoundPacketData loginstart = ServerBoundPacketData.create(PacketType.SERVERBOUND_LOGIN_START);
	StringSerializer.writeVarIntUTF8String(loginstart, username);
	codec.read(loginstart);
}
 
Example 12
Source File: Ping.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToServer() {
	ServerBoundPacketData setprotocol = ServerBoundPacketData.create(PacketType.SERVERBOUND_HANDSHAKE_START);
	VarNumberSerializer.writeVarInt(setprotocol, ProtocolVersionsHelper.LATEST_PC.getId());
	StringSerializer.writeVarIntUTF8String(setprotocol, "");
	setprotocol.writeShort(Bukkit.getPort());
	VarNumberSerializer.writeVarInt(setprotocol, 1);
	codec.read(setprotocol);

	codec.read(ServerBoundPacketData.create(PacketType.SERVERBOUND_STATUS_REQUEST));
}
 
Example 13
Source File: ResourcePack.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 14
Source File: MiddleSetProtocol.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToServer() {
	ServerBoundPacketData setprotocol = ServerBoundPacketData.create(PacketType.SERVERBOUND_HANDSHAKE_START);
	VarNumberSerializer.writeVarInt(setprotocol, ProtocolVersionsHelper.LATEST_PC.getId());
	StringSerializer.writeVarIntUTF8String(setprotocol, hostname);
	setprotocol.writeShort(port);
	VarNumberSerializer.writeVarInt(setprotocol, nextState);
	codec.read(setprotocol);
}
 
Example 15
Source File: MiddleCustomPayload.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ServerBoundPacketData create(String tag, byte[] data) {
	ServerBoundPacketData serializer = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_CUSTOM_PAYLOAD);
	StringSerializer.writeVarIntUTF8String(serializer, tag);
	serializer.writeBytes(data);
	return serializer;
}
 
Example 16
Source File: AbstractDeclareRecipes.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void writeRecipeData(ByteBuf to, ProtocolVersion version, ShapelessRecipe recipe) {
	StringSerializer.writeVarIntUTF8String(to, recipe.getGroup());
	ArraySerializer.writeVarIntTArray(to, recipe.getIngredients(), (lTo, ingredient) -> writeIngredient(lTo, version, ingredient));
	ItemStackSerializer.writeItemStack(to, version, I18NData.DEFAULT_LOCALE, recipe.getResult());
}
 
Example 17
Source File: CustomPayload.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ClientBoundPacketData create(String tag, Consumer<ByteBuf> dataWriter) {
	ClientBoundPacketData custompayload = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CUSTOM_PAYLOAD);
	StringSerializer.writeVarIntUTF8String(custompayload, tag);
	dataWriter.accept(custompayload);
	return custompayload;
}
 
Example 18
Source File: MiddleLoginStart.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void writeToServer() {
	ServerBoundPacketData loginstart = ServerBoundPacketData.create(PacketType.SERVERBOUND_LOGIN_START);
	StringSerializer.writeVarIntUTF8String(loginstart, name);
	codec.read(loginstart);
}
 
Example 19
Source File: Chat.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ClientBoundPacketData create(MessagePosition position, BaseComponent message) {
	ClientBoundPacketData chat = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHAT);
	StringSerializer.writeVarIntUTF8String(chat, ChatAPI.toJSON(message));
	MiscSerializer.writeByteEnum(chat, position);
	return chat;
}
 
Example 20
Source File: MiddleCustomPayload.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ServerBoundPacketData create(String tag) {
	ServerBoundPacketData serializer = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_CUSTOM_PAYLOAD);
	StringSerializer.writeVarIntUTF8String(serializer, tag);
	return serializer;
}