mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-08 19:51:05 +00:00
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:
parent
d161fc60ac
commit
460abc722e
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user