2011-07-23 21:00:47 +02:00
|
|
|
package com.Acrobot.ChestShop.Signs;
|
2011-06-23 23:25:34 +02:00
|
|
|
|
|
|
|
import com.Acrobot.ChestShop.Permission;
|
2011-07-05 19:08:55 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.uSign;
|
2011-06-23 23:25:34 +02:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
import org.bukkit.block.Sign;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
2011-07-23 21:00:47 +02:00
|
|
|
public class restrictedSign {
|
|
|
|
public static boolean isRestrictedShop(Sign sign) {
|
|
|
|
Block blockUp = sign.getBlock().getRelative(BlockFace.UP);
|
2011-07-05 19:08:55 +02:00
|
|
|
return uSign.isSign(blockUp) && isRestricted(((Sign) blockUp.getState()).getLines());
|
2011-06-23 23:25:34 +02:00
|
|
|
}
|
|
|
|
|
2011-07-02 20:34:14 +02:00
|
|
|
public static boolean isRestricted(String[] lines) {
|
2011-06-23 23:25:34 +02:00
|
|
|
return lines[0].equalsIgnoreCase("[restricted]");
|
|
|
|
}
|
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
public static boolean isRestricted(Sign sign) {
|
|
|
|
return sign.getLine(0).equalsIgnoreCase("[restricted]");
|
|
|
|
}
|
|
|
|
|
2011-07-02 20:34:14 +02:00
|
|
|
public static boolean canAccess(Sign sign, Player player) {
|
2011-07-23 21:00:47 +02:00
|
|
|
Block blockUp = sign.getBlock().getRelative(BlockFace.UP);
|
2012-01-09 22:39:38 +01:00
|
|
|
return !uSign.isSign(blockUp) || hasPermission(player, ((Sign) blockUp.getState()).getLines());
|
2011-09-06 19:01:57 +02:00
|
|
|
|
2012-01-09 22:39:38 +01:00
|
|
|
}
|
2011-06-23 23:25:34 +02:00
|
|
|
|
2012-03-17 15:00:25 +01:00
|
|
|
public static boolean canDestroy(Player p, Sign sign) {
|
2012-01-09 22:39:38 +01:00
|
|
|
Sign shopSign = getAssociatedSign(sign);
|
|
|
|
return uSign.canAccess(p, shopSign);
|
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
|
|
|
public static Sign getAssociatedSign(Sign restricted) {
|
2012-01-09 22:39:38 +01:00
|
|
|
Block down = restricted.getBlock().getRelative(BlockFace.DOWN);
|
|
|
|
return uSign.isSign(down) ? (Sign) down.getState() : null;
|
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
|
|
|
public static boolean hasPermission(Player p, String[] lines) {
|
2012-01-09 22:39:38 +01:00
|
|
|
if (Permission.has(p, Permission.ADMIN)) return true;
|
2011-06-23 23:25:34 +02:00
|
|
|
|
2011-07-02 20:34:14 +02:00
|
|
|
for (int i = 1; i <= 3; i++) {
|
2012-01-09 22:39:38 +01:00
|
|
|
if (p.hasPermission(Permission.GROUP.toString() + lines[i])) return true;
|
2011-06-23 23:25:34 +02:00
|
|
|
}
|
2011-07-23 21:00:47 +02:00
|
|
|
return false;
|
2011-06-23 23:25:34 +02:00
|
|
|
}
|
|
|
|
}
|