ChestShop-3/com/Acrobot/ChestShop/Utils/BlockSearch.java

59 lines
1.8 KiB
Java
Raw Normal View History

2011-05-15 19:33:03 +02:00
package com.Acrobot.ChestShop.Utils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
/**
* @author Acrobot
*/
public class BlockSearch {
static BlockFace[] chestFaces = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
static BlockFace[] shopFaces = {BlockFace.DOWN, BlockFace.UP, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH, BlockFace.SELF};
2011-05-15 19:33:03 +02:00
2011-05-29 13:25:25 +02:00
public static Chest findChest(Sign sign) {
2011-05-15 19:33:03 +02:00
Block block = sign.getBlock();
return findChest(block);
}
2011-05-29 13:25:25 +02:00
public static Chest findChest(Block block) {
for (BlockFace bf : shopFaces) {
2011-05-15 19:33:03 +02:00
Block faceBlock = block.getFace(bf);
2011-05-29 13:25:25 +02:00
if (faceBlock.getType() == Material.CHEST) {
2011-05-15 19:33:03 +02:00
return (Chest) faceBlock.getState();
}
}
return null;
}
2011-05-29 13:25:25 +02:00
public static Sign findSign(Block block) {
for (BlockFace bf : shopFaces) {
2011-05-15 19:33:03 +02:00
Block faceBlock = block.getFace(bf);
2011-05-29 13:25:25 +02:00
if (SignUtil.isSign(faceBlock)) {
Sign sign = (Sign) faceBlock.getState();
if (SignUtil.isValid(sign)) {
2011-05-15 19:33:03 +02:00
return sign;
}
}
}
return null;
}
2011-06-09 22:54:01 +02:00
public static Chest findNeighbor(Block block) {
for (BlockFace blockFace : chestFaces) {
Block neighborBlock = block.getFace(blockFace);
2011-05-29 13:25:25 +02:00
if (neighborBlock.getType() == Material.CHEST) {
return (Chest) neighborBlock.getState();
}
}
return null; //Shame, we didn't find double chest :/
}
public static Chest findNeighbor(Chest chest){
return findNeighbor(chest.getBlock());
}
2011-05-15 19:33:03 +02:00
}