Skip to content

Commit

Permalink
- Bump min Towny version to 0.100.3.0. (#60)
Browse files Browse the repository at this point in the history
- Add the ability to choose which EventPriority TownyChat uses to
modify chat.
    - Closes TownyAdvanced/Towny#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.
  • Loading branch information
LlmDl authored Oct 17, 2024
1 parent 18ac6bb commit 5b27163
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.palmergames.bukkit</groupId>
<artifactId>TownyChat</artifactId>
<packaging>jar</packaging>
<version>0.116</version>
<version>0.117</version>

<licenses>
<license>
Expand All @@ -26,7 +26,7 @@
<java.version>17</java.version>
<project.bukkitAPIVersion>1.16</project.bukkitAPIVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<towny.version>0.100.3.0</towny.version>
<towny.version>0.100.4.0</towny.version>
</properties>

<!-- For use with GitHub Package Registry -->
Expand Down
13 changes: 12 additions & 1 deletion resources/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- 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.
2 changes: 1 addition & 1 deletion src/com/palmergames/bukkit/TownyChat/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/com/palmergames/bukkit/TownyChat/config/ChatSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5b27163

Please sign in to comment.