Comply with checkstyle again
This commit is contained in:
parent
e67b20dee0
commit
af4c7ba214
36 changed files with 329 additions and 74 deletions
|
|
@ -11,9 +11,9 @@ import java.util.Map;
|
||||||
import net.frankheijden.serverutils.bukkit.commands.CommandPlugins;
|
import net.frankheijden.serverutils.bukkit.commands.CommandPlugins;
|
||||||
import net.frankheijden.serverutils.bukkit.commands.CommandServerUtils;
|
import net.frankheijden.serverutils.bukkit.commands.CommandServerUtils;
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin;
|
import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin;
|
||||||
|
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||||
import net.frankheijden.serverutils.bukkit.listeners.BukkitListener;
|
import net.frankheijden.serverutils.bukkit.listeners.BukkitListener;
|
||||||
import net.frankheijden.serverutils.bukkit.managers.BukkitPluginManager;
|
import net.frankheijden.serverutils.bukkit.managers.BukkitPluginManager;
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
|
||||||
import net.frankheijden.serverutils.bukkit.reflection.RCommandMap;
|
import net.frankheijden.serverutils.bukkit.reflection.RCommandMap;
|
||||||
import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
import net.frankheijden.serverutils.bukkit.reflection.RCraftServer;
|
||||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||||
|
|
@ -68,7 +68,7 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new BukkitListener(), this);
|
Bukkit.getPluginManager().registerEvents(new BukkitListener(), this);
|
||||||
|
|
||||||
ServerUtilsApp.checkForUpdates();
|
ServerUtilsApp.tryCheckForUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerUtils getInstance() {
|
public static ServerUtils getInstance() {
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,35 @@ import net.frankheijden.serverutils.common.providers.ChatProvider;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides basic chat functionality for Bukkit servers.
|
||||||
|
*/
|
||||||
public class BukkitChatProvider extends ChatProvider {
|
public class BukkitChatProvider extends ChatProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the console sender of a Bukkit instance.
|
||||||
|
* @return The console sender.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ServerCommandSender getConsoleSender() {
|
public ServerCommandSender getConsoleSender() {
|
||||||
return BukkitUtils.wrap(Bukkit.getConsoleSender());
|
return BukkitUtils.wrap(Bukkit.getConsoleSender());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Colorizes the given string.
|
||||||
|
* @param str The string to color.
|
||||||
|
* @return The colored string.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String color(String str) {
|
public String color(String str) {
|
||||||
return ChatColor.translateAlternateColorCodes('&', str);
|
return ChatColor.translateAlternateColorCodes('&', str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcasts a message over a Bukkit instance.
|
||||||
|
* @param permission The permission the receivers need to have.
|
||||||
|
* @param message The message to broadcast.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void broadcast(String permission, String message) {
|
public void broadcast(String permission, String message) {
|
||||||
Bukkit.broadcast(message, permission);
|
Bukkit.broadcast(message, permission);
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,35 @@ package net.frankheijden.serverutils.bukkit.entities;
|
||||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrap for a Bukkit CommandSender.
|
||||||
|
*/
|
||||||
public class BukkitCommandSender implements ServerCommandSender {
|
public class BukkitCommandSender implements ServerCommandSender {
|
||||||
|
|
||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new CommandSender instance.
|
||||||
|
* @param sender The sender to wrap.
|
||||||
|
*/
|
||||||
public BukkitCommandSender(CommandSender sender) {
|
public BukkitCommandSender(CommandSender sender) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to a CommandSender.
|
||||||
|
* @param message The message to send.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
sender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the CommandSender has a permission.
|
||||||
|
* @param permission The permission to check.
|
||||||
|
* @return Whether or not they have the permission.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String permission) {
|
public boolean hasPermission(String permission) {
|
||||||
return sender.hasPermission(permission);
|
return sender.hasPermission(permission);
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bukkit.ServerUtils;
|
import net.frankheijden.serverutils.bukkit.ServerUtils;
|
||||||
import net.frankheijden.serverutils.common.providers.ResourceProvider;
|
|
||||||
import net.frankheijden.serverutils.common.config.YamlConfig;
|
import net.frankheijden.serverutils.common.config.YamlConfig;
|
||||||
|
import net.frankheijden.serverutils.common.providers.ResourceProvider;
|
||||||
|
|
||||||
public class BukkitResourceProvider implements ResourceProvider {
|
public class BukkitResourceProvider implements ResourceProvider {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package net.frankheijden.serverutils.bukkit.listeners;
|
package net.frankheijden.serverutils.bukkit.listeners;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.listeners.ServerListener;
|
|
||||||
import net.frankheijden.serverutils.bukkit.utils.BukkitUtils;
|
import net.frankheijden.serverutils.bukkit.utils.BukkitUtils;
|
||||||
|
import net.frankheijden.serverutils.common.listeners.ServerListener;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ import net.frankheijden.serverutils.bukkit.reflection.RCraftingManager;
|
||||||
import net.frankheijden.serverutils.bukkit.reflection.RJavaPlugin;
|
import net.frankheijden.serverutils.bukkit.reflection.RJavaPlugin;
|
||||||
import net.frankheijden.serverutils.bukkit.reflection.RPluginClassLoader;
|
import net.frankheijden.serverutils.bukkit.reflection.RPluginClassLoader;
|
||||||
import net.frankheijden.serverutils.bukkit.reflection.RSimplePluginManager;
|
import net.frankheijden.serverutils.bukkit.reflection.RSimplePluginManager;
|
||||||
import net.frankheijden.serverutils.common.managers.AbstractPluginManager;
|
|
||||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||||
import net.frankheijden.serverutils.common.entities.Result;
|
import net.frankheijden.serverutils.common.entities.Result;
|
||||||
|
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.PluginCommand;
|
||||||
|
|
@ -329,6 +329,15 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getPluginFile(Plugin plugin) {
|
||||||
|
try {
|
||||||
|
return RJavaPlugin.getFile(plugin);
|
||||||
|
} catch (ReflectiveOperationException ex) {
|
||||||
|
throw new RuntimeException("Error retrieving current plugin file", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getPluginsFolder() {
|
public File getPluginsFolder() {
|
||||||
return plugin.getDataFolder().getParentFile();
|
return plugin.getDataFolder().getParentFile();
|
||||||
|
|
@ -343,13 +352,4 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
||||||
public String getPluginName(Plugin plugin) {
|
public String getPluginName(Plugin plugin) {
|
||||||
return plugin.getName();
|
return plugin.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public File getPluginFile(Plugin plugin) {
|
|
||||||
try {
|
|
||||||
return RJavaPlugin.getFile(plugin);
|
|
||||||
} catch (ReflectiveOperationException ex) {
|
|
||||||
throw new RuntimeException("Error retrieving current plugin file", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.bukkit.entities.BukkitReflection.MINOR;
|
import static net.frankheijden.serverutils.bukkit.entities.BukkitReflection.MINOR;
|
||||||
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
|
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
|
||||||
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
||||||
|
|
@ -18,6 +16,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||||
|
|
||||||
public class RDedicatedServer {
|
public class RDedicatedServer {
|
||||||
|
|
||||||
private static Class<?> dedicatedServerClass;
|
private static Class<?> dedicatedServerClass;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
|
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.ReflectionUtils.getAllFields;
|
||||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
||||||
|
|
@ -9,6 +7,8 @@ import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VE
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||||
|
|
||||||
public class RDedicatedServerProperties {
|
public class RDedicatedServerProperties {
|
||||||
|
|
||||||
private static Class<?> serverPropertiesClass;
|
private static Class<?> serverPropertiesClass;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
||||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
||||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
||||||
|
|
@ -9,6 +7,8 @@ import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VE
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||||
|
|
||||||
public class RDedicatedServerSettings {
|
public class RDedicatedServerSettings {
|
||||||
|
|
||||||
private static Class<?> serverSettingsClass;
|
private static Class<?> serverSettingsClass;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
||||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
||||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.invoke;
|
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.invoke;
|
||||||
|
|
@ -11,6 +9,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||||
|
|
||||||
public class RJsonList {
|
public class RJsonList {
|
||||||
|
|
||||||
private static Class<?> jsonListClass;
|
private static Class<?> jsonListClass;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
||||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
||||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
||||||
|
|
@ -9,6 +7,8 @@ import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VE
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||||
|
|
||||||
public class RMinecraftServer {
|
public class RMinecraftServer {
|
||||||
|
|
||||||
private static Class<?> minecraftServerClass;
|
private static Class<?> minecraftServerClass;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
||||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
||||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
||||||
|
|
@ -9,6 +7,8 @@ import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VE
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||||
|
|
||||||
public class RPlayerList {
|
public class RPlayerList {
|
||||||
|
|
||||||
private static Class<?> playerListClass;
|
private static Class<?> playerListClass;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package net.frankheijden.serverutils.bukkit.reflection;
|
package net.frankheijden.serverutils.bukkit.reflection;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
import static net.frankheijden.serverutils.common.reflection.MethodParam.methodOf;
|
||||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllMethods;
|
||||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
||||||
|
|
@ -9,6 +7,8 @@ import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VE
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.bukkit.entities.BukkitReflection;
|
||||||
|
|
||||||
public class RPropertyManager {
|
public class RPropertyManager {
|
||||||
|
|
||||||
private static Class<?> propertyManagerClass;
|
private static Class<?> propertyManagerClass;
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ public class ServerUtils extends Plugin {
|
||||||
reload();
|
reload();
|
||||||
getProxy().getPluginManager().registerListener(this, new BungeeListener());
|
getProxy().getPluginManager().registerListener(this, new BungeeListener());
|
||||||
|
|
||||||
ServerUtilsApp.checkForUpdates();
|
ServerUtilsApp.tryCheckForUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerUtils getInstance() {
|
public static ServerUtils getInstance() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package net.frankheijden.serverutils.bungee.commands;
|
package net.frankheijden.serverutils.bungee.commands;
|
||||||
|
|
||||||
|
import static net.frankheijden.serverutils.common.config.Messenger.sendMessage;
|
||||||
|
|
||||||
import co.aikar.commands.BaseCommand;
|
import co.aikar.commands.BaseCommand;
|
||||||
import co.aikar.commands.annotation.CommandAlias;
|
import co.aikar.commands.annotation.CommandAlias;
|
||||||
import co.aikar.commands.annotation.CommandCompletion;
|
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.Default;
|
||||||
import co.aikar.commands.annotation.Description;
|
import co.aikar.commands.annotation.Description;
|
||||||
import co.aikar.commands.annotation.Subcommand;
|
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.ServerUtils;
|
||||||
import net.frankheijden.serverutils.bungee.entities.BungeeLoadResult;
|
import net.frankheijden.serverutils.bungee.entities.BungeeLoadResult;
|
||||||
import net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
|
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.Plugin;
|
||||||
import net.md_5.bungee.api.plugin.PluginDescription;
|
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")
|
@CommandAlias("bsu|bserverutils")
|
||||||
public class CommandServerUtils extends BaseCommand {
|
public class CommandServerUtils extends BaseCommand {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.bungee.ServerUtils;
|
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.config.YamlConfig;
|
||||||
|
import net.frankheijden.serverutils.common.providers.ResourceProvider;
|
||||||
|
|
||||||
public class BungeeResourceProvider implements ResourceProvider {
|
public class BungeeResourceProvider implements ResourceProvider {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,6 @@
|
||||||
package net.frankheijden.serverutils.bungee.managers;
|
package net.frankheijden.serverutils.bungee.managers;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
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.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -27,6 +16,18 @@ import java.util.jar.JarFile;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
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> {
|
public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
||||||
|
|
||||||
private static final ProxyServer proxy = ProxyServer.getInstance();
|
private static final ProxyServer proxy = ProxyServer.getInstance();
|
||||||
|
|
@ -102,9 +103,8 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
||||||
String name = desc.getName();
|
String name = desc.getName();
|
||||||
try {
|
try {
|
||||||
plugin.onEnable();
|
plugin.onEnable();
|
||||||
proxy.getLogger().log(Level.INFO, "Enabled plugin {0} version {1} by {2}", new Object[] {
|
Object[] args = new Object[] { name, desc.getVersion(), desc.getAuthor() };
|
||||||
name, desc.getVersion(), desc.getAuthor()
|
proxy.getLogger().log(Level.INFO, "Enabled plugin {0} version {1} by {2}", args);
|
||||||
});
|
|
||||||
return Result.SUCCESS;
|
return Result.SUCCESS;
|
||||||
} catch (Throwable th) {
|
} catch (Throwable th) {
|
||||||
proxy.getLogger().log(Level.WARNING, "Exception encountered when loading plugin: " + name, 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);
|
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) {
|
public File getPluginFile(String pluginName) {
|
||||||
for (File file : getPluginJars()) {
|
for (File file : getPluginJars()) {
|
||||||
PluginDescription desc;
|
PluginDescription desc;
|
||||||
|
|
@ -172,6 +177,17 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
||||||
return null;
|
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 {
|
public static PluginDescription getPluginDescription(File file) throws Exception {
|
||||||
try (JarFile jar = new JarFile(file)) {
|
try (JarFile jar = new JarFile(file)) {
|
||||||
JarEntry entry = getPluginDescriptionEntry(jar);
|
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) {
|
public static JarEntry getPluginDescriptionEntry(JarFile jar) {
|
||||||
JarEntry entry = jar.getJarEntry("bungee.yml");
|
JarEntry entry = jar.getJarEntry("bungee.yml");
|
||||||
if (entry == null) return jar.getJarEntry("plugin.yml");
|
if (entry == null) return jar.getJarEntry("plugin.yml");
|
||||||
return entry;
|
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) {
|
public static Closeable getCloseable(Plugin plugin) {
|
||||||
ClassLoader loader = plugin.getClass().getClassLoader();
|
ClassLoader loader = plugin.getClass().getClassLoader();
|
||||||
if (loader instanceof Closeable) return (Closeable) loader;
|
if (loader instanceof Closeable) return (Closeable) loader;
|
||||||
|
|
@ -211,6 +237,11 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
||||||
return getPlugins(false);
|
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) {
|
public List<Plugin> getPlugins(boolean modules) {
|
||||||
Collection<Plugin> plugins = plugin.getProxy().getPluginManager().getPlugins();
|
Collection<Plugin> plugins = plugin.getProxy().getPluginManager().getPlugins();
|
||||||
if (modules) return new ArrayList<>(plugins);
|
if (modules) return new ArrayList<>(plugins);
|
||||||
|
|
@ -224,11 +255,11 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
||||||
return plugin.getDataFolder().getName();
|
return plugin.getDataFolder().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public File getPluginFile(Plugin plugin) {
|
* Retrieves the plugins sorted by their names.
|
||||||
return plugin.getFile();
|
* @param modules Whether or not to include `module` plugins
|
||||||
}
|
* @return The sorted plugins.
|
||||||
|
*/
|
||||||
public List<Plugin> getPluginsSorted(boolean modules) {
|
public List<Plugin> getPluginsSorted(boolean modules) {
|
||||||
List<Plugin> plugins = getPlugins(modules);
|
List<Plugin> plugins = getPlugins(modules);
|
||||||
plugins.sort(Comparator.comparing(this::getPluginName));
|
plugins.sort(Comparator.comparing(this::getPluginName));
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
package net.frankheijden.serverutils.bungee.reflection;
|
package net.frankheijden.serverutils.bungee.reflection;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
|
||||||
import net.md_5.bungee.api.plugin.PluginDescription;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.common.reflection.FieldParam.fieldOf;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import static net.frankheijden.serverutils.common.reflection.ReflectionUtils.getAllFields;
|
import net.md_5.bungee.api.plugin.PluginDescription;
|
||||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
|
||||||
|
|
||||||
public class RPluginClassLoader {
|
public class RPluginClassLoader {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.ReflectionUtils.getAllFields;
|
||||||
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
||||||
|
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import net.frankheijden.serverutils.common.utils.MapUtils;
|
import net.frankheijden.serverutils.common.utils.MapUtils;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
@ -60,6 +61,13 @@ public class RPluginManager {
|
||||||
return (Map<String, Command>) get(fields, instance, "commandMap");
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
public static Plugin getPlugin(Object instance, Command cmd) throws IllegalAccessException {
|
public static Plugin getPlugin(Object instance, Command cmd) throws IllegalAccessException {
|
||||||
Object obj = get(fields, instance, "commandsByPlugin");
|
Object obj = get(fields, instance, "commandsByPlugin");
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,10 @@ public class ServerUtilsApp<T> {
|
||||||
new ServerUtilsApp<>(obj, plugin);
|
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")) {
|
if (Config.getInstance().getConfig().getBoolean("settings.check-updates")) {
|
||||||
UpdateCheckerTask.start(getPlugin().getChatProvider().getConsoleSender(), true);
|
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.ListBuilder;
|
||||||
import net.frankheijden.serverutils.common.utils.ListFormat;
|
import net.frankheijden.serverutils.common.utils.ListFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides some common utility methods for the Plugins command.
|
||||||
|
*/
|
||||||
public class Plugins {
|
public class Plugins {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,26 @@
|
||||||
package net.frankheijden.serverutils.common.config;
|
package net.frankheijden.serverutils.common.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The general common config class.
|
||||||
|
*/
|
||||||
public class Config extends YamlResource {
|
public class Config extends YamlResource {
|
||||||
|
|
||||||
private static Config instance;
|
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) {
|
public Config(String fileName, String resource) {
|
||||||
super(fileName, resource);
|
super(fileName, resource);
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the current instance of the Config.
|
||||||
|
* @return The current instance.
|
||||||
|
*/
|
||||||
public static Config getInstance() {
|
public static Config getInstance() {
|
||||||
return instance;
|
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.entities.ServerUtilsPlugin;
|
||||||
import net.frankheijden.serverutils.common.utils.StringUtils;
|
import net.frankheijden.serverutils.common.utils.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The general common messenger class.
|
||||||
|
*/
|
||||||
public class Messenger extends YamlResource {
|
public class Messenger extends YamlResource {
|
||||||
|
|
||||||
private static Messenger instance;
|
private static Messenger instance;
|
||||||
private static final ServerUtilsPlugin plugin = ServerUtilsApp.getPlugin();
|
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) {
|
public Messenger(String fileName, String resource) {
|
||||||
super(fileName, resource);
|
super(fileName, resource);
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the current instance of the Messenger.
|
||||||
|
* @return The current instance.
|
||||||
|
*/
|
||||||
public static Messenger getInstance() {
|
public static Messenger getInstance() {
|
||||||
return instance;
|
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) {
|
public static String color(String str) {
|
||||||
return Messenger.plugin.getChatProvider().color(str);
|
return Messenger.plugin.getChatProvider().color(str);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,56 @@ package net.frankheijden.serverutils.common.config;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrap for a Yaml Configuration file.
|
||||||
|
*/
|
||||||
public interface YamlConfig {
|
public interface YamlConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the value at a given path.
|
||||||
|
* @param path The path.
|
||||||
|
* @return The object.
|
||||||
|
*/
|
||||||
Object get(String path);
|
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);
|
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);
|
String getString(String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a boolean from a path.
|
||||||
|
* @param path The path.
|
||||||
|
* @return The boolean at given path.
|
||||||
|
*/
|
||||||
boolean getBoolean(String path);
|
boolean getBoolean(String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the key nodes at the current level.
|
||||||
|
* @return The keys.
|
||||||
|
*/
|
||||||
Collection<? extends String> getKeys();
|
Collection<? extends String> getKeys();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the YamlConfig to disk.
|
||||||
|
* @throws IOException Iff an I/O error occurred.
|
||||||
|
*/
|
||||||
void save() throws IOException;
|
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) {
|
static void addDefaults(YamlConfig def, YamlConfig conf) {
|
||||||
addDefaults(def, 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.entities.ServerUtilsPlugin;
|
||||||
import net.frankheijden.serverutils.common.providers.ResourceProvider;
|
import net.frankheijden.serverutils.common.providers.ResourceProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class which provides functionality for loading and setting defaults of Yaml Configurations.
|
||||||
|
*/
|
||||||
public class YamlResource {
|
public class YamlResource {
|
||||||
|
|
||||||
private static final ServerUtilsPlugin plugin = ServerUtilsApp.getPlugin();
|
private static final ServerUtilsPlugin plugin = ServerUtilsApp.getPlugin();
|
||||||
|
|
@ -26,6 +29,10 @@ public class YamlResource {
|
||||||
config = YamlConfig.init(provider.load(is), provider.load(file));
|
config = YamlConfig.init(provider.load(is), provider.load(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the YamlConfig of this resource.
|
||||||
|
* @return The YamlConfig.
|
||||||
|
*/
|
||||||
public YamlConfig getConfig() {
|
public YamlConfig getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ package net.frankheijden.serverutils.common.entities;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A result which should be closed when done.
|
||||||
|
*/
|
||||||
public class CloseableResult implements Closeable {
|
public class CloseableResult implements Closeable {
|
||||||
|
|
||||||
private Result result;
|
private Result result;
|
||||||
|
|
@ -20,18 +23,35 @@ public class CloseableResult implements Closeable {
|
||||||
this.closeable = closeable;
|
this.closeable = closeable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new closable result with no closable instance.
|
||||||
|
* @param result The result of the procedure
|
||||||
|
*/
|
||||||
public CloseableResult(Result result) {
|
public CloseableResult(Result result) {
|
||||||
this(result, null);
|
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) {
|
public CloseableResult(Closeable closeable) {
|
||||||
this(Result.SUCCESS, closeable);
|
this(Result.SUCCESS, closeable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the result.
|
||||||
|
* @return The result.
|
||||||
|
*/
|
||||||
public Result getResult() {
|
public Result getResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the result of this instance.
|
||||||
|
* @param result The result to set.
|
||||||
|
* @return The current instance.
|
||||||
|
*/
|
||||||
public CloseableResult set(Result result) {
|
public CloseableResult set(Result result) {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -49,6 +69,10 @@ public class CloseableResult implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the closable.
|
||||||
|
* @throws IOException Iff an I/O error occurred.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
closeable.close();
|
closeable.close();
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,60 @@
|
||||||
package net.frankheijden.serverutils.common.entities;
|
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> {
|
public class LoadResult<T> {
|
||||||
|
|
||||||
private final T obj;
|
private final T obj;
|
||||||
private final Result result;
|
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) {
|
public LoadResult(T obj, Result result) {
|
||||||
this.obj = obj;
|
this.obj = obj;
|
||||||
this.result = result;
|
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) {
|
public LoadResult(T obj) {
|
||||||
this(obj, Result.SUCCESS);
|
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) {
|
public LoadResult(Result result) {
|
||||||
this(null, result);
|
this(null, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the loaded object.
|
||||||
|
* @return The loaded object.
|
||||||
|
*/
|
||||||
public T get() {
|
public T get() {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result of the LoadResult.
|
||||||
|
* @return The result.
|
||||||
|
*/
|
||||||
public Result getResult() {
|
public Result getResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the result is a success.
|
||||||
|
* @return Whether there is success or not.
|
||||||
|
*/
|
||||||
public boolean isSuccess() {
|
public boolean isSuccess() {
|
||||||
return obj != null && result == Result.SUCCESS;
|
return obj != null && result == Result.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ package net.frankheijden.serverutils.common.entities;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.config.Messenger;
|
import net.frankheijden.serverutils.common.config.Messenger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enum containing possible results.
|
||||||
|
*/
|
||||||
public enum Result {
|
public enum Result {
|
||||||
NOT_EXISTS,
|
NOT_EXISTS,
|
||||||
NOT_ENABLED,
|
NOT_ENABLED,
|
||||||
|
|
@ -17,10 +20,18 @@ public enum Result {
|
||||||
|
|
||||||
private String arg;
|
private String arg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* private constructor which initializes a result with an empty argument.
|
||||||
|
*/
|
||||||
Result() {
|
Result() {
|
||||||
this.arg = "";
|
this.arg = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the argument of the result's message.
|
||||||
|
* @param arg The argument
|
||||||
|
* @return The current instance.
|
||||||
|
*/
|
||||||
public Result arg(String arg) {
|
public Result arg(String arg) {
|
||||||
this.arg = arg;
|
this.arg = arg;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,20 @@
|
||||||
package net.frankheijden.serverutils.common.entities;
|
package net.frankheijden.serverutils.common.entities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A basic wrapper for a CommandSender.
|
||||||
|
*/
|
||||||
public interface ServerCommandSender {
|
public interface ServerCommandSender {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to a CommandSender.
|
||||||
|
* @param message The message to send.
|
||||||
|
*/
|
||||||
void sendMessage(String message);
|
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);
|
boolean hasPermission(String permission);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ public class ServerListener {
|
||||||
|
|
||||||
private static final YamlConfig config = Config.getInstance().getConfig();
|
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) {
|
public static void handleUpdate(ServerCommandSender sender) {
|
||||||
if (!config.getBoolean("settings.check-updates-login")) return;
|
if (!config.getBoolean("settings.check-updates-login")) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package net.frankheijden.serverutils.common.managers;
|
package net.frankheijden.serverutils.common.managers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||||
import net.frankheijden.serverutils.common.entities.LoadResult;
|
import net.frankheijden.serverutils.common.entities.LoadResult;
|
||||||
import net.frankheijden.serverutils.common.entities.Result;
|
import net.frankheijden.serverutils.common.entities.Result;
|
||||||
import net.frankheijden.serverutils.common.providers.PluginProvider;
|
import net.frankheijden.serverutils.common.providers.PluginProvider;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public abstract class AbstractPluginManager<T> extends PluginProvider<T> {
|
public abstract class AbstractPluginManager<T> extends PluginProvider<T> {
|
||||||
|
|
||||||
public abstract LoadResult<T> loadPlugin(String pluginFile);
|
public abstract LoadResult<T> loadPlugin(String pluginFile);
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,28 @@ package net.frankheijden.serverutils.common.providers;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A basic chat provider class.
|
||||||
|
*/
|
||||||
public abstract class ChatProvider {
|
public abstract class ChatProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the console sender of a server instance.
|
||||||
|
* @return The console sender.
|
||||||
|
*/
|
||||||
public abstract ServerCommandSender getConsoleSender();
|
public abstract ServerCommandSender getConsoleSender();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Colorizes the given string.
|
||||||
|
* @param str The string to color.
|
||||||
|
* @return The colored string.
|
||||||
|
*/
|
||||||
public abstract String color(String str);
|
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);
|
public abstract void broadcast(String permission, String message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,20 @@ public abstract class PluginProvider<T> {
|
||||||
|
|
||||||
public abstract File getPluginFile(T plugin);
|
public abstract File getPluginFile(T plugin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of plugins, sorted by name.
|
||||||
|
* @return The list of plugins.
|
||||||
|
*/
|
||||||
public List<T> getPluginsSorted() {
|
public List<T> getPluginsSorted() {
|
||||||
List<T> plugins = getPlugins();
|
List<T> plugins = getPlugins();
|
||||||
plugins.sort(Comparator.comparing(this::getPluginName));
|
plugins.sort(Comparator.comparing(this::getPluginName));
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of plugin names.
|
||||||
|
* @return The plugin names.
|
||||||
|
*/
|
||||||
public List<String> getPluginNames() {
|
public List<String> getPluginNames() {
|
||||||
return getPlugins().stream()
|
return getPlugins().stream()
|
||||||
.map(this::getPluginName)
|
.map(this::getPluginName)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package net.frankheijden.serverutils.common.providers;
|
package net.frankheijden.serverutils.common.providers;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.config.YamlConfig;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.common.config.YamlConfig;
|
||||||
|
|
||||||
public interface ResourceProvider {
|
public interface ResourceProvider {
|
||||||
|
|
||||||
InputStream getResource(String resource);
|
InputStream getResource(String resource);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
|
@ -12,13 +13,13 @@ import java.net.UnknownHostException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
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.Config;
|
||||||
import net.frankheijden.serverutils.common.config.Messenger;
|
import net.frankheijden.serverutils.common.config.Messenger;
|
||||||
import net.frankheijden.serverutils.common.config.YamlConfig;
|
import net.frankheijden.serverutils.common.config.YamlConfig;
|
||||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
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.FileUtils;
|
||||||
import net.frankheijden.serverutils.common.utils.VersionUtils;
|
import net.frankheijden.serverutils.common.utils.VersionUtils;
|
||||||
|
|
||||||
|
|
@ -158,8 +159,9 @@ public class UpdateCheckerTask implements Runnable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File pluginFile = plugin.getPluginManager().getPluginFile(ServerUtilsApp.getPlatformPlugin());
|
||||||
try {
|
try {
|
||||||
FileUtils.download(downloadLink, plugin.getPluginManager().getPluginFile(ServerUtilsApp.getPlatformPlugin()));
|
FileUtils.download(downloadLink, pluginFile);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
broadcastDownloadStatus(githubVersion, true);
|
broadcastDownloadStatus(githubVersion, true);
|
||||||
throw new RuntimeException(DOWNLOAD_ERROR, ex);
|
throw new RuntimeException(DOWNLOAD_ERROR, ex);
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,9 @@ subprojects {
|
||||||
toolVersion "8.25"
|
toolVersion "8.25"
|
||||||
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
|
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
|
||||||
|
|
||||||
// ignoreFailures = false
|
ignoreFailures = false
|
||||||
// maxErrors = 0
|
maxErrors = 0
|
||||||
// maxWarnings = 0
|
maxWarnings = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar.dependsOn checkstyleMain, checkstyleTest, test
|
shadowJar.dependsOn checkstyleMain, checkstyleTest, test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue