From 2f251686407bec8564604938b29f4f4730c7ef03 Mon Sep 17 00:00:00 2001 From: noil755 Date: Fri, 29 Nov 2019 19:09:58 -0500 Subject: [PATCH] fix config, module manager, module --- .../rigamortis/seppuku/api/module/Module.java | 38 +++++---- .../seppuku/impl/config/ValueConfig.java | 77 +++++++++---------- .../impl/management/ModuleManager.java | 2 +- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/api/module/Module.java b/src/main/java/me/rigamortis/seppuku/api/module/Module.java index 866c3de..1530134 100644 --- a/src/main/java/me/rigamortis/seppuku/api/module/Module.java +++ b/src/main/java/me/rigamortis/seppuku/api/module/Module.java @@ -1,7 +1,7 @@ package me.rigamortis.seppuku.api.module; import me.rigamortis.seppuku.Seppuku; -import me.rigamortis.seppuku.api.value.old.*; +import me.rigamortis.seppuku.api.value.Value; import java.util.ArrayList; import java.util.List; @@ -89,29 +89,32 @@ public class Module { final StringBuilder sb = new StringBuilder(); for(Value v : this.getValueList()) { - if(v instanceof BooleanValue) { - sb.append(v.getDisplayName() + "\n"); + if (v.getValue() instanceof Boolean) { + sb.append(v.getName() + "\n"); } - if(v instanceof NumberValue && !(v instanceof OptionalValue)) { - sb.append(v.getDisplayName() + " \n"); + + if (v.getValue() instanceof Number && !(v.getValue() instanceof Enum)) { + sb.append(v.getName() + " \n"); } - if(v instanceof StringValue) { - sb.append(v.getDisplayName() + " \n"); + + if (v.getValue() instanceof String) { + sb.append(v.getName() + " \n"); } - if(v instanceof OptionalValue) { - final OptionalValue val = (OptionalValue) v; + + if (v.getValue() instanceof Enum) { + final Enum val = (Enum) v.getValue(); final StringBuilder options = new StringBuilder(); - final int size = val.getOptions().length; + final int size = val.getClass().getEnumConstants().length; - for(int i = 0; i < val.getOptions().length; i++) { - final String option = val.getOptions()[i]; + for (int i = 0; i < size; i++) { + final Enum option = val.getClass().getEnumConstants()[i]; - options.append(option + ((i == size - 1) ? "" : "|")); + options.append(option.name() + ((i == size - 1) ? "" : " | ")); } - sb.append(v.getDisplayName() + " <" + options.toString() + ">\n"); + sb.append(v.getName() + " <" + options.toString() + ">\n"); } } @@ -122,12 +125,13 @@ public class Module { public Value find(String alias) { for(Value v : this.getValueList()) { - for(String s : v.getAlias()) { - if(alias.equalsIgnoreCase(s)) { + for (String s : v.getAlias()) { + if (alias.equalsIgnoreCase(s)) { return v; } } - if(v.getDisplayName().equalsIgnoreCase(alias)) { + + if (v.getName().equalsIgnoreCase(alias)) { return v; } } diff --git a/src/main/java/me/rigamortis/seppuku/impl/config/ValueConfig.java b/src/main/java/me/rigamortis/seppuku/impl/config/ValueConfig.java index 31e98b1..0921c43 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/config/ValueConfig.java +++ b/src/main/java/me/rigamortis/seppuku/impl/config/ValueConfig.java @@ -4,7 +4,7 @@ import me.rigamortis.seppuku.Seppuku; import me.rigamortis.seppuku.api.config.Configurable; import me.rigamortis.seppuku.api.module.Module; import me.rigamortis.seppuku.api.util.StringUtil; -import me.rigamortis.seppuku.api.value.old.*; +import me.rigamortis.seppuku.api.value.Value; import me.rigamortis.seppuku.impl.management.ConfigManager; import java.io.*; @@ -37,40 +37,41 @@ public final class ValueConfig extends Configurable { final String[] split = line.split(":"); final Value v = mod.find(split[0]); if (v != null) { - if (v instanceof BooleanValue) { - final BooleanValue val = (BooleanValue) v; + if (v.getValue() instanceof Boolean) { if (StringUtil.isBoolean(split[1])) { - val.setBoolean(Boolean.parseBoolean(split[1])); + v.setValue(Boolean.parseBoolean(split[1])); } } - if (v instanceof NumberValue && !(v instanceof OptionalValue)) { - final NumberValue val = (NumberValue) v; - if (split[2].equals("Float") && val.getType() == Float.class) { + + if (v.getValue() instanceof Number && !(v.getValue() instanceof Enum)) { + if (split[2].equals("Float") && v.getValue().getClass() == Float.class) { if (StringUtil.isFloat(split[1])) { - val.setFloat(Float.parseFloat(split[1])); + v.setValue(Float.parseFloat(split[1])); } } - if (split[2].equals("Integer") && val.getType() == Integer.class) { - if(StringUtil.isInt(split[1])) { - val.setInt(Integer.parseInt(split[1])); + + if (split[2].equals("Integer") && v.getValue().getClass() == Integer.class) { + if (StringUtil.isInt(split[1])) { + v.setValue(Integer.parseInt(split[1])); } } - if (split[2].equals("Double") && val.getType() == Double.class) { - if(StringUtil.isDouble(split[1])) { - val.setDouble(Double.parseDouble(split[1])); + + if (split[2].equals("Double") && v.getValue().getClass() == Double.class) { + if (StringUtil.isDouble(split[1])) { + v.setValue(Double.parseDouble(split[1])); } } } - if (v instanceof OptionalValue) { - final OptionalValue val = (OptionalValue) v; - if(StringUtil.isInt(split[1])) { - val.setInt(Integer.parseInt(split[1])); + + if (v.getValue() instanceof Enum) { + if (StringUtil.isInt(split[1])) { + v.setValue(Integer.parseInt(split[1])); } } - if(v instanceof StringValue) { - final StringValue val = (StringValue) v; - if(split.length > 1) { - val.setString(split[1]); + + if (v.getValue() instanceof String) { + if (split.length > 1) { + v.setValue(split[1]); } } } @@ -97,32 +98,26 @@ public final class ValueConfig extends Configurable { final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath() + mod.getDisplayName() + ".cfg")); for (Value val : mod.getValueList()) { - if (val instanceof BooleanValue) { - final BooleanValue v = (BooleanValue) val; - writer.write(val.getDisplayName() + ":" + v.getBoolean()); + if (val.getValue() instanceof Boolean) { + writer.write(val.getName() + ":" + val.getValue()); writer.newLine(); } - if (val instanceof NumberValue && !(val instanceof OptionalValue)) { - final NumberValue v = (NumberValue) val; - if (v.getType() == Float.class) { - writer.write(val.getDisplayName() + ":" + v.getFloat() + ":Float"); + + if (val.getValue() instanceof Number && !(val.getValue() instanceof Enum)) { + if (val.getValue().getClass() == Float.class) { + writer.write(val.getName() + ":" + val.getValue() + ":Float"); writer.newLine(); - } else if (v.getType() == Integer.class) { - writer.write(val.getDisplayName() + ":" + v.getInt() + ":Integer"); + } else if (val.getValue().getClass() == Integer.class) { + writer.write(val.getName() + ":" + val.getValue() + ":Integer"); writer.newLine(); - } else if (v.getType() == Double.class) { - writer.write(val.getDisplayName() + ":" + v.getDouble() + ":Double"); + } else if (val.getValue().getClass() == Double.class) { + writer.write(val.getName() + ":" + val.getValue() + ":Double"); writer.newLine(); } } - if (val instanceof OptionalValue) { - final OptionalValue v = (OptionalValue) val; - writer.write(val.getDisplayName() + ":" + v.getInt()); - writer.newLine(); - } - if(val instanceof StringValue) { - final StringValue v = (StringValue) val; - writer.write(val.getDisplayName() + ":" + v.getString()); + + if (val.getValue() instanceof Enum || val.getValue() instanceof String) { + writer.write(val.getName() + ":" + val.getValue()); writer.newLine(); } } diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java index 0a34fdc..c464790 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java @@ -6,7 +6,7 @@ import me.rigamortis.seppuku.api.event.module.EventModulePostLoaded; import me.rigamortis.seppuku.api.module.Module; import me.rigamortis.seppuku.api.util.ReflectionUtil; import me.rigamortis.seppuku.api.util.StringUtil; -import me.rigamortis.seppuku.api.value.old.Value; +import me.rigamortis.seppuku.api.value.Value; import me.rigamortis.seppuku.impl.module.combat.*; import me.rigamortis.seppuku.impl.module.hidden.CommandsModule; import me.rigamortis.seppuku.impl.module.hidden.IgnoreModule;