Added permission nodes for shop creation for specific items

Examples:
- "shopchest.create.apple"
- "shopchest.create.stone.2"

But: If a player has permission "shopchest.create", he is allowed to
create shops of all items. Also, the creation of admin shops is not
affected by these permissions.
This commit is contained in:
Eric 2017-04-26 16:21:04 +02:00
parent d161fc60ac
commit 460abc722e
2 changed files with 29 additions and 4 deletions

View File

@ -107,8 +107,7 @@ class ShopCommand implements CommandExecutor {
Player p = (Player) sender;
if (args[0].equalsIgnoreCase("create")) {
if (p.hasPermission(Permissions.CREATE)) {
if (Utils.hasPermissionToCreateShop(p, Utils.getPreferredItemInHand(p))) {
if (args.length == 4) {
needsHelp = false;
create(args, ShopType.NORMAL, p);
@ -438,7 +437,7 @@ class ShopCommand implements CommandExecutor {
}
}
plugin.debug(p.getName() + "'s prices are higher than the minimum");
plugin.debug(p.getName() + "'s prices are lower than the maximum");
if (sellEnabled && buyEnabled) {
if (plugin.getShopChestConfig().buy_greater_or_equal_sell) {
@ -552,7 +551,7 @@ class ShopCommand implements CommandExecutor {
if (sender instanceof Player) {
if (sender.hasPermission(Permissions.CREATE_ADMIN)) {
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " create <amount> <buy-price> <sell-price> [normal|admin] - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE));
} else {
} else if (sender.hasPermission(Permissions.CREATE)) {
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " create <amount> <buy-price> <sell-price> - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE));
}

View File

@ -257,6 +257,32 @@ public class Utils {
return true;
}
/**
* <p>Check if a player is allowed to create a shop that sells (or buys) the given item.</p>
* The player is allowed to create the shop if has either the permission {@code shopchest.create},
* {@code shopchest.create.[ITEM]} or {@code shopchest.create.[ITEM].[DURABILITY]}
* @param player Player to check
* @param item Item to be sold or bought
* @return Whether the player is allowed
*/
public static boolean hasPermissionToCreateShop(Player player, ItemStack item) {
if (player.hasPermission(Permissions.CREATE)) {
return true;
}
if (item.getDurability() == 0) {
if (player.hasPermission(Permissions.CREATE + "." + item.getType().toString())) {
return true;
}
}
if (player.hasPermission(Permissions.CREATE + "." + item.getType().toString() + "." + item.getDurability())) {
return true;
}
return false;
}
/**
* @param className Name of the class
* @return Class in {@code net.minecraft.server.[VERSION]} package with the specified name or {@code null} if the class was not found