From 7ab8d22325b7eee2c335ab8fbe09b82231ec38c5 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 25 Mar 2016 02:03:36 +1100 Subject: [PATCH] Move confirmation to commands.yml --- .../com/intellectualcrafters/plot/PS.java | 11 ---------- .../plot/commands/Area.java | 21 ++++++++++++++----- .../plot/commands/Clear.java | 5 +++-- .../plot/commands/Delete.java | 7 +++---- .../plot/commands/Merge.java | 12 ++++++++--- .../plot/commands/Owner.java | 5 +++-- .../plot/commands/Purge.java | 12 ++++++++--- .../plot/commands/Unlink.java | 6 +++--- .../plot/config/Settings.java | 7 ------- 9 files changed, 46 insertions(+), 40 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 89b3bbe24..abe577707 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1951,11 +1951,6 @@ public class PS { this.config.set("platform", this.platform); Map options = new HashMap<>(); - // Command confirmation - options.put("confirmation.setowner", Settings.CONFIRM_SETOWNER); - options.put("confirmation.clear", Settings.CONFIRM_CLEAR); - options.put("confirmation.delete", Settings.CONFIRM_DELETE); - options.put("confirmation.unlink", Settings.CONFIRM_UNLINK); // Protection options.put("protection.redstone.disable-offline", Settings.REDSTONE_DISABLER); @@ -2081,12 +2076,6 @@ public class PS { } } - // Command confirmation - Settings.CONFIRM_SETOWNER = this.config.getBoolean("confirmation.setowner"); - Settings.CONFIRM_CLEAR = this.config.getBoolean("confirmation.clear"); - Settings.CONFIRM_DELETE = this.config.getBoolean("confirmation.delete"); - Settings.CONFIRM_UNLINK = this.config.getBoolean("confirmation.unlink"); - // Protection Settings.REDSTONE_DISABLER = this.config.getBoolean("protection.redstone.disable-offline"); Settings.REDSTONE_DISABLER_UNOCCUPIED = this.config.getBoolean("protection.redstone.disable-unoccupied"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java index 1684652ec..ef5a783fc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java @@ -38,7 +38,8 @@ import java.util.Set; requiredType = RequiredType.NONE, description = "Create a new PlotArea", aliases = "world", - usage = "/plot area ") + usage = "/plot area ", + confirmation=true) public class Area extends SubCommand { @Override @@ -113,7 +114,7 @@ public class Area extends SubCommand { object.setupGenerator = "PlotSquared"; object.step = area.getSettingNodes(); final String path = "worlds." + area.worldname + ".areas." + area.id + "-" + object.min + "-" + object.max; - CmdConfirm.addPending(plr, "/plot area create pos2 (Creates world)", new Runnable() { + Runnable run = new Runnable() { @Override public void run() { if (offsetx != 0) { @@ -139,7 +140,12 @@ public class Area extends SubCommand { MainUtil.sendMessage(plr, "An error occured while creating the world: " + area.worldname); } } - }); + }; + if (hasConfirmation(plr)) { + CmdConfirm.addPending(plr, "/plot area create pos2 (Creates world)", run); + } else { + run.run(); + } return true; } } @@ -234,7 +240,7 @@ public class Area extends SubCommand { C.SETUP_WORLD_TAKEN.send(plr, pa.worldname); return false; } - CmdConfirm.addPending(plr, "/plot area " + StringMan.join(args, " "), new Runnable() { + Runnable run = new Runnable() { @Override public void run() { String path = "worlds." + pa.worldname; @@ -259,7 +265,12 @@ public class Area extends SubCommand { e.printStackTrace(); } } - }); + }; + if (hasConfirmation(plr)) { + CmdConfirm.addPending(plr, "/plot area " + StringMan.join(args, " "), run); + } else { + run.run(); + } return true; } if (pa.id == null) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index f1e9264f3..5c7fb4957 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -40,7 +40,8 @@ import java.util.Set; permission = "plots.clear", category = CommandCategory.APPEARANCE, usage = "/plot clear [id]", - aliases = "reset") + aliases = "reset", + confirmation=true) public class Clear extends SubCommand { @Override @@ -118,7 +119,7 @@ public class Clear extends SubCommand { } } }; - if (Settings.CONFIRM_CLEAR && !Permissions.hasPermission(plr, "plots.confirm.bypass")) { + if (hasConfirmation(plr)) { CmdConfirm.addPending(plr, "/plot clear " + plot.getId(), runnable); } else { TaskManager.runTask(runnable); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index d47181e85..8eba866f7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -21,7 +21,6 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; @@ -32,7 +31,6 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; - import java.util.HashSet; @CommandDeclaration( @@ -42,7 +40,8 @@ import java.util.HashSet; usage = "/plot delete", aliases = {"dispose", "del"}, category = CommandCategory.CLAIMING, - requiredType = RequiredType.NONE) + requiredType = RequiredType.NONE, + confirmation=true) public class Delete extends SubCommand { @Override @@ -90,7 +89,7 @@ public class Delete extends SubCommand { } } }; - if (Settings.CONFIRM_DELETE && !Permissions.hasPermission(plr, "plots.confirm.bypass")) { + if (hasConfirmation(plr)) { CmdConfirm.addPending(plr, "/plot delete " + plot.getId(), run); } else { TaskManager.runTask(run); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 47bd1a416..0eb69791c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -42,7 +42,8 @@ import java.util.UUID; description = "Merge the plot you are standing on, with another plot", permission = "plots.merge", usage = "/plot merge [removeroads]", category = CommandCategory.SETTINGS, - requiredType = RequiredType.NONE) + requiredType = RequiredType.NONE, + confirmation=true) public class Merge extends SubCommand { public final static String[] values = new String[]{"north", "east", "south", "west", "auto"}; @@ -180,7 +181,7 @@ public class Merge extends SubCommand { } isOnline = true; final int dir = direction; - CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable() { + Runnable run = new Runnable() { @Override public void run() { MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED); @@ -200,7 +201,12 @@ public class Merge extends SubCommand { } MainUtil.sendMessage(plr, C.SUCCESS_MERGE); } - }); + }; + if (hasConfirmation(plr)) { + CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), run); + } else { + run.run(); + } } if (!isOnline) { MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java index 932275d61..3e43d170d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java @@ -41,7 +41,8 @@ import java.util.UUID; usage = "/plot setowner ", aliases = {"owner", "so", "seto"}, category = CommandCategory.CLAIMING, - requiredType = RequiredType.NONE) + requiredType = RequiredType.NONE, + confirmation=true) public class Owner extends SetCommand { @Override @@ -104,7 +105,7 @@ public class Owner extends SetCommand { } } }; - if (Settings.CONFIRM_SETOWNER && !Permissions.hasPermission(plr, "plots.confirm.bypass")) { + if (hasConfirmation(plr)) { CmdConfirm.addPending(plr, "/plot set owner " + value, run); } else { TaskManager.runTask(run); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index 1506dd4ec..ad1dc160c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -43,7 +43,8 @@ import java.util.UUID; permission = "plots.admin", description = "Purge all plots for a world", category = CommandCategory.ADMINISTRATION, - requiredType = RequiredType.CONSOLE) + requiredType = RequiredType.CONSOLE, + confirmation=true) public class Purge extends SubCommand { @Override @@ -167,7 +168,7 @@ public class Purge extends SubCommand { return false; } String cmd = "/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)"; - CmdConfirm.addPending(plr, cmd, new Runnable() { + Runnable run = new Runnable() { @Override public void run() { HashSet ids = new HashSet(); @@ -181,7 +182,12 @@ public class Purge extends SubCommand { DBFunc.purgeIds(ids); C.PURGE_SUCCESS.send(plr, ids.size() + "/" + toDelete.size()); } - }); + }; + if (hasConfirmation(plr)) { + CmdConfirm.addPending(plr, cmd, run); + } else { + run.run(); + } return true; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java index c09bd62fb..346902a49 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java @@ -21,7 +21,6 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -37,7 +36,8 @@ import com.plotsquared.general.commands.CommandDeclaration; description = "Unlink a mega-plot", usage = "/plot unlink", requiredType = RequiredType.NONE, - category = CommandCategory.SETTINGS) + category = CommandCategory.SETTINGS, + confirmation=true) public class Unlink extends SubCommand { @Override @@ -77,7 +77,7 @@ public class Unlink extends SubCommand { MainUtil.sendMessage(plr, C.UNLINK_SUCCESS); } }; - if (Settings.CONFIRM_UNLINK && !Permissions.hasPermission(plr, "plots.confirm.bypass")) { + if (hasConfirmation(plr)) { CmdConfirm.addPending(plr, "/plot unlink " + plot.getId(), runnable); } else { TaskManager.runTask(runnable); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 57dac19c9..bfad4eaab 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -172,13 +172,6 @@ public class Settings { public static boolean TWIN_MODE_UUID = false; public static boolean OFFLINE_MODE = false; public static boolean UUID_LOWERCASE = false; - /** - * Command confirmation - */ - public static boolean CONFIRM_SETOWNER = true; - public static boolean CONFIRM_CLEAR = true; - public static boolean CONFIRM_DELETE = true; - public static boolean CONFIRM_UNLINK = true; /** * Use global plot limit? */