Add initial cloud commands + refactors to common
This commit is contained in:
parent
f21306021d
commit
6545d7ffac
89 changed files with 1959 additions and 1893 deletions
|
|
@ -1,40 +1,25 @@
|
|||
package net.frankheijden.serverutils.bukkit;
|
||||
|
||||
import co.aikar.commands.BukkitCommandCompletionContext;
|
||||
import co.aikar.commands.CommandCompletions;
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.frankheijden.serverutils.bukkit.commands.CommandPlugins;
|
||||
import net.frankheijden.serverutils.bukkit.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin;
|
||||
import net.frankheijden.serverutils.bukkit.listeners.BukkitListener;
|
||||
import net.frankheijden.serverutils.bukkit.managers.BukkitPluginManager;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCommandMap;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||
import net.frankheijden.serverutils.common.config.Config;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.frankheijden.serverutils.common.utils.StringUtils;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.defaults.PluginsCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
||||
public class ServerUtils extends JavaPlugin {
|
||||
|
||||
private static ServerUtils instance;
|
||||
private static final String CONFIG_RESOURCE = "bukkit-config.yml";
|
||||
private static final String MESSAGES_RESOURCE = "bukkit-messages.yml";
|
||||
|
||||
private BukkitPlugin plugin;
|
||||
private PaperCommandManager commandManager;
|
||||
private CommandPlugins commandPlugins;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
|
@ -45,23 +30,7 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
ServerUtilsApp.init(this, plugin);
|
||||
|
||||
new Metrics(this, ServerUtilsApp.BSTATS_METRICS_ID);
|
||||
|
||||
this.commandManager = new PaperCommandManager(this);
|
||||
commandManager.registerCommand(new CommandServerUtils(), true);
|
||||
this.commandPlugins = null;
|
||||
|
||||
BukkitPluginManager manager = plugin.getPluginManager();
|
||||
CommandCompletions<BukkitCommandCompletionContext> completions = commandManager.getCommandCompletions();
|
||||
completions.registerAsyncCompletion("plugins", context -> manager.getPluginNames());
|
||||
completions.registerAsyncCompletion("pluginJars", context -> manager.getPluginFileNames());
|
||||
completions.registerAsyncCompletion("supportedConfigs", context -> CommandServerUtils.getSupportedConfigs());
|
||||
completions.registerAsyncCompletion("commands", context -> manager.getCommands());
|
||||
reload();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new BukkitListener(), this);
|
||||
plugin.enable();
|
||||
|
||||
ServerUtilsApp.tryCheckForUpdates();
|
||||
}
|
||||
|
||||
public static ServerUtils getInstance() {
|
||||
|
|
@ -75,54 +44,20 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
commandManager.unregisterCommands();
|
||||
restoreBukkitPluginCommand();
|
||||
plugin.disable();
|
||||
}
|
||||
|
||||
private void removeCommands(String... commands) {
|
||||
Map<String, Command> map;
|
||||
try {
|
||||
map = RCommandMap.getKnownCommands(RCraftServer.getCommandMap());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
for (String command : commands) {
|
||||
map.remove(command);
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreBukkitPluginCommand() {
|
||||
RCraftServer.getCommandMap().register("bukkit", new PluginsCommand("plugins"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the configurations of the plugin.
|
||||
* Also makes sure the bukkit /pl command gets restored.
|
||||
* Retrieves the disabled commands from the configuration.
|
||||
*/
|
||||
public void reload() {
|
||||
if (commandPlugins != null) {
|
||||
commandManager.unregisterCommand(commandPlugins);
|
||||
restoreBukkitPluginCommand();
|
||||
}
|
||||
|
||||
new Config("config.yml", CONFIG_RESOURCE);
|
||||
new Messenger("messages.yml", MESSAGES_RESOURCE);
|
||||
|
||||
if (!Config.getInstance().getConfig().getBoolean("settings.disable-plugins-command")) {
|
||||
this.removeCommands("pl", "plugins");
|
||||
this.commandPlugins = new CommandPlugins();
|
||||
commandManager.registerCommand(commandPlugins, true);
|
||||
}
|
||||
|
||||
getPlugin().getTaskManager().runTask(() -> BukkitPluginManager.unregisterExactCommands(getDisabledCommands()));
|
||||
}
|
||||
|
||||
private List<Command> getDisabledCommands() {
|
||||
public List<Command> getDisabledCommands() {
|
||||
List<Command> commands = new ArrayList<>();
|
||||
for (String cmd : Config.getInstance().getConfig().getStringList("disabled-commands")) {
|
||||
for (String cmd : plugin.getConfigResource().getConfig().getStringList("disabled-commands")) {
|
||||
String[] split = cmd.split(":");
|
||||
|
||||
Command command;
|
||||
|
|
@ -153,8 +88,4 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
public PaperCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue