diff --git a/pom.xml b/pom.xml
index 72bdc24..410c5f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
com.palmergames.bukkit
TownyChat
jar
- 0.116
+ 0.117
@@ -26,7 +26,7 @@
17
1.16
UTF-8
- 0.100.3.0
+ 0.100.4.0
diff --git a/resources/changelog.txt b/resources/changelog.txt
index a22b1d4..47b94d5 100644
--- a/resources/changelog.txt
+++ b/resources/changelog.txt
@@ -500,4 +500,15 @@ v0.116:
- When a channel has ignoreable: false, players will not be able to ignore the channel.
- Ignoring channels is achieved by using /res toggle ignoreotherchannels. When this mode is used you will only see the channel you are present in.
- ie: if you are in town chat, with ignoreotherchannels active, you will not see the general, nation or local chats.
- - Closes https://github.com/TownyAdvanced/Towny/issues/6441.
\ No newline at end of file
+ - Closes https://github.com/TownyAdvanced/Towny/issues/6441.
+0.117:
+ - Bump min Towny version to 0.100.3.0.
+ - Add the ability to choose which EventPriority TownyChat uses to modify chat.
+ - Closes https://github.com/TownyAdvanced/Towny/issues/7625.
+ - New ChatConfig.yml Option: modify_chat.listener_priority
+ - Default: normal
+ - The priority used for the AsyncPlayerChatEvent listener in TownyChat. This option will decide when TownyChat listens to the Chat event thrown by Bukkit-based servers.
+ - Valid settings are: lowest, low, normal, high, highest
+ - Lowest is the earliest listener, allowing TownyChat to act upon chat before Low, Normal, High, and Highest priority plugins.
+ - Highest will cause TownyChat to change chat after other plugins operating on lower priorities.
+ - If you don't know what any of this means leave it at normal.
\ No newline at end of file
diff --git a/src/com/palmergames/bukkit/TownyChat/Chat.java b/src/com/palmergames/bukkit/TownyChat/Chat.java
index d10fb36..67aa934 100644
--- a/src/com/palmergames/bukkit/TownyChat/Chat.java
+++ b/src/com/palmergames/bukkit/TownyChat/Chat.java
@@ -58,7 +58,7 @@ public class Chat extends JavaPlugin {
private DynmapAPI dynMap = null;
private Essentials essentials = null;
- private static String requiredTownyVersion = "0.100.3.0";
+ private static String requiredTownyVersion = "0.100.4.0";
public static boolean usingPlaceholderAPI = false;
public static boolean usingEssentialsDiscord = false;
boolean chatConfigError = false;
diff --git a/src/com/palmergames/bukkit/TownyChat/config/ChatConfigNodes.java b/src/com/palmergames/bukkit/TownyChat/config/ChatConfigNodes.java
index be3bc04..5316036 100644
--- a/src/com/palmergames/bukkit/TownyChat/config/ChatConfigNodes.java
+++ b/src/com/palmergames/bukkit/TownyChat/config/ChatConfigNodes.java
@@ -142,6 +142,15 @@ public enum ChatConfigNodes {
"modify_chat",
"",
""),
+ MODIFY_CHAT_LISTENER_PRIORITY(
+ "modify_chat.listener_priority",
+ "normal",
+ "",
+ "# The priority used for the AsyncPlayerChatEvent listener in TownyChat. This option will decide when TownyChat listens to the Chat event thrown by Bukkit-based servers.",
+ "# Valid settings are: lowest, low, normal, high, highest",
+ "# Lowest is the earliest listener, allowing TownyChat to act upon chat before Low, Normal, High, and Highest priority plugins.",
+ "# Highest will cause TownyChat to change chat after other plugins operating on lower priorities.",
+ "# If you don't know what any of this means leave it at normal."),
MODIFY_CHAT_ENABLE(
"modify_chat.enable",
"true",
diff --git a/src/com/palmergames/bukkit/TownyChat/config/ChatSettings.java b/src/com/palmergames/bukkit/TownyChat/config/ChatSettings.java
index d6502b8..3132571 100644
--- a/src/com/palmergames/bukkit/TownyChat/config/ChatSettings.java
+++ b/src/com/palmergames/bukkit/TownyChat/config/ChatSettings.java
@@ -184,6 +184,14 @@ public static boolean isExclamationPoint() {
return getBoolean(ChatConfigNodes.ALLOW_EXCLAMATION_POINT_SHOUTS);
}
+ public static String getChatListenerPriority() {
+ String priority = getString(ChatConfigNodes.MODIFY_CHAT_LISTENER_PRIORITY).toLowerCase(Locale.ROOT);
+ return switch(priority) {
+ case "lowest","low","normal","high","highest"-> priority;
+ default -> "normal";
+ };
+ }
+
/*
* Get Tags formats.
*/
diff --git a/src/com/palmergames/bukkit/TownyChat/listener/TownyChatPlayerListener.java b/src/com/palmergames/bukkit/TownyChat/listener/TownyChatPlayerListener.java
index bcb9f48..82dab93 100644
--- a/src/com/palmergames/bukkit/TownyChat/listener/TownyChatPlayerListener.java
+++ b/src/com/palmergames/bukkit/TownyChat/listener/TownyChatPlayerListener.java
@@ -63,9 +63,39 @@ public void onPlayerQuit(final PlayerQuitEvent event) {
private void refreshPlayerChannels(Player player) {
plugin.getChannelsHandler().getAllChannels().values().stream().forEach(channel -> channel.forgetPlayer(player));
}
-
+
+ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
+ public void onLowestPlayerChat(AsyncPlayerChatEvent event) {
+ if (ChatSettings.getChatListenerPriority().equalsIgnoreCase("lowest"))
+ handleChatEvent(event);
+ }
+
+ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
+ public void onLowPlayerChat(AsyncPlayerChatEvent event) {
+ if (ChatSettings.getChatListenerPriority().equalsIgnoreCase("low"))
+ handleChatEvent(event);
+ }
+
@EventHandler(ignoreCancelled = true)
- public void onPlayerChat(AsyncPlayerChatEvent event) {
+ public void onNormalPlayerChat(AsyncPlayerChatEvent event) {
+ if (ChatSettings.getChatListenerPriority().equalsIgnoreCase("normal"))
+ handleChatEvent(event);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onHighPlayerChat(AsyncPlayerChatEvent event) {
+ if (ChatSettings.getChatListenerPriority().equalsIgnoreCase("high"))
+ handleChatEvent(event);
+ }
+
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onHighestPlayerChat(AsyncPlayerChatEvent event) {
+ if (ChatSettings.getChatListenerPriority().equalsIgnoreCase("highest"))
+ handleChatEvent(event);
+ }
+
+ private void handleChatEvent(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
// Check if the message contains colour codes we need to remove or parse.