Description - Adding a proper Word censor
Difficulty - 2/10, have no clue how hard this could be
files added/modified - PublicChat.java, Engine.java, Censor.java
well i was bored and decided to make this, even though i wouldn't put it in a server
this took about 5 min.
Step 1:
Create a new file in the utils folder called "Censor.java"
In that file paste this,
Code:
package ZabboScape.util;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Censor {
public static List<String> censored = new ArrayList<String>();
public Censor() {
loadWords();
}
private void loadWords() {
String word = null;
try {
BufferedReader in = new BufferedReader(new FileReader("./data/Censor.txt"));
while ((word = in.readLine()) != null) {
censored.add(word);
}
in.close();
in = null;
} catch (Exception e) {
Misc.println("Error load the censor.");
}
}
}
Save and close
Step 2:
Open up Engine.java and paste this in there
Code:
/*Word censor*/
public static Censor Censor = new Censor();
Step 3:
Open up public chat and add this under p.chatText = Misc.decryptPlayerChat(p.stream, numChars);
Code:
for (String s : Engine.Censor.censored) {
if (p.chatText.contains(s)) {
int length = s.length();
String replace = "";
for(int i = 0; i < length; i++) {
replace += "*";
}
p.chatText = p.chatText.replaceAll(s, replace);
}
}
Save and close
Step 4:
go to your data folder and create a file called Censor (make sure its a text file)
and add all the words you want to be censored into it
Post any errors are ask any questions and i'll do my best to help you