From 207b2490197472258cb682d96ba2ca4684002f41 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 8 Sep 2015 12:59:34 +0200 Subject: [PATCH] Fixed Bugs --- plugin.yml | 2 +- src/de/epiceric/shopchest/ShopChest.java | 9 ++++++--- .../shopchest/interfaces/utils/Utils_R1.java | 2 +- .../shopchest/interfaces/utils/Utils_R2.java | 2 +- .../shopchest/interfaces/utils/Utils_R3.java | 2 +- src/de/epiceric/shopchest/shop/Shop.java | 5 +++++ src/de/epiceric/shopchest/sql/Database.java | 14 +++++++------- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/plugin.yml b/plugin.yml index c232c15..1d368fa 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ShopChest main: de.epiceric.shopchest.ShopChest -version: 1.5.3 +version: 1.5.4 author: EpicEric website: https://www.spigotmc.org/resources/shopchest.11431/ depend: [Vault] diff --git a/src/de/epiceric/shopchest/ShopChest.java b/src/de/epiceric/shopchest/ShopChest.java index 991367b..fd3fa6b 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -83,6 +83,7 @@ public class ShopChest extends JavaPlugin{ return perm != null; } + @Override public void onEnable() { @@ -107,6 +108,9 @@ public class ShopChest extends JavaPlugin{ logger.severe("Could not submit stats."); } + reloadConfig(); + saveDefaultConfig(); + sqlite = new SQLite(this); sqlite.load(); @@ -137,8 +141,7 @@ public class ShopChest extends JavaPlugin{ setupPermissions(); instance = this; - reloadConfig(); - saveDefaultConfig(); + UpdateChecker uc = new UpdateChecker(this, getDescription().getWebsite()); logger.info("Checking for Updates"); @@ -206,7 +209,7 @@ public class ShopChest extends JavaPlugin{ int count = 0; - for (int id = 1; id < sqlite.getCount() + 1; id++) { + for (int id = 1; id < sqlite.getHighestID() + 1; id++) { try { Shop shop = sqlite.getShop(id); diff --git a/src/de/epiceric/shopchest/interfaces/utils/Utils_R1.java b/src/de/epiceric/shopchest/interfaces/utils/Utils_R1.java index fb2ab2f..9256d00 100644 --- a/src/de/epiceric/shopchest/interfaces/utils/Utils_R1.java +++ b/src/de/epiceric/shopchest/interfaces/utils/Utils_R1.java @@ -36,7 +36,7 @@ public class Utils_R1 extends Utils { int count = 0; - for (int id = 1; id < ShopChest.sqlite.getCount() + 1; id++) { + for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) { try { Shop shop = ShopChest.sqlite.getShop(id); diff --git a/src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java b/src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java index f52c34d..61dace4 100644 --- a/src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java +++ b/src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java @@ -37,7 +37,7 @@ public class Utils_R2 extends Utils { int count = 0; - for (int id = 1; id < ShopChest.sqlite.getCount() + 1; id++) { + for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) { try { Shop shop = ShopChest.sqlite.getShop(id); diff --git a/src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java b/src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java index 2d4dd56..554d286 100644 --- a/src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java +++ b/src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java @@ -36,7 +36,7 @@ public class Utils_R3 extends Utils { int count = 0; - for (int id = 1; id < ShopChest.sqlite.getCount() + 1; id++) { + for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) { try { Shop shop = ShopChest.sqlite.getShop(id); diff --git a/src/de/epiceric/shopchest/shop/Shop.java b/src/de/epiceric/shopchest/shop/Shop.java index d181c70..93a8f04 100644 --- a/src/de/epiceric/shopchest/shop/Shop.java +++ b/src/de/epiceric/shopchest/shop/Shop.java @@ -101,6 +101,11 @@ public class Shop { } } else { + try { + throw new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ()); + } catch (Exception e) { + e.printStackTrace(); + } return; } diff --git a/src/de/epiceric/shopchest/sql/Database.java b/src/de/epiceric/shopchest/sql/Database.java index 7b768bd..ffece94 100644 --- a/src/de/epiceric/shopchest/sql/Database.java +++ b/src/de/epiceric/shopchest/sql/Database.java @@ -54,25 +54,25 @@ public abstract class Database { } public int getNextFreeID() { - for (int i = 1; i < getCount() + 1; i++) { + for (int i = 1; i < getHighestID() + 1; i++) { if (getProduct(i) == null) { return i; } else { - if (i == getCount()) { + if (i == getHighestID()) { return i + 1; } } } - return 0; + return 1; } - public int getCount() { + public int getHighestID() { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; - int highestID = 0; + int highestID = 1; try { conn = getSQLConnection(); ps = conn.prepareStatement("SELECT * FROM " + table + ";"); @@ -97,13 +97,13 @@ public abstract class Database { plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex); } } - return -1; + return 0; } public int getShopID(Shop shop) { - for (int i = 1; i < getCount() + 1; i++) { + for (int i = 1; i < getHighestID() + 1; i++) { try { Shop s = getShop(i);