From e32c80af3f977e8ff41434993c249f2b15ab1dc8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 7 Jan 2021 15:25:52 +0100 Subject: [PATCH 01/15] Extend PersonalKit --- .../src/de/steamwar/sql/PersonalKit.java | 64 ++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index f839f0d..7169a87 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -25,11 +25,14 @@ import org.bukkit.inventory.ItemStack; import java.io.StringReader; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; public class PersonalKit { private final int userID; + private String name; private final String gamemode; private String inventory; private String armor; @@ -39,30 +42,42 @@ public class PersonalKit { gamemode = rs.getString("GameMode"); inventory = rs.getString("Inventory"); armor = rs.getString("Armor"); + name = rs.getString("Name"); } - public static PersonalKit get(int userID, String gamemode){ + public static List get(int userID, String gamemode){ ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ?", userID, gamemode); try { - if(!rs.next()) - return null; - - return new PersonalKit(rs); + List list = new ArrayList<>(); + while (rs.next()) + list.add(new PersonalKit(rs)); + return list; } catch (SQLException e) { throw new SecurityException("Failed loading personal kit", e); } } - public static PersonalKit save(int userID, String gamemode, ItemStack[] inventory, ItemStack[] armor){ + public static PersonalKit get(int userID, String gamemode, String name) { + ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?", userID, gamemode, name); + try { + if(!rs.next()) + return null; + return new PersonalKit(rs); + } catch (SQLException e) { + throw new SecurityException("Failed loading personal kit", e); + } + } + + public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){ YamlConfiguration inventoryConfig = new YamlConfiguration(); inventoryConfig.set("Inventory", inventory); YamlConfiguration armorConfig = new YamlConfiguration(); armorConfig.set("Armor", armor); - SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Inventory, Armor) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor)", + SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor)", userID, gamemode, inventoryConfig.saveToString(), armorConfig.saveToString()); - return get(userID, gamemode); + return get(userID, gamemode, name); } public ItemStack[] getInventory(){ @@ -74,4 +89,37 @@ public class PersonalKit { YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(armor)); return Objects.requireNonNull(config.getList("Armor")).toArray(new ItemStack[0]); } + + public int getUserID() { + return userID; + } + + public String getName() { + return name; + } + + public String getGamemode() { + return gamemode; + } + + public void setName(String name) { + this.name = name; + SQL.update("UPDATE PersonalKit SET Name = ?", this.name); + } + + public void setInventory(ItemStack[] inventory) { + YamlConfiguration inventoryConfig = new YamlConfiguration(); + inventoryConfig.set("Inventory", inventory); + + this.inventory = inventoryConfig.saveToString(); + SQL.update("UPDATE PersonalKit SET Inventory = ?", this.inventory); + } + + public void setArmor(ItemStack[] armor) { + YamlConfiguration armorConfig = new YamlConfiguration(); + armorConfig.set("Armor", armor); + + this.armor = armorConfig.saveToString(); + SQL.update("UPDATE PersonalKit SET Armor = ?", this.armor); + } } From 63d59121b3287657adb3c23b84541b5264dece2c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 9 Jan 2021 11:49:29 +0100 Subject: [PATCH 02/15] Add KitId --- .../src/de/steamwar/sql/PersonalKit.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index 7169a87..2560298 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -31,6 +31,7 @@ import java.util.Objects; public class PersonalKit { + private final int kitID; private final int userID; private String name; private final String gamemode; @@ -38,6 +39,7 @@ public class PersonalKit { private String armor; private PersonalKit(ResultSet rs) throws SQLException { + kitID = rs.getInt("KitID"); userID = rs.getInt("UserID"); gamemode = rs.getString("GameMode"); inventory = rs.getString("Inventory"); @@ -68,7 +70,7 @@ public class PersonalKit { } } - public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){ + public static void create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){ YamlConfiguration inventoryConfig = new YamlConfiguration(); inventoryConfig.set("Inventory", inventory); @@ -76,8 +78,7 @@ public class PersonalKit { armorConfig.set("Armor", armor); SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor)", - userID, gamemode, inventoryConfig.saveToString(), armorConfig.saveToString()); - return get(userID, gamemode, name); + userID, gamemode, name, inventoryConfig.saveToString(), armorConfig.saveToString()); } public ItemStack[] getInventory(){ @@ -104,7 +105,7 @@ public class PersonalKit { public void setName(String name) { this.name = name; - SQL.update("UPDATE PersonalKit SET Name = ?", this.name); + SQL.update("UPDATE PersonalKit SET Name = ? WHERE KitID = ?", this.name, kitID); } public void setInventory(ItemStack[] inventory) { @@ -112,7 +113,7 @@ public class PersonalKit { inventoryConfig.set("Inventory", inventory); this.inventory = inventoryConfig.saveToString(); - SQL.update("UPDATE PersonalKit SET Inventory = ?", this.inventory); + SQL.update("UPDATE PersonalKit SET Inventory = ? WHERE KitID = ?", this.inventory, kitID); } public void setArmor(ItemStack[] armor) { @@ -120,6 +121,10 @@ public class PersonalKit { armorConfig.set("Armor", armor); this.armor = armorConfig.saveToString(); - SQL.update("UPDATE PersonalKit SET Armor = ?", this.armor); + SQL.update("UPDATE PersonalKit SET Armor = ? WHERE KitID = ?", this.armor, kitID); + } + + public void delete() { + SQL.update("DELETE FROM `PersonalKit` WHERE KitID = ?", kitID); } } From e88f183e72d688d25495de8dc0a7aa69d293a3e5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 9 Jan 2021 12:13:03 +0100 Subject: [PATCH 03/15] Add InUse --- .../src/de/steamwar/sql/PersonalKit.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index 2560298..d0b361f 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -37,6 +37,7 @@ public class PersonalKit { private final String gamemode; private String inventory; private String armor; + private boolean inUse; private PersonalKit(ResultSet rs) throws SQLException { kitID = rs.getInt("KitID"); @@ -45,6 +46,7 @@ public class PersonalKit { inventory = rs.getString("Inventory"); armor = rs.getString("Armor"); name = rs.getString("Name"); + inUse = rs.getBoolean("InUse"); } public static List get(int userID, String gamemode){ @@ -81,6 +83,23 @@ public class PersonalKit { userID, gamemode, name, inventoryConfig.saveToString(), armorConfig.saveToString()); } + public static PersonalKit getKitInUse(int userID, String gamemode) { + ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND InUse = ?", userID, gamemode, true); + try { + List list = new ArrayList<>(); + while (rs.next()) + list.add(new PersonalKit(rs)); + if(list.size() > 1) { + list.forEach(kit -> { + if(list.indexOf(kit) >= 1) kit.setInUse(false); + }); + } + return list.get(0); + } catch (SQLException e) { + throw new SecurityException("Failed loading personal kit", e); + } + } + public ItemStack[] getInventory(){ YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(inventory)); return Objects.requireNonNull(config.getList("Inventory")).toArray(new ItemStack[0]); @@ -103,6 +122,15 @@ public class PersonalKit { return gamemode; } + public boolean isInUse() { + return inUse; + } + + public void setInUse(boolean inUse) { + this.inUse = inUse; + SQL.update("UPDATE PersonalKit SET InUse = ? WHERE KitID = ?", this.inUse, kitID); + } + public void setName(String name) { this.name = name; SQL.update("UPDATE PersonalKit SET Name = ? WHERE KitID = ?", this.name, kitID); From 5266bb6492b728cba90cd93f21f42693d175284e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 9 Jan 2021 17:36:03 +0100 Subject: [PATCH 04/15] List at get with name --- SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index d0b361f..263850c 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -61,12 +61,13 @@ public class PersonalKit { } } - public static PersonalKit get(int userID, String gamemode, String name) { + public static List get(int userID, String gamemode, String name) { ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?", userID, gamemode, name); try { - if(!rs.next()) - return null; - return new PersonalKit(rs); + List list = new ArrayList<>(); + while (rs.next()) + list.add(new PersonalKit(rs)); + return list; } catch (SQLException e) { throw new SecurityException("Failed loading personal kit", e); } @@ -93,7 +94,9 @@ public class PersonalKit { list.forEach(kit -> { if(list.indexOf(kit) >= 1) kit.setInUse(false); }); + list.removeIf(kit -> !kit.isInUse()); } + if(list.isEmpty()) return null; return list.get(0); } catch (SQLException e) { throw new SecurityException("Failed loading personal kit", e); From d8191836a82c5e83621bf63929647d05d464b30a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 10 Jan 2021 16:58:20 +0100 Subject: [PATCH 05/15] Remove Multiple Kits with same Name --- .../src/de/steamwar/sql/PersonalKit.java | 74 +++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index 263850c..c572d14 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -31,7 +31,6 @@ import java.util.Objects; public class PersonalKit { - private final int kitID; private final int userID; private String name; private final String gamemode; @@ -40,7 +39,6 @@ public class PersonalKit { private boolean inUse; private PersonalKit(ResultSet rs) throws SQLException { - kitID = rs.getInt("KitID"); userID = rs.getInt("UserID"); gamemode = rs.getString("GameMode"); inventory = rs.getString("Inventory"); @@ -61,27 +59,21 @@ public class PersonalKit { } } - public static List get(int userID, String gamemode, String name) { + public static PersonalKit get(int userID, String gamemode, String name) { ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?", userID, gamemode, name); try { - List list = new ArrayList<>(); - while (rs.next()) - list.add(new PersonalKit(rs)); - return list; + if(!rs.next()) + return null; + return new PersonalKit(rs); } catch (SQLException e) { throw new SecurityException("Failed loading personal kit", e); } } - public static void create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){ - YamlConfiguration inventoryConfig = new YamlConfiguration(); - inventoryConfig.set("Inventory", inventory); - - YamlConfiguration armorConfig = new YamlConfiguration(); - armorConfig.set("Armor", armor); - - SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor)", - userID, gamemode, name, inventoryConfig.saveToString(), armorConfig.saveToString()); + public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){ + SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor), Name = VALUES(name)", + userID, gamemode, name, getInventoryConfig(inventory), getArmorConfig(armor)); + return get(userID, gamemode, name); } public static PersonalKit getKitInUse(int userID, String gamemode) { @@ -103,6 +95,17 @@ public class PersonalKit { } } + public static boolean nameInUse(int userID, String gamemode, String name) { + ResultSet set = SQL.select("SELECT COUNT(*) AS Count FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?", userID, gamemode, name); + try { + if(!set.next()) + return true; + return set.getInt("Count") > 0; + } catch (SQLException e) { + throw new SecurityException("Failed loading personal kit", e); + } + } + public ItemStack[] getInventory(){ YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(inventory)); return Objects.requireNonNull(config.getList("Inventory")).toArray(new ItemStack[0]); @@ -131,31 +134,44 @@ public class PersonalKit { public void setInUse(boolean inUse) { this.inUse = inUse; - SQL.update("UPDATE PersonalKit SET InUse = ? WHERE KitID = ?", this.inUse, kitID); + updateDB(); } public void setName(String name) { this.name = name; - SQL.update("UPDATE PersonalKit SET Name = ? WHERE KitID = ?", this.name, kitID); + updateDB(); } public void setInventory(ItemStack[] inventory) { - YamlConfiguration inventoryConfig = new YamlConfiguration(); - inventoryConfig.set("Inventory", inventory); - - this.inventory = inventoryConfig.saveToString(); - SQL.update("UPDATE PersonalKit SET Inventory = ? WHERE KitID = ?", this.inventory, kitID); + this.inventory = getInventoryConfig(inventory); + updateDB(); } public void setArmor(ItemStack[] armor) { - YamlConfiguration armorConfig = new YamlConfiguration(); - armorConfig.set("Armor", armor); - - this.armor = armorConfig.saveToString(); - SQL.update("UPDATE PersonalKit SET Armor = ? WHERE KitID = ?", this.armor, kitID); + this.armor = getArmorConfig(armor); + updateDB(); } public void delete() { - SQL.update("DELETE FROM `PersonalKit` WHERE KitID = ?", kitID); + SQL.update("DELETE FROM `PersonalKit` WHERE KitID = ?"); + } + + private static String getInventoryConfig(ItemStack[] inventory) { + YamlConfiguration inventoryConfig = new YamlConfiguration(); + inventoryConfig.set("Inventory", inventory); + + return inventoryConfig.saveToString(); + } + + private static String getArmorConfig(ItemStack[] armor) { + YamlConfiguration armorConfig = new YamlConfiguration(); + armorConfig.set("Armor", armor); + + return armorConfig.saveToString(); + } + + private void updateDB() { + SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor, InUse) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor), Name = VALUES(Name), InUse = VALUES(InUse)", + userID, gamemode, name, inventory, armor, inUse); } } From fa9361785be6ec2e00ee497b5ff64df55a76adb5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 15 Jan 2021 13:57:37 +0100 Subject: [PATCH 06/15] Remove Unused Method --- SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index c572d14..1aa82ed 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -124,10 +124,6 @@ public class PersonalKit { return name; } - public String getGamemode() { - return gamemode; - } - public boolean isInUse() { return inUse; } From 234671a8b03550dbef5e5234c3596aa116fcd5fd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 24 Jan 2021 15:02:31 +0100 Subject: [PATCH 07/15] Update some Function --- .../src/de/steamwar/sql/PersonalKit.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index 1aa82ed..910397d 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -129,6 +129,13 @@ public class PersonalKit { } public void setInUse(boolean inUse) { + setUse(inUse); + PersonalKit kit = getKitInUse(userID, gamemode); + if(kit != null) + kit.setUse(inUse); + } + + private void setUse(boolean inUse) { this.inUse = inUse; updateDB(); } @@ -148,6 +155,12 @@ public class PersonalKit { updateDB(); } + public void setContainer(ItemStack[] inventory, ItemStack[] armor) { + this.armor = getArmorConfig(armor); + this.inventory = getInventoryConfig(inventory); + updateDB(); + } + public void delete() { SQL.update("DELETE FROM `PersonalKit` WHERE KitID = ?"); } From fe050d76a4f8191268ce90682d1c34392e84d04f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 24 Jan 2021 15:09:13 +0100 Subject: [PATCH 08/15] Fix Order and Change Fuction --- SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index 910397d..a0afac1 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -84,7 +84,7 @@ public class PersonalKit { list.add(new PersonalKit(rs)); if(list.size() > 1) { list.forEach(kit -> { - if(list.indexOf(kit) >= 1) kit.setInUse(false); + if(list.indexOf(kit) >= 1) kit.setUse(false); }); list.removeIf(kit -> !kit.isInUse()); } @@ -129,10 +129,10 @@ public class PersonalKit { } public void setInUse(boolean inUse) { - setUse(inUse); PersonalKit kit = getKitInUse(userID, gamemode); if(kit != null) kit.setUse(inUse); + setUse(inUse); } private void setUse(boolean inUse) { From c8c99c21fe2892ec0f4308da9c68b9fd582293db Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 27 Jan 2021 12:23:23 +0100 Subject: [PATCH 09/15] Fixing... --- .../src/de/steamwar/sql/PersonalKit.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index a0afac1..9db33f0 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -72,7 +72,7 @@ public class PersonalKit { public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){ SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor), Name = VALUES(name)", - userID, gamemode, name, getInventoryConfig(inventory), getArmorConfig(armor)); + userID, gamemode, name, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor)); return get(userID, gamemode, name); } @@ -128,11 +128,11 @@ public class PersonalKit { return inUse; } - public void setInUse(boolean inUse) { + public void setInUse() { PersonalKit kit = getKitInUse(userID, gamemode); if(kit != null) - kit.setUse(inUse); - setUse(inUse); + kit.setUse(false); + setUse(true); } private void setUse(boolean inUse) { @@ -146,18 +146,18 @@ public class PersonalKit { } public void setInventory(ItemStack[] inventory) { - this.inventory = getInventoryConfig(inventory); + this.inventory = saveInvConfig("Inventory", inventory); updateDB(); } public void setArmor(ItemStack[] armor) { - this.armor = getArmorConfig(armor); + this.armor = saveInvConfig("Armor", armor); updateDB(); } public void setContainer(ItemStack[] inventory, ItemStack[] armor) { - this.armor = getArmorConfig(armor); - this.inventory = getInventoryConfig(inventory); + this.armor = saveInvConfig("Armor", armor); + this.inventory = saveInvConfig("Inventory", inventory); updateDB(); } @@ -165,16 +165,9 @@ public class PersonalKit { SQL.update("DELETE FROM `PersonalKit` WHERE KitID = ?"); } - private static String getInventoryConfig(ItemStack[] inventory) { - YamlConfiguration inventoryConfig = new YamlConfiguration(); - inventoryConfig.set("Inventory", inventory); - - return inventoryConfig.saveToString(); - } - - private static String getArmorConfig(ItemStack[] armor) { + private static String saveInvConfig(String name, ItemStack[] inv) { YamlConfiguration armorConfig = new YamlConfiguration(); - armorConfig.set("Armor", armor); + armorConfig.set(name, inv); return armorConfig.saveToString(); } From ded1e41dfc4a1256cb907a52764e8abd7e1d8aed Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 30 Jan 2021 16:49:19 +0100 Subject: [PATCH 10/15] Hotfix couldnt save chunk --- SpigotCore_Main/src/de/steamwar/sql/SWException.java | 1 + 1 file changed, 1 insertion(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SWException.java b/SpigotCore_Main/src/de/steamwar/sql/SWException.java index a9e72f0..0bbfb8b 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SWException.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SWException.java @@ -67,6 +67,7 @@ public class SWException { reasons.add("Chunk file at ["); reasons.add("Ignoring unknown attribute"); reasons.add("Skipping player strafe phase because no player was found"); + reasons.add("Couldn't save chunk; already in use by another instance of Minecraft?"); ignorereasons = Collections.unmodifiableList(reasons); } From 5f3004c78d09d2572ec6e8e74740d81820be0e63 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 30 Jan 2021 16:50:53 +0100 Subject: [PATCH 11/15] Add Fix SQL Exception --- SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index 9db33f0..6c58500 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -162,7 +162,7 @@ public class PersonalKit { } public void delete() { - SQL.update("DELETE FROM `PersonalKit` WHERE KitID = ?"); + SQL.update("DELETE FROM `PersonalKit` WHERE UserID = ? AND GameMode = ? AND Name = ?", userID, gamemode, name); } private static String saveInvConfig(String name, ItemStack[] inv) { From 614fab209fcd4d20c9d2a958a3d5bf68890d4152 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 30 Jan 2021 17:10:38 +0100 Subject: [PATCH 12/15] Add Fix Armor Null --- SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index 6c58500..912266a 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -71,6 +71,9 @@ public class PersonalKit { } public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){ + if(armor == null) { + armor = new ItemStack[]{null, null, null, null}; + } SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor), Name = VALUES(name)", userID, gamemode, name, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor)); return get(userID, gamemode, name); From 0327eb37c4700c82ebedb2df7786f8766970d886 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 2 Feb 2021 23:26:01 +0100 Subject: [PATCH 13/15] Add Support for Itemstack --- .../de/steamwar/inventory/SWInventory.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java b/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java index c96c3c4..7de1c87 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java @@ -28,11 +28,9 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class SWInventory implements Listener { @@ -55,9 +53,13 @@ public class SWInventory implements Listener { callbacks.put(-1, c); } + public void setItem(int pos, ItemStack itemStack, InvCallback c){ + inventory.setItem(pos, itemStack); + callbacks.put(pos, c); + } + public void setItem(int pos, SWItem item){ - inventory.setItem(pos, item.getItemStack()); - callbacks.put(pos, item.getCallback()); + setItem(pos, item.getItemStack(), item.getCallback()); } public void setItem(int pos, Material m, String name, InvCallback c){ @@ -91,9 +93,10 @@ public class SWInventory implements Listener { if(!player.equals(e.getWhoClicked())) return; - e.setCancelled(true); - if(callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null) + if(callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null) { + e.setCancelled(true); callbacks.get(e.getRawSlot()).clicked(e.getClick()); + } } @EventHandler From c694d5f1033ac65d0e6cc3ed93b57015037aeebd Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 17:53:28 +0100 Subject: [PATCH 14/15] Add TPSWatcher.getTPSLimited --- SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 314f246..e900586 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -29,7 +29,7 @@ public class TPSWatcher { private static final TPSWatcher tps_TenSecond = new TPSWatcher(10000); private long lastTime = System.currentTimeMillis(); - private double tps = 20.0; + private double tps = TICK_DEFAULT; private TPSWatcher(long timeInterval) { Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { @@ -46,12 +46,20 @@ public class TPSWatcher { return getTPS(TPSType.ONE_SECOND); } + public static double getTPSLimited(double limit) { + return getTPSLimited(TPSType.ONE_SECOND, limit); + } + public static double getTPSUnlimited() { return getTPSUnlimited(TPSType.ONE_SECOND); } + public static double getTPSLimited(TPSType tpsType, double limit) { + return Math.min(getTPSUnlimited(tpsType), limit); + } + public static double getTPS(TPSType tpsType) { - return Math.min(getTPSUnlimited(tpsType), 20.0); + return Math.min(getTPSUnlimited(tpsType), TICK_DEFAULT); } public static double getTPSUnlimited(TPSType tpsType) { From e28d4af9de12819c3aa1fc396329a2e0f48e1898 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 18:00:01 +0100 Subject: [PATCH 15/15] Simplify TPSWatcher --- SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index e900586..cb92fcf 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -46,20 +46,20 @@ public class TPSWatcher { return getTPS(TPSType.ONE_SECOND); } - public static double getTPSLimited(double limit) { - return getTPSLimited(TPSType.ONE_SECOND, limit); + public static double getTPS(double limit) { + return getTPS(TPSType.ONE_SECOND, limit); } public static double getTPSUnlimited() { return getTPSUnlimited(TPSType.ONE_SECOND); } - public static double getTPSLimited(TPSType tpsType, double limit) { - return Math.min(getTPSUnlimited(tpsType), limit); + public static double getTPS(TPSType tpsType) { + return getTPS(tpsType, TICK_DEFAULT); } - public static double getTPS(TPSType tpsType) { - return Math.min(getTPSUnlimited(tpsType), TICK_DEFAULT); + public static double getTPS(TPSType tpsType, double limit) { + return Math.min(getTPSUnlimited(tpsType), limit); } public static double getTPSUnlimited(TPSType tpsType) {