diff --git a/pom.xml b/pom.xml index e912893..c093382 100644 --- a/pom.xml +++ b/pom.xml @@ -16,8 +16,8 @@ - spigotmc-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + steamwar + https://steamwar.de/maven/ @@ -47,9 +47,9 @@ - org.spigotmc - spigot-api - 1.12.2-R0.1-SNAPSHOT + steamwar + Spigot + 1.0 provided diff --git a/src/de/steamwar/inventory/SWInventory.java b/src/de/steamwar/inventory/SWInventory.java index 1c7ef62..8ed9456 100644 --- a/src/de/steamwar/inventory/SWInventory.java +++ b/src/de/steamwar/inventory/SWInventory.java @@ -57,7 +57,7 @@ public class SWInventory implements Listener, Inventory { } public void setItem(int pos, Material m, String name, List lore, boolean e, InvCallback c){ - setItem(pos, m, (byte)0, name, new ArrayList<>(), false, c); + setItem(pos, m, (byte)0, name, lore, e, c); } public void setItem(int pos, Material m, byte meta, String name, List lore, boolean e, InvCallback c){ diff --git a/src/de/steamwar/inventory/SWItem.java b/src/de/steamwar/inventory/SWItem.java index 19a82bc..cdb3de2 100644 --- a/src/de/steamwar/inventory/SWItem.java +++ b/src/de/steamwar/inventory/SWItem.java @@ -32,13 +32,17 @@ public class SWItem { public SWItem(Material material, byte meta, String name, List lore, boolean enchanted, InvCallback c){ itemStack = new ItemStack(material, 1, (short)0, meta); itemMeta = itemStack.getItemMeta(); - hideAttributes(); - itemMeta.setDisplayName(name); - if(lore != null && !lore.isEmpty()) - itemMeta.setLore(lore); - if(enchanted) - itemMeta.addEnchant(Enchantment.DURABILITY , 10, true); - itemStack.setItemMeta(itemMeta); + + if(itemMeta != null){ + hideAttributes(); + + itemMeta.setDisplayName(name); + if(lore != null && !lore.isEmpty()) + itemMeta.setLore(lore); + if(enchanted) + itemMeta.addEnchant(Enchantment.DURABILITY , 10, true); + itemStack.setItemMeta(itemMeta); + } callback = c; } diff --git a/src/de/warking/hunjy/MySQL/Schematic.java b/src/de/warking/hunjy/MySQL/Schematic.java index eb96bd9..d0c3ad0 100644 --- a/src/de/warking/hunjy/MySQL/Schematic.java +++ b/src/de/warking/hunjy/MySQL/Schematic.java @@ -15,6 +15,15 @@ public class Schematic { private String Item; private SchematicType SchemType; + private Schematic(ResultSet rs) throws SQLException { + this( + rs.getString("SchemName"), + rs.getInt("SchemOwner"), + rs.getString("Item"), + SchematicType.fromDB(rs.getString("SchemType")), + false); + } + private Schematic(String schemName, int schemOwner, String item, SchematicType schemType, boolean updateDB){ SchemName = schemName; SchemOwner = schemOwner; @@ -36,7 +45,7 @@ public class Schematic { sql.update("INSERT INTO Schematic" + " (SchemName, SchemOwner, Item, SchemType)" + " VALUES" + - " ('" + SchemName + "', '" + SchemOwner + "', '" + Item + "', '" + SchemType.name() + "')" + + " ('" + SchemName + "', '" + SchemOwner + "', '" + Item + "', '" + SchemType.toDB() + "')" + " ON DUPLICATE KEY UPDATE" + " Item = VALUES(Item), SchemType = VALUES(SchemType)"); } @@ -56,9 +65,7 @@ public class Schematic { } return getSchemFromDB(schemName, member.getSchemOwner()); } - String item = schematic.getString("Item"); - SchematicType schemType = SchematicType.valueOf(schematic.getString("SchemType")); - return new Schematic(schemName, schemOwner, item, schemType, false); + return new Schematic(schematic); } catch (SQLException e) { e.printStackTrace(); } @@ -74,10 +81,7 @@ public class Schematic { ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemOwner = '" + schemOwner + "'"); List schematics = new ArrayList<>(); while(schematic.next()){ - String schemName = schematic.getString("SchemName"); - String item = schematic.getString("Item"); - SchematicType schemType = SchematicType.valueOf(schematic.getString("SchemType")); - schematics.add(new Schematic(schemName, schemOwner, item, schemType, false)); + schematics.add(new Schematic(schematic)); } List addedSchems = SchematicMember.getAccessibleSchems(schemOwner); for(SchematicMember schem : addedSchems){ @@ -106,13 +110,10 @@ public class Schematic { public static List getAllSchemsOfType(SchematicType schemType){ try{ - ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemType = '" + schemType.name() + "'"); + ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemType = '" + schemType.toDB() + "'"); List schematics = new ArrayList<>(); while(schematic.next()){ - int schemOwner = schematic.getInt("SchemOwner"); - String schemName = schematic.getString("SchemName"); - String item = schematic.getString("Item"); - schematics.add(new Schematic(schemName, schemOwner, item, schemType, false)); + schematics.add(new Schematic(schematic)); } return schematics; }catch(SQLException e){ diff --git a/src/de/warking/hunjy/MySQL/SchematicType.java b/src/de/warking/hunjy/MySQL/SchematicType.java index 5c86ff1..3cac83e 100644 --- a/src/de/warking/hunjy/MySQL/SchematicType.java +++ b/src/de/warking/hunjy/MySQL/SchematicType.java @@ -1,13 +1,76 @@ package de.warking.hunjy.MySQL; +import java.util.HashMap; +import java.util.Map; + public enum SchematicType { - normal, - airship, - wargear, - warship, - miniwargear, - Cairship, - Cwargear, - Cwarship, - Cminiwargear + Normal("", Type.NORMAL), + CAirShip("", Type.CHECK_TYPE), + CWarGear("", Type.CHECK_TYPE), + CWarShip("", Type.CHECK_TYPE), + CMiniWarGear("", Type.CHECK_TYPE), + AirShip("", Type.FIGHT_TYPE, CAirShip), + WarGear("", Type.FIGHT_TYPE, CWarGear), + WarShip("", Type.FIGHT_TYPE, CWarShip), + MiniWarGear("", Type.FIGHT_TYPE, CMiniWarGear); + + private static Map fromDB = new HashMap<>(); + + static{ + for(SchematicType type : values()){ + fromDB.put(type.toDB(), type); + } + } + + private final String kuerzel; + private final Type type; + private SchematicType checkType; + + SchematicType(String kuerzel, Type type){ + this(kuerzel, type, null); + } + + SchematicType(String kuerzel, Type type, SchematicType checkType){ + this.kuerzel = kuerzel; + this.type = type; + this.checkType = checkType; + } + + public boolean isAssignable(){ + return type == Type.NORMAL || type == Type.FIGHT_TYPE; + } + + public SchematicType checkType(){ + return checkType; + } + + public boolean check(){ + return type == Type.CHECK_TYPE; + } + + public boolean fightType(){ + return type == Type.FIGHT_TYPE; + } + + public boolean writeable(){ + return type == Type.NORMAL; + } + + public String getKuerzel() { + return kuerzel; + } + + public String toDB(){ + return name().toLowerCase(); + } + + public static SchematicType fromDB(String input){ + return fromDB.get(input.toLowerCase()); + } + + enum Type{ + NORMAL, + CHECK_TYPE, + FIGHT_TYPE + } }