From ac9d24f789c4b5e59cfc0beb4e5aa6dc6b214997 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 6 Jun 2019 22:19:49 +0800 Subject: [PATCH] comments Former-commit-id: 4b61ecb25871a55723b03aaec82ff872258a5973 [formerly d35263dddc9704701b28ae5f0b09c55ca90e0d74] Former-commit-id: cdf7f200c63540a30de1b86c915cf6860e813fbb --- .../quickshop/Shop/ArmorStandDisplayItem.java | 11 +++++++++ .../quickshop/Shop/ContainerShop.java | 2 ++ .../maxgamer/quickshop/Shop/DisplayItem.java | 7 ++++++ .../quickshop/Shop/RealDisplayItem.java | 23 +++++++++++++++---- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java index f1d2c0a6b..f81130e3d 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java @@ -127,11 +127,15 @@ public class ArmorStandDisplayItem implements DisplayItem { @Override public boolean checkDisplayIsMoved() { + if (this.armorStand == null) + return false; return !this.armorStand.getLocation().equals(getDisplayLocation()); } @Override public boolean checkDisplayNeedRegen() { + if (this.armorStand == null) + return false; return !this.armorStand.isValid() || this.armorStand.isDead(); } @@ -185,4 +189,11 @@ public class ArmorStandDisplayItem implements DisplayItem { public void fixDisplayNeedRegen() { respawn(); } + + @Override + public boolean isSpawned() { + if (this.armorStand == null) + return false; + return this.armorStand.isValid(); + } } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index a8ea44cfe..40c8d8532 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -843,6 +843,8 @@ public class ContainerShop implements Shop { public void checkDisplay() { if (this.displayItem == null) return; + if (!this.displayItem.isSpawned()) + this.displayItem.spawn(); if (this.displayItem.checkDisplayNeedRegen()) this.displayItem.fixDisplayNeedRegen(); if (this.displayItem.checkDisplayIsMoved()) diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index e11f4772e..e789ed634 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -105,6 +105,13 @@ public interface DisplayItem { */ public abstract void fixDisplayNeedRegen(); + /** + * Check the display is or not already spawned + * + * @return Spawned + */ + public abstract boolean isSpawned(); + /** * Create a new itemStack with protect flag. * @param itemStack Old itemStack diff --git a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java index f9e36af88..191b9e384 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java @@ -3,10 +3,10 @@ package org.maxgamer.quickshop.Shop; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; -import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Util.Util; @@ -60,7 +60,7 @@ public class RealDisplayItem implements DisplayItem { this.item.setPickupDelay(Integer.MAX_VALUE); this.item.setSilent(true); this.item.setPortalCooldown(Integer.MAX_VALUE); - this.item.setGravity(false); + this.item.setVelocity(new Vector(0, 0.1, 0)); safeGuard(this.item); Util.debugLog("Spawned new DisplayItem for shop " + shop.getLocation().toString()); } @@ -70,8 +70,8 @@ public class RealDisplayItem implements DisplayItem { if (entity == null) { Util.debugLog("Failed to safeGuard the NULL, somethings given a wrong args."); } - if (!(entity instanceof ArmorStand)) { - Util.debugLog("Failed to safeGuard " + entity.getLocation().toString() + ", cause target not a ArmorStand"); + if (!(entity instanceof Item)) { + Util.debugLog("Failed to safeGuard " + entity.getLocation().toString() + ", cause target not a Item"); return; } Item item = (Item) entity; @@ -136,12 +136,18 @@ public class RealDisplayItem implements DisplayItem { @Override public boolean checkDisplayNeedRegen() { + if (this.item == null) + return false; return !this.item.isValid() || this.item.isDead(); } @Override public boolean checkDisplayIsMoved() { - return !this.item.getLocation().equals(getDisplayLocation()); + if (this.item == null) + return false; + //return !this.item.getLocation().equals(getDisplayLocation()); + /* We give 0.2 value to allow item drop on the chest, not floating on the air. */ + return this.item.getLocation().distance(getDisplayLocation()) > 0.2; } @Override @@ -164,6 +170,13 @@ public class RealDisplayItem implements DisplayItem { } } + @Override + public boolean isSpawned() { + if (this.item == null) + return false; + return this.item.isValid(); + } + // /** // * Spawns the dummy item on top of the shop. // */