Handle all commands like pre-1.13 for now

This commit is contained in:
Kenzie Togami 2019-03-04 19:57:22 -08:00
parent 4878f38250
commit bb33897221
No known key found for this signature in database
GPG Key ID: 5D200B325E157A81
2 changed files with 34 additions and 11 deletions

View File

@ -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,18 +116,16 @@ public class CommandWrapper {
}
private static Command<CommandSource> commandFor(CommandMapping mapping) {
return ctx -> {
return FAKE_COMMAND;
}
public static final Command<CommandSource> FAKE_COMMAND = 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;
};
}
private static Predicate<CommandSource> requirementsFor(CommandMapping mapping) {
return ctx -> {

View File

@ -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<CommandSource> 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.
*