diff --git a/pom.xml b/pom.xml
index e99fab4..24149c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -135,6 +135,21 @@
1.0.0
provided
+
+ net.kyori
+ adventure-api
+ 4.14.0
+
+
+ net.kyori
+ adventure-text-minimessage
+ 4.14.0
+
+
+ net.kyori
+ adventure-text-serializer-legacy
+ 4.14.0
+
diff --git a/src/com/palmergames/bukkit/TownyChat/Chat.java b/src/com/palmergames/bukkit/TownyChat/Chat.java
index d80f0bb..2ce4329 100644
--- a/src/com/palmergames/bukkit/TownyChat/Chat.java
+++ b/src/com/palmergames/bukkit/TownyChat/Chat.java
@@ -1,6 +1,7 @@
package com.palmergames.bukkit.TownyChat;
import com.earth2me.essentials.Essentials;
+import com.palmergames.adventure.platform.bukkit.BukkitAudiences;
import com.palmergames.bukkit.TownyChat.Command.ChannelCommand;
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
import com.palmergames.bukkit.TownyChat.Command.commandobjects.ChannelJoinAliasCommand;
@@ -27,6 +28,7 @@ import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
+import org.checkerframework.checker.nullness.qual.NonNull;
import org.dynmap.DynmapAPI;
import java.io.File;
@@ -57,6 +59,7 @@ public class Chat extends JavaPlugin {
private Towny towny = null;
private DynmapAPI dynMap = null;
private Essentials essentials = null;
+ private BukkitAudiences adventure = null;
private static String requiredTownyVersion = "0.100.0.0";
public static boolean usingPlaceholderAPI = false;
@@ -75,6 +78,7 @@ public class Chat extends JavaPlugin {
pm = getServer().getPluginManager();
channels = new ChannelsHolder(this);
playerChannelMap = new ConcurrentHashMap<>();
+ adventure = BukkitAudiences.create(this);
checkPlugins();
if (towny == null || !townyVersionCheck()) {
@@ -125,11 +129,22 @@ public class Chat extends JavaPlugin {
return chat;
}
+ public @NonNull BukkitAudiences adventure() {
+ if(this.adventure == null) {
+ throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
+ }
+ return this.adventure;
+ }
+
@Override
public void onDisable() {
unregisterPermissions();
// reset any handles
+ if (adventure != null) {
+ adventure.close();
+ adventure = null;
+ }
dynMap = null;
towny = null;
pm = null;
diff --git a/src/com/palmergames/bukkit/TownyChat/events/AsyncChatHookEvent.java b/src/com/palmergames/bukkit/TownyChat/events/AsyncChatHookEvent.java
index 8e6f0bb..034de97 100644
--- a/src/com/palmergames/bukkit/TownyChat/events/AsyncChatHookEvent.java
+++ b/src/com/palmergames/bukkit/TownyChat/events/AsyncChatHookEvent.java
@@ -1,6 +1,8 @@
package com.palmergames.bukkit.TownyChat.events;
+import com.palmergames.bukkit.TownyChat.Chat;
import com.palmergames.bukkit.TownyChat.channels.Channel;
+import net.kyori.adventure.audience.Audience;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@@ -32,6 +34,7 @@ public class AsyncChatHookEvent extends Event {
protected boolean changed;
protected Channel channel;
protected Set recipients;
+ protected Audience audience;
public AsyncChatHookEvent(AsyncPlayerChatEvent event, Channel channel, boolean async) {
super(async);
@@ -39,6 +42,7 @@ public class AsyncChatHookEvent extends Event {
this.changed = false;
this.channel = channel;
this.recipients = new HashSet<>(event.getRecipients());
+ this.audience = Audience.audience(getRecipients().stream().map(player -> Chat.getTownyChat().adventure().player(player)).toArray(Audience[]::new));
}
public Channel getChannel() {
@@ -74,6 +78,10 @@ public class AsyncChatHookEvent extends Event {
public Set getRecipients() {
return this.recipients;
}
+
+ public Audience getAudience() {
+ return this.audience;
+ }
public boolean isCancelled() {
return event.isCancelled();
@@ -87,6 +95,12 @@ public class AsyncChatHookEvent extends Event {
changed = true;
this.recipients.clear();
this.recipients.addAll(recipients);
+ setAudience(Audience.audience(this.recipients.stream().map(player -> Chat.getTownyChat().adventure().player(player)).toArray(Audience[]::new))); // Update audience as well
+ }
+
+ public void setAudience(Audience audience) {
+ changed = true;
+ this.audience = audience;
}
public void setFormat(String format) {