Fix deserialization problems

This commit is contained in:
okx-code
2021-11-02 21:44:02 +00:00
parent 50ccfd4266
commit 80f5808d56
4 changed files with 26 additions and 9 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ plugins {
}
group 'sh.okx'
version '3.13'
version '3.13.1'
java {
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -35,9 +35,9 @@ public class RanksGui {
ConfigurationSection basePath = plugin.getMessages().getConfigurationSection("rankup.ranksgui");
String title = get(ConfigurationSection::getString, "title", playerPath, basePath, "Ranks");
int rows = get(ConfigurationSection::getInt, "rows", playerPath, basePath, 3);
int offset = get(ConfigurationSection::getInt, "offset", playerPath, basePath, 10);
int width = get(ConfigurationSection::getInt, "width", playerPath, basePath, 7);
int rows = get(this::getInt, "rows", playerPath, basePath, 3);
int offset = get(this::getInt, "offset", playerPath, basePath, 10);
int width = get(this::getInt, "width", playerPath, basePath, 7);
inventory = Bukkit.createInventory(null, rows * 9, Colour.translate(title));
@@ -87,6 +87,19 @@ public class RanksGui {
player.openInventory(inventory);
}
private Integer getInt(ConfigurationSection section, String key) {
String string = section.getString(key);
if (string == null) {
return null;
} else {
try {
return Integer.parseInt(string);
} catch (IllegalArgumentException ex) {
return null;
}
}
}
private <T> T get(BiFunction<ConfigurationSection, String, T> fun, String path, ConfigurationSection primary, ConfigurationSection secondary, T def) {
T get = null;
if (primary != null) {
@@ -57,10 +57,12 @@ public class ShadowDeserializer {
private static void updateMap(Map<String, String> map, UnmodifiableConfig config, String prefix) {
for (Entry message : config.entrySet()) {
Object value = message.getValue();
if (value instanceof String) {
map.put(prefix + message.getKey(), (String) value);
} else if (value instanceof UnmodifiableConfig) {
if (value != null) {
if (value instanceof UnmodifiableConfig) {
updateMap(map, (UnmodifiableConfig) value, prefix + message.getKey() + ".");
} else {
map.put(prefix + message.getKey(), String.valueOf(value));
}
}
}
}
@@ -43,8 +43,10 @@ public class YamlDeserializer {
Set<String> rankup = rankupSection.getKeys(true);
messages = new HashMap<>(rankup.size());
for (String key : rankup) {
if (!rankupSection.isConfigurationSection(key)) {
messages.put(MemorySection.createPath(rankupSection, key, section), rankupSection.getString(key));
}
}
} else {
messages = Collections.emptyMap();
}