mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-03 14:38:56 +00:00
feat: add adventure lib
This commit is contained in:
3 files changed
+44
No files matched your search
@@ -135,6 +135,21 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.palmergames.bukkit.TownyChat;
|
package com.palmergames.bukkit.TownyChat;
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
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.ChannelCommand;
|
||||||
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
|
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
|
||||||
import com.palmergames.bukkit.TownyChat.Command.commandobjects.ChannelJoinAliasCommand;
|
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.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.dynmap.DynmapAPI;
|
import org.dynmap.DynmapAPI;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -57,6 +59,7 @@ public class Chat extends JavaPlugin {
|
|||||||
private Towny towny = null;
|
private Towny towny = null;
|
||||||
private DynmapAPI dynMap = null;
|
private DynmapAPI dynMap = null;
|
||||||
private Essentials essentials = null;
|
private Essentials essentials = null;
|
||||||
|
private BukkitAudiences adventure = null;
|
||||||
|
|
||||||
private static String requiredTownyVersion = "0.100.0.0";
|
private static String requiredTownyVersion = "0.100.0.0";
|
||||||
public static boolean usingPlaceholderAPI = false;
|
public static boolean usingPlaceholderAPI = false;
|
||||||
@@ -75,6 +78,7 @@ public class Chat extends JavaPlugin {
|
|||||||
pm = getServer().getPluginManager();
|
pm = getServer().getPluginManager();
|
||||||
channels = new ChannelsHolder(this);
|
channels = new ChannelsHolder(this);
|
||||||
playerChannelMap = new ConcurrentHashMap<>();
|
playerChannelMap = new ConcurrentHashMap<>();
|
||||||
|
adventure = BukkitAudiences.create(this);
|
||||||
|
|
||||||
checkPlugins();
|
checkPlugins();
|
||||||
if (towny == null || !townyVersionCheck()) {
|
if (towny == null || !townyVersionCheck()) {
|
||||||
@@ -125,11 +129,22 @@ public class Chat extends JavaPlugin {
|
|||||||
return chat;
|
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
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
unregisterPermissions();
|
unregisterPermissions();
|
||||||
// reset any handles
|
// reset any handles
|
||||||
|
|
||||||
|
if (adventure != null) {
|
||||||
|
adventure.close();
|
||||||
|
adventure = null;
|
||||||
|
}
|
||||||
dynMap = null;
|
dynMap = null;
|
||||||
towny = null;
|
towny = null;
|
||||||
pm = null;
|
pm = null;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.palmergames.bukkit.TownyChat.events;
|
package com.palmergames.bukkit.TownyChat.events;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.TownyChat.Chat;
|
||||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@@ -32,6 +34,7 @@ public class AsyncChatHookEvent extends Event {
|
|||||||
protected boolean changed;
|
protected boolean changed;
|
||||||
protected Channel channel;
|
protected Channel channel;
|
||||||
protected Set<Player> recipients;
|
protected Set<Player> recipients;
|
||||||
|
protected Audience audience;
|
||||||
|
|
||||||
public AsyncChatHookEvent(AsyncPlayerChatEvent event, Channel channel, boolean async) {
|
public AsyncChatHookEvent(AsyncPlayerChatEvent event, Channel channel, boolean async) {
|
||||||
super(async);
|
super(async);
|
||||||
@@ -39,6 +42,7 @@ public class AsyncChatHookEvent extends Event {
|
|||||||
this.changed = false;
|
this.changed = false;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.recipients = new HashSet<>(event.getRecipients());
|
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() {
|
public Channel getChannel() {
|
||||||
@@ -75,6 +79,10 @@ public class AsyncChatHookEvent extends Event {
|
|||||||
return this.recipients;
|
return this.recipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Audience getAudience() {
|
||||||
|
return this.audience;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return event.isCancelled();
|
return event.isCancelled();
|
||||||
}
|
}
|
||||||
@@ -87,6 +95,12 @@ public class AsyncChatHookEvent extends Event {
|
|||||||
changed = true;
|
changed = true;
|
||||||
this.recipients.clear();
|
this.recipients.clear();
|
||||||
this.recipients.addAll(recipients);
|
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) {
|
public void setFormat(String format) {
|
||||||
|
|||||||
Reference in new issue
Block a user