Fix nested command configuration

This commit is contained in:
Jesse Boyd 2016-03-30 04:47:47 +11:00
parent 560ebf412b
commit bbe43f782c
3 changed files with 21 additions and 17 deletions

View File

@ -147,7 +147,7 @@ public class MainCommand extends Command {
if (EconHandler.manager != null) { if (EconHandler.manager != null) {
PlotArea area = player.getApplicablePlotArea(); PlotArea area = player.getApplicablePlotArea();
if (area != null) { 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) { if (price != null && EconHandler.manager.getMoney(player) < price) {
failure.run(); failure.run();
return; return;
@ -162,7 +162,7 @@ public class MainCommand extends Command {
if (EconHandler.manager != null) { if (EconHandler.manager != null) {
PlotArea area = player.getApplicablePlotArea(); PlotArea area = player.getApplicablePlotArea();
if (area != null) { 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) { if (price != null && EconHandler.manager.getMoney(player) < price) {
failure.run(); failure.run();
return; return;

View File

@ -18,15 +18,15 @@ public abstract class SetCommand extends SubCommand {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
if (!Permissions.hasPermission(plr, "plots.admin.command." + getId())) { if (!Permissions.hasPermission(plr, "plots.admin.command." + getFullId())) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command." + getId()); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command." + getFullId());
MainUtil.sendMessage(plr, C.PLOT_NOT_CLAIMED); MainUtil.sendMessage(plr, C.PLOT_NOT_CLAIMED);
return false; return false;
} }
} }
if (!plot.isOwner(plr.getUUID())) { if (!plot.isOwner(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.admin.command." + getId())) { if (!Permissions.hasPermission(plr, "plots.admin.command." + getFullId())) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command." + getId()); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command." + getFullId());
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false; return false;
} }

View File

@ -100,6 +100,13 @@ public abstract class Command {
return this.id; return this.id;
} }
public String getFullId() {
if (parent != null && parent.getParent() != null) {
return parent.getFullId() + "." + id;
}
return this.id;
}
public List<Command> getCommands(PlotPlayer player) { public List<Command> getCommands(PlotPlayer player) {
List<Command> commands = new ArrayList<>(); List<Command> commands = new ArrayList<>();
for (Command cmd : this.allCommands) { for (Command cmd : this.allCommands) {
@ -166,7 +173,7 @@ public abstract class Command {
options.put("confirmation", declaration.confirmation()); options.put("confirmation", declaration.confirmation());
boolean set = false; boolean set = false;
for (Map.Entry<String, Object> entry : options.entrySet()) { for (Map.Entry<String, Object> entry : options.entrySet()) {
String key = this.id + "." + entry.getKey(); String key = this.getFullId() + "." + entry.getKey();
if (!PS.get().commands.contains(key)) { if (!PS.get().commands.contains(key)) {
PS.get().commands.set(key, entry.getValue()); PS.get().commands.set(key, entry.getValue());
set = true; set = true;
@ -180,10 +187,10 @@ public abstract class Command {
} }
} }
this.aliases = PS.get().commands.getStringList(this.id + ".aliases"); this.aliases = PS.get().commands.getStringList(this.getFullId() + ".aliases");
this.description = PS.get().commands.getString(this.id + ".description"); this.description = PS.get().commands.getString(this.getFullId() + ".description");
this.usage = PS.get().commands.getString(this.id + ".usage"); this.usage = PS.get().commands.getString(this.getFullId() + ".usage");
this.confirmation = PS.get().commands.getBoolean(this.id + ".confirmation"); this.confirmation = PS.get().commands.getBoolean(this.getFullId() + ".confirmation");
if (this.parent != null) { if (this.parent != null) {
this.parent.register(this); this.parent.register(this);
} }
@ -207,10 +214,7 @@ public abstract class Command {
if (this.parent == null) { if (this.parent == null) {
return "plots.use"; return "plots.use";
} }
if (this.parent.parent == null) { return "plots." + getFullId();
return "plots." + this.id;
}
return this.parent.getPermission() + "." + this.id;
} }
public <T> void paginate(PlotPlayer player, List<T> c, int size, int page, RunnableVal3<Integer, T, PlotMessage> add, String baseCommand, public <T> void paginate(PlotPlayer player, List<T> c, int size, int page, RunnableVal3<Integer, T, PlotMessage> add, String baseCommand,
@ -523,12 +527,12 @@ public abstract class Command {
if (this.hashCode() != other.hashCode()) { if (this.hashCode() != other.hashCode()) {
return false; return false;
} }
return this.id.equals(other.id); return this.getFullId().equals(other.getFullId());
} }
@Override @Override
public int hashCode() { public int hashCode() {
return this.id.hashCode(); return this.getFullId().hashCode();
} }
public enum CommandResult { public enum CommandResult {