2015-07-09 16:20:19 +02:00
|
|
|
package com.intellectualcrafters.plot.util;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.config.C;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
|
2015-07-10 16:08:07 +02:00
|
|
|
public enum Permissions {
|
2015-07-09 16:20:19 +02:00
|
|
|
// 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"),
|
2015-07-13 19:42:02 +02:00
|
|
|
BREAK_UNOWNED("plots.admin.break.unowned", "break"),
|
|
|
|
// MERGE
|
|
|
|
MERGE_OTHER("plots.merge.other", "merge");
|
2015-07-09 16:20:19 +02:00
|
|
|
|
|
|
|
public String s;
|
|
|
|
public String cat;
|
|
|
|
|
2015-07-10 16:08:07 +02:00
|
|
|
Permissions(String perm, String cat) {
|
2015-07-09 16:20:19 +02:00
|
|
|
this.s = perm;
|
|
|
|
this.cat = cat;
|
|
|
|
}
|
2015-07-13 19:42:02 +02:00
|
|
|
|
|
|
|
public static boolean hasPermission(final PlotPlayer player, final Permissions perm) {
|
|
|
|
return hasPermission(player, perm.s);
|
|
|
|
}
|
2015-07-09 16:20:19 +02:00
|
|
|
|
2015-07-13 20:27:05 +02:00
|
|
|
|
2015-07-09 16:20:19 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|