2011-05-15 19:33:03 +02:00
|
|
|
package com.Acrobot.ChestShop.Utils;
|
|
|
|
|
2011-10-11 13:15:53 +02:00
|
|
|
import com.Acrobot.ChestShop.Listeners.blockBreak;
|
2011-07-23 21:00:47 +02:00
|
|
|
import com.Acrobot.ChestShop.Signs.restrictedSign;
|
2011-05-15 19:33:03 +02:00
|
|
|
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
|
|
|
|
*/
|
2011-07-05 19:08:55 +02:00
|
|
|
public class uBlock {
|
2011-06-23 23:25:34 +02:00
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
private static final BlockFace[] chestFaces = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
|
2011-09-09 15:15:53 +02:00
|
|
|
private static final BlockFace[] shopFaces = {BlockFace.SELF, BlockFace.DOWN, BlockFace.UP, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
|
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) {
|
2011-06-23 23:25:34 +02:00
|
|
|
for (BlockFace bf : shopFaces) {
|
2011-07-23 21:00:47 +02:00
|
|
|
Block faceBlock = block.getRelative(bf);
|
2011-08-13 12:08:34 +02:00
|
|
|
if (faceBlock.getType() == Material.CHEST) return (Chest) faceBlock.getState();
|
2011-05-15 19:33:03 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-12-01 14:02:58 +01:00
|
|
|
public static Sign findSign(Block block, String originalName) {
|
|
|
|
for (BlockFace bf : shopFaces) {
|
|
|
|
Block faceBlock = block.getRelative(bf);
|
|
|
|
if (uSign.isSign(faceBlock)) {
|
|
|
|
Sign sign = (Sign) faceBlock.getState();
|
|
|
|
if (uSign.isValid(sign) && !sign.getLine(0).equals(originalName) && (faceBlock.equals(block) || blockBreak.getAttachedFace(sign).equals(block))) return sign;
|
|
|
|
}
|
|
|
|
}
|
2011-10-11 13:15:53 +02:00
|
|
|
for (BlockFace bf : shopFaces) {
|
|
|
|
Block faceBlock = block.getRelative(bf);
|
|
|
|
if (uSign.isSign(faceBlock)) {
|
|
|
|
Sign sign = (Sign) faceBlock.getState();
|
|
|
|
if (uSign.isValid(sign) && (faceBlock.equals(block) || blockBreak.getAttachedFace(sign).equals(block))) return sign;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Well, I need to re-write this plugin... I hate to code like that - sorry!
|
|
|
|
public static Sign findSign2(Block block){
|
2011-06-23 23:25:34 +02:00
|
|
|
for (BlockFace bf : shopFaces) {
|
2011-07-23 21:00:47 +02:00
|
|
|
Block faceBlock = block.getRelative(bf);
|
2011-07-05 19:08:55 +02:00
|
|
|
if (uSign.isSign(faceBlock)) {
|
2011-05-29 13:25:25 +02:00
|
|
|
Sign sign = (Sign) faceBlock.getState();
|
2011-08-13 12:08:34 +02:00
|
|
|
if (uSign.isValid(sign)) return sign;
|
2011-05-15 19:33:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2011-06-09 22:54:01 +02:00
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
public static Sign findRestrictedSign(Block block) {
|
|
|
|
for (BlockFace bf : shopFaces) {
|
|
|
|
Block faceBlock = block.getRelative(bf);
|
|
|
|
if (uSign.isSign(faceBlock)) {
|
|
|
|
Sign sign = (Sign) faceBlock.getState();
|
2011-10-11 13:15:53 +02:00
|
|
|
if (restrictedSign.isRestricted(sign) && (faceBlock.equals(block) || blockBreak.getAttachedFace(sign).equals(block))) return sign;
|
2011-07-23 21:00:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-06-19 23:52:36 +02:00
|
|
|
public static Chest findNeighbor(Block block) {
|
2011-06-23 23:25:34 +02:00
|
|
|
for (BlockFace blockFace : chestFaces) {
|
2011-07-23 21:00:47 +02:00
|
|
|
Block neighborBlock = block.getRelative(blockFace);
|
2011-05-29 13:25:25 +02:00
|
|
|
if (neighborBlock.getType() == Material.CHEST) {
|
|
|
|
return (Chest) neighborBlock.getState();
|
|
|
|
}
|
|
|
|
}
|
2011-08-13 12:08:34 +02:00
|
|
|
return null;
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
2011-06-19 23:52:36 +02:00
|
|
|
|
2011-07-02 20:34:14 +02:00
|
|
|
public static Chest findNeighbor(Chest chest) {
|
2011-06-19 23:52:36 +02:00
|
|
|
return findNeighbor(chest.getBlock());
|
|
|
|
}
|
2011-05-15 19:33:03 +02:00
|
|
|
}
|