add command queuing

Dieser Commit ist enthalten in:
Jesse Boyd 2019-07-19 03:10:04 +10:00
Ursprung b696f9fc79
Commit 81298bf555
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
7 geänderte Dateien mit 204 neuen und 131 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,8 @@ import com.sk89q.worldedit.command.factory.ReplaceFactory;
import com.sk89q.worldedit.command.factory.TreeGeneratorFactory; import com.sk89q.worldedit.command.factory.TreeGeneratorFactory;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.CommandQueued;
import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator;
import com.sk89q.worldedit.command.util.PermissionCondition; import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.Contextual;

Datei anzeigen

@ -42,6 +42,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.CommandQueued;
import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator;
import com.sk89q.worldedit.command.util.CreatureButcher; import com.sk89q.worldedit.command.util.CreatureButcher;
import com.sk89q.worldedit.command.util.EntityRemover; import com.sk89q.worldedit.command.util.EntityRemover;
import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.Logging;
@ -102,7 +104,7 @@ import org.enginehub.piston.annotation.param.Switch;
/** /**
* Utility commands. * Utility commands.
*/ */
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) @CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class, CommandQueuedConditionGenerator.Registration.class})
@Command(aliases = {}, desc = "Various utility commands: [More Info](http://wiki.sk89q.com/wiki/WorldEdit/Utilities)") @Command(aliases = {}, desc = "Various utility commands: [More Info](http://wiki.sk89q.com/wiki/WorldEdit/Utilities)")
public class UtilityCommands { public class UtilityCommands {
@ -174,9 +176,9 @@ public class UtilityCommands {
name = "/cancel", name = "/cancel",
aliases= {"fcancel"}, aliases= {"fcancel"},
desc = "Cancel your current command" desc = "Cancel your current command"
//queued = false
) )
@CommandPermissions("fawe.cancel") @CommandPermissions("fawe.cancel")
@CommandQueued(false)
public void cancel(FawePlayer player) { public void cancel(FawePlayer player) {
int cancelled = player.cancel(false); int cancelled = player.cancel(false);
BBC.WORLDEDIT_CANCEL_COUNT.send(player, cancelled); BBC.WORLDEDIT_CANCEL_COUNT.send(player, cancelled);
@ -213,8 +215,8 @@ public class UtilityCommands {
" - 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
) )
@CommandQueued(false)
@CommandPermissions("worldedit.patterns") @CommandPermissions("worldedit.patterns")
public void patterns(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void patterns(Player player, LocalSession session, CommandContext args) throws WorldEditException {
displayModifierHelp(player, DefaultPatternParser.class, args); displayModifierHelp(player, DefaultPatternParser.class, args);
@ -229,8 +231,8 @@ public class UtilityCommands {
" - 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
) )
@CommandQueued(false)
@CommandPermissions("worldedit.masks") @CommandPermissions("worldedit.masks")
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);
@ -244,8 +246,8 @@ public class UtilityCommands {
" - 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
) )
@CommandQueued(false)
@CommandPermissions("worldedit.transforms") @CommandPermissions("worldedit.transforms")
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);

Datei anzeigen

@ -29,6 +29,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.CommandQueued;
import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator;
import com.sk89q.worldedit.command.util.PrintCommandHelp; import com.sk89q.worldedit.command.util.PrintCommandHelp;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent; import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent;
@ -53,7 +55,7 @@ import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.ArgFlag; import org.enginehub.piston.annotation.param.ArgFlag;
import org.enginehub.piston.annotation.param.Switch; import org.enginehub.piston.annotation.param.Switch;
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) @CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class, CommandQueuedConditionGenerator.Registration.class})
public class WorldEditCommands { public class WorldEditCommands {
private static final DateTimeFormatter dateFormat = DateTimeFormatter private static final DateTimeFormatter dateFormat = DateTimeFormatter
@ -69,8 +71,8 @@ public class WorldEditCommands {
name = "version", name = "version",
aliases = { "ver" }, aliases = { "ver" },
desc = "Get WorldEdit/FAWE version" desc = "Get WorldEdit/FAWE version"
//queued = false
) )
@CommandQueued(false)
public void version(Actor actor) { public void version(Actor actor) {
FaweVersion fVer = Fawe.get().getVersion(); FaweVersion fVer = Fawe.get().getVersion();
String fVerStr = fVer == null ? "unknown" : "-" + fVer.build; String fVerStr = fVer == null ? "unknown" : "-" + fVer.build;
@ -119,8 +121,8 @@ public class WorldEditCommands {
name = "report", name = "report",
aliases = { "debugpaste" }, aliases = { "debugpaste" },
desc = "Writes a report of latest.log, config.yml, message.yml and your commands.yml to https://athion.net/ISPaster/paste" desc = "Writes a report of latest.log, config.yml, message.yml and your commands.yml to https://athion.net/ISPaster/paste"
// queued = false
) )
@CommandQueued(false)
@CommandPermissions({"worldedit.report", "worldedit.debugpaste"}) @CommandPermissions({"worldedit.report", "worldedit.debugpaste"})
public void report(Actor actor) throws WorldEditException, IOException { public void report(Actor actor) throws WorldEditException, IOException {
BBC.DOWNLOAD_LINK.send(actor, IncendoPaster.debugPaste()); BBC.DOWNLOAD_LINK.send(actor, IncendoPaster.debugPaste());
@ -129,8 +131,8 @@ public class WorldEditCommands {
@Command( @Command(
name = "threads", name = "threads",
desc = "Print all thread stacks" desc = "Print all thread stacks"
//queued = false
) )
@CommandQueued(false)
@CommandPermissions("worldedit.threads") @CommandPermissions("worldedit.threads")
public void threads(Actor actor) throws WorldEditException { public void threads(Actor actor) throws WorldEditException {
Map<Thread, StackTraceElement[]> stacks = Thread.getAllStackTraces(); Map<Thread, StackTraceElement[]> stacks = Thread.getAllStackTraces();
@ -179,8 +181,8 @@ public class WorldEditCommands {
@Command( @Command(
name = "help", name = "help",
desc = "Displays help for FAWE commands" desc = "Displays help for FAWE commands"
//queued = false
) )
@CommandQueued(false)
@CommandPermissions("worldedit.help") @CommandPermissions("worldedit.help")
public void help(Actor actor, public void help(Actor actor,
@Switch(name = 's', desc = "List sub-commands of the given command, if applicable") @Switch(name = 's', desc = "List sub-commands of the given command, if applicable")

Datei anzeigen

@ -0,0 +1,15 @@
package com.sk89q.worldedit.command.util;
import org.enginehub.piston.annotation.CommandCondition;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Sets a command to be queued
*/
@Retention(RetentionPolicy.RUNTIME)
@CommandCondition(CommandQueuedConditionGenerator.class)
public @interface CommandQueued {
boolean value() default false;
}

Datei anzeigen

@ -0,0 +1,24 @@
package com.sk89q.worldedit.command.util;
import org.enginehub.piston.Command;
import org.enginehub.piston.inject.InjectedValueAccess;
/**
* Dummy class
*/
public class CommandQueuedCondition implements Command.Condition {
private final boolean value;
public CommandQueuedCondition(boolean value) {
this.value = value;
}
public boolean isQueued() {
return value;
}
@Override
public boolean satisfied(InjectedValueAccess injectedValueAccess) {
return true;
}
}

Datei anzeigen

@ -0,0 +1,24 @@
package com.sk89q.worldedit.command.util;
import org.enginehub.piston.Command;
import org.enginehub.piston.gen.CommandConditionGenerator;
import org.enginehub.piston.util.NonnullByDefault;
import java.lang.reflect.Method;
import static com.google.common.base.Preconditions.checkNotNull;
@NonnullByDefault
public final class CommandQueuedConditionGenerator implements CommandConditionGenerator {
public interface Registration {
Registration commandQueuedConditionGenerator(CommandPermissionsConditionGenerator generator);
}
@Override
public Command.Condition generateCondition(Method commandMethod) {
CommandQueued annotation = commandMethod.getAnnotation(CommandQueued.class);
checkNotNull(annotation, "Annotation is missing from commandMethod");
return new CommandQueuedCondition(annotation.value());
}
}

Datei anzeigen

@ -84,6 +84,8 @@ import com.sk89q.worldedit.command.argument.RegionFactoryConverter;
import com.sk89q.worldedit.command.argument.RegistryConverter; import com.sk89q.worldedit.command.argument.RegistryConverter;
import com.sk89q.worldedit.command.argument.VectorConverter; import com.sk89q.worldedit.command.argument.VectorConverter;
import com.sk89q.worldedit.command.argument.ZonedDateTimeConverter; import com.sk89q.worldedit.command.argument.ZonedDateTimeConverter;
import com.sk89q.worldedit.command.util.CommandQueued;
import com.sk89q.worldedit.command.util.CommandQueuedCondition;
import com.sk89q.worldedit.command.util.PermissionCondition; import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.command.util.SubCommandPermissionCondition; import com.sk89q.worldedit.command.util.SubCommandPermissionCondition;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -294,121 +296,122 @@ public final class PlatformCommandManager {
private void registerAllCommands() { private void registerAllCommands() {
if (Settings.IMP.ENABLED_COMPONENTS.COMMANDS) { if (Settings.IMP.ENABLED_COMPONENTS.COMMANDS) {
registerSubCommands( // TODO NOT IMPLEMENTED dunno why these have issues generating
"schematic", // registerSubCommands(
ImmutableList.of("schem", "/schematic", "/schem"), // "schematic",
"Schematic commands for saving/loading areas", // ImmutableList.of("schem", "/schematic", "/schem"),
SchematicCommandsRegistration.builder(), // "Schematic commands for saving/loading areas",
new SchematicCommands(worldEdit) // SchematicCommandsRegistration.builder(),
); // new SchematicCommands(worldEdit)
registerSubCommands( // );
"snapshot", // registerSubCommands(
ImmutableList.of("snap"), // "snapshot",
"Snapshot commands for restoring backups", // ImmutableList.of("snap"),
SnapshotCommandsRegistration.builder(), // "Snapshot commands for restoring backups",
new SnapshotCommands(worldEdit) // SnapshotCommandsRegistration.builder(),
); // new SnapshotCommands(worldEdit)
registerSubCommands( // );
"superpickaxe", // registerSubCommands(
ImmutableList.of("pickaxe", "sp"), // "superpickaxe",
"Super-pickaxe commands", // ImmutableList.of("pickaxe", "sp"),
SuperPickaxeCommandsRegistration.builder(), // "Super-pickaxe commands",
new SuperPickaxeCommands(worldEdit) // SuperPickaxeCommandsRegistration.builder(),
); // new SuperPickaxeCommands(worldEdit)
registerSubCommands( // );
"brush", // registerSubCommands(
ImmutableList.of("br", "/brush", "/br"), // "brush",
"Brushing commands", // ImmutableList.of("br", "/brush", "/br"),
BrushCommandsRegistration.builder(), // "Brushing commands",
new BrushCommands(worldEdit), // BrushCommandsRegistration.builder(),
(Consumer<CommandManager>) manager -> { // new BrushCommands(worldEdit),
PaintBrushCommands.register(commandManagerService, manager, registration); // (Consumer<CommandManager>) manager -> {
ApplyBrushCommands.register(commandManagerService, manager, registration); // PaintBrushCommands.register(commandManagerService, manager, registration);
} // ApplyBrushCommands.register(commandManagerService, manager, registration);
); // }
registerSubCommands( // );
"worldedit", // registerSubCommands(
ImmutableList.of("we"), // "worldedit",
"WorldEdit commands", // ImmutableList.of("we"),
WorldEditCommandsRegistration.builder(), // "WorldEdit commands",
new WorldEditCommands(worldEdit) // WorldEditCommandsRegistration.builder(),
); // new WorldEditCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
BiomeCommandsRegistration.builder(), // commandManager,
new BiomeCommands() // BiomeCommandsRegistration.builder(),
); // new BiomeCommands()
this.registration.register( // );
commandManager, // this.registration.register(
ChunkCommandsRegistration.builder(), // commandManager,
new ChunkCommands(worldEdit) // ChunkCommandsRegistration.builder(),
); // new ChunkCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
ClipboardCommandsRegistration.builder(), // commandManager,
new ClipboardCommands(worldEdit) // ClipboardCommandsRegistration.builder(),
); // new ClipboardCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
GeneralCommandsRegistration.builder(), // commandManager,
new GeneralCommands(worldEdit) // GeneralCommandsRegistration.builder(),
); // new GeneralCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
GenerationCommandsRegistration.builder(), // commandManager,
new GenerationCommands(worldEdit) // GenerationCommandsRegistration.builder(),
); // new GenerationCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
HistoryCommandsRegistration.builder(), // commandManager,
new HistoryCommands(worldEdit) // HistoryCommandsRegistration.builder(),
); // new HistoryCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
NavigationCommandsRegistration.builder(), // commandManager,
new NavigationCommands(worldEdit) // NavigationCommandsRegistration.builder(),
); // new NavigationCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
RegionCommandsRegistration.builder(), // commandManager,
new RegionCommands(worldEdit) // RegionCommandsRegistration.builder(),
); // new RegionCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
ScriptingCommandsRegistration.builder(), // commandManager,
new ScriptingCommands(worldEdit) // ScriptingCommandsRegistration.builder(),
); // new ScriptingCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
SelectionCommandsRegistration.builder(), // commandManager,
new SelectionCommands(worldEdit) // SelectionCommandsRegistration.builder(),
); // new SelectionCommands(worldEdit)
ExpandCommands.register(registration, commandManager, commandManagerService); // );
this.registration.register( // ExpandCommands.register(registration, commandManager, commandManagerService);
commandManager, // this.registration.register(
SnapshotUtilCommandsRegistration.builder(), // commandManager,
new SnapshotUtilCommands(worldEdit) // SnapshotUtilCommandsRegistration.builder(),
); // new SnapshotUtilCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
ToolCommandsRegistration.builder(), // commandManager,
new ToolCommands(worldEdit) // ToolCommandsRegistration.builder(),
); // new ToolCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
ToolUtilCommandsRegistration.builder(), // commandManager,
new ToolUtilCommands(worldEdit) // ToolUtilCommandsRegistration.builder(),
); // new ToolUtilCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
UtilityCommandsRegistration.builder(), // commandManager,
new UtilityCommands(worldEdit) // UtilityCommandsRegistration.builder(),
); // new UtilityCommands(worldEdit)
this.registration.register( // );
commandManager, // this.registration.register(
AnvilCommandsRegistration.builder(), // commandManager,
new AnvilCommands(worldEdit) // AnvilCommandsRegistration.builder(),
); // new AnvilCommands(worldEdit)
// );
} }
} }
@ -533,13 +536,14 @@ public final class PlatformCommandManager {
TaskManager.IMP.taskNow(() -> { TaskManager.IMP.taskNow(() -> {
int space0 = args.indexOf(' '); int space0 = args.indexOf(' ');
String arg0 = space0 == -1 ? args : args.substring(0, space0); String arg0 = space0 == -1 ? args : args.substring(0, space0);
Optional<Command> cmd = commandManager.getCommand(arg0); Optional<Command> optional = commandManager.getCommand(arg0);
if (cmd.isPresent()) { if (!optional.isPresent()) return;
if (!cmd.queued()) { Command cmd = optional.get();
CommandQueuedCondition queued = cmd.getCondition().as(CommandQueuedCondition.class).orElse(null);
if (queued != null && !queued.isQueued()) {
handleCommandOnCurrentThread(finalEvent); handleCommandOnCurrentThread(finalEvent);
return; return;
} }
}
if (!fp.runAction( if (!fp.runAction(
() -> PlatformCommandManager.this.handleCommandOnCurrentThread(finalEvent), false, true)) { () -> PlatformCommandManager.this.handleCommandOnCurrentThread(finalEvent), false, true)) {
BBC.WORLDEDIT_COMMAND_LIMIT.send(fp); BBC.WORLDEDIT_COMMAND_LIMIT.send(fp);