diff --git a/proxy/src/main/java/proxy/Proxy.java b/proxy/src/main/java/proxy/Proxy.java index 8c85b62..bfa25d6 100755 --- a/proxy/src/main/java/proxy/Proxy.java +++ b/proxy/src/main/java/proxy/Proxy.java @@ -27,7 +27,6 @@ import java.io.File; import java.io.IOException; import java.net.IDN; import java.net.InetAddress; -import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -43,6 +42,7 @@ import java.util.concurrent.FutureTask; import javax.imageio.ImageIO; import com.google.common.base.Charsets; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Queues; import com.google.common.util.concurrent.Futures; @@ -58,15 +58,17 @@ import proxy.network.MessageSerializer2; import proxy.network.NetHandlerHandshake; import proxy.network.NetHandlerPlayServer; import proxy.network.NetworkManager; -import proxy.network.ServerStatusResponse; import proxy.network.ThreadQuickExitException; import proxy.packet.play.server.S40PacketDisconnect; import proxy.util.ChatColor; import proxy.util.ChatComponentText; -import proxy.util.GameProfile; +import proxy.util.Profile; +import proxy.util.ServerInfo; import proxy.util.User; +import proxy.util.VersionId; import proxy.util.LazyLoadBase; import proxy.util.Log; +import proxy.util.PlayerInfo; public class Proxy { public static final LazyLoadBase NIO_EVENT_LOOP = new LazyLoadBase() { @@ -83,8 +85,8 @@ public class Proxy { private volatile boolean isAlive; private volatile boolean running = true; - private final List endpoints = Collections.synchronizedList(new ArrayList()); - private final List networkManagers = Collections.synchronizedList(new ArrayList()); + private final List endpoints = Collections.synchronizedList(Lists.newArrayList()); + private final List networkManagers = Collections.synchronizedList(Lists.newArrayList()); private final Queue> futureTaskQueue = Queues.>newArrayDeque(); private final Map users = Maps.newHashMap(); private final Map players = Maps.newHashMap(); @@ -100,10 +102,10 @@ public class Proxy { private int proxyPort = 25566; private int minPassLength = 8; private int maxAttempts = 5; - private ServerStatusResponse status = getStatus(new File("icon.png"), ChatColor.AQUA + "Server\n" + ChatColor.GREEN + "Test!!", 90, 10, "Test1", + private ServerInfo status = getStatus(new File("icon.png"), ChatColor.AQUA + "Server\n" + ChatColor.GREEN + "Test!!", 90, 10, "Test1", "Test2 ...", "Test #3 !!"); - private static void addFaviconToStatusResponse(ServerStatusResponse info, File file) { + private static void addFaviconToStatusResponse(ServerInfo info, File file) { if(file.isFile()) { ByteBuf buf = Unpooled.buffer(); try { @@ -112,7 +114,7 @@ public class Proxy { throw new IllegalArgumentException("Icon must be 64x64 pixels"); ImageIO.write(img, "PNG", new ByteBufOutputStream(buf)); ByteBuf base64 = Base64.encode(buf); - info.setFavicon("data:image/png;base64," + base64.toString(Charsets.UTF_8)); + info.setIcon("data:image/png;base64," + base64.toString(Charsets.UTF_8)); } catch(Exception e) { Log.error(e, "Couldn't load server icon"); @@ -123,17 +125,17 @@ public class Proxy { } } - public static ServerStatusResponse getStatus(File icon, String motd, int max, int current, String... lines) { - ServerStatusResponse info = new ServerStatusResponse(); - info.setServerDescription(new ChatComponentText(motd)); - info.setProtocolVersionInfo(new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.8.9", 47)); + public static ServerInfo getStatus(File icon, String motd, int max, int current, String... lines) { + ServerInfo info = new ServerInfo(); + info.setMotd(new ChatComponentText(motd)); + info.setVersion(new VersionId("1.8.9", 47)); addFaviconToStatusResponse(info, icon); - info.setPlayerCountData(new ServerStatusResponse.PlayerCountData(max, current)); - GameProfile[] profiles = new GameProfile[Math.min(lines.length, 12)]; + info.setInfo(new PlayerInfo(max, current)); + Profile[] profiles = new Profile[Math.min(lines.length, 12)]; for(int z = 0; z < profiles.length; z++) { - profiles[z] = new GameProfile(Proxy.getOfflineUUID(lines[z]), lines[z]); + profiles[z] = new Profile(Proxy.getOfflineUUID(lines[z]), lines[z]); } - info.getPlayerCountData().setPlayers(profiles); + info.getInfo().setList(profiles); return info; } @@ -282,7 +284,7 @@ public class Proxy { } private ListenableFuture callFromMainThread(Callable callable) { - if(!this.isCallingFromMinecraftThread()) { + if(!this.isMainThread()) { ListenableFutureTask task = ListenableFutureTask.create(callable); synchronized(this.futureTaskQueue) { @@ -304,7 +306,7 @@ public class Proxy { this.callFromMainThread(Executors.callable(task)); } - public boolean isCallingFromMinecraftThread() { + public boolean isMainThread() { return Thread.currentThread() == this.serverThread; } @@ -312,7 +314,7 @@ public class Proxy { return this.compression; } - public ServerStatusResponse getStatus() { + public ServerInfo getStatus() { return this.status; } diff --git a/proxy/src/main/java/proxy/nbt/NBTTagCompound.java b/proxy/src/main/java/proxy/nbt/NBTTagCompound.java index 66810ab..2c38f30 100755 --- a/proxy/src/main/java/proxy/nbt/NBTTagCompound.java +++ b/proxy/src/main/java/proxy/nbt/NBTTagCompound.java @@ -3,14 +3,16 @@ package proxy.nbt; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import java.util.HashMap; import java.util.Map; import java.util.Set; + +import com.google.common.collect.Maps; + import java.util.Map.Entry; public class NBTTagCompound extends NBTBase { - private Map tagMap = new HashMap(); + private Map tagMap = Maps.newHashMap(); /** * Write the actual data contents of the tag, implemented in NBT extension classes diff --git a/proxy/src/main/java/proxy/nbt/NBTTagList.java b/proxy/src/main/java/proxy/nbt/NBTTagList.java index c7741ba..d08b801 100755 --- a/proxy/src/main/java/proxy/nbt/NBTTagList.java +++ b/proxy/src/main/java/proxy/nbt/NBTTagList.java @@ -3,14 +3,15 @@ package proxy.nbt; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import java.util.ArrayList; import java.util.List; +import com.google.common.collect.Lists; + import proxy.util.Log; public class NBTTagList extends NBTBase { - private List tagList = new ArrayList(); + private List tagList = Lists.newArrayList(); /** * The type byte for the tags in the list - they must all be of the same type. @@ -60,7 +61,7 @@ public class NBTTagList extends NBTBase else { sizeTracker.read(32L * (long)i); - this.tagList = new ArrayList(i); + this.tagList = Lists.newArrayListWithCapacity(i); for (int j = 0; j < i; ++j) { diff --git a/proxy/src/main/java/proxy/network/NetHandlerPlayServer.java b/proxy/src/main/java/proxy/network/NetHandlerPlayServer.java index cc1c804..4e442f4 100755 --- a/proxy/src/main/java/proxy/network/NetHandlerPlayServer.java +++ b/proxy/src/main/java/proxy/network/NetHandlerPlayServer.java @@ -113,7 +113,7 @@ import proxy.util.ChatColor; import proxy.util.ChatComponent; import proxy.util.ChatComponentText; import proxy.util.User; -import proxy.util.ItemStack; +import proxy.util.Stack; import proxy.util.Log; public class NetHandlerPlayServer implements INetHandler { @@ -502,7 +502,7 @@ public class NetHandlerPlayServer implements INetHandler { public void processCreativeInventoryAction(C10PacketCreativeInventoryAction packetIn) { if(!this.connected) return; - ItemStack stack = packetIn.getStack(); + Stack stack = packetIn.getStack(); // TODO: validate item this.sendToServer(packetIn); } @@ -522,7 +522,7 @@ public class NetHandlerPlayServer implements INetHandler { if("MC|BEdit".equals(packetIn.getChannelName())) { PacketBuffer packetbuffer = packetIn.getBufferData(); try { - ItemStack itemstack1 = packetbuffer.readItemStackFromBuffer(); + Stack itemstack1 = packetbuffer.readStack(); if(itemstack1 != null) { NBTTagList pages = itemstack1.getTag().getTagList("pages", 8); @@ -541,7 +541,7 @@ public class NetHandlerPlayServer implements INetHandler { else if("MC|BSign".equals(packetIn.getChannelName())) { PacketBuffer packetbuffer = packetIn.getBufferData(); try { - ItemStack itemstack = packetbuffer.readItemStackFromBuffer(); + Stack itemstack = packetbuffer.readStack(); if(itemstack != null) { String title = itemstack.getTag().getString("title"); diff --git a/proxy/src/main/java/proxy/network/PacketBuffer.java b/proxy/src/main/java/proxy/network/PacketBuffer.java index 6b1629e..8599a82 100755 --- a/proxy/src/main/java/proxy/network/PacketBuffer.java +++ b/proxy/src/main/java/proxy/network/PacketBuffer.java @@ -22,9 +22,9 @@ import java.util.UUID; import proxy.nbt.NBTSizeTracker; import proxy.nbt.NBTTagCompound; -import proxy.util.BlockPos; +import proxy.util.Vec3; import proxy.util.ChatComponent; -import proxy.util.ItemStack; +import proxy.util.Stack; public class PacketBuffer extends ByteBuf { @@ -67,14 +67,14 @@ public class PacketBuffer extends ByteBuf return abyte; } - public BlockPos readBlockPos() + public Vec3 readVector() { - return BlockPos.fromLong(this.readLong()); + return new Vec3(this.readLong()); } - public void writeBlockPos(BlockPos pos) + public void writeVector(Vec3 pos) { - this.writeLong(pos.toLong()); + this.writeLong(pos.getData()); } public ChatComponent readChatComponent() throws IOException @@ -244,10 +244,7 @@ public class PacketBuffer extends ByteBuf } } - /** - * Writes the ItemStack's ID (short), then size (byte), then damage. (short) - */ - public void writeItemStackToBuffer(ItemStack stack) + public void writeStack(Stack stack) { if (stack == null) { @@ -262,19 +259,16 @@ public class PacketBuffer extends ByteBuf } } - /** - * Reads an ItemStack from this buffer - */ - public ItemStack readItemStackFromBuffer() throws IOException + public Stack readStack() throws IOException { - ItemStack stack = null; + Stack stack = null; short id = this.readShort(); if (id >= 0) { byte size = this.readByte(); short meta = this.readShort(); - stack = new ItemStack(id, size, meta, this.readNBTTagCompoundFromBuffer()); + stack = new Stack(id, size, meta, this.readNBTTagCompoundFromBuffer()); } return stack; diff --git a/proxy/src/main/java/proxy/network/PacketThreadUtil.java b/proxy/src/main/java/proxy/network/PacketThreadUtil.java index 7d19b08..7cec4a5 100755 --- a/proxy/src/main/java/proxy/network/PacketThreadUtil.java +++ b/proxy/src/main/java/proxy/network/PacketThreadUtil.java @@ -4,7 +4,7 @@ import proxy.Proxy; public class PacketThreadUtil { public static void checkThreadAndEnqueue(final Packet packet, final T handler, Proxy proxy) throws ThreadQuickExitException { - if(!proxy.isCallingFromMinecraftThread()) { + if(!proxy.isMainThread()) { proxy.schedule(new Runnable() { public void run() { packet.processPacket(handler); diff --git a/proxy/src/main/java/proxy/network/ServerStatusResponse.java b/proxy/src/main/java/proxy/network/ServerStatusResponse.java deleted file mode 100755 index 59f52a9..0000000 --- a/proxy/src/main/java/proxy/network/ServerStatusResponse.java +++ /dev/null @@ -1,249 +0,0 @@ -package proxy.network; - -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.Type; -import java.util.UUID; - -import proxy.util.ChatComponent; -import proxy.util.GameProfile; -import proxy.util.JsonUtils; - -public class ServerStatusResponse -{ - private ChatComponent serverMotd; - private ServerStatusResponse.PlayerCountData playerCount; - private ServerStatusResponse.MinecraftProtocolVersionIdentifier protocolVersion; - private String favicon; - - public ChatComponent getServerDescription() - { - return this.serverMotd; - } - - public void setServerDescription(ChatComponent motd) - { - this.serverMotd = motd; - } - - public ServerStatusResponse.PlayerCountData getPlayerCountData() - { - return this.playerCount; - } - - public void setPlayerCountData(ServerStatusResponse.PlayerCountData countData) - { - this.playerCount = countData; - } - - public ServerStatusResponse.MinecraftProtocolVersionIdentifier getProtocolVersionInfo() - { - return this.protocolVersion; - } - - public void setProtocolVersionInfo(ServerStatusResponse.MinecraftProtocolVersionIdentifier protocolVersionData) - { - this.protocolVersion = protocolVersionData; - } - - public void setFavicon(String faviconBlob) - { - this.favicon = faviconBlob; - } - - public String getFavicon() - { - return this.favicon; - } - - public static class MinecraftProtocolVersionIdentifier - { - private final String name; - private final int protocol; - - public MinecraftProtocolVersionIdentifier(String nameIn, int protocolIn) - { - this.name = nameIn; - this.protocol = protocolIn; - } - - public String getName() - { - return this.name; - } - - public int getProtocol() - { - return this.protocol; - } - - public static class Serializer implements JsonDeserializer, JsonSerializer - { - public ServerStatusResponse.MinecraftProtocolVersionIdentifier deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException - { - JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "version"); - return new ServerStatusResponse.MinecraftProtocolVersionIdentifier(JsonUtils.getString(jsonobject, "name"), JsonUtils.getInt(jsonobject, "protocol")); - } - - public JsonElement serialize(ServerStatusResponse.MinecraftProtocolVersionIdentifier p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_) - { - JsonObject jsonobject = new JsonObject(); - jsonobject.addProperty("name", p_serialize_1_.getName()); - jsonobject.addProperty("protocol", (Number)Integer.valueOf(p_serialize_1_.getProtocol())); - return jsonobject; - } - } - } - - public static class PlayerCountData - { - private final int maxPlayers; - private final int onlinePlayerCount; - private GameProfile[] players; - - public PlayerCountData(int maxOnlinePlayers, int onlinePlayers) - { - this.maxPlayers = maxOnlinePlayers; - this.onlinePlayerCount = onlinePlayers; - } - - public int getMaxPlayers() - { - return this.maxPlayers; - } - - public int getOnlinePlayerCount() - { - return this.onlinePlayerCount; - } - - public GameProfile[] getPlayers() - { - return this.players; - } - - public void setPlayers(GameProfile[] playersIn) - { - this.players = playersIn; - } - - public static class Serializer implements JsonDeserializer, JsonSerializer - { - public ServerStatusResponse.PlayerCountData deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException - { - JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "players"); - ServerStatusResponse.PlayerCountData serverstatusresponse$playercountdata = new ServerStatusResponse.PlayerCountData(JsonUtils.getInt(jsonobject, "max"), JsonUtils.getInt(jsonobject, "online")); - - if (JsonUtils.isJsonArray(jsonobject, "sample")) - { - JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sample"); - - if (jsonarray.size() > 0) - { - GameProfile[] agameprofile = new GameProfile[jsonarray.size()]; - - for (int i = 0; i < agameprofile.length; ++i) - { - JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonarray.get(i), "player[" + i + "]"); - String s = JsonUtils.getString(jsonobject1, "id"); - agameprofile[i] = new GameProfile(UUID.fromString(s), JsonUtils.getString(jsonobject1, "name")); - } - - serverstatusresponse$playercountdata.setPlayers(agameprofile); - } - } - - return serverstatusresponse$playercountdata; - } - - public JsonElement serialize(ServerStatusResponse.PlayerCountData p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_) - { - JsonObject jsonobject = new JsonObject(); - jsonobject.addProperty("max", (Number)Integer.valueOf(p_serialize_1_.getMaxPlayers())); - jsonobject.addProperty("online", (Number)Integer.valueOf(p_serialize_1_.getOnlinePlayerCount())); - - if (p_serialize_1_.getPlayers() != null && p_serialize_1_.getPlayers().length > 0) - { - JsonArray jsonarray = new JsonArray(); - - for (int i = 0; i < p_serialize_1_.getPlayers().length; ++i) - { - JsonObject jsonobject1 = new JsonObject(); - UUID uuid = p_serialize_1_.getPlayers()[i].getId(); - jsonobject1.addProperty("id", uuid == null ? "" : uuid.toString()); - jsonobject1.addProperty("name", p_serialize_1_.getPlayers()[i].getName()); - jsonarray.add(jsonobject1); - } - - jsonobject.add("sample", jsonarray); - } - - return jsonobject; - } - } - } - - public static class Serializer implements JsonDeserializer, JsonSerializer - { - public ServerStatusResponse deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException - { - JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "status"); - ServerStatusResponse serverstatusresponse = new ServerStatusResponse(); - - if (jsonobject.has("description")) - { - serverstatusresponse.setServerDescription((ChatComponent)p_deserialize_3_.deserialize(jsonobject.get("description"), ChatComponent.class)); - } - - if (jsonobject.has("players")) - { - serverstatusresponse.setPlayerCountData((ServerStatusResponse.PlayerCountData)p_deserialize_3_.deserialize(jsonobject.get("players"), ServerStatusResponse.PlayerCountData.class)); - } - - if (jsonobject.has("version")) - { - serverstatusresponse.setProtocolVersionInfo((ServerStatusResponse.MinecraftProtocolVersionIdentifier)p_deserialize_3_.deserialize(jsonobject.get("version"), ServerStatusResponse.MinecraftProtocolVersionIdentifier.class)); - } - - if (jsonobject.has("favicon")) - { - serverstatusresponse.setFavicon(JsonUtils.getString(jsonobject, "favicon")); - } - - return serverstatusresponse; - } - - public JsonElement serialize(ServerStatusResponse p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_) - { - JsonObject jsonobject = new JsonObject(); - - if (p_serialize_1_.getServerDescription() != null) - { - jsonobject.add("description", p_serialize_3_.serialize(p_serialize_1_.getServerDescription())); - } - - if (p_serialize_1_.getPlayerCountData() != null) - { - jsonobject.add("players", p_serialize_3_.serialize(p_serialize_1_.getPlayerCountData())); - } - - if (p_serialize_1_.getProtocolVersionInfo() != null) - { - jsonobject.add("version", p_serialize_3_.serialize(p_serialize_1_.getProtocolVersionInfo())); - } - - if (p_serialize_1_.getFavicon() != null) - { - jsonobject.addProperty("favicon", p_serialize_1_.getFavicon()); - } - - return jsonobject; - } - } -} diff --git a/proxy/src/main/java/proxy/packet/play/client/C07PacketPlayerDigging.java b/proxy/src/main/java/proxy/packet/play/client/C07PacketPlayerDigging.java index 228e605..140610b 100755 --- a/proxy/src/main/java/proxy/packet/play/client/C07PacketPlayerDigging.java +++ b/proxy/src/main/java/proxy/packet/play/client/C07PacketPlayerDigging.java @@ -5,11 +5,11 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class C07PacketPlayerDigging implements Packet { - private BlockPos position; + private Vec3 position; private byte facing; private C07PacketPlayerDigging.Action status; @@ -19,7 +19,7 @@ public class C07PacketPlayerDigging implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.status = (C07PacketPlayerDigging.Action)buf.readEnumValue(C07PacketPlayerDigging.Action.class); - this.position = buf.readBlockPos(); + this.position = buf.readVector(); this.facing = (byte)buf.readUnsignedByte(); } @@ -29,7 +29,7 @@ public class C07PacketPlayerDigging implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeEnumValue(this.status); - buf.writeBlockPos(this.position); + buf.writeVector(this.position); buf.writeByte(this.facing); } diff --git a/proxy/src/main/java/proxy/packet/play/client/C08PacketPlayerBlockPlacement.java b/proxy/src/main/java/proxy/packet/play/client/C08PacketPlayerBlockPlacement.java index 5c432bb..7613688 100755 --- a/proxy/src/main/java/proxy/packet/play/client/C08PacketPlayerBlockPlacement.java +++ b/proxy/src/main/java/proxy/packet/play/client/C08PacketPlayerBlockPlacement.java @@ -5,14 +5,14 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; -import proxy.util.ItemStack; +import proxy.util.Vec3; +import proxy.util.Stack; public class C08PacketPlayerBlockPlacement implements Packet { - private BlockPos position; + private Vec3 position; private int placedBlockDirection; - private ItemStack stack; + private Stack stack; private float facingX; private float facingY; private float facingZ; @@ -22,9 +22,9 @@ public class C08PacketPlayerBlockPlacement implements Packet { @@ -13,7 +13,7 @@ public class C0EPacketClickWindow implements Packet private int slotId; private int usedButton; private short actionNumber; - private ItemStack clickedItem; + private Stack clickedItem; private int mode; /** @@ -34,7 +34,7 @@ public class C0EPacketClickWindow implements Packet this.usedButton = buf.readByte(); this.actionNumber = buf.readShort(); this.mode = buf.readByte(); - this.clickedItem = buf.readItemStackFromBuffer(); + this.clickedItem = buf.readStack(); } /** @@ -47,6 +47,6 @@ public class C0EPacketClickWindow implements Packet buf.writeByte(this.usedButton); buf.writeShort(this.actionNumber); buf.writeByte(this.mode); - buf.writeItemStackToBuffer(this.clickedItem); + buf.writeStack(this.clickedItem); } } diff --git a/proxy/src/main/java/proxy/packet/play/client/C10PacketCreativeInventoryAction.java b/proxy/src/main/java/proxy/packet/play/client/C10PacketCreativeInventoryAction.java index c3d4389..4a33eb8 100755 --- a/proxy/src/main/java/proxy/packet/play/client/C10PacketCreativeInventoryAction.java +++ b/proxy/src/main/java/proxy/packet/play/client/C10PacketCreativeInventoryAction.java @@ -5,12 +5,12 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.ItemStack; +import proxy.util.Stack; public class C10PacketCreativeInventoryAction implements Packet { private int slotId; - private ItemStack stack; + private Stack stack; /** * Passes this Packet on to the NetHandler for processing. @@ -26,7 +26,7 @@ public class C10PacketCreativeInventoryAction implements Packet { - private BlockPos pos; + private Vec3 pos; private ChatComponent[] lines; /** @@ -18,7 +18,7 @@ public class C12PacketUpdateSign implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.pos = buf.readBlockPos(); + this.pos = buf.readVector(); this.lines = new ChatComponent[4]; for (int i = 0; i < 4; ++i) @@ -34,7 +34,7 @@ public class C12PacketUpdateSign implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeBlockPos(this.pos); + buf.writeVector(this.pos); for (int i = 0; i < 4; ++i) { diff --git a/proxy/src/main/java/proxy/packet/play/client/C14PacketTabComplete.java b/proxy/src/main/java/proxy/packet/play/client/C14PacketTabComplete.java index 5f25e2d..8eedde0 100755 --- a/proxy/src/main/java/proxy/packet/play/client/C14PacketTabComplete.java +++ b/proxy/src/main/java/proxy/packet/play/client/C14PacketTabComplete.java @@ -5,12 +5,12 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class C14PacketTabComplete implements Packet { private String message; - private BlockPos targetBlock; + private Vec3 targetBlock; public C14PacketTabComplete() { @@ -18,10 +18,10 @@ public class C14PacketTabComplete implements Packet public C14PacketTabComplete(String msg) { - this(msg, (BlockPos)null); + this(msg, (Vec3)null); } - public C14PacketTabComplete(String msg, BlockPos target) + public C14PacketTabComplete(String msg, Vec3 target) { this.message = msg; this.targetBlock = target; @@ -37,7 +37,7 @@ public class C14PacketTabComplete implements Packet if (flag) { - this.targetBlock = buf.readBlockPos(); + this.targetBlock = buf.readVector(); } } @@ -52,7 +52,7 @@ public class C14PacketTabComplete implements Packet if (flag) { - buf.writeBlockPos(this.targetBlock); + buf.writeVector(this.targetBlock); } } @@ -69,7 +69,7 @@ public class C14PacketTabComplete implements Packet return this.message; } - public BlockPos getTargetBlock() + public Vec3 getTargetBlock() { return this.targetBlock; } diff --git a/proxy/src/main/java/proxy/packet/play/server/S04PacketEntityEquipment.java b/proxy/src/main/java/proxy/packet/play/server/S04PacketEntityEquipment.java index d2e36e0..42d9655 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S04PacketEntityEquipment.java +++ b/proxy/src/main/java/proxy/packet/play/server/S04PacketEntityEquipment.java @@ -5,13 +5,13 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.ItemStack; +import proxy.util.Stack; public class S04PacketEntityEquipment implements Packet { private int entityID; private int equipmentSlot; - private ItemStack itemStack; + private Stack itemStack; /** * Reads the raw packet data from the data stream. @@ -20,7 +20,7 @@ public class S04PacketEntityEquipment implements Packet { this.entityID = buf.readVarIntFromBuffer(); this.equipmentSlot = buf.readShort(); - this.itemStack = buf.readItemStackFromBuffer(); + this.itemStack = buf.readStack(); } /** @@ -30,7 +30,7 @@ public class S04PacketEntityEquipment implements Packet { buf.writeVarIntToBuffer(this.entityID); buf.writeShort(this.equipmentSlot); - buf.writeItemStackToBuffer(this.itemStack); + buf.writeStack(this.itemStack); } /** diff --git a/proxy/src/main/java/proxy/packet/play/server/S05PacketSpawnPosition.java b/proxy/src/main/java/proxy/packet/play/server/S05PacketSpawnPosition.java index 480a709..0355626 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S05PacketSpawnPosition.java +++ b/proxy/src/main/java/proxy/packet/play/server/S05PacketSpawnPosition.java @@ -5,18 +5,18 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S05PacketSpawnPosition implements Packet { - private BlockPos spawnBlockPos; + private Vec3 spawnBlockPos; /** * Reads the raw packet data from the data stream. */ public void readPacketData(PacketBuffer buf) throws IOException { - this.spawnBlockPos = buf.readBlockPos(); + this.spawnBlockPos = buf.readVector(); } /** @@ -24,7 +24,7 @@ public class S05PacketSpawnPosition implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeBlockPos(this.spawnBlockPos); + buf.writeVector(this.spawnBlockPos); } /** diff --git a/proxy/src/main/java/proxy/packet/play/server/S0APacketUseBed.java b/proxy/src/main/java/proxy/packet/play/server/S0APacketUseBed.java index 49976f5..e49a1bf 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S0APacketUseBed.java +++ b/proxy/src/main/java/proxy/packet/play/server/S0APacketUseBed.java @@ -5,12 +5,12 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S0APacketUseBed implements Packet { private int playerID; - private BlockPos bedPos; + private Vec3 bedPos; /** * Reads the raw packet data from the data stream. @@ -18,7 +18,7 @@ public class S0APacketUseBed implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.playerID = buf.readVarIntFromBuffer(); - this.bedPos = buf.readBlockPos(); + this.bedPos = buf.readVector(); } /** @@ -27,7 +27,7 @@ public class S0APacketUseBed implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeVarIntToBuffer(this.playerID); - buf.writeBlockPos(this.bedPos); + buf.writeVector(this.bedPos); } /** diff --git a/proxy/src/main/java/proxy/packet/play/server/S0CPacketSpawnPlayer.java b/proxy/src/main/java/proxy/packet/play/server/S0CPacketSpawnPlayer.java index f6508f5..703acb6 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S0CPacketSpawnPlayer.java +++ b/proxy/src/main/java/proxy/packet/play/server/S0CPacketSpawnPlayer.java @@ -7,7 +7,7 @@ import java.util.UUID; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.DataWatcher; +import proxy.util.EntityData; import proxy.util.MathHelper; public class S0CPacketSpawnPlayer implements Packet @@ -20,7 +20,7 @@ public class S0CPacketSpawnPlayer implements Packet private byte yaw; private byte pitch; private int currentItem; - private List field_148958_j; + private List field_148958_j; public S0CPacketSpawnPlayer() { @@ -51,7 +51,7 @@ public class S0CPacketSpawnPlayer implements Packet this.yaw = buf.readByte(); this.pitch = buf.readByte(); this.currentItem = buf.readShort(); - this.field_148958_j = DataWatcher.readWatchedListFromPacketBuffer(buf); + this.field_148958_j = EntityData.readData(buf); } /** @@ -67,7 +67,7 @@ public class S0CPacketSpawnPlayer implements Packet buf.writeByte(this.yaw); buf.writeByte(this.pitch); buf.writeShort(this.currentItem); - DataWatcher.writeWatchedListToPacketBuffer(this.field_148958_j, buf); + EntityData.writeData(this.field_148958_j, buf); } /** diff --git a/proxy/src/main/java/proxy/packet/play/server/S0FPacketSpawnMob.java b/proxy/src/main/java/proxy/packet/play/server/S0FPacketSpawnMob.java index cceca36..d67688b 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S0FPacketSpawnMob.java +++ b/proxy/src/main/java/proxy/packet/play/server/S0FPacketSpawnMob.java @@ -6,7 +6,7 @@ import java.util.List; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.DataWatcher; +import proxy.util.EntityData; public class S0FPacketSpawnMob implements Packet { @@ -21,7 +21,7 @@ public class S0FPacketSpawnMob implements Packet private byte yaw; private byte pitch; private byte headPitch; - private List watcher; + private List watcher; /** * Reads the raw packet data from the data stream. @@ -39,7 +39,7 @@ public class S0FPacketSpawnMob implements Packet this.velocityX = buf.readShort(); this.velocityY = buf.readShort(); this.velocityZ = buf.readShort(); - this.watcher = DataWatcher.readWatchedListFromPacketBuffer(buf); + this.watcher = EntityData.readData(buf); } /** @@ -58,7 +58,7 @@ public class S0FPacketSpawnMob implements Packet buf.writeShort(this.velocityX); buf.writeShort(this.velocityY); buf.writeShort(this.velocityZ); - DataWatcher.writeWatchedListToPacketBuffer(this.watcher, buf); + EntityData.writeData(this.watcher, buf); } /** diff --git a/proxy/src/main/java/proxy/packet/play/server/S10PacketSpawnPainting.java b/proxy/src/main/java/proxy/packet/play/server/S10PacketSpawnPainting.java index fa53f51..a763896 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S10PacketSpawnPainting.java +++ b/proxy/src/main/java/proxy/packet/play/server/S10PacketSpawnPainting.java @@ -5,12 +5,12 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S10PacketSpawnPainting implements Packet { private int entityID; - private BlockPos position; + private Vec3 position; private byte facing; private String title; @@ -21,7 +21,7 @@ public class S10PacketSpawnPainting implements Packet { this.entityID = buf.readVarIntFromBuffer(); this.title = buf.readStringFromBuffer(13); - this.position = buf.readBlockPos(); + this.position = buf.readVector(); this.facing = (byte)buf.readUnsignedByte(); } @@ -32,7 +32,7 @@ public class S10PacketSpawnPainting implements Packet { buf.writeVarIntToBuffer(this.entityID); buf.writeString(this.title); - buf.writeBlockPos(this.position); + buf.writeVector(this.position); buf.writeByte(this.facing); } diff --git a/proxy/src/main/java/proxy/packet/play/server/S1CPacketEntityMetadata.java b/proxy/src/main/java/proxy/packet/play/server/S1CPacketEntityMetadata.java index 6bddc4d..f5e6c53 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S1CPacketEntityMetadata.java +++ b/proxy/src/main/java/proxy/packet/play/server/S1CPacketEntityMetadata.java @@ -6,12 +6,12 @@ import java.util.List; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.DataWatcher; +import proxy.util.EntityData; public class S1CPacketEntityMetadata implements Packet { private int entityId; - private List field_149378_b; + private List field_149378_b; /** * Reads the raw packet data from the data stream. @@ -19,7 +19,7 @@ public class S1CPacketEntityMetadata implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.entityId = buf.readVarIntFromBuffer(); - this.field_149378_b = DataWatcher.readWatchedListFromPacketBuffer(buf); + this.field_149378_b = EntityData.readData(buf); } /** @@ -28,7 +28,7 @@ public class S1CPacketEntityMetadata implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeVarIntToBuffer(this.entityId); - DataWatcher.writeWatchedListToPacketBuffer(this.field_149378_b, buf); + EntityData.writeData(this.field_149378_b, buf); } /** diff --git a/proxy/src/main/java/proxy/packet/play/server/S23PacketBlockChange.java b/proxy/src/main/java/proxy/packet/play/server/S23PacketBlockChange.java index 2f7cd10..0e10fe7 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S23PacketBlockChange.java +++ b/proxy/src/main/java/proxy/packet/play/server/S23PacketBlockChange.java @@ -5,11 +5,11 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S23PacketBlockChange implements Packet { - private BlockPos blockPosition; + private Vec3 blockPosition; private int blockState; /** @@ -17,7 +17,7 @@ public class S23PacketBlockChange implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.blockPosition = buf.readBlockPos(); + this.blockPosition = buf.readVector(); this.blockState = buf.readVarIntFromBuffer(); } @@ -26,7 +26,7 @@ public class S23PacketBlockChange implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeBlockPos(this.blockPosition); + buf.writeVector(this.blockPosition); buf.writeVarIntToBuffer(this.blockState); } diff --git a/proxy/src/main/java/proxy/packet/play/server/S24PacketBlockAction.java b/proxy/src/main/java/proxy/packet/play/server/S24PacketBlockAction.java index 5c57d7a..c9707b1 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S24PacketBlockAction.java +++ b/proxy/src/main/java/proxy/packet/play/server/S24PacketBlockAction.java @@ -5,11 +5,11 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S24PacketBlockAction implements Packet { - private BlockPos blockPosition; + private Vec3 blockPosition; private int instrument; private int pitch; private int block; @@ -19,7 +19,7 @@ public class S24PacketBlockAction implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.blockPosition = buf.readBlockPos(); + this.blockPosition = buf.readVector(); this.instrument = buf.readUnsignedByte(); this.pitch = buf.readUnsignedByte(); this.block = buf.readVarIntFromBuffer(); @@ -30,7 +30,7 @@ public class S24PacketBlockAction implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeBlockPos(this.blockPosition); + buf.writeVector(this.blockPosition); buf.writeByte(this.instrument); buf.writeByte(this.pitch); buf.writeVarIntToBuffer(this.block); diff --git a/proxy/src/main/java/proxy/packet/play/server/S25PacketBlockBreakAnim.java b/proxy/src/main/java/proxy/packet/play/server/S25PacketBlockBreakAnim.java index b13ae2c..f011c6d 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S25PacketBlockBreakAnim.java +++ b/proxy/src/main/java/proxy/packet/play/server/S25PacketBlockBreakAnim.java @@ -5,12 +5,12 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S25PacketBlockBreakAnim implements Packet { private int breakerId; - private BlockPos position; + private Vec3 position; private int progress; /** @@ -19,7 +19,7 @@ public class S25PacketBlockBreakAnim implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.breakerId = buf.readVarIntFromBuffer(); - this.position = buf.readBlockPos(); + this.position = buf.readVector(); this.progress = buf.readUnsignedByte(); } @@ -29,7 +29,7 @@ public class S25PacketBlockBreakAnim implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeVarIntToBuffer(this.breakerId); - buf.writeBlockPos(this.position); + buf.writeVector(this.position); buf.writeByte(this.progress); } diff --git a/proxy/src/main/java/proxy/packet/play/server/S27PacketExplosion.java b/proxy/src/main/java/proxy/packet/play/server/S27PacketExplosion.java index 5dbec57..a9bf48f 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S27PacketExplosion.java +++ b/proxy/src/main/java/proxy/packet/play/server/S27PacketExplosion.java @@ -8,7 +8,7 @@ import com.google.common.collect.Lists; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S27PacketExplosion implements Packet { @@ -16,7 +16,7 @@ public class S27PacketExplosion implements Packet private double posY; private double posZ; private float strength; - private List affectedBlockPositions; + private List affectedBlockPositions; private float field_149152_f; private float field_149153_g; private float field_149159_h; @@ -31,7 +31,7 @@ public class S27PacketExplosion implements Packet this.posZ = (double)buf.readFloat(); this.strength = buf.readFloat(); int i = buf.readInt(); - this.affectedBlockPositions = Lists.newArrayListWithCapacity(i); + this.affectedBlockPositions = Lists.newArrayListWithCapacity(i); int j = (int)this.posX; int k = (int)this.posY; int l = (int)this.posZ; @@ -41,7 +41,7 @@ public class S27PacketExplosion implements Packet int j1 = buf.readByte() + j; int k1 = buf.readByte() + k; int l1 = buf.readByte() + l; - this.affectedBlockPositions.add(new BlockPos(j1, k1, l1)); + this.affectedBlockPositions.add(new Vec3(j1, k1, l1)); } this.field_149152_f = buf.readFloat(); @@ -63,7 +63,7 @@ public class S27PacketExplosion implements Packet int j = (int)this.posY; int k = (int)this.posZ; - for (BlockPos blockpos : this.affectedBlockPositions) + for (Vec3 blockpos : this.affectedBlockPositions) { int l = blockpos.getX() - i; int i1 = blockpos.getY() - j; diff --git a/proxy/src/main/java/proxy/packet/play/server/S28PacketEffect.java b/proxy/src/main/java/proxy/packet/play/server/S28PacketEffect.java index 346d223..f4aef9a 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S28PacketEffect.java +++ b/proxy/src/main/java/proxy/packet/play/server/S28PacketEffect.java @@ -5,12 +5,12 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S28PacketEffect implements Packet { private int soundType; - private BlockPos soundPos; + private Vec3 soundPos; private int soundData; private boolean serverWide; @@ -20,7 +20,7 @@ public class S28PacketEffect implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.soundType = buf.readInt(); - this.soundPos = buf.readBlockPos(); + this.soundPos = buf.readVector(); this.soundData = buf.readInt(); this.serverWide = buf.readBoolean(); } @@ -31,7 +31,7 @@ public class S28PacketEffect implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeInt(this.soundType); - buf.writeBlockPos(this.soundPos); + buf.writeVector(this.soundPos); buf.writeInt(this.soundData); buf.writeBoolean(this.serverWide); } diff --git a/proxy/src/main/java/proxy/packet/play/server/S2FPacketSetSlot.java b/proxy/src/main/java/proxy/packet/play/server/S2FPacketSetSlot.java index c622e93..151fede 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S2FPacketSetSlot.java +++ b/proxy/src/main/java/proxy/packet/play/server/S2FPacketSetSlot.java @@ -5,13 +5,13 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.ItemStack; +import proxy.util.Stack; public class S2FPacketSetSlot implements Packet { private int windowId; private int slot; - private ItemStack item; + private Stack item; /** * Passes this Packet on to the NetHandler for processing. @@ -28,7 +28,7 @@ public class S2FPacketSetSlot implements Packet { this.windowId = buf.readByte(); this.slot = buf.readShort(); - this.item = buf.readItemStackFromBuffer(); + this.item = buf.readStack(); } /** @@ -38,6 +38,6 @@ public class S2FPacketSetSlot implements Packet { buf.writeByte(this.windowId); buf.writeShort(this.slot); - buf.writeItemStackToBuffer(this.item); + buf.writeStack(this.item); } } diff --git a/proxy/src/main/java/proxy/packet/play/server/S30PacketWindowItems.java b/proxy/src/main/java/proxy/packet/play/server/S30PacketWindowItems.java index 14361ba..77c778e 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S30PacketWindowItems.java +++ b/proxy/src/main/java/proxy/packet/play/server/S30PacketWindowItems.java @@ -5,12 +5,12 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.ItemStack; +import proxy.util.Stack; public class S30PacketWindowItems implements Packet { private int windowId; - private ItemStack[] itemStacks; + private Stack[] itemStacks; /** * Reads the raw packet data from the data stream. @@ -19,11 +19,11 @@ public class S30PacketWindowItems implements Packet { this.windowId = buf.readUnsignedByte(); int i = buf.readShort(); - this.itemStacks = new ItemStack[i]; + this.itemStacks = new Stack[i]; for (int j = 0; j < i; ++j) { - this.itemStacks[j] = buf.readItemStackFromBuffer(); + this.itemStacks[j] = buf.readStack(); } } @@ -35,9 +35,9 @@ public class S30PacketWindowItems implements Packet buf.writeByte(this.windowId); buf.writeShort(this.itemStacks.length); - for (ItemStack itemstack : this.itemStacks) + for (Stack itemstack : this.itemStacks) { - buf.writeItemStackToBuffer(itemstack); + buf.writeStack(itemstack); } } diff --git a/proxy/src/main/java/proxy/packet/play/server/S33PacketUpdateSign.java b/proxy/src/main/java/proxy/packet/play/server/S33PacketUpdateSign.java index 3560ec8..b915321 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S33PacketUpdateSign.java +++ b/proxy/src/main/java/proxy/packet/play/server/S33PacketUpdateSign.java @@ -5,13 +5,13 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; import proxy.util.ChatComponent; import proxy.util.ChatComponentText; public class S33PacketUpdateSign implements Packet { - private BlockPos blockPos; + private Vec3 blockPos; private ChatComponent[] lines; public S33PacketUpdateSign() { @@ -19,7 +19,7 @@ public class S33PacketUpdateSign implements Packet } public S33PacketUpdateSign(int x, int y, int z, String line1, String line2, String line3, String line4) { - this.blockPos = new BlockPos(x, y, z); + this.blockPos = new Vec3(x, y, z); this.lines = new ChatComponent[] {new ChatComponentText(line1), new ChatComponentText(line2), new ChatComponentText(line3), new ChatComponentText(line4)}; } @@ -28,7 +28,7 @@ public class S33PacketUpdateSign implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.blockPos = buf.readBlockPos(); + this.blockPos = buf.readVector(); this.lines = new ChatComponent[4]; for (int i = 0; i < 4; ++i) @@ -42,7 +42,7 @@ public class S33PacketUpdateSign implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeBlockPos(this.blockPos); + buf.writeVector(this.blockPos); for (int i = 0; i < 4; ++i) { diff --git a/proxy/src/main/java/proxy/packet/play/server/S35PacketUpdateTileEntity.java b/proxy/src/main/java/proxy/packet/play/server/S35PacketUpdateTileEntity.java index 008a7c5..cf18377 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S35PacketUpdateTileEntity.java +++ b/proxy/src/main/java/proxy/packet/play/server/S35PacketUpdateTileEntity.java @@ -6,11 +6,11 @@ import proxy.nbt.NBTTagCompound; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S35PacketUpdateTileEntity implements Packet { - private BlockPos blockPos; + private Vec3 blockPos; private int metadata; private NBTTagCompound nbt; @@ -19,7 +19,7 @@ public class S35PacketUpdateTileEntity implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.blockPos = buf.readBlockPos(); + this.blockPos = buf.readVector(); this.metadata = buf.readUnsignedByte(); this.nbt = buf.readNBTTagCompoundFromBuffer(); } @@ -29,7 +29,7 @@ public class S35PacketUpdateTileEntity implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeBlockPos(this.blockPos); + buf.writeVector(this.blockPos); buf.writeByte((byte)this.metadata); buf.writeNBTTagCompoundToBuffer(this.nbt); } diff --git a/proxy/src/main/java/proxy/packet/play/server/S36PacketSignEditorOpen.java b/proxy/src/main/java/proxy/packet/play/server/S36PacketSignEditorOpen.java index 842eb52..d619194 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S36PacketSignEditorOpen.java +++ b/proxy/src/main/java/proxy/packet/play/server/S36PacketSignEditorOpen.java @@ -5,18 +5,18 @@ import java.io.IOException; import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.util.BlockPos; +import proxy.util.Vec3; public class S36PacketSignEditorOpen implements Packet { - private BlockPos signPosition; + private Vec3 signPosition; public S36PacketSignEditorOpen() { } public S36PacketSignEditorOpen(int x, int y, int z) { - this.signPosition = new BlockPos(x, y, z); + this.signPosition = new Vec3(x, y, z); } /** @@ -32,7 +32,7 @@ public class S36PacketSignEditorOpen implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.signPosition = buf.readBlockPos(); + this.signPosition = buf.readVector(); } /** @@ -40,6 +40,6 @@ public class S36PacketSignEditorOpen implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeBlockPos(this.signPosition); + buf.writeVector(this.signPosition); } } diff --git a/proxy/src/main/java/proxy/packet/play/server/S38PacketPlayerListItem.java b/proxy/src/main/java/proxy/packet/play/server/S38PacketPlayerListItem.java index acfa082..a0f1120 100755 --- a/proxy/src/main/java/proxy/packet/play/server/S38PacketPlayerListItem.java +++ b/proxy/src/main/java/proxy/packet/play/server/S38PacketPlayerListItem.java @@ -10,7 +10,7 @@ import proxy.network.NetHandlerPlayServer; import proxy.network.Packet; import proxy.network.PacketBuffer; import proxy.util.ChatComponent; -import proxy.util.GameProfile; +import proxy.util.Profile; import proxy.util.Property; public class S38PacketPlayerListItem implements Packet @@ -22,7 +22,7 @@ public class S38PacketPlayerListItem implements Packet { } - public S38PacketPlayerListItem(S38PacketPlayerListItem.Action actionIn, GameProfile profile, int ping, int mode, ChatComponent display) + public S38PacketPlayerListItem(S38PacketPlayerListItem.Action actionIn, Profile profile, int ping, int mode, ChatComponent display) { this.action = actionIn; @@ -39,7 +39,7 @@ public class S38PacketPlayerListItem implements Packet for (int j = 0; j < i; ++j) { - GameProfile gameprofile = null; + Profile gameprofile = null; int k = 0; int worldsettings$gametype = 0; ChatComponent ichatcomponent = null; @@ -47,7 +47,7 @@ public class S38PacketPlayerListItem implements Packet switch (this.action) { case ADD_PLAYER: - gameprofile = new GameProfile(buf.readUuid(), buf.readStringFromBuffer(16)); + gameprofile = new Profile(buf.readUuid(), buf.readStringFromBuffer(16)); int l = buf.readVarIntFromBuffer(); int i1 = 0; @@ -77,17 +77,17 @@ public class S38PacketPlayerListItem implements Packet break; case UPDATE_GAME_MODE: - gameprofile = new GameProfile(buf.readUuid(), (String)null); + gameprofile = new Profile(buf.readUuid(), (String)null); worldsettings$gametype = buf.readVarIntFromBuffer(); break; case UPDATE_LATENCY: - gameprofile = new GameProfile(buf.readUuid(), (String)null); + gameprofile = new Profile(buf.readUuid(), (String)null); k = buf.readVarIntFromBuffer(); break; case UPDATE_DISPLAY_NAME: - gameprofile = new GameProfile(buf.readUuid(), (String)null); + gameprofile = new Profile(buf.readUuid(), (String)null); if (buf.readBoolean()) { @@ -97,7 +97,7 @@ public class S38PacketPlayerListItem implements Packet break; case REMOVE_PLAYER: - gameprofile = new GameProfile(buf.readUuid(), (String)null); + gameprofile = new Profile(buf.readUuid(), (String)null); } this.players.add(new S38PacketPlayerListItem.AddPlayerData(gameprofile, k, worldsettings$gametype, ichatcomponent)); @@ -126,7 +126,7 @@ public class S38PacketPlayerListItem implements Packet buf.writeString(property.getName()); buf.writeString(property.getValue()); - if (property.hasSignature()) + if (property.getSignature() != null) { buf.writeBoolean(true); buf.writeString(property.getSignature()); @@ -219,10 +219,10 @@ public class S38PacketPlayerListItem implements Packet { private final int ping; private final int gamemode; - private final GameProfile profile; + private final Profile profile; private final ChatComponent displayName; - public AddPlayerData(GameProfile profile, int pingIn, int gamemodeIn, ChatComponent displayNameIn) + public AddPlayerData(Profile profile, int pingIn, int gamemodeIn, ChatComponent displayNameIn) { this.profile = profile; this.ping = pingIn; @@ -230,7 +230,7 @@ public class S38PacketPlayerListItem implements Packet this.displayName = displayNameIn; } - public GameProfile getProfile() + public Profile getProfile() { return this.profile; } diff --git a/proxy/src/main/java/proxy/packet/status/server/S00PacketServerInfo.java b/proxy/src/main/java/proxy/packet/status/server/S00PacketServerInfo.java index c8d6d39..0b55b0b 100755 --- a/proxy/src/main/java/proxy/packet/status/server/S00PacketServerInfo.java +++ b/proxy/src/main/java/proxy/packet/status/server/S00PacketServerInfo.java @@ -8,21 +8,23 @@ import java.io.IOException; import proxy.network.NetHandlerStatusClient; import proxy.network.Packet; import proxy.network.PacketBuffer; -import proxy.network.ServerStatusResponse; import proxy.util.ChatComponent; import proxy.util.ChatStyle; -import proxy.util.EnumTypeAdapterFactory; +import proxy.util.JsonEnumFactory; +import proxy.util.PlayerInfo; +import proxy.util.ServerInfo; +import proxy.util.VersionId; public class S00PacketServerInfo implements Packet { - private static final Gson GSON = (new GsonBuilder()).registerTypeAdapter(ServerStatusResponse.MinecraftProtocolVersionIdentifier.class, new ServerStatusResponse.MinecraftProtocolVersionIdentifier.Serializer()).registerTypeAdapter(ServerStatusResponse.PlayerCountData.class, new ServerStatusResponse.PlayerCountData.Serializer()).registerTypeAdapter(ServerStatusResponse.class, new ServerStatusResponse.Serializer()).registerTypeHierarchyAdapter(ChatComponent.class, new ChatComponent.Serializer()).registerTypeHierarchyAdapter(ChatStyle.class, new ChatStyle.Serializer()).registerTypeAdapterFactory(new EnumTypeAdapterFactory()).create(); - private ServerStatusResponse response; + private static final Gson GSON = (new GsonBuilder()).registerTypeAdapter(VersionId.class, new VersionId.Serializer()).registerTypeAdapter(PlayerInfo.class, new PlayerInfo.Serializer()).registerTypeAdapter(ServerInfo.class, new ServerInfo.Serializer()).registerTypeHierarchyAdapter(ChatComponent.class, new ChatComponent.Serializer()).registerTypeHierarchyAdapter(ChatStyle.class, new ChatStyle.Serializer()).registerTypeAdapterFactory(new JsonEnumFactory()).create(); + private ServerInfo response; public S00PacketServerInfo() { } - public S00PacketServerInfo(ServerStatusResponse responseIn) + public S00PacketServerInfo(ServerInfo responseIn) { this.response = responseIn; } @@ -32,7 +34,7 @@ public class S00PacketServerInfo implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.response = (ServerStatusResponse)GSON.fromJson(buf.readStringFromBuffer(32767), ServerStatusResponse.class); + this.response = (ServerInfo)GSON.fromJson(buf.readStringFromBuffer(32767), ServerInfo.class); } /** @@ -51,7 +53,7 @@ public class S00PacketServerInfo implements Packet handler.handleServerInfo(this); } - public ServerStatusResponse getResponse() + public ServerInfo getResponse() { return this.response; } diff --git a/proxy/src/main/java/proxy/util/BlockPos.java b/proxy/src/main/java/proxy/util/BlockPos.java deleted file mode 100755 index 000d865..0000000 --- a/proxy/src/main/java/proxy/util/BlockPos.java +++ /dev/null @@ -1,45 +0,0 @@ -package proxy.util; - -public class BlockPos { - private static final int NUM_X_BITS = 1 + MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000)); - private static final int NUM_Z_BITS = NUM_X_BITS; - private static final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS; - private static final int Y_SHIFT = 0 + NUM_Z_BITS; - private static final int X_SHIFT = Y_SHIFT + NUM_Y_BITS; - private static final long X_MASK = (1L << NUM_X_BITS) - 1L; - private static final long Y_MASK = (1L << NUM_Y_BITS) - 1L; - private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L; - - private final int x; - private final int y; - private final int z; - - public BlockPos(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public int getX() { - return this.x; - } - - public int getY() { - return this.y; - } - - public int getZ() { - return this.z; - } - - public long toLong() { - return ((long)this.getX() & X_MASK) << X_SHIFT | ((long)this.getY() & Y_MASK) << Y_SHIFT | ((long)this.getZ() & Z_MASK) << 0; - } - - public static BlockPos fromLong(long serialized) { - int i = (int)(serialized << 64 - X_SHIFT - NUM_X_BITS >> 64 - NUM_X_BITS); - int j = (int)(serialized << 64 - Y_SHIFT - NUM_Y_BITS >> 64 - NUM_Y_BITS); - int k = (int)(serialized << 64 - NUM_Z_BITS >> 64 - NUM_Z_BITS); - return new BlockPos(i, j, k); - } -} diff --git a/proxy/src/main/java/proxy/util/ChatColor.java b/proxy/src/main/java/proxy/util/ChatColor.java index 7e3c792..0fa597d 100755 --- a/proxy/src/main/java/proxy/util/ChatColor.java +++ b/proxy/src/main/java/proxy/util/ChatColor.java @@ -30,6 +30,10 @@ public enum ChatColor { private final String value; + public static String strip(String str) { + return str == null ? null : STRIP_PATTERN.matcher(str).replaceAll(""); + } + private ChatColor(char code) { this.value = "\u00a7" + code; } @@ -37,8 +41,4 @@ public enum ChatColor { public String toString() { return this.value; } - - public static String strip(String str) { - return str == null ? null : STRIP_PATTERN.matcher(str).replaceAll(""); - } } diff --git a/proxy/src/main/java/proxy/util/ChatComponent.java b/proxy/src/main/java/proxy/util/ChatComponent.java index 775aa61..29766d7 100755 --- a/proxy/src/main/java/proxy/util/ChatComponent.java +++ b/proxy/src/main/java/proxy/util/ChatComponent.java @@ -74,29 +74,29 @@ public abstract class ChatComponent if (jsonobject.has("with")) { - JsonArray jsonarray = jsonobject.getAsJsonArray("with"); - Object[] aobject = new Object[jsonarray.size()]; + JsonArray arr = jsonobject.getAsJsonArray("with"); + Object[] args = new Object[arr.size()]; - for (int i = 0; i < aobject.length; ++i) + for (int z = 0; z < args.length; z++) { - aobject[i] = this.deserialize(jsonarray.get(i), p_deserialize_2_, p_deserialize_3_); + args[z] = this.deserialize(arr.get(z), p_deserialize_2_, p_deserialize_3_); - if (aobject[i] instanceof ChatComponentText) + if (args[z] instanceof ChatComponentText) { - ChatComponentText chatcomponenttext = (ChatComponentText)aobject[i]; + ChatComponentText text = (ChatComponentText)args[z]; - if ((((ChatComponent)chatcomponenttext).style == null || ((ChatComponent)chatcomponenttext).style.isEmpty()) && ((ChatComponent)chatcomponenttext).siblings.isEmpty()) + if ((((ChatComponent)text).style == null || ((ChatComponent)text).style.isEmpty()) && ((ChatComponent)text).siblings.isEmpty()) { - aobject[i] = chatcomponenttext.getText(); + args[z] = text.getText(); } } } - ichatcomponent = new ChatComponentTranslation(s, aobject); + ichatcomponent = new ChatComponentTranslation(s, args); } else { - ichatcomponent = new ChatComponentTranslation(s, new Object[0]); + ichatcomponent = new ChatComponentTranslation(s); } } else if (jsonobject.has("score")) @@ -196,11 +196,11 @@ public abstract class ChatComponent ChatComponentTranslation chatcomponenttranslation = (ChatComponentTranslation)p_serialize_1_; jsonobject.addProperty("translate", chatcomponenttranslation.getKey()); - if (chatcomponenttranslation.getFormatArgs() != null && chatcomponenttranslation.getFormatArgs().length > 0) + if (chatcomponenttranslation.getArgs() != null && chatcomponenttranslation.getArgs().length > 0) { JsonArray jsonarray1 = new JsonArray(); - for (Object object : chatcomponenttranslation.getFormatArgs()) + for (Object object : chatcomponenttranslation.getArgs()) { if (object instanceof ChatComponent) { @@ -254,7 +254,7 @@ public abstract class ChatComponent GsonBuilder gsonbuilder = new GsonBuilder(); gsonbuilder.registerTypeHierarchyAdapter(ChatComponent.class, new ChatComponent.Serializer()); gsonbuilder.registerTypeHierarchyAdapter(ChatStyle.class, new ChatStyle.Serializer()); - gsonbuilder.registerTypeAdapterFactory(new EnumTypeAdapterFactory()); + gsonbuilder.registerTypeAdapterFactory(new JsonEnumFactory()); GSON = gsonbuilder.create(); } } diff --git a/proxy/src/main/java/proxy/util/ChatComponentScore.java b/proxy/src/main/java/proxy/util/ChatComponentScore.java index 426de0b..7f39a72 100755 --- a/proxy/src/main/java/proxy/util/ChatComponentScore.java +++ b/proxy/src/main/java/proxy/util/ChatComponentScore.java @@ -5,9 +5,9 @@ public class ChatComponentScore extends ChatComponent { private final String objective; private String value = ""; - public ChatComponentScore(String nameIn, String objectiveIn) { - this.name = nameIn; - this.objective = objectiveIn; + public ChatComponentScore(String name, String objective) { + this.name = name; + this.objective = objective; } public String getName() { @@ -18,8 +18,8 @@ public class ChatComponentScore extends ChatComponent { return this.objective; } - public void setValue(String valueIn) { - this.value = valueIn; + public void setValue(String value) { + this.value = value; } public String getValue() { diff --git a/proxy/src/main/java/proxy/util/ChatComponentSelector.java b/proxy/src/main/java/proxy/util/ChatComponentSelector.java index 49df6a5..5ee68fb 100755 --- a/proxy/src/main/java/proxy/util/ChatComponentSelector.java +++ b/proxy/src/main/java/proxy/util/ChatComponentSelector.java @@ -3,8 +3,8 @@ package proxy.util; public class ChatComponentSelector extends ChatComponent { private final String selector; - public ChatComponentSelector(String selectorIn) { - this.selector = selectorIn; + public ChatComponentSelector(String selector) { + this.selector = selector; } public String getSelector() { diff --git a/proxy/src/main/java/proxy/util/ChatComponentText.java b/proxy/src/main/java/proxy/util/ChatComponentText.java index 1836b65..8c99178 100755 --- a/proxy/src/main/java/proxy/util/ChatComponentText.java +++ b/proxy/src/main/java/proxy/util/ChatComponentText.java @@ -3,8 +3,8 @@ package proxy.util; public class ChatComponentText extends ChatComponent { private final String text; - public ChatComponentText(String msg) { - this.text = msg; + public ChatComponentText(String text) { + this.text = text; } public String getText() { diff --git a/proxy/src/main/java/proxy/util/ChatComponentTranslation.java b/proxy/src/main/java/proxy/util/ChatComponentTranslation.java index cc6f628..f9d70f6 100755 --- a/proxy/src/main/java/proxy/util/ChatComponentTranslation.java +++ b/proxy/src/main/java/proxy/util/ChatComponentTranslation.java @@ -2,24 +2,24 @@ package proxy.util; public class ChatComponentTranslation extends ChatComponent { private final String key; - private final Object[] formatArgs; + private final Object[] args; - public ChatComponentTranslation(String translationKey, Object... args) { - this.key = translationKey; - this.formatArgs = args; + public ChatComponentTranslation(String key, Object... args) { + this.key = key; + this.args = args; } public String getKey() { return this.key; } - public Object[] getFormatArgs() { - return this.formatArgs; + public Object[] getArgs() { + return this.args; } public String toString() { StringBuilder sb = new StringBuilder(this.key); - for(Object arg : this.formatArgs) { + for(Object arg : this.args) { sb.append(' ').append(arg); } return sb.toString(); diff --git a/proxy/src/main/java/proxy/util/ChatStyle.java b/proxy/src/main/java/proxy/util/ChatStyle.java index 05627ce..9f09ea9 100755 --- a/proxy/src/main/java/proxy/util/ChatStyle.java +++ b/proxy/src/main/java/proxy/util/ChatStyle.java @@ -84,11 +84,11 @@ public class ChatStyle if (jsonobject1 != null) { JsonPrimitive jsonprimitive = jsonobject1.getAsJsonPrimitive("action"); - ClickEvent.Action clickevent$action = jsonprimitive == null ? null : ClickEvent.Action.getValueByCanonicalName(jsonprimitive.getAsString()); + ClickAction clickevent$action = jsonprimitive == null ? null : ClickAction.getByName(jsonprimitive.getAsString()); JsonPrimitive jsonprimitive1 = jsonobject1.getAsJsonPrimitive("value"); String s = jsonprimitive1 == null ? null : jsonprimitive1.getAsString(); - if (clickevent$action != null && s != null && clickevent$action.shouldAllowInChat()) + if (clickevent$action != null && s != null && clickevent$action.isSerialized()) { chatstyle.chatClickEvent = new ClickEvent(clickevent$action, s); } @@ -102,10 +102,10 @@ public class ChatStyle if (jsonobject2 != null) { JsonPrimitive jsonprimitive2 = jsonobject2.getAsJsonPrimitive("action"); - HoverEvent.Action hoverevent$action = jsonprimitive2 == null ? null : HoverEvent.Action.getValueByCanonicalName(jsonprimitive2.getAsString()); + HoverAction hoverevent$action = jsonprimitive2 == null ? null : HoverAction.getByName(jsonprimitive2.getAsString()); ChatComponent ichatcomponent = (ChatComponent)p_deserialize_3_.deserialize(jsonobject2.get("value"), ChatComponent.class); - if (hoverevent$action != null && ichatcomponent != null && hoverevent$action.shouldAllowInChat()) + if (hoverevent$action != null && ichatcomponent != null && hoverevent$action.isSerialized()) { chatstyle.chatHoverEvent = new HoverEvent(hoverevent$action, ichatcomponent); } @@ -169,7 +169,7 @@ public class ChatStyle if (p_serialize_1_.chatClickEvent != null) { JsonObject jsonobject1 = new JsonObject(); - jsonobject1.addProperty("action", p_serialize_1_.chatClickEvent.getAction().getCanonicalName()); + jsonobject1.addProperty("action", p_serialize_1_.chatClickEvent.getAction().getName()); jsonobject1.addProperty("value", p_serialize_1_.chatClickEvent.getValue()); jsonobject.add("clickEvent", jsonobject1); } @@ -177,7 +177,7 @@ public class ChatStyle if (p_serialize_1_.chatHoverEvent != null) { JsonObject jsonobject2 = new JsonObject(); - jsonobject2.addProperty("action", p_serialize_1_.chatHoverEvent.getAction().getCanonicalName()); + jsonobject2.addProperty("action", p_serialize_1_.chatHoverEvent.getAction().getName()); jsonobject2.add("value", p_serialize_3_.serialize(p_serialize_1_.chatHoverEvent.getValue())); jsonobject.add("hoverEvent", jsonobject2); } diff --git a/proxy/src/main/java/proxy/util/ClickAction.java b/proxy/src/main/java/proxy/util/ClickAction.java new file mode 100644 index 0000000..760ec94 --- /dev/null +++ b/proxy/src/main/java/proxy/util/ClickAction.java @@ -0,0 +1,42 @@ +package proxy.util; + +import java.util.Map; + +import com.google.common.collect.Maps; + +public enum ClickAction { + OPEN_URL("open_url", true), + OPEN_FILE("open_file", false), + RUN_COMMAND("run_command", true), + TWITCH_USER_INFO("twitch_user_info", false), + SUGGEST_COMMAND("suggest_command", true), + CHANGE_PAGE("change_page", true); + + private static final Map LOOKUP = Maps.newHashMap(); + + private final boolean serialize; + private final String name; + + static { + for(ClickAction action : values()) { + LOOKUP.put(action.name, action); + } + } + + public static ClickAction getByName(String name) { + return LOOKUP.get(name); + } + + private ClickAction(String name, boolean serialize) { + this.name = name; + this.serialize = serialize; + } + + public boolean isSerialized() { + return this.serialize; + } + + public String getName() { + return this.name; + } +} \ No newline at end of file diff --git a/proxy/src/main/java/proxy/util/ClickEvent.java b/proxy/src/main/java/proxy/util/ClickEvent.java index 48b666e..75ab01f 100755 --- a/proxy/src/main/java/proxy/util/ClickEvent.java +++ b/proxy/src/main/java/proxy/util/ClickEvent.java @@ -1,59 +1,19 @@ package proxy.util; -import java.util.HashMap; -import java.util.Map; - public class ClickEvent { - private final ClickEvent.Action action; + private final ClickAction action; private final String value; - public ClickEvent(ClickEvent.Action theAction, String theValue) { - this.action = theAction; - this.value = theValue; + public ClickEvent(ClickAction action, String value) { + this.action = action; + this.value = value; } - public ClickEvent.Action getAction() { + public ClickAction getAction() { return this.action; } public String getValue() { return this.value; } - - public static enum Action { - OPEN_URL("open_url", true), - OPEN_FILE("open_file", false), - RUN_COMMAND("run_command", true), - TWITCH_USER_INFO("twitch_user_info", false), - SUGGEST_COMMAND("suggest_command", true), - CHANGE_PAGE("change_page", true); - - private static final Map nameMapping = new HashMap(); - - private final boolean allowedInChat; - private final String canonicalName; - - private Action(String canonicalNameIn, boolean allowedInChatIn) { - this.canonicalName = canonicalNameIn; - this.allowedInChat = allowedInChatIn; - } - - public boolean shouldAllowInChat() { - return this.allowedInChat; - } - - public String getCanonicalName() { - return this.canonicalName; - } - - public static ClickEvent.Action getValueByCanonicalName(String canonicalNameIn) { - return nameMapping.get(canonicalNameIn); - } - - static { - for(ClickEvent.Action clickevent$action : values()) { - nameMapping.put(clickevent$action.getCanonicalName(), clickevent$action); - } - } - } } diff --git a/proxy/src/main/java/proxy/util/DataWatcher.java b/proxy/src/main/java/proxy/util/DataWatcher.java deleted file mode 100755 index 3d7d238..0000000 --- a/proxy/src/main/java/proxy/util/DataWatcher.java +++ /dev/null @@ -1,201 +0,0 @@ -package proxy.util; - -import java.io.IOException; -import java.util.List; -import com.google.common.collect.Lists; - -import proxy.network.PacketBuffer; - -public class DataWatcher -{ - private static class Vec3f { - protected final float x; - protected final float y; - protected final float z; - - public Vec3f(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public float getX() { - return this.x; - } - - public float getY() { - return this.y; - } - - public float getZ() { - return this.z; - } - } - - public static void writeWatchedListToPacketBuffer(List objectsList, PacketBuffer buffer) throws IOException - { - if (objectsList != null) - { - for (DataWatcher.WatchableObject datawatcher$watchableobject : objectsList) - { - writeWatchableObjectToPacketBuffer(buffer, datawatcher$watchableobject); - } - } - - buffer.writeByte(127); - } - - private static void writeWatchableObjectToPacketBuffer(PacketBuffer buffer, DataWatcher.WatchableObject object) throws IOException - { - int i = (object.getObjectType() << 5 | object.getDataValueId() & 31) & 255; - buffer.writeByte(i); - - switch (object.getObjectType()) - { - case 0: - buffer.writeByte(((Byte)object.getObject()).byteValue()); - break; - - case 1: - buffer.writeShort(((Short)object.getObject()).shortValue()); - break; - - case 2: - buffer.writeInt(((Integer)object.getObject()).intValue()); - break; - - case 3: - buffer.writeFloat(((Float)object.getObject()).floatValue()); - break; - - case 4: - buffer.writeString((String)object.getObject()); - break; - - case 5: - ItemStack itemstack = (ItemStack)object.getObject(); - buffer.writeItemStackToBuffer(itemstack); - break; - - case 6: - BlockPos blockpos = (BlockPos)object.getObject(); - buffer.writeInt(blockpos.getX()); - buffer.writeInt(blockpos.getY()); - buffer.writeInt(blockpos.getZ()); - break; - - case 7: - Vec3f rotations = (Vec3f)object.getObject(); - buffer.writeFloat(rotations.getX()); - buffer.writeFloat(rotations.getY()); - buffer.writeFloat(rotations.getZ()); - } - } - - public static List readWatchedListFromPacketBuffer(PacketBuffer buffer) throws IOException - { - List list = null; - - for (int i = buffer.readByte(); i != 127; i = buffer.readByte()) - { - if (list == null) - { - list = Lists.newArrayList(); - } - - int j = (i & 224) >> 5; - int k = i & 31; - DataWatcher.WatchableObject datawatcher$watchableobject = null; - - switch (j) - { - case 0: - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, Byte.valueOf(buffer.readByte())); - break; - - case 1: - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, Short.valueOf(buffer.readShort())); - break; - - case 2: - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, Integer.valueOf(buffer.readInt())); - break; - - case 3: - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, Float.valueOf(buffer.readFloat())); - break; - - case 4: - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, buffer.readStringFromBuffer(32767)); - break; - - case 5: - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, buffer.readItemStackFromBuffer()); - break; - - case 6: - int l = buffer.readInt(); - int i1 = buffer.readInt(); - int j1 = buffer.readInt(); - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, new BlockPos(l, i1, j1)); - break; - - case 7: - float f = buffer.readFloat(); - float f1 = buffer.readFloat(); - float f2 = buffer.readFloat(); - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, new Vec3f(f, f1, f2)); - } - - list.add(datawatcher$watchableobject); - } - - return list; - } - - public static class WatchableObject - { - private final int objectType; - private final int dataValueId; - private Object watchedObject; - private boolean watched; - - public WatchableObject(int type, int id, Object object) - { - this.dataValueId = id; - this.watchedObject = object; - this.objectType = type; - this.watched = true; - } - - public int getDataValueId() - { - return this.dataValueId; - } - - public void setObject(Object object) - { - this.watchedObject = object; - } - - public Object getObject() - { - return this.watchedObject; - } - - public int getObjectType() - { - return this.objectType; - } - - public boolean isWatched() - { - return this.watched; - } - - public void setWatched(boolean watched) - { - this.watched = watched; - } - } -} diff --git a/proxy/src/main/java/proxy/util/EntityData.java b/proxy/src/main/java/proxy/util/EntityData.java new file mode 100644 index 0000000..4837690 --- /dev/null +++ b/proxy/src/main/java/proxy/util/EntityData.java @@ -0,0 +1,122 @@ +package proxy.util; + +import java.io.IOException; +import java.util.List; + +import com.google.common.collect.Lists; + +import proxy.network.PacketBuffer; + +public class EntityData { + private final int type; + private final int id; + private final Object data; + + private static void writeData(PacketBuffer buf, EntityData data) throws IOException { + int value = (data.getType() << 5 | data.getId() & 31) & 255; + buf.writeByte(value); + switch(data.getType()) { + case 0: + buf.writeByte(((Byte)data.getData()).byteValue()); + break; + case 1: + buf.writeShort(((Short)data.getData()).shortValue()); + break; + case 2: + buf.writeInt(((Integer)data.getData()).intValue()); + break; + case 3: + buf.writeFloat(((Float)data.getData()).floatValue()); + break; + case 4: + buf.writeString((String)data.getData()); + break; + case 5: + Stack stack = (Stack)data.getData(); + buf.writeStack(stack); + break; + case 6: + Vec3 vec = (Vec3)data.getData(); + buf.writeInt(vec.getX()); + buf.writeInt(vec.getY()); + buf.writeInt(vec.getZ()); + break; + case 7: + Vec3f vecf = (Vec3f)data.getData(); + buf.writeFloat(vecf.getX()); + buf.writeFloat(vecf.getY()); + buf.writeFloat(vecf.getZ()); + } + } + + public static void writeData(List list, PacketBuffer buf) throws IOException { + if(list != null) { + for(EntityData data : list) { + EntityData.writeData(buf, data); + } + } + buf.writeByte(127); + } + + public static List readData(PacketBuffer buf) throws IOException { + List list = null; + for(int value = buf.readByte(); value != 127; value = buf.readByte()) { + if(list == null) + list = Lists.newArrayList(); + int type = (value & 224) >> 5; + int id = value & 31; + EntityData data = null; + switch(type) { + case 0: + data = new EntityData(type, id, Byte.valueOf(buf.readByte())); + break; + case 1: + data = new EntityData(type, id, Short.valueOf(buf.readShort())); + break; + case 2: + data = new EntityData(type, id, Integer.valueOf(buf.readInt())); + break; + case 3: + data = new EntityData(type, id, Float.valueOf(buf.readFloat())); + break; + case 4: + data = new EntityData(type, id, buf.readStringFromBuffer(32767)); + break; + case 5: + data = new EntityData(type, id, buf.readStack()); + break; + case 6: + int x = buf.readInt(); + int y = buf.readInt(); + int z = buf.readInt(); + data = new EntityData(type, id, new Vec3(x, y, z)); + break; + case 7: + float xf = buf.readFloat(); + float yf = buf.readFloat(); + float zf = buf.readFloat(); + data = new EntityData(type, id, new Vec3f(xf, yf, zf)); + } + list.add(data); + } + return list; + } + + public EntityData(int type, int id, Object data) { + this.type = type; + this.id = id; + this.data = data; + } + + public int getType() { + return this.type; + } + + public int getId() { + return this.id; + } + + public Object getData() { + return this.data; + } +} \ No newline at end of file diff --git a/proxy/src/main/java/proxy/util/EnumTypeAdapterFactory.java b/proxy/src/main/java/proxy/util/EnumTypeAdapterFactory.java deleted file mode 100755 index 505a663..0000000 --- a/proxy/src/main/java/proxy/util/EnumTypeAdapterFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -package proxy.util; - -import com.google.gson.Gson; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; -import java.io.IOException; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -public class EnumTypeAdapterFactory implements TypeAdapterFactory -{ - public TypeAdapter create(Gson gson, TypeToken token) - { - Class oclass = (Class)token.getRawType(); - - if (!oclass.isEnum()) - { - return null; - } - else - { - final Map map = new HashMap(); - - for (T t : oclass.getEnumConstants()) - { - map.put(this.func_151232_a(t), t); - } - - return new TypeAdapter() - { - public void write(JsonWriter p_write_1_, T p_write_2_) throws IOException - { - if (p_write_2_ == null) - { - p_write_1_.nullValue(); - } - else - { - p_write_1_.value(EnumTypeAdapterFactory.this.func_151232_a(p_write_2_)); - } - } - public T read(JsonReader p_read_1_) throws IOException - { - if (p_read_1_.peek() == JsonToken.NULL) - { - p_read_1_.nextNull(); - return (T)null; - } - else - { - return (T)map.get(p_read_1_.nextString()); - } - } - }; - } - } - - private String func_151232_a(Object p_151232_1_) - { - return p_151232_1_ instanceof Enum ? ((Enum)p_151232_1_).name().toLowerCase(Locale.US) : p_151232_1_.toString().toLowerCase(Locale.US); - } -} diff --git a/proxy/src/main/java/proxy/util/GameProfile.java b/proxy/src/main/java/proxy/util/GameProfile.java deleted file mode 100644 index 4cedbb2..0000000 --- a/proxy/src/main/java/proxy/util/GameProfile.java +++ /dev/null @@ -1,64 +0,0 @@ -package proxy.util; - -import java.util.UUID; - -public class GameProfile { - private final UUID id; - private final String name; - private final PropertyMap properties = new PropertyMap(); - private boolean legacy; - - public GameProfile(UUID id, String name) { - this.id = id; - this.name = name; - } - - public UUID getId() { - return this.id; - } - - public String getName() { - return this.name; - } - - public PropertyMap getProperties() { - return this.properties; - } - - public boolean equals(Object o) { - if(this == o) { - return true; - } else if(o != null && this.getClass() == o.getClass()) { - GameProfile that = (GameProfile)o; - if(this.id != null) { - if(!this.id.equals(that.id)) { - return false; - } - } else if(that.id != null) { - return false; - } - - if(this.name != null) { - if(!this.name.equals(that.name)) { - return false; - } - } else if(that.name != null) { - return false; - } - - return true; - } else { - return false; - } - } - - public int hashCode() { - int result = this.id != null?this.id.hashCode():0; - result = 31 * result + (this.name != null?this.name.hashCode():0); - return result; - } - - public boolean isLegacy() { - return this.legacy; - } -} diff --git a/proxy/src/main/java/proxy/util/HoverAction.java b/proxy/src/main/java/proxy/util/HoverAction.java new file mode 100644 index 0000000..adb9de2 --- /dev/null +++ b/proxy/src/main/java/proxy/util/HoverAction.java @@ -0,0 +1,40 @@ +package proxy.util; + +import java.util.Map; + +import com.google.common.collect.Maps; + +public enum HoverAction { + SHOW_TEXT("show_text", true), + SHOW_ACHIEVEMENT("show_achievement", true), + SHOW_ITEM("show_item", true), + SHOW_ENTITY("show_entity", true); + + private static final Map LOOKUP = Maps.newHashMap(); + + private final boolean serialize; + private final String name; + + static { + for(HoverAction action : values()) { + LOOKUP.put(action.name, action); + } + } + + public static HoverAction getByName(String name) { + return LOOKUP.get(name); + } + + private HoverAction(String name, boolean serialize) { + this.name = name; + this.serialize = serialize; + } + + public boolean isSerialized() { + return this.serialize; + } + + public String getName() { + return this.name; + } +} \ No newline at end of file diff --git a/proxy/src/main/java/proxy/util/HoverEvent.java b/proxy/src/main/java/proxy/util/HoverEvent.java index d25c571..f7af3a0 100755 --- a/proxy/src/main/java/proxy/util/HoverEvent.java +++ b/proxy/src/main/java/proxy/util/HoverEvent.java @@ -1,57 +1,19 @@ package proxy.util; -import java.util.HashMap; -import java.util.Map; - public class HoverEvent { - private final HoverEvent.Action action; + private final HoverAction action; private final ChatComponent value; - public HoverEvent(HoverEvent.Action actionIn, ChatComponent valueIn) { - this.action = actionIn; - this.value = valueIn; + public HoverEvent(HoverAction action, ChatComponent value) { + this.action = action; + this.value = value; } - public HoverEvent.Action getAction() { + public HoverAction getAction() { return this.action; } public ChatComponent getValue() { return this.value; } - - public static enum Action { - SHOW_TEXT("show_text", true), - SHOW_ACHIEVEMENT("show_achievement", true), - SHOW_ITEM("show_item", true), - SHOW_ENTITY("show_entity", true); - - private static final Map nameMapping = new HashMap(); - - private final boolean allowedInChat; - private final String canonicalName; - - private Action(String canonicalNameIn, boolean allowedInChatIn) { - this.canonicalName = canonicalNameIn; - this.allowedInChat = allowedInChatIn; - } - - public boolean shouldAllowInChat() { - return this.allowedInChat; - } - - public String getCanonicalName() { - return this.canonicalName; - } - - public static HoverEvent.Action getValueByCanonicalName(String canonicalNameIn) { - return nameMapping.get(canonicalNameIn); - } - - static { - for(HoverEvent.Action hoverevent$action : values()) { - nameMapping.put(hoverevent$action.getCanonicalName(), hoverevent$action); - } - } - } } diff --git a/proxy/src/main/java/proxy/util/JsonEnumFactory.java b/proxy/src/main/java/proxy/util/JsonEnumFactory.java new file mode 100755 index 0000000..3f850c2 --- /dev/null +++ b/proxy/src/main/java/proxy/util/JsonEnumFactory.java @@ -0,0 +1,49 @@ +package proxy.util; + +import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Locale; +import java.util.Map; + +public class JsonEnumFactory implements TypeAdapterFactory { + public TypeAdapter create(Gson gson, TypeToken type) { + Class clazz = (Class)type.getRawType(); + if(!clazz.isEnum()) + return null; + final Map map = Maps.newHashMap(); + for(T t : clazz.getEnumConstants()) { + map.put(this.formatName(t), t); + } + return new TypeAdapter() { + public void write(JsonWriter writer, T data) throws IOException { + if(data == null) { + writer.nullValue(); + } + else { + writer.value(JsonEnumFactory.this.formatName(data)); + } + } + + public T read(JsonReader reader) throws IOException { + if(reader.peek() == JsonToken.NULL) { + reader.nextNull(); + return (T)null; + } + else { + return (T)map.get(reader.nextString()); + } + } + }; + } + + private String formatName(Object data) { + return data instanceof Enum ? ((Enum)data).name().toLowerCase(Locale.US) : data.toString().toLowerCase(Locale.US); + } +} diff --git a/proxy/src/main/java/proxy/util/PlayerInfo.java b/proxy/src/main/java/proxy/util/PlayerInfo.java new file mode 100644 index 0000000..bb2e12b --- /dev/null +++ b/proxy/src/main/java/proxy/util/PlayerInfo.java @@ -0,0 +1,78 @@ +package proxy.util; + +import java.lang.reflect.Type; +import java.util.UUID; + +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +public class PlayerInfo { + private final int capacity; + private final int online; + private Profile[] list; + + public PlayerInfo(int capacity, int online) { + this.capacity = capacity; + this.online = online; + } + + public int getCapacity() { + return this.capacity; + } + + public int getOnline() { + return this.online; + } + + public Profile[] getList() { + return this.list; + } + + public void setList(Profile[] list) { + this.list = list; + } + + public static class Serializer implements JsonDeserializer, JsonSerializer { + public PlayerInfo deserialize(JsonElement elem, Type type, JsonDeserializationContext context) throws JsonParseException { + JsonObject obj = JsonUtils.getJsonObject(elem, "players"); + PlayerInfo info = new PlayerInfo(JsonUtils.getInt(obj, "max"), JsonUtils.getInt(obj, "online")); + if(JsonUtils.isJsonArray(obj, "sample")) { + JsonArray arr = JsonUtils.getJsonArray(obj, "sample"); + if(arr.size() > 0) { + Profile[] list = new Profile[arr.size()]; + for(int z = 0; z < list.length; z++) { + JsonObject profile = JsonUtils.getJsonObject(arr.get(z), "player[" + z + "]"); + String id = JsonUtils.getString(profile, "id"); + list[z] = new Profile(UUID.fromString(id), JsonUtils.getString(profile, "name")); + } + info.setList(list); + } + } + return info; + } + + public JsonElement serialize(PlayerInfo info, Type type, JsonSerializationContext context) { + JsonObject obj = new JsonObject(); + obj.addProperty("max", info.getCapacity()); + obj.addProperty("online", info.getOnline()); + if(info.getList() != null && info.getList().length > 0) { + JsonArray arr = new JsonArray(); + for(int z = 0; z < info.getList().length; z++) { + JsonObject profile = new JsonObject(); + UUID id = info.getList()[z].getId(); + profile.addProperty("id", id == null ? "" : id.toString()); + profile.addProperty("name", info.getList()[z].getName()); + arr.add(profile); + } + obj.add("sample", arr); + } + return obj; + } + } +} \ No newline at end of file diff --git a/proxy/src/main/java/proxy/util/Profile.java b/proxy/src/main/java/proxy/util/Profile.java new file mode 100644 index 0000000..81bbf2c --- /dev/null +++ b/proxy/src/main/java/proxy/util/Profile.java @@ -0,0 +1,27 @@ +package proxy.util; + +import java.util.UUID; + +public class Profile { + private final UUID id; + private final String name; + private final PropertyMap properties = new PropertyMap(); + private boolean legacy; + + public Profile(UUID id, String name) { + this.id = id; + this.name = name; + } + + public UUID getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public PropertyMap getProperties() { + return this.properties; + } +} diff --git a/proxy/src/main/java/proxy/util/Property.java b/proxy/src/main/java/proxy/util/Property.java index e417251..1b8dfd9 100644 --- a/proxy/src/main/java/proxy/util/Property.java +++ b/proxy/src/main/java/proxy/util/Property.java @@ -1,33 +1,29 @@ package proxy.util; public class Property { - private final String name; - private final String value; - private final String signature; + private final String name; + private final String value; + private final String signature; - public Property(String value, String name) { - this(value, name, (String)null); - } + public Property(String value, String name) { + this(value, name, null); + } - public Property(String name, String value, String signature) { - this.name = name; - this.value = value; - this.signature = signature; - } + public Property(String name, String value, String signature) { + this.name = name; + this.value = value; + this.signature = signature; + } - public String getName() { - return this.name; - } + public String getName() { + return this.name; + } - public String getValue() { - return this.value; - } + public String getValue() { + return this.value; + } - public String getSignature() { - return this.signature; - } - - public boolean hasSignature() { - return this.signature != null; - } + public String getSignature() { + return this.signature; + } } diff --git a/proxy/src/main/java/proxy/util/PropertyMap.java b/proxy/src/main/java/proxy/util/PropertyMap.java index 7e750b2..f20012d 100644 --- a/proxy/src/main/java/proxy/util/PropertyMap.java +++ b/proxy/src/main/java/proxy/util/PropertyMap.java @@ -15,58 +15,53 @@ import java.lang.reflect.Type; import java.util.Map.Entry; public class PropertyMap extends ForwardingMultimap { - private final Multimap properties = LinkedHashMultimap.create(); + private final Multimap properties = LinkedHashMultimap.create(); - protected Multimap delegate() { - return this.properties; - } + protected Multimap delegate() { + return this.properties; + } - public static class Serializer implements JsonSerializer, JsonDeserializer { - public PropertyMap deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - PropertyMap result = new PropertyMap(); - if(json instanceof JsonObject) { - JsonObject object = (JsonObject)json; + public static class Serializer implements JsonSerializer, JsonDeserializer { + public PropertyMap deserialize(JsonElement elem, Type type, JsonDeserializationContext context) throws JsonParseException { + PropertyMap properties = new PropertyMap(); + if(elem instanceof JsonObject) { + JsonObject obj = (JsonObject)elem; + for(Entry entry : obj.entrySet()) { + if(entry.getValue() instanceof JsonArray) { + for(JsonElement element : (JsonArray)entry.getValue()) { + properties.put(entry.getKey(), new Property(entry.getKey(), element.getAsString())); + } + } + } + } + else if(elem instanceof JsonArray) { + for(JsonElement element : (JsonArray)elem) { + if(element instanceof JsonObject) { + JsonObject obj = (JsonObject)element; + String name = obj.getAsJsonPrimitive("name").getAsString(); + String value = obj.getAsJsonPrimitive("value").getAsString(); + if(obj.has("signature")) + properties.put(name, new Property(name, value, obj.getAsJsonPrimitive("signature").getAsString())); + else + properties.put(name, new Property(name, value)); + } + } + } - for(Entry entry : object.entrySet()) { - if(entry.getValue() instanceof JsonArray) { - for(JsonElement element : (JsonArray)entry.getValue()) { - result.put(entry.getKey(), new Property((String)entry.getKey(), element.getAsString())); - } - } - } - } else if(json instanceof JsonArray) { - for(JsonElement element : (JsonArray)json) { - if(element instanceof JsonObject) { - JsonObject object = (JsonObject)element; - String name = object.getAsJsonPrimitive("name").getAsString(); - String value = object.getAsJsonPrimitive("value").getAsString(); - if(object.has("signature")) { - result.put(name, new Property(name, value, object.getAsJsonPrimitive("signature").getAsString())); - } else { - result.put(name, new Property(name, value)); - } - } - } - } + return properties; + } - return result; - } - - public JsonElement serialize(PropertyMap src, Type typeOfSrc, JsonSerializationContext context) { - JsonArray result = new JsonArray(); - - for(Property property : src.values()) { - JsonObject object = new JsonObject(); - object.addProperty("name", property.getName()); - object.addProperty("value", property.getValue()); - if(property.hasSignature()) { - object.addProperty("signature", property.getSignature()); - } - - result.add(object); - } - - return result; - } - } + public JsonElement serialize(PropertyMap properties, Type type, JsonSerializationContext context) { + JsonArray arr = new JsonArray(); + for(Property property : properties.values()) { + JsonObject obj = new JsonObject(); + obj.addProperty("name", property.getName()); + obj.addProperty("value", property.getValue()); + if(property.getSignature() != null) + obj.addProperty("signature", property.getSignature()); + arr.add(obj); + } + return arr; + } + } } diff --git a/proxy/src/main/java/proxy/util/ServerInfo.java b/proxy/src/main/java/proxy/util/ServerInfo.java new file mode 100755 index 0000000..e2d39e2 --- /dev/null +++ b/proxy/src/main/java/proxy/util/ServerInfo.java @@ -0,0 +1,78 @@ +package proxy.util; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; + +public class ServerInfo { + private ChatComponent motd; + private PlayerInfo info; + private VersionId version; + private String icon; + + public ChatComponent getMotd() { + return this.motd; + } + + public void setMotd(ChatComponent motd) { + this.motd = motd; + } + + public PlayerInfo getInfo() { + return this.info; + } + + public void setInfo(PlayerInfo info) { + this.info = info; + } + + public VersionId getVersion() { + return this.version; + } + + public void setVersion(VersionId version) { + this.version = version; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getIcon() { + return this.icon; + } + + public static class Serializer implements JsonDeserializer, JsonSerializer { + public ServerInfo deserialize(JsonElement elem, Type type, JsonDeserializationContext context) throws JsonParseException { + JsonObject obj = JsonUtils.getJsonObject(elem, "status"); + ServerInfo status = new ServerInfo(); + if(obj.has("description")) + status.setMotd((ChatComponent)context.deserialize(obj.get("description"), ChatComponent.class)); + if(obj.has("players")) + status.setInfo((PlayerInfo)context.deserialize(obj.get("players"), PlayerInfo.class)); + if(obj.has("version")) + status.setVersion((VersionId)context.deserialize(obj.get("version"), VersionId.class)); + if(obj.has("favicon")) + status.setIcon(JsonUtils.getString(obj, "favicon")); + return status; + } + + public JsonElement serialize(ServerInfo status, Type type, JsonSerializationContext context) { + JsonObject obj = new JsonObject(); + if(status.getMotd() != null) + obj.add("description", context.serialize(status.getMotd())); + if(status.getInfo() != null) + obj.add("players", context.serialize(status.getInfo())); + if(status.getVersion() != null) + obj.add("version", context.serialize(status.getVersion())); + if(status.getIcon() != null) + obj.addProperty("favicon", status.getIcon()); + return obj; + } + } +} diff --git a/proxy/src/main/java/proxy/util/ItemStack.java b/proxy/src/main/java/proxy/util/Stack.java similarity index 66% rename from proxy/src/main/java/proxy/util/ItemStack.java rename to proxy/src/main/java/proxy/util/Stack.java index ebf6ddc..4f3adf5 100755 --- a/proxy/src/main/java/proxy/util/ItemStack.java +++ b/proxy/src/main/java/proxy/util/Stack.java @@ -2,27 +2,23 @@ package proxy.util; import proxy.nbt.NBTTagCompound; -public final class ItemStack { +public final class Stack { private final short id; private final byte size; private final short meta; private final NBTTagCompound tag; - public ItemStack(short id, byte size, short meta, NBTTagCompound tag) { + public Stack(short id, byte size, short meta, NBTTagCompound tag) { this.id = id; this.size = size; this.meta = meta; this.tag = tag; } - public ItemStack copy() { - return new ItemStack(this.id, this.size, this.meta, (NBTTagCompound)this.tag.copy()); - } - public short getId() { return this.id; } - + public byte getSize() { return this.size; } diff --git a/proxy/src/main/java/proxy/util/Vec3.java b/proxy/src/main/java/proxy/util/Vec3.java new file mode 100755 index 0000000..d643621 --- /dev/null +++ b/proxy/src/main/java/proxy/util/Vec3.java @@ -0,0 +1,35 @@ +package proxy.util; + +public class Vec3 { + private final int x; + private final int y; + private final int z; + + public Vec3(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Vec3(long data) { + this.x = (int)(data << 64 - 38 - 26 >> 64 - 26); + this.y = (int)(data << 64 - 26 - 12 >> 64 - 12); + this.z = (int)(data << 64 - 26 >> 64 - 26); + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public long getData() { + return ((long)this.getX() & 0x3ffffff) << 38 | ((long)this.getY() & 0xfff) << 26 | ((long)this.getZ() & 0x3ffffff) << 0; + } +} diff --git a/proxy/src/main/java/proxy/util/Vec3f.java b/proxy/src/main/java/proxy/util/Vec3f.java new file mode 100644 index 0000000..735bfe8 --- /dev/null +++ b/proxy/src/main/java/proxy/util/Vec3f.java @@ -0,0 +1,25 @@ +package proxy.util; + +public class Vec3f { + private final float x; + private final float y; + private final float z; + + public Vec3f(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + public float getX() { + return this.x; + } + + public float getY() { + return this.y; + } + + public float getZ() { + return this.z; + } +} \ No newline at end of file diff --git a/proxy/src/main/java/proxy/util/VersionId.java b/proxy/src/main/java/proxy/util/VersionId.java new file mode 100644 index 0000000..d0ef9a3 --- /dev/null +++ b/proxy/src/main/java/proxy/util/VersionId.java @@ -0,0 +1,43 @@ +package proxy.util; + +import java.lang.reflect.Type; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +public class VersionId { + private final String name; + private final int protocol; + + public VersionId(String name, int protocol) { + this.name = name; + this.protocol = protocol; + } + + public String getName() { + return this.name; + } + + public int getProtocol() { + return this.protocol; + } + + public static class Serializer implements JsonDeserializer, JsonSerializer { + public VersionId deserialize(JsonElement elem, Type type, JsonDeserializationContext context) throws JsonParseException { + JsonObject obj = JsonUtils.getJsonObject(elem, "version"); + return new VersionId(JsonUtils.getString(obj, "name"), JsonUtils.getInt(obj, "protocol")); + } + + public JsonElement serialize(VersionId version, Type type, JsonSerializationContext context) { + JsonObject obj = new JsonObject(); + obj.addProperty("name", version.getName()); + obj.addProperty("protocol", (Number)Integer.valueOf(version.getProtocol())); + return obj; + } + } +} \ No newline at end of file