Small fix for property deserialization
This commit is contained in:
parent
4c8d25c4df
commit
dd3eda5512
4 changed files with 14 additions and 6 deletions
|
@ -63,7 +63,7 @@ public class PropertySetCommand implements CommandHandler {
|
||||||
valueName = "NONE";
|
valueName = "NONE";
|
||||||
}
|
}
|
||||||
else if (type == ParrotVariant.class && context.argSize() < 1 && npc.getProperty(property) != null) {
|
else if (type == ParrotVariant.class && context.argSize() < 1 && npc.getProperty(property) != null) {
|
||||||
value = ParrotVariant.NONE;
|
value = null;
|
||||||
valueName = "NONE";
|
valueName = "NONE";
|
||||||
}
|
}
|
||||||
else if (type == BlockState.class) {
|
else if (type == BlockState.class) {
|
||||||
|
|
|
@ -15,7 +15,11 @@ public class EnumPropertySerializer<T extends Enum<T>> implements PropertySerial
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T deserialize(String property) {
|
public T deserialize(String property) {
|
||||||
return Enum.valueOf(enumClass, property.toUpperCase());
|
try {
|
||||||
|
return Enum.valueOf(enumClass, property.toUpperCase());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,13 +10,12 @@ public class IntegerPropertySerializer implements PropertySerializer<Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer deserialize(String property) {
|
public Integer deserialize(String property) {
|
||||||
int i = 0;
|
|
||||||
try {
|
try {
|
||||||
i = Integer.parseInt(property);
|
return Integer.parseInt(property);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return i;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 ...");
|
Bukkit.getLogger().log(Level.WARNING, "Unknown serializer for property '" + key + "' for npc '" + config.getString("id") + "'. skipping ...");
|
||||||
continue;
|
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();
|
HologramImpl hologram = npc.getHologram();
|
||||||
|
|
Loading…
Reference in a new issue