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

@ -31,7 +31,6 @@ import net.frankheijden.serverutils.common.entities.results.Result;
import net.frankheijden.serverutils.common.entities.exceptions.InvalidPluginDescriptionException; import net.frankheijden.serverutils.common.entities.exceptions.InvalidPluginDescriptionException;
import net.frankheijden.serverutils.common.events.PluginEvent; import net.frankheijden.serverutils.common.events.PluginEvent;
import net.frankheijden.serverutils.common.managers.AbstractPluginManager; import net.frankheijden.serverutils.common.managers.AbstractPluginManager;
import net.kyori.adventure.text.minimessage.Template;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -69,7 +68,7 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin, BukkitPlu
return pluginResults.addResult(pluginId, Result.INVALID_DESCRIPTION); return pluginResults.addResult(pluginId, Result.INVALID_DESCRIPTION);
} catch (UnknownDependencyException ex) { } catch (UnknownDependencyException ex) {
return pluginResults.addResult(pluginId, Result.UNKNOWN_DEPENDENCY, return pluginResults.addResult(pluginId, Result.UNKNOWN_DEPENDENCY,
Template.of("dependency", ex.getMessage()) "dependency", ex.getMessage()
); );
} catch (InvalidPluginException ex) { } catch (InvalidPluginException ex) {
if (ex.getCause() instanceof IllegalArgumentException) { if (ex.getCause() instanceof IllegalArgumentException) {

View file

@ -1,6 +1,5 @@
package net.frankheijden.serverutils.common.config; package net.frankheijden.serverutils.common.config;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -61,19 +60,22 @@ public class MessagesResource extends ServerUtilsResource {
/** /**
* Creates a {@link Component}. * Creates a {@link Component}.
*/ */
public Component toComponent(Template... placeholders) { public Component toComponent() {
if (this.component == null) { return this.component == null ? miniMessage.parse(messageString) : this.component;
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" * Creates a {@link Component}.
+ " but the following placeholders were provided: " + Arrays.toString(placeholders)); */
} else { public Component toComponent(Template... templates) {
return this.component; 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) { public void sendTo(ServerUtilsAudience<?> serverAudience, Template... placeholders) {

View file

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

View file

@ -3,7 +3,6 @@ package net.frankheijden.serverutils.common.entities.results;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import net.kyori.adventure.text.minimessage.Template;
public class CloseablePluginResults<T> extends PluginResults<T> implements Closeable { public class CloseablePluginResults<T> extends PluginResults<T> implements Closeable {
@ -17,21 +16,21 @@ public class CloseablePluginResults<T> extends PluginResults<T> implements Close
} }
@Override @Override
public CloseablePluginResults<T> addResult(String pluginId, Result result, Template... templates) { public CloseablePluginResults<T> addResult(String pluginId, Result result, String... placeholders) {
super.addResult(pluginId, result, templates); super.addResult(pluginId, result, placeholders);
return this; return this;
} }
@Override @Override
public CloseablePluginResults<T> addResult(String pluginId, T plugin, Template... templates) { public CloseablePluginResults<T> addResult(String pluginId, T plugin, String... placeholders) {
super.addResult(pluginId, plugin, templates); super.addResult(pluginId, plugin, placeholders);
return this; return this;
} }
@Override @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; return this;
} }
@ -39,9 +38,9 @@ public class CloseablePluginResults<T> extends PluginResults<T> implements Close
String pluginId, String pluginId,
T plugin, T plugin,
List<Closeable> closeables, 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 @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.ServerUtilsApp;
import net.frankheijden.serverutils.common.config.ConfigKey; import net.frankheijden.serverutils.common.config.ConfigKey;
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience; import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
import net.kyori.adventure.text.minimessage.Template;
public class PluginResult<T> implements AbstractResult { public class PluginResult<T> implements AbstractResult {
private final String pluginId; private final String pluginId;
private final T plugin; private final T plugin;
private final Result result; private final Result result;
private final Template[] templates; private final String[] placeholders;
public PluginResult(String pluginId, Result result) { public PluginResult(String pluginId, Result result) {
this(pluginId, null, result); this(pluginId, null, result);
@ -19,13 +18,14 @@ public class PluginResult<T> implements AbstractResult {
/** /**
* Constructs a new PluginResult. * 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.pluginId = pluginId;
this.plugin = plugin; this.plugin = plugin;
this.result = result; this.result = result;
this.templates = new Template[templates.length + 1]; this.placeholders = new String[placeholders.length + 2];
this.templates[0] = Template.of("plugin", pluginId); this.placeholders[0] = "plugin";
System.arraycopy(templates, 0, this.templates, 1, templates.length); this.placeholders[1] = pluginId;
System.arraycopy(placeholders, 0, this.placeholders, 2, placeholders.length);
} }
public String getPluginId() { public String getPluginId() {
@ -40,8 +40,8 @@ public class PluginResult<T> implements AbstractResult {
return result; return result;
} }
public Template[] getTemplates() { public String[] getPlaceholders() {
return templates; return placeholders;
} }
public boolean isSuccess() { public boolean isSuccess() {
@ -50,7 +50,7 @@ public class PluginResult<T> implements AbstractResult {
public void sendTo(ServerUtilsAudience<?> sender, ConfigKey successKey) { public void sendTo(ServerUtilsAudience<?> sender, ConfigKey successKey) {
ConfigKey key = isSuccess() ? successKey : result.getKey(); 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 @Override

View file

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

View file

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

View file

@ -6,7 +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.minimessage.Template;
public class PluginWatchResults implements Iterable<PluginWatchResult> { public class PluginWatchResults implements Iterable<PluginWatchResult> {
@ -16,8 +15,8 @@ public class PluginWatchResults implements Iterable<PluginWatchResult> {
this.watchResults = new ArrayList<>(); this.watchResults = new ArrayList<>();
} }
public PluginWatchResults add(WatchResult result, Template... templates) { public PluginWatchResults add(WatchResult result, String... placeholders) {
return add(new PluginWatchResult(result, templates)); return add(new PluginWatchResult(result, placeholders));
} }
public PluginWatchResults add(PluginWatchResult watchResult) { public PluginWatchResults add(PluginWatchResult watchResult) {
@ -32,7 +31,7 @@ public class PluginWatchResults implements Iterable<PluginWatchResult> {
MessagesResource messages = ServerUtilsApp.getPlugin().getMessagesResource(); MessagesResource messages = ServerUtilsApp.getPlugin().getMessagesResource();
for (PluginWatchResult watchResult : watchResults) { 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.PluginWatchResults;
import net.frankheijden.serverutils.common.entities.results.WatchResult; import net.frankheijden.serverutils.common.entities.results.WatchResult;
import net.frankheijden.serverutils.common.tasks.PluginWatcherTask; import net.frankheijden.serverutils.common.tasks.PluginWatcherTask;
import net.kyori.adventure.text.minimessage.Template;
public class WatchManager<P, T> { public class WatchManager<P, T> {
@ -30,7 +29,7 @@ public class WatchManager<P, T> {
for (P watchPlugin : plugins) { for (P watchPlugin : plugins) {
String pluginId = plugin.getPluginManager().getPluginId(watchPlugin); String pluginId = plugin.getPluginManager().getPluginId(watchPlugin);
if (watchTasks.containsKey(pluginId)) { 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)); pluginIds.add(plugin.getPluginManager().getPluginId(watchPlugin));
@ -49,7 +48,7 @@ public class WatchManager<P, T> {
PluginWatchResults watchResults = new PluginWatchResults(); PluginWatchResults watchResults = new PluginWatchResults();
for (String pluginId : pluginIds) { for (String pluginId : pluginIds) {
watchResults.add(WatchResult.START, Template.of("plugin", pluginId)); watchResults.add(WatchResult.START, "plugin", pluginId);
} }
return watchResults; return watchResults;
} }
@ -64,11 +63,11 @@ public class WatchManager<P, T> {
PluginWatchResults watchResults = new PluginWatchResults(); PluginWatchResults watchResults = new PluginWatchResults();
for (String pluginId : task.pluginIds) { for (String pluginId : task.pluginIds) {
watchResults.add(WatchResult.START, Template.of("plugin", pluginId)); watchResults.add(WatchResult.START, "plugin", pluginId);
} }
return watchResults; 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 { private static final class WatchTask {

View file

@ -44,7 +44,6 @@ import net.frankheijden.serverutils.velocity.reflection.RVelocityEventManager;
import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginContainer; import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginContainer;
import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginManager; import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginManager;
import net.frankheijden.serverutils.velocity.reflection.RVelocityScheduler; import net.frankheijden.serverutils.velocity.reflection.RVelocityScheduler;
import net.kyori.adventure.text.minimessage.Template;
import org.slf4j.Logger; import org.slf4j.Logger;
public class VelocityPluginManager extends AbstractPluginManager<PluginContainer, VelocityPluginDescription> { public class VelocityPluginManager extends AbstractPluginManager<PluginContainer, VelocityPluginDescription> {
@ -93,7 +92,7 @@ public class VelocityPluginManager extends AbstractPluginManager<PluginContainer
dependency.getId() dependency.getId()
); );
return loadResults.addResult(description.getId(), Result.UNKNOWN_DEPENDENCY, return loadResults.addResult(description.getId(), Result.UNKNOWN_DEPENDENCY,
Template.of("dependency", dependency.getId()) "dependency", dependency.getId()
); );
} }
} }