Allow certain commands to bypass queuing

This commit is contained in:
Jesse Boyd 2018-08-24 19:33:52 +10:00
parent c3db5c0cf1
commit a61c856adc
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
12 changed files with 81 additions and 67 deletions

View File

@ -222,12 +222,14 @@ public class FaweBukkit implements IFawe, Listener {
@Override @Override
public void setupCommand(final String label, final FaweCommand cmd) { public void setupCommand(final String label, final FaweCommand cmd) {
if (plugin instanceof JavaPlugin) { if (plugin instanceof JavaPlugin) {
TaskManager.IMP.task(() -> {
PluginCommand registered = ((JavaPlugin) plugin).getCommand(label); PluginCommand registered = ((JavaPlugin) plugin).getCommand(label);
if (registered == null) { if (registered == null) {
debug("Command not registered in plugin.yml: " + label); debug("Command not registered in plugin.yml: " + label);
return; return;
} }
registered.setExecutor(new BukkitCommand(cmd)); registered.setExecutor(new BukkitCommand(cmd));
});
} }
} }

View File

@ -8,10 +8,6 @@ loadbefore: [WorldEdit,AsyncWorldEdit,AsyncWorldEditInjector,WorldGuard]
load: STARTUP load: STARTUP
database: false database: false
#softdepend: [WorldGuard, PlotSquared, MCore, Factions, GriefPrevention, Residence, Towny, PlotMe, PreciousStones] #softdepend: [WorldGuard, PlotSquared, MCore, Factions, GriefPrevention, Residence, Towny, PlotMe, PreciousStones]
commands:
fcancel:
description: "Cancel your edit"
aliases: [fawecancel,/fcancel,/cancel,/fawecancel]
permissions: permissions:
fawe.plotsquared: fawe.plotsquared:
default: true default: true

View File

@ -1,6 +1,5 @@
package com.boydti.fawe; package com.boydti.fawe;
import com.boydti.fawe.command.Cancel;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Commands; import com.boydti.fawe.config.Commands;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
@ -187,7 +186,6 @@ public class Fawe {
ignore.printStackTrace(); ignore.printStackTrace();
} }
} }
this.setupCommands();
/* /*
* Instance independent stuff * Instance independent stuff
*/ */
@ -355,10 +353,6 @@ public class Fawe {
return timer.getTPS(); return timer.getTPS();
} }
private void setupCommands() {
this.IMP.setupCommand("fcancel", new Cancel());
}
public void setupConfigs() { public void setupConfigs() {
MainUtil.copyFile(MainUtil.getJarFile(), "de/message.yml", null); MainUtil.copyFile(MainUtil.getJarFile(), "de/message.yml", null);
MainUtil.copyFile(MainUtil.getJarFile(), "ru/message.yml", null); MainUtil.copyFile(MainUtil.getJarFile(), "ru/message.yml", null);

View File

@ -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;
}
}

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.config;
import com.boydti.fawe.configuration.ConfigurationSection; import com.boydti.fawe.configuration.ConfigurationSection;
import com.boydti.fawe.configuration.file.YamlConfiguration; import com.boydti.fawe.configuration.file.YamlConfiguration;
import com.boydti.fawe.util.StringMan;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import java.io.File; import java.io.File;
import java.io.IOException; 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; int finalMax = max == null ? -1 : max;
return new Command() { return new Command() {
@Override @Override
@ -69,6 +70,11 @@ public class Commands {
public boolean anyFlags() { public boolean anyFlags() {
return !(flags.isEmpty() || flags.matches("[a-z]+")); return !(flags.isEmpty() || flags.matches("[a-z]+"));
} }
@Override
public boolean queued() {
return queued;
}
}; };
} }
@ -111,7 +117,7 @@ public class Commands {
} }
HashMap<String, Object> options = new HashMap<>(); HashMap<String, Object> options = new HashMap<>();
options.put("aliases", new ArrayList<String>(Arrays.asList(command.aliases()))); options.put("aliases", new ArrayList<>(Arrays.asList(command.aliases())));
options.put("usage", command.usage()); options.put("usage", command.usage());
options.put("desc", command.desc()); options.put("desc", command.desc());
options.put("help", command.help()); options.put("help", command.help());
@ -138,7 +144,7 @@ public class Commands {
@Override @Override
public Class<? extends Annotation> annotationType() { public Class<? extends Annotation> annotationType() {
return command.annotationType(); return this.command.annotationType();
} }
@Override @Override
@ -158,17 +164,17 @@ public class Commands {
@Override @Override
public int min() { public int min() {
return command.min(); return this.command.min();
} }
@Override @Override
public int max() { public int max() {
return command.max(); return this.command.max();
} }
@Override @Override
public String flags() { public String flags() {
return command.flags(); return this.command.flags();
} }
@Override @Override
@ -178,7 +184,12 @@ public class Commands {
@Override @Override
public boolean anyFlags() { public boolean anyFlags() {
return command.anyFlags(); return this.command.anyFlags();
}
@Override
public boolean queued() {
return this.command.queued();
} }
} }
} }

View File

@ -90,4 +90,10 @@ public @interface Command {
*/ */
boolean anyFlags() default false; boolean anyFlags() default false;
/**
* Should the command be queued
* @return true if so
*/
boolean queued() default true;
} }

View File

@ -102,7 +102,8 @@ public class UtilityCommands extends MethodCommands {
" - Use [brackets] for arguments\n" + " - Use [brackets] for arguments\n" +
" - Use , to OR multiple\n" + " - Use , to OR multiple\n" +
"e.g. #surfacespread[10][#existing],andesite\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 { public void patterns(Player player, LocalSession session, CommandContext args) throws WorldEditException {
displayModifierHelp(player, HashTagPatternParser.class, args); displayModifierHelp(player, HashTagPatternParser.class, args);
@ -117,7 +118,8 @@ public class UtilityCommands extends MethodCommands {
" - Use , to OR multiple\n" + " - Use , to OR multiple\n" +
" - Use & to AND multiple\n" + " - Use & to AND multiple\n" +
"e.g. >[stone,dirt],#light[0][5],$jungle\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 { public void masks(Player player, LocalSession session, CommandContext args) throws WorldEditException {
displayModifierHelp(player, DefaultMaskParser.class, args); displayModifierHelp(player, DefaultMaskParser.class, args);
@ -131,7 +133,8 @@ public class UtilityCommands extends MethodCommands {
" - Use [brackets] for arguments\n" + " - Use [brackets] for arguments\n" +
" - Use , to OR multiple\n" + " - Use , to OR multiple\n" +
" - Use & to AND 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 { public void transforms(Player player, LocalSession session, CommandContext args) throws WorldEditException {
displayModifierHelp(player, DefaultTransformParser.class, args); 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( @Command(
aliases = {"/fill"}, aliases = {"/fill"},
usage = "<pattern> <radius> [depth] [direction]", usage = "<pattern> <radius> [depth] [direction]",
@ -589,7 +603,8 @@ public class UtilityCommands extends MethodCommands {
usage = "[<command>]", usage = "[<command>]",
desc = "Displays help for WorldEdit commands", desc = "Displays help for WorldEdit commands",
min = 0, min = 0,
max = -1 max = -1,
queued = false
) )
public void help(Actor actor, CommandContext args) throws WorldEditException { public void help(Actor actor, CommandContext args) throws WorldEditException {
help(args, worldEdit, actor); help(args, worldEdit, actor);

View File

@ -59,7 +59,8 @@ public class WorldEditCommands {
usage = "", usage = "",
desc = "Get WorldEdit/FAWE version", desc = "Get WorldEdit/FAWE version",
min = 0, min = 0,
max = 0 max = 0,
queued = false
) )
public void version(Actor actor) throws WorldEditException { public void version(Actor actor) throws WorldEditException {
FaweVersion fVer = Fawe.get().getVersion(); FaweVersion fVer = Fawe.get().getVersion();
@ -196,7 +197,8 @@ public class WorldEditCommands {
usage = "", usage = "",
desc = "Print all thread stacks", desc = "Print all thread stacks",
min = 0, min = 0,
max = 0 max = 0,
queued = false
) )
@CommandPermissions("worldedit.threads") @CommandPermissions("worldedit.threads")
public void threads(Actor actor) throws WorldEditException { public void threads(Actor actor) throws WorldEditException {
@ -242,7 +244,8 @@ public class WorldEditCommands {
usage = "[<command>]", usage = "[<command>]",
desc = "Displays help for FAWE commands", desc = "Displays help for FAWE commands",
min = 0, min = 0,
max = -1 max = -1,
queued = false
) )
public void help(Actor actor, CommandContext args) throws WorldEditException { public void help(Actor actor, CommandContext args) throws WorldEditException {
UtilityCommands.help(args, we, actor); UtilityCommands.help(args, we, actor);

View File

@ -51,16 +51,11 @@ import com.sk89q.worldedit.internal.command.*;
import com.sk89q.worldedit.scripting.CommandScriptLoader; import com.sk89q.worldedit.scripting.CommandScriptLoader;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.util.command.CallableProcessor; import com.sk89q.worldedit.util.command.*;
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.composition.ProvidedValue; import com.sk89q.worldedit.util.command.composition.ProvidedValue;
import com.sk89q.worldedit.util.command.fluent.CommandGraph; import com.sk89q.worldedit.util.command.fluent.CommandGraph;
import com.sk89q.worldedit.util.command.fluent.DispatcherNode; import com.sk89q.worldedit.util.command.fluent.DispatcherNode;
import com.sk89q.worldedit.util.command.parametric.ExceptionConverter; import com.sk89q.worldedit.util.command.parametric.*;
import com.sk89q.worldedit.util.command.parametric.LegacyCommandsHandler;
import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.util.logging.LogFormat;
@ -498,6 +493,16 @@ public final class CommandManager {
TaskManager.IMP.taskNow(new Runnable() { TaskManager.IMP.taskNow(new Runnable() {
@Override @Override
public void run() { 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() { if (!fp.runAction(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -28,6 +28,9 @@ public abstract class AParametricCallable implements CommandCallable {
public abstract ParametricBuilder getBuilder(); public abstract ParametricBuilder getBuilder();
public abstract boolean anyFlags(); public abstract boolean anyFlags();
public abstract Command getCommand(); public abstract Command getCommand();
public Command getDefinition() {
return getCommand();
}
public abstract String getGroup(); public abstract String getGroup();
@Override @Override
public abstract String toString(); public abstract String toString();

View File

@ -60,6 +60,7 @@ public class ParametricCallable extends AParametricCallable {
private final Set<Character> legacyFlags = new HashSet<Character>(); private final Set<Character> legacyFlags = new HashSet<Character>();
private final SimpleDescription description = new SimpleDescription(); private final SimpleDescription description = new SimpleDescription();
private final CommandPermissions commandPermissions; private final CommandPermissions commandPermissions;
private final Command definition;
/** /**
* Create a new instance. * Create a new instance.
@ -179,6 +180,7 @@ public class ParametricCallable extends AParametricCallable {
// Get permissions annotation // Get permissions annotation
commandPermissions = method.getAnnotation(CommandPermissions.class); commandPermissions = method.getAnnotation(CommandPermissions.class);
this.definition = definition;
} }
@Override @Override
@ -186,6 +188,11 @@ public class ParametricCallable extends AParametricCallable {
return object.getClass().getAnnotation(Command.class); return object.getClass().getAnnotation(Command.class);
} }
@Override
public Command getDefinition() {
return definition;
}
@Override @Override
public String getGroup() { public String getGroup() {
return object.getClass().getSimpleName().replaceAll("Commands", "").replaceAll("Util$", ""); return object.getClass().getSimpleName().replaceAll("Commands", "").replaceAll("Util$", "");

View File

@ -31,7 +31,8 @@
{ {
if (!f.hasOwnProperty('permission')) f.permission = "fawe.use"; if (!f.hasOwnProperty('permission')) f.permission = "fawe.use";
if (!f.hasOwnProperty('aliases')) f.aliases = [f.name]; 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 man = com.sk89q.worldedit.extension.platform.CommandManager.getInstance();
var builder = man.getBuilder(); var builder = man.getBuilder();
var args = getParamNames(f); var args = getParamNames(f);