Skip to content

Delegate Bukkit command registering logic to CommandRegistrationStrategy#560

Merged
DerEchtePilz merged 10 commits intodev/devfrom
dev/example/paper-command-registration
Jun 6, 2024
Merged

Delegate Bukkit command registering logic to CommandRegistrationStrategy#560
DerEchtePilz merged 10 commits intodev/devfrom
dev/example/paper-command-registration

Conversation

@willkroboth
Copy link
Copy Markdown
Collaborator

@willkroboth willkroboth commented Jun 3, 2024

This PR moves a lot of the current logic for registering commands on Bukkit into the class SpigotCommandRegistration. This allows an alternate implementation of the new CommandRegistrationStrategy interface to be loaded when internal changes from PaperMC/Paper#8235 (Paper-1.20.6-65 and later) are present. The CommandRegistrationStrategy is created by the method NMS#createCommandRegistrationStrategy.

This is a more permanent fix than #555 and resolves these issues when running on Paper-1.20.65 and later:

  • Running /minecraft:reload deletes CommandAPI commands (Thanks FireML on Discord)
  • unregisterBukkit parameter of CommandAPIBukkit#unregister isn't fully taken into account

The implementation can still probably be refined by #517 (e.g. CommandAPI-Spigot should never need PaperCommandRegistration, and later Paper versions should never need SpigotCommandReigistration)

The NMS methods getResourcesDispatcher, isVanillaCommandWrapper, wrapToVanillaCommandWrapper, and isBukkitCommandWrapper were moved to SpigotCommandRegistration because they only make sense if Paper changes are not present. These methods are only used in the CommandAPI by SpigotCommandRegistration anyway, but developers can still access them using CommandAPIBukkit#getCommandRegistrationStrategy. PaperCommandRegistration provides a similar method: isBukkitCommand.

TODO:

Before merging I want to double check that the following works

  • Commands register during server start up
  • Commands register after server enables
  • unregisterBukkit parameter is repsected
  • Commands persist after minecraft:reload

On the following versions:

  • Latest Paper (Paper-1.20.6-131)

  • Paper-1.20.6-65

  • Paper-1.20.6-64

  • Paper-1.20.5

  • Paper-1.20.4

  • Spigot 1.20.6

  • Spigot 1.20.4

And of course~ code review is greatly appreciated!

willkroboth and others added 8 commits June 3, 2024 11:36
…tegy`

Just a rough example implementation

`NMS#getResourceDispatcher` replaced by `NMS#createCommandRegistrationStrategy`, which creates a `SpigotCommandRegistration` implementation using the resources dispatcher

Alternate fix for #554. If we're on Paper-1.20.6-65, a `PaperCommandRegistration` implementation is used instead. This can be used to properly handle the internal changes made by PaperMC/Paper#8235.
…cher`

It seems the underlying field accessed by running `this.<MinecraftServer>getMinecraftServer().getCommands().getDispatcher()` changes at some point. So, calling this during load actually results in just another copy of the `brigadierDispatcher`. However, if we call it later, it correctly returns the `resourcesDispatcher`.
…mands are unregistered

Avoids reintroducing unregistered commands after `/minecraft:reload`
Copy link
Copy Markdown
Member

@DerEchtePilz DerEchtePilz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's our standpoint on those * imports?
Do we want them? I personally tried to avoid them in general but we can also leave them like they are if we think they're fine.

Comment on lines +25 to +27
public PaperCommandRegistration(
Supplier<CommandDispatcher<Source>> getBrigadierDispatcher, Predicate<CommandNode<Source>> isBukkitCommand
) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some me kind of nitpick but can we have this on one line?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I think I expected to need to add more parameters (like SpigotCommandRegistration), but just two is a reasonable length.

@JorelAli
Copy link
Copy Markdown
Member

JorelAli commented Jun 3, 2024

What's our standpoint on those * imports? Do we want them?

We don't care. They don't change the output of the compiled code, the only downside to them is it's harder for humans to statically analyse code by staring at it in something other than an IDE, but it's 2024 and that's basically irrelevant.

Copy link
Copy Markdown
Member

@DerEchtePilz DerEchtePilz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DerEchtePilz DerEchtePilz merged commit 96a7014 into dev/dev Jun 6, 2024
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.

3 participants