Java Code Examples for protocolsupport.api.ProtocolVersion

The following examples show how to use protocolsupport.api.ProtocolVersion. 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
public int getPlayerProtocol(UUID playerId) {
    Player player = getServer().getPlayer(playerId);
    if (player != null) {
        int protocol = serverProtocolVersion;
        if (viaApi != null) {
            protocol = viaApi.getPlayerVersion(playerId);
        }
        if (protocolSupportApi && protocol == serverProtocolVersion) { // if still same format test if player is using previous version
            ProtocolVersion version = ProtocolSupportAPI.getProtocolVersion(player);
            if (version.getProtocolType() == ProtocolType.PC) {
                protocol = version.getId();
            }
        }
        return protocol;
    }
    return -1;
}
 
Example 2
protected void setProtocol(Channel channel, ProtocolVersion version) {
	ConnectionImpl connection = prepare(channel, version);
	IPipeLineBuilder builder = InitialPacketDecoder.BUILDERS.get(connection.getVersion());
	builder.buildBungeeClientCodec(channel, connection);
	if (encapsulatedinfo == null) {
		builder.buildBungeeClientPipeLine(channel, connection);
	} else {
		ChannelPipeline pipeline = channel.pipeline();
		pipeline.replace(PipelineUtils.FRAME_DECODER, PipelineUtils.FRAME_DECODER, new VarIntFrameDecoder());
		if (encapsulatedinfo.hasCompression()) {
			pipeline.addAfter(PipelineUtils.FRAME_DECODER, "decompress", new PacketDecompressor());
			pipeline.addAfter(PipelineUtils.FRAME_PREPENDER, "compress", new PacketCompressor(256));
		}
		if ((encapsulatedinfo.getAddress() != null) && connection.getRawAddress().getAddress().isLoopbackAddress()) {
			connection.changeAddress(encapsulatedinfo.getAddress());
		}
	}
	buffer.readerIndex(0);
	channel.pipeline().firstContext().fireChannelRead(buffer.unwrap());
}
 
Example 3
@Override
protected void writeToClient() {
	ClientBoundPacketData startgame = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_START_GAME);
	startgame.writeInt(player.getId());
	startgame.writeByte(gamemodeCurrent.getId() | (hardcore ? 0x8 : 0));
	if (version.isBefore(ProtocolVersion.MINECRAFT_1_9_1)) {
		startgame.writeByte(LegacyDimension.getId(dimension));
	} else {
		startgame.writeInt(LegacyDimension.getId(dimension));
	}
	MiscSerializer.writeByteEnum(startgame, Difficulty.HARD);
	startgame.writeByte(maxplayers);
	StringSerializer.writeVarIntUTF8String(startgame, "default");
	startgame.writeBoolean(reducedDebugInfo);
	codec.write(startgame);
}
 
Example 4
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
	Player player = event.getPlayer();
	Connection connection = ProtocolSupportAPI.getConnection(player);
	if (
		(connection != null) &&
		(connection.getVersion().getProtocolType() == ProtocolType.PC) &&
		connection.getVersion().isBefore(ProtocolVersion.MINECRAFT_1_9)
	) {
		BlockDataEntry blockdataentry = MinecraftBlockData.get(MaterialAPI.getBlockDataNetworkId(event.getBlock().getBlockData()));
		player.playSound(
			event.getBlock().getLocation(),
			blockdataentry.getBreakSound(),
			SoundCategory.BLOCKS,
			(blockdataentry.getVolume() + 1.0F) / 2.0F,
			blockdataentry.getPitch() * 0.8F
		);
	}
}
 
Example 5
protected static ConnectionImpl prepare(Channel channel, ProtocolVersion version) {
	channel.pipeline().remove(ChannelHandlers.INITIAL_DECODER);
	ConnectionImpl connection = ConnectionImpl.getFromChannel(channel);
	if (ServerPlatform.get().getMiscUtils().isDebugging()) {
		ProtocolSupport.logInfo(MessageFormat.format("{0} connected with protocol version {1}", connection.getAddress(), version));
	}
	connection.getNetworkManagerWrapper().setPacketListener(ServerPlatform.get().getMiscUtils().createHandshakeListener(connection.getNetworkManagerWrapper()));
	if (!ProtocolSupportAPI.isProtocolVersionEnabled(version)) {
		if (version.getProtocolType() == ProtocolType.PC) {
			version = version.isBeforeOrEq(ProtocolVersion.MINECRAFT_1_6_4) ? ProtocolVersion.MINECRAFT_LEGACY : ProtocolVersion.MINECRAFT_FUTURE;
		} else {
			throw new IllegalArgumentException(MessageFormat.format("Unable to get legacy or future version for disabled protocol version {0}", version));
		}
	}
	connection.setVersion(version);
	return connection;
}
 
Example 6
protected static NetworkItemStack remapComplex(
	Int2ObjectOpenHashMap<EnumMap<ProtocolVersion, List<ItemStackComplexRemapper>>> registry,
	ProtocolVersion version, String locale,
	NetworkItemStack itemstack
) {
	EnumMap<ProtocolVersion, List<ItemStackComplexRemapper>> map = registry.get(itemstack.getTypeId());
	if (map != null) {
		List<ItemStackComplexRemapper> transformers = map.get(version);
		if (transformers != null) {
			for (ItemStackComplexRemapper transformer : transformers) {
				itemstack = transformer.remap(version, locale, itemstack);
			}
		}
	}
	return itemstack;
}
 
Example 7
protected WolfEntityMetadataRemapper() {
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.Wolf.BEGGING, 18), ProtocolVersionsHelper.UP_1_15);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.Wolf.BEGGING, 18), ProtocolVersionsHelper.ALL_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.Wolf.BEGGING, 16), ProtocolVersionsHelper.RANGE__1_11__1_13_2);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.Wolf.BEGGING, 16), ProtocolVersion.MINECRAFT_1_10);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.Wolf.BEGGING, 15), ProtocolVersionsHelper.ALL_1_9);
	addRemap(new IndexValueRemapperBooleanToByte(NetworkEntityMetadataObjectIndex.Wolf.BEGGING, 19), ProtocolVersionsHelper.DOWN_1_8);

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.Wolf.COLLAR_COLOR, 19), ProtocolVersionsHelper.UP_1_15);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.Wolf.COLLAR_COLOR, 19), ProtocolVersionsHelper.ALL_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.Wolf.COLLAR_COLOR, 17), ProtocolVersionsHelper.ALL_1_13);
	addRemap(new VarIntWolfCollarColorIndexValueRemapper(17), ProtocolVersionsHelper.RANGE__1_10__1_12_2);
	addRemap(new VarIntWolfCollarColorIndexValueRemapper(16), ProtocolVersionsHelper.ALL_1_9);
	addRemap(new IndexValueRemapper<NetworkEntityMetadataObjectVarInt>(NetworkEntityMetadataObjectIndex.Wolf.COLLAR_COLOR, 20) {
		@Override
		public NetworkEntityMetadataObject<?> remapValue(NetworkEntityMetadataObjectVarInt object) {
			return new NetworkEntityMetadataObjectByte((byte) (15 - object.getValue()));
		}
	}, ProtocolVersion.MINECRAFT_1_8);
	addRemap(new IndexValueRemapperNumberToByte(NetworkEntityMetadataObjectIndex.Wolf.COLLAR_COLOR, 20), ProtocolVersionsHelper.DOWN_1_7_10);
}
 
Example 8
@Override
public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) {
	int data = itemstack.getLegacyData();
	String name = LegacyPotionId.fromLegacyId(data);
	if (!StringUtils.isEmpty(name)) {
		NBTCompound tag = CommonNBT.getOrCreateRootTag(itemstack);
		tag.setTag(CommonNBT.POTION_TYPE, new NBTString(name));
		itemstack.setTypeId(ItemMaterialLookup.getRuntimeId(LegacyPotionId.isThrowable(data) ? Material.SPLASH_POTION : Material.POTION));
	}
	return itemstack;
}
 
Example 9
@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
@Override
public void readFromClientData(ConnectionImpl connection, ByteBuf clientdata) {
	ProtocolVersion version = connection.getVersion();
	uuid = MiscSerializer.readUUID(clientdata);
	skinId = StringSerializer.readString(clientdata, version);
	skinName = StringSerializer.readString(clientdata, version);
	previousName = StringSerializer.readString(clientdata, version);
	skinData = ArraySerializer.readVarIntByteArray(clientdata);
	capeData = ArraySerializer.readVarIntByteArray(clientdata);
	geometryId = StringSerializer.readString(clientdata, version);
	geometryData = StringSerializer.readString(clientdata, version);
	clientdata.readBoolean();
}
 
Example 11
@Override
public BaseComponent convert(ProtocolVersion version, String locale, BaseComponent component) {
	if (component instanceof TranslateComponent) {
		TranslateComponent tcomponent = (TranslateComponent) component;
		List<BaseComponent> tlargs = tcomponent.getTranslationArgs();
		BaseComponent rootcomponent = cloneComponentAuxData(tcomponent, new TextComponent(""));
		String translation = TranslationAPI.getTranslationString(locale, tcomponent.getTranslationKey());
		Matcher matcher = langFormat.matcher(translation);
		int index = 0;
		int tlargindex = 0;
		while (matcher.find()) {
			rootcomponent.addSibling(new TextComponent(translation.substring(index, matcher.start())));
			index = matcher.end();
			if (matcher.group(2).equals("%")) {
				rootcomponent.addSibling(new TextComponent("%"));
			} else if (matcher.group(2).equals("s")) {
				int ltlargindex = tlargindex;
				if (!matcher.group(1).isEmpty()) {
					ltlargindex = Integer.parseInt(matcher.group(1)) - 1;
				}
				if (tlargindex < tlargs.size()) {
					rootcomponent.addSibling(tlargs.get(ltlargindex));
				} else {
					rootcomponent.addSibling(new TextComponent("[Invalid traslation argument index]"));
				}
			}
			tlargindex++;
		}
		rootcomponent.addSibling(new TextComponent(translation.substring(index)));
		return rootcomponent;
	}
	return component;
}
 
Example 12
@Override
public void handleReadData() {
	//TODO: send needed collect packets from middle packet itself after implementing serverside entity position cache
	if (
		(collectorId == cache.getEntityCache().getSelfId()) &&
		(version.getProtocolType() == ProtocolType.PC) &&
		version.isBefore(ProtocolVersion.MINECRAFT_1_9)
	) {
		Player player = connection.getPlayer();
		NetworkEntity entity = cache.getEntityCache().getEntity(entityId);
		if ((entity != null) && (player != null)) {
			switch (entity.getType()) {
				case ITEM: {
					player.playSound(
						player.getLocation(), Sound.ENTITY_ITEM_PICKUP,
						0.2F, (((ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.7F) + 1.0F) * 2.0F
					);
					break;
				}
				case EXP_ORB: {
					player.playSound(
						player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,
						0.2F, (((ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.7F) + 1.0F) * 2.0F
					);
					break;
				}
				default: {
					break;
				}
			}
		}
	}
}
 
Example 13
protected static ProtocolVersion readNewHandshake(ByteBuf data) {
	int packetId = VarNumberSerializer.readVarInt(data);
	if (packetId == 0x00) {
		return ProtocolVersionsHelper.getNewProtocolVersion(VarNumberSerializer.readVarInt(data));
	} else {
		throw new DecoderException(packetId + " is not a valid packet id");
	}
}
 
Example 14
@Override
protected void readClientData(ByteBuf clientdata) {
	entityId = VarNumberSerializer.readVarInt(clientdata);
	int actionId = VarNumberSerializer.readVarInt(clientdata);
	jumpBoost = VarNumberSerializer.readVarInt(clientdata);
	if (version == ProtocolVersion.MINECRAFT_1_8) {
		action = actionById8.get(actionId);
	} else {
		action = Action.CONSTANT_LOOKUP.getByOrdinal(actionId);
	}
}
 
Example 15
protected static ClientBoundPacketData create(ProtocolVersion version, String locale, byte windowId, int slot, NetworkItemStack itemstack) {
	ClientBoundPacketData windowslot = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WINDOW_SET_SLOT);
	windowslot.writeByte(windowId);
	windowslot.writeShort(slot);
	ItemStackSerializer.writeItemStack(windowslot, version, locale, itemstack);
	return windowslot;
}
 
Example 16
@Test
public void testIsBetween() {
	Assertions.assertTrue(ProtocolVersion.MINECRAFT_1_6_4.isBetween(ProtocolVersion.MINECRAFT_1_4_7, ProtocolVersion.MINECRAFT_1_7_10));
	Assertions.assertTrue(ProtocolVersion.MINECRAFT_1_6_4.isBetween(ProtocolVersion.MINECRAFT_1_6_4, ProtocolVersion.MINECRAFT_1_7_10));
	Assertions.assertTrue(ProtocolVersion.MINECRAFT_1_6_4.isBetween(ProtocolVersion.MINECRAFT_1_4_7, ProtocolVersion.MINECRAFT_1_6_4));
	Assertions.assertFalse(ProtocolVersion.MINECRAFT_1_6_4.isBetween(ProtocolVersion.MINECRAFT_1_7_5, ProtocolVersion.MINECRAFT_1_9));
}
 
Example 17
public static ClientBoundPacketData create(
	ProtocolVersion version, String locale,
	int entityId, Slot slot, NetworkItemStack itemstack
) {
	ClientBoundPacketData entityequipment = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_ENTITY_EQUIPMENT);
	VarNumberSerializer.writeVarInt(entityequipment, entityId);
	MiscSerializer.writeVarIntEnum(entityequipment, slot);
	ItemStackSerializer.writeItemStack(entityequipment, version, locale, itemstack);
	return entityequipment;
}
 
Example 18
protected LivingEntityMetadataRemapper() {
	addRemap(new IndexValueRemapperOptionalChatToString(NetworkEntityMetadataObjectIndex.Entity.NAMETAG, 10), ProtocolVersionsHelper.ALL_1_7);
	addRemap(new IndexValueRemapperOptionalChatToString(NetworkEntityMetadataObjectIndex.Entity.NAMETAG, 10, 64), ProtocolVersionsHelper.ALL_1_6);
	addRemap(new IndexValueRemapperOptionalChatToString(NetworkEntityMetadataObjectIndex.Entity.NAMETAG, 5, 64), ProtocolVersionsHelper.DOWN_1_5_2);

	addRemap(new IndexValueRemapperBooleanToByte(NetworkEntityMetadataObjectIndex.Entity.NAMETAG_VISIBLE, 11), ProtocolVersionsHelper.RANGE__1_6__1_7);
	addRemap(new IndexValueRemapperBooleanToByte(NetworkEntityMetadataObjectIndex.Entity.NAMETAG_VISIBLE, 6), ProtocolVersionsHelper.DOWN_1_5_2);

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.HAND_USE, 7), ProtocolVersionsHelper.UP_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.HAND_USE, 6), ProtocolVersionsHelper.RANGE__1_10__1_13_2);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.HAND_USE, 5), ProtocolVersionsHelper.ALL_1_9);

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.HEALTH, 8), ProtocolVersionsHelper.UP_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.HEALTH, 7), ProtocolVersionsHelper.RANGE__1_10__1_13_2);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.HEALTH, 6), ProtocolVersion.getAllBetween(ProtocolVersion.MINECRAFT_1_9_4, ProtocolVersion.MINECRAFT_1_6_1));

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_COLOR, 9), ProtocolVersionsHelper.UP_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_COLOR, 8), ProtocolVersionsHelper.RANGE__1_10__1_13_2);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_COLOR, 7), ProtocolVersionsHelper.ALL_1_9);
	addRemap(new IndexValueRemapperNumberToInt(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_COLOR, 7), ProtocolVersionsHelper.RANGE__1_6__1_8);
	addRemap(new IndexValueRemapperNumberToInt(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_COLOR, 8), ProtocolVersionsHelper.DOWN_1_5_2);

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_AMBIENT, 10), ProtocolVersionsHelper.UP_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_AMBIENT, 9), ProtocolVersionsHelper.RANGE__1_10__1_13_2);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_AMBIENT, 8), ProtocolVersionsHelper.ALL_1_9);
	addRemap(new IndexValueRemapperBooleanToByte(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_AMBIENT, 8), ProtocolVersionsHelper.RANGE__1_6__1_8);
	addRemap(new IndexValueRemapperBooleanToByte(NetworkEntityMetadataObjectIndex.EntityLiving.POTION_AMBIENT, 9), ProtocolVersionsHelper.DOWN_1_5_2);

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.ARROWS_IN, 11), ProtocolVersionsHelper.UP_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.ARROWS_IN, 10), ProtocolVersionsHelper.RANGE__1_10__1_13_2);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.ARROWS_IN, 9), ProtocolVersionsHelper.ALL_1_9);
	addRemap(new IndexValueRemapperNumberToByte(NetworkEntityMetadataObjectIndex.EntityLiving.ARROWS_IN, 9), ProtocolVersionsHelper.RANGE__1_6__1_8);
	addRemap(new IndexValueRemapperNumberToByte(NetworkEntityMetadataObjectIndex.EntityLiving.ARROWS_IN, 10), ProtocolVersionsHelper.DOWN_1_5_2);

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.ABSORBTION_HEALTH, 12), ProtocolVersionsHelper.UP_1_15);

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.BED_LOCATION, 13), ProtocolVersionsHelper.UP_1_15);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.EntityLiving.BED_LOCATION, 12), ProtocolVersionsHelper.ALL_1_14);
}
 
Example 19
@Override
protected void writeToClient() {
	ClientBoundPacketData timeupdate = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_UPDATE_TIME);
	if (version.isBeforeOrEq(ProtocolVersion.MINECRAFT_1_5_2)) {
		timeOfDay = Math.abs(timeOfDay);
	}
	timeupdate.writeLong(worldAge);
	timeupdate.writeLong(timeOfDay);
	codec.write(timeupdate);
}
 
Example 20
protected static void register(TileEntityType type, Consumer<TileEntity> transformer, ProtocolVersion... versions) {
	for (ProtocolVersion version : versions) {
		tileEntityRemappers.get(version).tileToTile
		.computeIfAbsent(type, k -> new ArrayList<>())
		.add((tile, blockdata) -> transformer.accept(tile));
	}
}
 
Example 21
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 22
@Override
public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) {
	itemstack.setTypeId(ItemMaterialLookup.getRuntimeId(Material.PLAYER_HEAD));
	NBTCompound wrapper = new NBTCompound();
	wrapper.setTag("SkullOwner", createTag());
	itemstack.setNBT(wrapper);
	return itemstack;
}
 
Example 23
public static void callEvent(ProtocolVersion version, String locale, NetworkItemStack itemstack) {
	if (ItemStackWriteEvent.getHandlerList().getRegisteredListeners().length > 0) {
		ItemStackWriteEvent event = new ItemStackWriteEvent(version, locale, new WrappedNetworkItemStack(itemstack));
		Bukkit.getPluginManager().callEvent(event);
		List<String> additionalLore = event.getAdditionalLore();
		BaseComponent forcedDisplayName = event.getForcedDisplayName();
		if ((forcedDisplayName != null) || !additionalLore.isEmpty()) {
			NBTCompound rootTag = CommonNBT.getOrCreateRootTag(itemstack);
			NBTCompound displayNBT = CommonNBT.getOrCreateDisplayTag(rootTag);

			if (forcedDisplayName != null) {
				displayNBT.setTag(CommonNBT.DISPLAY_NAME, new NBTString(ChatAPI.toJSON(LegacyChatJson.convert(version, locale, forcedDisplayName))));
			}

			if (!additionalLore.isEmpty()) {
				NBTList<NBTString> loreNBT = displayNBT.getTagListOfType(CommonNBT.DISPLAY_LORE, NBTType.STRING);
				if (loreNBT == null) {
					loreNBT = new NBTList<>(NBTType.STRING);
				}
				for (String lore : additionalLore) {
					loreNBT.addTag(new NBTString(ChatAPI.toJSON(new TextComponent(lore))));
				}
				displayNBT.setTag(CommonNBT.DISPLAY_LORE, loreNBT);
			}
		}
	}
}
 
Example 24
@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 25
public Function<ByteBuf, T> get(ProtocolVersion version) {
	Function<ByteBuf, T> serializer = entries.get(version);
	if (serializer == null) {
		throw new IllegalArgumentException(MessageFormat.format("Don''t know how to deserialize type for protocol version {0}", version));
	}
	return entries.get(version);
}
 
Example 26
@Override
public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) {
	NBTNumber mapId;
	if ((itemstack.getNBT() != null) && ((mapId = itemstack.getNBT().getNumberTag(CommonNBT.MAP_ID)) != null)) {
		itemstack.setLegacyData(mapId.getAsInt());
	}
	return itemstack;
}
 
Example 27
public BiConsumer<ByteBuf, T> get(ProtocolVersion version) {
	BiConsumer<ByteBuf, T> serializer = entries.get(version);
	if (serializer == null) {
		throw new IllegalArgumentException(MessageFormat.format("Don''t know how to serialize type for protocol version {0}", version));
	}
	return entries.get(version);
}
 
Example 28
protected BattleHorseEntityMetadataRemapper() {
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.VARIANT, 18), ProtocolVersionsHelper.UP_1_15);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.VARIANT, 17), ProtocolVersionsHelper.ALL_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.VARIANT, 15), ProtocolVersionsHelper.RANGE__1_10__1_13_2);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.VARIANT, 14), ProtocolVersionsHelper.ALL_1_9);
	addRemap(new IndexValueRemapperNumberToInt(NetworkEntityMetadataObjectIndex.BattleHorse.VARIANT, 20), ProtocolVersionsHelper.DOWN_1_8);

	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.ARMOR, 19), ProtocolVersionsHelper.UP_1_15);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.ARMOR, 18), ProtocolVersionsHelper.ALL_1_14);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.ARMOR, 16), ProtocolVersionsHelper.RANGE__1_10__1_13_2);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.ARMOR, 17), ProtocolVersion.MINECRAFT_1_10);
	addRemap(new IndexValueRemapperNoOp(NetworkEntityMetadataObjectIndex.BattleHorse.ARMOR, 16), ProtocolVersionsHelper.ALL_1_9);
	addRemap(new IndexValueRemapperNumberToInt(NetworkEntityMetadataObjectIndex.BattleHorse.ARMOR, 22), ProtocolVersionsHelper.DOWN_1_8);
}
 
Example 29
@EventHandler
public void onShift(PlayerToggleSneakEvent event) {
	Player player = event.getPlayer();
	Connection connection = ProtocolSupportAPI.getConnection(player);
	if (
		player.isInsideVehicle() &&
		(connection != null) &&
		(connection.getVersion().getProtocolType() == ProtocolType.PC) &&
		connection.getVersion().isBeforeOrEq(ProtocolVersion.MINECRAFT_1_5_2)
	) {
		player.leaveVehicle();
	}
}
 
Example 30
public static int getTypeId(@SuppressWarnings("rawtypes") Class<? extends NetworkEntityMetadataObject> clazz, ProtocolVersion version) {
	EnumMap<ProtocolVersion, Integer> mmap = registry.get(clazz);
	if (mmap == null) {
		throw new IllegalStateException(MessageFormat.format("No type id registry exists for object {0}", clazz));
	}
	Integer id = mmap.get(version);
	if (id == null) {
		throw new IllegalArgumentException(MessageFormat.format("No type id exists for object {0} for protocol version {1}", clazz, version));
	}
	return id;
}