mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-12-27 07:48:48 +00:00
异步保存商店到数据库
由于handleChat已切回主线程,这里需要异步调用
This commit is contained in:
parent
1a624a8384
commit
4f3ee83b47
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user