mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-18 20:41:32 +01:00
Migrate CustomizableGui from old Config to SongodaYamlConfig
This commit is contained in:
parent
20b7a353b8
commit
d5ddde3e08
@ -2,8 +2,8 @@ package com.songoda.core.gui;
|
|||||||
|
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import com.songoda.core.compatibility.ServerVersion;
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
import com.songoda.core.configuration.Config;
|
import com.songoda.core.configuration.songoda.ConfigEntry;
|
||||||
import com.songoda.core.configuration.ConfigSection;
|
import com.songoda.core.configuration.songoda.SongodaYamlConfig;
|
||||||
import com.songoda.core.gui.methods.Clickable;
|
import com.songoda.core.gui.methods.Clickable;
|
||||||
import com.songoda.core.utils.TextUtils;
|
import com.songoda.core.utils.TextUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -16,6 +16,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -45,70 +46,89 @@ public class CustomizableGui extends Gui {
|
|||||||
localeFolder.mkdir();
|
localeFolder.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
Config config = new Config(plugin, "gui/" + guiKey + ".yml");
|
SongodaYamlConfig config = new SongodaYamlConfig(new File(plugin.getDataFolder(), "gui/" + guiKey + ".yml"));
|
||||||
|
try {
|
||||||
config.load();
|
config.load();
|
||||||
|
} catch (IOException ex) {
|
||||||
if (!config.isConfigurationSection("overrides")) {
|
// FIXME
|
||||||
config.setDefault("overrides.example.item", CompatibleMaterial.STONE.name(),
|
throw new RuntimeException(ex);
|
||||||
"This is the icon material you would like to replace",
|
|
||||||
"the current material with.")
|
|
||||||
.setDefault("overrides.example.position", 5,
|
|
||||||
"This is the current position of the icon you would like to move.",
|
|
||||||
"The number represents the cell the icon currently resides in.")
|
|
||||||
.setDefaultComment("overrides.example",
|
|
||||||
"This is just an example and does not override to any items",
|
|
||||||
"in this GUI.")
|
|
||||||
.setDefaultComment("overrides",
|
|
||||||
"For information on how to apply overrides please visit",
|
|
||||||
"https://wiki.songoda.com/Gui");
|
|
||||||
|
|
||||||
config.saveChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.isConfigurationSection("disabled")) {
|
config.setNodeComment("overrides", "For information on how to apply overrides please visit\n" +
|
||||||
config.setDefault("disabled", Arrays.asList("example3", "example4", "example5"),
|
"https://wiki.songoda.com/Gui");
|
||||||
"All keys on this list will be disabled. You can add any items key here",
|
config.setNodeComment("overrides.example", "This is just an example and does not override to any items in this GUI.");
|
||||||
|
|
||||||
|
new ConfigEntry(config, "overrides.example.item", CompatibleMaterial.STONE)
|
||||||
|
.withComment("This is the icon material you would like to replace\n" +
|
||||||
|
"the current material with.");
|
||||||
|
new ConfigEntry(config, "overrides.example.position", 5)
|
||||||
|
.withComment("This is the current position of the icon you would like to move.\n" +
|
||||||
|
"The number represents the cell the icon currently resides in.");
|
||||||
|
|
||||||
|
ConfigEntry disabledGuis = new ConfigEntry(config, "disabled", Arrays.asList("example3", "example4", "example5"))
|
||||||
|
.withComment("All keys on this list will be disabled. You can add any items key here\n" +
|
||||||
"if you no longer want that item in the GUI.");
|
"if you no longer want that item in the GUI.");
|
||||||
|
|
||||||
config.saveChanges();
|
try {
|
||||||
|
config.save();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
// FIXME
|
||||||
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomContent customContent = loadedGuis.computeIfAbsent(guiKey, g -> new CustomContent(guiKey));
|
CustomContent customContent = loadedGuis.computeIfAbsent(guiKey, g -> new CustomContent(guiKey));
|
||||||
loadedGuis.put(guiKey, customContent);
|
loadedGuis.put(guiKey, customContent);
|
||||||
this.customContent = customContent;
|
this.customContent = customContent;
|
||||||
|
|
||||||
int rows = config.getInt("overrides.__ROWS__", -1);
|
int rows = config.getAsEntry("overrides.__ROWS__").getInt(-1);
|
||||||
if (rows != -1) {
|
if (rows != -1) {
|
||||||
customContent.setRows(rows);
|
customContent.setRows(rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ConfigSection section : config.getSections("overrides")) {
|
for (String overrideKey : config.getKeys("overrides")) {
|
||||||
if (section.contains("row") ||
|
String keyPrefix = "overrides." + overrideKey;
|
||||||
section.contains("col") ||
|
|
||||||
section.contains("mirrorrow") ||
|
ConfigEntry title = config.getAsEntry(keyPrefix + ".title");
|
||||||
section.contains("mirrorcol")) {
|
|
||||||
if (section.contains("mirrorrow") || section.contains("mirrorcol")) {
|
ConfigEntry position = config.getAsEntry(keyPrefix + ".position");
|
||||||
customContent.addButton(section.getNodeKey(), section.getInt("row", -1),
|
|
||||||
section.getInt("col", -1),
|
ConfigEntry row = config.getAsEntry(keyPrefix + ".row");
|
||||||
section.getBoolean("mirrorrow", false),
|
ConfigEntry col = config.getAsEntry(keyPrefix + ".col");
|
||||||
section.getBoolean("mirrorcol", false),
|
|
||||||
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null);
|
ConfigEntry mirrorRow = config.getAsEntry(keyPrefix + ".mirrorrow");
|
||||||
|
ConfigEntry mirrorCol = config.getAsEntry(keyPrefix + ".mirrorcol");
|
||||||
|
|
||||||
|
ConfigEntry item = config.getAsEntry(keyPrefix + ".item");
|
||||||
|
ConfigEntry lore = config.getAsEntry(keyPrefix + ".lore");
|
||||||
|
|
||||||
|
boolean configHasRowOrColSet = row.has() || col.has();
|
||||||
|
boolean configHasMirrorRowOrColSet = mirrorRow.has() || mirrorCol.has();
|
||||||
|
|
||||||
|
if (configHasMirrorRowOrColSet) {
|
||||||
|
customContent.addButton(overrideKey,
|
||||||
|
row.getInt(-1),
|
||||||
|
col.getInt(-1),
|
||||||
|
mirrorRow.getBoolean(),
|
||||||
|
mirrorCol.getBoolean(),
|
||||||
|
item.getMaterial());
|
||||||
|
} else if (configHasRowOrColSet) {
|
||||||
|
customContent.addButton(overrideKey,
|
||||||
|
row.getInt(-1),
|
||||||
|
col.getInt(-1),
|
||||||
|
title.getString(),
|
||||||
|
lore.getStringList(),
|
||||||
|
item.getMaterial());
|
||||||
} else {
|
} else {
|
||||||
customContent.addButton(section.getNodeKey(), section.getInt("row", -1),
|
customContent.addButton(overrideKey,
|
||||||
section.getInt("col", -1),
|
position.getString("-1"),
|
||||||
section.getString("title", null),
|
title.getString(),
|
||||||
section.isSet("lore") ? section.getStringList("lore") : null,
|
lore.getStringList(),
|
||||||
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null);
|
item.getMaterial());
|
||||||
}
|
|
||||||
} else {
|
|
||||||
customContent.addButton(section.getNodeKey(), section.getString("position", "-1"),
|
|
||||||
section.getString("title", null),
|
|
||||||
section.isSet("lore") ? section.getStringList("lore") : null,
|
|
||||||
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String disabled : config.getStringList("disabled")) {
|
for (String disabled : disabledGuis.getStringList(Collections.emptyList())) {
|
||||||
customContent.disableButton(disabled);
|
customContent.disableButton(disabled);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user