mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-29 13:36:04 +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?
|
* @return Is this block a sign?
|
||||||
*/
|
*/
|
||||||
public static boolean isSign(Block block) {
|
public static boolean isSign(Block block) {
|
||||||
|
if (!isLoaded(block)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
BlockData data = block.getBlockData();
|
BlockData data = block.getBlockData();
|
||||||
return data instanceof Sign || data instanceof WallSign;
|
return data instanceof Sign || data instanceof WallSign;
|
||||||
}
|
}
|
||||||
@ -33,7 +37,7 @@ public class BlockUtil {
|
|||||||
* @return Is this block a chest?
|
* @return Is this block a chest?
|
||||||
*/
|
*/
|
||||||
public static boolean isChest(Block block) {
|
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;
|
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
|
@Deprecated
|
||||||
public static org.bukkit.block.Chest findConnectedChest(Sign sign) {
|
public static org.bukkit.block.Chest findConnectedChest(Sign sign) {
|
||||||
|
if (!BlockUtil.isLoaded(sign.getBlock())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
BlockFace signFace = null;
|
BlockFace signFace = null;
|
||||||
BlockData data = sign.getBlockData();
|
BlockData data = sign.getBlockData();
|
||||||
if (data instanceof WallSign) {
|
if (data instanceof WallSign) {
|
||||||
@ -79,6 +82,10 @@ public class uBlock {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private static org.bukkit.block.Chest findConnectedChest(Block block, BlockFace signFace) {
|
private static org.bukkit.block.Chest findConnectedChest(Block block, BlockFace signFace) {
|
||||||
|
if (!BlockUtil.isLoaded(block)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (signFace != null) {
|
if (signFace != null) {
|
||||||
Block faceBlock = block.getRelative(signFace);
|
Block faceBlock = block.getRelative(signFace);
|
||||||
if (BlockUtil.isChest(faceBlock)) {
|
if (BlockUtil.isChest(faceBlock)) {
|
||||||
@ -98,6 +105,10 @@ public class uBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Container findConnectedContainer(Sign sign) {
|
public static Container findConnectedContainer(Sign sign) {
|
||||||
|
if (!BlockUtil.isLoaded(sign.getBlock())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
BlockFace signFace = null;
|
BlockFace signFace = null;
|
||||||
BlockData data = sign.getBlockData();
|
BlockData data = sign.getBlockData();
|
||||||
if (data instanceof WallSign) {
|
if (data instanceof WallSign) {
|
||||||
@ -107,6 +118,10 @@ public class uBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Container findConnectedContainer(Block block) {
|
public static Container findConnectedContainer(Block block) {
|
||||||
|
if (!BlockUtil.isLoaded(block)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
BlockFace signFace = null;
|
BlockFace signFace = null;
|
||||||
BlockData data = block.getBlockData();
|
BlockData data = block.getBlockData();
|
||||||
if (data instanceof WallSign) {
|
if (data instanceof WallSign) {
|
||||||
@ -221,6 +236,9 @@ public class uBlock {
|
|||||||
public static Sign findAnyNearbyShopSign(Block block) {
|
public static Sign findAnyNearbyShopSign(Block block) {
|
||||||
for (BlockFace bf : SHOP_FACES) {
|
for (BlockFace bf : SHOP_FACES) {
|
||||||
Block faceBlock = block.getRelative(bf);
|
Block faceBlock = block.getRelative(bf);
|
||||||
|
if (!BlockUtil.isLoaded(faceBlock)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
BlockData data = faceBlock.getBlockData();
|
BlockData data = faceBlock.getBlockData();
|
||||||
if (data instanceof WallSign) {
|
if (data instanceof WallSign) {
|
||||||
@ -247,6 +265,10 @@ public class uBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Block findNeighbor(Block block) {
|
public static Block findNeighbor(Block block) {
|
||||||
|
if (!BlockUtil.isLoaded(block)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
BlockData blockData = block.getBlockData();
|
BlockData blockData = block.getBlockData();
|
||||||
if (!(blockData instanceof Chest)) {
|
if (!(blockData instanceof Chest)) {
|
||||||
return null;
|
return null;
|
||||||
@ -275,6 +297,10 @@ public class uBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Block neighborBlock = block.getRelative(chestFace);
|
Block neighborBlock = block.getRelative(chestFace);
|
||||||
|
if (!BlockUtil.isLoaded(neighborBlock)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (neighborBlock.getType() == block.getType()) {
|
if (neighborBlock.getType() == block.getType()) {
|
||||||
return neighborBlock;
|
return neighborBlock;
|
||||||
}
|
}
|
||||||
@ -287,7 +313,7 @@ public class uBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean couldBeShopContainer(Block block) {
|
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) {
|
public static boolean couldBeShopContainer(InventoryHolder holder) {
|
||||||
|
Loading…
Reference in New Issue
Block a user