Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: YouHaveTrouble/Censura
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: ForgeMC/ForgeCensura
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 8 commits
  • 13 files changed
  • 1 contributor

Commits on Dec 17, 2021

  1. docs: 📝 update readme

    konhi committed Dec 17, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c733636 View commit details
  2. chore: 🔧 update config

    konhi committed Dec 17, 2021
    Copy the full SHA
    7f14bf6 View commit details
  3. Copy the full SHA
    66eda69 View commit details

Commits on Dec 18, 2021

  1. feat: ✨ kurwa

    konhi committed Dec 18, 2021
    Copy the full SHA
    feaa4ec View commit details
  2. Copy the full SHA
    fa96e48 View commit details
  3. Update readme.md

    konhi authored Dec 18, 2021
    Copy the full SHA
    fb8a79e View commit details

Commits on Dec 21, 2021

  1. Copy the full SHA
    db6f225 View commit details
  2. Copy the full SHA
    ae393ad View commit details
18 changes: 4 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# ⳺ Censura ⳻
Advanced censorship plugin for minecraft servers
Fork of [YouHaveTrouble/Censura](https://github.com/YouHaveTrouble/Censura) suited for ForgeMC. Check [config](https://github.com/ForgeMC/ForgeCensura/blob/master/src/main/resources/config.yml) for more info.

Censura's goal is to completely eliminate usage of selected words on your minecraft server.

Filters include using game chat, placing and editing signs, editing and signing books, renaming items on an anvil and
filtering arguments of selected commands.

You can add any words to the 3-step filter via configuration file. You can also add exceptions for each word to avoid
false positives. Any detection will result in action triggering it to be cancelled - chat message won't send, sign will
be placed empty etc. In addition you can set any commands to trigger on detection to punish the player.

See [plugin wiki](https://github.com/YouHaveTrouble/Censura/wiki) for more details.

Found a bug? [Report it here](https://github.com/YouHaveTrouble/Censura/issues)
Differences:
- allows to ghost commands and notify admins about it
- regex whitelist
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ public CachedConfig() {
if (config.getBoolean("checks.nametag-use", true))
registerListener(EntityRenameListener.class);

registerListener(CommandColonListener.class);

ConfigurationSection filter = config.getConfigurationSection("filter");
if (filter == null) {
28 changes: 25 additions & 3 deletions src/main/java/eu/endermite/censura/filter/Filter.java
Original file line number Diff line number Diff line change
@@ -6,8 +6,14 @@
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.player.AsyncPlayerChatEvent;

import javax.annotation.Nullable;
import java.text.Normalizer;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

public class Filter {
@@ -37,7 +43,7 @@ public static boolean detect(String message, CachedConfig.FilterCategory filter)
return false;
}

public static boolean filter(String message, Player player) {
public static boolean filter(String message, Player player, @Nullable Event event) {
if (player.isOp() && Censura.getCachedConfig().getOpBypass())
return false;

@@ -46,7 +52,7 @@ public static boolean filter(String message, Player player) {

for (CachedConfig.FilterCategory filter : Censura.getCachedConfig().getCategories()) {
if (detect(message, filter)) {
doActions(filter.getPunishments(), player);
doActions(filter.getPunishments(), player, event);
return true;
}
}
@@ -62,7 +68,7 @@ public static boolean filterNoActions(String message) {
return false;
}

public static void doActions(List<String> actions, Player player) {
public static void doActions(List<String> actions, Player player, Event event) {
for (String a : actions) {
if (a.startsWith("command:")) {
CommandSender sender = Censura.getPlugin().getServer().getConsoleSender();
@@ -73,6 +79,22 @@ public static void doActions(List<String> actions, Player player) {
String message = a.replaceFirst("message: ", "");
String msg = message.replaceAll("%player%", player.getName());
player.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
} else if (a.equals("ghost")) {
if (event instanceof AsyncPlayerChatEvent) {
// Make message invisible to everyone except sender.
AsyncPlayerChatEvent chatEvent = (AsyncPlayerChatEvent) event;
Set<Player> recipients = chatEvent.getRecipients();
recipients.removeIf(recipient -> recipient != chatEvent.getPlayer());

// Notify admins about filter
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.hasPermission("censura.filteredMessages")) {
String messageForAdmins = ChatColor.translateAlternateColorCodes('&', String.format("&cCensura - %s: %s", onlinePlayer.getName(), chatEvent.getMessage()));
onlinePlayer.sendMessage(messageForAdmins);
Censura.getPlugin().getLogger().info("Sent to admins.");
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/eu/endermite/censura/filter/RegexMatch.java
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@ public RegexMatch(String input) {

@Override
public boolean match(String message, FilterCache cache) {
/* This is stupid, "forgemc.pl google.com" won't be filtered. */
if (message.contains("forgemc.pl")) {
return false;
}

return pattern.matcher(message).matches();
}

Original file line number Diff line number Diff line change
@@ -15,15 +15,15 @@ public void onChatEvent(org.bukkit.event.player.PlayerEditBookEvent event) {
BookMeta bookMeta = event.getNewBookMeta();
try {
for (String page : bookMeta.getPages()) {
if (Filter.filter(page, event.getPlayer())) {
if (Filter.filter(page, event.getPlayer(), event)) {
event.setCancelled(true);
return;
}
}
} catch (NullPointerException ignored) {}
if (!event.isSigning())
return;
if (Filter.filter(event.getNewBookMeta().getTitle(), event.getPlayer()))
if (Filter.filter(event.getNewBookMeta().getTitle(), event.getPlayer(), event))
event.setCancelled(true);
}
}
Original file line number Diff line number Diff line change
@@ -10,8 +10,6 @@ public class ChatEventListener implements Listener {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChatEvent(AsyncPlayerChatEvent event) {
if (Filter.filter(event.getMessage(), event.getPlayer()))
event.setCancelled(true);
Filter.filter(event.getMessage(), event.getPlayer(), event);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package eu.endermite.censura.listener;

import eu.endermite.censura.Censura;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

public class CommandColonListener implements Listener {
@EventHandler
public void onChatEven(PlayerCommandPreprocessEvent event) {
event.setMessage(getMessageWithoutPrefix(event));
}

/** /minecraft:xp -> /xp */
private String getMessageWithoutPrefix(PlayerCommandPreprocessEvent event) {
String message = event.getMessage();
String[] messageAsArray = message.split(" ");
String commandName = messageAsArray[0];

if (!isInvalidCommand(message) && commandName.contains(":")) {
String commandNameWithoutPrefix = commandName.split(":")[1];
messageAsArray[0] = commandNameWithoutPrefix;

String messageWithoutPrefix = messageAsArray.toString();
Censura.getPlugin().getLogger().info(String.format("Censura: Prefix removed: %s", commandName));

return messageWithoutPrefix;
}

return message;
}

private boolean isInvalidCommand(String command) {
// only syntax like minecraft:xp should work
if (colonCount(command) > 1) {
return true;
}

return false;
}

private long colonCount(String message) {
return message.chars().filter(i -> i == ':').count();
}
}
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public class CommandListener implements Listener {
public void onInteractEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
String msg = event.getMessage().toLowerCase();
for (String cmd : Censura.getCachedConfig().getCommandsToFilter()) {
if (msg.startsWith("/" + cmd + " ") && Filter.filter(msg, event.getPlayer())) {
if (msg.startsWith("/" + cmd + " ") && Filter.filter(msg, event.getPlayer(), event)) {
event.setCancelled(true);
return;
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public void onEntityRename(org.bukkit.event.player.PlayerInteractEntityEvent eve
if (handItem.getType() != Material.NAME_TAG)
return;

if (Filter.filter(handItem.getItemMeta().getDisplayName(), event.getPlayer()))
if (Filter.filter(handItem.getItemMeta().getDisplayName(), event.getPlayer(), event))
event.setCancelled(true);

}
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ public void onInteractEvent(org.bukkit.event.inventory.InventoryClickEvent event
AnvilInventory anvil = (AnvilInventory)inv;
Player player = (Player)event.getWhoClicked();

if (Filter.filter(anvil.getRenameText(), player))
if (Filter.filter(anvil.getRenameText(), player, event))
event.setCancelled(true);


Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ public void onSignChangeEvent(org.bukkit.event.block.SignChangeEvent event) {

String content = String.join(" ", event.getLines());

if (Filter.filter(content, player))
if (Filter.filter(content, player, event))
event.setCancelled(true);

}
64 changes: 38 additions & 26 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -61,38 +61,50 @@ replacements:
filter:
severe:
action:
- "command: ban %player% Censura - Using offensive words."
- "command: tempmute %player% 4h Używanie obraźliwych słów"
match:
- nigger
- nibber
- niga
- niba
- hitler did nothing wrong
- heil hitler
- nigger: "contain"
- nibber: "contain"
- niga: "contain"
- niba: "contain"
- pedal: "contain"
- niger: "contain"
- zjeb
- chuj
- huj
- : "contain"
- : "contain"
normal:
action:
- "command: kick %player% Censura - Stop using curse words!"
- "ghost"
match:
- fuck: "contain"
- bitch
- faggot
- tranny
- trannie
- gay is a sin
- gay is sin
light:
- hitler: "contain"
- kurwa
- (kurw[a-z]*): "regex"
- (jeba[a-zęóąśłżźćń]*): "regex"
- (pierd[ao][^ł]l*): "regex"
- (cip[a-zęóąśłżźćń]*): "regex"
- (pi[zź]d): "regex"
- (g[^łl]([óo]wn)): "regex"
- (dup[ay]): "regex"
- (dupie): "regex"
- (kutas): "regex"
- (penis): "regex"
- (dziwk[aoi]): "regex"
- (dziwek): "regex"
advertise:
action:
- "message: Censura - Stop using bad words, %player%!"
- "ghost"
match:
- sex
- porn: "contain"
- shit: "contain"
- fag: "contain"
- nigg: "contain"
- ([ &.,]|^)([\w]{5,})([., ]){1,}(pl|com|org|net|biz|mobi|kz|tk|server.pro|serv.nu)([ &.,]|$): "regex"
- ([\d]{1,3}[.,]{1,}){3,}([\d]{1,3}): "regex"
- aternos

# Messages used by the plugin
messages:
no-permission: "Censura - &cYou don't have permission to do this."
no-such-command: "Censura - &cThere is no such command."
config-reloaded: "Censura - &aConfiguration reloaded."
kick-bad-name: "Censura\n&cYour name contains bad words!"
no-permission: "Censura - &cNie masz uprawnień, by to zrobić."
no-such-command: "Censura - &cNie istnieje taka komenda."
config-reloaded: "Censura - &aKonfiguracja przeładowana."
kick-bad-name: "Censura\n&cTwój nick zawiera zakazane słowa!"

# Regex whitelist is configured in RegexMatch.
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -14,3 +14,6 @@ permissions:
censura.bypass:
default: false
description: Allows to bypass filters of Censura
censura.filteredMessages:
default: false
description: Show filtered messages on chat