Initial BungeeCord edition
This commit is contained in:
parent
4416d55173
commit
23e8e80191
75 changed files with 1931 additions and 396 deletions
|
|
@ -3,23 +3,25 @@ package net.frankheijden.serverutils.bukkit;
|
|||
import co.aikar.commands.BukkitCommandCompletionContext;
|
||||
import co.aikar.commands.CommandCompletions;
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
import java.io.File;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.frankheijden.serverutils.bukkit.commands.CommandPlugins;
|
||||
import net.frankheijden.serverutils.bukkit.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.bukkit.config.Config;
|
||||
import net.frankheijden.serverutils.bukkit.config.Messenger;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin;
|
||||
import net.frankheijden.serverutils.bukkit.listeners.MainListener;
|
||||
import net.frankheijden.serverutils.bukkit.managers.VersionManager;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.BukkitReflection;
|
||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCommandMap;
|
||||
import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
||||
import net.frankheijden.serverutils.bukkit.tasks.UpdateCheckerTask;
|
||||
import net.frankheijden.serverutils.bukkit.utils.BukkitUtils;
|
||||
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.providers.PluginProvider;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
|
|
@ -30,31 +32,33 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
|
||||
public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
||||
|
||||
private static final int BSTATS_METRICS_ID = 7790;
|
||||
|
||||
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;
|
||||
|
||||
public static ServerUtils getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
instance = this;
|
||||
|
||||
new Metrics(this, BSTATS_METRICS_ID);
|
||||
this.plugin = new BukkitPlugin(this);
|
||||
ServerUtilsApp.init(plugin);
|
||||
|
||||
new Metrics(this, ServerUtilsApp.BSTATS_METRICS_ID);
|
||||
new BukkitReflection();
|
||||
|
||||
this.commandManager = new PaperCommandManager(this);
|
||||
commandManager.registerCommand(new CommandServerUtils());
|
||||
this.commandPlugins = null;
|
||||
|
||||
PluginProvider<Plugin> provider = plugin.getPluginProvider();
|
||||
CommandCompletions<BukkitCommandCompletionContext> completions = commandManager.getCommandCompletions();
|
||||
completions.registerAsyncCompletion("plugins", context -> getPluginNames());
|
||||
completions.registerAsyncCompletion("pluginJars", context -> getPluginFileNames());
|
||||
completions.registerAsyncCompletion("plugins", context -> provider.getPluginNames());
|
||||
completions.registerAsyncCompletion("pluginJars", context -> provider.getPluginFileNames());
|
||||
completions.registerAsyncCompletion("supportedConfigs ", context -> CommandServerUtils.getSupportedConfigs());
|
||||
completions.registerAsyncCompletion("commands", context -> {
|
||||
try {
|
||||
|
|
@ -72,24 +76,20 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
checkForUpdates();
|
||||
}
|
||||
|
||||
public static ServerUtils getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public BukkitPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
restoreBukkitPluginCommand();
|
||||
}
|
||||
|
||||
private List<String> getPluginNames() {
|
||||
return Arrays.stream(Bukkit.getPluginManager().getPlugins())
|
||||
.map(Plugin::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<String> getPluginFileNames() {
|
||||
return Arrays.stream(getJars())
|
||||
.map(File::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void removeCommands(String... commands) {
|
||||
Map<String, Command> map;
|
||||
try {
|
||||
|
|
@ -118,10 +118,10 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
restoreBukkitPluginCommand();
|
||||
}
|
||||
|
||||
new Config(copyResourceIfNotExists("config.yml", "bukkit-config.yml"));
|
||||
new Messenger(copyResourceIfNotExists("messages.yml", "bukkit-messages.yml"));
|
||||
new Config("config.yml", CONFIG_RESOURCE);
|
||||
new Messenger("messages.yml", MESSAGES_RESOURCE);
|
||||
|
||||
if (!Config.getInstance().getBoolean("settings.disable-plugins-command")) {
|
||||
if (!Config.getInstance().getConfig().getBoolean("settings.disable-plugins-command")) {
|
||||
this.removeCommands("pl", "plugins");
|
||||
this.commandPlugins = new CommandPlugins();
|
||||
commandManager.registerCommand(commandPlugins);
|
||||
|
|
@ -132,38 +132,9 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
return commandManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all files with a jar extension in the plugins/ folder.
|
||||
* @return An array of jar files.
|
||||
*/
|
||||
public File[] getJars() {
|
||||
File parent = getDataFolder().getParentFile();
|
||||
if (parent == null) return new File[0];
|
||||
return parent.listFiles(f -> f.getName().endsWith(".jar"));
|
||||
}
|
||||
|
||||
private void createDataFolderIfNotExists() {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
private File copyResourceIfNotExists(String targetName, String resource) {
|
||||
createDataFolderIfNotExists();
|
||||
|
||||
File file = new File(getDataFolder(), targetName);
|
||||
if (!file.exists()) {
|
||||
getLogger().info(String.format("'%s' not found, creating!", targetName));
|
||||
saveResource(resource, false);
|
||||
File copiedFile = new File(getDataFolder(), resource);
|
||||
copiedFile.renameTo(file);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
private void checkForUpdates() {
|
||||
if (Config.getInstance().getBoolean("settings.check-updates")) {
|
||||
UpdateCheckerTask.start(Bukkit.getConsoleSender(), true);
|
||||
if (Config.getInstance().getConfig().getBoolean("settings.check-updates")) {
|
||||
UpdateCheckerTask.start(BukkitUtils.wrap(Bukkit.getConsoleSender()), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue