Small fix for property deserialization

This commit is contained in:
D3v1s0m 2023-09-12 22:53:58 +05:30
parent 4c8d25c4df
commit dd3eda5512
No known key found for this signature in database
GPG Key ID: FA1F770C7B1D40C1
4 changed files with 14 additions and 6 deletions

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

@ -15,7 +15,11 @@ public class EnumPropertySerializer<T extends Enum<T>> 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

@ -10,13 +10,12 @@ public class IntegerPropertySerializer implements PropertySerializer<Integer> {
@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

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