2011-05-15 19:33:03 +02:00
|
|
|
package com.Acrobot.ChestShop;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2018-06-24 01:17:35 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2013-11-01 14:24:08 +01:00
|
|
|
import org.bukkit.command.CommandSender;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2020-01-29 16:35:04 +01:00
|
|
|
import java.util.Locale;
|
2018-11-19 21:10:48 +01:00
|
|
|
import java.util.Optional;
|
|
|
|
|
2011-05-15 18:16:25 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
2011-05-29 13:25:25 +02:00
|
|
|
public enum Permission {
|
2012-03-01 22:03:59 +01:00
|
|
|
SHOP_CREATION_BUY("ChestShop.shop.create.buy"),
|
2018-06-24 01:17:35 +02:00
|
|
|
SHOP_CREATION_BUY_ID("ChestShop.shop.create.buy."),
|
|
|
|
|
2012-03-01 22:03:59 +01:00
|
|
|
SHOP_CREATION_SELL("ChestShop.shop.create.sell"),
|
2018-06-24 01:17:35 +02:00
|
|
|
SHOP_CREATION_SELL_ID("ChestShop.shop.create.sell."),
|
2012-03-01 22:03:59 +01:00
|
|
|
|
2018-06-24 01:17:35 +02:00
|
|
|
SHOP_CREATION("ChestShop.shop.create"),
|
2012-03-01 22:03:59 +01:00
|
|
|
SHOP_CREATION_ID("ChestShop.shop.create."),
|
|
|
|
|
2011-06-23 23:25:34 +02:00
|
|
|
BUY("ChestShop.shop.buy"),
|
2011-08-13 12:08:34 +02:00
|
|
|
BUY_ID("ChestShop.shop.buy."),
|
2012-03-01 22:03:59 +01:00
|
|
|
|
2011-08-13 12:08:34 +02:00
|
|
|
SELL_ID("ChestShop.shop.sell."),
|
2011-06-23 23:25:34 +02:00
|
|
|
SELL("ChestShop.shop.sell"),
|
2012-03-01 22:03:59 +01:00
|
|
|
|
2011-07-01 14:12:26 +02:00
|
|
|
ADMIN("ChestShop.admin"),
|
2018-11-19 21:10:48 +01:00
|
|
|
ADMIN_SHOP("ChestShop.adminshop"),
|
2011-12-01 14:02:58 +01:00
|
|
|
MOD("ChestShop.mod"),
|
2018-11-19 21:10:48 +01:00
|
|
|
OTHER_NAME("ChestShop.name"),
|
|
|
|
OTHER_NAME_CREATE("ChestShop.othername.create"),
|
|
|
|
OTHER_NAME_DESTROY("ChestShop.othername.destroy"),
|
|
|
|
OTHER_NAME_ACCESS("ChestShop.othername.access"),
|
2012-01-25 16:32:34 +01:00
|
|
|
GROUP("ChestShop.group."),
|
2012-08-24 10:24:20 +02:00
|
|
|
|
|
|
|
NOFEE("ChestShop.nofee"),
|
2014-05-20 23:13:25 +02:00
|
|
|
DISCOUNT("ChestShop.discount."),
|
2019-04-25 19:44:22 +02:00
|
|
|
NO_BUY_TAX("ChestShop.notax.buy"),
|
|
|
|
NO_SELL_TAX("ChestShop.notax.sell"),
|
2014-05-20 23:13:25 +02:00
|
|
|
|
2018-11-25 00:59:13 +01:00
|
|
|
NOTIFY_TOGGLE("ChestShop.toggle"),
|
2019-09-16 13:56:30 +02:00
|
|
|
ACCESS_TOGGLE("ChestShop.accesstoggle"),
|
2021-02-15 17:28:33 +01:00
|
|
|
ITEMINFO("ChestShop.iteminfo"),
|
|
|
|
SHOPINFO("ChestShop.shopinfo");
|
2011-05-29 13:25:25 +02:00
|
|
|
|
|
|
|
private final String permission;
|
|
|
|
|
|
|
|
Permission(String permission) {
|
|
|
|
this.permission = permission;
|
|
|
|
}
|
|
|
|
|
2013-11-01 14:24:08 +01:00
|
|
|
public static boolean has(CommandSender sender, Permission permission) {
|
|
|
|
return has(sender, permission.permission);
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
|
|
|
|
2013-11-01 14:24:08 +01:00
|
|
|
public static boolean has(CommandSender sender, String node) {
|
2020-01-29 16:35:04 +01:00
|
|
|
return sender.hasPermission(node) || sender.hasPermission(node.toLowerCase(Locale.ROOT));
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2013-11-01 14:24:08 +01:00
|
|
|
public static boolean otherName(Player player, String name) {
|
2018-11-19 21:10:48 +01:00
|
|
|
return otherName(player, OTHER_NAME, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean otherName(Player player, Permission base, String name) {
|
|
|
|
boolean hasBase = base != OTHER_NAME && otherName(player, OTHER_NAME, name);
|
|
|
|
if (hasBase || has(player, base + ".*")) {
|
2020-01-29 16:35:04 +01:00
|
|
|
return !hasPermissionSetFalse(player, base+ "." + name) && !hasPermissionSetFalse(player, base + "." + name.toLowerCase(Locale.ROOT));
|
2012-05-10 16:32:25 +02:00
|
|
|
}
|
|
|
|
|
2020-01-29 16:35:04 +01:00
|
|
|
return has(player, base + "." + name) || has(player, base + "." + name.toLowerCase(Locale.ROOT));
|
2012-01-09 22:39:38 +01:00
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2020-06-01 23:58:34 +02:00
|
|
|
public static boolean hasPermissionSetFalse(CommandSender sender, String permission) {
|
2018-11-19 21:10:48 +01:00
|
|
|
return (sender.isPermissionSet(permission) && !sender.hasPermission(permission))
|
2020-01-29 16:35:04 +01:00
|
|
|
|| (sender.isPermissionSet(permission.toLowerCase(Locale.ROOT)) && !sender.hasPermission(permission.toLowerCase(Locale.ROOT)));
|
2012-01-09 22:39:38 +01:00
|
|
|
}
|
2011-06-09 22:54:01 +02:00
|
|
|
|
2018-06-24 01:17:35 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-06-09 22:54:01 +02:00
|
|
|
public String toString() {
|
|
|
|
return permission;
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|