fix spawn item on Server Start...

Signed-off-by: j502647092 <jtb1@163.com>
pull/3/HEAD
j502647092 2015-10-05 02:25:10 +08:00
parent 2bf76ca5d1
commit e61daeb989
2 changed files with 82 additions and 81 deletions

View File

@ -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;
}

View File

@ -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?");
}
}
}