diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index 3ea0074..0380025 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -63,7 +63,7 @@ public class PropertySetCommand implements CommandHandler { valueName = "NONE"; } else if (type == ParrotVariant.class && context.argSize() < 1 && npc.getProperty(property) != null) { - value = ParrotVariant.NONE; + value = null; valueName = "NONE"; } else if (type == BlockState.class) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EnumPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EnumPropertySerializer.java index c9a93c8..d71fb07 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EnumPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EnumPropertySerializer.java @@ -15,7 +15,11 @@ public class EnumPropertySerializer> implements PropertySerial @Override public T deserialize(String property) { - return Enum.valueOf(enumClass, property.toUpperCase()); + try { + return Enum.valueOf(enumClass, property.toUpperCase()); + } catch (IllegalArgumentException e) { + return null; + } } @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java index 4ef2ff5..e918668 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/IntegerPropertySerializer.java @@ -10,13 +10,12 @@ public class IntegerPropertySerializer implements PropertySerializer { @Override public Integer deserialize(String property) { - int i = 0; try { - i = Integer.parseInt(property); + return Integer.parseInt(property); } catch (NumberFormatException e) { e.printStackTrace(); } - return i; + return null; } @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java index 8325cc9..032a916 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/storage/yaml/YamlStorage.java @@ -70,7 +70,12 @@ public class YamlStorage implements NpcStorage { Bukkit.getLogger().log(Level.WARNING, "Unknown serializer for property '" + key + "' for npc '" + config.getString("id") + "'. skipping ..."); continue; } - npc.UNSAFE_setProperty(property, serializer.deserialize(properties.getString(key))); + Object value = serializer.deserialize(properties.getString(key)); + if (value == null) { + Bukkit.getLogger().log(Level.WARNING, "Failed to deserialize property '" + key + "' for npc '" + config.getString("id") + "'. Resetting to default ..."); + value = property.getDefaultValue(); + } + npc.UNSAFE_setProperty(property, value); } } HologramImpl hologram = npc.getHologram();