<commit_before>package protocolsupport.protocol.v_1_5.clientboundtransformer;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;
import java.util.zip.Deflater;

import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R1.util.CraftChatMessage;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;

import protocolsupport.protocol.DataStorage;
import protocolsupport.protocol.PacketDataSerializer;
import protocolsupport.protocol.v_1_5.remappers.BlockIDRemapper;
import protocolsupport.protocol.v_1_5.remappers.EntityIDRemapper;
import protocolsupport.protocol.watchedentites.WatchedEntity;
import protocolsupport.utils.Utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.EnumParticle;
import net.minecraft.server.v1_8_R1.ItemStack;
import net.minecraft.server.v1_8_R1.Packet;

public class PlayPacketTransformer implements PacketTransformer {

	@Override
	public void tranform(Channel channel, int packetId, Packet packet, PacketDataSerializer serializer) throws IOException {
		PacketDataSerializer packetdata = new PacketDataSerializer(Unpooled.buffer(), serializer.getVersion());
		packet.b(packetdata);
		switch (packetId) {
			case 0x00: { //PacketPlayOutKeepAlive
				serializer.writeByte(0x00);
				serializer.writeInt(packetdata.readVarInt());
				return;
			}
			case 0x01: { //PacketPlayOutLogin
				serializer.writeByte(0x01);
				int playerEnityId = packetdata.readInt();
				System.out.println(playerEnityId);
				DataStorage.addWatchedEntity(channel.remoteAddress(), new WatchedEntity(playerEnityId));
				serializer.writeInt(playerEnityId);
				int gamemode = packetdata.readByte();
				int dimension = packetdata.readByte();
				int difficulty = packetdata.readByte();
				int maxplayers = packetdata.readByte();
				serializer.writeString(packetdata.readString(32767));
				serializer.writeByte(gamemode);
				serializer.writeByte(dimension);
				serializer.writeByte(difficulty);
				serializer.writeByte(0);
				serializer.writeByte(Math.min(maxplayers, 60));
				return;
			}
			case 0x02: { //PacketPlayOutChat
				serializer.writeByte(0x03);
				serializer.writeString(CraftChatMessage.fromComponent(packetdata.d()));
				return;
			}
			case 0x03: { //PacketPlayOutUpdateTime
				serializer.writeByte(0x04);
				Utils.writeTheRestOfTheData(packetdata, serializer);
				return;
			}
			case 0x04: { //PacketPlayOutEntityEquipment
				serializer.writeByte(0x05);
				serializer.writeInt(packetdata.readVarInt());
				Utils.writeTheRestOfTheData(packetdata, serializer);
				return;
			}
			case 0x05: { //PacketPlayOutSpawnPosition
				serializer.writeByte(0x06);
				BlockPosition blockPos = packetdata.c();
				serializer.writeInt(blockPos.getX());
				serializer.writeInt(blockPos.getY() + 1);
				serializer.writeInt(blockPos.getZ());
				return;
			}
			case 0x06: { //PacketPlayOutUpdateHealth
				serializer.writeByte(0x08);
				serializer.writeShort((int) packetdata.readFloat());
				serializer.writeShort(packetdata.readVarInt());
				serializer.writeFloat(packetdata.readFloat());
				return;
			}
			case 0x07: { //PacketPlayOutRespawn
				serializer.writeByte(0x09);
				serializer.writeInt(packetdata.readInt());
				serializer.writeByte(packetdata.readByte());
				serializer.writeByte(packetdata.readByte());
				serializer.writeShort(256);
				Utils.writeTheRestOfTheData(packetdata, serializer);
				return;
			}
			case 0x08: { // PacketPlayOutPosition
				serializer.writeByte(0x0D);
				Player player = DataStorage.getPlayer(channel.remoteAddress());
				double x = packetdata.readDouble();
				double y = packetdata.readDouble() + 1.63;
				double z = packetdata.readDouble();
				float yaw = packetdata.readFloat();
				float pitch = packetdata.readFloat();
				short field = packetdata.readByte();
				Location location = player.getLocation();
				if ((field & 0x01) != 0) {
					x += location.getX();
				}
				if ((field & 0x02) != 0) {
					y += location.getY();
				}
				if ((field & 0x04) != 0) {
					z += location.getX();
				}
				if ((field & 0x08) != 0) {
					yaw += location.getYaw();
				}
				if ((field & 0x10) != 0) {
					pitch += location.getPitch();
				}
				serializer.writeDouble(x);
				serializer.writeDouble(y);
				serializer.writeDouble(y + 1.63);
				serializer.writeDouble(z);
				serializer.writeFloat(yaw);
				serializer.writeFloat(pitch);
				serializer.writeBoolean(false);
				return;
			}
			case 0x09: { //PacketPlayOutHeldItemSlot
				serializer.writeByte(0x10);
				serializer.writeShort(packetdata.readByte());
				return;
			}
			case 0x0A: { //PacketPlayOutBed
				serializer.writeByte(0x11);
				serializer.writeInt(packetdata.readVarInt());
				serializer.writeByte(0);
				BlockPosition blockPos = packetdata.c();
				serializer.writeInt(blockPos.getX());
				serializer.writeByte(blockPos.getY());
				serializer.writeInt(blockPos.getZ());
				return;
			}
			case 0x0B: { //PacketPlayOutAnimation
				serializer.writeByte(0x12);
				serializer.writeInt(packetdata.readVarInt());
				serializer.writeByte(packetdata.readByte());
				return;
			}
			case 0x0C: { //PacketPlayOutNamedEntitySpawn
				serializer.writeByte(0x14);
				serializer.writeInt(packetdata.readVarInt());
				UUID uuid = packetdata.g();
				String playerName = DataStorage.getTabName(channel.remoteAddress(), uuid);
				serializer.writeString(playerName != null ? playerName : "Unknown");
				serializer.writeInt(packetdata.readInt());
				serializer.writeInt(packetdata.readInt());
				serializer.writeInt(packetdata.readInt());
				serializer.writeByte(packetdata.readByte());
				serializer.writeByte(packetdata.readByte());
				serializer.writeShort(packetdata.readShort());
				Utils.writeTheRestOfTheData(packetdata, serializer);
				return;
			}
			case 0x0D: { //PacketPlayOutCollect
				serializer.writeByte(0x16);
				serializer.writeInt(packetdata.readVarInt());
				serializer.writeInt(packetdata.readVarInt());
				return;
			}
			case 0x0E: { //PacketPlayOutSpawnEntity
				serializer.writeByte(0x17);
				int entityId = packetdata.readVarInt();
				serializer.writeInt(entityId);<commit_msg>Forgot about other players<commit_after>package protocolsupport.protocol.v_1_5.clientboundtransformer;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;
import java.util.zip.Deflater;

import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R1.util.CraftChatMessage;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;

import protocolsupport.protocol.DataStorage;
import protocolsupport.protocol.PacketDataSerializer;
import protocolsupport.protocol.v_1_5.remappers.BlockIDRemapper;
import protocolsupport.protocol.v_1_5.remappers.EntityIDRemapper;
import protocolsupport.protocol.watchedentites.WatchedEntity;
import protocolsupport.utils.Utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.EnumParticle;
import net.minecraft.server.v1_8_R1.ItemStack;
import net.minecraft.server.v1_8_R1.Packet;

public class PlayPacketTransformer implements PacketTransformer {

	@Override
	public void tranform(Channel channel, int packetId, Packet packet, PacketDataSerializer serializer) throws IOException {
		PacketDataSerializer packetdata = new PacketDataSerializer(Unpooled.buffer(), serializer.getVersion());
		packet.b(packetdata);
		switch (packetId) {
			case 0x00: { //PacketPlayOutKeepAlive
				serializer.writeByte(0x00);
				serializer.writeInt(packetdata.readVarInt());
				return;
			}
			case 0x01: { //PacketPlayOutLogin
				serializer.writeByte(0x01);
				int playerEnityId = packetdata.readInt();
				DataStorage.addWatchedEntity(channel.remoteAddress(), new WatchedEntity(playerEnityId));
				serializer.writeInt(playerEnityId);
				int gamemode = packetdata.readByte();
				int dimension = packetdata.readByte();
				int difficulty = packetdata.readByte();
				int maxplayers = packetdata.readByte();
				serializer.writeString(packetdata.readString(32767));
				serializer.writeByte(gamemode);
				serializer.writeByte(dimension);
				serializer.writeByte(difficulty);
				serializer.writeByte(0);
				serializer.writeByte(Math.min(maxplayers, 60));
				return;
			}
			case 0x02: { //PacketPlayOutChat
				serializer.writeByte(0x03);
				serializer.writeString(CraftChatMessage.fromComponent(packetdata.d()));
				return;
			}
			case 0x03: { //PacketPlayOutUpdateTime
				serializer.writeByte(0x04);
				Utils.writeTheRestOfTheData(packetdata, serializer);
				return;
			}
			case 0x04: { //PacketPlayOutEntityEquipment
				serializer.writeByte(0x05);
				serializer.writeInt(packetdata.readVarInt());
				Utils.writeTheRestOfTheData(packetdata, serializer);
				return;
			}
			case 0x05: { //PacketPlayOutSpawnPosition
				serializer.writeByte(0x06);
				BlockPosition blockPos = packetdata.c();
				serializer.writeInt(blockPos.getX());
				serializer.writeInt(blockPos.getY() + 1);
				serializer.writeInt(blockPos.getZ());
				return;
			}
			case 0x06: { //PacketPlayOutUpdateHealth
				serializer.writeByte(0x08);
				serializer.writeShort((int) packetdata.readFloat());
				serializer.writeShort(packetdata.readVarInt());
				serializer.writeFloat(packetdata.readFloat());
				return;
			}
			case 0x07: { //PacketPlayOutRespawn
				serializer.writeByte(0x09);
				serializer.writeInt(packetdata.readInt());
				serializer.writeByte(packetdata.readByte());
				serializer.writeByte(packetdata.readByte());
				serializer.writeShort(256);
				Utils.writeTheRestOfTheData(packetdata, serializer);
				return;
			}
			case 0x08: { // PacketPlayOutPosition
				serializer.writeByte(0x0D);
				Player player = DataStorage.getPlayer(channel.remoteAddress());
				double x = packetdata.readDouble();
				double y = packetdata.readDouble() + 1.63;
				double z = packetdata.readDouble();
				float yaw = packetdata.readFloat();
				float pitch = packetdata.readFloat();
				short field = packetdata.readByte();
				Location location = player.getLocation();
				if ((field & 0x01) != 0) {
					x += location.getX();
				}
				if ((field & 0x02) != 0) {
					y += location.getY();
				}
				if ((field & 0x04) != 0) {
					z += location.getX();
				}
				if ((field & 0x08) != 0) {
					yaw += location.getYaw();
				}
				if ((field & 0x10) != 0) {
					pitch += location.getPitch();
				}
				serializer.writeDouble(x);
				serializer.writeDouble(y);
				serializer.writeDouble(y + 1.63);
				serializer.writeDouble(z);
				serializer.writeFloat(yaw);
				serializer.writeFloat(pitch);
				serializer.writeBoolean(false);
				return;
			}
			case 0x09: { //PacketPlayOutHeldItemSlot
				serializer.writeByte(0x10);
				serializer.writeShort(packetdata.readByte());
				return;
			}
			case 0x0A: { //PacketPlayOutBed
				serializer.writeByte(0x11);
				serializer.writeInt(packetdata.readVarInt());
				serializer.writeByte(0);
				BlockPosition blockPos = packetdata.c();
				serializer.writeInt(blockPos.getX());
				serializer.writeByte(blockPos.getY());
				serializer.writeInt(blockPos.getZ());
				return;
			}
			case 0x0B: { //PacketPlayOutAnimation
				serializer.writeByte(0x12);
				serializer.writeInt(packetdata.readVarInt());
				serializer.writeByte(packetdata.readByte());
				return;
			}
			case 0x0C: { //PacketPlayOutNamedEntitySpawn
				serializer.writeByte(0x14);
				int playerEntityId = packetdata.readVarInt();
				DataStorage.addWatchedEntity(channel.remoteAddress(), new WatchedEntity(playerEntityId));
				serializer.writeInt(playerEntityId);
				UUID uuid = packetdata.g();
				String playerName = DataStorage.getTabName(channel.remoteAddress(), uuid);
				serializer.writeString(playerName != null ? playerName : "Unknown");
				serializer.writeInt(packetdata.readInt());
				serializer.writeInt(packetdata.readInt());
				serializer.writeInt(packetdata.readInt());
				serializer.writeByte(packetdata.readByte());
				serializer.writeByte(packetdata.readByte());
				serializer.writeShort(packetdata.readShort());
				serializer.writeBytes(DataWatcherFilter.filterEntityData(serializer.getVersion(), DataStorage.getWatchedEntity(channel.remoteAddress(), playerEntityId), packetdata.readBytes(packetdata.readableBytes()).array()));
				return;
			}
			case 0x0D: { //PacketPlayOutCollect
				serializer.writeByte(0x16);
				serializer.writeInt(packetdata.readVarInt());
				serializer.writeInt(packetdata.readVarInt());
				return;
			}
			case 0x0E: { //PacketPlayOutSpawnEntity
				serializer.writeByte(0x17);
				int entityId = packetdata.readVarInt();
				serializer.writeInt(entityId);
{'fraction_non_alphanumeric': 0.12138593907449034, 'fraction_numerical': 0.022323850864274086, 'mean_word_length': 4.460008463817181, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2501496', 'n_tokens_mistral': 5083, 'n_tokens_neox': 4129, 'n_words': 603}