mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 11:37:05 +01:00
Use Bukkit permission system
This commit is contained in:
parent
32a6651ecf
commit
ffd787f2b0
@ -253,7 +253,7 @@ public class DGlobalPlayer implements GlobalPlayer {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return DPermission.hasPermission(player, permission);
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
|
||||
public boolean hasPermission(DPermission permission) {
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package de.erethon.dungeonsxl.player;
|
||||
|
||||
import de.erethon.commons.misc.EnumUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -99,32 +98,33 @@ public enum DPermission {
|
||||
|
||||
public static final String PREFIX = "dxl.";
|
||||
|
||||
private String node;
|
||||
private PermissionDefault isDefault;
|
||||
private Permission node;
|
||||
private List<DPermission> children = new ArrayList<>();
|
||||
|
||||
DPermission(String node, PermissionDefault isDefault) {
|
||||
this.node = node;
|
||||
this.isDefault = isDefault;
|
||||
this.node = new Permission(PREFIX + node, isDefault);
|
||||
}
|
||||
|
||||
DPermission(String node, PermissionDefault isDefault, DPermission... children) {
|
||||
this(node, isDefault);
|
||||
this.children = Arrays.asList(children);
|
||||
for (DPermission child : children) {
|
||||
child.node.addParent(node, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the permission node String
|
||||
*/
|
||||
public String getNode() {
|
||||
return PREFIX + node;
|
||||
return node.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if a player has the node by default
|
||||
*/
|
||||
public PermissionDefault isDefault() {
|
||||
return isDefault;
|
||||
return node.getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,48 +161,7 @@ public enum DPermission {
|
||||
* @return if the player has the permission
|
||||
*/
|
||||
public static boolean hasPermission(CommandSender sender, DPermission permission) {
|
||||
if (sender.hasPermission(permission.getNode())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (DPermission parent : DPermission.values()) {
|
||||
if (parent.getChildren().contains(permission) && sender.hasPermission(parent.getNode())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sender the CommandSender
|
||||
* @param permission the permission to check
|
||||
* @return if the player has the permission
|
||||
*/
|
||||
public static boolean hasPermission(CommandSender sender, String permission) {
|
||||
if (sender.hasPermission(permission)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DPermission dPermission = null;
|
||||
if (EnumUtil.isValidEnum(DPermission.class, permission)) {
|
||||
dPermission = DPermission.valueOf(permission);
|
||||
|
||||
} else if (DPermission.getByNode(permission) != null) {
|
||||
dPermission = DPermission.getByNode(permission);
|
||||
}
|
||||
|
||||
if (dPermission == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (DPermission parent : DPermission.values()) {
|
||||
if (parent.getChildren().contains(dPermission) && sender.hasPermission(parent.getNode())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return sender.hasPermission(permission.getNode());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,7 +169,7 @@ public enum DPermission {
|
||||
*/
|
||||
public static void register() {
|
||||
for (DPermission permission : values()) {
|
||||
Bukkit.getPluginManager().addPermission(new Permission(permission.getNode(), permission.isDefault()));
|
||||
Bukkit.getPluginManager().addPermission(permission.node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,7 +178,7 @@ public enum DPermission {
|
||||
*/
|
||||
public static void unregister() {
|
||||
for (DPermission permission : values()) {
|
||||
Bukkit.getPluginManager().removePermission(permission.getNode());
|
||||
Bukkit.getPluginManager().removePermission(permission.node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ package de.erethon.dungeonsxl.requirement;
|
||||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@ -62,7 +61,7 @@ public class PermissionRequirement implements Requirement {
|
||||
@Override
|
||||
public boolean check(Player player) {
|
||||
for (String permission : permissions) {
|
||||
if (!DPermission.hasPermission(player, permission)) {
|
||||
if (!player.hasPermission(permission)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import de.erethon.dungeonsxl.api.player.GamePlayer;
|
||||
import de.erethon.dungeonsxl.api.sign.DungeonSign;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.player.DPlayerListener;
|
||||
import de.erethon.dungeonsxl.trigger.InteractTrigger;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
@ -119,7 +118,7 @@ public class DSignListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DPermission.hasPermission(player, dsign.getBuildPermission())) {
|
||||
if (!player.hasPermission(dsign.getBuildPermission())) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_NO_PERMISSIONS.getMessage());
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user