Make more errors informative :)

This commit is contained in:
Myles 2016-03-22 19:37:15 +00:00
parent ef08117f34
commit 4ce846a899
4 changed files with 22 additions and 18 deletions

View File

@ -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> T get(Type<T> type, int index) {
public <T> T get(Type<T> type, int index) throws Exception {
int currentIndex = 0;
for (Pair<Type, Object> 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 <T> void set(Type<T> type, int index, T value) {
public <T> void set(Type<T> type, int index, T value) throws Exception {
int currentIndex = 0;
for (Pair<Type, Object> 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());
}
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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