Forwarding commands registered outside RegisterCommandsEvent (#291)
This commit is contained in:
parent
a4f015fce6
commit
0fcaba618f
|
@ -7,6 +7,7 @@ import com.mojang.brigadier.tree.RootCommandNode;
|
||||||
import io.izzel.arclight.common.bridge.command.CommandNodeBridge;
|
import io.izzel.arclight.common.bridge.command.CommandNodeBridge;
|
||||||
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
|
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
|
||||||
import io.izzel.arclight.common.bridge.server.MinecraftServerBridge;
|
import io.izzel.arclight.common.bridge.server.MinecraftServerBridge;
|
||||||
|
import io.izzel.arclight.common.mod.util.BukkitDispatcher;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.command.CommandSource;
|
||||||
import net.minecraft.command.Commands;
|
import net.minecraft.command.Commands;
|
||||||
import net.minecraft.command.ISuggestionProvider;
|
import net.minecraft.command.ISuggestionProvider;
|
||||||
|
@ -34,7 +35,7 @@ public abstract class CommandsMixin {
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
public void arclight$constructor() {
|
public void arclight$constructor() {
|
||||||
this.dispatcher = new CommandDispatcher<>();
|
this.dispatcher = new BukkitDispatcher((Commands) (Object) this);
|
||||||
this.dispatcher.setConsumer((context, b, i) -> context.getSource().onCommandComplete(context, b, i));
|
this.dispatcher.setConsumer((context, b, i) -> context.getSource().onCommandComplete(context, b, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package io.izzel.arclight.common.mod.util;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import net.minecraft.command.CommandSource;
|
||||||
|
import net.minecraft.command.Commands;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v.command.BukkitCommandWrapper;
|
||||||
|
import org.bukkit.craftbukkit.v.command.VanillaCommandWrapper;
|
||||||
|
|
||||||
|
public class BukkitDispatcher extends CommandDispatcher<CommandSource> {
|
||||||
|
|
||||||
|
private final Commands commands;
|
||||||
|
|
||||||
|
public BukkitDispatcher(Commands commands) {
|
||||||
|
this.commands = commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSource> register(LiteralArgumentBuilder<CommandSource> command) {
|
||||||
|
LiteralCommandNode<CommandSource> node = command.build();
|
||||||
|
if (!(node.getCommand() instanceof BukkitCommandWrapper)) {
|
||||||
|
VanillaCommandWrapper wrapper = new VanillaCommandWrapper(this.commands, node);
|
||||||
|
((CraftServer) Bukkit.getServer()).getCommandMap().register("forge", wrapper);
|
||||||
|
}
|
||||||
|
getRoot().addChild(node);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user