Tweaks (perms, debug, scripting)

This commit is contained in:
boy0001 2015-08-11 23:42:46 +10:00
parent 994ca12102
commit b40c464da9
8 changed files with 32 additions and 42 deletions

View File

@ -92,13 +92,8 @@ public class DebugExec extends SubCommand {
File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
if (file.exists()) {
init();
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
onCommand(ConsolePlayer.getConsole(), new String[] {"run", "start.js"});
}
}, 1);
}
}
public void init() {

View File

@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.helpmenu.HelpMenu;
@ -141,7 +142,7 @@ public class MainCommand extends CommandManager<PlotPlayer> {
if (category != null && !command.getCategory().equals(category)) {
continue;
}
if (player != null && !player.hasPermission(command.getPermission())) {
if (player != null && !Permissions.hasPermission(player, command.getPermission())) {
continue;
}
commands.add(command);

View File

@ -71,34 +71,34 @@ public class list extends SubCommand {
private String[] getArgumentList(PlotPlayer player) {
List<String> args = new ArrayList<>();
if (EconHandler.manager != null && player.hasPermission("plots.list.forsale")) {
if (EconHandler.manager != null && Permissions.hasPermission(player, "plots.list.forsale")) {
args.add("forsale");
}
if (player.hasPermission("plots.list.mine")) {
if (Permissions.hasPermission(player, "plots.list.mine")) {
args.add("mine");
}
if (player.hasPermission("plots.list.shared")) {
if (Permissions.hasPermission(player, "plots.list.shared")) {
args.add("shared");
}
if (player.hasPermission("plots.list.world")) {
if (Permissions.hasPermission(player, "plots.list.world")) {
args.add("world");
}
if (player.hasPermission("plots.list.top")) {
if (Permissions.hasPermission(player, "plots.list.top")) {
args.add("top");
}
if (player.hasPermission("plots.list..all")) {
if (Permissions.hasPermission(player, "plots.list..all")) {
args.add("all");
}
if (player.hasPermission("plots.list.unowned")) {
if (Permissions.hasPermission(player, "plots.list.unowned")) {
args.add("unowned");
}
if (player.hasPermission("plots.list.unknown")) {
if (Permissions.hasPermission(player, "plots.list.unknown")) {
args.add("unknown");
}
if (player.hasPermission("plots.list.player")) {
if (Permissions.hasPermission(player, "plots.list.player")) {
args.add("<player>");
}
if (player.hasPermission("plots.list.world")) {
if (Permissions.hasPermission(player, "plots.list.world")) {
args.add("<world>");
}
return args.toArray(new String[args.size()]);

View File

@ -37,6 +37,7 @@ import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
/**
* Flag Manager Utility
@ -369,7 +370,7 @@ public class FlagManager {
public static List<AbstractFlag> getFlags(final PlotPlayer player) {
final List<AbstractFlag> returnFlags = new ArrayList<>();
for (final AbstractFlag flag : flags) {
if (player.hasPermission("plots.set.flag." + flag.getKey().toLowerCase())) {
if (Permissions.hasPermission(player, "plots.set.flag." + flag.getKey().toLowerCase())) {
returnFlags.add(flag);
}
}

View File

@ -6,6 +6,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
public enum Permissions {
// ADMIN
ADMIN("plots.admin", "do-not-change"),
STAR("*", "do-not-change"),
// BUILD
BUILD_OTHER("plots.admin.build.other", "build"),
BUILD_ROAD("plots.admin.build.road", "build"),
@ -35,17 +36,17 @@ public enum Permissions {
public static boolean hasPermission(final PlotPlayer player, final String perm) {
if ((player == null) || player.hasPermission(ADMIN.s)) {
if ((player == null) || player.hasPermission(ADMIN.s) || player.hasPermission(STAR.s)) {
return true;
}
if (player.hasPermission(perm)) {
if (Permissions.hasPermission(player, 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 + "*")) {
if (player.hasPermission(n + STAR.s)) {
return true;
}
}
@ -53,35 +54,24 @@ public enum Permissions {
}
public static boolean hasPermission(final PlotPlayer player, final String perm, boolean notify) {
if ((player == null) || 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 (!hasPermission(player, perm)) {
if (notify) {
MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT, perm);
}
return false;
}
return true;
}
public static int hasPermissionRange(final PlotPlayer player, final String stub, final int range) {
if ((player == null) || player.hasPermission(ADMIN.s)) {
if ((player == null) || player.hasPermission(ADMIN.s) || player.hasPermission(STAR.s)) {
return Integer.MAX_VALUE;
}
if (player.hasPermission(stub + ".*")) {
if (Permissions.hasPermission(player, stub + ".*")) {
return Integer.MAX_VALUE;
}
for (int i = range; i > 0; i--) {
if (player.hasPermission(stub + "." + i)) {
if (Permissions.hasPermission(player, stub + "." + i)) {
return i;
}
}

View File

@ -355,7 +355,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
}
Flag flag;
if (!player.hasPermission(PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS) && (flag = FlagManager.getPlotFlag(plot, "blocked-cmds")) != null) {
if (!Permissions.hasPermission(pp, PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS) && (flag = FlagManager.getPlotFlag(plot, "blocked-cmds")) != null) {
List<String> v = (List<String>) flag.getValue();
String msg = event.getMessage().toLowerCase().replaceFirst("/", "");

View File

@ -85,8 +85,10 @@ public class BukkitPlayer extends PlotPlayer {
return true;
}
if (offline && EconHandler.manager != null) {
System.out.print("CHECKIGN VAULT!");
return EconHandler.manager.hasPermission(getName(), perm);
}
System.out.print("CHECKING: " + perm + " -> " + player.hasPermission(perm));
return this.player.hasPermission(perm);
}

View File

@ -15,6 +15,7 @@ import com.intellectualcrafters.plot.commands.DebugUUID;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringComparison;
import com.plotsquared.general.commands.Command;
@ -63,7 +64,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
String label = cmd.getCommand();
if (!label.equalsIgnoreCase(best)) {
if (label.startsWith(arg)) {
if (player.hasPermission(cmd.getPermission())) {
if (Permissions.hasPermission(player, cmd.getPermission())) {
tabOptions.add(cmd.getCommand());
} else if (cmd.getAliases().size() > 0) {
for (String alias : cmd.getAliases()) {