mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Tweaks (perms, debug, scripting)
This commit is contained in:
		@@ -92,12 +92,7 @@ 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);
 | 
			
		||||
            onCommand(ConsolePlayer.getConsole(), new String[] {"run", "start.js"});
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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()]);
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
        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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user