Skip to content

Conversation

@VladOliinyk
Copy link

Why?
Cannot execute MyCommands custom commands (even "registered") via console-command-on-entry flag.

Problem:
WorldGuard's onCrossBoundary event often fires asynchronously. Invoking Bukkit.dispatchCommand directly from this async context violates the Bukkit API contract, causing plugins that rely on the main thread (like MyCommand) to fail silently or throw IllegalStateException.

Solution:
Implemented a hybrid execution strategy in ConsoleCommandOnEntry/Exit handlers:

  1. Thread Safety: Checks Bukkit.isPrimaryThread(). If async, the command batch is scheduled via Bukkit.getScheduler().runTask(); otherwise, it runs immediately to minimize latency.
  2. Exception Isolation: Wrapped command execution in a try-catch block so that a failure in one command (e.g., an unregistered command) does not halt the execution of subsequent commands.
  3. Reliability: Replaced unsafe plugin lookup with JavaPlugin.getProvidingPlugin(getClass()) to ensure a valid plugin instance is used for scheduling.

Tested on Paper 1.21.11 (Paper version 1.21.11-88-main@8556cb4).
Goal reached, works for me, will update this thread if I find any bugs/errors/etc.

Prevent 'Asynchronous command dispatch' errors and silent failures for external plugins (e.g., MyCommand) by ensuring Bukkit.dispatchCommand is always executed on the primary server thread.

Tested (and fixed) purposly for MyCommand plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant