From 39b698f67dbd3a48fcbfa19f787757e6c294c20e Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 5 Jan 2020 17:35:19 +1100 Subject: [PATCH] Remove SkipQueue annotation, and combine with perm condition it seems piston only generates one condition, idk why --- .../worldedit/command/UtilityCommands.java | 10 +++---- .../worldedit/command/WorldEditCommands.java | 16 +++++------ .../command/util/CommandPermissions.java | 3 ++- .../CommandPermissionsConditionGenerator.java | 3 ++- .../command/util/CommandQueuedCondition.java | 24 ----------------- .../util/CommandQueuedConditionGenerator.java | 27 ------------------- .../command/util/PermissionCondition.java | 11 ++++++++ .../command/util/annotation/SkipQueue.java | 16 ----------- .../platform/PlatformCommandManager.java | 3 +-- .../command/CommandRegistrationHandler.java | 7 ----- 10 files changed, 25 insertions(+), 95 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandQueuedCondition.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandQueuedConditionGenerator.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/command/util/annotation/SkipQueue.java 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 7c9e02a09..ffad1f247 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 @@ -40,12 +40,10 @@ 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.CommandQueuedConditionGenerator; import com.sk89q.worldedit.command.util.CreatureButcher; import com.sk89q.worldedit.command.util.EntityRemover; import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.PrintCommandHelp; -import com.sk89q.worldedit.command.util.annotation.SkipQueue; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; @@ -104,7 +102,7 @@ import org.jetbrains.annotations.Range; /** * Utility commands. */ -@CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class, CommandQueuedConditionGenerator.Registration.class}) +@CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class}) public class UtilityCommands { private final WorldEdit we; @@ -185,8 +183,7 @@ public class UtilityCommands { aliases= {"fcancel"}, desc = "Cancel your current command" ) - @CommandPermissions("fawe.cancel") - @SkipQueue + @CommandPermissions(value = "fawe.cancel", queued = false) public void cancel(Player player) { int cancelled = player.cancel(false); player.print(Caption.of("fawe.cancel.worldedit.cancel.count" , cancelled)); @@ -704,8 +701,7 @@ public class UtilityCommands { name = "/confirm", desc = "Confirm a command" ) - @SkipQueue - @CommandPermissions("fawe.confirm") + @CommandPermissions(value = "fawe.confirm", queued = false) public void confirm(Player fp) throws WorldEditException { if (!fp.confirm()) { fp.print(TranslatableComponent.of("fawe.worldedit.utility.nothing.confirmed")); 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 138f5bee3..1666916ef 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 @@ -29,8 +29,6 @@ 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.annotation.SkipQueue; -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; @@ -58,7 +56,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, CommandQueuedConditionGenerator.Registration.class}) +@CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class}) public class WorldEditCommands { private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z"); @@ -73,7 +71,7 @@ public class WorldEditCommands { aliases = { "ver" }, desc = "Get WorldEdit/FAWE version" ) - @SkipQueue + @CommandPermissions(queued = false) public void version(Actor actor) { FaweVersion fVer = Fawe.get().getVersion(); String fVerStr = fVer == null ? "unknown" : "-" + fVer.build; @@ -136,8 +134,7 @@ public class WorldEditCommands { aliases = { "debugpaste" }, desc = "Writes a report of latest.log, config.yml, message.yml https://athion.net/ISPaster/paste" ) - @SkipQueue - @CommandPermissions({"worldedit.report", "worldedit.debugpaste"}) + @CommandPermissions(value = {"worldedit.report", "worldedit.debugpaste"}, queued = false) public void report(Actor actor) throws WorldEditException, IOException { String dest = IncendoPaster.debugPaste(); actor.printInfo(TranslatableComponent.of("worldedit.report.written", TextComponent.of(dest))); @@ -147,8 +144,7 @@ public class WorldEditCommands { name = "threads", desc = "Print all thread stacks" ) - @SkipQueue - @CommandPermissions("worldedit.threads") + @CommandPermissions(value = "worldedit.threads", queued = false) public void threads(Actor actor) throws WorldEditException { Map stacks = Thread.getAllStackTraces(); for (Map.Entry entry : stacks.entrySet()) { @@ -168,6 +164,7 @@ public class WorldEditCommands { name = "cui", desc = "Complete CUI handshake (internal usage)" ) + @CommandPermissions({}) public void cui(Player player, LocalSession session) { session.setCUISupport(true); session.dispatchCUISetup(player); @@ -197,8 +194,7 @@ public class WorldEditCommands { name = "help", desc = "Displays help for WorldEdit commands" ) - @SkipQueue - @CommandPermissions("worldedit.help") + @CommandPermissions(value = "worldedit.help", queued = false) public void help(Actor actor, @Switch(name = 's', desc = "List sub-commands of the given command, if applicable") boolean listSubCommands, diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandPermissions.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandPermissions.java index feefb9aba..60dd7492a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandPermissions.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandPermissions.java @@ -34,6 +34,7 @@ public @interface CommandPermissions { * * @return a list of permissions strings */ - String[] value(); + String[] value() default {}; + boolean queued() default true; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandPermissionsConditionGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandPermissionsConditionGenerator.java index b70bad5fe..4b0a40c51 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandPermissionsConditionGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandPermissionsConditionGenerator.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command.util; +import com.boydti.fawe.util.StringMan; import com.google.common.collect.ImmutableSet; import org.enginehub.piston.Command; import org.enginehub.piston.gen.CommandConditionGenerator; @@ -41,6 +42,6 @@ public final class CommandPermissionsConditionGenerator implements CommandCondit CommandPermissions annotation = commandMethod.getAnnotation(CommandPermissions.class); checkNotNull(annotation, "Annotation is missing from commandMethod"); Set permissions = ImmutableSet.copyOf(annotation.value()); - return new PermissionCondition(permissions); + return new PermissionCondition(permissions, annotation.queued()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandQueuedCondition.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandQueuedCondition.java deleted file mode 100644 index 7ced6f48b..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandQueuedCondition.java +++ /dev/null @@ -1,24 +0,0 @@ -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 isQueued; - - public CommandQueuedCondition(boolean isQueued) { - this.isQueued = isQueued; - } - - public boolean isQueued() { - return isQueued; - } - - @Override - public boolean satisfied(InjectedValueAccess injectedValueAccess) { - return true; - } -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandQueuedConditionGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandQueuedConditionGenerator.java deleted file mode 100644 index 5f72a31f1..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CommandQueuedConditionGenerator.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sk89q.worldedit.command.util; - -import com.sk89q.worldedit.command.util.annotation.SkipQueue; -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(CommandQueuedConditionGenerator generator); - } - - @Override - public Command.Condition generateCondition(Method commandMethod) { - SkipQueue skip = commandMethod.getAnnotation(SkipQueue.class); - if (skip == null) { - return Command.Condition.TRUE; - } - return new CommandQueuedCondition(!skip.value()); - } -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PermissionCondition.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PermissionCondition.java index 99a4622d6..098f309a8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PermissionCondition.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PermissionCondition.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command.util; +import com.boydti.fawe.util.StringMan; import com.sk89q.worldedit.extension.platform.Actor; import org.enginehub.piston.Command; import org.enginehub.piston.inject.InjectedValueAccess; @@ -31,9 +32,15 @@ public class PermissionCondition implements Command.Condition { private static final Key ACTOR_KEY = Key.of(Actor.class); private final Set permissions; + private final boolean queued; public PermissionCondition(Set permissions) { + this(permissions, true); + } + + public PermissionCondition(Set permissions, boolean queued) { this.permissions = permissions; + this.queued = queued; } public Set getPermissions() { @@ -47,4 +54,8 @@ public class PermissionCondition implements Command.Condition { .map(actor -> permissions.stream().anyMatch(actor::hasPermission)) .orElse(false); } + + public boolean isQueued() { + return queued; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/annotation/SkipQueue.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/annotation/SkipQueue.java deleted file mode 100644 index 13ce8ae1f..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/annotation/SkipQueue.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sk89q.worldedit.command.util.annotation; - -import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator; -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 SkipQueue { - boolean value() default true; -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index f4e7d013b..bb2e0f085 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -107,7 +107,6 @@ import com.sk89q.worldedit.command.argument.RegistryConverter; import com.sk89q.worldedit.command.argument.VectorConverter; import com.sk89q.worldedit.command.argument.WorldConverter; import com.sk89q.worldedit.command.argument.ZonedDateTimeConverter; -import com.sk89q.worldedit.command.util.CommandQueuedCondition; import com.sk89q.worldedit.command.util.PermissionCondition; import com.sk89q.worldedit.command.util.PrintCommandHelp; import com.sk89q.worldedit.command.util.SubCommandPermissionCondition; @@ -652,7 +651,7 @@ public final class PlatformCommandManager { return; } Command cmd = optional.get(); - CommandQueuedCondition queued = cmd.getCondition().as(CommandQueuedCondition.class).orElse(null); + PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null); if (queued != null && !queued.isQueued()) { handleCommandOnCurrentThread(event); return; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandRegistrationHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandRegistrationHandler.java index b628e2aa4..0697250a2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandRegistrationHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandRegistrationHandler.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.internal.command; import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; -import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator; import org.enginehub.piston.CommandManager; import org.enginehub.piston.gen.CommandCallListener; import org.enginehub.piston.gen.CommandRegistration; @@ -31,7 +30,6 @@ import java.util.List; public class CommandRegistrationHandler { private static final CommandPermissionsConditionGenerator PERM_GEN = new CommandPermissionsConditionGenerator(); - private static final CommandQueuedConditionGenerator QUEUED_GEN = new CommandQueuedConditionGenerator(); private final List callListeners; @@ -49,11 +47,6 @@ public class CommandRegistrationHandler { PERM_GEN ); } - if (registration instanceof CommandQueuedConditionGenerator.Registration) { - ((CommandQueuedConditionGenerator.Registration) registration).commandQueuedConditionGenerator( - QUEUED_GEN - ); - } registration.build(); } }