View Full Version : [508] Censor
Faab234
June 18th, 2010, 11:19
This is a simple code for a Censor in Palidino76:
PublicChat.java
Add under "Public class.......":
public String[] Censor = { "Fuck", "Lol", "SHIT", "Bitch"};
Under
if (p == null || p.stream == null) {
return;
}
This:
for (String s : Censor) {
p.chatText.replaceAll(s, "*******");
}
Other Version:
public static final String[] BAD_WORDS = {"fuck", "ass", "tit"};
public static String filterCurses(String text) {
for (String badWord : BAD_WORDS) {
for (String word : text.split(" ")) {
Pattern pattern = Pattern.compile("(?i)" + badWord);
Matcher matcher = pattern.matcher(word);
if (matcher.find()) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < word.length(); i++) {
builder.append("*");
}
text = text.replaceAll("(?i)" + word, builder.toString());
}
}
}
return text;
}
Imports:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
samuraiblood2
June 18th, 2010, 11:34
Regex was made for a reason.
public static final String[] BAD_WORDS = {"fuck", "ass", "tit"};
public static String filterCurses(String text) {
for (String badWord : BAD_WORDS) {
for (String word : text.split(" ")) {
Pattern pattern = Pattern.compile("(?i)" + badWord);
Matcher matcher = pattern.matcher(word);
if (matcher.find()) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < word.length(); i++) {
builder.append("*");
}
text = text.replaceAll("(?i)" + word, builder.toString());
}
}
}
return text;
}Using the above method would filter out curses that contain blacklisted words but aren't listed themselves. For example if someone types "asshole," the entire word would be commented out even though "ass" is the only word in the array. This also ignores case, so it doesn't need to be exactly as listed in the array.
Faab234
June 18th, 2010, 11:36
Regex was made for a reason.
public static final String[] BAD_WORDS = {"fuck", "ass", "tit"};
public static String filterCurses(String text) {
for (String badWord : BAD_WORDS) {
for (String word : text.split(" ")) {
Pattern pattern = Pattern.compile("(?i)" + badWord);
Matcher matcher = pattern.matcher(word);
if (matcher.find()) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < word.length(); i++) {
builder.append("*");
}
text = text.replaceAll("(?i)" + word, builder.toString());
}
}
}
return text;
}Using the above method would filter out curses that contain blacklisted words but aren't listed themselves. For example if someone types "asshole," the entire word would be commented out even though ass is the only word in the array. This also ignores case, so it doesn't need to be exactly as listed in the array.
Yea, Thanks for your reply, this is just a Simple Censor.
The sup
June 18th, 2010, 11:37
Thank you for this. Good if you have kids on your server.
Faab234
June 18th, 2010, 11:38
Thank you for this. Good if you have kids on your server.
Thanks for you comment.
samuraiblood2
June 18th, 2010, 11:39
Yea, Thanks for your reply, this is just a Simple Censor.
If you plan to add that into the original post, then make sure you add the import statements as well.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Faab234
June 18th, 2010, 11:44
If you plan to add that into the original post, then make sure you add the import statements as well.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Shit, Fogot it, Thanks.
Break
June 18th, 2010, 11:55
To long! I'll release now one that is much faster and better.
Faab234
June 18th, 2010, 12:02
To long! I'll release now one that is much faster and better.
To Long? Are you Kidding me?
Nathan
June 18th, 2010, 13:24
if (p.chatText.startsWith("/") && p.Donator > 0) {
try {
String chat = p.activeChat;
for (Player player : Server.engine.players) {
if (player != null) {
if (player.activeChatOwner.equals(p.activeChatOwner)) {
p.chatText = p.chatText.toLowerCase();
p.chatText = p.chatText.replaceAll("fuck","****");
p.chatText = p.chatText.replaceAll("fucker","*");
p.chatText = p.chatText.replaceAll("shit","****");
p.chatText = p.chatText.replaceAll("cunt","****");
p.chatText = p.chatText.replaceAll("bastard","*******");
p.chatText = p.chatText.replaceAll("fucking","***");
p.chatText = p.chatText.replaceAll("slut","****");
p.chatText = p.chatText.replaceAll("slag","****");
p.chatText = p.chatText.replaceAll("whore","*****");
p.chatText = p.chatText.replaceAll("bitch","*****");
p.chatText = p.chatText.replaceAll("nigga","*****");
p.chatText = p.chatText.replaceAll("nigger","******");
if (p.rights == 0 && p.Donator == 1) {
this is for when ppl use / to talk
ONTOPIC: nice tut :)
jamie
June 19th, 2010, 05:22
Thats nice. :)
Faab234
June 19th, 2010, 09:31
Thank you.
Nathan'
June 19th, 2010, 09:33
lol nice faab wont add though because i like it when players swear at me <3
Dodge'
October 1st, 2010, 21:55
Faab, yes this is very simple. But loading from a file would be 100% easier :) And you could add a ton of more words in like seconds, because you wouldnt have to add the other stuff inbetween words. just put them in a list
ie:
fuck
whore
hoe
and so on :)
Powered by vBulletin® Version 4.1.9 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.