Fixed dynamic command registration

This commit is contained in:
Auxilor
2022-11-28 17:28:29 +00:00
parent 80ad738bb2
commit abd07389ab
13 changed files with 180 additions and 55 deletions

View File

@@ -1,5 +1,6 @@
package com.willfp.eco.core;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.eco.core.config.ConfigType;
import com.willfp.eco.core.config.interfaces.Config;
import com.willfp.eco.core.config.interfaces.LoadableConfig;
@@ -29,6 +30,7 @@ import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandMap;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Mob;
@@ -510,6 +512,20 @@ public interface Eco {
*/
void syncCommands();
/**
* Get the command map.
*
* @return The command map.
*/
@NotNull CommandMap getCommandMap();
/**
* Unregister a command.
*
* @param command The command.
*/
void unregisterCommand(@NotNull final PluginCommand command);
/**
* Get the instance of eco; the bridge between the api frontend
* and the implementation backend.

View File

@@ -73,10 +73,7 @@ public abstract class PluginCommand extends HandledCommand implements CommandExe
public final void unregister() {
CommandMap commandMap = getCommandMap();
Command found = commandMap.getCommand(this.getName());
if (found != null) {
found.unregister(commandMap);
}
Eco.get().unregisterCommand(this);
Eco.get().syncCommands();
}