diff --git a/src/main/java/org/maxgamer/QuickShop/Listeners/ProtectListener.java b/src/main/java/org/maxgamer/QuickShop/Listeners/ProtectListener.java index f4df1e9..d1b4146 100644 --- a/src/main/java/org/maxgamer/QuickShop/Listeners/ProtectListener.java +++ b/src/main/java/org/maxgamer/QuickShop/Listeners/ProtectListener.java @@ -10,6 +10,7 @@ import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.Inventory; @@ -57,6 +58,9 @@ public class ProtectListener implements Listener { final ItemStack ci = e.getCurrentItem(); final Inventory inv = e.getInventory(); final int solt = e.getSlot(); + if (inv.getType() != InventoryType.PLAYER && inv.getType() != InventoryType.HOPPER) { + return; + } try { if (MarkUtil.hasMark(ci)) { inv.setItem(solt, new ItemStack(Material.AIR)); diff --git a/src/main/java/org/maxgamer/QuickShop/QuickShop.java b/src/main/java/org/maxgamer/QuickShop/QuickShop.java index 0da3ffb..8b614e9 100644 --- a/src/main/java/org/maxgamer/QuickShop/QuickShop.java +++ b/src/main/java/org/maxgamer/QuickShop/QuickShop.java @@ -225,12 +225,14 @@ public class QuickShop extends JavaPlugin { getLogger().info("尝试启动魔改库..."); final FancyMessage fm = new FancyMessage("test"); fm.then("item").itemTooltip(new ItemStack(Material.DIAMOND_SWORD)); - fm.then("link").link("ci.ccitycraft.cn"); + fm.then("link").link("ci.citycraft.cn"); fm.then("suggest").suggest("qs help"); fm.toJSONString(); getLogger().info("魔改库功能测试正常..."); } catch (final NoClassDefFoundError | NoSuchMethodError | Exception e) { - getLogger().info("启动魔改库失败 部分功能将被禁用..."); + getLogger().warning("========================================"); + getLogger().warning("警告: 启动魔改库失败 部分功能将被禁用..."); + getLogger().warning("========================================"); } try { @@ -287,13 +289,8 @@ public class QuickShop extends JavaPlugin { final Location loc = new Location(world, x, y, z); /* Skip invalid shops, if we know of any */ if (world != null && loc.getChunk().isLoaded() && (loc.getBlock().getState() instanceof InventoryHolder) == false) { - getLogger().info("商店不是一个可存储的方块 坐标 " + rs.getString("world") + " at: " + x + ", " + y + ", " + z + ". 删除..."); - final PreparedStatement delps = getDB().getConnection().prepareStatement("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?"); - delps.setInt(1, x); - delps.setInt(2, y); - delps.setInt(3, z); - delps.setString(4, worldName); - delps.execute(); + getLogger().info("商店不是一个可存储的方块 坐标 " + rs.getString("world") + ", " + x + ", " + y + ", " + z + ". 删除..."); + database.execute("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?", x, y, z, worldName); continue; } final int type = rs.getInt("type"); @@ -313,12 +310,7 @@ public class QuickShop extends JavaPlugin { getLogger().warning("载入商店数据时发生错误! 商店位置: " + worldName + " (" + x + ", " + y + ", " + z + ")..."); if (errors < 3) { getLogger().warning("删除错误的商店数据..."); - final PreparedStatement delps = getDB().getConnection().prepareStatement("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?"); - delps.setInt(1, x); - delps.setInt(2, y); - delps.setInt(3, z); - delps.setString(4, worldName); - delps.execute(); + database.execute("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?", x, y, z, worldName); } else { getLogger().warning("过多的错误数据 可能您的数据库文件已损坏! 请检查数据库文件!"); e.printStackTrace(); @@ -343,9 +335,9 @@ public class QuickShop extends JavaPlugin { if (configManager.isDisplay()) { Bukkit.getServer().getPluginManager().registerEvents(chunkListener, this); // Display item handler thread - getLogger().info("开启悬浮物品刷新线程..."); + getLogger().info("开启商店检查以及悬浮物刷新线程..."); final ItemWatcher itemWatcher = new ItemWatcher(this); - itemWatcherTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 20, 600); + itemWatcherTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 20, 1800); } this.chatListener = new ChatListener(this); Bukkit.getServer().getPluginManager().registerEvents(chatListener, this); diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java index a20a4ae..a09340f 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java @@ -23,14 +23,14 @@ import org.maxgamer.QuickShop.Util.MsgUtil; import org.maxgamer.QuickShop.Util.Util; public class ContainerShop implements Shop { - private final Location loc; - private double price; - private String owner; - private final ItemStack item; private DisplayItem displayItem; - private boolean unlimited; - private ShopType shopType; + private final ItemStack item; + private final Location loc; + private String owner; private final QuickShop plugin; + private double price; + private ShopType shopType; + private boolean unlimited; /** * Adds a new shop. @@ -637,8 +637,8 @@ public class ContainerShop implements Shop { @Override public String toString() { - final StringBuilder sb = new StringBuilder( - "商店 " + (loc.getWorld() == null ? "世界尚未载入" : "坐标: " + loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ")"); + final StringBuilder sb = new StringBuilder("商店 " + (loc.getWorld() == null ? "世界尚未载入" : "坐标: " + loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + + loc.getBlockZ() + ")"); sb.append(" 所有者: " + getOwner()); if (isUnlimited()) { sb.append("无限模式: true"); @@ -679,6 +679,7 @@ public class ContainerShop implements Shop { if (trans && this.getDisplayItem() == null) { this.displayItem = new DisplayItem(this, this.getItem()); this.getDisplayItem().spawn(); + return; } if (this.getDisplayItem() != null) { if (!trans) { // We have a display item in a block... delete it diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java index 622e2f9..c95a079 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java @@ -13,9 +13,9 @@ import org.maxgamer.QuickShop.Util.NMS; * cannot be interacted with. */ public class DisplayItem { - private final Shop shop; private final ItemStack iStack; private Item item; + private final Shop shop; // private Location displayLoc; /** @@ -95,7 +95,9 @@ public class DisplayItem { */ public void respawn() { remove(); - spawn(); + if (item.isValid()) { + spawn(); + } } /** diff --git a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java index 810ddc6..584b9b6 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java @@ -125,11 +125,20 @@ public class MsgUtil { } } + public static void sendItemMessage(final Player p, final ItemStack is, final String msg) { + try { + final FancyMessage fm = new FancyMessage(); + fm.text(msg).itemTooltip(is).send(p); + } catch (Exception | NoClassDefFoundError | NoSuchMethodError e) { + p.sendMessage(msg); + } + } + public static void sendPurchaseSuccess(final Player p, final Shop shop, final int amount) { p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.successful-purchase")); - final FancyMessage fm = new FancyMessage(); - fm.text(ChatColor.DARK_PURPLE + "| ").then(MsgUtil.p("menu.item-name-and-price", "" + amount, shop.getDataName(), Util.format((amount * shop.getPrice())))).itemTooltip(shop.getItem()).send(p); + final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item-name-and-price", "" + amount, shop.getDataName(), Util.format((amount * shop.getPrice()))); + sendItemMessage(p, shop.getItem(), msg); p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); } @@ -165,8 +174,8 @@ public class MsgUtil { p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information")); p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.owner", Bukkit.getOfflinePlayer(shop.getOwner()).getName() == null ? (shop.isUnlimited() ? "系统商店" : "未知") : Bukkit.getOfflinePlayer(shop.getOwner()).getName())); - final FancyMessage fm = new FancyMessage(); - fm.text(ChatColor.DARK_PURPLE + "| ").then(MsgUtil.p("menu.item", shop.getDataName())).itemTooltip(items).send(p); + final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item", shop.getDataName()); + sendItemMessage(p, shop.getItem(), msg); if (Util.isTool(items.getType())) { p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.damage-percent-remaining", Util.getToolPercentage(items))); } @@ -182,30 +191,6 @@ public class MsgUtil { } else { p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-selling")); } - // Map enchs = items.getItemMeta().getEnchants(); - // if (enchs != null && !enchs.isEmpty()) { - // p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.getMessage("menu.enchants") + "-----------------------+"); - // for (final Entry entries : enchs.entrySet()) { - // p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey().getName() + " " + entries.getValue()); - // } - // } - // try { - // Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta"); - // if (items.getItemMeta() instanceof EnchantmentStorageMeta) { - // final EnchantmentStorageMeta stor = (EnchantmentStorageMeta) items.getItemMeta(); - // stor.getStoredEnchants(); - // enchs = stor.getStoredEnchants(); - // if (enchs != null && !enchs.isEmpty()) { - // p.sendMessage(ChatColor.DARK_PURPLE + "+-----------------" + MsgUtil.getMessage("menu.stored-enchants") + "--------------------+"); - // for (final Entry entries : enchs.entrySet()) { - // p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey().getName() + " " + entries.getValue()); - // } - // } - // } - // } catch (final ClassNotFoundException e) { - // // They don't have an up to date enough build of CB to do this. - // // TODO: Remove this when it becomes redundant - // } p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/QuickShop/Util/Util.java b/src/main/java/org/maxgamer/QuickShop/Util/Util.java index 41dfebc..6468371 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/Util.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/Util.java @@ -33,10 +33,10 @@ public class Util { public static void addTransparentBlock(final Material m) { if (transparent.add(m) == false) { - System.out.println("Already added as transparent: " + m.toString()); + System.out.println("已添加透明方块: " + m.toString()); } if (!m.isBlock()) { - System.out.println(m + " is not a block!"); + System.out.println(m + " 不是一个方块!"); } } @@ -48,11 +48,15 @@ public class Util { * @return True if it can be made into a shop, otherwise false. */ public static boolean canBeShop(final Block b) { - final BlockState bs = b.getState(); - if (bs instanceof InventoryHolder == false) { + try { + final BlockState bs = b.getState(); + if (bs instanceof InventoryHolder == false) { + return false; + } + return shoppables.contains(bs.getType()); + } catch (final Exception e) { return false; } - return shoppables.contains(bs.getType()); } /** diff --git a/src/main/resources/item.yml b/src/main/resources/item.yml index 4e4ab47..1c11b67 100644 --- a/src/main/resources/item.yml +++ b/src/main/resources/item.yml @@ -1,4 +1,4 @@ -Version: 1.3 +Version: 1.0 AIR_-1: 爪子 AIR: 爪子 @@ -365,7 +365,7 @@ COOKED_BEEF: 熟牛肉 RAW_CHICKEN: 生鸡肉 COOKED_CHICKEN: 熟鸡肉 ROTTEN_FLESH: 腐肉 -ENDER_PEARL: 末地传送门 +ENDER_PEARL: 末影之眼 BLAZE_ROD: 烈焰棒 GHAST_TEAR: 恶魂之泪 GOLD_NUGGET: 金粒