mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-24 15:51:23 +01:00
Add more per material shop creation permissions
This commit is contained in:
parent
1cb481097c
commit
7311907559
@ -24,26 +24,39 @@ public class PermissionChecker implements Listener {
|
||||
public static void onPreShopCreation(PreShopCreationEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (Permission.has(player, ADMIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String priceLine = event.getSignLine(PRICE_LINE);
|
||||
String itemLine = event.getSignLine(ITEM_LINE);
|
||||
|
||||
ItemStack item = MaterialUtil.getItem(itemLine);
|
||||
|
||||
if (item == null || Permission.has(player, SHOP_CREATION_ID + item.getType().toString().toLowerCase())) {
|
||||
if (item == null) {
|
||||
if (!Permission.has(player, SHOP_CREATION)) {
|
||||
event.setOutcome(NO_PERMISSION);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (PriceUtil.hasBuyPrice(priceLine) && !Permission.has(player, SHOP_CREATION_BUY)) {
|
||||
String matID = item.getType().toString().toLowerCase();
|
||||
if (PriceUtil.hasBuyPrice(priceLine)) {
|
||||
if (Permission.has(player, SHOP_CREATION_BUY_ID + matID)) {
|
||||
return;
|
||||
}
|
||||
if (Permission.has(player, SHOP_CREATION) || (Permission.has(player, SHOP_CREATION_ID + matID) && Permission.has(player, SHOP_CREATION_BUY))) {
|
||||
return;
|
||||
}
|
||||
event.setOutcome(NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PriceUtil.hasSellPrice(priceLine) && !Permission.has(player, SHOP_CREATION_SELL)) {
|
||||
if (PriceUtil.hasSellPrice(priceLine)) {
|
||||
if (Permission.has(player, SHOP_CREATION_SELL_ID + matID)) {
|
||||
return;
|
||||
}
|
||||
if (Permission.has(player, SHOP_CREATION) || (Permission.has(player, SHOP_CREATION_ID + matID) && Permission.has(player, SHOP_CREATION_SELL))) {
|
||||
return;
|
||||
}
|
||||
event.setOutcome(NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.Acrobot.ChestShop;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -8,8 +9,12 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public enum Permission {
|
||||
SHOP_CREATION_BUY("ChestShop.shop.create.buy"),
|
||||
SHOP_CREATION_SELL("ChestShop.shop.create.sell"),
|
||||
SHOP_CREATION_BUY_ID("ChestShop.shop.create.buy."),
|
||||
|
||||
SHOP_CREATION_SELL("ChestShop.shop.create.sell"),
|
||||
SHOP_CREATION_SELL_ID("ChestShop.shop.create.sell."),
|
||||
|
||||
SHOP_CREATION("ChestShop.shop.create"),
|
||||
SHOP_CREATION_ID("ChestShop.shop.create."),
|
||||
|
||||
BUY("ChestShop.shop.buy"),
|
||||
@ -54,6 +59,21 @@ public enum Permission {
|
||||
return sender.isPermissionSet(permission) && sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
public static org.bukkit.permissions.Permission getPermission(Permission permission) {
|
||||
org.bukkit.permissions.Permission bukkitPerm = Bukkit.getServer().getPluginManager().getPermission(permission.permission);
|
||||
if (bukkitPerm == null) {
|
||||
bukkitPerm = permission.getPermission();
|
||||
try {
|
||||
Bukkit.getServer().getPluginManager().addPermission(bukkitPerm);
|
||||
} catch (IllegalArgumentException ignored) {} // this should never happen
|
||||
}
|
||||
return bukkitPerm;
|
||||
}
|
||||
|
||||
public org.bukkit.permissions.Permission getPermission() {
|
||||
return new org.bukkit.permissions.Permission(permission);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return permission;
|
||||
}
|
||||
|
@ -47,10 +47,14 @@ permissions:
|
||||
ChestShop.shop.create.sell: true
|
||||
ChestShop.shop.create.buy:
|
||||
description: Allows the user to create a shop that sells any item
|
||||
ChestShop.shop.create.buy.(itemType):
|
||||
description: Allows the user to create a shop that sells items with itemType like in the permission node (replace (itemType) with Material item name)
|
||||
ChestShop.shop.create.sell:
|
||||
description: Allows the user to create a shop that buy any item
|
||||
description: Allows the user to create a shop that buys any item
|
||||
ChestShop.shop.create.sell.(itemType):
|
||||
description: Allows the user to create a shop that buys items with itemType like in the permission node (replace (itemType) with Material item name)
|
||||
ChestShop.shop.create.(itemType):
|
||||
description: Allows user to create a shop that sells item with itemType like in the permission node (replace (itemType) with Material item name)
|
||||
description: Allows user to create a shop that sells items with itemType like in the permission node (replace (itemType) with Material item name)
|
||||
ChestShop.shop.buy.(itemType):
|
||||
description: Allows user to buy certain (itemType) from a shop (replace (itemType) with the Material item name)
|
||||
ChestShop.shop.sell.(itemType):
|
||||
|
Loading…
Reference in New Issue
Block a user