add command queuing

This commit is contained in:
Jesse Boyd 2019-07-19 03:10:04 +10:00
parent b696f9fc79
commit 81298bf555
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
7 changed files with 204 additions and 131 deletions

View File

@ -29,6 +29,8 @@ import com.sk89q.worldedit.command.factory.ReplaceFactory;
import com.sk89q.worldedit.command.factory.TreeGeneratorFactory;
import com.sk89q.worldedit.command.util.CommandPermissions;
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.entity.Player;
import com.sk89q.worldedit.function.Contextual;

View File

@ -42,6 +42,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
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.EntityRemover;
import com.sk89q.worldedit.command.util.Logging;
@ -102,7 +104,7 @@ import org.enginehub.piston.annotation.param.Switch;
/**
* 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)")
public class UtilityCommands {
@ -174,9 +176,9 @@ public class UtilityCommands {
name = "/cancel",
aliases= {"fcancel"},
desc = "Cancel your current command"
//queued = false
)
@CommandPermissions("fawe.cancel")
@CommandQueued(false)
public void cancel(FawePlayer player) {
int cancelled = player.cancel(false);
BBC.WORLDEDIT_CANCEL_COUNT.send(player, cancelled);
@ -213,8 +215,8 @@ public class UtilityCommands {
" - Use , to OR multiple\n" +
"e.g. #surfacespread[10][#existing],andesite\n" +
"More Info: https://git.io/vSPmA"
//queued = false
)
@CommandQueued(false)
@CommandPermissions("worldedit.patterns")
public void patterns(Player player, LocalSession session, CommandContext args) throws WorldEditException {
displayModifierHelp(player, DefaultPatternParser.class, args);
@ -229,8 +231,8 @@ public class UtilityCommands {
" - Use & to AND multiple\n" +
"e.g. >[stone,dirt],#light[0][5],$jungle\n" +
"More Info: https://git.io/v9r4K"
//queued = false
)
@CommandQueued(false)
@CommandPermissions("worldedit.masks")
public void masks(Player player, LocalSession session, CommandContext args) throws WorldEditException {
displayModifierHelp(player, DefaultMaskParser.class, args);
@ -244,8 +246,8 @@ public class UtilityCommands {
" - Use , to OR multiple\n" +
" - Use & to AND multiple\n" +
"More Info: https://git.io/v9KHO",
queued = false
)
@CommandQueued(false)
@CommandPermissions("worldedit.transforms")
public void transforms(Player player, LocalSession session, CommandContext args) throws WorldEditException {
displayModifierHelp(player, DefaultTransformParser.class, args);

View File

@ -29,6 +29,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
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.entity.Player;
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.Switch;
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
@CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class, CommandQueuedConditionGenerator.Registration.class})
public class WorldEditCommands {
private static final DateTimeFormatter dateFormat = DateTimeFormatter
@ -69,8 +71,8 @@ public class WorldEditCommands {
name = "version",
aliases = { "ver" },
desc = "Get WorldEdit/FAWE version"
//queued = false
)
@CommandQueued(false)
public void version(Actor actor) {
FaweVersion fVer = Fawe.get().getVersion();
String fVerStr = fVer == null ? "unknown" : "-" + fVer.build;
@ -119,8 +121,8 @@ public class WorldEditCommands {
name = "report",
aliases = { "debugpaste" },
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"})
public void report(Actor actor) throws WorldEditException, IOException {
BBC.DOWNLOAD_LINK.send(actor, IncendoPaster.debugPaste());
@ -129,8 +131,8 @@ public class WorldEditCommands {
@Command(
name = "threads",
desc = "Print all thread stacks"
//queued = false
)
@CommandQueued(false)
@CommandPermissions("worldedit.threads")
public void threads(Actor actor) throws WorldEditException {
Map<Thread, StackTraceElement[]> stacks = Thread.getAllStackTraces();
@ -179,8 +181,8 @@ public class WorldEditCommands {
@Command(
name = "help",
desc = "Displays help for FAWE commands"
//queued = false
)
@CommandQueued(false)
@CommandPermissions("worldedit.help")
public void help(Actor actor,
@Switch(name = 's', desc = "List sub-commands of the given command, if applicable")

View File

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

View File

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

View File

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

View File

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