Former-commit-id: 4b61ecb25871a55723b03aaec82ff872258a5973 [formerly d35263dddc9704701b28ae5f0b09c55ca90e0d74]
Former-commit-id: cdf7f200c63540a30de1b86c915cf6860e813fbb
This commit is contained in:
Ghost_chu committed 2019-06-06 22:19:49 +08:00
1 parent 9d19b2dbfc
commit ac9d24f789
4 files changed
+38 -5

No files matched your search

@@ -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();
}
}
@@ -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())
@@ -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
@@ -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.
// */