Refactor/rework
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package com.alttd.playershops.config;
|
||||
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class GuiIconConfig {
|
||||
|
||||
|
||||
private final String icon;
|
||||
private final String configPath;
|
||||
private final String defaultPath;
|
||||
public GuiIconConfig(String icon) {
|
||||
this.icon = icon;
|
||||
this.configPath = "gui-icon." + this.icon + ".";
|
||||
this.defaultPath = "gui-icon.divider.";
|
||||
init();
|
||||
}
|
||||
|
||||
static int version;
|
||||
|
||||
public void init() {
|
||||
Config.config.readConfig(GuiIconConfig.class, this);
|
||||
}
|
||||
|
||||
private static void set(String path, Object def) {
|
||||
Config.config.set(path, def);
|
||||
}
|
||||
|
||||
private String getString(String path, String def) {
|
||||
set(defaultPath + path, def);
|
||||
return Config.config.getNode(configPath + path).getString(
|
||||
Config.config.getNode(defaultPath + path).getString(def));
|
||||
}
|
||||
|
||||
private int getInt(String path, int def) {
|
||||
set(defaultPath + path, def);
|
||||
return Config.config.getNode(configPath + path).getInt(
|
||||
Config.config.getNode(defaultPath + path).getInt(def));
|
||||
}
|
||||
|
||||
private List<String> getStringList(String path, List<String> def) {
|
||||
try {
|
||||
set(defaultPath + path, def);
|
||||
return Config.config.getNode(configPath + path).getList(TypeToken.get(String.class),
|
||||
Config.config.getNode(defaultPath + path).getList(TypeToken.get(String.class), def));
|
||||
} catch(SerializationException ignore) {}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public int slot = 0;
|
||||
public String displayName = "Default";
|
||||
public String material = "dirt";
|
||||
public List<String> lore = new ArrayList<>();
|
||||
private void guiItems() {
|
||||
slot = getInt("slot", slot);
|
||||
material = getString("material", material);
|
||||
displayName = getString("display-name", displayName);
|
||||
lore = getStringList("lore", lore);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user