mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-25 19:45:36 +01:00
Make sure to not load chunks to check for shops (Fixes #473)
This commit is contained in:
parent
f7aa80e566
commit
986a22fb73
@ -22,6 +22,10 @@ public class BlockUtil {
|
||||
* @return Is this block a sign?
|
||||
*/
|
||||
public static boolean isSign(Block block) {
|
||||
if (!isLoaded(block)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockData data = block.getBlockData();
|
||||
return data instanceof Sign || data instanceof WallSign;
|
||||
}
|
||||
@ -33,7 +37,7 @@ public class BlockUtil {
|
||||
* @return Is this block a chest?
|
||||
*/
|
||||
public static boolean isChest(Block block) {
|
||||
return block.getBlockData() instanceof org.bukkit.block.data.type.Chest;
|
||||
return BlockUtil.isLoaded(block) && block.getBlockData() instanceof org.bukkit.block.data.type.Chest;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,4 +111,14 @@ public class BlockUtil {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the chunk a block is in is loaded
|
||||
*
|
||||
* @param block The block to check
|
||||
* @return Whether or not the chunk is loaded
|
||||
*/
|
||||
public static boolean isLoaded(Block block) {
|
||||
return block.getWorld().isChunkLoaded(block.getX() >> 4, block.getZ() >> 4);
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,9 @@ public class uBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public static org.bukkit.block.Chest findConnectedChest(Sign sign) {
|
||||
if (!BlockUtil.isLoaded(sign.getBlock())) {
|
||||
return null;
|
||||
}
|
||||
BlockFace signFace = null;
|
||||
BlockData data = sign.getBlockData();
|
||||
if (data instanceof WallSign) {
|
||||
@ -79,6 +82,10 @@ public class uBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
private static org.bukkit.block.Chest findConnectedChest(Block block, BlockFace signFace) {
|
||||
if (!BlockUtil.isLoaded(block)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (signFace != null) {
|
||||
Block faceBlock = block.getRelative(signFace);
|
||||
if (BlockUtil.isChest(faceBlock)) {
|
||||
@ -98,6 +105,10 @@ public class uBlock {
|
||||
}
|
||||
|
||||
public static Container findConnectedContainer(Sign sign) {
|
||||
if (!BlockUtil.isLoaded(sign.getBlock())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockFace signFace = null;
|
||||
BlockData data = sign.getBlockData();
|
||||
if (data instanceof WallSign) {
|
||||
@ -107,6 +118,10 @@ public class uBlock {
|
||||
}
|
||||
|
||||
public static Container findConnectedContainer(Block block) {
|
||||
if (!BlockUtil.isLoaded(block)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockFace signFace = null;
|
||||
BlockData data = block.getBlockData();
|
||||
if (data instanceof WallSign) {
|
||||
@ -221,6 +236,9 @@ public class uBlock {
|
||||
public static Sign findAnyNearbyShopSign(Block block) {
|
||||
for (BlockFace bf : SHOP_FACES) {
|
||||
Block faceBlock = block.getRelative(bf);
|
||||
if (!BlockUtil.isLoaded(faceBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockData data = faceBlock.getBlockData();
|
||||
if (data instanceof WallSign) {
|
||||
@ -247,6 +265,10 @@ public class uBlock {
|
||||
}
|
||||
|
||||
public static Block findNeighbor(Block block) {
|
||||
if (!BlockUtil.isLoaded(block)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (!(blockData instanceof Chest)) {
|
||||
return null;
|
||||
@ -275,6 +297,10 @@ public class uBlock {
|
||||
}
|
||||
|
||||
Block neighborBlock = block.getRelative(chestFace);
|
||||
if (!BlockUtil.isLoaded(neighborBlock)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (neighborBlock.getType() == block.getType()) {
|
||||
return neighborBlock;
|
||||
}
|
||||
@ -287,7 +313,7 @@ public class uBlock {
|
||||
}
|
||||
|
||||
public static boolean couldBeShopContainer(Block block) {
|
||||
return block != null && Properties.SHOP_CONTAINERS.contains(block.getType());
|
||||
return block != null && BlockUtil.isLoaded(block) && Properties.SHOP_CONTAINERS.contains(block.getType());
|
||||
}
|
||||
|
||||
public static boolean couldBeShopContainer(InventoryHolder holder) {
|
||||
|
Loading…
Reference in New Issue
Block a user