mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-24 22:26:45 +01:00
84 lines
2.7 KiB
Java
84 lines
2.7 KiB
Java
|
package com.intellectualcrafters.plot.util;
|
||
|
|
||
|
import com.intellectualcrafters.plot.config.C;
|
||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||
|
|
||
|
public enum Perm {
|
||
|
// ADMIN
|
||
|
ADMIN("plots.admin", "do-not-change"),
|
||
|
// BUILD
|
||
|
BUILD_OTHER("plots.admin.build.other", "build"),
|
||
|
BUILD_ROAD("plots.admin.build.road", "build"),
|
||
|
BUILD_UNOWNED("plots.admin.build.unowned", "build"),
|
||
|
// INTERACT
|
||
|
INTERACT_OTHER("plots.admin.interact.other", "interact"),
|
||
|
INTERACT_ROAD("plots.admin.interact.road", "interact"),
|
||
|
INTERACT_UNOWNED("plots.admin.interact.unowned", "interact"),
|
||
|
// BREAK
|
||
|
BREAK_OTHER("plots.admin.break.other", "break"),
|
||
|
BREAK_ROAD("plots.admin.break.road", "break"),
|
||
|
BREAK_UNOWNED("plots.admin.break.unowned", "break");
|
||
|
|
||
|
public String s;
|
||
|
public String cat;
|
||
|
|
||
|
Perm(String perm, String cat) {
|
||
|
this.s = perm;
|
||
|
this.cat = cat;
|
||
|
}
|
||
|
|
||
|
public static boolean hasPermission(final PlotPlayer player, final String perm) {
|
||
|
if ((player == null) || player.isOp() || player.hasPermission(ADMIN.s)) {
|
||
|
return true;
|
||
|
}
|
||
|
if (player.hasPermission(perm)) {
|
||
|
return true;
|
||
|
}
|
||
|
final String[] nodes = perm.split("\\.");
|
||
|
final StringBuilder n = new StringBuilder();
|
||
|
for (int i = 0; i < (nodes.length - 1); i++) {
|
||
|
n.append(nodes[i] + ("."));
|
||
|
if (player.hasPermission(n + "*")) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static boolean hasPermission(final PlotPlayer player, final String perm, boolean notify) {
|
||
|
if ((player == null) || player.isOp() || player.hasPermission(ADMIN.s)) {
|
||
|
return true;
|
||
|
}
|
||
|
if (player.hasPermission(perm)) {
|
||
|
return true;
|
||
|
}
|
||
|
final String[] nodes = perm.split("\\.");
|
||
|
final StringBuilder n = new StringBuilder();
|
||
|
for (int i = 0; i < (nodes.length - 1); i++) {
|
||
|
n.append(nodes[i] + ("."));
|
||
|
if (player.hasPermission(n + "*")) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
if (notify) {
|
||
|
MainUtil.sendMessage(player, C.NO_PERMISSION, perm);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static int hasPermissionRange(final PlotPlayer player, final String stub, final int range) {
|
||
|
if ((player == null) || player.isOp() || player.hasPermission(ADMIN.s)) {
|
||
|
return Integer.MAX_VALUE;
|
||
|
}
|
||
|
if (player.hasPermission(stub + ".*")) {
|
||
|
return Integer.MAX_VALUE;
|
||
|
}
|
||
|
for (int i = range; i > 0; i--) {
|
||
|
if (player.hasPermission(stub + "." + i)) {
|
||
|
return i;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
}
|