diff --git a/modules/API/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java b/modules/API/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java index 2744fbe5..37902ae5 100644 --- a/modules/API/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java +++ b/modules/API/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java @@ -453,6 +453,17 @@ public class StructureModifier { */ @SuppressWarnings("unchecked") public StructureModifier withType(Class fieldType, EquivalentConverter converter) { + if (fieldType == null) { + // It's not supported in this version, so return an empty modifier + return new StructureModifier() { + @Override + public T read(int index) { return null; } + + @Override + public StructureModifier write(int index, T value) { return this; } + }; + } + StructureModifier result = subtypeCache.get(fieldType); // Do we need to update the cache? @@ -462,7 +473,7 @@ public class StructureModifier { int index = 0; for (Field field : data) { - if (fieldType != null && fieldType.isAssignableFrom(field.getType())) { + if (fieldType.isAssignableFrom(field.getType())) { filtered.add(field); // Don't use the original index @@ -476,14 +487,12 @@ public class StructureModifier { // Cache structure modifiers result = withFieldType(fieldType, filtered, defaults); - - if (fieldType != null) { - subtypeCache.put(fieldType, result); + + subtypeCache.put(fieldType, result); - // Automatically compile the structure modifier - if (useStructureCompiler && BackgroundCompiler.getInstance() != null) - BackgroundCompiler.getInstance().scheduleCompilation(subtypeCache, fieldType); - } + // Automatically compile the structure modifier + if (useStructureCompiler && BackgroundCompiler.getInstance() != null) + BackgroundCompiler.getInstance().scheduleCompilation(subtypeCache, fieldType); } // Add the target too