feat: add adventure lib

This commit is contained in:
darksaid98 committed 2024-01-24 20:51:33 +01:00
1 parent 465400dfd5
commit 45e5f33410
3 files changed
+44

No files matched your search

+15
View File
@@ -135,6 +135,21 @@
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId>
<version>4.14.0</version>
</dependency>
</dependencies>
<build>
@@ -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;
@@ -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<Player> 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<Player> 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) {