Fix the hopper protection

This commit is contained in:
Acrobot 2014-01-08 00:12:29 +01:00
parent 138d0a6a35
commit 348cbda185
3 changed files with 31 additions and 4 deletions

View File

@ -1,12 +1,12 @@
package com.Acrobot.Breeze.Utils;
import org.bukkit.block.Block;
import org.bukkit.block.*;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.material.Attachable;
import org.bukkit.material.*;
/**
* @author Acrobot
@ -32,6 +32,16 @@ public class BlockUtil {
return block.getState() instanceof Chest;
}
/**
* Checks if the InventoryHolder is a chest
*
* @param holder Inventory holder to check
* @return Is this holder a chest?
*/
public static boolean isChest(InventoryHolder holder) {
return holder instanceof Chest || holder instanceof DoubleChest;
}
/**
* Gets the block to which the sign is attached
*

View File

@ -1,5 +1,6 @@
package com.Acrobot.ChestShop.Listeners.Item;
import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
@ -14,11 +15,11 @@ public class ItemMoveListener implements Listener {
@EventHandler
public static void onItemMove(InventoryMoveItemEvent event) {
if (event.getSource() == null || !(event.getSource().getHolder() instanceof Chest)) {
if (event.getSource() == null || !BlockUtil.isChest(event.getSource().getHolder())) {
return;
}
if (!ChestShopSign.isShopChest(((BlockState) event.getSource().getHolder()).getBlock())) {
if (!ChestShopSign.isShopChest(event.getSource().getHolder())) {
return;
}

View File

@ -7,9 +7,11 @@ import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.uName;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import java.util.regex.Pattern;
@ -61,6 +63,20 @@ public class ChestShopSign {
return uBlock.getConnectedSign((Chest) chest.getState()) != null;
}
public static boolean isShopChest(InventoryHolder holder) {
if (!BlockUtil.isChest(holder)) {
return false;
}
if (holder instanceof DoubleChest) {
return isShopChest(((DoubleChest) holder).getLocation().getBlock());
} else if (holder instanceof Chest) {
return isShopChest(((Chest) holder).getBlock());
} else {
return false;
}
}
public static boolean canAccess(Player player, Sign sign) {
if (player == null) return false;
if (sign == null) return true;