Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add more debug messages and allow dynamic EventPriority setting #80

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<name>ChatEx</name>
<inceptionYear>2022</inceptionYear>

<version>2.8.9</version>
<version>2.9.0</version>
<description>ChatManagement plugin for Bukkit</description>
<url>https://www.spigotmc.org/resources/chatex-continued.71041/</url>

Expand Down Expand Up @@ -40,7 +40,11 @@
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>de.jeter.chatex</shadedPattern>
<shadedPattern>de.jeter.chatex.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>de.jeter.updatechecker</pattern>
<shadedPattern>de.jeter.chatex.updatechecker</shadedPattern>
</relocation>
</relocations>
</configuration>
Expand Down
60 changes: 59 additions & 1 deletion src/main/java/de/jeter/chatex/ChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,51 @@ public class ChatListener implements Listener {
private final AdManager adManager = Config.ADS_SMART_MANAGER.getBoolean() ? new SmartAdManager() : new SimpleAdManager();
private final BlockedWords blockedWords = new BlockedWords();


@EventHandler(priority = EventPriority.LOWEST)
public void onLowest(final AsyncPlayerChatEvent event) {
if (Config.PRIORITY.getString().equalsIgnoreCase("LOWEST")) {
executeChatEvent(event);
}
}

@EventHandler(priority = EventPriority.LOW)
public void onLow(final AsyncPlayerChatEvent event) {
if (Config.PRIORITY.getString().equalsIgnoreCase("LOW")) {
executeChatEvent(event);
}
}

@EventHandler(priority = EventPriority.NORMAL)
public void onNormal(final AsyncPlayerChatEvent event) {
if (Config.PRIORITY.getString().equalsIgnoreCase("NORMAL")) {
executeChatEvent(event);
}
}

@EventHandler(priority = EventPriority.HIGH)
public void onHigh(final AsyncPlayerChatEvent event) {
if (Config.PRIORITY.getString().equalsIgnoreCase("HIGH")) {
executeChatEvent(event);
}
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(final AsyncPlayerChatEvent event) {
public void onHighest(final AsyncPlayerChatEvent event) {
if (Config.PRIORITY.getString().equalsIgnoreCase("HIGHEST")) {
executeChatEvent(event);
}
}

@EventHandler(priority = EventPriority.MONITOR)
public void onMonitor(final AsyncPlayerChatEvent event) {
if (Config.PRIORITY.getString().equalsIgnoreCase("MONITOR")) {
executeChatEvent(event);
}
}

private void executeChatEvent(AsyncPlayerChatEvent event) {
LogHelper.debug("ChatEvent fired with priority: " + Config.PRIORITY.getString().toUpperCase() + ", ChatEx reacting to it...");
Player player = event.getPlayer();

if (!player.hasPermission("chatex.allowchat")) {
Expand All @@ -53,6 +96,9 @@ public void onChat(final AsyncPlayerChatEvent event) {
}

String format = PluginManager.getInstance().getMessageFormat(event.getPlayer());
LogHelper.debug("Format: " + format);
LogHelper.debug("Prefix: " + PluginManager.getInstance().getPrefix(event.getPlayer()));
LogHelper.debug("Suffix: " + PluginManager.getInstance().getSuffix(event.getPlayer()));

String chatMessage = event.getMessage();

Expand All @@ -70,6 +116,8 @@ public void onChat(final AsyncPlayerChatEvent event) {
}
AntiSpamManager.getInstance().put(player);

LogHelper.debug("Player did not activate the AntiSpam. Continuing...");

if (adManager.checkForAds(chatMessage, player)) {
String message = Locales.MESSAGES_AD.getString(null).replaceAll("%perm", "chatex.bypassads");
MessageBlockedByAdManagerEvent messageBlockedByAdManagerEvent = new MessageBlockedByAdManagerEvent(player, chatMessage, message);
Expand All @@ -82,6 +130,8 @@ public void onChat(final AsyncPlayerChatEvent event) {
}
}

LogHelper.debug("Player did not activate the AdBlocker. Continuing...");

if (blockedWords.isBlocked(chatMessage)) {
String message = Locales.MESSAGES_BLOCKED.getString(null);
MessageContainsBlockedWordEvent messageContainsBlockedWordEvent = new MessageContainsBlockedWordEvent(player, chatMessage, message);
Expand All @@ -94,9 +144,12 @@ public void onChat(final AsyncPlayerChatEvent event) {
}
}

LogHelper.debug("Player did not use a blocked word. Continuing...");

boolean global = false;
if (Config.RANGEMODE.getBoolean() || Config.BUNGEECORD.getBoolean()) {
if (chatMessage.startsWith(Config.RANGEPREFIX.getString())) {
LogHelper.debug("Global mode enabled!");
if (player.hasPermission("chatex.chat.global")) {
chatMessage = chatMessage.replaceFirst(Pattern.quote(Config.RANGEPREFIX.getString()), "");
format = PluginManager.getInstance().getGlobalMessageFormat(player);
Expand All @@ -117,6 +170,7 @@ public void onChat(final AsyncPlayerChatEvent event) {
}
} else {
if (Config.RANGEMODE.getBoolean()) {
LogHelper.debug("Range mode enabled!");
event.getRecipients().clear();
if (Utils.getLocalRecipients(player).size() == 1 && Config.SHOW_NO_RECEIVER_MSG.getBoolean()) {
player.sendMessage(Locales.NO_LISTENING_PLAYERS.getString(player));
Expand All @@ -138,13 +192,16 @@ public void onChat(final AsyncPlayerChatEvent event) {
}

if (global && Config.BUNGEECORD.getBoolean()) {
LogHelper.debug("Local mode & Bungeecord mode enabled! Spreading Cross server message...");
String msgToSend = Utils.replacePlayerPlaceholders(player, format.replaceAll("%message", Matcher.quoteReplacement(chatMessage)));
ChannelHandler.getInstance().sendMessage(player, msgToSend);
}

LogHelper.debug("Replacing Placeholder in format...");
format = Utils.replacePlayerPlaceholders(player, format);
format = Utils.escape(format);
format = format.replace("%%message", "%2$s");
LogHelper.debug("Format after replacing: " + format);


try {
Expand All @@ -158,6 +215,7 @@ public void onChat(final AsyncPlayerChatEvent event) {

event.setMessage(Utils.translateColorCodes(chatMessage, player));
ChatLogger.writeToFile(player, chatMessage);
LogHelper.debug("Everything done! Method end.");
}

}
2 changes: 2 additions & 0 deletions src/main/java/de/jeter/chatex/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.jeter.chatex.ChatEx;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventPriority;

import java.io.File;
import java.io.IOException;
Expand All @@ -44,6 +45,7 @@ public enum Config {
RANGE("chat-range", 100, "The range to talk to other players. Set to -1 to enable world-wide-chat"),
LOGCHAT("logChat", false, "Should the chat be logged?"),
DEBUG("debug", false, "Should the debug log be enabled?"),
PRIORITY("EventPriority", EventPriority.NORMAL.name(), "Choose the Eventpriority here of ChatEx. Listeners are called in following order: LOWEST -> LOW -> NORMAL -> HIGH -> HIGHEST -> MONITOR"),
LOCALE("Locale", "en-EN", "Which language do you want? (You can choose betwenn de-DE, fr-FR, pt-BR, zh-CN and en-EN by default.)"),
ADS_ENABLED("Ads.Enabled", true, "Should we check for ads?"),
ADS_BYPASS("Ads.Bypass", Arrays.asList("127.0.0.1", "my-domain.com"), "A list with allowed ips or domains."),
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/jeter/chatex/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public static String replacePlayerPlaceholders(Player player, String format) {
String result = format;

if (HookManager.checkPlaceholderAPI()) {
LogHelper.debug("PlaceholderAPI is installed! Replacing...");
result = PlaceholderAPI.setPlaceholders(player, result);
LogHelper.debug("Result: " + result);
}

if ((HookManager.checkEssentials() || HookManager.checkPurpur()) && Config.AFK_PLACEHOLDER.getBoolean()) {
Expand Down