From 364d3f8f8304d6f749b82717eba1dd331ff83073 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jan 2020 14:37:59 +0100 Subject: [PATCH 1/2] WIP: Dnamic SchemType rework --- .../src/de/steamwar/sql/SchematicType.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java index 4f745cf..ff12ca0 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java @@ -3,8 +3,8 @@ package de.steamwar.sql; import java.util.HashMap; import java.util.Map; -public enum SchematicType { - Normal("", Type.NORMAL), +public class SchematicType { + public static final SchematicType Normal = new SchematicType("", Type.NORMAL); //Has to stay publicly availible CAirShip("CAS", Type.CHECK_TYPE), CWarGear("CWG", Type.CHECK_TYPE), @@ -46,11 +46,11 @@ public enum SchematicType { private final Type type; private SchematicType checkType; - SchematicType(String kuerzel, Type type){ + private SchematicType(String kuerzel, Type type){ this(kuerzel, type, null); } - SchematicType(String kuerzel, Type type, SchematicType checkType){ + private SchematicType(String kuerzel, Type type, SchematicType checkType){ this.kuerzel = kuerzel; this.type = type; this.checkType = checkType; @@ -88,6 +88,10 @@ public enum SchematicType { return fromDB.get(input.toLowerCase()); } + //public static List values(){ + //TODO + //} + enum Type{ NORMAL, CHECK_TYPE, -- 2.39.2 From 5c176b0afbb67dcbff43fcb3da44911a96fb5991 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jan 2020 16:19:53 +0100 Subject: [PATCH 2/2] Dynamic instanciating of SchematicTypes --- .../src/de/steamwar/sql/SchematicType.java | 79 +++++++++---------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java index ff12ca0..37d4c73 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java @@ -1,56 +1,45 @@ package de.steamwar.sql; -import java.util.HashMap; -import java.util.Map; +import de.steamwar.core.Core; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.util.*; public class SchematicType { - public static final SchematicType Normal = new SchematicType("", Type.NORMAL); //Has to stay publicly availible + public static final SchematicType Normal = new SchematicType("Normal", "", Type.NORMAL, null); //Has to stay publicly availible - CAirShip("CAS", Type.CHECK_TYPE), - CWarGear("CWG", Type.CHECK_TYPE), - CWarShip("CWS", Type.CHECK_TYPE), - CMiniWarGear("CMWG", Type.CHECK_TYPE), - AirShip("AS", Type.FIGHT_TYPE, CAirShip), - WarGear("WG", Type.FIGHT_TYPE, CWarGear), - WarShip("WS", Type.FIGHT_TYPE, CWarShip), - MiniWarGear("MWG", Type.FIGHT_TYPE, CMiniWarGear), - - CMPPWarGear1_12("CMPPWG", Type.CHECK_TYPE), - CSGWarShip("CSGWS", Type.CHECK_TYPE), - CWarGear1_10("CWG1.10", Type.CHECK_TYPE), - CWarShip1_9("CWS1.9", Type.CHECK_TYPE), - CWarShip1_8("CWS1.8", Type.CHECK_TYPE), - CWarGear1_7("CWG1.7", Type.CHECK_TYPE), - WarGear1_14("WG1.14", Type.FIGHT_TYPE, null), - MPPWarGear1_12("MPPWG", Type.FIGHT_TYPE, CMPPWarGear1_12), - SGWarShip("SGWS", Type.FIGHT_TYPE, CSGWarShip), - WarGear1_12("WG1.12", Type.FIGHT_TYPE, null), - WarShip1_12("WS1.12", Type.FIGHT_TYPE, null), - MiniWarGear1_12("MWG1.12", Type.FIGHT_TYPE, null), - WarGear1_10("WG1.10", Type.FIGHT_TYPE, CWarGear1_10), - WarShip1_9("WS1.9", Type.FIGHT_TYPE, CWarShip1_9), - WarShip1_8("WS1.8", Type.FIGHT_TYPE, CWarShip1_8), - WarGear1_7("WG1.7", Type.FIGHT_TYPE, CWarGear1_7) - - ; - - private static Map fromDB = new HashMap<>(); + private static final Map fromDB; + private static final List types; static{ - for(SchematicType type : values()){ - fromDB.put(type.toDB(), type); + File file = new File(Core.getInstance().getDataFolder(), "SchematicTypes.yml"); + + if(!file.exists()) + throw new SecurityException("SchematicType-ConfigFile not found!"); + + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + + List tmpTypes = new LinkedList<>(); + Map tmpFromDB = new HashMap<>(); + for(String type : config.getKeys(false)){ + String checktype = config.getString("checktype"); + SchematicType current = new SchematicType(type, config.getString("kuerzel"), Type.valueOf(config.getString("type")), checktype != null ? fromDB(checktype) : null); + tmpTypes.add(current); + tmpFromDB.put(type, current); } + + fromDB = Collections.unmodifiableMap(tmpFromDB); + types = Collections.unmodifiableList(tmpTypes); } + private final String name; private final String kuerzel; private final Type type; private SchematicType checkType; - private SchematicType(String kuerzel, Type type){ - this(kuerzel, type, null); - } - - private SchematicType(String kuerzel, Type type, SchematicType checkType){ + private SchematicType(String name, String kuerzel, Type type, SchematicType checkType){ + this.name = name; this.kuerzel = kuerzel; this.type = type; this.checkType = checkType; @@ -76,21 +65,25 @@ public class SchematicType { return type == Type.NORMAL; } + public String name(){ + return name; + } + public String getKuerzel() { return kuerzel; } public String toDB(){ - return name().toLowerCase(); + return name.toLowerCase(); } public static SchematicType fromDB(String input){ return fromDB.get(input.toLowerCase()); } - //public static List values(){ - //TODO - //} + public static List values(){ + return types; + } enum Type{ NORMAL, -- 2.39.2