1
0
mirror of https://e.coding.net/circlecloud/QuickShop.git synced 2024-11-22 01:58:54 +00:00

fix spawn item on Server Start...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
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 DisplayItem disItem = this.getDisplayItem();
final Location dispLoc = disItem.getDisplayLocation(); final Location dispLoc = disItem.getDisplayLocation();
if (dispLoc.getBlock() != null && dispLoc.getBlock().getType() == Material.WATER) { // Flowing if (dispLoc.getBlock() != null && dispLoc.getBlock().getType() == Material.WATER) { // Flowing
// water. // water.Stationery water does not move items.
// Stationery
// water
// does
// not
// move
// items.
disItem.remove(); disItem.remove();
return; return;
} }

View File

@ -14,8 +14,8 @@ import org.maxgamer.QuickShop.Util.NMS;
* cannot be interacted with. * cannot be interacted with.
*/ */
public class DisplayItem { public class DisplayItem {
private Shop shop; private final Shop shop;
private ItemStack iStack; private final ItemStack iStack;
private Item item; private Item item;
// private Location displayLoc; // private Location displayLoc;
@ -27,82 +27,12 @@ public class DisplayItem {
* @param iStack * @param iStack
* The item stack to clone properties of the display item from. * 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.shop = shop;
this.iStack = iStack.clone(); this.iStack = iStack.clone();
// this.displayLoc = shop.getLocation().clone().add(0.5, 1.2, 0.5); // 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 * @return Returns the exact location of the display item. (1 above shop
* block, in the center) * block, in the center)
@ -117,4 +47,81 @@ public class DisplayItem {
public Item getItem() { public Item getItem() {
return this.item; 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?");
}
}
} }