From 8d29a9fff272bb3cc0e3626250a0ef1f7a8f00c0 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Sat, 27 Oct 2018 12:19:08 +0800 Subject: [PATCH] cleanup code Former-commit-id: b0e393acd29365fb2c5992fdd7da9e60e29db8ea --- .../org/maxgamer/quickshop/Database/DatabaseHelper.java | 9 ++++++++- .../java/org/maxgamer/quickshop/Shop/ContainerShop.java | 5 +++-- src/main/java/org/maxgamer/quickshop/Util/ItemNMS.java | 4 +--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java b/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java index 64dc4ad00..215f27f76 100644 --- a/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java +++ b/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java @@ -4,8 +4,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; - +import org.bukkit.inventory.ItemStack; import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.Util.Util; public class DatabaseHelper { public static void setup(Database db) throws SQLException { @@ -106,5 +107,11 @@ public class DatabaseHelper { + " AND world = \"" + worldName + "\" LIMIT 1"); } + + public static void updateShop(Database db, String owner, ItemStack itemConfig, int unlimited, int shopType, + double price, int x, int y, int z, String world) { + String q = "UPDATE shops SET owner = ?, itemConfig = ?, unlimited = ?, type = ?, price = ? WHERE x = ? AND y = ? and z = ? and world = ?"; + db.execute(q, owner, Util.serialize(itemConfig), unlimited, shopType, price, x, y, z, world); + } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index f7e55b6a6..a7dc952be 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -199,9 +199,10 @@ public class ContainerShop implements Shop { int z = this.getLocation().getBlockZ(); String world = this.getLocation().getWorld().getName(); int unlimited = this.isUnlimited() ? 1 : 0; - String q = "UPDATE shops SET owner = ?, itemConfig = ?, unlimited = ?, type = ?, price = ? WHERE x = ? AND y = ? and z = ? and world = ?"; + //String q = "UPDATE shops SET owner = ?, itemConfig = ?, unlimited = ?, type = ?, price = ? WHERE x = ? AND y = ? and z = ? and world = ?"; try { - plugin.getDB().execute(q, this.getOwner().toString(), Util.serialize(this.getItem()), unlimited, shopType.toID(), this.getPrice(), x, y, z, world); + //plugin.getDB().execute(q, this.getOwner().toString(), Util.serialize(this.getItem()), unlimited, shopType.toID(), this.getPrice(), x, y, z, world); + DatabaseHelper.updateShop(plugin.getDB(), this.getOwner().toString(), this.getItem(), unlimited, shopType.toID(), this.getPrice(), x, y, z, world); } catch (Exception e) { e.printStackTrace(); plugin.getLogger().log(Level.WARNING, "Could not update shop in database! Changes will revert after a reboot!"); diff --git a/src/main/java/org/maxgamer/quickshop/Util/ItemNMS.java b/src/main/java/org/maxgamer/quickshop/Util/ItemNMS.java index 9cee5ca96..7a3a63e58 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/ItemNMS.java +++ b/src/main/java/org/maxgamer/quickshop/Util/ItemNMS.java @@ -21,11 +21,9 @@ public class ItemNMS { Object obj; try { obj = nmsClass.newInstance(); - } catch (InstantiationException e1) { - // TODO Auto-generated catch block + } catch (InstantiationException e1) { //NMS Class not found, Use old preview return null; } catch (IllegalAccessException e1) { - // TODO Auto-generated catch block return null; } try {