From bb33897221bed832bdfbc0d31853b19b709ae016 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Mon, 4 Mar 2019 19:57:22 -0800 Subject: [PATCH] Handle all commands like pre-1.13 for now --- .../sk89q/worldedit/forge/CommandWrapper.java | 22 +++++++++--------- .../sk89q/worldedit/forge/ForgeWorldEdit.java | 23 +++++++++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/CommandWrapper.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/CommandWrapper.java index cb1d051b4..b070d2a6c 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/CommandWrapper.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/CommandWrapper.java @@ -24,6 +24,8 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; import com.sk89q.worldedit.WorldEdit; @@ -114,19 +116,17 @@ public class CommandWrapper { } private static Command commandFor(CommandMapping mapping) { - return ctx -> { - EntityPlayerMP player = ctx.getSource().asPlayer(); - if (player.world.isRemote()) { - return 0; - } - WorldEdit.getInstance().getEventBus().post(new CommandEvent( - adaptPlayer(player), - ctx.getRange().get(ctx.getInput()) - )); - return 1; - }; + return FAKE_COMMAND; } + public static final Command FAKE_COMMAND = ctx -> { + EntityPlayerMP player = ctx.getSource().asPlayer(); + if (player.world.isRemote()) { + return 0; + } + return 1; + }; + private static Predicate requirementsFor(CommandMapping mapping) { return ctx -> { ForgePermissionsProvider permsProvider = ForgeWorldEdit.inst.getPermissionsProvider(); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java index 60025a7ec..b5a80a36b 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java @@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.forge.ForgeAdapter.adaptPlayer; import com.google.common.base.Joiner; +import com.mojang.brigadier.ParseResults; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.event.platform.PlatformReadyEvent; @@ -37,6 +39,7 @@ import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.item.ItemCategory; import com.sk89q.worldedit.world.item.ItemType; import net.minecraft.client.Minecraft; +import net.minecraft.command.CommandSource; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; @@ -270,6 +273,26 @@ public class ForgeWorldEdit { } } + @SubscribeEvent + public void onCommandEvent(CommandEvent event) throws CommandSyntaxException { + ParseResults parseResults = event.getParseResults(); + if (!(parseResults.getContext().getSource().getEntity() instanceof EntityPlayerMP)) { + return; + } + EntityPlayerMP player = parseResults.getContext().getSource().asPlayer(); + if (player.world.isRemote()) { + return; + } + if (parseResults.getContext().getCommand() != CommandWrapper.FAKE_COMMAND) { + return; + } + event.setCanceled(true); + WorldEdit.getInstance().getEventBus().post(new com.sk89q.worldedit.event.platform.CommandEvent( + adaptPlayer(parseResults.getContext().getSource().asPlayer()), + parseResults.getReader().getString() + )); + } + /** * Get the configuration. *