Refrain from using adventure in the PluginManager's

Otherwise we have the same issue in the ServerUtilsUpdater plugin with the different adventure shadings
This commit is contained in:
Frank van der Heijden 2021-08-03 18:34:31 +02:00
parent 0f9c6f4041
commit 11a5c5140b
No known key found for this signature in database
GPG key ID: B808721C2DD5B5B8
10 changed files with 55 additions and 61 deletions

View file

@ -1,6 +1,5 @@
package net.frankheijden.serverutils.common.config;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -61,19 +60,22 @@ public class MessagesResource extends ServerUtilsResource {
/**
* Creates a {@link Component}.
*/
public Component toComponent(Template... placeholders) {
if (this.component == null) {
if (placeholders.length == 0) {
throw new IllegalArgumentException("Message '" + key + "' has placeholders"
+ " but none were provided!");
}
return miniMessage.parse(messageString, placeholders);
} else if (placeholders.length != 0) {
throw new IllegalArgumentException("Message '" + key + "' does not have placeholders"
+ " but the following placeholders were provided: " + Arrays.toString(placeholders));
} else {
return this.component;
}
public Component toComponent() {
return this.component == null ? miniMessage.parse(messageString) : this.component;
}
/**
* Creates a {@link Component}.
*/
public Component toComponent(Template... templates) {
return this.component == null ? miniMessage.parse(messageString, templates) : this.component;
}
/**
* Creates a {@link Component}.
*/
public Component toComponent(String... placeholders) {
return this.component == null ? miniMessage.parse(messageString, placeholders) : this.component;
}
public void sendTo(ServerUtilsAudience<?> serverAudience, Template... placeholders) {

View file

@ -4,7 +4,6 @@ import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import net.kyori.adventure.text.minimessage.Template;
public class CloseablePluginResult<T> extends PluginResult<T> implements Closeable {
@ -20,9 +19,9 @@ public class CloseablePluginResult<T> extends PluginResult<T> implements Closeab
T plugin,
Result result,
List<Closeable> closeables,
Template... templates
String... placeholders
) {
super(pluginId, plugin, result, templates);
super(pluginId, plugin, result, placeholders);
this.closeables = closeables;
}

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.common.entities.results;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import net.kyori.adventure.text.minimessage.Template;
public class CloseablePluginResults<T> extends PluginResults<T> implements Closeable {
@ -17,21 +16,21 @@ public class CloseablePluginResults<T> extends PluginResults<T> implements Close
}
@Override
public CloseablePluginResults<T> addResult(String pluginId, Result result, Template... templates) {
super.addResult(pluginId, result, templates);
public CloseablePluginResults<T> addResult(String pluginId, Result result, String... placeholders) {
super.addResult(pluginId, result, placeholders);
return this;
}
@Override
public CloseablePluginResults<T> addResult(String pluginId, T plugin, Template... templates) {
super.addResult(pluginId, plugin, templates);
public CloseablePluginResults<T> addResult(String pluginId, T plugin, String... placeholders) {
super.addResult(pluginId, plugin, placeholders);
return this;
}
@Override
protected CloseablePluginResults<T> addResult(String pluginId, T plugin, Result result, Template... templates
protected CloseablePluginResults<T> addResult(String pluginId, T plugin, Result result, String... placeholders
) {
super.addResult(pluginId, plugin, result, templates);
super.addResult(pluginId, plugin, result, placeholders);
return this;
}
@ -39,9 +38,9 @@ public class CloseablePluginResults<T> extends PluginResults<T> implements Close
String pluginId,
T plugin,
List<Closeable> closeables,
Template... templates
String... placeholders
) {
return addResult(new CloseablePluginResult<>(pluginId, plugin, Result.SUCCESS, closeables, templates));
return addResult(new CloseablePluginResult<>(pluginId, plugin, Result.SUCCESS, closeables, placeholders));
}
@Override

View file

@ -3,14 +3,13 @@ package net.frankheijden.serverutils.common.entities.results;
import net.frankheijden.serverutils.common.ServerUtilsApp;
import net.frankheijden.serverutils.common.config.ConfigKey;
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
import net.kyori.adventure.text.minimessage.Template;
public class PluginResult<T> implements AbstractResult {
private final String pluginId;
private final T plugin;
private final Result result;
private final Template[] templates;
private final String[] placeholders;
public PluginResult(String pluginId, Result result) {
this(pluginId, null, result);
@ -19,13 +18,14 @@ public class PluginResult<T> implements AbstractResult {
/**
* Constructs a new PluginResult.
*/
public PluginResult(String pluginId, T plugin, Result result, Template... templates) {
public PluginResult(String pluginId, T plugin, Result result, String... placeholders) {
this.pluginId = pluginId;
this.plugin = plugin;
this.result = result;
this.templates = new Template[templates.length + 1];
this.templates[0] = Template.of("plugin", pluginId);
System.arraycopy(templates, 0, this.templates, 1, templates.length);
this.placeholders = new String[placeholders.length + 2];
this.placeholders[0] = "plugin";
this.placeholders[1] = pluginId;
System.arraycopy(placeholders, 0, this.placeholders, 2, placeholders.length);
}
public String getPluginId() {
@ -40,8 +40,8 @@ public class PluginResult<T> implements AbstractResult {
return result;
}
public Template[] getTemplates() {
return templates;
public String[] getPlaceholders() {
return placeholders;
}
public boolean isSuccess() {
@ -50,7 +50,7 @@ public class PluginResult<T> implements AbstractResult {
public void sendTo(ServerUtilsAudience<?> sender, ConfigKey successKey) {
ConfigKey key = isSuccess() ? successKey : result.getKey();
sender.sendMessage(ServerUtilsApp.getPlugin().getMessagesResource().get(key).toComponent(templates));
sender.sendMessage(ServerUtilsApp.getPlugin().getMessagesResource().get(key).toComponent(placeholders));
}
@Override

View file

@ -5,7 +5,6 @@ import java.util.Iterator;
import java.util.List;
import net.frankheijden.serverutils.common.config.ConfigKey;
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
import net.kyori.adventure.text.minimessage.Template;
public class PluginResults<T> implements Iterable<PluginResult<T>> {
@ -15,18 +14,18 @@ public class PluginResults<T> implements Iterable<PluginResult<T>> {
this.results = new ArrayList<>();
}
public PluginResults<T> addResult(String pluginId, Result result, Template... templates) {
addResult(pluginId, null, result, templates);
public PluginResults<T> addResult(String pluginId, Result result, String... placeholders) {
addResult(pluginId, null, result, placeholders);
return this;
}
public PluginResults<T> addResult(String pluginId, T plugin, Template... templates) {
addResult(pluginId, plugin, Result.SUCCESS, templates);
public PluginResults<T> addResult(String pluginId, T plugin, String... placeholders) {
addResult(pluginId, plugin, Result.SUCCESS, placeholders);
return this;
}
protected PluginResults<T> addResult(String pluginId, T plugin, Result result, Template... templates) {
addResult(new PluginResult<>(pluginId, plugin, result, templates));
protected PluginResults<T> addResult(String pluginId, T plugin, Result result, String... placeholders) {
addResult(new PluginResult<>(pluginId, plugin, result, placeholders));
return this;
}

View file

@ -1,24 +1,23 @@
package net.frankheijden.serverutils.common.entities.results;
import net.frankheijden.serverutils.common.config.ConfigKey;
import net.kyori.adventure.text.minimessage.Template;
public class PluginWatchResult implements AbstractResult {
private final WatchResult result;
private final Template[] templates;
private final String[] placeholders;
public PluginWatchResult(WatchResult result, Template... templates) {
public PluginWatchResult(WatchResult result, String... placeholders) {
this.result = result;
this.templates = templates;
this.placeholders = placeholders;
}
public WatchResult getResult() {
return result;
}
public Template[] getTemplates() {
return templates;
public String[] getPlaceholders() {
return placeholders;
}
@Override

View file

@ -6,7 +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.minimessage.Template;
public class PluginWatchResults implements Iterable<PluginWatchResult> {
@ -16,8 +15,8 @@ public class PluginWatchResults implements Iterable<PluginWatchResult> {
this.watchResults = new ArrayList<>();
}
public PluginWatchResults add(WatchResult result, Template... templates) {
return add(new PluginWatchResult(result, templates));
public PluginWatchResults add(WatchResult result, String... placeholders) {
return add(new PluginWatchResult(result, placeholders));
}
public PluginWatchResults add(PluginWatchResult watchResult) {
@ -32,7 +31,7 @@ public class PluginWatchResults implements Iterable<PluginWatchResult> {
MessagesResource messages = ServerUtilsApp.getPlugin().getMessagesResource();
for (PluginWatchResult watchResult : watchResults) {
sender.sendMessage(messages.get(watchResult.getKey()).toComponent(watchResult.getTemplates()));
sender.sendMessage(messages.get(watchResult.getKey()).toComponent(watchResult.getPlaceholders()));
}
}

View file

@ -10,7 +10,6 @@ import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
import net.frankheijden.serverutils.common.entities.results.PluginWatchResults;
import net.frankheijden.serverutils.common.entities.results.WatchResult;
import net.frankheijden.serverutils.common.tasks.PluginWatcherTask;
import net.kyori.adventure.text.minimessage.Template;
public class WatchManager<P, T> {
@ -30,7 +29,7 @@ public class WatchManager<P, T> {
for (P watchPlugin : plugins) {
String pluginId = plugin.getPluginManager().getPluginId(watchPlugin);
if (watchTasks.containsKey(pluginId)) {
return new PluginWatchResults().add(WatchResult.ALREADY_WATCHING, Template.of("plugin", pluginId));
return new PluginWatchResults().add(WatchResult.ALREADY_WATCHING, "plugin", pluginId);
}
pluginIds.add(plugin.getPluginManager().getPluginId(watchPlugin));
@ -49,7 +48,7 @@ public class WatchManager<P, T> {
PluginWatchResults watchResults = new PluginWatchResults();
for (String pluginId : pluginIds) {
watchResults.add(WatchResult.START, Template.of("plugin", pluginId));
watchResults.add(WatchResult.START, "plugin", pluginId);
}
return watchResults;
}
@ -64,11 +63,11 @@ public class WatchManager<P, T> {
PluginWatchResults watchResults = new PluginWatchResults();
for (String pluginId : task.pluginIds) {
watchResults.add(WatchResult.START, Template.of("plugin", pluginId));
watchResults.add(WatchResult.START, "plugin", pluginId);
}
return watchResults;
}
return new PluginWatchResults().add(WatchResult.NOT_WATCHING, Template.of("plugin", associatedPluginId));
return new PluginWatchResults().add(WatchResult.NOT_WATCHING, "plugin", associatedPluginId);
}
private static final class WatchTask {