diff --git a/src/main/java/de/epiceric/shopchest/ShopCommand.java b/src/main/java/de/epiceric/shopchest/ShopCommand.java index 4aac551..7236144 100644 --- a/src/main/java/de/epiceric/shopchest/ShopCommand.java +++ b/src/main/java/de/epiceric/shopchest/ShopCommand.java @@ -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 [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 - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE)); } diff --git a/src/main/java/de/epiceric/shopchest/utils/Utils.java b/src/main/java/de/epiceric/shopchest/utils/Utils.java index 0e98212..3fcef13 100644 --- a/src/main/java/de/epiceric/shopchest/utils/Utils.java +++ b/src/main/java/de/epiceric/shopchest/utils/Utils.java @@ -257,6 +257,32 @@ public class Utils { return true; } + /** + *

Check if a player is allowed to create a shop that sells (or buys) the given item.

+ * 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