From f33140b327c0137bc6e3a3073eca1df1e5e8a2bf Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Tue, 16 Apr 2019 23:02:23 -0700 Subject: [PATCH] Port ChunkCommands, fix up injection, simplify registration --- .../worldedit/command/BiomeCommands.java | 7 +- .../worldedit/command/BrushCommands.java | 3 +- .../worldedit/command/ChunkCommands.java | 35 ++--- .../worldedit/command/ClipboardCommands.java | 6 +- .../worldedit/command/GenerationCommands.java | 8 +- .../worldedit/command/NavigationCommands.java | 4 +- .../worldedit/command/RegionCommands.java | 9 +- .../worldedit/command/SchematicCommands.java | 3 +- .../worldedit/command/ScriptingCommands.java | 4 +- .../worldedit/command/SelectionCommands.java | 6 +- .../command/SnapshotUtilCommands.java | 4 +- .../worldedit/command/UtilityCommands.java | 14 +- .../worldedit/command/argument/Arguments.java | 3 +- .../CommandPermissionsConditionGenerator.java | 7 +- .../command/util}/Logging.java | 2 +- .../platform/PlatformCommandMananger.java | 122 ++++++++++++------ .../command/CommandLoggingHandler.java | 2 +- 17 files changed, 135 insertions(+), 104 deletions(-) rename worldedit-core/src/main/java/com/sk89q/{minecraft/util/commands => worldedit/command/util}/Logging.java (93%) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java index 81d208885..0bf6878dd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java @@ -19,12 +19,13 @@ package com.sk89q.worldedit.command; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; 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.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.function.FlatRegionFunction; @@ -54,12 +55,12 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; /** * Implements biome-related commands such as "/biomelist". */ -@CommandContainer +@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class BiomeCommands { /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 41da9f0f3..e310f136a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.command.tool.brush.HollowSphereBrush; import com.sk89q.worldedit.command.tool.brush.SmoothBrush; import com.sk89q.worldedit.command.tool.brush.SphereBrush; import com.sk89q.worldedit.command.util.CommandPermissions; +import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CreatureButcher; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -55,7 +56,7 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Commands to set brush shape. */ -@CommandContainer +@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class BrushCommands { private final WorldEdit worldEdit; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java index 30d99269d..8f9dc6ceb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java @@ -20,22 +20,23 @@ package com.sk89q.worldedit.command; import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; -import com.sk89q.minecraft.util.commands.Command; -import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; -import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; 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.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.MathUtils; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.storage.LegacyChunkStore; import com.sk89q.worldedit.world.storage.McRegionChunkStore; +import org.enginehub.piston.annotation.Command; +import org.enginehub.piston.annotation.CommandContainer; import java.io.FileOutputStream; import java.io.IOException; @@ -45,21 +46,19 @@ import java.util.Set; /** * Commands for working with chunks. */ +@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class ChunkCommands { private final WorldEdit worldEdit; - + public ChunkCommands(WorldEdit worldEdit) { checkNotNull(worldEdit); this.worldEdit = worldEdit; } @Command( - aliases = { "chunkinfo" }, - usage = "", - desc = "Get information about the chunk that you are inside", - min = 0, - max = 0 + name = "chunkinfo", + desc = "Get information about the chunk that you are inside" ) @CommandPermissions("worldedit.chunkinfo") public void chunkInfo(Player player) throws WorldEditException { @@ -79,11 +78,8 @@ public class ChunkCommands { } @Command( - aliases = { "listchunks" }, - usage = "", - desc = "List chunks that your selection includes", - min = 0, - max = 0 + name = "listchunks", + desc = "List chunks that your selection includes" ) @CommandPermissions("worldedit.listchunks") public void listChunks(Player player, LocalSession session) throws WorldEditException { @@ -95,11 +91,8 @@ public class ChunkCommands { } @Command( - aliases = { "delchunks" }, - usage = "", - desc = "Delete chunks that your selection includes", - min = 0, - max = 0 + name = "delchunks", + desc = "Delete chunks that your selection includes" ) @CommandPermissions("worldedit.delchunks") @Logging(REGION) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 0f61f0d2a..9d0dfe984 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -20,16 +20,16 @@ package com.sk89q.worldedit.command; import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT; +import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index 971fb58d8..f4578bdcd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -20,17 +20,17 @@ package com.sk89q.worldedit.command; import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL; +import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT; +import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.annotation.Selection; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java index 2d64d472b..b2fb9c4cb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java @@ -20,15 +20,15 @@ package com.sk89q.worldedit.command; import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.command.parametric.Optional; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index d788063d5..093d84f0e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -20,24 +20,23 @@ package com.sk89q.worldedit.command; import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.ORIENTATION_REGION; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL; +import static com.sk89q.worldedit.command.util.Logging.LogMode.ORIENTATION_REGION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; import static com.sk89q.worldedit.regions.Regions.asFlatRegion; import static com.sk89q.worldedit.regions.Regions.maximumBlockY; import static com.sk89q.worldedit.regions.Regions.minimumBlockY; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.generator.FloraGenerator; -import com.sk89q.worldedit.function.generator.ForestGenerator; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.NoiseFilter2D; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index ffa28d8ec..5fd4c6d98 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.LocalSession; 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.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; @@ -65,7 +66,7 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Commands that work with schematic files. */ -@CommandContainer +@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class SchematicCommands { /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java index 2b7d9a61f..d09c76c39 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java @@ -20,15 +20,15 @@ package com.sk89q.worldedit.command; import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL; +import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import java.io.File; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index 24e92070b..c79ec4fec 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -19,19 +19,19 @@ package com.sk89q.worldedit.command; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; +import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java index 51c5695e5..b8d6c7f3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java @@ -22,12 +22,12 @@ package com.sk89q.worldedit.command; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.DataException; @@ -40,7 +40,7 @@ import com.sk89q.worldedit.world.storage.MissingWorldException; import java.io.File; import java.io.IOException; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; public class SnapshotUtilCommands { 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 415b77adf..4d69452b2 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 @@ -19,14 +19,12 @@ package com.sk89q.worldedit.command; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; +import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT; -import com.google.common.base.Joiner; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -34,12 +32,12 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; 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.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Capability; -import com.sk89q.worldedit.extension.platform.PlatformCommandMananger; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.BlockPattern; @@ -53,17 +51,9 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.SessionOwner; -import com.sk89q.worldedit.util.command.CommandCallable; import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Dispatcher; -import com.sk89q.worldedit.util.command.PrimaryAliasComparator; import com.sk89q.worldedit.util.command.binding.Text; -import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; -import com.sk89q.worldedit.util.formatting.Style; -import com.sk89q.worldedit.util.formatting.StyledFragment; -import com.sk89q.worldedit.util.formatting.component.Code; -import com.sk89q.worldedit.util.formatting.component.CommandListBox; -import com.sk89q.worldedit.util.formatting.component.CommandUsageBox; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/Arguments.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/Arguments.java index 1bf5fc4e9..a1b444cbe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/Arguments.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/Arguments.java @@ -19,7 +19,8 @@ package com.sk89q.worldedit.command.argument; -import org.enginehub.piston.InjectedValueAccess; + +import org.enginehub.piston.inject.InjectedValueAccess; /** * Key-interface for {@link InjectedValueAccess} for the String arguments. 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 28041a1a1..b126198a6 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 @@ -20,10 +20,9 @@ package com.sk89q.worldedit.command.util; import com.google.common.collect.ImmutableSet; -import com.google.inject.Key; -import com.sk89q.worldedit.extension.platform.Actor; import org.enginehub.piston.Command; import org.enginehub.piston.gen.CommandConditionGenerator; +import org.enginehub.piston.gen.CommandRegistration; import org.enginehub.piston.util.NonnullByDefault; import java.lang.reflect.Method; @@ -34,6 +33,10 @@ import static com.google.common.base.Preconditions.checkNotNull; @NonnullByDefault public class CommandPermissionsConditionGenerator implements CommandConditionGenerator { + public interface Registration { + Registration commandPermissionsConditionGenerator(CommandPermissionsConditionGenerator generator); + } + @Override public Command.Condition generateCondition(Method commandMethod) { CommandPermissions annotation = commandMethod.getAnnotation(CommandPermissions.class); diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/Logging.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/Logging.java similarity index 93% rename from worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/Logging.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/util/Logging.java index d8d87dcc0..e678cfde3 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/Logging.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/Logging.java @@ -20,7 +20,7 @@ //$Id$ -package com.sk89q.minecraft.util.commands; +package com.sk89q.worldedit.command.util; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java index 5851efe9c..08c39fb49 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java @@ -21,9 +21,6 @@ package com.sk89q.worldedit.extension.platform; import com.google.common.collect.ImmutableList; import com.google.inject.Key; -import com.sk89q.minecraft.util.commands.CommandLocals; -import com.sk89q.minecraft.util.commands.CommandPermissionsException; -import com.sk89q.minecraft.util.commands.WrappedCommandException; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -32,6 +29,8 @@ import com.sk89q.worldedit.command.BiomeCommands; import com.sk89q.worldedit.command.BiomeCommandsRegistration; import com.sk89q.worldedit.command.BrushCommands; import com.sk89q.worldedit.command.BrushCommandsRegistration; +import com.sk89q.worldedit.command.ChunkCommands; +import com.sk89q.worldedit.command.ChunkCommandsRegistration; import com.sk89q.worldedit.command.SchematicCommands; import com.sk89q.worldedit.command.SchematicCommandsRegistration; import com.sk89q.worldedit.command.argument.Arguments; @@ -44,18 +43,16 @@ import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandSuggestionEvent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.internal.command.ActorAuthorizer; +import com.sk89q.worldedit.internal.command.CommandLoggingHandler; import com.sk89q.worldedit.internal.command.UserCommandCompleter; import com.sk89q.worldedit.internal.command.WorldEditBinding; import com.sk89q.worldedit.internal.command.WorldEditExceptionConverter; +import com.sk89q.worldedit.session.SessionOwner; import com.sk89q.worldedit.session.request.Request; -import com.sk89q.worldedit.util.command.Dispatcher; -import com.sk89q.worldedit.util.command.InvalidUsageException; 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.eventbus.Subscribe; -import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; -import com.sk89q.worldedit.util.formatting.component.CommandUsageBox; import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.world.World; @@ -66,6 +63,12 @@ import org.enginehub.piston.exception.CommandException; import org.enginehub.piston.exception.CommandExecutionException; import org.enginehub.piston.exception.ConditionFailedException; import org.enginehub.piston.exception.UsageException; +import org.enginehub.piston.gen.CommandCallListener; +import org.enginehub.piston.gen.CommandRegistration; +import org.enginehub.piston.inject.InjectedValueAccess; +import org.enginehub.piston.inject.InjectedValueStore; +import org.enginehub.piston.inject.MapBackedValueStore; +import org.enginehub.piston.inject.MemoizingValueAccess; import org.enginehub.piston.part.SubCommandPart; import org.enginehub.piston.util.ValueProvider; import org.slf4j.Logger; @@ -73,6 +76,8 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; +import java.util.Collections; +import java.util.List; import java.util.Optional; import java.util.logging.FileHandler; import java.util.logging.Level; @@ -93,12 +98,14 @@ public final class PlatformCommandMananger { private static final java.util.logging.Logger commandLog = java.util.logging.Logger.getLogger(PlatformCommandMananger.class.getCanonicalName() + ".CommandLog"); private static final Pattern numberFormatExceptionPattern = Pattern.compile("^For input string: \"(.*)\"$"); + private static final CommandPermissionsConditionGenerator PERM_GEN = new CommandPermissionsConditionGenerator(); private final WorldEdit worldEdit; private final PlatformManager platformManager; private final CommandManager commandManager; private final DynamicStreamHandler dynamicHandler = new DynamicStreamHandler(); private final ExceptionConverter exceptionConverter; + private final List callListeners; /** * Create a new instance. @@ -113,7 +120,27 @@ public final class PlatformCommandMananger { this.exceptionConverter = new WorldEditExceptionConverter(worldEdit); this.commandManager = DefaultCommandManagerService.getInstance() .newCommandManager(); + this.callListeners = Collections.singletonList( + new CommandLoggingHandler(worldEdit, commandLog) + ); + // setup separate from main constructor + // ensures that everything is definitely assigned + initialize(); + } + private void register(CommandManager manager, CommandRegistration registration, CI instance) { + registration.containerInstance(instance) + .commandManager(manager) + .listeners(callListeners); + if (registration instanceof CommandPermissionsConditionGenerator.Registration) { + ((CommandPermissionsConditionGenerator.Registration) registration).commandPermissionsConditionGenerator( + PERM_GEN + ); + } + registration.build(); + } + + private void initialize() { // Register this instance for command events worldEdit.getEventBus().register(this); @@ -127,9 +154,6 @@ public final class PlatformCommandMananger { builder.addBinding(new WorldEditBinding(worldEdit)); builder.addInvokeListener(new LegacyCommandsHandler()); - CommandPermissionsConditionGenerator permsGenerator = - new CommandPermissionsConditionGenerator(); - commandManager.register("schematic", cmd -> { cmd.aliases(ImmutableList.of("schem", "/schematic", "/schem")); cmd.description("Schematic commands for saving/loading areas"); @@ -137,19 +161,17 @@ public final class PlatformCommandMananger { CommandManager manager = DefaultCommandManagerService.getInstance() .newCommandManager(); - SchematicCommandsRegistration.builder() - .commandManager(manager) - .containerInstance(new SchematicCommands(worldEdit)) - .commandPermissionsConditionGenerator( - permsGenerator - ).build(); + register( + manager, + SchematicCommandsRegistration.builder(), + new SchematicCommands(worldEdit) + ); cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.") .withCommands(manager.getAllCommands().collect(Collectors.toList())) .required() .build()); }); - commandManager.register("brush", cmd -> { cmd.aliases(ImmutableList.of("br")); cmd.description("Brushing commands"); @@ -157,31 +179,33 @@ public final class PlatformCommandMananger { CommandManager manager = DefaultCommandManagerService.getInstance() .newCommandManager(); - BrushCommandsRegistration.builder() - .commandManager(manager) - .containerInstance(new BrushCommands(worldEdit)) - .commandPermissionsConditionGenerator( - permsGenerator - ).build(); + register( + manager, + BrushCommandsRegistration.builder(), + new BrushCommands(worldEdit) + ); cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.") .withCommands(manager.getAllCommands().collect(Collectors.toList())) .required() .build()); }); - - BiomeCommandsRegistration.builder() - .commandManager(commandManager) - .containerInstance(new BiomeCommands()) - .commandPermissionsConditionGenerator(permsGenerator) - .build(); + register( + commandManager, + BiomeCommandsRegistration.builder(), + new BiomeCommands() + ); + register( + commandManager, + ChunkCommandsRegistration.builder(), + new ChunkCommands(worldEdit) + ); // Unported commands are below. Delete once they're added to the main manager above. /* dispatcher = new CommandGraph() .builder(builder) .commands() - .registerMethods(new ChunkCommands(worldEdit)) .registerMethods(new ClipboardCommands(worldEdit)) .registerMethods(new GeneralCommands(worldEdit)) .registerMethods(new GenerationCommands(worldEdit)) @@ -309,13 +333,31 @@ public final class PlatformCommandMananger { } LocalConfiguration config = worldEdit.getConfiguration(); - commandManager.injectValue(Key.get(Actor.class), ValueProvider.constant(actor)); - commandManager.injectValue(Key.get(Arguments.class), ValueProvider.constant(event::getArguments)); - commandManager.injectValue(Key.get(EditSessionHolder.class), - context -> context.injectedValue(Key.get(Actor.class)) - .filter(Player.class::isInstance) - .map(Player.class::cast) - .map(p -> new EditSessionHolder(worldEdit, p))); + InjectedValueStore store = MapBackedValueStore.create(); + store.injectValue(Key.get(Actor.class), ValueProvider.constant(actor)); + if (actor instanceof Player) { + store.injectValue(Key.get(Player.class), ValueProvider.constant((Player) actor)); + } + store.injectValue(Key.get(Arguments.class), ValueProvider.constant(event::getArguments)); + store.injectValue(Key.get(LocalSession.class), + context -> { + LocalSession localSession = worldEdit.getSessionManager().get(actor); + localSession.tellVersion(actor); + return Optional.of(localSession); + }); + store.injectValue(Key.get(EditSession.class), + context -> { + LocalSession localSession = context.injectedValue(Key.get(LocalSession.class)) + .orElseThrow(() -> new IllegalStateException("No LocalSession")); + return context.injectedValue(Key.get(Player.class)) + .map(player -> { + EditSession editSession = localSession.createEditSession(player); + editSession.enableStandardMode(); + return editSession; + }); + }); + + MemoizingValueAccess context = MemoizingValueAccess.wrap(store); long start = System.currentTimeMillis(); @@ -325,7 +367,7 @@ public final class PlatformCommandMananger { // exceptions without writing a hook into every dispatcher, we need to unwrap these // exceptions and rethrow their converted form, if their is one. try { - commandManager.execute(ImmutableList.copyOf(split)); + commandManager.execute(context, ImmutableList.copyOf(split)); } catch (Throwable t) { // Use the exception converter to convert the exception if any of its causes // can be converted, otherwise throw the original exception @@ -358,8 +400,8 @@ public final class PlatformCommandMananger { log.error("An unknown error occurred", e); } } finally { - Optional editSessionOpt = commandManager.injectedValue(Key.get(EditSessionHolder.class)) - .map(EditSessionHolder::getSession); + Optional editSessionOpt = + context.injectedValueIfMemoized(Key.get(EditSession.class)); if (editSessionOpt.isPresent()) { EditSession editSession = editSessionOpt.get(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java index f8fa06ff6..8cd2cdb5f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.internal.command; import com.google.inject.Key; -import com.sk89q.minecraft.util.commands.Logging; +import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit;