2015-07-10 00:20:19 +10:00
|
|
|
package com.intellectualcrafters.plot.util;
|
|
|
|
|
2015-09-03 15:45:25 +10:00
|
|
|
import org.bukkit.permissions.Permission;
|
|
|
|
|
2015-07-10 00:20:19 +10:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2015-08-18 23:20:11 +10:00
|
|
|
import com.plotsquared.general.commands.CommandCaller;
|
2015-07-10 00:20:19 +10:00
|
|
|
|
2015-08-18 23:20:11 +10:00
|
|
|
public class Permissions {
|
|
|
|
public static boolean hasPermission(final PlotPlayer player, final C c) {
|
|
|
|
return hasPermission(player, c.s());
|
2015-07-14 03:42:02 +10:00
|
|
|
}
|
2015-07-10 00:20:19 +10:00
|
|
|
|
|
|
|
public static boolean hasPermission(final PlotPlayer player, final String perm) {
|
2015-08-18 23:20:11 +10:00
|
|
|
return hasPermission((CommandCaller) player, perm);
|
|
|
|
}
|
|
|
|
|
2015-09-03 15:45:25 +10:00
|
|
|
public static boolean hasPermission(final CommandCaller player, String perm) {
|
2015-08-18 23:20:11 +10:00
|
|
|
if ((player == null) || player.hasPermission(C.PERMISSION_ADMIN.s()) || player.hasPermission(C.PERMISSION_STAR.s())) {
|
2015-07-10 00:20:19 +10:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-12 04:04:17 +10:00
|
|
|
if (player.hasPermission(perm)) {
|
2015-07-10 00:20:19 +10:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-03 15:45:25 +10:00
|
|
|
perm = perm.toLowerCase().replaceAll("^[^a-z|0-9|\\.|_|-]", "");
|
|
|
|
String[] nodes = perm.split("\\.");
|
|
|
|
final StringBuilder n = new StringBuilder();
|
|
|
|
for (int i = 0; i < (nodes.length - 1); i++) {
|
|
|
|
n.append(nodes[i] + ("."));
|
|
|
|
if (!perm.equals(n + C.PERMISSION_STAR.s())) {
|
|
|
|
if (player.hasPermission(n + C.PERMISSION_STAR.s())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-10 00:20:19 +10:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPermission(final PlotPlayer player, final String perm, boolean notify) {
|
2015-08-11 23:42:46 +10:00
|
|
|
if (!hasPermission(player, perm)) {
|
|
|
|
if (notify) {
|
|
|
|
MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT, perm);
|
2015-07-10 00:20:19 +10:00
|
|
|
}
|
2015-08-11 23:42:46 +10:00
|
|
|
return false;
|
2015-07-10 00:20:19 +10:00
|
|
|
}
|
2015-08-11 23:42:46 +10:00
|
|
|
return true;
|
2015-07-10 00:20:19 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int hasPermissionRange(final PlotPlayer player, final String stub, final int range) {
|
2015-08-18 23:20:11 +10:00
|
|
|
if ((player == null) || player.hasPermission(C.PERMISSION_ADMIN.s()) || player.hasPermission(C.PERMISSION_STAR.s())) {
|
2015-07-10 00:20:19 +10:00
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
2015-08-12 04:04:17 +10:00
|
|
|
if (player.hasPermission(stub + ".*")) {
|
2015-07-10 00:20:19 +10:00
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
for (int i = range; i > 0; i--) {
|
2015-08-12 04:04:17 +10:00
|
|
|
if (player.hasPermission(stub + "." + i)) {
|
2015-07-10 00:20:19 +10:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|