switch to use DatabaseHelper

Former-commit-id: 4a3f9ff9f3818a1af9baa49926371ea3d42ae070
This commit is contained in:
Ghost_chu committed 2018-10-27 12:34:01 +08:00
1 parent 8d29a9fff2
commit 102d21f51b
2 files changed
+15 -7

No files matched your search

@@ -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());
}
}
@@ -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) {