mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-11-22 01:58:54 +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) {
|
public void createShop(final Shop shop) {
|
||||||
final Location loc = shop.getLocation();
|
final Location loc = shop.getLocation();
|
||||||
final ItemStack item = shop.getItem();
|
final ItemStack item = shop.getItem();
|
||||||
try {
|
final String serializeItem = Util.serialize(item);
|
||||||
// Write it to the database
|
final String worldName = loc.getWorld().getName();
|
||||||
final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
final int x = loc.getBlockX();
|
||||||
plugin.getDB().execute(q,
|
final int y = loc.getBlockY();
|
||||||
shop.getOwner(),
|
final int z = loc.getBlockZ();
|
||||||
shop.getPrice(),
|
// Async database execute
|
||||||
Util.serialize(item),
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
loc.getBlockX(),
|
@Override
|
||||||
loc.getBlockY(),
|
public void run() {
|
||||||
loc.getBlockZ(),
|
try {
|
||||||
loc.getWorld().getName(),
|
// Write it to the database
|
||||||
(shop.isUnlimited() ? 1 : 0),
|
final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
shop.getShopType().toID());
|
plugin.getDB().execute(q,
|
||||||
// Add it to the world
|
shop.getOwner(),
|
||||||
addShop(loc.getWorld().getName(), shop);
|
shop.getPrice(),
|
||||||
} catch (final Exception e) {
|
serializeItem,
|
||||||
plugin.getLogger().warning("无法保存商店到数据库! 下次重启商店将会消失!");
|
x,
|
||||||
plugin.getLogger().warning("错误信息: " + e.getMessage());
|
y,
|
||||||
e.printStackTrace();
|
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) {
|
public String format(final double d) {
|
||||||
return plugin.getEcon().format(d);
|
return plugin.getEcon().format(d);
|
||||||
|
Loading…
Reference in New Issue
Block a user