Despical / CommandFramework

A lightweight annotation based command system
https://spigotmc.org/resources/89933
GNU General Public License v3.0
23 stars 5 forks source link

[Feature] Unregister commands #4

Closed gamerover98 closed 1 year ago

gamerover98 commented 1 year ago

Description of the new feature

The current API provides methods to register commands but no one to do the opposite.

Scenario

A plugin that uses CommandFramework is unloaded using a plugin like PlugMan: what happens? Commands still exist in the server.

What to do

Add a new method called CommandFramework#unregister(...) that calls the org.bukkit.command.Command#unregister(CommandMap commandMap) method.

How this should be used

Two ways:

  1. commandFramework.unregister(plugin);
  2. commandFramework.unregister(commandClassInstance);

Looking forward to your feedback and collaboration on this enhancement. Thank you

Despical commented 1 year ago

commandFramework.unregister(commandClassInstance); is fine but the first method you suggested is just useless because the framework is initialized with only one instance so it won't make a difference.

Secondly, org.bukkit.command.Command#unregister method won't delete the command from server-side. (just want to inform you in this case you won't see unknown command message if you execute the deleted command because all registered commands are stored in a different map object in SimpleCommandMap class even they're unregistered.)

I'm going to add some new methods tomorrow, thank you for the idea.