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