PDA

View Full Version : [508] Word Censor [508]



UnitedScape
June 22nd, 2010, 09:30
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



/*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);



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

Dark Resurrection
June 22nd, 2010, 09:37
Lol forbid every word

Sceptylos
September 28th, 2010, 23:07
.\RH\Engine.java:32: cannot find symbol
symbol : class Censor
location: class RH.Engine
public static Censor Censor = new Censor();
^
.\RH\Engine.java:32: cannot find symbol
symbol : class Censor
location: class RH.Engine
public static Censor Censor = new Censor();
^
2 errors
Appuyez sur une touche pour continuer...

d3mons dead
October 1st, 2010, 15:45
.\RH\Engine.java:32: cannot find symbol
symbol : class Censor
location: class RH.Engine
public static Censor Censor = new Censor();
^
.\RH\Engine.java:32: cannot find symbol
symbol : class Censor
location: class RH.Engine
public static Censor Censor = new Censor();
^
2 errors
Appuyez sur une touche pour continuer...

u dident import censor class in engine your engine class