Last active
July 15, 2020 17:43
-
-
Save JTK222/0f1fe6c6ec3bfbf4c1604183fb00eaef to your computer and use it in GitHub Desktop.
A rudimentary implementation of client side commands. No auto completion, no error messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Mod.EventBusSubscriber(modid = MODID, value = Dist.CLIENT) | |
public class ClientChatListener { | |
private static CommandDispatcher<CommandSource> commands = new CommandDispatcher(); | |
static{ | |
commands.register(Commands.literal("foo").executes(context -> { | |
context.getSource().sendFeedback(new StringTextComponent("bar"), false); | |
return 1; | |
})); | |
} | |
@SubscribeEvent | |
public static void playerChat(ClientChatEvent event){ | |
if(event.getMessage().startsWith("/")){ | |
try{ | |
ParseResults<CommandSource> parse = commands.parse(event.getMessage().substring(1), Minecraft.getInstance().player.getCommandSource()); | |
if(parse.getContext().getNodes().size() > 0){ | |
event.setCanceled(true); | |
commands.execute(parse); | |
} | |
} catch (CommandSyntaxException e) {} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment