Finished EnchantmentType refactor

This commit is contained in:
Auxilor 2020-11-28 09:43:29 +00:00
parent 7c0e17f1f3
commit 05f1775ef6
2 changed files with 19 additions and 13 deletions

View File

@ -43,7 +43,7 @@ public abstract class EnchantmentYamlConfig {
if(!basedir.exists()) basedir.mkdirs(); if(!basedir.exists()) basedir.mkdirs();
File dir = new File(basedir, type.name().toLowerCase() + "/"); File dir = new File(basedir, type.getName() + "/");
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }
@ -64,7 +64,7 @@ public abstract class EnchantmentYamlConfig {
} }
private void saveResource(boolean replace) { private void saveResource(boolean replace) {
String resourcePath = "/enchants/" + type.name().toLowerCase() + "/" + name + ".yml"; String resourcePath = "/enchants/" + type.getName() + "/" + name + ".yml";
InputStream in = source.getResourceAsStream(resourcePath); InputStream in = source.getResourceAsStream(resourcePath);
@ -98,7 +98,7 @@ public abstract class EnchantmentYamlConfig {
try { try {
config.load(configFile); config.load(configFile);
String resourcePath = "/enchants/" + type.name().toLowerCase() + "/" + name + ".yml"; String resourcePath = "/enchants/" + type.getName() + "/" + name + ".yml";
InputStream newIn = source.getResourceAsStream(resourcePath); InputStream newIn = source.getResourceAsStream(resourcePath);
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8)); BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));

View File

@ -436,28 +436,30 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
} }
public static class EnchantmentType { public static class EnchantmentType {
public static final EnchantmentType NORMAL = new EnchantmentType(false, () -> ConfigManager.getLang().getString("not-curse-color")); public static final EnchantmentType NORMAL = new EnchantmentType("normal", false, () -> ConfigManager.getLang().getString("not-curse-color"));
public static final EnchantmentType CURSE = new EnchantmentType(false, () -> ConfigManager.getLang().getString("curse-color")); public static final EnchantmentType CURSE = new EnchantmentType("curse", false, () -> ConfigManager.getLang().getString("curse-color"));
public static final EnchantmentType SPECIAL = new EnchantmentType(() -> !ConfigManager.getConfig().getBool("types.special.allow-multiple"), () -> ConfigManager.getLang().getString("special-color")); public static final EnchantmentType SPECIAL = new EnchantmentType("special", () -> !ConfigManager.getConfig().getBool("types.special.allow-multiple"), () -> ConfigManager.getLang().getString("special-color"));
public static final EnchantmentType ARTIFACT = new EnchantmentType(() -> !ConfigManager.getConfig().getBool("types.artifact.allow-multiple"), () -> ConfigManager.getLang().getString("artifact-color")); public static final EnchantmentType ARTIFACT = new EnchantmentType("artifact", () -> !ConfigManager.getConfig().getBool("types.artifact.allow-multiple"), () -> ConfigManager.getLang().getString("artifact-color"));
public static final EnchantmentType SPELL = new EnchantmentType(true, () -> ConfigManager.getLang().getString("spell-color")); public static final EnchantmentType SPELL = new EnchantmentType("spell", true, () -> ConfigManager.getLang().getString("spell-color"));
private static final Set<EnchantmentType> values = new HashSet<>(); private static final Set<EnchantmentType> values = new HashSet<>();
private boolean singular; private boolean singular;
private String color; private String color;
private final String name;
private final ObjectCallable<String> colorCallable; private final ObjectCallable<String> colorCallable;
private final ObjectCallable<Boolean> singularCallable; private final ObjectCallable<Boolean> singularCallable;
public EnchantmentType(boolean singular, String color) { public EnchantmentType(String name, boolean singular, String color) {
this(() -> singular, () -> color); this(name, () -> singular, () -> color);
} }
public EnchantmentType(boolean singular, ObjectCallable<String> colorCallable) { public EnchantmentType(String name, boolean singular, ObjectCallable<String> colorCallable) {
this(() -> singular, colorCallable); this(name, () -> singular, colorCallable);
} }
public EnchantmentType(ObjectCallable<Boolean> singularCallable, ObjectCallable<String> colorCallable) { public EnchantmentType(String name, ObjectCallable<Boolean> singularCallable, ObjectCallable<String> colorCallable) {
this.name = name;
this.singularCallable = singularCallable; this.singularCallable = singularCallable;
this.colorCallable = colorCallable; this.colorCallable = colorCallable;
color = colorCallable.call(); color = colorCallable.call();
@ -478,6 +480,10 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
return singular; return singular;
} }
public String getName() {
return name;
}
public static void update() { public static void update() {
values.forEach(EnchantmentType::refresh); values.forEach(EnchantmentType::refresh);
} }