Closed kangarko closed 1 month ago
commands need to be dispatched in the correct context, i.e. the players tick thread (see the player scheduler)
Can't I just call Player#chat("/" + command)?
Upon trying, looks like there is a bug in Folia:
[15:56:54 WARN]: java.lang.IllegalStateException: PlayerCommandPreprocessEvent may only be triggered synchronously.
[15:56:54 WARN]: at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:42)
[15:56:54 WARN]: at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:131)
[15:56:54 WARN]: at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:628)
[15:56:54 WARN]: at net.minecraft.server.network.ServerGamePacketListenerImpl.performUnsignedChatCommand(ServerGamePacketListenerImpl.java:2257)
[15:56:54 WARN]: at net.minecraft.server.network.ServerGamePacketListenerImpl.handleCommand(ServerGamePacketListenerImpl.java:2547)
[15:56:54 WARN]: at org.bukkit.craftbukkit.entity.CraftPlayer.chat(CraftPlayer.java:755)
that stuff expects to be called within the context of the player. That event is a sync event, after all. calling chat() async works for chat because that expects to be dispatched async, commands expect to be ran on the 'main thread'
Got it. Thank you.
Expected behavior
Player performs the command successfully.
Observed/Actual behavior
Steps/models to reproduce
Call Player#performCommand from AsyncPlayerChatEvent or wrap it in runDelayed scheduler.
Plugin and Datapack List
ChatControlRed
Folia version
This server is running Folia version 1.21.1-DEV-dev/1.21.1@88e0907 (2024-09-09T13:10:08Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)
Other
Hey,
I'd like to learn the proper way to dispatching commands in Folia from AsyncPlayerEvent. Attaching details above. Thanks.