Phase out the plugin.yml command permissions

in favour of a custom message.
This commit is contained in:
Acrobot 2013-11-01 14:24:08 +01:00
parent 36c33612a0
commit 8afdc7edc7
3 changed files with 16 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.Breeze.Utils.NumberUtil;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Permission;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -21,6 +22,11 @@ public class Give implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!Permission.has(sender, Permission.ADMIN)) {
sender.sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
return true;
}
if (args.length < 1) {
return false;
}

View File

@ -1,5 +1,6 @@
package com.Acrobot.ChestShop;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
@ -31,25 +32,25 @@ public enum Permission {
this.permission = permission;
}
public static boolean has(Player player, Permission permission) {
return has(player, permission.permission);
public static boolean has(CommandSender sender, Permission permission) {
return has(sender, permission.permission);
}
public static boolean has(Player player, String node) {
return player.hasPermission(node) || player.hasPermission(node.toLowerCase());
public static boolean has(CommandSender sender, String node) {
return sender.hasPermission(node) || sender.hasPermission(node.toLowerCase());
}
public static boolean otherName(Player p, String name) {
if (has(p, Permission.ADMIN)) {
public static boolean otherName(Player player, String name) {
if (has(player, Permission.ADMIN)) {
return false;
}
String node = OTHER_NAME + name;
return hasPermissionSet(p, node) || hasPermissionSet(p, node.toLowerCase());
return hasPermissionSet(player, node) || hasPermissionSet(player, node.toLowerCase());
}
private static boolean hasPermissionSet(Player p, String perm) {
return p.isPermissionSet(perm) && p.hasPermission(perm);
private static boolean hasPermissionSet(CommandSender sender, String permission) {
return sender.isPermissionSet(permission) && sender.hasPermission(permission);
}
public String toString() {

View File

@ -28,7 +28,6 @@ commands:
aliases: [give]
description: Gives an item to the appropriate player
usage: /<command> <item code> (amount) (player)
permission: ChestShop.admin
csVersion:
aliases: [chestshop]
description: Shows the ChestShop's version