2011-05-15 19:33:03 +02:00
|
|
|
package com.Acrobot.ChestShop.Protection;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-10-11 13:15:53 +02:00
|
|
|
import com.Acrobot.ChestShop.Listeners.blockBreak;
|
2011-08-13 12:08:34 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.uLongName;
|
2011-10-11 13:15:53 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.uSign;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.block.Block;
|
2011-10-11 13:15:53 +02:00
|
|
|
import org.bukkit.block.BlockFace;
|
2011-05-29 13:25:25 +02:00
|
|
|
import org.bukkit.block.Sign;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2011-12-01 14:02:58 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2011-05-15 18:16:25 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class Security {
|
2011-10-11 13:15:53 +02:00
|
|
|
private static BlockFace[] faces = {BlockFace.UP, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
|
2011-12-01 14:02:58 +01:00
|
|
|
public static ArrayList<Protection> protections = new ArrayList<Protection>();
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static boolean protect(String name, Block block) {
|
2011-12-01 14:02:58 +01:00
|
|
|
boolean works = false;
|
|
|
|
for (int i = 0; i < protections.size() && !works; i++) works = protections.get(i).protect(name, block);
|
|
|
|
return works;
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static boolean canAccess(Player player, Block block) {
|
2011-12-01 14:02:58 +01:00
|
|
|
boolean works = true;
|
|
|
|
for (int i = 0; i < protections.size() && works; i++) works = protections.get(i).canAccess(player, block);
|
|
|
|
return works;
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static boolean isProtected(Block block) {
|
2011-12-01 14:02:58 +01:00
|
|
|
boolean isProtected = false;
|
|
|
|
for (int i = 0; i < protections.size() && !isProtected; i++) isProtected = protections.get(i).isProtected(block);
|
|
|
|
return isProtected;
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2011-10-11 13:15:53 +02:00
|
|
|
public static boolean canPlaceSign(Player p, Sign sign) {
|
2011-12-01 14:02:58 +01:00
|
|
|
return !thereIsAnotherSignByPlayer(blockBreak.getAttachedFace(sign), sign.getBlock(), uLongName.stripName(p.getName()));
|
2011-10-11 13:15:53 +02:00
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2011-10-11 13:15:53 +02:00
|
|
|
private static boolean thereIsAnotherSignByPlayer(Block baseBlock, Block signBlock, String shortName){
|
|
|
|
for (BlockFace bf : faces){
|
|
|
|
Block block = baseBlock.getRelative(bf);
|
|
|
|
if(uSign.isSign(block) && !block.equals(signBlock) && blockBreak.getAttachedFace((Sign) block.getState()).equals(baseBlock) && !((Sign) block.getState()).getLine(0).equals(shortName)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|