Fabric API

Fabric API

106M Downloads

Cannot execute command: Cannot invoke CommandDispatcher.execute

apple502j opened this issue ยท 2 comments

commented

This is an issue reported several times by multiple users; see #2631 and #2809.

Summary

Commands cannot be executed. The error is:Cannot invoke ''com.mojang.brigadier.CommandDispatcher.execute(String,Object)''because ''net.fabricmc.fabric.impl.command.client.ClientCommandInternals.activeDispatcher'' is null.

Cause

Most, if not all, of the reports indicate they are on a server. The cause is currently being investigated.

Fix

WIP. We haven't been able to reproduce this; I have a speculative fix but I am not sure if folks here are happy with merging it.

commented

This issue can be reproduced by registering a ClientPlayConnectionEvents.JOIN listener that throws an exception, then connecting to a server and attempting to run a command:

ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
	dispatcher.register(ClientCommandManager.literal("pling").executes(context -> {
		return Command.SINGLE_SUCCESS;
	}));
});

ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
	throw new IllegalStateException();
});

Note that this issue cannot be reproduced in singleplayer as the client will just crash. Connecting to a server prints the exception to the log instead, leaving the client command dispatcher in an invalid uninitialized state.

commented

Fixed by #2813.