Comply with checkstyle again
This commit is contained in:
parent
e67b20dee0
commit
af4c7ba214
36 changed files with 329 additions and 74 deletions
|
|
@ -24,7 +24,10 @@ public class ServerUtilsApp<T> {
|
|||
new ServerUtilsApp<>(obj, plugin);
|
||||
}
|
||||
|
||||
public static void checkForUpdates() {
|
||||
/**
|
||||
* Tries checking for updates if enabled by the config.
|
||||
*/
|
||||
public static void tryCheckForUpdates() {
|
||||
if (Config.getInstance().getConfig().getBoolean("settings.check-updates")) {
|
||||
UpdateCheckerTask.start(getPlugin().getChatProvider().getConsoleSender(), true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
|||
import net.frankheijden.serverutils.common.utils.ListBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ListFormat;
|
||||
|
||||
/**
|
||||
* Provides some common utility methods for the Plugins command.
|
||||
*/
|
||||
public class Plugins {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,14 +1,26 @@
|
|||
package net.frankheijden.serverutils.common.config;
|
||||
|
||||
/**
|
||||
* The general common config class.
|
||||
*/
|
||||
public class Config extends YamlResource {
|
||||
|
||||
private static Config instance;
|
||||
|
||||
/**
|
||||
* Constructs a new Config with the config file name and the resource name from the jar.
|
||||
* @param fileName The file name in the data folder.
|
||||
* @param resource The resource name in the jar file.
|
||||
*/
|
||||
public Config(String fileName, String resource) {
|
||||
super(fileName, resource);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current instance of the Config.
|
||||
* @return The current instance.
|
||||
*/
|
||||
public static Config getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,28 @@ import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
|||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
import net.frankheijden.serverutils.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* The general common messenger class.
|
||||
*/
|
||||
public class Messenger extends YamlResource {
|
||||
|
||||
private static Messenger instance;
|
||||
private static final ServerUtilsPlugin plugin = ServerUtilsApp.getPlugin();
|
||||
|
||||
/**
|
||||
* Constructs a new Messenger with the messages file name and the resource name from the jar.
|
||||
* @param fileName The file name in the data folder.
|
||||
* @param resource The resource name in the jar file.
|
||||
*/
|
||||
public Messenger(String fileName, String resource) {
|
||||
super(fileName, resource);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current instance of the Messenger.
|
||||
* @return The current instance.
|
||||
*/
|
||||
public static Messenger getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
|
@ -61,6 +73,11 @@ public class Messenger extends YamlResource {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Colorizes the given string.
|
||||
* @param str The string to color.
|
||||
* @return The colored string.
|
||||
*/
|
||||
public static String color(String str) {
|
||||
return Messenger.plugin.getChatProvider().color(str);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,20 +3,56 @@ package net.frankheijden.serverutils.common.config;
|
|||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A wrap for a Yaml Configuration file.
|
||||
*/
|
||||
public interface YamlConfig {
|
||||
|
||||
/**
|
||||
* Retrieves the value at a given path.
|
||||
* @param path The path.
|
||||
* @return The object.
|
||||
*/
|
||||
Object get(String path);
|
||||
|
||||
/**
|
||||
* Sets a value to a path.
|
||||
* @param path The path.
|
||||
* @param value The object to set the path's value to.
|
||||
*/
|
||||
void set(String path, Object value);
|
||||
|
||||
/**
|
||||
* Retrieves a string from a path.
|
||||
* @param path The path.
|
||||
* @return The string at given path.
|
||||
*/
|
||||
String getString(String path);
|
||||
|
||||
/**
|
||||
* Retrieves a boolean from a path.
|
||||
* @param path The path.
|
||||
* @return The boolean at given path.
|
||||
*/
|
||||
boolean getBoolean(String path);
|
||||
|
||||
/**
|
||||
* Retrieves the key nodes at the current level.
|
||||
* @return The keys.
|
||||
*/
|
||||
Collection<? extends String> getKeys();
|
||||
|
||||
/**
|
||||
* Saves the YamlConfig to disk.
|
||||
* @throws IOException Iff an I/O error occurred.
|
||||
*/
|
||||
void save() throws IOException;
|
||||
|
||||
/**
|
||||
* Adds defaults if keys don't exist to the configuration specified.
|
||||
* @param def The defaults to copy values over from.
|
||||
* @param conf The configuration to copy the defaults to.
|
||||
*/
|
||||
static void addDefaults(YamlConfig def, YamlConfig conf) {
|
||||
addDefaults(def, conf, "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ import net.frankheijden.serverutils.common.ServerUtilsApp;
|
|||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
import net.frankheijden.serverutils.common.providers.ResourceProvider;
|
||||
|
||||
/**
|
||||
* A class which provides functionality for loading and setting defaults of Yaml Configurations.
|
||||
*/
|
||||
public class YamlResource {
|
||||
|
||||
private static final ServerUtilsPlugin plugin = ServerUtilsApp.getPlugin();
|
||||
|
|
@ -26,6 +29,10 @@ public class YamlResource {
|
|||
config = YamlConfig.init(provider.load(is), provider.load(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the YamlConfig of this resource.
|
||||
* @return The YamlConfig.
|
||||
*/
|
||||
public YamlConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package net.frankheijden.serverutils.common.entities;
|
|||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A result which should be closed when done.
|
||||
*/
|
||||
public class CloseableResult implements Closeable {
|
||||
|
||||
private Result result;
|
||||
|
|
@ -20,18 +23,35 @@ public class CloseableResult implements Closeable {
|
|||
this.closeable = closeable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new closable result with no closable instance.
|
||||
* @param result The result of the procedure
|
||||
*/
|
||||
public CloseableResult(Result result) {
|
||||
this(result, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new closable result with a closable instance and success result.
|
||||
* @param closeable The closable of the procedure.
|
||||
*/
|
||||
public CloseableResult(Closeable closeable) {
|
||||
this(Result.SUCCESS, closeable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the result.
|
||||
* @return The result.
|
||||
*/
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the result of this instance.
|
||||
* @param result The result to set.
|
||||
* @return The current instance.
|
||||
*/
|
||||
public CloseableResult set(Result result) {
|
||||
this.result = result;
|
||||
return this;
|
||||
|
|
@ -49,6 +69,10 @@ public class CloseableResult implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the closable.
|
||||
* @throws IOException Iff an I/O error occurred.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
closeable.close();
|
||||
|
|
|
|||
|
|
@ -1,31 +1,60 @@
|
|||
package net.frankheijden.serverutils.common.entities;
|
||||
|
||||
/**
|
||||
* A result which contains a loaded object from a load operation.
|
||||
* @param <T> The loaded object type
|
||||
*/
|
||||
public class LoadResult<T> {
|
||||
|
||||
private final T obj;
|
||||
private final Result result;
|
||||
|
||||
/**
|
||||
* Constructs a new LoadResult with an object and a result.
|
||||
* @param obj The object of the load operation.
|
||||
* @param result The result of the load operation.
|
||||
*/
|
||||
public LoadResult(T obj, Result result) {
|
||||
this.obj = obj;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new LoadResult with an object and a success result.
|
||||
* @param obj The object of the load operation.
|
||||
*/
|
||||
public LoadResult(T obj) {
|
||||
this(obj, Result.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new LoadResult without a loaded object, just a result.
|
||||
* @param result The result of the load operation.
|
||||
*/
|
||||
public LoadResult(Result result) {
|
||||
this(null, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the loaded object.
|
||||
* @return The loaded object.
|
||||
*/
|
||||
public T get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* The result of the LoadResult.
|
||||
* @return The result.
|
||||
*/
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the result is a success.
|
||||
* @return Whether there is success or not.
|
||||
*/
|
||||
public boolean isSuccess() {
|
||||
return obj != null && result == Result.SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ package net.frankheijden.serverutils.common.entities;
|
|||
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
|
||||
/**
|
||||
* An enum containing possible results.
|
||||
*/
|
||||
public enum Result {
|
||||
NOT_EXISTS,
|
||||
NOT_ENABLED,
|
||||
|
|
@ -17,10 +20,18 @@ public enum Result {
|
|||
|
||||
private String arg;
|
||||
|
||||
/**
|
||||
* private constructor which initializes a result with an empty argument.
|
||||
*/
|
||||
Result() {
|
||||
this.arg = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the argument of the result's message.
|
||||
* @param arg The argument
|
||||
* @return The current instance.
|
||||
*/
|
||||
public Result arg(String arg) {
|
||||
this.arg = arg;
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,20 @@
|
|||
package net.frankheijden.serverutils.common.entities;
|
||||
|
||||
/**
|
||||
* A basic wrapper for a CommandSender.
|
||||
*/
|
||||
public interface ServerCommandSender {
|
||||
|
||||
/**
|
||||
* Sends a message to a CommandSender.
|
||||
* @param message The message to send.
|
||||
*/
|
||||
void sendMessage(String message);
|
||||
|
||||
/**
|
||||
* Checks if the CommandSender has a permission.
|
||||
* @param permission The permission to check.
|
||||
* @return Whether or not they have the permission.
|
||||
*/
|
||||
boolean hasPermission(String permission);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ public class ServerListener {
|
|||
|
||||
private static final YamlConfig config = Config.getInstance().getConfig();
|
||||
|
||||
/**
|
||||
* Handles the update check on the given ServerCommandSender.
|
||||
* @param sender The sender which triggered the update.
|
||||
*/
|
||||
public static void handleUpdate(ServerCommandSender sender) {
|
||||
if (!config.getBoolean("settings.check-updates-login")) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package net.frankheijden.serverutils.common.managers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||
import net.frankheijden.serverutils.common.entities.LoadResult;
|
||||
import net.frankheijden.serverutils.common.entities.Result;
|
||||
import net.frankheijden.serverutils.common.providers.PluginProvider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class AbstractPluginManager<T> extends PluginProvider<T> {
|
||||
|
||||
public abstract LoadResult<T> loadPlugin(String pluginFile);
|
||||
|
|
|
|||
|
|
@ -2,11 +2,28 @@ package net.frankheijden.serverutils.common.providers;
|
|||
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
|
||||
/**
|
||||
* A basic chat provider class.
|
||||
*/
|
||||
public abstract class ChatProvider {
|
||||
|
||||
/**
|
||||
* Retrieves the console sender of a server instance.
|
||||
* @return The console sender.
|
||||
*/
|
||||
public abstract ServerCommandSender getConsoleSender();
|
||||
|
||||
/**
|
||||
* Colorizes the given string.
|
||||
* @param str The string to color.
|
||||
* @return The colored string.
|
||||
*/
|
||||
public abstract String color(String str);
|
||||
|
||||
/**
|
||||
* Broadcasts a message over a server instance.
|
||||
* @param permission The permission the receivers need to have.
|
||||
* @param message The message to broadcast.
|
||||
*/
|
||||
public abstract void broadcast(String permission, String message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,20 @@ public abstract class PluginProvider<T> {
|
|||
|
||||
public abstract File getPluginFile(T plugin);
|
||||
|
||||
/**
|
||||
* Retrieves a list of plugins, sorted by name.
|
||||
* @return The list of plugins.
|
||||
*/
|
||||
public List<T> getPluginsSorted() {
|
||||
List<T> plugins = getPlugins();
|
||||
plugins.sort(Comparator.comparing(this::getPluginName));
|
||||
return plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of plugin names.
|
||||
* @return The plugin names.
|
||||
*/
|
||||
public List<String> getPluginNames() {
|
||||
return getPlugins().stream()
|
||||
.map(this::getPluginName)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package net.frankheijden.serverutils.common.providers;
|
||||
|
||||
import net.frankheijden.serverutils.common.config.YamlConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.frankheijden.serverutils.common.config.YamlConfig;
|
||||
|
||||
public interface ResourceProvider {
|
||||
|
||||
InputStream getResource(String resource);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.google.gson.JsonArray;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
|
|
@ -12,13 +13,13 @@ import java.net.UnknownHostException;
|
|||
import java.util.logging.Level;
|
||||
|
||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
import net.frankheijden.serverutils.common.managers.AbstractVersionManager;
|
||||
import net.frankheijden.serverutils.common.config.Config;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.frankheijden.serverutils.common.config.YamlConfig;
|
||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
import net.frankheijden.serverutils.common.managers.AbstractVersionManager;
|
||||
import net.frankheijden.serverutils.common.utils.FileUtils;
|
||||
import net.frankheijden.serverutils.common.utils.VersionUtils;
|
||||
|
||||
|
|
@ -158,8 +159,9 @@ public class UpdateCheckerTask implements Runnable {
|
|||
return;
|
||||
}
|
||||
|
||||
File pluginFile = plugin.getPluginManager().getPluginFile(ServerUtilsApp.getPlatformPlugin());
|
||||
try {
|
||||
FileUtils.download(downloadLink, plugin.getPluginManager().getPluginFile(ServerUtilsApp.getPlatformPlugin()));
|
||||
FileUtils.download(downloadLink, pluginFile);
|
||||
} catch (IOException ex) {
|
||||
broadcastDownloadStatus(githubVersion, true);
|
||||
throw new RuntimeException(DOWNLOAD_ERROR, ex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue