Add initial cloud commands + refactors to common

This commit is contained in:
Frank van der Heijden 2021-07-24 02:02:55 +02:00
parent f21306021d
commit 6545d7ffac
No known key found for this signature in database
GPG key ID: B808721C2DD5B5B8
89 changed files with 1959 additions and 1893 deletions

View file

@ -3,6 +3,7 @@ plugins {
}
group = rootProject.group + '.common'
String dependencyDir = group + '.dependencies'
version = rootProject.version
archivesBaseName = rootProject.name + '-Common'
@ -11,8 +12,8 @@ repositories {
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
compileOnly 'com.github.FrankHeijden:ServerUtilsUpdater:v1.0.0'
compileOnly 'com.google.code.gson:gson:2.8.6'
}
blossom {
@ -24,4 +25,5 @@ shadowJar {
exclude 'net/frankheijden/serverutilsupdater/**'
exclude 'plugin.yml'
exclude 'bungee.yml'
relocate 'com.google.gson', dependencyDir + '.gson'
}

View file

@ -0,0 +1,46 @@
package net.frankheijden.serverutils.common.commands;
import cloud.commandframework.context.CommandContext;
import java.util.List;
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
import net.frankheijden.serverutils.common.utils.ListBuilder;
import net.frankheijden.serverutils.common.utils.ListFormat;
public abstract class CommandPlugins<
U extends ServerUtilsPlugin<P, T, C, S>,
P,
T,
C extends ServerCommandSender<S>,
S
> extends ServerUtilsCommand<U, P, T, C, S> {
protected CommandPlugins(U plugin) {
super(plugin, "plugins");
}
protected abstract void handlePlugins(CommandContext<C> context);
/**
* Sends a plugin list to the receiver.
* @param sender The receiver of the plugin list.
* @param plugins The plugins to be sent.
* @param pluginFormat The format of the plugins to be sent.
* @param <T> The plugin type.
*/
protected void handlePlugins(C sender, List<P> plugins, ListFormat<P> pluginFormat) {
String prefix = plugin.getMessagesResource().getMessage(
"serverutils.plugins.prefix",
"%count%", String.valueOf(plugins.size())
);
if (prefix == null) prefix = "";
plugin.getMessagesResource().sendMessage(sender, "serverutils.plugins.header");
sender.sendMessage(plugin.getChatProvider().color(prefix + ListBuilder.create(plugins)
.seperator(plugin.getMessagesResource().getMessage("serverutils.plugins.seperator"))
.lastSeperator(plugin.getMessagesResource().getMessage("serverutils.plugins.last_seperator"))
.format(pluginFormat)
.toString()));
plugin.getMessagesResource().sendMessage(sender, "serverutils.plugins.footer");
}
}

View file

@ -0,0 +1,240 @@
package net.frankheijden.serverutils.common.commands;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.context.CommandContext;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import net.frankheijden.serverutils.common.entities.AbstractResult;
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.entities.ServerCommandSender;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
import net.frankheijden.serverutils.common.managers.AbstractPluginManager;
import net.frankheijden.serverutils.common.utils.FormatBuilder;
import net.frankheijden.serverutils.common.utils.ListBuilder;
import net.frankheijden.serverutils.common.utils.ListFormat;
public abstract class CommandServerUtils<
U extends ServerUtilsPlugin<P, T, C, S>,
P,
T,
C extends ServerCommandSender<S>,
S
> extends ServerUtilsCommand<U, P, T, C, S> {
protected CommandServerUtils(
U plugin
) {
super(plugin, "serverutils");
}
@Override
public void register(CommandManager<C> manager, Command.Builder<C> builder) {
final List<String> pluginFileNames = plugin.getPluginManager().getPluginFileNames();
addArgument(CommandArgument.<C, String>ofType(String.class, "jarFile")
.manager(manager)
.withSuggestionsProvider((context, s) -> pluginFileNames)
.build());
final List<String> pluginNames = plugin.getPluginManager().getPluginNames();
addArgument(CommandArgument.<C, String>ofType(String.class, "plugin")
.manager(manager)
.withSuggestionsProvider((context, s) -> pluginNames)
.build());
final List<String> commandNames = new ArrayList<>(plugin.getPluginManager().getCommands());
addArgument(CommandArgument.<C, String>ofType(String.class, "command")
.manager(manager)
.withSuggestionsProvider((context, s) -> commandNames)
.build());
manager.command(builder
.handler(this::handleHelpCommand));
manager.command(parseSubcommand(builder, "help")
.handler(this::handleHelpCommand));
manager.command(parseSubcommand(builder, "reload")
.handler(this::handleReload));
manager.command(parseSubcommand(builder, "loadplugin")
.argument(getArgument("jarFile"))
.handler(this::handleLoadPlugin));
manager.command(parseSubcommand(builder, "unloadplugin")
.argument(getArgument("plugin"))
.handler(this::handleUnloadPlugin));
manager.command(parseSubcommand(builder, "reloadplugin")
.argument(getArgument("plugin"))
.handler(this::handleReloadPlugin));
manager.command(parseSubcommand(builder, "watchplugin")
.argument(getArgument("plugin"))
.handler(this::handleWatchPlugin));
manager.command(parseSubcommand(builder, "unwatchplugin")
.argument(getArgument("plugin"))
.handler(this::handleUnwatchPlugin));
manager.command(parseSubcommand(builder, "plugininfo")
.argument(getArgument("plugin"))
.handler(this::handlePluginInfo));
manager.command(parseSubcommand(builder, "commandinfo")
.argument(getArgument("command"))
.handler(this::handleCommandInfo));
}
private void handleHelpCommand(CommandContext<C> context) {
C sender = context.getSender();
plugin.getMessagesResource().sendMessage(sender, "serverutils.help.header");
FormatBuilder builder = FormatBuilder.create(plugin.getMessagesResource().getMessage("serverutils.help.format"))
.orderedKeys("%command%", "%subcommand%", "%help%");
for (Command<C> command : plugin.getCommands()) {
List<CommandArgument<C, ?>> arguments = command.getArguments();
if (arguments.size() < 2) continue;
String commandName = arguments.get(0).getName();
StringBuilder sb = new StringBuilder();
for (int i = 1; i < arguments.size(); i++) {
CommandArgument<C, ?> argument = arguments.get(i);
sb.append(" ").append(argument.getName());
}
String subcommand = sb.toString();
String description = command.getComponents().get(1).getArgumentDescription().getDescription();
builder.add(commandName, subcommand, description);
}
builder.build().forEach(msg -> plugin.getMessagesResource().sendRawMessage(sender, msg));
plugin.getMessagesResource().sendMessage(sender, "serverutils.help.footer");
}
private void handleReload(CommandContext<C> context) {
C sender = context.getSender();
plugin.reload();
plugin.getMessagesResource().sendMessage(sender, "serverutils.success",
"%action%", "reload",
"%what%", "ServerUtils configurations");
}
private void handleLoadPlugin(CommandContext<C> context) {
C sender = context.getSender();
String jarFile = context.get("jarFile");
AbstractPluginManager<P> pluginManager = plugin.getPluginManager();
LoadResult<P> loadResult = pluginManager.loadPlugin(jarFile);
if (!loadResult.isSuccess()) {
loadResult.getResult().sendTo(sender, "load", jarFile);
return;
}
P loadedPlugin = loadResult.get();
Result result = pluginManager.enablePlugin(loadedPlugin);
result.sendTo(sender, "load", pluginManager.getPluginName(loadedPlugin));
}
private void handleUnloadPlugin(CommandContext<C> context) {
C sender = context.getSender();
String pluginName = context.get("plugin");
CloseableResult result = plugin.getPluginManager().unloadPlugin(pluginName);
result.getResult().sendTo(sender, "unload", pluginName);
result.tryClose();
}
private void handleReloadPlugin(CommandContext<C> context) {
C sender = context.getSender();
String pluginName = context.get("plugin");
Result result = plugin.getPluginManager().reloadPlugin(pluginName);
result.sendTo(sender, "reload", pluginName);
}
private void handleWatchPlugin(CommandContext<C> context) {
C sender = context.getSender();
String pluginName = context.get("plugin");
AbstractResult result = plugin.getPluginManager().watchPlugin(sender, pluginName);
result.sendTo(sender, "watch", pluginName);
}
private void handleUnwatchPlugin(CommandContext<C> context) {
C sender = context.getSender();
String pluginName = context.get("plugin");
AbstractResult result = plugin.getPluginManager().unwatchPlugin(pluginName);
result.sendTo(sender, "unwatch", pluginName);
}
private void handlePluginInfo(CommandContext<C> context) {
C sender = context.getSender();
String pluginName = context.get("plugin");
if (this.plugin.getPluginManager().getPlugin(pluginName) == null) {
Result.NOT_EXISTS.sendTo(sender, "fetch", pluginName);
return;
}
createInfo(sender, "plugininfo", pluginName, this::createPluginInfo);
}
protected abstract FormatBuilder createPluginInfo(
FormatBuilder builder,
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
String pluginName
);
private void handleCommandInfo(CommandContext<C> context) {
C sender = context.getSender();
String commandName = context.get("command");
if (!plugin.getPluginManager().getCommands().contains(commandName)) {
plugin.getMessagesResource().sendMessage(sender, "serverutils.commandinfo.not_exists");
return;
}
createInfo(sender, "commandinfo", commandName, this::createCommandInfo);
}
protected abstract FormatBuilder createCommandInfo(
FormatBuilder builder,
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
String commandName
);
private void createInfo(C sender, String command, String item, InfoCreator creator) {
String messagePrefix = "serverutils." + command;
String format = plugin.getMessagesResource().getMessage(messagePrefix + ".format");
String listFormatString = plugin.getMessagesResource().getMessage(messagePrefix + ".list_format");
String seperator = plugin.getMessagesResource().getMessage(messagePrefix + ".seperator");
String lastSeperator = plugin.getMessagesResource().getMessage(messagePrefix + ".last_seperator");
ListFormat<String> listFormat = str -> listFormatString.replace("%value%", str);
plugin.getMessagesResource().sendMessage(sender, messagePrefix + ".header");
creator.createInfo(
FormatBuilder
.create(format)
.orderedKeys("%key%", "%value%"),
listBuilderConsumer -> {
ListBuilder<String> builder = ListBuilder.<String>create()
.format(listFormat)
.seperator(seperator)
.lastSeperator(lastSeperator);
listBuilderConsumer.accept(builder);
return builder.toString();
},
item
).build().forEach(str -> plugin.getMessagesResource().sendRawMessage(sender, str));
plugin.getMessagesResource().sendMessage(sender, messagePrefix + ".footer");
}
private interface InfoCreator {
FormatBuilder createInfo(
FormatBuilder builder,
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
String item
);
}
}

View file

@ -1,33 +0,0 @@
package net.frankheijden.serverutils.common.commands;
import java.util.List;
import net.frankheijden.serverutils.common.config.Messenger;
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 {
/**
* Sends a plugin list to the receiver.
* @param sender The receiver of the plugin list.
* @param plugins The plugins to be sent.
* @param pluginFormat The format of the plugins to be sent.
* @param <T> The plugin type.
*/
public static <T> void sendPlugins(ServerCommandSender sender, List<T> plugins, ListFormat<T> pluginFormat) {
Messenger.sendMessage(sender, "serverutils.plugins.header");
String prefix = Messenger.getMessage("serverutils.plugins.prefix",
"%count%", String.valueOf(plugins.size()));
if (prefix == null) prefix = "";
sender.sendMessage(Messenger.color(prefix + ListBuilder.create(plugins)
.seperator(Messenger.getMessage("serverutils.plugins.seperator"))
.lastSeperator(Messenger.getMessage("serverutils.plugins.last_seperator"))
.format(pluginFormat)
.toString()));
Messenger.sendMessage(sender, "serverutils.plugins.footer");
}
}

View file

@ -0,0 +1,106 @@
package net.frankheijden.serverutils.common.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.flags.CommandFlag;
import cloud.commandframework.permission.Permission;
import java.util.HashMap;
import java.util.Map;
import net.frankheijden.serverutils.common.config.ServerUtilsConfig;
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
public abstract class ServerUtilsCommand<U extends ServerUtilsPlugin<P, T, C, S>,
P,
T,
C extends ServerCommandSender<S>,
S
> {
protected final U plugin;
protected final String commandName;
protected final ServerUtilsConfig commandConfig;
protected final Map<String, CommandArgument<C, ?>> arguments;
protected ServerUtilsCommand(
U plugin,
String commandName
) {
this.plugin = plugin;
this.commandName = commandName;
this.commandConfig = (ServerUtilsConfig) plugin.getCommandsResource().getConfig().get(commandName);
this.arguments = new HashMap<>();
}
/**
* Registers commands with the given CommandManager.
*/
public final void register(CommandManager<C> manager) {
register(
manager,
manager.commandBuilder(
applyPrefix(commandConfig.getString("main")),
commandConfig.getStringList("aliases").stream()
.map(this::applyPrefix)
.toArray(String[]::new)
).permission(commandConfig.getString("permission"))
);
}
protected abstract void register(CommandManager<C> manager, Command.Builder<C> builder);
public <A> void addArgument(CommandArgument<C, A> argument) {
this.arguments.put(argument.getName(), argument);
}
public CommandArgument<C, ?> getArgument(String name) {
return this.arguments.get(name).copy();
}
/**
* Parses a subcommand from the config.
*/
public Command.Builder<C> parseSubcommand(Command.Builder<C> builder, String subcommand) {
ServerUtilsConfig subcommandConfig = (ServerUtilsConfig) commandConfig.get("subcommands." + subcommand);
return builder
.literal(
subcommandConfig.getString("main"),
ArgumentDescription.of(subcommandConfig.getString("description")),
subcommandConfig.getStringList("aliases").toArray(new String[0])
)
.permission(subcommandConfig.getString("permission"));
}
/**
* Parses a flag from the config.
*/
public CommandFlag<Void> parseFlag(String flag) {
ServerUtilsConfig flagConfig = (ServerUtilsConfig) commandConfig.get("flags." + flag);
return CommandFlag.newBuilder(flagConfig.getString("main"))
.withAliases(flagConfig.getStringList("aliases").toArray(new String[0]))
.withPermission(Permission.of(flagConfig.getString("permission")))
.withDescription(ArgumentDescription.of(flagConfig.getString("description")))
.build();
}
private String applyPrefix(String str) {
final String prefixChar;
switch (plugin.getPlatform()) {
case BUKKIT:
prefixChar = "";
break;
case BUNGEE:
prefixChar = "b";
break;
case VELOCITY:
prefixChar = "v";
break;
default:
throw new IllegalArgumentException("Unknown platform: " + plugin.getPlatform().name());
}
return str.replace("%prefix%", prefixChar);
}
}

View file

@ -0,0 +1,15 @@
package net.frankheijden.serverutils.common.config;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
/**
* The Commands configuration.
*/
public class CommandsResource extends ServerUtilsResource {
private static final String COMMANDS_RESOURCE = "commands";
public CommandsResource(ServerUtilsPlugin<?, ?, ?, ?> plugin) {
super(plugin, COMMANDS_RESOURCE);
}
}

View file

@ -1,27 +0,0 @@
package net.frankheijden.serverutils.common.config;
/**
* The general common config class.
*/
public class Config extends ServerUtilsResource {
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;
}
}

View file

@ -0,0 +1,12 @@
package net.frankheijden.serverutils.common.config;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
public class ConfigResource extends ServerUtilsResource {
private static final String CONFIG_RESOURCE = "config";
public ConfigResource(ServerUtilsPlugin<?, ?, ?, ?> plugin) {
super(plugin, CONFIG_RESOURCE);
}
}

View file

@ -0,0 +1,154 @@
package net.frankheijden.serverutils.common.config;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class JsonConfig implements ServerUtilsConfig {
protected static final Gson gson = new Gson();
private final JsonObject config;
private File file = null;
public JsonConfig(File file) throws IOException {
this.config = gson.fromJson(Files.newBufferedReader(file.toPath()), JsonObject.class);
this.file = file;
}
public JsonConfig(JsonObject config) {
this.config = config;
}
public JsonObject getConfig() {
return config;
}
private JsonElement getJsonElement(String path) {
JsonElement result = config;
for (String memberName : path.split("\\.")) {
if (result == null) return null;
result = result.getAsJsonObject().get(memberName);
}
return result;
}
/**
* Parses a json element as a java object. Supported constructs are:
* - Primitives (bool, number, string).
* - Simple string lists.
*/
public static Object toObjectValue(JsonElement jsonElement) {
if (jsonElement == null) return null;
if (jsonElement.isJsonPrimitive()) {
JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonElement;
if (jsonPrimitive.isBoolean()) return jsonPrimitive.getAsBoolean();
else if (jsonPrimitive.isNumber()) return jsonPrimitive.getAsNumber();
else if (jsonPrimitive.isString()) return jsonPrimitive.getAsString();
else {
throw new IllegalStateException("Not a JSON Primitive: " + jsonPrimitive);
}
} else if (jsonElement.isJsonArray()) {
JsonArray jsonArray = (JsonArray) jsonElement;
List<String> stringList = new ArrayList<>(jsonArray.size());
for (JsonElement childJsonElement : jsonArray) {
stringList.add(toObjectValue(childJsonElement).toString());
}
return stringList;
}
return null;
}
@Override
public Object get(String path) {
JsonElement result = getJsonElement(path);
if (result != null && result.isJsonObject()) {
return new JsonConfig(result.getAsJsonObject());
}
return result;
}
@Override
public List<String> getStringList(String path) {
Object obj = get(path);
if (!(obj instanceof JsonArray)) throw new IllegalStateException("Not a JSON Array: " + obj);
JsonArray jsonArray = (JsonArray) obj;
List<String> list = new ArrayList<>(jsonArray.size());
for (JsonElement jsonElement : jsonArray) {
list.add(jsonElement.getAsString());
}
return list;
}
@Override
public Map<String, Object> getMap(String path) {
return gson.fromJson(getJsonElement(path), new TypeToken<Map<String, Object>>() {}.getType());
}
@Override
public void set(String path, Object value) {
int lastDotIndex = path.lastIndexOf('.');
String memberName = path;
JsonObject jsonObject = config.getAsJsonObject();
if (lastDotIndex != -1) {
memberName = path.substring(lastDotIndex + 1);
for (String pathSection : path.substring(0, lastDotIndex).split("\\.")) {
JsonElement childMember = jsonObject.get(pathSection);
if (childMember == null) {
childMember = new JsonObject();
}
jsonObject.add(pathSection, childMember);
jsonObject = childMember.getAsJsonObject();
}
}
jsonObject.add(memberName, gson.toJsonTree(value));
}
@Override
public String getString(String path) {
JsonElement element = getJsonElement(path);
if (element == null) return null;
return element.getAsString();
}
@Override
public boolean getBoolean(String path) {
JsonElement element = getJsonElement(path);
if (element == null) return false;
return element.getAsBoolean();
}
@Override
public Collection<? extends String> getKeys() {
return config.keySet();
}
@Override
public void save() throws IOException {
Files.write(
file.toPath(),
gson.toJson(config).getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING
);
}
}

View file

@ -0,0 +1,56 @@
package net.frankheijden.serverutils.common.config;
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
import net.frankheijden.serverutils.common.utils.StringUtils;
public class MessagesResource extends ServerUtilsResource {
public static final String MESSAGES_RESOURCE = "messages";
public MessagesResource(ServerUtilsPlugin<?, ?, ?, ?> plugin) {
super(plugin, MESSAGES_RESOURCE);
}
/**
* Retrieves a message from the config.
* @param path The yml path to the message.
* @param replacements The replacements to be taken into account.
* @return The config message with translated placeholders.
*/
public String getMessage(String path, String... replacements) {
String message = config.getString(path);
if (message != null) {
return StringUtils.apply(message, replacements);
} else {
plugin.getLogger().severe("Missing locale in messages.yml at path '" + path + "'!");
}
return null;
}
/**
* Sends a message to a player with translated placeholders.
* @param sender The receiver.
* @param msg The message to be sent.
* @param replacements The replacements to be taken into account.
*/
public void sendRawMessage(ServerCommandSender<?> sender, String msg, String... replacements) {
String message = StringUtils.apply(msg, replacements);
if (message != null) {
sender.sendMessage(plugin.getChatProvider().color(message));
}
}
/**
* Sends a message from the specified config path to a player with translated placeholders.
* @param sender The receiver.
* @param path The yml path to the message.
* @param replacements The replacements to be taken into account.
*/
public void sendMessage(ServerCommandSender<?> sender, String path, String... replacements) {
String message = getMessage(path, replacements);
if (message != null) {
sender.sendMessage(plugin.getChatProvider().color(message));
}
}
}

View file

@ -1,84 +0,0 @@
package net.frankheijden.serverutils.common.config;
import net.frankheijden.serverutils.common.ServerUtilsApp;
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 ServerUtilsResource {
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;
}
/**
* Retrieves a message from the config.
* @param path The yml path to the message.
* @param replacements The replacements to be taken into account.
* @return The config message with translated placeholders.
*/
public static String getMessage(String path, String... replacements) {
String message = instance.getConfig().getString(path);
if (message != null) {
return StringUtils.apply(message, replacements);
} else {
Messenger.plugin.getLogger().severe("Missing locale in messages.yml at path '" + path + "'!");
}
return null;
}
/**
* Sends a message to a player with translated placeholders.
* @param sender The receiver.
* @param msg The message to be sent.
* @param replacements The replacements to be taken into account.
*/
public static void sendRawMessage(ServerCommandSender sender, String msg, String... replacements) {
String message = StringUtils.apply(msg, replacements);
if (message != null) {
sender.sendMessage(Messenger.plugin.getChatProvider().color(message));
}
}
/**
* Sends a message from the specified config path to a player with translated placeholders.
* @param sender The receiver.
* @param path The yml path to the message.
* @param replacements The replacements to be taken into account.
*/
public static void sendMessage(ServerCommandSender sender, String path, String... replacements) {
String message = getMessage(path, replacements);
if (message != null) {
sender.sendMessage(Messenger.plugin.getChatProvider().color(message));
}
}
/**
* 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);
}
}

View file

@ -1,9 +1,18 @@
package net.frankheijden.serverutils.common.config;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
import net.frankheijden.serverutils.common.providers.ResourceProvider;
/**
* A wrap for a Configuration file.
@ -87,6 +96,9 @@ public interface ServerUtilsConfig {
if (value instanceof ServerUtilsConfig) {
addDefaults((ServerUtilsConfig) value, conf, newKey);
} else if (conf.get(newKey) == null) {
if (value instanceof JsonElement) {
value = JsonConfig.toObjectValue((JsonElement) value);
}
conf.set(newKey, value);
}
}
@ -132,4 +144,38 @@ public interface ServerUtilsConfig {
}
return conf;
}
/**
* Loads a resource from the jar file.
*/
static <U extends ServerUtilsPlugin<P, T, C, S>, P, T, C extends ServerCommandSender<S>, S> ServerUtilsConfig load(
U plugin,
Path path,
String resource
) {
ResourceProvider provider = plugin.getResourceProvider();
// Create the platform JsonConfig by merging the platformResource with the common resource
JsonConfig generalConfig = new JsonConfig(JsonConfig.gson.fromJson(
new InputStreamReader(provider.getRawResource(resource + ".json")),
JsonObject.class
));
String platformResource = plugin.getPlatform().name().toLowerCase(Locale.ENGLISH) + '-' + resource;
JsonConfig platformConfig = new JsonConfig(JsonConfig.gson.fromJson(
new InputStreamReader(provider.getRawResource(platformResource + ".json")),
JsonObject.class
));
addDefaults(platformConfig, generalConfig);
if (!Files.exists(path)) {
try {
Files.createFile(path);
} catch (IOException ex) {
ex.printStackTrace();
}
}
return init(generalConfig, provider.load(path.toFile()));
}
}

View file

@ -1,37 +1,30 @@
package net.frankheijden.serverutils.common.config;
import java.io.File;
import java.io.InputStream;
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 Configurations.
*/
public class ServerUtilsResource {
private static final ServerUtilsPlugin plugin = ServerUtilsApp.getPlugin();
protected final ServerUtilsPlugin<?, ?, ?, ?> plugin;
protected final ServerUtilsConfig config;
private final ServerUtilsConfig config;
/**
* Creates a new YamlResource instance.
* Loads the resource from the jar file.
* @param fileName The destination file.
* @param resource The resource from the jar file.
*/
public ServerUtilsResource(String fileName, String resource) {
ResourceProvider provider = plugin.getResourceProvider();
InputStream is = provider.getResource(resource);
File file = plugin.copyResourceIfNotExists(fileName, resource);
config = ServerUtilsConfig.init(provider.load(is), provider.load(file));
protected ServerUtilsResource(ServerUtilsPlugin<?, ?, ?, ?> plugin, ServerUtilsConfig config) {
this.plugin = plugin;
this.config = config;
}
protected ServerUtilsResource(ServerUtilsPlugin<?, ?, ?, ?> plugin, String resourceName) {
this(
plugin,
ServerUtilsConfig.load(
plugin,
plugin.getDataFolder().toPath().resolve(
resourceName + plugin.getResourceProvider().getResourceExtension()
),
resourceName
)
);
}
/**
* Retrieves the YamlConfig of this resource.
* @return The YamlConfig.
*/
public ServerUtilsConfig getConfig() {
return config;
}

View file

@ -9,5 +9,5 @@ public interface AbstractResult {
* @param action The action which let to the result.
* @param what An associated variable.
*/
void sendTo(ServerCommandSender sender, String action, String what);
void sendTo(ServerCommandSender<?> sender, String action, String what);
}

View file

@ -1,6 +1,6 @@
package net.frankheijden.serverutils.common.entities;
import net.frankheijden.serverutils.common.config.Messenger;
import net.frankheijden.serverutils.common.ServerUtilsApp;
/**
* An enum containing possible results.
@ -45,10 +45,13 @@ public enum Result implements AbstractResult {
* @param what An associated variable.
*/
@Override
public void sendTo(ServerCommandSender sender, String action, String what) {
Messenger.sendMessage(sender, "serverutils." + this.name().toLowerCase(),
public void sendTo(ServerCommandSender<?> sender, String action, String what) {
ServerUtilsApp.getPlugin().getMessagesResource().sendMessage(
sender,
"serverutils." + this.name().toLowerCase(),
"%action%", action,
"%what%", what,
"%arg%", arg);
"%arg%", arg
);
}
}

View file

@ -3,7 +3,7 @@ package net.frankheijden.serverutils.common.entities;
/**
* A basic wrapper for a CommandSender.
*/
public interface ServerCommandSender {
public interface ServerCommandSender<C> {
/**
* Sends a message to a CommandSender.
@ -23,4 +23,9 @@ public interface ServerCommandSender {
* @return Boolean true or false.
*/
boolean isPlayer();
/**
* Returns the server specific implementation source.
*/
C getSource();
}

View file

@ -1,8 +1,15 @@
package net.frankheijden.serverutils.common.entities;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.logging.Logger;
import net.frankheijden.serverutils.common.ServerUtilsApp;
import net.frankheijden.serverutils.common.config.CommandsResource;
import net.frankheijden.serverutils.common.config.ConfigResource;
import net.frankheijden.serverutils.common.config.MessagesResource;
import net.frankheijden.serverutils.common.managers.AbstractPluginManager;
import net.frankheijden.serverutils.common.managers.AbstractTaskManager;
import net.frankheijden.serverutils.common.managers.UpdateManager;
@ -10,17 +17,35 @@ import net.frankheijden.serverutils.common.providers.ChatProvider;
import net.frankheijden.serverutils.common.providers.ResourceProvider;
import net.frankheijden.serverutils.common.utils.FileUtils;
public abstract class ServerUtilsPlugin {
public abstract class ServerUtilsPlugin<P, T, C extends ServerCommandSender<S>, S> {
private final UpdateManager updateManager = new UpdateManager();
private CommandsResource commandsResource;
private ConfigResource configResource;
private MessagesResource messagesResource;
protected CommandManager<C> commandManager;
public abstract <T> AbstractPluginManager<T> getPluginManager();
public abstract Platform getPlatform();
public abstract <T> AbstractTaskManager<T> getTaskManager();
public CommandsResource getCommandsResource() {
return commandsResource;
}
public ConfigResource getConfigResource() {
return configResource;
}
public MessagesResource getMessagesResource() {
return messagesResource;
}
public abstract AbstractPluginManager<P> getPluginManager();
public abstract AbstractTaskManager<T> getTaskManager();
public abstract ResourceProvider getResourceProvider();
public abstract ChatProvider getChatProvider();
public abstract ChatProvider<C, S> getChatProvider();
public UpdateManager getUpdateManager() {
return updateManager;
@ -30,7 +55,9 @@ public abstract class ServerUtilsPlugin {
public abstract File getDataFolder();
public abstract <T> T fetchUpdaterData();
public Collection<Command<C>> getCommands() {
return commandManager.getCommands();
}
public void createDataFolderIfNotExists() {
if (getDataFolder().exists()) return;
@ -58,11 +85,48 @@ public abstract class ServerUtilsPlugin {
return file;
}
public void enable() {
protected abstract CommandManager<C> newCommandManager();
/**
* Enables the plugin.
*/
public final void enable() {
reload();
enablePlugin();
ServerUtilsApp.tryCheckForUpdates();
}
protected void enablePlugin() {
}
public void disable() {
public final void disable() {
disablePlugin();
getTaskManager().cancelAllTasks();
}
protected void disablePlugin() {
}
/**
* Reloads the plugin's configurations.
*/
public final void reload() {
this.commandsResource = new CommandsResource(this);
this.configResource = new ConfigResource(this);
this.messagesResource = new MessagesResource(this);
this.commandManager = newCommandManager();
reloadPlugin();
}
protected void reloadPlugin() {
}
public enum Platform {
BUKKIT,
BUNGEE,
VELOCITY,
}
}

View file

@ -1,6 +1,6 @@
package net.frankheijden.serverutils.common.entities;
import net.frankheijden.serverutils.common.config.Messenger;
import net.frankheijden.serverutils.common.ServerUtilsApp;
public enum WatchResult implements AbstractResult {
@ -17,8 +17,11 @@ public enum WatchResult implements AbstractResult {
* @param what An associated variable.
*/
@Override
public void sendTo(ServerCommandSender sender, String action, String what) {
Messenger.sendMessage(sender, "serverutils.watcher." + this.name().toLowerCase(),
"%what%", what);
public void sendTo(ServerCommandSender<?> sender, String action, String what) {
ServerUtilsApp.getPlugin().getMessagesResource().sendMessage(
sender,
"serverutils.watcher." + this.name().toLowerCase(),
"%what%", what
);
}
}

View file

@ -1,15 +1,26 @@
package net.frankheijden.serverutils.common.listeners;
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
import net.frankheijden.serverutils.common.tasks.UpdateCheckerTask;
public class ServerListener {
public abstract class ServerListener<
U extends ServerUtilsPlugin<P, T, C, S>,
P,
T,
C extends ServerCommandSender<S>,
S
> extends ServerUtilsListener<U, P, T, C, S> {
protected ServerListener(U plugin) {
super(plugin);
}
/**
* Handles the update check on the given ServerCommandSender.
* @param sender The sender which triggered the update.
*/
public static void handleUpdate(ServerCommandSender sender) {
protected void handleUpdate(C sender) {
if (sender.hasPermission("serverutils.notification.update")) {
UpdateCheckerTask.tryStart(sender, "login");
}

View file

@ -0,0 +1,19 @@
package net.frankheijden.serverutils.common.listeners;
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
public abstract class ServerUtilsListener<
U extends ServerUtilsPlugin<P, T, C, S>,
P,
T,
C extends ServerCommandSender<S>,
S
> {
protected final U plugin;
protected ServerUtilsListener(U plugin) {
this.plugin = plugin;
}
}

View file

@ -11,23 +11,23 @@ import net.frankheijden.serverutils.common.entities.WatchResult;
import net.frankheijden.serverutils.common.providers.PluginProvider;
import net.frankheijden.serverutils.common.tasks.PluginWatcherTask;
public abstract class AbstractPluginManager<T> extends PluginProvider<T> {
public interface AbstractPluginManager<P> extends PluginProvider<P> {
public abstract LoadResult<T> loadPlugin(String pluginFile);
LoadResult<P> loadPlugin(String pluginFile);
public abstract LoadResult<T> loadPlugin(File file);
LoadResult<P> loadPlugin(File file);
public abstract Result enablePlugin(T plugin);
Result enablePlugin(P plugin);
public abstract Result disablePlugin(T plugin);
Result disablePlugin(P plugin);
public abstract Result reloadPlugin(String pluginName);
Result reloadPlugin(String pluginName);
public abstract Result reloadPlugin(T plugin);
Result reloadPlugin(P plugin);
public abstract CloseableResult unloadPlugin(String pluginName);
CloseableResult unloadPlugin(String pluginName);
public abstract CloseableResult unloadPlugin(T plugin);
CloseableResult unloadPlugin(P plugin);
/**
* Starts watching the specified plugin for changes.
@ -35,7 +35,7 @@ public abstract class AbstractPluginManager<T> extends PluginProvider<T> {
* @param pluginName The plugin to watch.
* @return The result of the action.
*/
public AbstractResult watchPlugin(ServerCommandSender sender, String pluginName) {
default AbstractResult watchPlugin(ServerCommandSender<?> sender, String pluginName) {
if (getPlugin(pluginName) == null) return Result.NOT_EXISTS;
ServerUtilsApp.getPlugin().getTaskManager()
.runTaskAsynchronously(pluginName, new PluginWatcherTask(sender, pluginName));
@ -47,7 +47,7 @@ public abstract class AbstractPluginManager<T> extends PluginProvider<T> {
* @param pluginName The plugin to stop watching.
* @return The result of the action.
*/
public AbstractResult unwatchPlugin(String pluginName) {
default AbstractResult unwatchPlugin(String pluginName) {
if (ServerUtilsApp.getPlugin().getTaskManager().cancelTask(pluginName)) return WatchResult.STOPPED;
return WatchResult.NOT_WATCHING;
}

View file

@ -18,7 +18,7 @@ public abstract class AbstractTaskManager<T> {
*
* @param taskCloser The consumer which will close tasks.
*/
public AbstractTaskManager(Consumer<T> taskCloser) {
protected AbstractTaskManager(Consumer<T> taskCloser) {
this.taskCloser = taskCloser;
this.serverTasks = new ArrayList<>();
this.tasks = new HashMap<>();

View file

@ -5,25 +5,30 @@ import net.frankheijden.serverutils.common.entities.ServerCommandSender;
/**
* A basic chat provider class.
*/
public abstract class ChatProvider {
public interface ChatProvider<C extends ServerCommandSender<T>, T> {
/**
* Retrieves the console sender of a server instance.
* @return The console sender.
*/
public abstract ServerCommandSender getConsoleSender();
C getConsoleSender();
/**
* Converts the given source (specific to impl) to a ServerCommandSender.
*/
C get(T source);
/**
* Colorizes the given string.
* @param str The string to color.
* @return The colored string.
*/
public abstract String color(String str);
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);
void broadcast(String permission, String message);
}

View file

@ -8,30 +8,30 @@ import java.util.Set;
import java.util.stream.Collectors;
import net.frankheijden.serverutils.common.ServerUtilsApp;
public abstract class PluginProvider<T> {
public interface PluginProvider<P> {
public File getPluginsFolder() {
default File getPluginsFolder() {
return ServerUtilsApp.getPlugin().getDataFolder().getParentFile();
}
public abstract List<T> getPlugins();
List<P> getPlugins();
public abstract String getPluginName(T plugin);
String getPluginName(P plugin);
public abstract File getPluginFile(T plugin);
File getPluginFile(P plugin);
public abstract File getPluginFile(String pluginName);
File getPluginFile(String pluginName);
public abstract T getPlugin(String pluginName);
P getPlugin(String pluginName);
public abstract Set<String> getCommands();
Set<String> getCommands();
/**
* Retrieves a list of plugins, sorted by name.
* @return The list of plugins.
*/
public List<T> getPluginsSorted() {
List<T> plugins = getPlugins();
default List<P> getPluginsSorted() {
List<P> plugins = getPlugins();
plugins.sort(Comparator.comparing(this::getPluginName));
return plugins;
}
@ -40,7 +40,7 @@ public abstract class PluginProvider<T> {
* Retrieves a list of plugin names.
* @return The plugin names.
*/
public List<String> getPluginNames() {
default List<String> getPluginNames() {
return getPlugins().stream()
.map(this::getPluginName)
.collect(Collectors.toList());
@ -50,7 +50,7 @@ public abstract class PluginProvider<T> {
* Retrieves all files with a jar extension in the plugins/ folder and returns solely their name.
* @return An list of jar file names.
*/
public List<String> getPluginFileNames() {
default List<String> getPluginFileNames() {
return Arrays.stream(getPluginJars())
.map(File::getName)
.collect(Collectors.toList());
@ -60,7 +60,7 @@ public abstract class PluginProvider<T> {
* Retrieves all files with a jar extension in the plugins/ folder.
* @return An array of jar files.
*/
public File[] getPluginJars() {
default File[] getPluginJars() {
File parent = getPluginsFolder();
if (parent == null || !parent.exists()) return new File[0];
return parent.listFiles(f -> f.getName().endsWith(".jar"));

View file

@ -6,9 +6,15 @@ import net.frankheijden.serverutils.common.config.ServerUtilsConfig;
public interface ResourceProvider {
InputStream getResource(String resource);
default InputStream getResource(String resource) {
return getRawResource(resource + getResourceExtension());
}
InputStream getRawResource(String resource);
ServerUtilsConfig load(InputStream is);
ServerUtilsConfig load(File file);
String getResourceExtension();
}

View file

@ -10,8 +10,6 @@ import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.logging.Level;
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.config.ServerUtilsConfig;
import net.frankheijden.serverutils.common.entities.LoadResult;
import net.frankheijden.serverutils.common.entities.Result;
@ -26,10 +24,11 @@ import net.frankheijden.serverutilsupdater.common.Updater;
public class UpdateCheckerTask implements Runnable {
private static final ServerUtilsPlugin plugin = ServerUtilsApp.getPlugin();
private static final ServerUtilsConfig config = Config.getInstance().getConfig();
@SuppressWarnings("unchecked")
private static final ServerUtilsPlugin<Object, ?, ?, ?> plugin = ServerUtilsApp.getPlugin();
private static final ServerUtilsConfig config = plugin.getConfigResource().getConfig();
private final ServerCommandSender sender;
private final ServerCommandSender<?> sender;
private final boolean download;
private final boolean install;
@ -53,7 +52,7 @@ public class UpdateCheckerTask implements Runnable {
private static final String UPDATER_ENABLE_ERROR = "Failed to enable ServerUtilsUpdater: {0}";
private static final String UP_TO_DATE = "We are up-to-date!";
private UpdateCheckerTask(ServerCommandSender sender, boolean download, boolean install) {
private UpdateCheckerTask(ServerCommandSender<?> sender, boolean download, boolean install) {
this.sender = sender;
this.download = download;
this.install = install;
@ -63,7 +62,7 @@ public class UpdateCheckerTask implements Runnable {
* Checks for updates if enabled per config for the specific action.
* Action must be 'login' or 'boot'.
*/
public static void tryStart(ServerCommandSender sender, String action) {
public static void tryStart(ServerCommandSender<?> sender, String action) {
if (config.getBoolean("settings.check-updates-" + action)) {
start(sender, action);
}
@ -73,7 +72,7 @@ public class UpdateCheckerTask implements Runnable {
* Checks for updates and downloads/installs if configured.
* Action must be 'login' or 'boot'.
*/
public static void start(ServerCommandSender sender, String action) {
public static void start(ServerCommandSender<?> sender, String action) {
plugin.getTaskManager().runTaskAsynchronously(new UpdateCheckerTask(
sender,
config.getBoolean("settings.download-updates-" + action),
@ -113,7 +112,7 @@ public class UpdateCheckerTask implements Runnable {
GitHubAsset pluginAsset = GitHubAsset.from(pluginJson);
if (!download || pluginAsset == null) {
if (sender.isPlayer()) {
Messenger.sendMessage(sender, "serverutils.update.available",
plugin.getMessagesResource().sendMessage(sender, "serverutils.update.available",
"%old%", ServerUtilsApp.VERSION,
"%new%", githubVersion,
"%info%", body);
@ -123,7 +122,7 @@ public class UpdateCheckerTask implements Runnable {
plugin.getLogger().log(Level.INFO, DOWNLOAD_START, pluginAsset.getDownloadUrl());
if (sender.isPlayer()) {
Messenger.sendMessage(sender, "serverutils.update.downloading",
plugin.getMessagesResource().sendMessage(sender, "serverutils.update.downloading",
"%old%", ServerUtilsApp.VERSION,
"%new%", githubVersion,
"%info%", body);
@ -228,7 +227,7 @@ public class UpdateCheckerTask implements Runnable {
}
private void deletePlugin() {
plugin.getPluginManager().getPluginFile((Object) ServerUtilsApp.getPlatformPlugin()).delete();
plugin.getPluginManager().getPluginFile(ServerUtilsApp.getPlatformPlugin()).delete();
}
private void tryReloadPlugin(File pluginFile, File updaterFile) {
@ -254,7 +253,7 @@ public class UpdateCheckerTask implements Runnable {
private void broadcastDownloadStatus(String githubVersion, boolean isError) {
final String path = "serverutils.update." + (isError ? "failed" : "success");
String message = Messenger.getMessage(path, "%new%", githubVersion);
String message = plugin.getMessagesResource().getMessage(path, "%new%", githubVersion);
plugin.getChatProvider().broadcast("serverutils.notification.update", message);
}
}

View file

@ -2,21 +2,17 @@ package net.frankheijden.serverutils.common.utils;
import java.util.ArrayList;
import java.util.List;
import net.frankheijden.serverutils.common.config.Messenger;
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
public class FormatBuilder {
private final String format;
private final List<String[]> valueList;
private String[] orderedKeys;
private boolean alwaysSend;
private FormatBuilder(String format) {
this.format = format;
this.valueList = new ArrayList<>();
this.orderedKeys = new String[0];
this.alwaysSend = false;
}
public static FormatBuilder create(String format) {
@ -33,25 +29,27 @@ public class FormatBuilder {
return this;
}
public FormatBuilder alwaysSend(boolean alwaysSend) {
this.alwaysSend = alwaysSend;
return this;
/**
* Builds the current FormatBuilder instance into a list of strings.
*/
public List<String> build() {
List<String> strings = new ArrayList<>();
for (String[] values : valueList) {
String str = format;
for (int i = 0; i < Math.min(values.length, orderedKeys.length); i++) {
String value = values[i];
if (value == null || value.isEmpty()) break;
str = str.replace(orderedKeys[i], value);
}
strings.add(str);
}
return strings;
}
/**
* Builds the format and sends it to the CommandSender.
* @param sender The receiver of the list.
*/
public void sendTo(ServerCommandSender sender) {
valueList.forEach(values -> {
int length = Math.min(values.length, orderedKeys.length);
String message = format;
for (int i = 0; i < length; i++) {
String value = values[i];
if ((value == null || value.isEmpty()) && !alwaysSend) return;
message = message.replace(orderedKeys[i], String.valueOf(value));
}
Messenger.sendRawMessage(sender, message);
});
@Override
public String toString() {
return build().toString();
}
}

View file

@ -12,21 +12,17 @@ public class ListBuilder<T> {
private String seperator;
private String lastSeperator;
private ListBuilder(List<T> list) {
this.list = list;
private ListBuilder() {
this.list = new ArrayList<>();
}
public static <T> ListBuilder<T> create(List<T> list) {
return new ListBuilder<>(list);
}
public static <T> ListBuilder<T> create(Collection<T> list) {
return new ListBuilder<>(new ArrayList<>(list));
public static <T> ListBuilder<T> create(Collection<? extends T> list) {
return new ListBuilder<T>().addAll(list);
}
@SafeVarargs
public static <T> ListBuilder<T> create(T... elements) {
return new ListBuilder<>(Arrays.asList(elements));
return new ListBuilder<T>().addAll(Arrays.asList(elements));
}
/**
@ -56,6 +52,11 @@ public class ListBuilder<T> {
return this;
}
public ListBuilder<T> addAll(Collection<? extends T> collection) {
this.list.addAll(collection);
return this;
}
@Override
public String toString() {
if (list.size() == 1) {

View file

@ -0,0 +1,88 @@
{
"plugins": {
"main": "%prefix%plugins",
"aliases": ["%prefix%pl"],
"permission": "serverutils.plugins",
"display-in-help": true,
"flags": {
"version": {
"main": "version",
"aliases": ["v"],
"permission": "serverutils.plugins.version",
"description": "Displays the plugin versions.",
"display-in-help": true
}
}
},
"serverutils": {
"main": "%prefix%serverutils",
"aliases": ["%prefix%su"],
"permission": "serverutils.help",
"display-in-help": false,
"subcommands": {
"help": {
"main": "help",
"aliases": [],
"permission": "serverutils.help",
"description": "Displays the help page.",
"display-in-help": true
},
"reload": {
"main": "reload",
"aliases": [],
"permission": "serverutils.reload",
"description": "Reloads the ServerUtils plugin.",
"display-in-help": true
},
"loadplugin": {
"main": "loadplugin",
"aliases": ["lp"],
"permission": "serverutils.loadplugin",
"description": "Loads the specified jar file as a plugin.",
"display-in-help": true
},
"unloadplugin": {
"main": "unloadplugin",
"aliases": ["up"],
"permission": "serverutils.unloadplugin",
"description": "Disables and unloads the specified plugin.",
"display-in-help": true
},
"reloadplugin": {
"main": "reloadplugin",
"aliases": ["rp"],
"permission": "serverutils.reloadplugin",
"description": "Reloads the specified plugin.",
"display-in-help": true
},
"watchplugin": {
"main": "watchplugin",
"aliases": ["wp"],
"permission": "serverutils.watchplugin",
"description": "Watches the specified plugin for changes.",
"display-in-help": true
},
"unwatchplugin": {
"main": "unwatchplugin",
"aliases": ["uwp"],
"permission": "serverutils.watchplugin",
"description": "Stops watching the specified plugin for changes.",
"display-in-help": true
},
"plugininfo": {
"main": "plugininfo",
"aliases": ["pi"],
"permission": "serverutils.plugininfo",
"description": "Shows information about the specified plugin.",
"display-in-help": true
},
"commandinfo": {
"main": "commandinfo",
"aliases": ["ci"],
"permission": "serverutils.commandinfo",
"description": "Shows information about the specified command.",
"display-in-help": true
}
}
}
}

View file

@ -0,0 +1,11 @@
{
"settings": {
"disable-plugins-command": false,
"check-updates-boot": true,
"check-updates-login": false,
"download-updates-boot": false,
"download-updates-login": false,
"install-updates-boot": false,
"install-updates-login": false
}
}

View file

@ -0,0 +1,60 @@
{
"serverutils": {
"success": "&3Successfully %action%ed &b%what%&3!",
"warning": "&3Successfully %action%ed &b%what%&3, but with warnings.",
"error": "&cAn error occurred while %action%ing &4%what%&c, please check the console!",
"not_exists": "&cAn error occurred while %action%ing &4%what%&c, plugin does not exist!",
"not_enabled": "&cAn error occurred while %action%ing &4%what%&c, plugin is not enabled!",
"already_loaded": "&cAn error occurred while %action%ing &4%what%&c, plugin is already loaded!",
"already_enabled": "&cAn error occurred while %action%ing &4%what%&c, plugin is already enabled!",
"already_disabled": "&cAn error occurred while %action%ing &4%what%&c, plugin is already disabled!",
"file_deleted": "&cAccessing the jar file while %action%ing &4%what%&c went wrong, plugin has been deleted!",
"invalid_description": "&cAn error occurred while %action%ing &4%what%&c, plugin doesn't have a valid description!",
"invalid_plugin": "&cAn error occurred while %action%ing &4%what%&c, plugin is invalid!",
"unknown_dependency": "&cAn error occurred while %action%ing &4%what%&c, plugin has a dependeny which is not loaded: &4%arg%",
"watcher": {
"start": "&3Started watching &b%what%&3!",
"change": "&3Change detected for plugin &b%what%&3, reloading now...",
"stopped": "&3Stopped watching &b%what%&3!",
"not_watching": "&cWe aren't watching that plugin!"
},
"update": {
"available": "&8&m------------=&r&8[ &b&lServerUtils Update&r &8]&m=--------------\n &3Current version: &b%old%\n &3New version: &b%new%\n &3Release info: &b%info%\n&8&m-------------------------------------------------",
"downloading": "&8&m------------=&r&8[ &b&lServerUtils Update&r &8]&m=--------------\n &3A new version of ServerUtils will be downloaded and installed after a restart!\n &3Current version: &b%old%\n &3New version: &b%new%\n &3Release info: &b%info%\n&8&m-------------------------------------------------",
"download_failed": "&cFailed to download version %new% of ServerUtils. Please update manually.",
"download_success": "&3ServerUtils has been downloaded and will be installed on the next restart."
},
"help": {
"header": "&8&m-------------=&r&8[ &b&lServerUtils Help&r &8]&m=---------------",
"format": "&8/&3%command%&b%subcommand% &f(&7%help%&f)",
"footer": "&8&m-------------------------------------------------"
},
"plugins": {
"header": "&8&m------------=&r&8[ &b&lServerUtils Plugins&r &8]&m=-------------",
"prefix": " &3Plugins &8(&a%count%&8)&b: ",
"format": "&3%plugin%",
"format_disabled": "&c%plugin%",
"seperator": "&b, ",
"last_seperator": " &band ",
"version": " &8(&a%version%&8)",
"footer": "&8&m-------------------------------------------------"
},
"plugininfo": {
"header": "&8&m-----------=&r&8[ &b&lServerUtils PluginInfo&r &8]&m=-----------",
"format": " &3%key%&8: &b%value%",
"list_format": "&b%value%",
"seperator": "&8, ",
"last_seperator": " &8and ",
"footer": "&8&m-------------------------------------------------"
},
"commandinfo": {
"header": "&8&m-----------=&r&8[ &b&lServerUtils CommandInfo&r &8]&m=----------",
"format": " &3%key%&8: &b%value%",
"list_format": "&b%value%",
"seperator": "&8, ",
"last_seperator": " &8and ",
"footer": "&8&m-------------------------------------------------",
"not_exists": "&cThat command is not a valid registered command."
}
}
}