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:
parent
0f9c6f4041
commit
11a5c5140b
10 changed files with 55 additions and 61 deletions
|
|
@ -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.events.PluginEvent;
|
||||
import net.frankheijden.serverutils.common.managers.AbstractPluginManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
|
|
@ -69,7 +68,7 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin, BukkitPlu
|
|||
return pluginResults.addResult(pluginId, Result.INVALID_DESCRIPTION);
|
||||
} catch (UnknownDependencyException ex) {
|
||||
return pluginResults.addResult(pluginId, Result.UNKNOWN_DEPENDENCY,
|
||||
Template.of("dependency", ex.getMessage())
|
||||
"dependency", ex.getMessage()
|
||||
);
|
||||
} catch (InvalidPluginException ex) {
|
||||
if (ex.getCause() instanceof IllegalArgumentException) {
|
||||
|
|
|
|||
|
|
@ -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!");
|
||||
public Component toComponent() {
|
||||
return this.component == null ? miniMessage.parse(messageString) : this.component;
|
||||
}
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ import net.frankheijden.serverutils.velocity.reflection.RVelocityEventManager;
|
|||
import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginContainer;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginManager;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityScheduler;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class VelocityPluginManager extends AbstractPluginManager<PluginContainer, VelocityPluginDescription> {
|
||||
|
|
@ -93,7 +92,7 @@ public class VelocityPluginManager extends AbstractPluginManager<PluginContainer
|
|||
dependency.getId()
|
||||
);
|
||||
return loadResults.addResult(description.getId(), Result.UNKNOWN_DEPENDENCY,
|
||||
Template.of("dependency", dependency.getId())
|
||||
"dependency", dependency.getId()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue