- 69
- 1
- 2
В одиночном мире команд отображаютса но на сервах нет
Java:
@SubscribeEvent
public static void onRegisterCommandEvent(RegisterCommandsEvent event){
CommandDispatcher<CommandSource> commandDispatcher =event.getDispatcher();
addbind.register(commandDispatcher);
spawn.register(commandDispatcher);
vanish.register(commandDispatcher);
}
Java:
package com.example.examplemod;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.util.text.ITextComponent;
public class addbind implements Command<CommandSource> {
private static final addbind CMD = new addbind();
public static void register(CommandDispatcher<CommandSource> dispatcher) {
LiteralArgumentBuilder<CommandSource> addbind = Commands.literal("addbind")
.requires((commandSource -> commandSource.hasPermission(0)))
.executes(CMD);
dispatcher.register(addbind);
}
@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
System.out.println(context);
Minecraft.getInstance().setScreen(new TestGui());
return 0;
}
}
class spawn implements Command<CommandSource> {
private static final spawn CMD = new spawn();
public static void register(CommandDispatcher<CommandSource> dispatcher) {
LiteralArgumentBuilder<CommandSource> spawn = Commands.literal("s")
.requires((commandSource -> commandSource.hasPermission(0)))
.executes(CMD);
dispatcher.register(spawn);
}
@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
System.out.println(context);
((ClientPlayerEntity) Minecraft.getInstance().player).chat("/spawn");
return 0;
}
}
class vanish implements Command<CommandSource> {
private static final vanish CMD = new vanish();
public static void register(CommandDispatcher<CommandSource> dispatcher) {
LiteralArgumentBuilder<CommandSource> vanish = Commands.literal("v")
.requires((commandSource -> commandSource.hasPermission(0)))
.executes(CMD);
dispatcher.register(vanish);
}
@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
System.out.println(context);
((ClientPlayerEntity) Minecraft.getInstance().player).chat("/vanish");
return 0;
}
}

