Comply with checkstyle again

This commit is contained in:
Frank van der Heijden 2020-07-05 16:59:07 +02:00
parent e67b20dee0
commit af4c7ba214
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
36 changed files with 329 additions and 74 deletions

View file

@ -47,7 +47,7 @@ public class ServerUtils extends Plugin {
reload();
getProxy().getPluginManager().registerListener(this, new BungeeListener());
ServerUtilsApp.checkForUpdates();
ServerUtilsApp.tryCheckForUpdates();
}
public static ServerUtils getInstance() {

View file

@ -1,5 +1,7 @@
package net.frankheijden.serverutils.bungee.commands;
import static net.frankheijden.serverutils.common.config.Messenger.sendMessage;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
@ -7,6 +9,11 @@ import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Subcommand;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.frankheijden.serverutils.bungee.ServerUtils;
import net.frankheijden.serverutils.bungee.entities.BungeeLoadResult;
import net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
@ -25,12 +32,6 @@ import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginDescription;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static net.frankheijden.serverutils.common.config.Messenger.sendMessage;
@CommandAlias("bsu|bserverutils")
public class CommandServerUtils extends BaseCommand {

View file

@ -5,8 +5,8 @@ import java.io.IOException;
import java.io.InputStream;
import net.frankheijden.serverutils.bungee.ServerUtils;
import net.frankheijden.serverutils.common.providers.ResourceProvider;
import net.frankheijden.serverutils.common.config.YamlConfig;
import net.frankheijden.serverutils.common.providers.ResourceProvider;
public class BungeeResourceProvider implements ResourceProvider {

View file

@ -1,17 +1,6 @@
package net.frankheijden.serverutils.bungee.managers;
import com.google.common.base.Preconditions;
import net.frankheijden.serverutils.bungee.ServerUtils;
import net.frankheijden.serverutils.bungee.entities.BungeeLoadResult;
import net.frankheijden.serverutils.bungee.reflection.RPluginClassLoader;
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
import net.frankheijden.serverutils.common.managers.AbstractPluginManager;
import net.frankheijden.serverutils.common.entities.CloseableResult;
import net.frankheijden.serverutils.common.entities.Result;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginDescription;
import org.yaml.snakeyaml.Yaml;
import java.io.Closeable;
import java.io.File;
@ -27,6 +16,18 @@ import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.stream.Collectors;
import net.frankheijden.serverutils.bungee.ServerUtils;
import net.frankheijden.serverutils.bungee.entities.BungeeLoadResult;
import net.frankheijden.serverutils.bungee.reflection.RPluginClassLoader;
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
import net.frankheijden.serverutils.common.entities.CloseableResult;
import net.frankheijden.serverutils.common.entities.Result;
import net.frankheijden.serverutils.common.managers.AbstractPluginManager;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginDescription;
import org.yaml.snakeyaml.Yaml;
public class BungeePluginManager extends AbstractPluginManager<Plugin> {
private static final ProxyServer proxy = ProxyServer.getInstance();
@ -73,7 +74,7 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
try {
desc = getPluginDescription(file);
} catch (Exception ex) {
proxy.getLogger().log(Level.WARNING, "Could not load plugin from file " + file, ex );
proxy.getLogger().log(Level.WARNING, "Could not load plugin from file " + file, ex);
return new BungeeLoadResult(Result.INVALID_DESCRIPTION);
}
@ -102,9 +103,8 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
String name = desc.getName();
try {
plugin.onEnable();
proxy.getLogger().log(Level.INFO, "Enabled plugin {0} version {1} by {2}", new Object[] {
name, desc.getVersion(), desc.getAuthor()
});
Object[] args = new Object[] { name, desc.getVersion(), desc.getAuthor() };
proxy.getLogger().log(Level.INFO, "Enabled plugin {0} version {1} by {2}", args);
return Result.SUCCESS;
} catch (Throwable th) {
proxy.getLogger().log(Level.WARNING, "Exception encountered when loading plugin: " + name, th);
@ -158,6 +158,11 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
return new File(proxy.getPluginsFolder(), fileName);
}
/**
* Retrieves the File of a plugin associated with a name.
* @param pluginName The plugin name to search for.
* @return The File if the plugin exists with that name.
*/
public File getPluginFile(String pluginName) {
for (File file : getPluginJars()) {
PluginDescription desc;
@ -172,6 +177,17 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
return null;
}
@Override
public File getPluginFile(Plugin plugin) {
return plugin.getFile();
}
/**
* Retrieves the PluginDescription of a (plugin's) File.
* @param file The file.
* @return The PluginDescription.
* @throws Exception Iff and I/O exception occurred, or notNullChecks failed.
*/
public static PluginDescription getPluginDescription(File file) throws Exception {
try (JarFile jar = new JarFile(file)) {
JarEntry entry = getPluginDescriptionEntry(jar);
@ -189,12 +205,22 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
}
}
/**
* Retrieves the JarEntry which contains the Description file of the JarFile.
* @param jar The JarFile.
* @return The description JarEntry.
*/
public static JarEntry getPluginDescriptionEntry(JarFile jar) {
JarEntry entry = jar.getJarEntry("bungee.yml");
if (entry == null) return jar.getJarEntry("plugin.yml");
return entry;
}
/**
* Retrieves the closable classloader of the plugin, if possible.
* @param plugin The plugin.
* @return The closable instance.
*/
public static Closeable getCloseable(Plugin plugin) {
ClassLoader loader = plugin.getClass().getClassLoader();
if (loader instanceof Closeable) return (Closeable) loader;
@ -211,6 +237,11 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
return getPlugins(false);
}
/**
* Retrieves a list of plugins.
* @param modules Whether or not to include `module` plugins.
* @return The list of plugins.
*/
public List<Plugin> getPlugins(boolean modules) {
Collection<Plugin> plugins = plugin.getProxy().getPluginManager().getPlugins();
if (modules) return new ArrayList<>(plugins);
@ -224,11 +255,11 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
return plugin.getDataFolder().getName();
}
@Override
public File getPluginFile(Plugin plugin) {
return plugin.getFile();
}
/**
* Retrieves the plugins sorted by their names.
* @param modules Whether or not to include `module` plugins
* @return The sorted plugins.
*/
public List<Plugin> getPluginsSorted(boolean modules) {
List<Plugin> plugins = getPlugins(modules);
plugins.sort(Comparator.comparing(this::getPluginName));

View file

@ -1,17 +1,14 @@
package net.frankheijden.serverutils.bungee.reflection;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.PluginDescription;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Map;
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.PluginDescription;
public class RPluginClassLoader {

View file

@ -5,10 +5,11 @@ import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.get
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
import com.google.common.collect.Multimap;
import java.lang.reflect.Field;
import java.util.Map;
import com.google.common.collect.Multimap;
import net.frankheijden.serverutils.common.utils.MapUtils;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Plugin;
@ -60,6 +61,13 @@ public class RPluginManager {
return (Map<String, Command>) get(fields, instance, "commandMap");
}
/**
* Retrieves the registered plugin of the command.
* @param instance The PluginManager instance.
* @param cmd The command to check the plugin of.
* @return The plugin of the command
* @throws IllegalAccessException Iff some reflection error occurred.
*/
@SuppressWarnings("unchecked")
public static Plugin getPlugin(Object instance, Command cmd) throws IllegalAccessException {
Object obj = get(fields, instance, "commandsByPlugin");