From e61daeb9899b05b2597b7c9b3170a562a4a5ea9c Mon Sep 17 00:00:00 2001 From: j502647092 Date: Mon, 5 Oct 2015 02:25:10 +0800 Subject: [PATCH] fix spawn item on Server Start... Signed-off-by: j502647092 --- .../QuickShop/Shop/ContainerShop.java | 8 +- .../maxgamer/QuickShop/Shop/DisplayItem.java | 155 +++++++++--------- 2 files changed, 82 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java index 75516b1..d3ea7a9 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java @@ -688,13 +688,7 @@ public class ContainerShop implements Shop { final DisplayItem disItem = this.getDisplayItem(); final Location dispLoc = disItem.getDisplayLocation(); if (dispLoc.getBlock() != null && dispLoc.getBlock().getType() == Material.WATER) { // Flowing - // water. - // Stationery - // water - // does - // not - // move - // items. + // water.Stationery water does not move items. disItem.remove(); return; } diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java index 1319884..b6b5a9a 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java @@ -14,95 +14,25 @@ import org.maxgamer.QuickShop.Util.NMS; * cannot be interacted with. */ public class DisplayItem { - private Shop shop; - private ItemStack iStack; + private final Shop shop; + private final ItemStack iStack; private Item item; // private Location displayLoc; /** * Creates a new display item. - * + * * @param shop * The shop (See Shop) * @param iStack * The item stack to clone properties of the display item from. */ - public DisplayItem(Shop shop, ItemStack iStack) { + public DisplayItem(final Shop shop, final ItemStack iStack) { this.shop = shop; this.iStack = iStack.clone(); // this.displayLoc = shop.getLocation().clone().add(0.5, 1.2, 0.5); } - /** - * Spawns the dummy item on top of the shop. - */ - public void spawn() { - if (shop.getLocation().getWorld() == null) - return; - Location dispLoc = this.getDisplayLocation(); - this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack); - this.item.setVelocity(new Vector(0, 0.1, 0)); - if (QuickShop.debug) { - System.out.println("Spawned item. Safeguarding."); - } - try { - NMS.safeGuard(this.item); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("QuickShop version mismatch! This version of QuickShop is incompatible with this version of bukkit! Try update?"); - } - } - - /** - * Spawns the new display item. Does not remove duplicate items. - */ - public void respawn() { - remove(); - spawn(); - } - - /** - * Removes all items floating ontop of the chest that aren't the display - * item. - */ - public boolean removeDupe() { - if (shop.getLocation().getWorld() == null) - return false; - // QuickShop qs = (QuickShop) - // Bukkit.getPluginManager().getPlugin("QuickShop"); - Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation(); - boolean removed = false; - Chunk c = displayLoc.getChunk(); - for (Entity e : c.getEntities()) { - if (!(e instanceof Item)) - continue; - if (this.item != null && e.getEntityId() == this.item.getEntityId()) - continue; - Location eLoc = e.getLocation().getBlock().getLocation(); - if (eLoc.equals(displayLoc) || eLoc.equals(shop.getLocation())) { - ItemStack near = ((Item) e).getItemStack(); - // if its the same its a dupe - if (this.shop.matches(near)) { - e.remove(); - removed = true; - if (QuickShop.debug) { - System.out.println("Removed rogue item: " + near.getType()); - } - } - } - } - return removed; - } - - /** - * Removes the display item. - */ - public void remove() { - if (this.item == null) - return; - this.item.remove(); - } - /** * @return Returns the exact location of the display item. (1 above shop * block, in the center) @@ -117,4 +47,81 @@ public class DisplayItem { public Item getItem() { return this.item; } + + /** + * Removes the display item. + */ + public void remove() { + if (this.item == null) { + return; + } + this.item.remove(); + } + + /** + * Removes all items floating ontop of the chest that aren't the display + * item. + */ + public boolean removeDupe() { + if (shop.getLocation().getWorld() == null) { + return false; + } + // QuickShop qs = (QuickShop) + // Bukkit.getPluginManager().getPlugin("QuickShop"); + final Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation(); + boolean removed = false; + final Chunk c = displayLoc.getChunk(); + for (final Entity e : c.getEntities()) { + if (!(e instanceof Item)) { + continue; + } + if (this.item != null && e.getEntityId() == this.item.getEntityId()) { + continue; + } + final Location eLoc = e.getLocation().getBlock().getLocation(); + if (eLoc.equals(displayLoc) || eLoc.equals(shop.getLocation())) { + final ItemStack near = ((Item) e).getItemStack(); + // if its the same its a dupe + if (this.shop.matches(near)) { + e.remove(); + removed = true; + if (QuickShop.debug) { + System.out.println("Removed rogue item: " + near.getType()); + } + } + } + } + return removed; + } + + /** + * Spawns the new display item. Does not remove duplicate items. + */ + public void respawn() { + remove(); + spawn(); + } + + /** + * Spawns the dummy item on top of the shop. + */ + public void spawn() { + if (shop.getLocation().getWorld() == null) { + return; + } + final Location dispLoc = this.getDisplayLocation(); + try { + this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack); + this.item.setVelocity(new Vector(0, 0.1, 0)); + } catch (final Exception e) { + } + if (QuickShop.debug) { + System.out.println("Spawned item. Safeguarding."); + } + try { + NMS.safeGuard(this.item); + } catch (final Exception e) { + System.out.println("QuickShop version mismatch! This version of QuickShop is incompatible with this version of bukkit! Try update?"); + } + } } \ No newline at end of file