From bbe43f782ccd2aea0bd66f3a8ebb0018990962f3 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 30 Mar 2016 04:47:47 +1100 Subject: [PATCH] Fix nested command configuration --- .../plot/commands/MainCommand.java | 4 +-- .../plot/commands/SetCommand.java | 8 +++--- .../plotsquared/general/commands/Command.java | 26 +++++++++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 8d2d7e203..249fbfa54 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -147,7 +147,7 @@ public class MainCommand extends Command { if (EconHandler.manager != null) { PlotArea area = player.getApplicablePlotArea(); if (area != null) { - Double price = area.PRICES.get(cmd.getId()); + Double price = area.PRICES.get(cmd.getFullId()); if (price != null && EconHandler.manager.getMoney(player) < price) { failure.run(); return; @@ -162,7 +162,7 @@ public class MainCommand extends Command { if (EconHandler.manager != null) { PlotArea area = player.getApplicablePlotArea(); if (area != null) { - Double price = area.PRICES.get(cmd.getId()); + Double price = area.PRICES.get(cmd.getFullId()); if (price != null && EconHandler.manager.getMoney(player) < price) { failure.run(); return; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/SetCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/SetCommand.java index ffdb93f6d..bd78883fa 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/SetCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/SetCommand.java @@ -18,15 +18,15 @@ public abstract class SetCommand extends SubCommand { return !sendMessage(plr, C.NOT_IN_PLOT); } if (!plot.hasOwner()) { - if (!Permissions.hasPermission(plr, "plots.admin.command." + getId())) { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command." + getId()); + if (!Permissions.hasPermission(plr, "plots.admin.command." + getFullId())) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command." + getFullId()); MainUtil.sendMessage(plr, C.PLOT_NOT_CLAIMED); return false; } } if (!plot.isOwner(plr.getUUID())) { - if (!Permissions.hasPermission(plr, "plots.admin.command." + getId())) { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command." + getId()); + if (!Permissions.hasPermission(plr, "plots.admin.command." + getFullId())) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command." + getFullId()); MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } diff --git a/Core/src/main/java/com/plotsquared/general/commands/Command.java b/Core/src/main/java/com/plotsquared/general/commands/Command.java index f03e1538f..d9af77f93 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/Command.java +++ b/Core/src/main/java/com/plotsquared/general/commands/Command.java @@ -100,6 +100,13 @@ public abstract class Command { return this.id; } + public String getFullId() { + if (parent != null && parent.getParent() != null) { + return parent.getFullId() + "." + id; + } + return this.id; + } + public List getCommands(PlotPlayer player) { List commands = new ArrayList<>(); for (Command cmd : this.allCommands) { @@ -166,7 +173,7 @@ public abstract class Command { options.put("confirmation", declaration.confirmation()); boolean set = false; for (Map.Entry entry : options.entrySet()) { - String key = this.id + "." + entry.getKey(); + String key = this.getFullId() + "." + entry.getKey(); if (!PS.get().commands.contains(key)) { PS.get().commands.set(key, entry.getValue()); set = true; @@ -180,10 +187,10 @@ public abstract class Command { } } - this.aliases = PS.get().commands.getStringList(this.id + ".aliases"); - this.description = PS.get().commands.getString(this.id + ".description"); - this.usage = PS.get().commands.getString(this.id + ".usage"); - this.confirmation = PS.get().commands.getBoolean(this.id + ".confirmation"); + this.aliases = PS.get().commands.getStringList(this.getFullId() + ".aliases"); + this.description = PS.get().commands.getString(this.getFullId() + ".description"); + this.usage = PS.get().commands.getString(this.getFullId() + ".usage"); + this.confirmation = PS.get().commands.getBoolean(this.getFullId() + ".confirmation"); if (this.parent != null) { this.parent.register(this); } @@ -207,10 +214,7 @@ public abstract class Command { if (this.parent == null) { return "plots.use"; } - if (this.parent.parent == null) { - return "plots." + this.id; - } - return this.parent.getPermission() + "." + this.id; + return "plots." + getFullId(); } public void paginate(PlotPlayer player, List c, int size, int page, RunnableVal3 add, String baseCommand, @@ -523,12 +527,12 @@ public abstract class Command { if (this.hashCode() != other.hashCode()) { return false; } - return this.id.equals(other.id); + return this.getFullId().equals(other.getFullId()); } @Override public int hashCode() { - return this.id.hashCode(); + return this.getFullId().hashCode(); } public enum CommandResult {