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) {