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

View File

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

View File

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

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.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<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("desc", command.desc());
options.put("help", command.help());
@ -138,7 +144,7 @@ public class Commands {
@Override
public Class<? extends Annotation> 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();
}
}
}

View File

@ -90,4 +90,10 @@ public @interface Command {
*/
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 , 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 = "<pattern> <radius> [depth] [direction]",
@ -589,7 +603,8 @@ public class UtilityCommands extends MethodCommands {
usage = "[<command>]",
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);

View File

@ -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 = "[<command>]",
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);

View File

@ -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() {

View File

@ -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();

View File

@ -60,6 +60,7 @@ public class ParametricCallable extends AParametricCallable {
private final Set<Character> legacyFlags = new HashSet<Character>();
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$", "");

View File

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