From 4f3ee83b472c50143c1df91809b8420df8ab10e9 Mon Sep 17 00:00:00 2001 From: 17jiong <17jiong@gmail.com> Date: Mon, 29 Jan 2018 01:06:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E4=BF=9D=E5=AD=98=E5=95=86?= =?UTF-8?q?=E5=BA=97=E5=88=B0=E6=95=B0=E6=8D=AE=E5=BA=93=20=E7=94=B1?= =?UTF-8?q?=E4=BA=8EhandleChat=E5=B7=B2=E5=88=87=E5=9B=9E=E4=B8=BB?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=EF=BC=8C=E8=BF=99=E9=87=8C=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maxgamer/QuickShop/Shop/ShopManager.java | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/ShopManager.java b/src/main/java/org/maxgamer/QuickShop/Shop/ShopManager.java index 85fb954..b462d4c 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/ShopManager.java @@ -95,29 +95,40 @@ public class ShopManager { } public void createShop(final Shop shop) { - final Location loc = shop.getLocation(); - final ItemStack item = shop.getItem(); - try { - // Write it to the database - final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; - plugin.getDB().execute(q, - shop.getOwner(), - shop.getPrice(), - Util.serialize(item), - loc.getBlockX(), - loc.getBlockY(), - loc.getBlockZ(), - loc.getWorld().getName(), - (shop.isUnlimited() ? 1 : 0), - shop.getShopType().toID()); - // Add it to the world - addShop(loc.getWorld().getName(), shop); - } catch (final Exception e) { - plugin.getLogger().warning("无法保存商店到数据库! 下次重启商店将会消失!"); - plugin.getLogger().warning("错误信息: " + e.getMessage()); - e.printStackTrace(); - } - } + final Location loc = shop.getLocation(); + final ItemStack item = shop.getItem(); + final String serializeItem = Util.serialize(item); + final String worldName = loc.getWorld().getName(); + final int x = loc.getBlockX(); + final int y = loc.getBlockY(); + final int z = loc.getBlockZ(); + // Async database execute + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override + public void run() { + try { + // Write it to the database + final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; + plugin.getDB().execute(q, + shop.getOwner(), + shop.getPrice(), + serializeItem, + x, + y, + y, + worldName, + (shop.isUnlimited() ? 1 : 0), + shop.getShopType().toID()); + } catch (final Exception e) { + plugin.getLogger().warning("无法保存商店到数据库! 下次重启商店将会消失!"); + plugin.getLogger().warning("错误信息: " + e.getMessage()); + e.printStackTrace(); + } + } + }); + // Add it to the world + addShop(worldName, shop); + } public String format(final double d) { return plugin.getEcon().format(d);