From 1872845d2b4e9032e46eedab16e397d1fd4e0bea Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 30 Mar 2016 15:58:31 +0100 Subject: [PATCH] Add additional information when packets aren't sent correctly. --- .../java/us/myles/ViaVersion/api/PacketWrapper.java | 8 ++++---- src/main/java/us/myles/ViaVersion/api/Pair.java | 7 +++++-- .../us/myles/ViaVersion/api/minecraft/Position.java | 2 ++ .../myles/ViaVersion/api/minecraft/chunks/Chunk.java | 2 ++ .../us/myles/ViaVersion/api/minecraft/item/Item.java | 6 ++---- .../ViaVersion/api/minecraft/metadata/Metadata.java | 10 ++++++++++ src/main/java/us/myles/ViaVersion/api/type/Type.java | 5 +++++ 7 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 860e1161a..47d9b690e 100644 --- a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -52,7 +52,7 @@ public class PacketWrapper { } 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()); + throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()).set("Data", packetValues); } /** @@ -92,7 +92,7 @@ public class PacketWrapper { try { return type.read(inputBuffer); } catch (Exception e) { - throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()); + throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Data", packetValues); } } else { Pair read = readableObjects.poll(); @@ -103,7 +103,7 @@ public class PacketWrapper { return read(type); // retry } else { 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()); + throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Data", packetValues); } } } @@ -172,7 +172,7 @@ public class PacketWrapper { } packetValue.getKey().write(buffer, value); } catch (Exception e) { - throw new InformativeException(e).set("Index", index).set("Type", packetValue.getKey().getTypeName()).set("Packet ID", getId()); + throw new InformativeException(e).set("Index", index).set("Type", packetValue.getKey().getTypeName()).set("Packet ID", getId()).set("Data", packetValues); } index++; } diff --git a/src/main/java/us/myles/ViaVersion/api/Pair.java b/src/main/java/us/myles/ViaVersion/api/Pair.java index 2f744bb9b..ae1ccf19e 100644 --- a/src/main/java/us/myles/ViaVersion/api/Pair.java +++ b/src/main/java/us/myles/ViaVersion/api/Pair.java @@ -3,12 +3,10 @@ package us.myles.ViaVersion.api; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import lombok.ToString; @Getter @Setter @EqualsAndHashCode -@ToString public class Pair { private X key; private Y value; @@ -17,4 +15,9 @@ public class Pair { this.key = key; this.value = value; } + + @Override + public String toString() { + return "Pair{" + key + ", " + value + '}'; + } } diff --git a/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java b/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java index 7d59aba0f..33ec6d103 100644 --- a/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java @@ -2,9 +2,11 @@ package us.myles.ViaVersion.api.minecraft; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.ToString; @AllArgsConstructor @Getter +@ToString public class Position { private Long x; private Long y; diff --git a/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java b/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java index ec2d1761c..a167a261d 100644 --- a/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java @@ -2,9 +2,11 @@ package us.myles.ViaVersion.api.minecraft.chunks; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; @RequiredArgsConstructor @Getter +@ToString public class Chunk { private final int x; private final int z; diff --git a/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java b/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java index 022c4d50d..35209c2e6 100644 --- a/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java @@ -1,9 +1,6 @@ package us.myles.ViaVersion.api.minecraft.item; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.bukkit.inventory.ItemStack; import org.spacehq.opennbt.tag.builtin.CompoundTag; @@ -11,6 +8,7 @@ import org.spacehq.opennbt.tag.builtin.CompoundTag; @Setter @NoArgsConstructor @AllArgsConstructor +@ToString public class Item { private short id; private byte amount; diff --git a/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java b/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java index adefbd856..58215b791 100644 --- a/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java @@ -13,4 +13,14 @@ public class Metadata { private int typeID; private Type type; private Object value; + + @Override + public String toString() { + return "Metadata{" + + "id=" + id + + ", typeID=" + typeID + + ", type=" + type + + ", value=" + value + + '}'; + } } diff --git a/src/main/java/us/myles/ViaVersion/api/type/Type.java b/src/main/java/us/myles/ViaVersion/api/type/Type.java index 3d10ab997..53cdb5dfc 100644 --- a/src/main/java/us/myles/ViaVersion/api/type/Type.java +++ b/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -77,4 +77,9 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { this.outputClass = outputClass; this.typeName = typeName; } + + @Override + public String toString() { + return "Type|" + getTypeName(); + } }