From a61c856adca73631ac6172e16efad1cb6a5679b8 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 24 Aug 2018 19:33:52 +1000 Subject: [PATCH] Allow certain commands to bypass queuing --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 14 +++++---- .../src/main/resources/plugin.yml | 4 --- .../src/main/java/com/boydti/fawe/Fawe.java | 6 ---- .../java/com/boydti/fawe/command/Cancel.java | 29 ------------------- .../java/com/boydti/fawe/config/Commands.java | 25 +++++++++++----- .../minecraft/util/commands/Command.java | 6 ++++ .../worldedit/command/UtilityCommands.java | 23 ++++++++++++--- .../worldedit/command/WorldEditCommands.java | 9 ++++-- .../extension/platform/CommandManager.java | 19 +++++++----- .../parametric/AParametricCallable.java | 3 ++ .../parametric/ParametricCallable.java | 7 +++++ worldedit-core/src/main/resources/cs_adv.js | 3 +- 12 files changed, 81 insertions(+), 67 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/command/Cancel.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index 7767dce14..2ef99a834 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -222,12 +222,14 @@ public class FaweBukkit implements IFawe, Listener { @Override public void setupCommand(final String label, final FaweCommand cmd) { if (plugin instanceof JavaPlugin) { - PluginCommand registered = ((JavaPlugin) plugin).getCommand(label); - if (registered == null) { - debug("Command not registered in plugin.yml: " + label); - return; - } - registered.setExecutor(new BukkitCommand(cmd)); + TaskManager.IMP.task(() -> { + PluginCommand registered = ((JavaPlugin) plugin).getCommand(label); + if (registered == null) { + debug("Command not registered in plugin.yml: " + label); + return; + } + registered.setExecutor(new BukkitCommand(cmd)); + }); } } diff --git a/worldedit-bukkit/src/main/resources/plugin.yml b/worldedit-bukkit/src/main/resources/plugin.yml index b62b370f3..7d6dbb247 100644 --- a/worldedit-bukkit/src/main/resources/plugin.yml +++ b/worldedit-bukkit/src/main/resources/plugin.yml @@ -8,10 +8,6 @@ loadbefore: [WorldEdit,AsyncWorldEdit,AsyncWorldEditInjector,WorldGuard] load: STARTUP database: false #softdepend: [WorldGuard, PlotSquared, MCore, Factions, GriefPrevention, Residence, Towny, PlotMe, PreciousStones] -commands: - fcancel: - description: "Cancel your edit" - aliases: [fawecancel,/fcancel,/cancel,/fawecancel] permissions: fawe.plotsquared: default: true diff --git a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java index 03e28d817..6b56a41ba 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -1,6 +1,5 @@ package com.boydti.fawe; -import com.boydti.fawe.command.Cancel; import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Commands; import com.boydti.fawe.config.Settings; @@ -187,7 +186,6 @@ public class Fawe { ignore.printStackTrace(); } } - this.setupCommands(); /* * Instance independent stuff */ @@ -355,10 +353,6 @@ public class Fawe { return timer.getTPS(); } - private void setupCommands() { - this.IMP.setupCommand("fcancel", new Cancel()); - } - public void setupConfigs() { MainUtil.copyFile(MainUtil.getJarFile(), "de/message.yml", null); MainUtil.copyFile(MainUtil.getJarFile(), "ru/message.yml", null); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/Cancel.java b/worldedit-core/src/main/java/com/boydti/fawe/command/Cancel.java deleted file mode 100644 index 40a368609..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/Cancel.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.boydti.fawe.command; - -import com.boydti.fawe.config.BBC; -import com.boydti.fawe.object.FaweCommand; -import com.boydti.fawe.object.FawePlayer; -import com.boydti.fawe.object.FaweQueue; -import com.boydti.fawe.object.brush.visualization.VirtualWorld; -import com.boydti.fawe.util.SetQueue; -import com.sk89q.worldedit.EditSession; -import java.util.Collection; -import java.util.UUID; - -public class Cancel extends FaweCommand { - - public Cancel() { - super("fawe.cancel", false); - } - - @Override - public boolean execute(final FawePlayer player, final String... args) { - if (player == null) { - return false; - } - int cancelled = player.cancel(false); - BBC.WORLDEDIT_CANCEL_COUNT.send(player, cancelled); - return true; - } - -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/config/Commands.java b/worldedit-core/src/main/java/com/boydti/fawe/config/Commands.java index bc610002c..e4288fa5a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/config/Commands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/config/Commands.java @@ -2,6 +2,7 @@ package com.boydti.fawe.config; import com.boydti.fawe.configuration.ConfigurationSection; import com.boydti.fawe.configuration.file.YamlConfiguration; +import com.boydti.fawe.util.StringMan; import com.sk89q.minecraft.util.commands.Command; import java.io.File; import java.io.IOException; @@ -30,7 +31,7 @@ public class Commands { } } - public static Command fromArgs(String[] aliases, String usage, String desc, int min, Integer max, String flags, String help) { + public static Command fromArgs(String[] aliases, String usage, String desc, int min, Integer max, String flags, String help, boolean queued) { int finalMax = max == null ? -1 : max; return new Command() { @Override @@ -69,6 +70,11 @@ public class Commands { public boolean anyFlags() { return !(flags.isEmpty() || flags.matches("[a-z]+")); } + + @Override + public boolean queued() { + return queued; + } }; } @@ -111,7 +117,7 @@ public class Commands { } HashMap options = new HashMap<>(); - options.put("aliases", new ArrayList(Arrays.asList(command.aliases()))); + options.put("aliases", new ArrayList<>(Arrays.asList(command.aliases()))); options.put("usage", command.usage()); options.put("desc", command.desc()); options.put("help", command.help()); @@ -138,7 +144,7 @@ public class Commands { @Override public Class annotationType() { - return command.annotationType(); + return this.command.annotationType(); } @Override @@ -158,17 +164,17 @@ public class Commands { @Override public int min() { - return command.min(); + return this.command.min(); } @Override public int max() { - return command.max(); + return this.command.max(); } @Override public String flags() { - return command.flags(); + return this.command.flags(); } @Override @@ -178,7 +184,12 @@ public class Commands { @Override public boolean anyFlags() { - return command.anyFlags(); + return this.command.anyFlags(); + } + + @Override + public boolean queued() { + return this.command.queued(); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/Command.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/Command.java index cc811acb7..5bee25f32 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/Command.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/Command.java @@ -90,4 +90,10 @@ public @interface Command { */ boolean anyFlags() default false; + /** + * Should the command be queued + * @return true if so + */ + boolean queued() default true; + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 6cb09c8fd..0502f77b1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -102,7 +102,8 @@ public class UtilityCommands extends MethodCommands { " - Use [brackets] for arguments\n" + " - Use , to OR multiple\n" + "e.g. #surfacespread[10][#existing],andesite\n" + - "More Info: https://git.io/vSPmA" + "More Info: https://git.io/vSPmA", + queued = false ) public void patterns(Player player, LocalSession session, CommandContext args) throws WorldEditException { displayModifierHelp(player, HashTagPatternParser.class, args); @@ -117,7 +118,8 @@ public class UtilityCommands extends MethodCommands { " - Use , to OR multiple\n" + " - Use & to AND multiple\n" + "e.g. >[stone,dirt],#light[0][5],$jungle\n" + - "More Info: https://git.io/v9r4K" + "More Info: https://git.io/v9r4K", + queued = false ) public void masks(Player player, LocalSession session, CommandContext args) throws WorldEditException { displayModifierHelp(player, DefaultMaskParser.class, args); @@ -131,7 +133,8 @@ public class UtilityCommands extends MethodCommands { " - Use [brackets] for arguments\n" + " - Use , to OR multiple\n" + " - Use & to AND multiple\n" + - "More Info: https://git.io/v9KHO" + "More Info: https://git.io/v9KHO", + queued = false ) public void transforms(Player player, LocalSession session, CommandContext args) throws WorldEditException { displayModifierHelp(player, DefaultTransformParser.class, args); @@ -160,6 +163,17 @@ public class UtilityCommands extends MethodCommands { } } + @Command( + aliases = {"/cancel", "fcancel"}, + desc = "Cancel your current command", + max = 0, + queued = false + ) + public void cancel(FawePlayer player) { + int cancelled = player.cancel(false); + BBC.WORLDEDIT_CANCEL_COUNT.send(player, cancelled); + } + @Command( aliases = {"/fill"}, usage = " [depth] [direction]", @@ -589,7 +603,8 @@ public class UtilityCommands extends MethodCommands { usage = "[]", desc = "Displays help for WorldEdit commands", min = 0, - max = -1 + max = -1, + queued = false ) public void help(Actor actor, CommandContext args) throws WorldEditException { help(args, worldEdit, actor); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index e04b5d5d9..8caa07c09 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -59,7 +59,8 @@ public class WorldEditCommands { usage = "", desc = "Get WorldEdit/FAWE version", min = 0, - max = 0 + max = 0, + queued = false ) public void version(Actor actor) throws WorldEditException { FaweVersion fVer = Fawe.get().getVersion(); @@ -196,7 +197,8 @@ public class WorldEditCommands { usage = "", desc = "Print all thread stacks", min = 0, - max = 0 + max = 0, + queued = false ) @CommandPermissions("worldedit.threads") public void threads(Actor actor) throws WorldEditException { @@ -242,7 +244,8 @@ public class WorldEditCommands { usage = "[]", desc = "Displays help for FAWE commands", min = 0, - max = -1 + max = -1, + queued = false ) public void help(Actor actor, CommandContext args) throws WorldEditException { UtilityCommands.help(args, we, actor); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index 6b46a953a..1890ab1ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -51,16 +51,11 @@ import com.sk89q.worldedit.internal.command.*; import com.sk89q.worldedit.scripting.CommandScriptLoader; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.auth.AuthorizationException; -import com.sk89q.worldedit.util.command.CallableProcessor; -import com.sk89q.worldedit.util.command.CommandCallable; -import com.sk89q.worldedit.util.command.Dispatcher; -import com.sk89q.worldedit.util.command.InvalidUsageException; +import com.sk89q.worldedit.util.command.*; import com.sk89q.worldedit.util.command.composition.ProvidedValue; import com.sk89q.worldedit.util.command.fluent.CommandGraph; import com.sk89q.worldedit.util.command.fluent.DispatcherNode; -import com.sk89q.worldedit.util.command.parametric.ExceptionConverter; -import com.sk89q.worldedit.util.command.parametric.LegacyCommandsHandler; -import com.sk89q.worldedit.util.command.parametric.ParametricBuilder; +import com.sk89q.worldedit.util.command.parametric.*; import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.LogFormat; @@ -498,6 +493,16 @@ public final class CommandManager { TaskManager.IMP.taskNow(new Runnable() { @Override public void run() { + int space0 = args.indexOf(' '); + String arg0 = space0 == -1 ? args : args.substring(0, space0); + CommandMapping cmd = dispatcher.get(arg0); + if (cmd != null && cmd.getCallable() instanceof AParametricCallable) { + Command info = ((AParametricCallable) cmd.getCallable()).getDefinition(); + if (!info.queued()) { + handleCommandOnCurrentThread(finalEvent); + return; + } + } if (!fp.runAction(new Runnable() { @Override public void run() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java index a7cd05137..a8c9a408e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java @@ -28,6 +28,9 @@ public abstract class AParametricCallable implements CommandCallable { public abstract ParametricBuilder getBuilder(); public abstract boolean anyFlags(); public abstract Command getCommand(); + public Command getDefinition() { + return getCommand(); + } public abstract String getGroup(); @Override public abstract String toString(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java index d603d005c..25f7efa7e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java @@ -60,6 +60,7 @@ public class ParametricCallable extends AParametricCallable { private final Set legacyFlags = new HashSet(); private final SimpleDescription description = new SimpleDescription(); private final CommandPermissions commandPermissions; + private final Command definition; /** * Create a new instance. @@ -179,6 +180,7 @@ public class ParametricCallable extends AParametricCallable { // Get permissions annotation commandPermissions = method.getAnnotation(CommandPermissions.class); + this.definition = definition; } @Override @@ -186,6 +188,11 @@ public class ParametricCallable extends AParametricCallable { return object.getClass().getAnnotation(Command.class); } + @Override + public Command getDefinition() { + return definition; + } + @Override public String getGroup() { return object.getClass().getSimpleName().replaceAll("Commands", "").replaceAll("Util$", ""); diff --git a/worldedit-core/src/main/resources/cs_adv.js b/worldedit-core/src/main/resources/cs_adv.js index e82583e8d..f619c3e49 100644 --- a/worldedit-core/src/main/resources/cs_adv.js +++ b/worldedit-core/src/main/resources/cs_adv.js @@ -31,7 +31,8 @@ { if (!f.hasOwnProperty('permission')) f.permission = "fawe.use"; if (!f.hasOwnProperty('aliases')) f.aliases = [f.name]; - var cmd = com.boydti.fawe.config.Commands.fromArgs(f.aliases, f.usage, f.desc, f.min, f.max, f.flags, f.help); + if (!f.hasOwnProperty('queued')) f.queued = true; + var cmd = com.boydti.fawe.config.Commands.fromArgs(f.aliases, f.usage, f.desc, f.min, f.max, f.flags, f.help, f.queued); var man = com.sk89q.worldedit.extension.platform.CommandManager.getInstance(); var builder = man.getBuilder(); var args = getParamNames(f);