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();
|
new BukkitReflection();
|
||||||
|
|
||||||
this.commandManager = new PaperCommandManager(this);
|
this.commandManager = new PaperCommandManager(this);
|
||||||
commandManager.registerCommand(new CommandServerUtils());
|
commandManager.registerCommand(new CommandServerUtils(), true);
|
||||||
this.commandPlugins = null;
|
this.commandPlugins = null;
|
||||||
|
|
||||||
BukkitPluginManager manager = plugin.getPluginManager();
|
BukkitPluginManager manager = plugin.getPluginManager();
|
||||||
|
|
@ -113,7 +113,7 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
||||||
if (!Config.getInstance().getConfig().getBoolean("settings.disable-plugins-command")) {
|
if (!Config.getInstance().getConfig().getBoolean("settings.disable-plugins-command")) {
|
||||||
this.removeCommands("pl", "plugins");
|
this.removeCommands("pl", "plugins");
|
||||||
this.commandPlugins = new CommandPlugins();
|
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 net.frankheijden.serverutils.common.managers.AbstractPluginManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.plugin.InvalidDescriptionException;
|
import org.bukkit.plugin.InvalidDescriptionException;
|
||||||
import org.bukkit.plugin.InvalidPluginException;
|
import org.bukkit.plugin.InvalidPluginException;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
@ -188,11 +188,15 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
||||||
public Result enablePlugin(Plugin plugin) {
|
public Result enablePlugin(Plugin plugin) {
|
||||||
if (plugin == null) return Result.NOT_EXISTS;
|
if (plugin == null) return Result.NOT_EXISTS;
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled(plugin.getName())) return Result.ALREADY_ENABLED;
|
if (Bukkit.getPluginManager().isPluginEnabled(plugin.getName())) return Result.ALREADY_ENABLED;
|
||||||
|
|
||||||
Bukkit.getPluginManager().enablePlugin(plugin);
|
Bukkit.getPluginManager().enablePlugin(plugin);
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled(plugin.getName())) {
|
try {
|
||||||
return Result.SUCCESS;
|
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;
|
if (knownCommands == null) return;
|
||||||
|
|
||||||
knownCommands.values().removeIf(c -> {
|
knownCommands.values().removeIf(c -> {
|
||||||
if (c instanceof PluginCommand) {
|
if (c instanceof PluginIdentifiableCommand) {
|
||||||
PluginCommand pc = (PluginCommand) c;
|
PluginIdentifiableCommand pc = (PluginIdentifiableCommand) c;
|
||||||
if (pc.getPlugin() == plugin) {
|
if (pc.getPlugin().getName().equals(plugin.getName())) {
|
||||||
pc.unregister(RCraftServer.getCommandMap());
|
c.unregister(RCraftServer.getCommandMap());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
RCraftServer.syncCommands();
|
||||||
|
} catch (ReflectiveOperationException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,8 @@ public class RCraftServer {
|
||||||
fieldOf("chunkGCLoadThresh", max(12)),
|
fieldOf("chunkGCLoadThresh", max(12)),
|
||||||
fieldOf("playerList"));
|
fieldOf("playerList"));
|
||||||
methods = getAllMethods(craftServerClass,
|
methods = getAllMethods(craftServerClass,
|
||||||
methodOf("loadIcon"));
|
methodOf("loadIcon"),
|
||||||
|
methodOf("syncCommands"));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -101,6 +102,10 @@ public class RCraftServer {
|
||||||
return commandMap;
|
return commandMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void syncCommands() throws InvocationTargetException, IllegalAccessException {
|
||||||
|
invoke(methods, craftServer, "syncCommands");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads the bukkit configuration.
|
* Reloads the bukkit configuration.
|
||||||
* @throws ReflectiveOperationException Iff exception thrown regarding reflection.
|
* @throws ReflectiveOperationException Iff exception thrown regarding reflection.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue