From 4ce846a899ba65f5535881ce37e6cf1de5572ed1 Mon Sep 17 00:00:00 2001 From: Myles Date: Tue, 22 Mar 2016 19:37:15 +0000 Subject: [PATCH] Make more errors informative :) --- .../us/myles/ViaVersion/api/PacketWrapper.java | 14 +++++++++----- .../protocols/base/BaseProtocol.java | 6 +++--- .../packets/PlayerPackets.java | 2 +- .../protocol1_9to1_8/packets/SpawnPackets.java | 18 +++++++++--------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index d15938f04..31d16deed 100644 --- a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -39,7 +39,7 @@ public class PacketWrapper { * @param index The index of the part (relative to the type) * @return The requested type or throws ArrayIndexOutOfBounds */ - public T get(Type type, int index) { + public T get(Type type, int index) throws Exception { int currentIndex = 0; for (Pair packetValue : packetValues) { if (packetValue.getKey() == type) { // Ref check @@ -49,7 +49,9 @@ public class PacketWrapper { currentIndex++; } } - throw new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index); + + Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index); + throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()); } /** @@ -59,7 +61,7 @@ public class PacketWrapper { * @param index The index of the part (relative to the type) * @param value The value of the part you wish to set it to. */ - public void set(Type type, int index, T value) { + public void set(Type type, int index, T value) throws Exception { int currentIndex = 0; for (Pair packetValue : packetValues) { if (packetValue.getKey() == type) { // Ref check @@ -70,7 +72,8 @@ public class PacketWrapper { currentIndex++; } } - throw new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index); + Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index); + throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()); } /** @@ -98,7 +101,8 @@ public class PacketWrapper { if (type == Type.NOTHING) { return read(type); // retry } else { - throw new IOException("Unable to read type " + type.getTypeName() + ", found " + read.getKey().getTypeName()); + Exception e = new IOException("Unable to read type " + type.getTypeName() + ", found " + read.getKey().getTypeName()); + throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()); } } } diff --git a/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java b/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java index 83265907c..be0ba0638 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java +++ b/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java @@ -34,7 +34,7 @@ public class BaseProtocol extends Protocol { map(Type.STRING); handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { ProtocolInfo info = wrapper.user().get(ProtocolInfo.class); String originalStatus = wrapper.get(Type.STRING, 0); try { @@ -73,7 +73,7 @@ public class BaseProtocol extends Protocol { map(Type.STRING); // 1 - Player Username handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { ProtocolInfo info = wrapper.user().get(ProtocolInfo.class); info.setState(State.PLAY); // Save other info @@ -101,7 +101,7 @@ public class BaseProtocol extends Protocol { map(Type.VAR_INT); // 3 - Next State handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { int protVer = wrapper.get(Type.VAR_INT, 0); int state = wrapper.get(Type.VAR_INT, 1); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index b8760c4f6..9a82c0691 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -145,7 +145,7 @@ public class PlayerPackets { // Parse this info handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception{ int entityID = wrapper.get(Type.INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.getClientEntityTypes().put(entityID, EntityType.PLAYER); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java index a48b17f6b..8e8b318cb 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java @@ -34,7 +34,7 @@ public class SpawnPackets { create(new ValueCreator() { @Override - public void write(PacketWrapper wrapper) { + public void write(PacketWrapper wrapper) throws Exception { int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID @@ -45,7 +45,7 @@ public class SpawnPackets { // Parse this info handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { int entityID = wrapper.get(Type.VAR_INT, 0); int typeID = wrapper.get(Type.BYTE, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); @@ -92,7 +92,7 @@ public class SpawnPackets { // Parse this info handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.getClientEntityTypes().put(entityID, EntityType.EXPERIENCE_ORB); @@ -116,7 +116,7 @@ public class SpawnPackets { // Parse this info handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { // Currently only lightning uses this int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); @@ -138,7 +138,7 @@ public class SpawnPackets { create(new ValueCreator() { @Override - public void write(PacketWrapper wrapper) { + public void write(PacketWrapper wrapper) throws Exception { int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID @@ -149,7 +149,7 @@ public class SpawnPackets { // Parse this info handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { int entityID = wrapper.get(Type.VAR_INT, 0); int typeID = wrapper.get(Type.UNSIGNED_BYTE, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); @@ -205,7 +205,7 @@ public class SpawnPackets { // Parse this info handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.getClientEntityTypes().put(entityID, EntityType.PAINTING); @@ -215,7 +215,7 @@ public class SpawnPackets { create(new ValueCreator() { @Override - public void write(PacketWrapper wrapper) { + public void write(PacketWrapper wrapper) throws Exception { int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID @@ -282,7 +282,7 @@ public class SpawnPackets { handler(new PacketHandler() { @Override - public void handle(PacketWrapper wrapper) { + public void handle(PacketWrapper wrapper) throws Exception { Integer[] entities = wrapper.get(Type.VAR_INT_ARRAY, 0); for (Integer entity : entities) { // EntityTracker