Add "depending plugin" warning
This commit is contained in:
parent
d1aa18b30b
commit
1b4997869d
17 changed files with 257 additions and 43 deletions
|
|
@ -4,7 +4,7 @@ version = rootProject.version
|
|||
archivesBaseName = rootProject.name + '-Bukkit'
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.FrankHeijden.cloud:cloud-paper:fea4605277'
|
||||
implementation "com.github.FrankHeijden.cloud:cloud-paper:${rootProject.cloudVersion}"
|
||||
implementation 'org.bstats:bstats-bukkit:2.2.1'
|
||||
implementation project(":Common")
|
||||
compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import net.frankheijden.serverutils.bukkit.reflection.RDedicatedServer;
|
|||
import net.frankheijden.serverutils.bukkit.utils.ReloadHandler;
|
||||
import net.frankheijden.serverutils.bukkit.utils.VersionReloadHandler;
|
||||
import net.frankheijden.serverutils.common.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.common.commands.arguments.PluginsArgument;
|
||||
import net.frankheijden.serverutils.common.entities.results.PluginResults;
|
||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ForwardFilter;
|
||||
|
|
@ -76,7 +77,11 @@ public class BukkitCommandServerUtils extends CommandServerUtils<BukkitPlugin, P
|
|||
.argument(getArgument("plugins"))
|
||||
.handler(this::handleEnablePlugin));
|
||||
manager.command(buildSubcommand(builder, "disableplugin")
|
||||
.argument(getArgument("plugins"))
|
||||
.argument(new PluginsArgument<>(
|
||||
true,
|
||||
"plugins",
|
||||
new PluginsArgument.PluginsParser<>(plugin, arrayCreator, getRawPath("disableplugin"))
|
||||
))
|
||||
.handler(this::handleDisablePlugin));
|
||||
manager.command(buildSubcommand(builder, "reloadconfig")
|
||||
.argument(getArgument("config"))
|
||||
|
|
@ -95,6 +100,10 @@ public class BukkitCommandServerUtils extends CommandServerUtils<BukkitPlugin, P
|
|||
BukkitCommandSender sender = context.getSender();
|
||||
List<Plugin> plugins = Arrays.asList(context.get("plugins"));
|
||||
|
||||
if (checkDependingPlugins(context, sender, plugins, "disableplugin")) {
|
||||
return;
|
||||
}
|
||||
|
||||
PluginResults<Plugin> result = plugin.getPluginManager().disablePlugins(plugins);
|
||||
result.sendTo(sender, "disabl");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,16 +131,17 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin, BukkitPlu
|
|||
RSimplePluginManager.getPlugins(Bukkit.getPluginManager()).remove(plugin);
|
||||
RSimplePluginManager.removeLookupName(Bukkit.getPluginManager(), pluginId);
|
||||
|
||||
ClassLoader loader = RJavaPlugin.getClassLoader(plugin);
|
||||
RPluginClassLoader.clearClassLoader(loader);
|
||||
addIfInstance(closeables, (Closeable) () -> {
|
||||
Map<String, Class<?>> classes = RPluginClassLoader.getClasses(loader);
|
||||
getPluginLoader(getPluginFile(plugin)).ifPresent(pluginLoader -> {
|
||||
RJavaPluginLoader.removeClasses(pluginLoader, classes.keySet());
|
||||
});
|
||||
});
|
||||
addIfInstance(closeables, loader);
|
||||
addIfInstance(closeables, RJavaPlugin.clearJavaPlugin(plugin));
|
||||
ClassLoader classLoader = plugin.getClass().getClassLoader();
|
||||
RPluginClassLoader.clearClassLoader(classLoader);
|
||||
|
||||
PluginLoader loader = RPluginClassLoader.getLoader(classLoader);
|
||||
Map<String, Class<?>> classes = RPluginClassLoader.getClasses(classLoader);
|
||||
RJavaPluginLoader.removeClasses(loader, classes.keySet());
|
||||
|
||||
RJavaPlugin.clearJavaPlugin(plugin);
|
||||
|
||||
addIfInstance(closeables, RPluginClassLoader.getLibraryLoader(classLoader));
|
||||
addIfInstance(closeables, classLoader);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return unloadResults.addResult(pluginId, Result.ERROR);
|
||||
|
|
|
|||
|
|
@ -29,10 +29,6 @@ public class RJavaPlugin {
|
|||
public static Closeable clearJavaPlugin(Object instance) {
|
||||
reflection.set(instance, "loader", null);
|
||||
reflection.set(instance, "classLoader", null);
|
||||
Class<?> clazz = reflection.invoke(instance, "getClass");
|
||||
if (clazz != null && clazz.getClassLoader() instanceof Closeable) {
|
||||
return (Closeable) clazz.getClassLoader();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package net.frankheijden.serverutils.bukkit.reflection;
|
||||
|
||||
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
||||
import dev.frankheijden.minecraftreflection.exceptions.MinecraftReflectionException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import dev.frankheijden.minecraftreflection.exceptions.MinecraftReflectionException;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
|
||||
public class RJavaPluginLoader {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package net.frankheijden.serverutils.bukkit.reflection;
|
||||
|
||||
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
||||
import dev.frankheijden.minecraftreflection.MinecraftReflectionVersion;
|
||||
import java.util.Map;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
|
||||
public class RPluginClassLoader {
|
||||
|
||||
|
|
@ -23,12 +25,23 @@ public class RPluginClassLoader {
|
|||
}
|
||||
}
|
||||
|
||||
public static PluginLoader getLoader(ClassLoader loader) {
|
||||
if (loader == null) return null;
|
||||
return reflection.get(loader, "loader");
|
||||
}
|
||||
|
||||
public static ClassLoader getLibraryLoader(ClassLoader loader) {
|
||||
if (loader == null && MinecraftReflectionVersion.MINOR <= 16) return null;
|
||||
return reflection.get(loader, "libraryLoader");
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the plugin fields from the specified PluginClassLoader.
|
||||
* @param pluginLoader The plugin loader instance.
|
||||
*/
|
||||
public static void clearPluginClassLoader(Object pluginLoader) {
|
||||
if (pluginLoader == null) return;
|
||||
|
||||
reflection.set(pluginLoader, "plugin", null);
|
||||
reflection.set(pluginLoader, "pluginInit", null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,16 @@
|
|||
],
|
||||
"permission": "serverutils.disableplugin",
|
||||
"description": "Disables the specified plugin(s).",
|
||||
"display-in-help": true
|
||||
"display-in-help": true,
|
||||
"flags": {
|
||||
"force": {
|
||||
"main": "force",
|
||||
"aliases": ["f"],
|
||||
"permission": "serverutils.disableplugin",
|
||||
"description": "Force disables the specified plugin(s).",
|
||||
"display-in-help": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"reloadconfig": {
|
||||
"main": "reloadconfig",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.FrankHeijden.cloud:cloud-bungee:fea4605277'
|
||||
implementation "com.github.FrankHeijden.cloud:cloud-bungee:${rootProject.cloudVersion}"
|
||||
implementation 'org.bstats:bstats-bungeecord:2.2.1'
|
||||
implementation project(":Common")
|
||||
compileOnly 'net.md-5:bungeecord-api:1.17-R0.1-SNAPSHOT'
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import cloud.commandframework.context.CommandContext;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
|
@ -14,6 +15,7 @@ import java.util.function.IntFunction;
|
|||
import net.frankheijden.serverutils.common.commands.arguments.JarFilesArgument;
|
||||
import net.frankheijden.serverutils.common.commands.arguments.PluginArgument;
|
||||
import net.frankheijden.serverutils.common.commands.arguments.PluginsArgument;
|
||||
import net.frankheijden.serverutils.common.config.MessagesResource;
|
||||
import net.frankheijden.serverutils.common.config.ServerUtilsConfig;
|
||||
import net.frankheijden.serverutils.common.entities.results.AbstractResult;
|
||||
import net.frankheijden.serverutils.common.entities.results.CloseablePluginResults;
|
||||
|
|
@ -30,7 +32,7 @@ import net.frankheijden.serverutils.common.utils.ListFormat;
|
|||
public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?, ?>, P, C extends ServerCommandSender<?>>
|
||||
extends ServerUtilsCommand<U, C> {
|
||||
|
||||
private final IntFunction<P[]> arrayCreator;
|
||||
protected final IntFunction<P[]> arrayCreator;
|
||||
|
||||
protected CommandServerUtils(U plugin, IntFunction<P[]> arrayCreator) {
|
||||
super(plugin, "serverutils");
|
||||
|
|
@ -40,7 +42,7 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
|||
@Override
|
||||
public void register(CommandManager<C> manager, Command.Builder<C> builder) {
|
||||
addArgument(new JarFilesArgument<>(true, "jarFiles", plugin));
|
||||
addArgument(new PluginsArgument<>(true, "plugins", plugin, arrayCreator));
|
||||
addArgument(new PluginsArgument<>(true, "plugins", new PluginsArgument.PluginsParser<>(plugin, arrayCreator)));
|
||||
addArgument(new PluginArgument<>(true, "plugin", plugin));
|
||||
addArgument(CommandArgument.<C, String>ofType(String.class, "command")
|
||||
.manager(manager)
|
||||
|
|
@ -57,10 +59,18 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
|||
.argument(getArgument("jarFiles"))
|
||||
.handler(this::handleLoadPlugin));
|
||||
manager.command(buildSubcommand(builder, "unloadplugin")
|
||||
.argument(getArgument("plugins"))
|
||||
.argument(new PluginsArgument<>(
|
||||
true,
|
||||
"plugins",
|
||||
new PluginsArgument.PluginsParser<>(plugin, arrayCreator, getRawPath("unloadplugin"))
|
||||
))
|
||||
.handler(this::handleUnloadPlugin));
|
||||
manager.command(buildSubcommand(builder, "reloadplugin")
|
||||
.argument(getArgument("plugins"))
|
||||
.argument(new PluginsArgument<>(
|
||||
true,
|
||||
"plugins",
|
||||
new PluginsArgument.PluginsParser<>(plugin, arrayCreator, getRawPath("reloadplugin"))
|
||||
))
|
||||
.handler(this::handleReloadPlugin));
|
||||
manager.command(buildSubcommand(builder, "watchplugin")
|
||||
.argument(getArgument("plugin"))
|
||||
|
|
@ -170,6 +180,10 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
|||
C sender = context.getSender();
|
||||
List<P> plugins = Arrays.asList(context.get("plugins"));
|
||||
|
||||
if (checkDependingPlugins(context, sender, plugins, "unloadplugin")) {
|
||||
return;
|
||||
}
|
||||
|
||||
PluginResults<P> disableResults = plugin.getPluginManager().disablePlugins(plugins);
|
||||
for (PluginResult<P> disableResult : disableResults.getResults()) {
|
||||
if (!disableResult.isSuccess() && disableResult.getResult() != Result.ALREADY_DISABLED) {
|
||||
|
|
@ -187,10 +201,59 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
|||
C sender = context.getSender();
|
||||
List<P> plugins = Arrays.asList(context.get("plugins"));
|
||||
|
||||
if (checkDependingPlugins(context, sender, plugins, "reloadplugin")) {
|
||||
return;
|
||||
}
|
||||
|
||||
PluginResults<P> reloadResult = plugin.getPluginManager().reloadPlugins(plugins);
|
||||
reloadResult.sendTo(sender, "reload");
|
||||
}
|
||||
|
||||
protected boolean checkDependingPlugins(CommandContext<C> context, C sender, List<P> plugins, String subcommand) {
|
||||
if (context.flags().contains("force")) return false;
|
||||
|
||||
AbstractPluginManager<P, ?> pluginManager = plugin.getPluginManager();
|
||||
MessagesResource messages = plugin.getMessagesResource();
|
||||
|
||||
boolean hasDependingPlugins = false;
|
||||
for (P plugin : plugins) {
|
||||
String pluginId = pluginManager.getPluginId(plugin);
|
||||
|
||||
List<P> dependingPlugins = pluginManager.getPluginsDependingOn(pluginId);
|
||||
if (!dependingPlugins.isEmpty()) {
|
||||
String prefixString = messages.getMessage(
|
||||
"serverutils.depending_plugins.prefix",
|
||||
"%what%", pluginId
|
||||
);
|
||||
|
||||
String dependingPluginsString = ListBuilder.create(dependingPlugins)
|
||||
.format(p -> messages.getMessage(
|
||||
"serverutils.depending_plugins.format",
|
||||
"%plugin%", pluginManager.getPluginId(p)
|
||||
))
|
||||
.seperator(messages.getMessage("serverutils.depending_plugins.separator"))
|
||||
.lastSeperator(messages.getMessage("serverutils.depending_plugins.last_separator"))
|
||||
.toString();
|
||||
messages.sendRawMessage(sender, prefixString + dependingPluginsString);
|
||||
hasDependingPlugins = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDependingPlugins) {
|
||||
String flagPath = getRawPath(subcommand) + ".flags.force";
|
||||
String forceFlag = plugin.getCommandsResource().getAllFlagAliases(flagPath).stream()
|
||||
.min(Comparator.comparingInt(String::length))
|
||||
.orElse("-f");
|
||||
|
||||
messages.sendMessage(sender,
|
||||
"serverutils.depending_plugins.override",
|
||||
"%command%", context.getRawInputJoined() + " " + forceFlag
|
||||
);
|
||||
}
|
||||
|
||||
return hasDependingPlugins;
|
||||
}
|
||||
|
||||
private void handleWatchPlugin(CommandContext<C> context) {
|
||||
C sender = context.getSender();
|
||||
P pluginArg = context.get("plugin");
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import cloud.commandframework.arguments.CommandArgument;
|
|||
import cloud.commandframework.arguments.flags.CommandFlag;
|
||||
import cloud.commandframework.permission.CommandPermission;
|
||||
import cloud.commandframework.permission.Permission;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.frankheijden.serverutils.common.config.ServerUtilsConfig;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
|
|
@ -58,9 +60,14 @@ public abstract class ServerUtilsCommand<U extends ServerUtilsPlugin<?, ?, C, ?,
|
|||
*/
|
||||
public Command.Builder<C> buildSubcommand(Command.Builder<C> builder, String subcommandName) {
|
||||
CommandElement subcommand = parseSubcommand(subcommandName);
|
||||
return builder
|
||||
|
||||
builder = builder
|
||||
.literal(subcommand.getMain(), subcommand.getDescription(), subcommand.getAliases())
|
||||
.permission(subcommand.getPermission());
|
||||
for (CommandElement flagElement : subcommand.getFlags()) {
|
||||
builder = builder.flag(createFlag(flagElement));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -76,7 +83,16 @@ public abstract class ServerUtilsCommand<U extends ServerUtilsPlugin<?, ?, C, ?,
|
|||
.map(this::applyPrefix)
|
||||
.toArray(String[]::new);
|
||||
|
||||
return new CommandElement(main, description, permission, displayInHelp, aliases);
|
||||
List<CommandElement> flags = new ArrayList<>();
|
||||
Object flagsObject = elementConfig.get("flags");
|
||||
if (flagsObject instanceof ServerUtilsConfig) {
|
||||
ServerUtilsConfig flagsConfig = ((ServerUtilsConfig) flagsObject);
|
||||
for (String flagName : flagsConfig.getKeys()) {
|
||||
flags.add(parseElement((ServerUtilsConfig) flagsConfig.get(flagName)));
|
||||
}
|
||||
}
|
||||
|
||||
return new CommandElement(main, description, permission, displayInHelp, aliases, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,15 +102,25 @@ public abstract class ServerUtilsCommand<U extends ServerUtilsPlugin<?, ?, C, ?,
|
|||
return parseElement((ServerUtilsConfig) commandConfig.get("subcommands." + subcommandName));
|
||||
}
|
||||
|
||||
public String getRawPath(String subcommandName) {
|
||||
return "commands." + commandName + ".subcommands." + subcommandName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a flag from the config.
|
||||
*/
|
||||
public CommandFlag<Void> parseFlag(String flagName) {
|
||||
CommandElement flag = parseElement((ServerUtilsConfig) commandConfig.get("flags." + flagName));
|
||||
return CommandFlag.newBuilder(flag.getMain())
|
||||
.withAliases(flag.getAliases())
|
||||
.withPermission(flag.getPermission())
|
||||
.withDescription(flag.getDescription())
|
||||
return createFlag(parseElement((ServerUtilsConfig) commandConfig.get("flags." + flagName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a flag from a CommandElement.
|
||||
*/
|
||||
public CommandFlag<Void> createFlag(CommandElement flagElement) {
|
||||
return CommandFlag.newBuilder(flagElement.getMain())
|
||||
.withAliases(flagElement.getAliases())
|
||||
.withPermission(flagElement.getPermission())
|
||||
.withDescription(flagElement.getDescription())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -124,19 +150,22 @@ public abstract class ServerUtilsCommand<U extends ServerUtilsPlugin<?, ?, C, ?,
|
|||
private final CommandPermission permission;
|
||||
private final boolean displayInHelp;
|
||||
private final String[] aliases;
|
||||
private final List<CommandElement> flags;
|
||||
|
||||
public CommandElement(
|
||||
String main,
|
||||
ArgumentDescription description,
|
||||
CommandPermission permission,
|
||||
boolean displayInHelp,
|
||||
String... aliases
|
||||
String[] aliases,
|
||||
List<CommandElement> flags
|
||||
) {
|
||||
this.main = main;
|
||||
this.description = description;
|
||||
this.permission = permission;
|
||||
this.displayInHelp = displayInHelp;
|
||||
this.aliases = aliases;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public String getMain() {
|
||||
|
|
@ -158,5 +187,9 @@ public abstract class ServerUtilsCommand<U extends ServerUtilsPlugin<?, ?, C, ?,
|
|||
public String[] getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public List<CommandElement> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
|
|||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.function.IntFunction;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
|
|
@ -21,13 +23,12 @@ public class PluginsArgument<C extends ServerCommandSender<?>, P> extends Comman
|
|||
public PluginsArgument(
|
||||
boolean required,
|
||||
String name,
|
||||
ServerUtilsPlugin<P, ?, C, ?, ?> plugin,
|
||||
IntFunction<P[]> arrayCreator
|
||||
PluginsParser<C, P> parser
|
||||
) {
|
||||
super(
|
||||
required,
|
||||
name,
|
||||
new PluginsParser<>(plugin, arrayCreator),
|
||||
parser,
|
||||
"",
|
||||
new TypeToken<P[]>() {},
|
||||
null
|
||||
|
|
@ -38,10 +39,23 @@ public class PluginsArgument<C extends ServerCommandSender<?>, P> extends Comman
|
|||
|
||||
private final ServerUtilsPlugin<P, ?, C, ?, ?> plugin;
|
||||
private final IntFunction<P[]> arrayCreator;
|
||||
private final String commandConfigPath;
|
||||
|
||||
public PluginsParser(ServerUtilsPlugin<P, ?, C, ?, ?> plugin, IntFunction<P[]> arrayCreator) {
|
||||
this(plugin, arrayCreator, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new PluginsParser.
|
||||
*/
|
||||
public PluginsParser(
|
||||
ServerUtilsPlugin<P, ?, C, ?, ?> plugin,
|
||||
IntFunction<P[]> arrayCreator,
|
||||
String commandConfigPath
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.arrayCreator = arrayCreator;
|
||||
this.commandConfigPath = commandConfigPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -50,8 +64,13 @@ public class PluginsArgument<C extends ServerCommandSender<?>, P> extends Comman
|
|||
return ArgumentParseResult.failure(new NoInputProvidedException(PluginsParser.class, context));
|
||||
}
|
||||
|
||||
P[] plugins = arrayCreator.apply(inputQueue.size());
|
||||
for (int i = 0; i < plugins.length; i++) {
|
||||
Set<String> flags = plugin.getCommandsResource().getAllFlagAliases(commandConfigPath + ".flags.force");
|
||||
|
||||
int queueSize = inputQueue.size();
|
||||
List<P> plugins = new ArrayList<>(queueSize);
|
||||
for (int i = 0; i < queueSize; i++) {
|
||||
if (flags.contains(inputQueue.peek())) continue;
|
||||
|
||||
Optional<P> pluginOptional = plugin.getPluginManager().getPlugin(inputQueue.peek());
|
||||
if (!pluginOptional.isPresent()) {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException(
|
||||
|
|
@ -60,10 +79,10 @@ public class PluginsArgument<C extends ServerCommandSender<?>, P> extends Comman
|
|||
}
|
||||
|
||||
inputQueue.remove();
|
||||
plugins[i] = pluginOptional.get();
|
||||
plugins.add(pluginOptional.get());
|
||||
}
|
||||
|
||||
return ArgumentParseResult.success(plugins);
|
||||
return ArgumentParseResult.success(plugins.stream().toArray(arrayCreator));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package net.frankheijden.serverutils.common.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
|
||||
/**
|
||||
|
|
@ -13,6 +16,26 @@ public class CommandsResource extends ServerUtilsResource {
|
|||
super(plugin, COMMANDS_RESOURCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all flag aliases for the given flag path.
|
||||
*/
|
||||
public Set<String> getAllFlagAliases(String path) {
|
||||
Object flagObject = getConfig().get(path);
|
||||
if (flagObject instanceof ServerUtilsConfig) {
|
||||
ServerUtilsConfig flagConfig = (ServerUtilsConfig) flagObject;
|
||||
|
||||
Set<String> flagAliases = new HashSet<>();
|
||||
flagAliases.add("--" + flagConfig.getString("main"));
|
||||
for (String alias : flagConfig.getStringList("aliases")) {
|
||||
flagAliases.add("-" + alias);
|
||||
}
|
||||
|
||||
return flagAliases;
|
||||
}
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(int currentConfigVersion) {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package net.frankheijden.serverutils.common.providers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
|
@ -46,6 +47,22 @@ public interface PluginProvider<P, D extends ServerUtilsPluginDescription> {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves plugins which depend on the given plugin.
|
||||
*/
|
||||
default List<P> getPluginsDependingOn(String pluginId) {
|
||||
List<P> plugins = new ArrayList<>();
|
||||
|
||||
for (P loadedPlugin : getPlugins()) {
|
||||
ServerUtilsPluginDescription description = getLoadedPluginDescription(loadedPlugin);
|
||||
if (description.getDependencies().contains(pluginId)) {
|
||||
plugins.add(loadedPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
||||
Optional<P> getPlugin(String pluginId);
|
||||
|
||||
D getLoadedPluginDescription(P plugin);
|
||||
|
|
|
|||
|
|
@ -49,14 +49,32 @@
|
|||
"aliases": ["up"],
|
||||
"permission": "serverutils.unloadplugin",
|
||||
"description": "Disables and unloads the specified plugin(s).",
|
||||
"display-in-help": true
|
||||
"display-in-help": true,
|
||||
"flags": {
|
||||
"force": {
|
||||
"main": "force",
|
||||
"aliases": ["f"],
|
||||
"permission": "serverutils.unloadplugin",
|
||||
"description": "Force disable and unload the specified plugin(s).",
|
||||
"display-in-help": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"reloadplugin": {
|
||||
"main": "reloadplugin",
|
||||
"aliases": ["rp"],
|
||||
"permission": "serverutils.reloadplugin",
|
||||
"description": "Reloads the specified plugin(s).",
|
||||
"display-in-help": true
|
||||
"display-in-help": true,
|
||||
"flags": {
|
||||
"force": {
|
||||
"main": "force",
|
||||
"aliases": ["f"],
|
||||
"permission": "serverutils.reloadplugin",
|
||||
"description": "Force reloads the specified plugin(s).",
|
||||
"display-in-help": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"watchplugin": {
|
||||
"main": "watchplugin",
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@
|
|||
"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%",
|
||||
"depending_plugins": {
|
||||
"prefix": "&cPlugin &4%what%&c has depending plugins: ",
|
||||
"format": "&4%plugin%",
|
||||
"separator": "&c, ",
|
||||
"last_separator": " &cand ",
|
||||
"override": "&cUse \"&4/%command%&c\" to force command execution."
|
||||
},
|
||||
"watcher": {
|
||||
"start": "&3Started watching &b%what%&3!",
|
||||
"change": "&3Change detected for plugin &b%what%&3, reloading now...",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.FrankHeijden.cloud:cloud-velocity:fea4605277'
|
||||
implementation "com.github.FrankHeijden.cloud:cloud-velocity:${rootProject.cloudVersion}"
|
||||
implementation 'org.bstats:bstats-velocity:2.2.1'
|
||||
implementation project(":Common")
|
||||
compileOnly 'com.velocitypowered:velocity-api:3.0.0'
|
||||
|
|
|
|||
10
build.gradle
10
build.gradle
|
|
@ -7,6 +7,12 @@ group = 'net.frankheijden.serverutils'
|
|||
String dependencyDir = group + '.dependencies'
|
||||
version = '2.5.6'
|
||||
|
||||
allprojects {
|
||||
ext {
|
||||
cloudVersion = '62e3bc97ef'
|
||||
}
|
||||
}
|
||||
|
||||
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
subprojects {
|
||||
|
|
@ -25,8 +31,8 @@ subprojects {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.FrankHeijden.cloud:cloud-core:fea4605277'
|
||||
implementation 'com.github.FrankHeijden.cloud:cloud-brigadier:fea4605277'
|
||||
implementation "com.github.FrankHeijden.cloud:cloud-core:${rootProject.cloudVersion}"
|
||||
implementation "com.github.FrankHeijden.cloud:cloud-brigadier:${rootProject.cloudVersion}"
|
||||
implementation 'com.github.FrankHeijden:MinecraftReflection:1.0.0'
|
||||
implementation 'com.google.guava:guava:30.1.1-jre'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue