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,27 +1,15 @@
|
|||
package net.frankheijden.serverutils.bungee;
|
||||
|
||||
import co.aikar.commands.BungeeCommandCompletionContext;
|
||||
import co.aikar.commands.BungeeCommandManager;
|
||||
import co.aikar.commands.CommandCompletions;
|
||||
import net.frankheijden.serverutils.bungee.commands.CommandPlugins;
|
||||
import net.frankheijden.serverutils.bungee.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeePlugin;
|
||||
import net.frankheijden.serverutils.bungee.listeners.BungeeListener;
|
||||
import net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
|
||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||
import net.frankheijden.serverutils.common.config.Config;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
|
||||
public class ServerUtils extends Plugin {
|
||||
|
||||
private static ServerUtils instance;
|
||||
private static final String CONFIG_RESOURCE = "bungee-config.yml";
|
||||
private static final String MESSAGES_RESOURCE = "bungee-messages.yml";
|
||||
|
||||
private BungeePlugin plugin;
|
||||
private BungeeCommandManager commandManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
|
@ -32,29 +20,12 @@ public class ServerUtils extends Plugin {
|
|||
ServerUtilsApp.init(this, plugin);
|
||||
|
||||
new Metrics(this, ServerUtilsApp.BSTATS_METRICS_ID);
|
||||
|
||||
this.commandManager = new BungeeCommandManager(this);
|
||||
commandManager.registerCommand(new CommandPlugins());
|
||||
commandManager.registerCommand(new CommandServerUtils());
|
||||
|
||||
BungeePluginManager manager = plugin.getPluginManager();
|
||||
CommandCompletions<BungeeCommandCompletionContext> commandCompletions = commandManager.getCommandCompletions();
|
||||
commandCompletions.registerAsyncCompletion("plugins", context -> manager.getPluginNames());
|
||||
commandCompletions.registerAsyncCompletion("pluginJars", context -> manager.getPluginFileNames());
|
||||
commandCompletions.registerAsyncCompletion("commands", context -> manager.getCommands());
|
||||
|
||||
reload();
|
||||
getProxy().getPluginManager().registerListener(this, new BungeeListener());
|
||||
|
||||
plugin.enable();
|
||||
|
||||
ServerUtilsApp.tryCheckForUpdates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
commandManager.unregisterCommands();
|
||||
plugin.disable();
|
||||
}
|
||||
|
||||
|
|
@ -65,13 +36,4 @@ public class ServerUtils extends Plugin {
|
|||
public BungeePlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public BungeeCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
new Config("config.yml", CONFIG_RESOURCE);
|
||||
new Messenger("messages.yml", MESSAGES_RESOURCE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package net.frankheijden.serverutils.bungee.commands;
|
||||
|
||||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeeCommandSender;
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeePlugin;
|
||||
import net.frankheijden.serverutils.common.commands.CommandPlugins;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginDescription;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
|
||||
public class BungeeCommandPlugins extends CommandPlugins<
|
||||
BungeePlugin,
|
||||
Plugin,
|
||||
ScheduledTask,
|
||||
BungeeCommandSender,
|
||||
CommandSender
|
||||
> {
|
||||
|
||||
public BungeeCommandPlugins(BungeePlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void register(
|
||||
CommandManager<BungeeCommandSender> manager,
|
||||
Command.Builder<BungeeCommandSender> builder
|
||||
) {
|
||||
manager.command(builder
|
||||
.flag(parseFlag("version"))
|
||||
.flag(parseFlag("modules"))
|
||||
.handler(this::handlePlugins));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlugins(CommandContext<BungeeCommandSender> context) {
|
||||
BungeeCommandSender sender = context.getSender();
|
||||
boolean hasVersionFlag = context.flags().contains("version");
|
||||
boolean hasModulesFlag = context.flags().contains("modules");
|
||||
|
||||
handlePlugins(sender, plugin.getPluginManager().getPluginsSorted(hasModulesFlag), bungeePlugin -> {
|
||||
PluginDescription description = bungeePlugin.getDescription();
|
||||
|
||||
String message = plugin.getMessagesResource().getMessage(
|
||||
"serverutils.plugins.format",
|
||||
"%plugin%", description.getName()
|
||||
);
|
||||
|
||||
if (hasVersionFlag) {
|
||||
message += plugin.getMessagesResource().getMessage(
|
||||
"serverutils.plugins.version",
|
||||
"%version%", description.getVersion()
|
||||
);
|
||||
}
|
||||
|
||||
return message;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package net.frankheijden.serverutils.bungee.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import net.frankheijden.serverutils.bungee.ServerUtils;
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeeCommandSender;
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeePlugin;
|
||||
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
|
||||
import net.frankheijden.serverutils.common.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ListBuilder;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginDescription;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
|
||||
public class BungeeCommandServerUtils extends CommandServerUtils<
|
||||
BungeePlugin,
|
||||
Plugin,
|
||||
ScheduledTask,
|
||||
BungeeCommandSender,
|
||||
CommandSender
|
||||
> {
|
||||
|
||||
public BungeeCommandServerUtils(BungeePlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FormatBuilder createPluginInfo(
|
||||
FormatBuilder builder,
|
||||
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
|
||||
String pluginName
|
||||
) {
|
||||
Plugin container = plugin.getPluginManager().getPlugin(pluginName);
|
||||
PluginDescription desc = container.getDescription();
|
||||
|
||||
return builder
|
||||
.add("Name", desc.getName())
|
||||
.add("Version", desc.getVersion())
|
||||
.add("Author", desc.getAuthor())
|
||||
.add("Description", desc.getDescription())
|
||||
.add("Main", desc.getMain())
|
||||
.add("File", desc.getFile().getName())
|
||||
.add("Depend", listBuilderFunction.apply(b -> b.addAll(desc.getDepends())))
|
||||
.add("Soft Depend", listBuilderFunction.apply(b -> b.addAll(desc.getSoftDepends())));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FormatBuilder createCommandInfo(
|
||||
FormatBuilder builder,
|
||||
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
|
||||
String commandName
|
||||
) {
|
||||
PluginManager proxyPluginManager = ServerUtils.getInstance().getProxy().getPluginManager();
|
||||
Map<String, Command> commands;
|
||||
try {
|
||||
commands = RPluginManager.getCommands(proxyPluginManager);
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
builder.add("Error", "Please check the console.");
|
||||
return builder;
|
||||
}
|
||||
|
||||
Command cmd = commands.get(commandName);
|
||||
Plugin plugin = RPluginManager.getPlugin(proxyPluginManager, cmd);
|
||||
|
||||
return builder
|
||||
.add("Name", cmd.getName())
|
||||
.add("Plugin", plugin == null ? "<UNKNOWN>" : plugin.getDescription().getName())
|
||||
.add("Aliases", listBuilderFunction.apply(b -> b.addAll(Arrays.asList(cmd.getAliases()))))
|
||||
.add("Permission", cmd.getPermission());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
package net.frankheijden.serverutils.bungee.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 net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
|
||||
import net.frankheijden.serverutils.bungee.utils.BungeeUtils;
|
||||
import net.frankheijden.serverutils.common.commands.Plugins;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
|
||||
@CommandAlias("bpl|bplugins|bungeepl")
|
||||
public class CommandPlugins extends BaseCommand {
|
||||
|
||||
private static final BungeePluginManager manager = BungeePluginManager.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|-m -v|-m")
|
||||
@CommandPermission("serverutils.plugins")
|
||||
@Description("Shows the plugins of this proxy.")
|
||||
public void onPlugins(CommandSender sender, String... args) {
|
||||
boolean version = contains(args, "-v");
|
||||
boolean modules = contains(args, "-m");
|
||||
Plugins.sendPlugins(BungeeUtils.wrap(sender), manager.getPluginsSorted(modules), pl -> {
|
||||
String ver = version ? Messenger.getMessage("serverutils.plugins.version",
|
||||
"%version%", pl.getDescription().getVersion()) : "";
|
||||
return Messenger.getMessage("serverutils.plugins.format",
|
||||
"%plugin%", pl.getDescription().getName()) + ver;
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean contains(String[] arr, String val) {
|
||||
for (String s : arr) {
|
||||
if (s.equalsIgnoreCase(val)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,292 +0,0 @@
|
|||
package net.frankheijden.serverutils.bungee.commands;
|
||||
|
||||
import static net.frankheijden.serverutils.common.config.Messenger.sendMessage;
|
||||
|
||||
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 java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.frankheijden.serverutils.bungee.ServerUtils;
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeeLoadResult;
|
||||
import net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
|
||||
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
|
||||
import net.frankheijden.serverutils.bungee.utils.BungeeUtils;
|
||||
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.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginDescription;
|
||||
|
||||
@CommandAlias("bsu|bserverutils")
|
||||
public class CommandServerUtils extends BaseCommand {
|
||||
|
||||
private static final ProxyServer proxy = ProxyServer.getInstance();
|
||||
private static final ServerUtils plugin = ServerUtils.getInstance();
|
||||
private static final Set<String> ALIASES;
|
||||
|
||||
static {
|
||||
ALIASES = new HashSet<>();
|
||||
ALIASES.add("bserverutils");
|
||||
ALIASES.add("bplugins");
|
||||
ALIASES.add("bungeepl");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the help page to the sender.
|
||||
* @param commandSender The sender of the command.
|
||||
*/
|
||||
@Default
|
||||
@Subcommand("help")
|
||||
@CommandPermission("serverutils.help")
|
||||
@Description("Shows a help page with a few commands.")
|
||||
public void onHelp(CommandSender commandSender) {
|
||||
ServerCommandSender sender = BungeeUtils.wrap(commandSender);
|
||||
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(CommandSender sender) {
|
||||
plugin.reload();
|
||||
sendMessage(BungeeUtils.wrap(sender), "serverutils.success",
|
||||
"%action%", "reload",
|
||||
"%what%", "ServerUtils Bungee configurations");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the specified plugin on the proxy.
|
||||
* @param commandSender 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(CommandSender commandSender, String jarFile) {
|
||||
ServerCommandSender sender = BungeeUtils.wrap(commandSender);
|
||||
|
||||
BungeeLoadResult loadResult = BungeePluginManager.get().loadPlugin(jarFile);
|
||||
if (!loadResult.isSuccess()) {
|
||||
loadResult.getResult().sendTo(sender, "load", jarFile);
|
||||
return;
|
||||
}
|
||||
|
||||
Plugin plugin = loadResult.get();
|
||||
Result result = BungeePluginManager.get().enablePlugin(plugin);
|
||||
result.sendTo(sender, "load", plugin.getDescription().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unloads the specified plugin from the proxy.
|
||||
* @param commandSender 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(CommandSender commandSender, String pluginName) {
|
||||
CloseableResult result = BungeePluginManager.get().unloadPlugin(pluginName);
|
||||
result.getResult().sendTo(BungeeUtils.wrap(commandSender), "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(CommandSender 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 = BungeePluginManager.get().reloadPlugin(pluginName).toString();
|
||||
|
||||
String msg = (String) section.get(result.toLowerCase());
|
||||
if (msg != null && !msg.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', 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 sender 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(CommandSender sender, String pluginName) {
|
||||
ServerCommandSender commandSender = BungeeUtils.wrap(sender);
|
||||
AbstractResult result = BungeePluginManager.get().watchPlugin(commandSender, pluginName);
|
||||
result.sendTo(commandSender, "watch", pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops watching the given plugin.
|
||||
* @param sender 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(CommandSender sender, String pluginName) {
|
||||
AbstractResult result = BungeePluginManager.get().unwatchPlugin(pluginName);
|
||||
result.sendTo(BungeeUtils.wrap(sender), "unwatch", pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows information about the specified plugin.
|
||||
* @param commandSender 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(CommandSender commandSender, String pluginName) {
|
||||
ServerCommandSender sender = BungeeUtils.wrap(commandSender);
|
||||
|
||||
Plugin plugin = ProxyServer.getInstance().getPluginManager().getPlugin(pluginName);
|
||||
if (plugin == null) {
|
||||
Result.NOT_EXISTS.sendTo(sender, "fetch", pluginName);
|
||||
return;
|
||||
}
|
||||
|
||||
PluginDescription desc = plugin.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("Name", desc.getName())
|
||||
.add("Version", desc.getVersion())
|
||||
.add("Author", desc.getAuthor())
|
||||
.add("Description", desc.getDescription())
|
||||
.add("Main", desc.getMain())
|
||||
.add("File", desc.getFile().getName())
|
||||
.add("Depend", ListBuilder.create(desc.getDepends())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString())
|
||||
.add("Soft Depend", ListBuilder.create(desc.getSoftDepends())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString());
|
||||
|
||||
builder.sendTo(sender);
|
||||
Messenger.sendMessage(sender, "serverutils.plugininfo.footer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows information about a provided command.
|
||||
* @param commandSender 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(CommandSender commandSender, String command) {
|
||||
ServerCommandSender sender = BungeeUtils.wrap(commandSender);
|
||||
|
||||
Map<String, Command> commands;
|
||||
try {
|
||||
commands = RPluginManager.getCommands(proxy.getPluginManager());
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Command cmd = commands.get(command);
|
||||
if (cmd == null) {
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.not_exists");
|
||||
return;
|
||||
}
|
||||
|
||||
Plugin plugin = RPluginManager.getPlugin(proxy.getPluginManager(), cmd);
|
||||
if (plugin == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String format = Messenger.getMessage("serverutils.commandinfo.format");
|
||||
String listFormatString = Messenger.getMessage("serverutils.commandinfo.list_format");
|
||||
String seperator = Messenger.getMessage("serverutils.commandinfo.seperator");
|
||||
String lastSeperator = Messenger.getMessage("serverutils.commandinfo.last_seperator");
|
||||
|
||||
ListFormat<String> listFormat = str -> listFormatString.replace("%value%", str);
|
||||
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.header");
|
||||
FormatBuilder builder = FormatBuilder.create(format)
|
||||
.orderedKeys("%key%", "%value%")
|
||||
.add("Name", cmd.getName())
|
||||
.add("Plugin", plugin.getDescription().getName())
|
||||
.add("Aliases", ListBuilder.create(cmd.getAliases())
|
||||
.format(listFormat)
|
||||
.seperator(seperator)
|
||||
.lastSeperator(lastSeperator)
|
||||
.toString())
|
||||
.add("Permission", cmd.getPermission());
|
||||
|
||||
builder.sendTo(sender);
|
||||
Messenger.sendMessage(sender, "serverutils.commandinfo.footer");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,21 @@
|
|||
package net.frankheijden.serverutils.bungee.entities;
|
||||
|
||||
import net.frankheijden.serverutils.bungee.utils.BungeeUtils;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.frankheijden.serverutils.common.providers.ChatProvider;
|
||||
import net.frankheijden.serverutils.common.utils.HexUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
public class BungeeChatProvider extends ChatProvider {
|
||||
public class BungeeChatProvider implements ChatProvider<BungeeCommandSender, CommandSender> {
|
||||
|
||||
@Override
|
||||
public ServerCommandSender getConsoleSender() {
|
||||
return BungeeUtils.wrap(ProxyServer.getInstance().getConsole());
|
||||
public BungeeCommandSender getConsoleSender() {
|
||||
return new BungeeCommandSender(ProxyServer.getInstance().getConsole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BungeeCommandSender get(CommandSender source) {
|
||||
return new BungeeCommandSender(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
|||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class BungeeCommandSender implements ServerCommandSender {
|
||||
public class BungeeCommandSender implements ServerCommandSender<CommandSender> {
|
||||
|
||||
private final CommandSender sender;
|
||||
|
||||
|
|
@ -30,4 +30,9 @@ public class BungeeCommandSender implements ServerCommandSender {
|
|||
public boolean isPlayer() {
|
||||
return sender instanceof ProxiedPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSender getSource() {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,26 @@
|
|||
package net.frankheijden.serverutils.bungee.entities;
|
||||
|
||||
import cloud.commandframework.bungee.BungeeCommandManager;
|
||||
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
import net.frankheijden.serverutils.bungee.ServerUtils;
|
||||
import net.frankheijden.serverutils.bungee.commands.BungeeCommandPlugins;
|
||||
import net.frankheijden.serverutils.bungee.commands.BungeeCommandServerUtils;
|
||||
import net.frankheijden.serverutils.bungee.listeners.BungeeServerListener;
|
||||
import net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
|
||||
import net.frankheijden.serverutils.bungee.managers.BungeeTaskManager;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||
import net.md_5.bungee.api.plugin.PluginDescription;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
|
||||
public class BungeePlugin extends ServerUtilsPlugin {
|
||||
public class BungeePlugin extends ServerUtilsPlugin<
|
||||
Plugin,
|
||||
ScheduledTask,
|
||||
BungeeCommandSender,
|
||||
CommandSender
|
||||
> {
|
||||
|
||||
private final ServerUtils plugin;
|
||||
private final BungeePluginManager pluginManager;
|
||||
|
|
@ -29,13 +41,26 @@ public class BungeePlugin extends ServerUtilsPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected BungeeCommandManager<BungeeCommandSender> newCommandManager() {
|
||||
return new BungeeCommandManager<>(
|
||||
plugin,
|
||||
AsynchronousCommandExecutionCoordinator.<BungeeCommandSender>newBuilder().build(),
|
||||
chatProvider::get,
|
||||
BungeeCommandSender::getSource
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform getPlatform() {
|
||||
return Platform.BUNGEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BungeePluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public BungeeTaskManager getTaskManager() {
|
||||
return taskManager;
|
||||
}
|
||||
|
|
@ -61,13 +86,13 @@ public class BungeePlugin extends ServerUtilsPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public PluginDescription fetchUpdaterData() {
|
||||
try {
|
||||
return BungeePluginManager.getPluginDescription(pluginManager.getPluginFile("ServerUtils"));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
protected void enablePlugin() {
|
||||
plugin.getProxy().getPluginManager().registerListener(plugin, new BungeeServerListener(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reloadPlugin() {
|
||||
new BungeeCommandPlugins(this).register(commandManager);
|
||||
new BungeeCommandServerUtils(this).register(commandManager);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public class BungeeResourceProvider implements ResourceProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResource(String resource) {
|
||||
public InputStream getRawResource(String resource) {
|
||||
return plugin.getResourceAsStream(resource);
|
||||
}
|
||||
|
||||
|
|
@ -34,4 +34,9 @@ public class BungeeResourceProvider implements ResourceProvider {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourceExtension() {
|
||||
return ".yml";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
package net.frankheijden.serverutils.bungee.listeners;
|
||||
|
||||
import net.frankheijden.serverutils.bungee.utils.BungeeUtils;
|
||||
import net.frankheijden.serverutils.common.listeners.ServerListener;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class BungeeListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onServerConnect(ServerConnectEvent event) {
|
||||
if (event.getReason() != ServerConnectEvent.Reason.JOIN_PROXY) return;
|
||||
ServerListener.handleUpdate(BungeeUtils.wrap(event.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package net.frankheijden.serverutils.bungee.listeners;
|
||||
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeeCommandSender;
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeePlugin;
|
||||
import net.frankheijden.serverutils.common.listeners.ServerListener;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class BungeeServerListener extends ServerListener<
|
||||
BungeePlugin,
|
||||
Plugin,
|
||||
ScheduledTask,
|
||||
BungeeCommandSender,
|
||||
CommandSender
|
||||
> implements Listener {
|
||||
|
||||
public BungeeServerListener(BungeePlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerConnect(ServerConnectEvent event) {
|
||||
if (event.getReason() != ServerConnectEvent.Reason.JOIN_PROXY) return;
|
||||
handleUpdate(plugin.getChatProvider().get(event.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ import net.md_5.bungee.api.plugin.Plugin;
|
|||
import net.md_5.bungee.api.plugin.PluginDescription;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
||||
public class BungeePluginManager implements AbstractPluginManager<Plugin> {
|
||||
|
||||
private static final ProxyServer proxy = ProxyServer.getInstance();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
package net.frankheijden.serverutils.bungee.utils;
|
||||
|
||||
import net.frankheijden.serverutils.bungee.entities.BungeeCommandSender;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
|
||||
public class BungeeUtils {
|
||||
|
||||
public static ServerCommandSender wrap(CommandSender sender) {
|
||||
return new BungeeCommandSender(sender);
|
||||
}
|
||||
}
|
||||
13
Bungee/src/main/resources/bungee-commands.json
Normal file
13
Bungee/src/main/resources/bungee-commands.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"plugins": {
|
||||
"flags": {
|
||||
"modules": {
|
||||
"main": "modules",
|
||||
"aliases": ["m"],
|
||||
"permission": "serverutils.plugins.modules",
|
||||
"description": "Displays the proxy modules.",
|
||||
"display-in-help": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Bungee/src/main/resources/bungee-config.json
Normal file
1
Bungee/src/main/resources/bungee-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
Bungee/src/main/resources/bungee-messages.json
Normal file
1
Bungee/src/main/resources/bungee-messages.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
|
|
@ -1,61 +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%"
|
||||
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 Bungee 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 Bungee 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."
|
||||
help:
|
||||
header: "&8&m----------=&r&8[ &b&lServerUtils Bungee 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 Bungee 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-------------------------------------------------"
|
||||
plugininfo:
|
||||
header: "&8&m-------=&r&8[ &b&lServerUtils Bungee 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 Bungee 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."
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
name: ServerUtils
|
||||
main: net.frankheijden.serverutils.bungee.ServerUtils
|
||||
version: ${version}
|
||||
author: FrankHeijden
|
||||
author: FrankHeijden
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue