ChestShop-3/com/Acrobot/ChestShop/Protection/Default.java

41 lines
1.5 KiB
Java
Raw Normal View History

2011-05-15 19:33:03 +02:00
package com.Acrobot.ChestShop.Protection;
import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.uLongName;
import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
/**
* @author Acrobot
*/
2011-05-29 13:25:25 +02:00
public class Default implements Protection {
public boolean isProtected(Block block) {
if ((uSign.isSign(block) && uSign.isValid((Sign) block.getState())) || uBlock.findSign(block) != null) return true;
if (!(block.getState() instanceof Chest)) return false;
Chest neighbor = uBlock.findNeighbor(block);
return neighbor != null && uBlock.findSign(neighbor.getBlock()) != null;
}
public boolean canAccess(Player player, Block block) {
Sign sign = uBlock.findSign(block);
Chest neighborChest = uBlock.findNeighbor(block);
Sign neighborSign = (neighborChest != null ? uBlock.findSign(neighborChest.getBlock()) : null);
String playerName = player.getName();
String signLine = "";
if (uSign.isSign(block) && uSign.isValid((Sign) block.getState())) signLine = ((Sign) block.getState()).getLine(0);
if (sign != null) signLine = sign.getLine(0);
if (neighborSign != null) signLine = neighborSign.getLine(0);
return uLongName.stripName(playerName).equals(signLine);
}
public boolean protect(String name, Block block) {
return false;
}
}