Improve Bukkit (un)loading once more
- Call CraftServer#synCommands after (un)loading plugin - Force command registrations of ServerUtils
This commit is contained in:
parent
1723a9564f
commit
7d6d360908
3 changed files with 26 additions and 11 deletions
|
|
@ -46,7 +46,7 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
new BukkitReflection();
|
||||
|
||||
this.commandManager = new PaperCommandManager(this);
|
||||
commandManager.registerCommand(new CommandServerUtils());
|
||||
commandManager.registerCommand(new CommandServerUtils(), true);
|
||||
this.commandPlugins = null;
|
||||
|
||||
BukkitPluginManager manager = plugin.getPluginManager();
|
||||
|
|
@ -113,7 +113,7 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
if (!Config.getInstance().getConfig().getBoolean("settings.disable-plugins-command")) {
|
||||
this.removeCommands("pl", "plugins");
|
||||
this.commandPlugins = new CommandPlugins();
|
||||
commandManager.registerCommand(commandPlugins);
|
||||
commandManager.registerCommand(commandPlugins, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import net.frankheijden.serverutils.common.entities.Result;
|
|||
import net.frankheijden.serverutils.common.managers.AbstractPluginManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
import org.bukkit.plugin.InvalidPluginException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
|
@ -188,11 +188,15 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
|||
public Result enablePlugin(Plugin plugin) {
|
||||
if (plugin == null) return Result.NOT_EXISTS;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled(plugin.getName())) return Result.ALREADY_ENABLED;
|
||||
|
||||
Bukkit.getPluginManager().enablePlugin(plugin);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled(plugin.getName())) {
|
||||
return Result.SUCCESS;
|
||||
try {
|
||||
RCraftServer.syncCommands();
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return Result.ERROR;
|
||||
|
||||
return Bukkit.getPluginManager().isPluginEnabled(plugin.getName()) ? Result.SUCCESS : Result.ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -253,16 +257,22 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
|||
if (knownCommands == null) return;
|
||||
|
||||
knownCommands.values().removeIf(c -> {
|
||||
if (c instanceof PluginCommand) {
|
||||
PluginCommand pc = (PluginCommand) c;
|
||||
if (pc.getPlugin() == plugin) {
|
||||
pc.unregister(RCraftServer.getCommandMap());
|
||||
if (c instanceof PluginIdentifiableCommand) {
|
||||
PluginIdentifiableCommand pc = (PluginIdentifiableCommand) c;
|
||||
if (pc.getPlugin().getName().equals(plugin.getName())) {
|
||||
c.unregister(RCraftServer.getCommandMap());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
try {
|
||||
RCraftServer.syncCommands();
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ public class RCraftServer {
|
|||
fieldOf("chunkGCLoadThresh", max(12)),
|
||||
fieldOf("playerList"));
|
||||
methods = getAllMethods(craftServerClass,
|
||||
methodOf("loadIcon"));
|
||||
methodOf("loadIcon"),
|
||||
methodOf("syncCommands"));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
|
@ -101,6 +102,10 @@ public class RCraftServer {
|
|||
return commandMap;
|
||||
}
|
||||
|
||||
public static void syncCommands() throws InvocationTargetException, IllegalAccessException {
|
||||
invoke(methods, craftServer, "syncCommands");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the bukkit configuration.
|
||||
* @throws ReflectiveOperationException Iff exception thrown regarding reflection.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue