censure ip?

Discussion in 'Plugin Development' started by gamerover98, Sep 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    gamerover98

    hello, how to censure numeric ip and for example mc.myserver.net ?
    this is my plugin for censure word:
    Code:java
    1. @EventHandler
    2. public void onChatMessage(PlayerChatEvent e) {
    3. String message = e.getMessage();
    4. String censura = e.getMessage();
    5. String parolaccia = e.getMessage();
    6. int censuraCount = 0;
    7.  
    8. for(char p : censura.toLowerCase().toCharArray()){
    9. if(censura == parolaccia)
    10. censura = parolaccia.replaceAll("word", "w**d");
    11. if(censura == parolaccia)
    12. censura = parolaccia.replaceAll("WORD", "W**D");
    13.  

    I haven't put .equalsIgnoreCase() because all chat becomes small...
     
  2. gamerover98 Couple of things:

    1) Your if statements will never* be true. You're essentially checking if any of the individual characters are equal to the entire message.
    2) replaceAll() is for regex. When you're just using for literals and not using regex, you should use replace(). Side note: regex is useful for finding IPs and URLs.

    * Well, it will be true if they have a 1 character message, but then your replaceAll() statement would never find a match...
     
  3. Offline

    1Rogue


    Correction, his statements would /always/ be true.

    gamerover98

    This kind of task is a lot more complex than the approach you are taking to it. People who want to spam/advertise in your chat won't be afraid to use my(.)coolserver - .com etc.
     
  4. 1Rogue My mistake. For some reason (probably the worse than useless for loop) I thought he was trying to compare the individual characters to the whole String, rather than the String to the same String. Which now I think about it, wouldn't have been false, it wouldn't have compiled. Either way, not sure the reasoning behind it and main solution would be to learn the basics of Java gamerover98 :)
     
    hintss likes this.
Thread Status:
Not open for further replies.

Share This Page