Fix display issues and double chests

This commit is contained in:
Eric 2018-07-23 21:05:57 +02:00
parent 2ac81b0b8f
commit 43bb3e3b38
3 changed files with 36 additions and 18 deletions

View File

@ -28,6 +28,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest; import org.bukkit.block.DoubleChest;
import org.bukkit.block.data.type.Chest.Type;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -39,7 +40,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder;
import pl.islandworld.api.IslandWorldApi; import pl.islandworld.api.IslandWorldApi;
import us.talabrek.ultimateskyblock.api.IslandInfo; import us.talabrek.ultimateskyblock.api.IslandInfo;
@ -71,6 +72,9 @@ public class ChestProtectListener implements Listener {
public void onResult(Void result) { public void onResult(Void result) {
newShop.create(true); newShop.create(true);
shopUtils.addShop(newShop, true); shopUtils.addShop(newShop, true);
for (Player player : shop.getLocation().getWorld().getPlayers()) {
shopUtils.updateShops(player, true);
}
} }
}); });
} else { } else {
@ -125,30 +129,37 @@ public class ChestProtectListener implements Listener {
} }
} }
private BlockFace getNeighborFacing(Type chestType, BlockFace facing) {
switch (facing) {
case NORTH:
return chestType == Type.LEFT ? BlockFace.EAST : BlockFace.WEST;
case EAST:
return chestType == Type.LEFT ? BlockFace.SOUTH : BlockFace.NORTH;
case SOUTH:
return chestType == Type.LEFT ? BlockFace.WEST : BlockFace.EAST;
case WEST:
return chestType == Type.LEFT ? BlockFace.NORTH : BlockFace.SOUTH;
default:
return null;
}
}
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) { public void onBlockPlace(BlockPlaceEvent e) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
Block b = e.getBlockPlaced(); final Block b = e.getBlockPlaced();
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
Chest c = (Chest) b.getState(); Chest c = (Chest) b.getState();
InventoryHolder ih = c.getInventory().getHolder(); org.bukkit.block.data.type.Chest data = (org.bukkit.block.data.type.Chest) c.getBlockData();
if (ih instanceof DoubleChest) { if (data.getType() != Type.SINGLE) {
DoubleChest dc = (DoubleChest) ih; BlockFace neighborFacing = getNeighborFacing(data.getType(), data.getFacing());
Chest r = (Chest) dc.getRightSide(); Block b2 = b.getRelative(neighborFacing);
Chest l = (Chest) dc.getLeftSide();
if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) { if (shopUtils.isShop(b.getLocation()) || shopUtils.isShop(b2.getLocation())) {
final Shop shop; final Shop shop = shopUtils.getShop(b2.getLocation());
if (b.getLocation().equals(r.getLocation())) {
shop = shopUtils.getShop(l.getLocation());
} else if (b.getLocation().equals(l.getLocation())) {
shop = shopUtils.getShop(r.getLocation());
} else {
return;
}
plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
@ -232,6 +243,9 @@ public class ChestProtectListener implements Listener {
newShop.create(true); newShop.create(true);
shopUtils.addShop(newShop, true); shopUtils.addShop(newShop, true);
plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
for (Player player : shop.getLocation().getWorld().getPlayers()) {
shopUtils.updateShops(player, true);
}
} }
}); });
} else { } else {

View File

@ -287,7 +287,7 @@ public class Shop {
Chest r = chests[0]; Chest r = chests[0];
Chest l = chests[1]; Chest l = chests[1];
if (b.getLocation().equals(r.getLocation())) { if (b.getLocation().equals(l.getLocation())) {
if (r.getX() != l.getX()) { if (r.getX() != l.getX()) {
holoLocation = new Location(w, x, y - subtractY, z + 0.5); holoLocation = new Location(w, x, y - subtractY, z + 0.5);
} else if (r.getZ() != l.getZ()) { } else if (r.getZ() != l.getZ()) {

View File

@ -378,6 +378,10 @@ public class ShopUtils {
nearestShop = shop; nearestShop = shop;
nearestDistance = distance; nearestDistance = distance;
continue; continue;
} else if (nearestShop.getLocation().equals(shop.getLocation())) {
// shops are the same (double chest)
// => skip since it's already been handled
continue;
} }
// else: hologram is farther than nearest, so we hide it // else: hologram is farther than nearest, so we hide it
} }