Avoid component newlines, instead send message per line
This commit is contained in:
parent
083012abfe
commit
12b3aa5720
11 changed files with 133 additions and 160 deletions
|
|
@ -98,7 +98,7 @@ public class BukkitCommandServerUtils extends CommandServerUtils<BukkitPlugin, P
|
||||||
List<Plugin> plugins = Arrays.asList(context.get("plugins"));
|
List<Plugin> plugins = Arrays.asList(context.get("plugins"));
|
||||||
|
|
||||||
PluginResults<Plugin> enableResults = plugin.getPluginManager().enablePlugins(plugins);
|
PluginResults<Plugin> enableResults = plugin.getPluginManager().enablePlugins(plugins);
|
||||||
sender.sendMessage(enableResults.toComponent(BukkitMessageKey.ENABLEPLUGIN));
|
enableResults.sendTo(sender, BukkitMessageKey.ENABLEPLUGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDisablePlugin(CommandContext<BukkitAudience> context) {
|
private void handleDisablePlugin(CommandContext<BukkitAudience> context) {
|
||||||
|
|
@ -110,7 +110,7 @@ public class BukkitCommandServerUtils extends CommandServerUtils<BukkitPlugin, P
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginResults<Plugin> disableResults = plugin.getPluginManager().disablePlugins(plugins);
|
PluginResults<Plugin> disableResults = plugin.getPluginManager().disablePlugins(plugins);
|
||||||
sender.sendMessage(disableResults.toComponent(BukkitMessageKey.DISABLEPLUGIN));
|
disableResults.sendTo(sender, BukkitMessageKey.DISABLEPLUGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleReloadConfig(CommandContext<BukkitAudience> context) {
|
private void handleReloadConfig(CommandContext<BukkitAudience> context) {
|
||||||
|
|
@ -166,25 +166,25 @@ public class BukkitCommandServerUtils extends CommandServerUtils<BukkitPlugin, P
|
||||||
) {
|
) {
|
||||||
PluginDescriptionFile description = bukkitPlugin.getDescription();
|
PluginDescriptionFile description = bukkitPlugin.getDescription();
|
||||||
|
|
||||||
builder.add("Name", bukkitPlugin.getName())
|
builder.key("Name").value(bukkitPlugin.getName())
|
||||||
.add("Full Name", description.getFullName())
|
.key("Full Name").value(description.getFullName())
|
||||||
.add("Version", description.getVersion())
|
.key("Version").value(description.getVersion())
|
||||||
.add("Website", description.getWebsite())
|
.key("Website").value(description.getWebsite())
|
||||||
.add("Authors", listBuilderFunction.apply(b -> b.addAll(description.getAuthors())))
|
.key("Authors").value(listBuilderFunction.apply(b -> b.addAll(description.getAuthors())))
|
||||||
.add("Description", description.getDescription())
|
.key("Description").value(description.getDescription())
|
||||||
.add("Main", description.getMain())
|
.key("Main").value(description.getMain())
|
||||||
.add("Prefix", description.getPrefix())
|
.key("Prefix").value(description.getPrefix())
|
||||||
.add("Load Order", description.getLoad().name())
|
.key("Load Order").value(description.getLoad().name())
|
||||||
.add("Load Before", listBuilderFunction.apply(b -> b.addAll(description.getLoadBefore())))
|
.key("Load Before").value(listBuilderFunction.apply(b -> b.addAll(description.getLoadBefore())))
|
||||||
.add("Depend", listBuilderFunction.apply(b -> b.addAll(description.getDepend())))
|
.key("Depend").value(listBuilderFunction.apply(b -> b.addAll(description.getDepend())))
|
||||||
.add("Soft Depend", listBuilderFunction.apply(b -> b.addAll(description.getSoftDepend())));
|
.key("Soft Depend").value(listBuilderFunction.apply(b -> b.addAll(description.getSoftDepend())));
|
||||||
|
|
||||||
if (MinecraftReflectionVersion.MINOR >= 13) {
|
if (MinecraftReflectionVersion.MINOR >= 13) {
|
||||||
builder.add("API Version", description.getAPIVersion());
|
builder.key("API Version").value(description.getAPIVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MinecraftReflectionVersion.MINOR >= 15) {
|
if (MinecraftReflectionVersion.MINOR >= 15) {
|
||||||
builder.add("Provides", listBuilderFunction.apply(b -> b.addAll(description.getProvides())));
|
builder.key("Provides").value(listBuilderFunction.apply(b -> b.addAll(description.getProvides())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
|
|
@ -197,17 +197,17 @@ public class BukkitCommandServerUtils extends CommandServerUtils<BukkitPlugin, P
|
||||||
String commandName
|
String commandName
|
||||||
) {
|
) {
|
||||||
Command cmd = BukkitPluginManager.getCommand(commandName);
|
Command cmd = BukkitPluginManager.getCommand(commandName);
|
||||||
builder.add("Name", cmd.getName());
|
builder.key("Name").value(cmd.getName());
|
||||||
|
|
||||||
if (cmd instanceof PluginIdentifiableCommand) {
|
if (cmd instanceof PluginIdentifiableCommand) {
|
||||||
builder.add("Plugin", ((PluginIdentifiableCommand) cmd).getPlugin().getName());
|
builder.key("Plugin").value(((PluginIdentifiableCommand) cmd).getPlugin().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.add("Aliases", listBuilderFunction.apply(b -> b.addAll(cmd.getAliases())))
|
return builder.key("Aliases").value(listBuilderFunction.apply(b -> b.addAll(cmd.getAliases())))
|
||||||
.add("Usage", cmd.getUsage())
|
.key("Usage").value(cmd.getUsage())
|
||||||
.add("Description", cmd.getDescription())
|
.key("Description").value(cmd.getDescription())
|
||||||
.add("Label", cmd.getLabel())
|
.key("Label").value(cmd.getLabel())
|
||||||
.add("Permission", cmd.getPermission())
|
.key("Permission").value(cmd.getPermission())
|
||||||
.add("Permission Message", cmd.getPermissionMessage());
|
.key("Permission Message").value(cmd.getPermissionMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,14 @@ public class BungeeCommandServerUtils extends CommandServerUtils<BungeePlugin, P
|
||||||
PluginDescription desc = bungeePlugin.getDescription();
|
PluginDescription desc = bungeePlugin.getDescription();
|
||||||
|
|
||||||
return builder
|
return builder
|
||||||
.add("Name", desc.getName())
|
.key("Name").value(desc.getName())
|
||||||
.add("Version", desc.getVersion())
|
.key("Version").value(desc.getVersion())
|
||||||
.add("Author", desc.getAuthor())
|
.key("Author").value(desc.getAuthor())
|
||||||
.add("Description", desc.getDescription())
|
.key("Description").value(desc.getDescription())
|
||||||
.add("Main", desc.getMain())
|
.key("Main").value(desc.getMain())
|
||||||
.add("File", desc.getFile().getName())
|
.key("File").value(desc.getFile().getName())
|
||||||
.add("Depend", listBuilderFunction.apply(b -> b.addAll(desc.getDepends())))
|
.key("Depend").value(listBuilderFunction.apply(b -> b.addAll(desc.getDepends())))
|
||||||
.add("Soft Depend", listBuilderFunction.apply(b -> b.addAll(desc.getSoftDepends())));
|
.key("Soft Depend").value(listBuilderFunction.apply(b -> b.addAll(desc.getSoftDepends())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -54,7 +54,7 @@ public class BungeeCommandServerUtils extends CommandServerUtils<BungeePlugin, P
|
||||||
commands = RPluginManager.getCommands(proxyPluginManager);
|
commands = RPluginManager.getCommands(proxyPluginManager);
|
||||||
} catch (IllegalAccessException ex) {
|
} catch (IllegalAccessException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
builder.add("Error", "Please check the console.");
|
builder.key("Error").value("Please check the console.");
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,9 +62,9 @@ public class BungeeCommandServerUtils extends CommandServerUtils<BungeePlugin, P
|
||||||
Plugin plugin = RPluginManager.getPlugin(proxyPluginManager, cmd);
|
Plugin plugin = RPluginManager.getPlugin(proxyPluginManager, cmd);
|
||||||
|
|
||||||
return builder
|
return builder
|
||||||
.add("Name", cmd.getName())
|
.key("Name").value(cmd.getName())
|
||||||
.add("Plugin", plugin == null ? "<UNKNOWN>" : plugin.getDescription().getName())
|
.key("Plugin").value(plugin == null ? "<UNKNOWN>" : plugin.getDescription().getName())
|
||||||
.add("Aliases", listBuilderFunction.apply(b -> b.addAll(Arrays.asList(cmd.getAliases()))))
|
.key("Aliases").value(listBuilderFunction.apply(b -> b.addAll(Arrays.asList(cmd.getAliases()))))
|
||||||
.add("Permission", cmd.getPermission());
|
.key("Permission").value(cmd.getPermission());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import net.frankheijden.serverutils.common.entities.results.PluginResult;
|
||||||
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
|
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
|
||||||
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||||
import net.frankheijden.serverutils.common.tasks.UpdateCheckerTask;
|
import net.frankheijden.serverutils.common.tasks.UpdateCheckerTask;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
public class ServerUtilsApp<U extends ServerUtilsPlugin<P, T, C, S, D>, P, T, C extends ServerUtilsAudience<S>, S, D extends ServerUtilsPluginDescription> {
|
public class ServerUtilsApp<U extends ServerUtilsPlugin<P, T, C, S, D>, P, T, C extends ServerUtilsAudience<S>, S, D extends ServerUtilsPluginDescription> {
|
||||||
|
|
||||||
|
|
@ -66,15 +65,13 @@ public class ServerUtilsApp<U extends ServerUtilsPlugin<P, T, C, S, D>, P, T, C
|
||||||
File file = plugin.getPluginManager().getPluginFile(updaterPlugin);
|
File file = plugin.getPluginManager().getPluginFile(updaterPlugin);
|
||||||
PluginResult<P> disableResult = plugin.getPluginManager().disablePlugin(updaterPlugin);
|
PluginResult<P> disableResult = plugin.getPluginManager().disablePlugin(updaterPlugin);
|
||||||
if (!disableResult.isSuccess()) {
|
if (!disableResult.isSuccess()) {
|
||||||
Component component = disableResult.toComponent(null);
|
disableResult.sendTo(plugin.getChatProvider().getConsoleServerAudience(), null);
|
||||||
plugin.getChatProvider().getConsoleServerAudience().sendMessage(component);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseablePluginResult<P> unloadResult = plugin.getPluginManager().unloadPlugin(disableResult.getPlugin());
|
CloseablePluginResult<P> unloadResult = plugin.getPluginManager().unloadPlugin(disableResult.getPlugin());
|
||||||
if (!unloadResult.isSuccess()) {
|
if (!unloadResult.isSuccess()) {
|
||||||
Component component = unloadResult.toComponent(null);
|
unloadResult.sendTo(plugin.getChatProvider().getConsoleServerAudience(), null);
|
||||||
plugin.getChatProvider().getConsoleServerAudience().sendMessage(component);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,9 +97,7 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
C sender = context.getSender();
|
C sender = context.getSender();
|
||||||
|
|
||||||
MessagesResource messages = plugin.getMessagesResource();
|
MessagesResource messages = plugin.getMessagesResource();
|
||||||
TextComponent.Builder builder = Component.text()
|
sender.sendMessage(messages.get(MessageKey.HELP_HEADER).toComponent());
|
||||||
.append(messages.get(MessageKey.HELP_HEADER).toComponent())
|
|
||||||
.append(Component.newline());
|
|
||||||
|
|
||||||
MessagesResource.Message helpFormatMessage = messages.get(MessageKey.HELP_FORMAT);
|
MessagesResource.Message helpFormatMessage = messages.get(MessageKey.HELP_FORMAT);
|
||||||
|
|
||||||
|
|
@ -110,10 +108,10 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
String shortestCommandAlias = determineShortestAlias(commandElement);
|
String shortestCommandAlias = determineShortestAlias(commandElement);
|
||||||
|
|
||||||
if (commandElement.shouldDisplayInHelp()) {
|
if (commandElement.shouldDisplayInHelp()) {
|
||||||
builder.append(helpFormatMessage.toComponent(
|
sender.sendMessage(helpFormatMessage.toComponent(
|
||||||
Template.of("command", shortestCommandAlias),
|
Template.of("command", shortestCommandAlias),
|
||||||
Template.of("help", commandElement.getDescription().getDescription())
|
Template.of("help", commandElement.getDescription().getDescription())
|
||||||
)).append(Component.newline());
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Object subcommandsObject = commandConfig.get("subcommands");
|
Object subcommandsObject = commandConfig.get("subcommands");
|
||||||
|
|
@ -125,10 +123,10 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
CommandElement subcommandElement = parseElement(subcommandConfig);
|
CommandElement subcommandElement = parseElement(subcommandConfig);
|
||||||
if (subcommandElement.shouldDisplayInHelp()) {
|
if (subcommandElement.shouldDisplayInHelp()) {
|
||||||
String shortestSubcommandAlias = determineShortestAlias(subcommandElement);
|
String shortestSubcommandAlias = determineShortestAlias(subcommandElement);
|
||||||
builder.append(helpFormatMessage.toComponent(
|
sender.sendMessage(helpFormatMessage.toComponent(
|
||||||
Template.of("command", shortestCommandAlias + ' ' + shortestSubcommandAlias),
|
Template.of("command", shortestCommandAlias + ' ' + shortestSubcommandAlias),
|
||||||
Template.of("help", subcommandElement.getDescription().getDescription())
|
Template.of("help", subcommandElement.getDescription().getDescription())
|
||||||
)).append(Component.newline());
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -143,17 +141,16 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
if (flagElement.shouldDisplayInHelp()) {
|
if (flagElement.shouldDisplayInHelp()) {
|
||||||
String shortestFlagAlias = determineShortestAlias(flagElement);
|
String shortestFlagAlias = determineShortestAlias(flagElement);
|
||||||
String flagPrefix = "-" + (flagElement.getMain().equals(shortestFlagAlias) ? "_" : "");
|
String flagPrefix = "-" + (flagElement.getMain().equals(shortestFlagAlias) ? "_" : "");
|
||||||
builder.append(helpFormatMessage.toComponent(
|
sender.sendMessage(helpFormatMessage.toComponent(
|
||||||
Template.of("command", shortestCommandAlias + ' ' + flagPrefix + shortestFlagAlias),
|
Template.of("command", shortestCommandAlias + ' ' + flagPrefix + shortestFlagAlias),
|
||||||
Template.of("help", flagElement.getDescription().getDescription())
|
Template.of("help", flagElement.getDescription().getDescription())
|
||||||
)).append(Component.newline());
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(messages.get(MessageKey.HELP_FOOTER).toComponent());
|
sender.sendMessage(messages.get(MessageKey.HELP_FOOTER).toComponent());
|
||||||
sender.sendMessage(builder.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String determineShortestAlias(CommandElement element) {
|
private String determineShortestAlias(CommandElement element) {
|
||||||
|
|
@ -180,12 +177,12 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
PluginResults<P> loadResults = pluginManager.loadPlugins(jarFiles);
|
PluginResults<P> loadResults = pluginManager.loadPlugins(jarFiles);
|
||||||
if (!loadResults.isSuccess()) {
|
if (!loadResults.isSuccess()) {
|
||||||
PluginResult<P> failedResult = loadResults.last();
|
PluginResult<P> failedResult = loadResults.last();
|
||||||
sender.sendMessage(failedResult.toComponent(null));
|
failedResult.sendTo(sender, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginResults<P> enableResults = pluginManager.enablePlugins(loadResults.getPlugins());
|
PluginResults<P> enableResults = pluginManager.enablePlugins(loadResults.getPlugins());
|
||||||
sender.sendMessage(enableResults.toComponent(MessageKey.LOADPLUGIN));
|
enableResults.sendTo(sender, MessageKey.LOADPLUGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleUnloadPlugin(CommandContext<C> context) {
|
private void handleUnloadPlugin(CommandContext<C> context) {
|
||||||
|
|
@ -199,14 +196,14 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
PluginResults<P> disableResults = plugin.getPluginManager().disablePlugins(plugins);
|
PluginResults<P> disableResults = plugin.getPluginManager().disablePlugins(plugins);
|
||||||
for (PluginResult<P> disableResult : disableResults.getResults()) {
|
for (PluginResult<P> disableResult : disableResults.getResults()) {
|
||||||
if (!disableResult.isSuccess() && disableResult.getResult() != Result.ALREADY_DISABLED) {
|
if (!disableResult.isSuccess() && disableResult.getResult() != Result.ALREADY_DISABLED) {
|
||||||
sender.sendMessage(disableResult.toComponent(null));
|
disableResult.sendTo(sender, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseablePluginResults<P> unloadResults = plugin.getPluginManager().unloadPlugins(plugins);
|
CloseablePluginResults<P> unloadResults = plugin.getPluginManager().unloadPlugins(plugins);
|
||||||
unloadResults.tryClose();
|
unloadResults.tryClose();
|
||||||
sender.sendMessage(unloadResults.toComponent(MessageKey.UNLOADPLUGIN));
|
unloadResults.sendTo(sender, MessageKey.UNLOADPLUGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleReloadPlugin(CommandContext<C> context) {
|
private void handleReloadPlugin(CommandContext<C> context) {
|
||||||
|
|
@ -218,7 +215,7 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginResults<P> reloadResults = plugin.getPluginManager().reloadPlugins(plugins);
|
PluginResults<P> reloadResults = plugin.getPluginManager().reloadPlugins(plugins);
|
||||||
sender.sendMessage(reloadResults.toComponent(MessageKey.RELOADPLUGIN));
|
reloadResults.sendTo(sender, MessageKey.RELOADPLUGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean checkDependingPlugins(CommandContext<C> context, C sender, List<P> plugins, String subcommand) {
|
protected boolean checkDependingPlugins(CommandContext<C> context, C sender, List<P> plugins, String subcommand) {
|
||||||
|
|
@ -227,27 +224,24 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
AbstractPluginManager<P, ?> pluginManager = plugin.getPluginManager();
|
AbstractPluginManager<P, ?> pluginManager = plugin.getPluginManager();
|
||||||
MessagesResource messages = plugin.getMessagesResource();
|
MessagesResource messages = plugin.getMessagesResource();
|
||||||
|
|
||||||
TextComponent.Builder builder = Component.text();
|
|
||||||
|
|
||||||
boolean hasDependingPlugins = false;
|
boolean hasDependingPlugins = false;
|
||||||
for (P plugin : plugins) {
|
for (P plugin : plugins) {
|
||||||
String pluginId = pluginManager.getPluginId(plugin);
|
String pluginId = pluginManager.getPluginId(plugin);
|
||||||
|
|
||||||
List<P> dependingPlugins = pluginManager.getPluginsDependingOn(pluginId);
|
List<P> dependingPlugins = pluginManager.getPluginsDependingOn(pluginId);
|
||||||
if (!dependingPlugins.isEmpty()) {
|
if (!dependingPlugins.isEmpty()) {
|
||||||
|
TextComponent.Builder builder = Component.text();
|
||||||
builder.append(messages.get(MessageKey.DEPENDING_PLUGINS_PREFIX).toComponent(
|
builder.append(messages.get(MessageKey.DEPENDING_PLUGINS_PREFIX).toComponent(
|
||||||
Template.of("plugin", pluginId)
|
Template.of("plugin", pluginId)
|
||||||
));
|
));
|
||||||
|
|
||||||
MessagesResource.Message dependingPluginsFormat = messages.get(MessageKey.DEPENDING_PLUGINS_FORMAT);
|
|
||||||
builder.append(ListComponentBuilder.create(dependingPlugins)
|
builder.append(ListComponentBuilder.create(dependingPlugins)
|
||||||
.format(p -> dependingPluginsFormat.toComponent(
|
.format(p -> messages.get(MessageKey.DEPENDING_PLUGINS_FORMAT).toComponent(
|
||||||
Template.of("plugin", pluginManager.getPluginId(p))
|
Template.of("plugin", pluginManager.getPluginId(p))
|
||||||
))
|
))
|
||||||
.separator(messages.get(MessageKey.DEPENDING_PLUGINS_SEPARATOR).toComponent())
|
.separator(messages.get(MessageKey.DEPENDING_PLUGINS_SEPARATOR).toComponent())
|
||||||
.lastSeparator(messages.get(MessageKey.DEPENDING_PLUGINS_LAST_SEPARATOR).toComponent())
|
.lastSeparator(messages.get(MessageKey.DEPENDING_PLUGINS_LAST_SEPARATOR).toComponent())
|
||||||
.build());
|
.build());
|
||||||
builder.append(Component.newline());
|
sender.sendMessage(builder.build());
|
||||||
hasDependingPlugins = true;
|
hasDependingPlugins = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -258,13 +252,11 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
.min(Comparator.comparingInt(String::length))
|
.min(Comparator.comparingInt(String::length))
|
||||||
.orElse("-f");
|
.orElse("-f");
|
||||||
|
|
||||||
builder.append(messages.get(MessageKey.DEPENDING_PLUGINS_OVERRIDE).toComponent(
|
sender.sendMessage(messages.get(MessageKey.DEPENDING_PLUGINS_OVERRIDE).toComponent(
|
||||||
Template.of("command", context.getRawInputJoined() + " " + forceFlag)
|
Template.of("command", context.getRawInputJoined() + " " + forceFlag)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(builder.build());
|
|
||||||
|
|
||||||
return hasDependingPlugins;
|
return hasDependingPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,31 +315,26 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
private <T> void createInfo(C sender, String command, T item, InfoCreator<T> creator) {
|
private <T> void createInfo(C sender, String command, T item, InfoCreator<T> creator) {
|
||||||
MessagesResource messages = plugin.getMessagesResource();
|
MessagesResource messages = plugin.getMessagesResource();
|
||||||
|
|
||||||
String messagePrefix = "messages." + command;
|
MessagesResource.Message formatMessage = messages.get(command + ".format");
|
||||||
MessagesResource.Message formatMessage = messages.get(messagePrefix + ".format");
|
MessagesResource.Message listFormatMessage = messages.get(command + ".list-format");
|
||||||
MessagesResource.Message listFormatMessage = messages.get(messagePrefix + ".list-format");
|
Component separator = messages.get(command + ".list-separator").toComponent();
|
||||||
Component separator = messages.get(messagePrefix + ".list-separator").toComponent();
|
Component lastSeparator = messages.get(command + ".list-last-separator").toComponent();
|
||||||
Component lastSeparator = messages.get(messagePrefix + ".list-last-separator").toComponent();
|
|
||||||
|
|
||||||
TextComponent.Builder builder = Component.text()
|
|
||||||
.append(messages.get(messagePrefix + ".header").toComponent())
|
|
||||||
.append(Component.newline());
|
|
||||||
|
|
||||||
|
sender.sendMessage(messages.get(command + ".header").toComponent());
|
||||||
creator.createInfo(
|
creator.createInfo(
|
||||||
KeyValueComponentBuilder.create(formatMessage, "key", "value"),
|
KeyValueComponentBuilder.create(formatMessage, "key", "value"),
|
||||||
listBuilderConsumer -> {
|
listBuilderConsumer -> {
|
||||||
ListComponentBuilder<String> listBuilder = ListComponentBuilder.<String>create()
|
ListComponentBuilder<String> listBuilder = ListComponentBuilder.<String>create()
|
||||||
.format(str -> listFormatMessage.toComponent(Template.of("value", str)))
|
.format(str -> listFormatMessage.toComponent(Template.of("value", str)))
|
||||||
.separator(separator)
|
.separator(separator)
|
||||||
.lastSeparator(lastSeparator);
|
.lastSeparator(lastSeparator)
|
||||||
|
.emptyValue(null);
|
||||||
listBuilderConsumer.accept(listBuilder);
|
listBuilderConsumer.accept(listBuilder);
|
||||||
return listBuilder.build();
|
return listBuilder.build();
|
||||||
},
|
},
|
||||||
item
|
item
|
||||||
);
|
).build().forEach(sender::sendMessage);
|
||||||
|
sender.sendMessage(messages.get(command + ".footer").toComponent());
|
||||||
builder.append(messages.get(messagePrefix + ".footer").toComponent());
|
|
||||||
sender.sendMessage(builder.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface InfoCreator<T> {
|
private interface InfoCreator<T> {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package net.frankheijden.serverutils.common.entities.results;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||||
import net.frankheijden.serverutils.common.config.ConfigKey;
|
import net.frankheijden.serverutils.common.config.ConfigKey;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
|
||||||
public class PluginResult<T> implements AbstractResult {
|
public class PluginResult<T> implements AbstractResult {
|
||||||
|
|
@ -48,9 +48,9 @@ public class PluginResult<T> implements AbstractResult {
|
||||||
return plugin != null && result == Result.SUCCESS;
|
return plugin != null && result == Result.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component toComponent(ConfigKey successKey) {
|
public void sendTo(ServerUtilsAudience<?> sender, ConfigKey successKey) {
|
||||||
ConfigKey key = isSuccess() ? successKey : result.getKey();
|
ConfigKey key = isSuccess() ? successKey : result.getKey();
|
||||||
return ServerUtilsApp.getPlugin().getMessagesResource().get(key).toComponent(templates);
|
sender.sendMessage(ServerUtilsApp.getPlugin().getMessagesResource().get(key).toComponent(templates));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.frankheijden.serverutils.common.config.ConfigKey;
|
import net.frankheijden.serverutils.common.config.ConfigKey;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
|
||||||
public class PluginResults<T> implements Iterable<PluginResult<T>> {
|
public class PluginResults<T> implements Iterable<PluginResult<T>> {
|
||||||
|
|
@ -68,14 +67,12 @@ public class PluginResults<T> implements Iterable<PluginResult<T>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link Component}.
|
* Sends the result(s) to the given sender.
|
||||||
*/
|
*/
|
||||||
public Component toComponent(ConfigKey successKey) {
|
public void sendTo(ServerUtilsAudience<?> sender, ConfigKey successKey) {
|
||||||
TextComponent.Builder builder = Component.text();
|
|
||||||
for (PluginResult<T> result : results) {
|
for (PluginResult<T> result : results) {
|
||||||
builder.append(result.toComponent(successKey));
|
result.sendTo(sender, successKey);
|
||||||
}
|
}
|
||||||
return builder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ import java.util.List;
|
||||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||||
import net.frankheijden.serverutils.common.config.MessagesResource;
|
import net.frankheijden.serverutils.common.config.MessagesResource;
|
||||||
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
|
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.TextComponent;
|
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
|
||||||
public class PluginWatchResults implements Iterable<PluginWatchResult> {
|
public class PluginWatchResults implements Iterable<PluginWatchResult> {
|
||||||
|
|
@ -33,11 +31,9 @@ public class PluginWatchResults implements Iterable<PluginWatchResult> {
|
||||||
public void sendTo(ServerUtilsAudience<?> sender) {
|
public void sendTo(ServerUtilsAudience<?> sender) {
|
||||||
MessagesResource messages = ServerUtilsApp.getPlugin().getMessagesResource();
|
MessagesResource messages = ServerUtilsApp.getPlugin().getMessagesResource();
|
||||||
|
|
||||||
TextComponent.Builder builder = Component.text();
|
|
||||||
for (PluginWatchResult watchResult : watchResults) {
|
for (PluginWatchResult watchResult : watchResults) {
|
||||||
builder.append(messages.get(watchResult.getKey()).toComponent(watchResult.getTemplates()));
|
sender.sendMessage(messages.get(watchResult.getKey()).toComponent(watchResult.getTemplates()));
|
||||||
}
|
}
|
||||||
sender.sendMessage(builder.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ public class PluginWatcherTask<P, T> extends AbstractTask {
|
||||||
fileNameToWatchEntryMap.clear();
|
fileNameToWatchEntryMap.clear();
|
||||||
|
|
||||||
PluginResults<P> reloadResults = pluginManager.reloadPlugins(plugins);
|
PluginResults<P> reloadResults = pluginManager.reloadPlugins(plugins);
|
||||||
sender.sendMessage(reloadResults.toComponent(MessageKey.RELOADPLUGIN));
|
reloadResults.sendTo(sender, MessageKey.RELOADPLUGIN);
|
||||||
|
|
||||||
for (PluginResult<P> reloadResult : reloadResults) {
|
for (PluginResult<P> reloadResult : reloadResults) {
|
||||||
if (!reloadResult.isSuccess()) continue;
|
if (!reloadResult.isSuccess()) continue;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.frankheijden.serverutils.common.config.MessagesResource;
|
import net.frankheijden.serverutils.common.config.MessagesResource;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
|
||||||
public class KeyValueComponentBuilder {
|
public class KeyValueComponentBuilder {
|
||||||
|
|
@ -36,60 +35,52 @@ public class KeyValueComponentBuilder {
|
||||||
return new KeyValueComponentBuilder(format, keyPlaceholder, valuePlaceholder);
|
return new KeyValueComponentBuilder(format, keyPlaceholder, valuePlaceholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public KeyValueComponentBuilder.KeyValuePair key(String key) {
|
||||||
* Adds an entry.
|
return new KeyValuePair(key);
|
||||||
*/
|
|
||||||
public KeyValueComponentBuilder add(String key, String value) {
|
|
||||||
if (value != null) this.templatesList.add(new Template[]{
|
|
||||||
Template.of(keyPlaceholder, key),
|
|
||||||
Template.of(valuePlaceholder, value)
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public KeyValueComponentBuilder.KeyValuePair key(Component key) {
|
||||||
* Adds an entry.
|
return new KeyValuePair(key);
|
||||||
*/
|
|
||||||
public KeyValueComponentBuilder add(String key, Component value) {
|
|
||||||
if (value != null) this.templatesList.add(new Template[]{
|
|
||||||
Template.of(keyPlaceholder, key),
|
|
||||||
Template.of(valuePlaceholder, value)
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private KeyValueComponentBuilder add(Template key, Template value) {
|
||||||
* Adds an entry.
|
this.templatesList.add(new Template[]{ key, value });
|
||||||
*/
|
|
||||||
public KeyValueComponentBuilder add(Component key, String value) {
|
|
||||||
if (value != null) this.templatesList.add(new Template[]{
|
|
||||||
Template.of(keyPlaceholder, key),
|
|
||||||
Template.of(valuePlaceholder, value)
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an entry.
|
|
||||||
*/
|
|
||||||
public KeyValueComponentBuilder add(Component key, Component value) {
|
|
||||||
if (value != null) this.templatesList.add(new Template[]{
|
|
||||||
Template.of(keyPlaceholder, key),
|
|
||||||
Template.of(valuePlaceholder, value)
|
|
||||||
});
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the current ListMessageBuilder instance into a Component.
|
* Builds the current ListMessageBuilder instance into a Component.
|
||||||
*/
|
*/
|
||||||
public Component build() {
|
public List<Component> build() {
|
||||||
TextComponent.Builder builder = Component.text();
|
List<Component> components = new ArrayList<>(templatesList.size());
|
||||||
|
|
||||||
for (Template[] templates : templatesList) {
|
for (Template[] templates : templatesList) {
|
||||||
builder.append(format.toComponent(templates));
|
components.add(format.toComponent(templates));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return components;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class KeyValuePair {
|
||||||
|
|
||||||
|
private final Template key;
|
||||||
|
|
||||||
|
private KeyValuePair(String key) {
|
||||||
|
this.key = Template.of(keyPlaceholder, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeyValuePair(Component key) {
|
||||||
|
this.key = Template.of(keyPlaceholder, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyValueComponentBuilder value(String value) {
|
||||||
|
if (value == null) return KeyValueComponentBuilder.this;
|
||||||
|
return add(key, Template.of(valuePlaceholder, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyValueComponentBuilder value(Component value) {
|
||||||
|
if (value == null) return KeyValueComponentBuilder.this;
|
||||||
|
return add(key, Template.of(valuePlaceholder, value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,11 @@ public class ListComponentBuilder<T> {
|
||||||
private Format<T> format;
|
private Format<T> format;
|
||||||
private Component separator;
|
private Component separator;
|
||||||
private Component lastSeparator;
|
private Component lastSeparator;
|
||||||
|
private Component emptyValue;
|
||||||
|
|
||||||
private ListComponentBuilder() {
|
private ListComponentBuilder() {
|
||||||
this.elements = new ArrayList<>();
|
this.elements = new ArrayList<>();
|
||||||
|
this.emptyValue = Component.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> ListComponentBuilder<T> create(Collection<? extends T> list) {
|
public static <T> ListComponentBuilder<T> create(Collection<? extends T> list) {
|
||||||
|
|
@ -42,6 +44,11 @@ public class ListComponentBuilder<T> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ListComponentBuilder<T> emptyValue(Component emptyValue) {
|
||||||
|
this.emptyValue = emptyValue;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ListComponentBuilder<T> addAll(Collection<? extends T> elements) {
|
public ListComponentBuilder<T> addAll(Collection<? extends T> elements) {
|
||||||
this.elements.addAll(elements);
|
this.elements.addAll(elements);
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -51,10 +58,12 @@ public class ListComponentBuilder<T> {
|
||||||
* Builds the ListComponent.
|
* Builds the ListComponent.
|
||||||
*/
|
*/
|
||||||
public Component build() {
|
public Component build() {
|
||||||
if (elements.size() == 1) {
|
if (elements.isEmpty()) {
|
||||||
|
return emptyValue;
|
||||||
|
} else if (elements.size() == 1) {
|
||||||
return format.format(elements.iterator().next());
|
return format.format(elements.iterator().next());
|
||||||
} else {
|
} else {
|
||||||
TextComponent.Builder builder = Component.empty().toBuilder();
|
TextComponent.Builder builder = Component.text();
|
||||||
|
|
||||||
int sizeMinusTwo = elements.size() - 2;
|
int sizeMinusTwo = elements.size() - 2;
|
||||||
for (int i = 0; i < elements.size(); i++) {
|
for (int i = 0; i < elements.size(); i++) {
|
||||||
|
|
|
||||||
|
|
@ -33,22 +33,18 @@ public class VelocityCommandServerUtils extends CommandServerUtils<VelocityPlugi
|
||||||
PluginDescription desc = container.getDescription();
|
PluginDescription desc = container.getDescription();
|
||||||
|
|
||||||
return builder
|
return builder
|
||||||
.add("Id", desc.getId())
|
.key("Id").value(desc.getId())
|
||||||
.add("Name", desc.getName().orElse(null))
|
.key("Name").value(desc.getName().orElse(null))
|
||||||
.add("Version", desc.getVersion().orElse("<UNKNOWN>"))
|
.key("Version").value(desc.getVersion().orElse("<UNKNOWN>"))
|
||||||
.add(
|
.key("Author" + (desc.getAuthors().size() == 1 ? "" : "s"))
|
||||||
"Author" + (desc.getAuthors().size() == 1 ? "" : "s"),
|
.value(listBuilderFunction.apply(b -> b.addAll(desc.getAuthors())))
|
||||||
listBuilderFunction.apply(b -> b.addAll(desc.getAuthors()))
|
.key("Description").value(desc.getDescription().orElse(null))
|
||||||
)
|
.key("URL").value(desc.getUrl().orElse(null))
|
||||||
.add("Description", desc.getDescription().orElse(null))
|
.key("Source").value(desc.getSource().map(Path::toString).orElse(null))
|
||||||
.add("URL", desc.getUrl().orElse(null))
|
.key("Dependencies")
|
||||||
.add("Source", desc.getSource().map(Path::toString).orElse(null))
|
.value(listBuilderFunction.apply(b -> b.addAll(desc.getDependencies().stream()
|
||||||
.add(
|
|
||||||
"Dependencies",
|
|
||||||
listBuilderFunction.apply(b -> b.addAll(desc.getDependencies().stream()
|
|
||||||
.map(PluginDependency::getId)
|
.map(PluginDependency::getId)
|
||||||
.collect(Collectors.toList())))
|
.collect(Collectors.toList()))));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -63,7 +59,7 @@ public class VelocityCommandServerUtils extends CommandServerUtils<VelocityPlugi
|
||||||
);
|
);
|
||||||
|
|
||||||
return builder
|
return builder
|
||||||
.add("Name", dispatcher.getRoot().getChild(commandName).getName())
|
.key("Name").value(dispatcher.getRoot().getChild(commandName).getName())
|
||||||
.add("Plugin", plugin.getPluginCommandManager().findPluginId(commandName).orElse("<UNKNOWN>"));
|
.key("Plugin").value(plugin.getPluginCommandManager().findPluginId(commandName).orElse("<UNKNOWN>"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue