From 8fb9c5c220f366bfb6feafcb5d47d4e5462f21af Mon Sep 17 00:00:00 2001 From: jameslfc19 Date: Mon, 27 Jul 2020 00:43:21 +0100 Subject: [PATCH] ChestLink Verifier Fix for ChestLinks not being converted to single chests when a block is on top of the DoubleChest. --- .../chests/runnables/ChestLinkVerifier.java | 36 +++++++++++++++++++ .../autocraft/AutoCraftingStorage.java | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/ChestLinkVerifier.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/ChestLinkVerifier.java index fdf5068..a79a892 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/ChestLinkVerifier.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/runnables/ChestLinkVerifier.java @@ -5,8 +5,10 @@ import com.jamesdpeters.minecraft.chests.serialize.Config; import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; +import org.bukkit.block.data.Directional; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.scheduler.BukkitRunnable; @@ -42,6 +44,8 @@ public class ChestLinkVerifier extends BukkitRunnable { convertToSingleChest(left.getInventory()); convertToSingleChest(right.getInventory()); } + } else { + manualCheck(chest); } } @@ -72,4 +76,36 @@ public class ChestLinkVerifier extends BukkitRunnable { return (leftStorage != null) || (rightStorage != null); } + + private void manualCheck(Chest chest){ + if(chest.getBlockData() instanceof Directional) { + Directional directional = (Directional) chest.getBlockData(); + BlockFace facing = directional.getFacing(); + BlockFace[] perpendulcarFaces = getPerpendicularFaces(facing); + if(perpendulcarFaces == null) return; + for (BlockFace perpendicularFace : perpendulcarFaces) { + Block toTest = block.getRelative(perpendicularFace); + if(toTest.getState() instanceof Chest && Config.getChestLink().getStorage(toTest.getLocation()) != null){ + convertToSingleChest(chest.getInventory()); + convertToSingleChest(((Chest) toTest.getState()).getInventory()); + convertToSingleChest(chest.getInventory()); + } + } + } + } + + private static final BlockFace[] NS = new BlockFace[]{BlockFace.WEST, BlockFace.EAST}; + private static final BlockFace[] WE = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH}; + + private BlockFace[] getPerpendicularFaces(BlockFace face){ + switch (face){ + case NORTH: + case SOUTH: + return NS; + case WEST: + case EAST: + return WE; + } + return null; + } } diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/autocraft/AutoCraftingStorage.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/autocraft/AutoCraftingStorage.java index dcf2244..ef227e0 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/autocraft/AutoCraftingStorage.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/storage/autocraft/AutoCraftingStorage.java @@ -126,6 +126,6 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio @Override public void postConfigLoad() { super.postConfigLoad(); - if(recipeSerializable != null) onItemDisplayUpdate(recipeSerializable.getRecipe().getResult()); + if(recipeSerializable != null && recipeSerializable.getRecipe() != null) onItemDisplayUpdate(recipeSerializable.getRecipe().getResult()); } }