From 102d21f51b2656b89078092756365e3c5fa0d834 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Sat, 27 Oct 2018 12:34:01 +0800 Subject: [PATCH] switch to use DatabaseHelper Former-commit-id: 4a3f9ff9f3818a1af9baa49926371ea3d42ae070 --- .../maxgamer/quickshop/Database/DatabaseHelper.java | 12 ++++++++++-- .../org/maxgamer/quickshop/Shop/ShopManager.java | 10 +++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java b/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java index 215f27f76..555cf72d7 100644 --- a/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java +++ b/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java @@ -108,10 +108,18 @@ public class DatabaseHelper { } - public static void updateShop(Database db, String owner, ItemStack itemConfig, int unlimited, int shopType, + public static void updateShop(Database db, String owner, ItemStack item, 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); + db.execute(q, owner, Util.serialize(item), unlimited, shopType, price, x, y, z, world); + } + + public static void createShop(String owner, double price, ItemStack item, int unlimited, int shopType, String world, int x, int y, int z) { + String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; + QuickShop.instance.getDB().execute(q, owner, price, Util.serialize(item), x, y, z, world, unlimited, shopType); + // Reremake write in schedule data + String scheduleq = "INSERT INTO schedule (owner, world, x, y, z, timestamp) VALUES (?, ?, ?, ?, ?, ?)"; + QuickShop.instance.getDB().execute(scheduleq , owner, world,x,y,z, System.currentTimeMillis()); } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index cf220d863..7538c896b 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -26,6 +26,7 @@ import org.bukkit.material.Sign; import org.bukkit.plugin.RegisteredListener; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Database.Database; +import org.maxgamer.quickshop.Database.DatabaseHelper; import org.maxgamer.quickshop.Util.MsgUtil; import org.maxgamer.quickshop.Util.Permissions; import org.maxgamer.quickshop.Util.Util; @@ -55,15 +56,14 @@ public class ShopManager { public void createShop(Shop shop) { ShopCreateEvent ssShopCreateEvent = new ShopCreateEvent(shop, Bukkit.getPlayer(shop.getOwner())); Bukkit.getPluginManager().callEvent(ssShopCreateEvent); + if(ssShopCreateEvent.isCancelled()) { + return; + } Location loc = shop.getLocation(); ItemStack item = shop.getItem(); try { // Write it to the database - String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; - plugin.getDB().execute(q, shop.getOwner().toString(), shop.getPrice(), Util.serialize(item), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getWorld().getName(), (shop.isUnlimited() ? 1 : 0), shop.getShopType().toID()); - // Reremake write in schedule data - String scheduleq = "INSERT INTO schedule (owner, world, x, y, z, timestamp) VALUES (?, ?, ?, ?, ?, ?)"; - plugin.getDB().execute(scheduleq , shop.getOwner().toString(), loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), System.currentTimeMillis()); + DatabaseHelper.createShop(shop.getOwner().toString(), shop.getPrice(), item, (shop.isUnlimited() ? 1 : 0), shop.getShopType().toID(), loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); // Add it to the world addShop(loc.getWorld().getName(), shop); } catch (Exception error) {