diff --git a/src/main/java/com/sk89q/worldguard/bukkit/util/Blocks.java b/src/main/java/com/sk89q/worldguard/bukkit/util/Blocks.java index 2a7323ee..e296abfb 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/util/Blocks.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/util/Blocks.java @@ -20,9 +20,13 @@ package com.sk89q.worldguard.bukkit.util; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; import org.bukkit.material.Bed; +import org.bukkit.material.Chest; import org.bukkit.material.MaterialData; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -43,7 +47,8 @@ private Blocks() { * @return a list of connected blocks, not including the given block */ public static List getConnected(Block block) { - MaterialData data = block.getState().getData(); + BlockState state = block.getState(); + MaterialData data = state.getData(); if (data instanceof Bed) { Bed bed = (Bed) data; @@ -52,6 +57,28 @@ public static List getConnected(Block block) { } else { return Arrays.asList(block.getRelative(bed.getFacing())); } + } else if (data instanceof Chest) { + BlockFace facing = ((Chest) data).getFacing(); + ArrayList chests = new ArrayList(); + if (facing == BlockFace.NORTH || facing == BlockFace.SOUTH) { + if (block.getRelative(BlockFace.EAST).getState().getData() instanceof Chest) { + chests.add(block.getRelative(BlockFace.EAST)); + } + if (block.getRelative(BlockFace.WEST).getState().getData() instanceof Chest) { + chests.add(block.getRelative(BlockFace.WEST)); + } + } else if (facing == BlockFace.EAST || facing == BlockFace.WEST) { + if (block.getRelative(BlockFace.NORTH).getState().getData() instanceof Chest) { + chests.add(block.getRelative(BlockFace.NORTH)); + } + if (block.getRelative(BlockFace.SOUTH).getState().getData() instanceof Chest) { + chests.add(block.getRelative(BlockFace.SOUTH)); + } + } else { + // don't know how to handle diagonal chests + return Collections.emptyList(); + } + return chests; } else { return Collections.emptyList(); }