-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.wdsj.asw.listener; | ||
|
||
import io.wdsj.asw.setting.PluginSettings; | ||
import io.wdsj.asw.util.Utils; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.server.BroadcastMessageEvent; | ||
|
||
import java.util.List; | ||
|
||
import static io.wdsj.asw.AdvancedSensitiveWords.*; | ||
import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; | ||
import static io.wdsj.asw.util.Utils.messagesFilteredNum; | ||
|
||
public class BroadCastListener implements Listener { | ||
|
||
@EventHandler(priority = EventPriority.LOWEST) | ||
public void onBroadCast(BroadcastMessageEvent event) { | ||
if (!isInitialized || !settingsManager.getProperty(PluginSettings.CHAT_BROADCAST_CHECK)) return; | ||
String originalMessage = event.getMessage(); | ||
long startTime = System.currentTimeMillis(); | ||
List<String> censoredWordList = sensitiveWordBs.findAll(originalMessage); | ||
if (!censoredWordList.isEmpty()) { | ||
messagesFilteredNum.getAndIncrement(); | ||
String processedMessage = sensitiveWordBs.replace(originalMessage); | ||
if (settingsManager.getProperty(PluginSettings.CHAT_METHOD).equalsIgnoreCase("cancel")) { | ||
event.setCancelled(true); | ||
} else { | ||
event.setMessage(processedMessage); | ||
} | ||
if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { | ||
Utils.logViolation("服务器广播消息(IP: 无)(Chat)(BroadCast)", originalMessage + censoredWordList); | ||
} | ||
long endTime = System.currentTimeMillis(); | ||
addProcessStatistic(endTime, startTime); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters