ChestLink Verifier

Fix for ChestLinks not being converted to single chests when a block is on top of the DoubleChest.
This commit is contained in:
jameslfc19 2020-07-27 00:43:21 +01:00
parent dd3d77e85a
commit 8fb9c5c220
2 changed files with 37 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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());
}
}