-
Notifications
You must be signed in to change notification settings - Fork 1
Add silent message moderation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: Build & Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Java 21 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '21' | ||
|
|
||
| - name: Build with Gradle | ||
| run: chmod +x gradlew && ./gradlew shadowJar | ||
|
|
||
| - name: Get version from tag | ||
| id: version | ||
| run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Create GitHub Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| name: "PixelChatGuardian v${{ steps.version.outputs.VERSION }}" | ||
| generate_release_notes: true | ||
| files: build/libs/PixelChatGuardian-*.jar |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,12 +83,24 @@ private void checkIfMessageShouldBeBlocked(@NotNull CarbonChatEvent event, @NotN | |
|
|
||
| // Check if classification matches any enabled blocking rules | ||
| if (ChatGuardHelper.messageMatchesEnabledRule(plugin, classification)) { | ||
| boolean blockOrCensor = plugin.getConfigHelper().getString(ConfigConstants.ChatGuard.MESSAGE_HANDLING).equals("BLOCK"); | ||
| if (blockOrCensor) event.cancelled(true); | ||
| else event.message(Component.text("*".repeat(message.length()))); | ||
| String messageHandling = plugin.getConfigHelper().getString(ConfigConstants.ChatGuard.MESSAGE_HANDLING); | ||
|
|
||
| switch (messageHandling) { | ||
| case "BLOCK" -> event.cancelled(true); | ||
| case "SILENT" -> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| // Cancel the event so no other players see the message | ||
| event.cancelled(true); | ||
| // Send the original message back to the author, creating the illusion of successful delivery | ||
| Player senderPlayer = Bukkit.getPlayer(event.sender().uuid()); | ||
| if (senderPlayer != null) | ||
| senderPlayer.sendMessage("<" + senderPlayer.getDisplayName() + "> " + message); | ||
| } | ||
| default -> // CENSOR | ||
| event.message(Component.text("*".repeat(message.length()))); | ||
| } | ||
|
|
||
| Player player = Bukkit.getPlayer(event.sender().uuid()); | ||
| if (player != null) ChatGuardHelper.notifyAndStrikePlayer(plugin, player, message, classification, blockOrCensor); | ||
| if (player != null) ChatGuardHelper.notifyAndStrikePlayer(plugin, player, message, classification, messageHandling); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,12 +117,12 @@ private void onAsyncPlayerChat(@NotNull AsyncPlayerChatEvent event) { | |
| } | ||
|
|
||
| /** | ||
| * Checks whether a message should be blocked or censored and takes appropriate actions | ||
| * Checks whether a message should be blocked, censored, or silently moderated and takes appropriate actions | ||
| * | ||
| * @param event The message event | ||
| * @param message The message to check | ||
| * @param player The player that sent the message | ||
| * @return {@code true} if the message has been blocked, {@code false} if it has been allowed through | ||
| * @return {@code true} if the message has been blocked or silently moderated, {@code false} if it has been allowed through | ||
| */ | ||
| private boolean checkIfMessageShouldBeBlocked(@NotNull AsyncPlayerChatEvent event, @NotNull String message, @NotNull Player player) { | ||
| // Debug logger message | ||
|
|
@@ -138,13 +138,24 @@ private boolean checkIfMessageShouldBeBlocked(@NotNull AsyncPlayerChatEvent even | |
|
|
||
| // Check if classification matches any enabled blocking rules | ||
| if (ChatGuardHelper.messageMatchesEnabledRule(plugin, classification)) { | ||
| boolean blockOrCensor = plugin.getConfigHelper().getString(ConfigConstants.ChatGuard.MESSAGE_HANDLING).equals("BLOCK"); | ||
| if (blockOrCensor) event.setCancelled(true); | ||
| else event.setMessage("*".repeat(message.length())); | ||
| String messageHandling = plugin.getConfigHelper().getString(ConfigConstants.ChatGuard.MESSAGE_HANDLING); | ||
|
|
||
| switch (messageHandling) { | ||
| case "BLOCK" -> event.setCancelled(true); | ||
| case "SILENT" -> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // Cancel the event so no other players see the message | ||
| event.setCancelled(true); | ||
| // Send the message back to the author using the chat format, creating the illusion of successful delivery | ||
| String fakeMessage = String.format(event.getFormat(), player.getDisplayName(), message); | ||
| player.sendMessage(fakeMessage); | ||
| } | ||
| default -> // CENSOR | ||
| event.setMessage("*".repeat(message.length())); | ||
| } | ||
|
|
||
| ChatGuardHelper.notifyAndStrikePlayer(plugin, player, message, classification, blockOrCensor); | ||
| ChatGuardHelper.notifyAndStrikePlayer(plugin, player, message, classification, messageHandling); | ||
|
|
||
| return true; // Message has been blocked or censored | ||
| return true; // Message has been blocked, censored, or silently moderated | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,12 +32,12 @@ private ChatGuardHelper() { | |
| /** | ||
| * Notifies the player of their message being blocked, logs the block itself, and also applies the strike system | ||
| * | ||
| * @param player The player that sent the message | ||
| * @param userMessage The message that the user sent | ||
| * @param classification The classification of the message | ||
| * @param blockOrCensor Whether the message should be blocked ({@code true}) or censored ({@code false}) | ||
| * @param player The player that sent the message | ||
| * @param userMessage The message that the user sent | ||
| * @param classification The classification of the message | ||
| * @param messageHandling The message handling mode: "BLOCK", "CENSOR", or "SILENT" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| */ | ||
| public static void notifyAndStrikePlayer(@NotNull PixelChat plugin, @NotNull Player player, @NotNull String userMessage, @NotNull MessageClassification classification, boolean blockOrCensor) { | ||
| public static void notifyAndStrikePlayer(@NotNull PixelChat plugin, @NotNull Player player, @NotNull String userMessage, @NotNull MessageClassification classification, @NotNull String messageHandling) { | ||
| // Debug logger message | ||
| plugin.getLoggingHelper().debug("Notify player"); | ||
|
|
||
|
|
@@ -47,13 +47,17 @@ public static void notifyAndStrikePlayer(@NotNull PixelChat plugin, @NotNull Pla | |
| chatGuardPrefix = plugin.getConfigHelper().getString(ConfigConstants.ChatGuard.CustomPrefix.FORMAT) + ChatColor.RESET + " "; | ||
| } else chatGuardPrefix = LangConstants.PLUGIN_PREFIX; | ||
|
|
||
| if (plugin.getConfigHelper().getBoolean(ConfigConstants.ChatGuard.NOTIFY_USER)) player.sendMessage(chatGuardPrefix + | ||
| plugin.getConfigHelperLanguage() | ||
| .getString(blockOrCensor ? LangConstants.ChatGuard.MESSAGE_BLOCKED : LangConstants.ChatGuard.MESSAGE_CENSORED) + | ||
| " " + ChatColor.RED + classification.reason()); | ||
| if (plugin.getConfigHelper().getBoolean(ConfigConstants.ChatGuard.NOTIFY_USER) && !messageHandling.equals("SILENT")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| String langKey = messageHandling.equals("BLOCK") ? LangConstants.ChatGuard.MESSAGE_BLOCKED : LangConstants.ChatGuard.MESSAGE_CENSORED; | ||
| player.sendMessage(chatGuardPrefix + plugin.getConfigHelperLanguage().getString(langKey) + " " + ChatColor.RED + classification.reason()); | ||
| } | ||
|
|
||
| plugin.getLoggingHelper() | ||
| .info("Message by " + player.getName() + (blockOrCensor ? " has been blocked: " : " has been censored: ") + userMessage); | ||
| String action = switch (messageHandling) { | ||
| case "BLOCK" -> "blocked"; | ||
| case "SILENT" -> "silently moderated"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| default -> "censored"; | ||
| }; | ||
| plugin.getLoggingHelper().info("Message by " + player.getName() + " has been " + action + ": " + userMessage); | ||
|
|
||
| if (!classification.isOffensiveLanguage()) return; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,7 +150,8 @@ chatguard: | |
|
|
||
| # Message handling configuration | ||
| # Default: CENSOR | ||
| # Options: Censor, BLOCK | ||
| # Options: CENSOR, BLOCK, SILENT | ||
| # SILENT: The message is only visible to the sender, creating the illusion of successful delivery | ||
|
Comment on lines
+153
to
+154
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| message-handling: CENSOR | ||
|
|
||
| # Notify user when message is blocked/censored | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice but we don't really need this at the current stage in the project, doing it manually is trivial as of now