thetrouper's method of antiswear
This commit is contained in:
@@ -41,8 +41,8 @@ public class EntityDamageListener implements Listener {
|
|||||||
|
|
||||||
if (cause.name().contains("ENTITY")) return;
|
if (cause.name().contains("ENTITY")) return;
|
||||||
if (ent instanceof LivingEntity eLiving) {
|
if (ent instanceof LivingEntity eLiving) {
|
||||||
eLiving.setNoDamageTicks(14);
|
eLiving.setNoDamageTicks(DEFAULT_NO_DAMAGE_TICKS);
|
||||||
eLiving.setMaximumNoDamageTicks(15);
|
eLiving.setMaximumNoDamageTicks(DEFAULT_MAX_NO_DAMAGE_TICKS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package fun.ogre.ogredupealias.plugin;
|
|||||||
import fun.ogre.ogredupealias.data.Config;
|
import fun.ogre.ogredupealias.data.Config;
|
||||||
import fun.ogre.ogredupealias.utils.ArrayUtils;
|
import fun.ogre.ogredupealias.utils.ArrayUtils;
|
||||||
import fun.ogre.ogredupealias.utils.ServerUtils;
|
import fun.ogre.ogredupealias.utils.ServerUtils;
|
||||||
|
import fun.ogre.ogredupealias.utils.StringUtils;
|
||||||
import fun.ogre.ogredupealias.utils.Text;
|
import fun.ogre.ogredupealias.utils.Text;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -73,41 +76,57 @@ public class ChatConstraints {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1: Strip special characters
|
||||||
|
* 2: lowercase the text
|
||||||
|
* 3: remove the known false positives
|
||||||
|
* 4: remove periods and spaces
|
||||||
|
* 5: scan for swears
|
||||||
|
* 6: notify the player (do not tell them what they flagged, only that they flagged it and that attempts to bypass will result in a mute)
|
||||||
|
* 7: notify staff (send the original message and the trimmed string) highlighting the flagged word (listing the keywords violated as a hover text)
|
||||||
|
*/
|
||||||
public boolean passSwear() {
|
public boolean passSwear() {
|
||||||
if (!Config.Chat.AntiSwear.enabled()) return true;
|
if (!Config.Chat.AntiSwear.enabled()) return true;
|
||||||
if (player.hasPermission("oda.chat.bypass.swear")) return true;
|
if (player.hasPermission("oda.chat.bypass.swear")) return true;
|
||||||
|
|
||||||
String s = message.toLowerCase().replaceAll("[^a-z0-9]","");
|
// 1
|
||||||
String d = s;
|
String msg = message.replaceAll("[^A-Za-z0-9]", "").trim();
|
||||||
List<String> caught = new ArrayList<>();
|
// 2
|
||||||
|
msg = msg.toLowerCase();
|
||||||
|
// 3
|
||||||
for (String whitelisted : Config.Chat.AntiSwear.whitelist()) {
|
for (String whitelisted : Config.Chat.AntiSwear.whitelist()) {
|
||||||
s = s.replaceAll(whitelisted.toLowerCase(),"");
|
msg = msg.replaceAll(whitelisted.toLowerCase(), "").trim();
|
||||||
}
|
}
|
||||||
|
// 4
|
||||||
|
msg = msg.replaceAll("[. _-]", "");
|
||||||
|
// 5
|
||||||
|
List<String> flags = new ArrayList<>();
|
||||||
for (String blacklisted : Config.Chat.AntiSwear.blacklist()) {
|
for (String blacklisted : Config.Chat.AntiSwear.blacklist()) {
|
||||||
if (s.contains(blacklisted.toLowerCase())) {
|
String key = blacklisted.toLowerCase();
|
||||||
caught.add(blacklisted);
|
if (msg.contains(key)) {
|
||||||
d = d.replaceAll(blacklisted, Text.color("&e" + blacklisted + "&f"));
|
flags.add(blacklisted);
|
||||||
|
msg = msg.replaceAll(key, Text.color("&e" + key + "&f"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 6
|
||||||
if (caught.isEmpty()) return true;
|
if (!flags.isEmpty()) {
|
||||||
|
player.sendMessage(Text.ofAll("&cPlease do not swear in chat! Attempting to bypass this filter would result in a mute!"));
|
||||||
String warn = ArrayUtils.list2string(caught);
|
// 7
|
||||||
|
String hover = Text.color("&bMessage: &f" + msg + "\n&bFlags: &f" + ArrayUtils.list2string(flags) + "\n&7&o(click to copy)");
|
||||||
TextComponent text = new TextComponent();
|
TextComponent text = new TextComponent();
|
||||||
text.setText(Text.builder("\n&cMessage: &f" + d + "\n&cCaught: &e" + warn).prefix().color().build());
|
text.setText(Text.ofAll("&f&n" + player.getName() + "&e has triggered the anti-swear!"));
|
||||||
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Text.color("&cMessage: &f" + d + "\n&cCaught: &e" + warn))));
|
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hover)));
|
||||||
|
text.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, this.message));
|
||||||
|
|
||||||
player.sendMessage(Text.builder("&cPlease do not swear in chat!").color().prefix().build());
|
ServerUtils.forEachPlayer(staff -> {
|
||||||
player.spigot().sendMessage(text);
|
|
||||||
ServerUtils.forEachStaff(staff -> {
|
|
||||||
staff.sendMessage(Text.builder("&b" + player.getName() + " &3has triggered the &bAntiSwear&3:").prefix().color().build());
|
|
||||||
staff.spigot().sendMessage(text);
|
staff.spigot().sendMessage(text);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private String removeColors(String msg) {
|
private String removeColors(String msg) {
|
||||||
return String.join(" ", Arrays.stream(msg.split(" "))
|
return String.join(" ", Arrays.stream(msg.split(" "))
|
||||||
.filter(s -> !(s.length() >= 1 && s.charAt(0) == '§'))
|
.filter(s -> !(s.length() >= 1 && s.charAt(0) == '§'))
|
||||||
|
|||||||
Reference in New Issue
Block a user