ChestShop-3/com/Acrobot/ChestShop/Signs/restrictedSign.java
Acrobot dc4d9961c1 - Fancy sign formatting :D
- Fixed LWC, Lockette and Default protections
- Added restricted signs (Changed how they work)
- Added an option to use another name
- Fixed a bug where default protection was initialized too many times
- Disallowed players to place another chest near a shop chest
- Speeded up and fixed enchantment and durability in itemstacks
- Changed /iteminfo a bit
- Added /chestshop reload
- Added many default permission kits
- Fixed dye colors
- Added an option to allow towny residents place shops in their town
2012-01-09 22:39:38 +01:00

55 lines
1.9 KiB
Java

package com.Acrobot.ChestShop.Signs;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
/**
* @author Acrobot
*/
public class restrictedSign {
public static boolean isRestrictedShop(Sign sign) {
Block blockUp = sign.getBlock().getRelative(BlockFace.UP);
return uSign.isSign(blockUp) && isRestricted(((Sign) blockUp.getState()).getLines());
}
public static boolean isRestricted(String[] lines) {
return lines[0].equalsIgnoreCase("[restricted]");
}
public static boolean isRestricted(Sign sign) {
return sign.getLine(0).equalsIgnoreCase("[restricted]");
}
public static boolean canAccess(Sign sign, Player player) {
Block blockUp = sign.getBlock().getRelative(BlockFace.UP);
return !uSign.isSign(blockUp) || hasPermission(player, ((Sign) blockUp.getState()).getLines());
}
public static boolean canDestroy(Player p, Sign sign){
Sign shopSign = getAssociatedSign(sign);
return uSign.canAccess(p, shopSign);
}
public static Sign getAssociatedSign(Sign restricted){
Block down = restricted.getBlock().getRelative(BlockFace.DOWN);
return uSign.isSign(down) ? (Sign) down.getState() : null;
}
public static boolean hasPermission(Player p, String[] lines){
if (Permission.has(p, Permission.ADMIN)) return true;
String world = p.getWorld().getName();
String playerName = p.getName();
for (int i = 1; i <= 3; i++) {
if (Permission.permissions != null && Permission.permissions.inGroup(world, playerName, lines[i])) return true;
if (p.hasPermission(Permission.GROUP.toString() + lines[i])) return true;
}
return false;
}
}