Add initial cloud commands + refactors to common
This commit is contained in:
parent
f21306021d
commit
6545d7ffac
89 changed files with 1959 additions and 1893 deletions
|
|
@ -1,8 +1,5 @@
|
|||
package net.frankheijden.serverutils.velocity;
|
||||
|
||||
import co.aikar.commands.CommandCompletions;
|
||||
import co.aikar.commands.VelocityCommandCompletionContext;
|
||||
import co.aikar.commands.VelocityCommandManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
|
|
@ -15,13 +12,8 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||
import net.frankheijden.serverutils.common.config.Config;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.frankheijden.serverutils.velocity.commands.CommandPlugins;
|
||||
import net.frankheijden.serverutils.velocity.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityPlugin;
|
||||
import net.frankheijden.serverutils.velocity.managers.VelocityPluginCommandManager;
|
||||
import net.frankheijden.serverutils.velocity.managers.VelocityPluginManager;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityCommandManager;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -37,12 +29,9 @@ import org.slf4j.Logger;
|
|||
public class ServerUtils {
|
||||
|
||||
private static ServerUtils instance;
|
||||
private static final String CONFIG_RESOURCE = "velocity-config.toml";
|
||||
private static final String MESSAGES_RESOURCE = "velocity-messages.toml";
|
||||
private static final String PLUGIN_COMMANDS_CACHE = ".pluginCommandsCache.json";
|
||||
|
||||
private VelocityPlugin plugin;
|
||||
private VelocityCommandManager commandManager;
|
||||
|
||||
@Inject
|
||||
private ProxyServer proxy;
|
||||
|
|
@ -95,21 +84,7 @@ public class ServerUtils {
|
|||
ServerUtilsApp.init(this, plugin);
|
||||
|
||||
metricsFactory.make(this, ServerUtilsApp.BSTATS_METRICS_ID);
|
||||
|
||||
this.commandManager = new VelocityCommandManager(proxy, this);
|
||||
commandManager.registerCommand(new CommandPlugins());
|
||||
commandManager.registerCommand(new CommandServerUtils(this));
|
||||
|
||||
VelocityPluginManager manager = plugin.getPluginManager();
|
||||
CommandCompletions<VelocityCommandCompletionContext> completions = commandManager.getCommandCompletions();
|
||||
completions.registerAsyncCompletion("plugins", context -> manager.getPluginNames());
|
||||
completions.registerAsyncCompletion("pluginJars", context -> manager.getPluginFileNames());
|
||||
completions.registerAsyncCompletion("commands", context -> manager.getCommands());
|
||||
|
||||
reload();
|
||||
plugin.enable();
|
||||
|
||||
ServerUtilsApp.tryCheckForUpdates();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,20 +115,15 @@ public class ServerUtils {
|
|||
return dataDirectory;
|
||||
}
|
||||
|
||||
public VelocityCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public VelocityPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public PluginContainer getPluginContainer() {
|
||||
return pluginContainer;
|
||||
}
|
||||
|
||||
public VelocityPluginCommandManager getPluginCommandManager() {
|
||||
return pluginCommandManager;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
new Config("config.toml", CONFIG_RESOURCE);
|
||||
new Messenger("messages.toml", MESSAGES_RESOURCE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
package net.frankheijden.serverutils.velocity.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import net.frankheijden.serverutils.common.commands.Plugins;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.frankheijden.serverutils.velocity.managers.VelocityPluginManager;
|
||||
import net.frankheijden.serverutils.velocity.utils.VelocityUtils;
|
||||
|
||||
@CommandAlias("vpl|vplugins|velocitypl")
|
||||
public class CommandPlugins extends BaseCommand {
|
||||
|
||||
private static final VelocityPluginManager manager = VelocityPluginManager.get();
|
||||
|
||||
/**
|
||||
* Sends the plugin list to the sender.
|
||||
* The `-v` flag will output the plugins with version.
|
||||
* The `-m` flag will also output modules in the plugin list.
|
||||
* @param sender The sender of the command.
|
||||
*/
|
||||
@Default
|
||||
@CommandCompletion("-v")
|
||||
@CommandPermission("serverutils.plugins")
|
||||
@Description("Shows the plugins of this proxy.")
|
||||
public void onPlugins(CommandSource sender, String... args) {
|
||||
boolean version = contains(args, "-v");
|
||||
Plugins.sendPlugins(VelocityUtils.wrap(sender), manager.getPluginsSorted(), pl -> {
|
||||
String ver = version ? Messenger.getMessage("serverutils.plugins.version",
|
||||
"%version%", pl.getDescription().getVersion().orElse("<UNKNOWN>")) : "";
|
||||
return Messenger.getMessage("serverutils.plugins.format",
|
||||
"%plugin%", pl.getDescription().getId()) + ver;
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean contains(String[] arr, String val) {
|
||||
for (String s : arr) {
|
||||
if (s.equalsIgnoreCase(val)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,275 +0,0 @@
|
|||
package net.frankheijden.serverutils.velocity.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.RegisteredCommand;
|
||||
import co.aikar.commands.RootCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.frankheijden.serverutils.common.entities.AbstractResult;
|
||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||
import net.frankheijden.serverutils.common.entities.Result;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.HexUtils;
|
||||
import net.frankheijden.serverutils.common.utils.ListBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ListFormat;
|
||||
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityLoadResult;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityCommandManager;
|
||||
import net.frankheijden.serverutils.velocity.utils.VelocityUtils;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
@CommandAlias("vsu|vserverutils")
|
||||
public class CommandServerUtils extends BaseCommand {
|
||||
|
||||
private static final Set<String> ALIASES;
|
||||
|
||||
static {
|
||||
ALIASES = new HashSet<>();
|
||||
ALIASES.add("vserverutils");
|
||||
ALIASES.add("vplugins");
|
||||
ALIASES.add("velocitypl");
|
||||
}
|
||||
|
||||
private final ServerUtils plugin;
|
||||
|
||||
public CommandServerUtils(ServerUtils plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the help page to the sender.
|
||||
* @param source The sender of the command.
|
||||
*/
|
||||
@Default
|
||||
@Subcommand("help")
|
||||
@CommandPermission("serverutils.help")
|
||||
@Description("Shows a help page with a few commands.")
|
||||
public void onHelp(CommandSource source) {
|
||||
ServerCommandSender sender = VelocityUtils.wrap(source);
|
||||
Messenger.sendMessage(sender, "serverutils.help.header");
|
||||
|
||||
FormatBuilder builder = FormatBuilder.create(Messenger.getMessage("serverutils.help.format"))
|
||||
.orderedKeys("%command%", "%subcommand%", "%help%");
|
||||
|
||||
Set<String> rootCommands = new HashSet<>();
|
||||
for (RootCommand root : plugin.getCommandManager().getRegisteredRootCommands()) {
|
||||
String rootName = root.getDefCommand().getName();
|
||||
if (!rootCommands.add(rootName)) continue;
|
||||
builder.add(rootName, "", root.getDescription());
|
||||
|
||||
Set<String> subCommands = new HashSet<>();
|
||||
for (RegisteredCommand<?> sub : root.getSubCommands().values()) {
|
||||
String name = sub.getPrefSubCommand().toLowerCase();
|
||||
if (name.isEmpty()) continue;
|
||||
if (!subCommands.add(name)) continue;
|
||||
builder.add(rootName, " " + name, sub.getHelpText());
|
||||
}
|
||||
}
|
||||
builder.sendTo(sender);
|
||||
Messenger.sendMessage(sender, "serverutils.help.footer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the configurations of ServerUtils.
|
||||
* @param sender The sender of the command.
|
||||
*/
|
||||
@Subcommand("reload")
|
||||
@CommandPermission("serverutils.reload")
|
||||
@Description("Reloads the ServerUtils plugin.")
|
||||
public void onReload(CommandSource sender) {
|
||||
plugin.reload();
|
||||
Messenger.sendMessage(VelocityUtils.wrap(sender), "serverutils.success",
|
||||
"%action%", "reload",
|
||||
"%what%", "ServerUtils Bungee configurations");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the specified plugin on the proxy.
|
||||
* @param source The sender of the command.
|
||||
* @param jarFile The filename of the plugin in the plugins/ directory.
|
||||
*/
|
||||
@Subcommand("loadplugin|lp")
|
||||
@CommandCompletion("@pluginJars")
|
||||
@CommandPermission("serverutils.loadplugin")
|
||||
@Description("Loads the specified jar file as a plugin.")
|
||||
public void onLoadPlugin(CommandSource source, String jarFile) {
|
||||
ServerCommandSender sender = VelocityUtils.wrap(source);
|
||||
|
||||
VelocityLoadResult loadResult = plugin.getPlugin().getPluginManager().loadPlugin(jarFile);
|
||||
if (!loadResult.isSuccess()) {
|
||||
loadResult.getResult().sendTo(sender, "load", jarFile);
|
||||
return;
|
||||
}
|
||||
|
||||
PluginContainer container = loadResult.get();
|
||||
Result result = plugin.getPlugin().getPluginManager().enablePlugin(container);
|
||||
result.sendTo(sender, "load", container.getDescription().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unloads the specified plugin from the proxy.
|
||||
* @param source The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("unloadplugin|up")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.unloadplugin")
|
||||
@Description("Disables and unloads the specified plugin.")
|
||||
public void onUnloadPlugin(CommandSource source, String pluginName) {
|
||||
CloseableResult result = plugin.getPlugin().getPluginManager().unloadPlugin(pluginName);
|
||||
result.getResult().sendTo(VelocityUtils.wrap(source), "unload", pluginName);
|
||||
result.tryClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the specified plugin on the proxy.
|
||||
* @param sender The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("reloadplugin|rp")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.reloadplugin")
|
||||
@Description("Reloads a specified plugin.")
|
||||
public void onReloadPlugin(CommandSource sender, String pluginName) {
|
||||
// Wacky method to have the resources needed for the reload in memory, in case of a self reload.
|
||||
HexUtils utils = new HexUtils();
|
||||
Map<String, Object> section = Messenger.getInstance().getConfig().getMap("serverutils");
|
||||
String result = plugin.getPlugin().getPluginManager().reloadPlugin(pluginName).toString();
|
||||
|
||||
String msg = (String) section.get(result.toLowerCase());
|
||||
if (msg != null && !msg.isEmpty()) {
|
||||
sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(utils.convertHexString(
|
||||
msg.replace("%action%", "reload").replace("%what%", pluginName))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Watches the given plugin and reloads it when a change is detected to the file.
|
||||
* @param source The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("watchplugin|wp")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.watchplugin")
|
||||
@Description("Watches the specified plugin for changes.")
|
||||
public void onWatchPlugin(CommandSource source, String pluginName) {
|
||||
ServerCommandSender sender = VelocityUtils.wrap(source);
|
||||
AbstractResult result = plugin.getPlugin().getPluginManager().watchPlugin(sender, pluginName);
|
||||
result.sendTo(sender, "watch", pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops watching the given plugin.
|
||||
* @param source The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("unwatchplugin|uwp")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.watchplugin")
|
||||
@Description("Stops watching the specified plugin for changes.")
|
||||
public void onUnwatchPlugin(CommandSource source, String pluginName) {
|
||||
AbstractResult result = plugin.getPlugin().getPluginManager().unwatchPlugin(pluginName);
|
||||
result.sendTo(VelocityUtils.wrap(source), "unwatch", pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows information about the specified plugin.
|
||||
* @param source The sender of the command.
|
||||
* @param pluginName The plugin name.
|
||||
*/
|
||||
@Subcommand("plugininfo|pi")
|
||||
@CommandCompletion("@plugins")
|
||||
@CommandPermission("serverutils.plugininfo")
|
||||
@Description("Shows information about the specified plugin.")
|
||||
public void onPluginInfo(CommandSource source, String pluginName) {
|
||||
ServerCommandSender sender = VelocityUtils.wrap(source);
|
||||
|
||||
Optional<PluginContainer> container = plugin.getProxy().getPluginManager().getPlugin(pluginName);
|
||||
if (!container.isPresent()) {
|
||||
Result.NOT_EXISTS.sendTo(sender, "fetch", pluginName);
|
||||
return;
|
||||
}
|
||||
|
||||
PluginDescription desc = container.get().getDescription();
|
||||
String format = Messenger.getMessage("serverutils.plugininfo.format");
|
||||
String listFormatString = Messenger.getMessage("serverutils.plugininfo.list_format");
|
||||
String seperator = Messenger.getMessage("serverutils.plugininfo.seperator");
|
||||
String lastSeperator = Messenger.getMessage("serverutils.plugininfo.last_seperator");
|
||||
|
||||
ListFormat<String> listFormat = str -> listFormatString.replace("%value%", str);
|
||||
|
||||
Messenger.sendMessage(sender, "serverutils.plugininfo.header");
|
||||
|
||||
FormatBuilder builder = FormatBuilder.create(format)
|
||||
.orderedKeys("%key%", "%value%")
|
||||
.add("Id", desc.getId())
|
||||
.add("Name", desc.getName().orElse(null))
|
||||
.add("Version", desc.getVersion().orElse("<UNKNOWN>"))
|
||||
.add("Author" + (desc.getAuthors().size() == 1 ? "" : "s"), ListBuilder.create(desc.getAuthors())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString())
|
||||
.add("Description", desc.getDescription().orElse(null))
|
||||
.add("URL", desc.getUrl().orElse(null))
|
||||
.add("Source", desc.getSource().map(Path::toString).orElse(null))
|
||||
.add("Dependencies", ListBuilder.create(desc.getDependencies())
|
||||
.format(d -> listFormat.format(d.getId()))
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString());
|
||||
|
||||
builder.sendTo(sender);
|
||||
Messenger.sendMessage(sender, "serverutils.plugininfo.footer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows information about a provided command.
|
||||
* @param source The sender of the command.
|
||||
* @param command The command to lookup.
|
||||
*/
|
||||
@Subcommand("commandinfo|ci")
|
||||
@CommandCompletion("@commands")
|
||||
@CommandPermission("serverutils.commandinfo")
|
||||
@Description("Shows information about the specified command.")
|
||||
public void onCommandInfo(CommandSource source, String command) {
|
||||
ServerCommandSender sender = VelocityUtils.wrap(source);
|
||||
|
||||
CommandDispatcher<CommandSource> dispatcher = RVelocityCommandManager.getDispatcher(
|
||||
plugin.getProxy().getCommandManager()
|
||||
);
|
||||
|
||||
CommandNode<CommandSource> node = dispatcher.getRoot().getChild(command);
|
||||
if (node == null) {
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.not_exists");
|
||||
return;
|
||||
}
|
||||
|
||||
String format = Messenger.getMessage("serverutils.commandinfo.format");
|
||||
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.header");
|
||||
FormatBuilder builder = FormatBuilder.create(format)
|
||||
.orderedKeys("%key%", "%value%")
|
||||
.add("Name", node.getName())
|
||||
.add("Plugin", plugin.getPluginCommandManager().findPluginId(command).orElse("<UNKNOWN>"));
|
||||
|
||||
builder.sendTo(sender);
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.footer");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package net.frankheijden.serverutils.velocity.commands;
|
||||
|
||||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import net.frankheijden.serverutils.common.commands.CommandPlugins;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityCommandSender;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityPlugin;
|
||||
|
||||
public class VelocityCommandPlugins extends CommandPlugins<
|
||||
VelocityPlugin,
|
||||
PluginContainer,
|
||||
ScheduledTask,
|
||||
VelocityCommandSender,
|
||||
CommandSource
|
||||
> {
|
||||
|
||||
public VelocityCommandPlugins(VelocityPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void register(
|
||||
CommandManager<VelocityCommandSender> manager,
|
||||
Command.Builder<VelocityCommandSender> builder
|
||||
) {
|
||||
manager.command(builder
|
||||
.flag(parseFlag("version"))
|
||||
.handler(this::handlePlugins));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlugins(CommandContext<VelocityCommandSender> context) {
|
||||
VelocityCommandSender sender = context.getSender();
|
||||
boolean hasVersionFlag = context.flags().contains("version");
|
||||
|
||||
handlePlugins(sender, plugin.getPluginManager().getPluginsSorted(), container -> {
|
||||
PluginDescription description = container.getDescription();
|
||||
|
||||
String message = plugin.getMessagesResource().getMessage(
|
||||
"serverutils.plugins.format",
|
||||
"%plugin%", description.getId()
|
||||
);
|
||||
|
||||
if (hasVersionFlag) {
|
||||
message += plugin.getMessagesResource().getMessage(
|
||||
"serverutils.plugins.version",
|
||||
"%version%", description.getVersion().orElse("<UNKNOWN>")
|
||||
);
|
||||
}
|
||||
|
||||
return message;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package net.frankheijden.serverutils.velocity.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import net.frankheijden.serverutils.common.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ListBuilder;
|
||||
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityCommandSender;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityPlugin;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityCommandManager;
|
||||
|
||||
public class VelocityCommandServerUtils extends CommandServerUtils<
|
||||
VelocityPlugin,
|
||||
PluginContainer,
|
||||
ScheduledTask,
|
||||
VelocityCommandSender,
|
||||
CommandSource
|
||||
> {
|
||||
|
||||
public VelocityCommandServerUtils(VelocityPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FormatBuilder createPluginInfo(
|
||||
FormatBuilder builder,
|
||||
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
|
||||
String pluginName
|
||||
) {
|
||||
PluginContainer container = plugin.getPluginManager().getPlugin(pluginName);
|
||||
PluginDescription desc = container.getDescription();
|
||||
|
||||
return builder
|
||||
.add("Id", desc.getId())
|
||||
.add("Name", desc.getName().orElse(null))
|
||||
.add("Version", desc.getVersion().orElse("<UNKNOWN>"))
|
||||
.add(
|
||||
"Author" + (desc.getAuthors().size() == 1 ? "" : "s"),
|
||||
listBuilderFunction.apply(b -> b.addAll(desc.getAuthors()))
|
||||
)
|
||||
.add("Description", desc.getDescription().orElse(null))
|
||||
.add("URL", desc.getUrl().orElse(null))
|
||||
.add("Source", desc.getSource().map(Path::toString).orElse(null))
|
||||
.add(
|
||||
"Dependencies",
|
||||
listBuilderFunction.apply(b -> b.addAll(desc.getDependencies().stream()
|
||||
.map(PluginDependency::getId)
|
||||
.collect(Collectors.toList())))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FormatBuilder createCommandInfo(
|
||||
FormatBuilder builder,
|
||||
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
|
||||
String commandName
|
||||
) {
|
||||
ServerUtils plugin = ServerUtils.getInstance();
|
||||
CommandDispatcher<CommandSource> dispatcher = RVelocityCommandManager.getDispatcher(
|
||||
plugin.getProxy().getCommandManager()
|
||||
);
|
||||
|
||||
return builder
|
||||
.add("Name", dispatcher.getRoot().getChild(commandName).getName())
|
||||
.add("Plugin", plugin.getPluginCommandManager().findPluginId(commandName).orElse("<UNKNOWN>"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
package net.frankheijden.serverutils.velocity.entities;
|
||||
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import net.frankheijden.serverutils.common.providers.ChatProvider;
|
||||
import net.frankheijden.serverutils.common.utils.HexUtils;
|
||||
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||
import net.frankheijden.serverutils.velocity.utils.VelocityUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class VelocityChatProvider extends ChatProvider {
|
||||
public class VelocityChatProvider implements ChatProvider<VelocityCommandSender, CommandSource> {
|
||||
|
||||
private final ServerUtils plugin;
|
||||
|
||||
|
|
@ -17,8 +16,13 @@ public class VelocityChatProvider extends ChatProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ServerCommandSender getConsoleSender() {
|
||||
return VelocityUtils.wrap(plugin.getProxy().getConsoleCommandSource());
|
||||
public VelocityCommandSender getConsoleSender() {
|
||||
return new VelocityCommandSender(plugin.getProxy().getConsoleCommandSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityCommandSender get(CommandSource source) {
|
||||
return new VelocityCommandSender(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import com.velocitypowered.api.proxy.Player;
|
|||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class VelocityCommandSender implements ServerCommandSender {
|
||||
public class VelocityCommandSender implements ServerCommandSender<CommandSource> {
|
||||
|
||||
private final CommandSource source;
|
||||
|
||||
|
|
@ -31,4 +31,9 @@ public class VelocityCommandSender implements ServerCommandSender {
|
|||
public boolean isPlayer() {
|
||||
return source instanceof Player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSource getSource() {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,25 @@
|
|||
package net.frankheijden.serverutils.velocity.entities;
|
||||
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
|
||||
import cloud.commandframework.velocity.VelocityCommandManager;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.logging.Logger;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||
import net.frankheijden.serverutils.velocity.commands.VelocityCommandPlugins;
|
||||
import net.frankheijden.serverutils.velocity.commands.VelocityCommandServerUtils;
|
||||
import net.frankheijden.serverutils.velocity.managers.VelocityPluginManager;
|
||||
import net.frankheijden.serverutils.velocity.managers.VelocityTaskManager;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RJavaPluginLoader;
|
||||
|
||||
public class VelocityPlugin extends ServerUtilsPlugin {
|
||||
public class VelocityPlugin extends ServerUtilsPlugin<
|
||||
PluginContainer,
|
||||
ScheduledTask,
|
||||
VelocityCommandSender,
|
||||
CommandSource
|
||||
> {
|
||||
|
||||
private final ServerUtils plugin;
|
||||
private final VelocityPluginManager pluginManager;
|
||||
|
|
@ -31,25 +40,39 @@ public class VelocityPlugin extends ServerUtilsPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public VelocityPluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
protected VelocityCommandManager<VelocityCommandSender> newCommandManager() {
|
||||
return new VelocityCommandManager<>(
|
||||
plugin.getPluginContainer(),
|
||||
plugin.getProxy(),
|
||||
AsynchronousCommandExecutionCoordinator.<VelocityCommandSender>newBuilder().build(),
|
||||
chatProvider::get,
|
||||
VelocityCommandSender::getSource
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityPluginManager getPluginManager() {
|
||||
return this.pluginManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public VelocityTaskManager getTaskManager() {
|
||||
return taskManager;
|
||||
return this.taskManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform getPlatform() {
|
||||
return Platform.VELOCITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityResourceProvider getResourceProvider() {
|
||||
return resourceProvider;
|
||||
return this.resourceProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityChatProvider getChatProvider() {
|
||||
return chatProvider;
|
||||
return this.chatProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -59,14 +82,12 @@ public class VelocityPlugin extends ServerUtilsPlugin {
|
|||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return plugin.getDataDirectory().toFile();
|
||||
return this.plugin.getDataDirectory().toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public PluginDescription fetchUpdaterData() {
|
||||
Path pluginPath = pluginManager.getPluginFile("ServerUtils").toPath();
|
||||
Object javaPluginLoader = RJavaPluginLoader.newInstance(plugin.getProxy(), pluginPath.getParent());
|
||||
return RJavaPluginLoader.loadPluginDescription(javaPluginLoader, pluginPath);
|
||||
protected void reloadPlugin() {
|
||||
new VelocityCommandPlugins(this).register(commandManager);
|
||||
new VelocityCommandServerUtils(this).register(commandManager);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class VelocityResourceProvider implements ResourceProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResource(String resource) {
|
||||
public InputStream getRawResource(String resource) {
|
||||
return plugin.getClass().getClassLoader().getResourceAsStream(resource);
|
||||
}
|
||||
|
||||
|
|
@ -43,4 +43,9 @@ public class VelocityResourceProvider implements ResourceProvider {
|
|||
public ServerUtilsConfig load(File file) {
|
||||
return new VelocityTomlConfig(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourceExtension() {
|
||||
return ".toml";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.frankheijden.serverutils.common.config.ServerUtilsConfig;
|
||||
|
|
@ -21,10 +22,10 @@ public class VelocityTomlConfig implements ServerUtilsConfig {
|
|||
* Creates a new VelocityTomlConfig instance.
|
||||
*/
|
||||
public VelocityTomlConfig(File file) {
|
||||
CommentedFileConfig config = CommentedFileConfig.of(file, TomlFormat.instance());
|
||||
config.load();
|
||||
CommentedFileConfig conf = CommentedFileConfig.of(file, TomlFormat.instance());
|
||||
conf.load();
|
||||
|
||||
this.config = config;
|
||||
this.config = conf;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +57,11 @@ public class VelocityTomlConfig implements ServerUtilsConfig {
|
|||
|
||||
@Override
|
||||
public void set(String path, Object value) {
|
||||
config.set(path, value);
|
||||
if (value == null) {
|
||||
config.remove(path);
|
||||
} else {
|
||||
config.set(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -71,7 +76,7 @@ public class VelocityTomlConfig implements ServerUtilsConfig {
|
|||
|
||||
@Override
|
||||
public Collection<? extends String> getKeys() {
|
||||
return config.valueMap().keySet();
|
||||
return new HashSet<>(config.valueMap().keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginContainer
|
|||
import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginManager;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityScheduler;
|
||||
|
||||
public class VelocityPluginManager extends AbstractPluginManager<PluginContainer> {
|
||||
public class VelocityPluginManager implements AbstractPluginManager<PluginContainer> {
|
||||
|
||||
private static VelocityPluginManager instance;
|
||||
private final ProxyServer proxy;
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
package net.frankheijden.serverutils.velocity.utils;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityCommandSender;
|
||||
|
||||
public class VelocityUtils {
|
||||
|
||||
public static ServerCommandSender wrap(CommandSource source) {
|
||||
return new VelocityCommandSender(source);
|
||||
}
|
||||
}
|
||||
1
Velocity/src/main/resources/velocity-commands.json
Normal file
1
Velocity/src/main/resources/velocity-commands.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
1
Velocity/src/main/resources/velocity-config.json
Normal file
1
Velocity/src/main/resources/velocity-config.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
[settings]
|
||||
check-updates-boot = true
|
||||
check-updates-login = false
|
||||
download-updates-boot = false
|
||||
download-updates-login = false
|
||||
install-updates-boot = false
|
||||
install-updates-login = false
|
||||
1
Velocity/src/main/resources/velocity-messages.json
Normal file
1
Velocity/src/main/resources/velocity-messages.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
[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, please check the console!"
|
||||
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%"
|
||||
|
||||
[serverutils.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!"
|
||||
|
||||
[serverutils.update]
|
||||
available = """
|
||||
&8&m--------=&r&8[ &b&lServerUtils Velocity Update&r &8]&m=---------
|
||||
&3Current version: &b%old%
|
||||
&3New version: &b%new%
|
||||
&3Release info: &b%info%
|
||||
&8&m-------------------------------------------------"""
|
||||
downloading = """
|
||||
&8&m--------=&r&8[ &b&lServerUtils Velocity Update&r &8]&m=----------
|
||||
&3A new version of ServerUtils will be downloaded and installed after a restart!
|
||||
&3Current version: &b%old%
|
||||
&3New version: &b%new%
|
||||
&3Release info: &b%info%
|
||||
&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."
|
||||
|
||||
[serverutils.help]
|
||||
header = "&8&m---------=&r&8[ &b&lServerUtils Velocity Help&r &8]&m=---------"
|
||||
format = "&8/&3%command%&b%subcommand% &f(&7%help%&f)"
|
||||
footer = "&8&m-------------------------------------------------"
|
||||
|
||||
[serverutils.plugins]
|
||||
header = "&8&m--------=&r&8[ &b&lServerUtils Velocity Plugins&r &8]&m=-------"
|
||||
prefix = " &3Plugins &8(&a%count%&8)&b: "
|
||||
format = "&3%plugin%"
|
||||
seperator = "&b, "
|
||||
last_seperator = " &band "
|
||||
version = " &8(&a%version%&8)"
|
||||
footer = "&8&m-------------------------------------------------"
|
||||
|
||||
[serverutils.plugininfo]
|
||||
header = "&8&m------=&r&8[ &b&lServerUtils Velocity PluginInfo&r &8]&m=------"
|
||||
format = " &3%key%&8: &b%value%"
|
||||
list_format = "&b%value%"
|
||||
seperator = "&8, "
|
||||
last_seperator = " &8and "
|
||||
footer = "&8&m-------------------------------------------------"
|
||||
|
||||
[serverutils.commandinfo]
|
||||
header = "&8&m-----=&r&8[ &b&lServerUtils Velocity 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."
|
||||
Loading…
Add table
Add a link
Reference in a new issue