diff --git a/ProtocolLib/src/com/comphenix/protocol/reflect/compiler/StructureCompiler.java b/ProtocolLib/src/com/comphenix/protocol/reflect/compiler/StructureCompiler.java index 2b989f9e..438aca91 100644 --- a/ProtocolLib/src/com/comphenix/protocol/reflect/compiler/StructureCompiler.java +++ b/ProtocolLib/src/com/comphenix/protocol/reflect/compiler/StructureCompiler.java @@ -42,7 +42,7 @@ import net.sf.cglib.asm.*; // case 6: return (TField) (Object) target.g; // case 7: return (TField) (Object) target.h; // default: -// throw new IllegalArgumentException("Invalid index " + fieldIndex); +// throw new FieldAccessException("Invalid index " + fieldIndex); // } // } // @@ -61,7 +61,7 @@ import net.sf.cglib.asm.*; // case 6: target.g = (Byte) value; break; // case 7: target.h = (Integer) value; break; // default: -// throw new IllegalArgumentException("Invalid index " + index); +// throw new FieldAccessException("Invalid index " + index); // } // // // Chaining @@ -181,6 +181,16 @@ public final class StructureCompiler { String targetSignature = Type.getDescriptor(targetType); String targetName = targetType.getName().replace('.', '/'); + try { + // This class might have been generated before. Try to load it. + Class before = loader.loadClass(PACKAGE_NAME.replace('/', '.') + "." + className); + + if (before != null) + return before; + } catch (ClassNotFoundException e) { + // That's ok. + } + cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, PACKAGE_NAME + "/" + className, "L" + COMPILED_CLASS + ";", COMPILED_CLASS, null);