Solved getMessage().contains is just lowercase?

Discussion in 'Plugin Development' started by danjb2000, Jun 1, 2014.

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

    danjb2000

    Hi guys, Making a chat filter plugin for my server,
    But I've just noticed a hickup with the code i'm using:
    People can just bypass it by using capitals, for example, I code in "fuck", They can just put "FUCK" and bypass it..

    Code:
    Code:java
    1. if (event.getMessage().contains("fuck")) {
    2. if (!event.getPlayer().hasPermission("cubedcraft.swearbypass")) {
    3. event.setCancelled(true);
    4. event.getPlayer().sendMessage(
    5. ChatColor.GREEN + "CubedCraft" + ChatColor.DARK_PURPLE
    6. + ">" + ChatColor.RED + " Do not swear!");
    7. } else {
    8. event.getPlayer().sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "CubedCraft" + ChatColor.DARK_GRAY + "] " + ChatColor.BLUE + "You have been allowed to swear, But it is advised you don't!");
    9. }
    10. }


    Oh, My main point: Is there a way around it? like .containsIgnoreCase? lol

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  2. Offline

    Necrodoom

    Check contains on a lower cased message?
     
    Konkz likes this.
  3. Offline

    danjb2000

    Hm?

    Just to check you understand me: I'm asking, Is there a way that one section of code can prevent the swearing in both upper and lowercase?
     
  4. Offline

    MrFlieder

    Code:java
    1. if(ev.getMessage().toLowerCase().contains("word"))
    2. {
    3. // your code
    4. }
     
  5. Offline

    danjb2000

    Don't worry, Solved.
    For anyones future reference:
    Code:java
    1. if (event.getMessage().toLowerCase().contains("fuck")) {
    would work. :)
     
    badboysteee98, Konkz and xYourFreindx like this.
  6. Offline

    badboysteee98

    danjb2000 Thank you I was looking for the same thing :)

    People who show the solved Puzzle are amazing and friendly people thanks again :)

    I have a question how would I do it as in like it gets a List of fliter message? Abit like this

    Config:
    Fliter:
    - Fuck
    - Shit
    - Dick

    And so on?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  7. Offline

    xYourFreindx

    Totally agree. I was also curious about this. But then realized I had learned this back in my first qbasic programming class. :D
    I gotta ask where you and everyone else gets those awesome cartoon profile pictures.
     
  8. Offline

    Konkz

    I suggest making a thread of this for your problem, as this one has been solved.
    But instead of hard coding the string "f**k" do getConfig().getList("path.to.my.list"); - that should work I think.

    xYourFreindx - http://www.faceyourmanga.com/editmangatar.php
     
  9. Offline

    MrFlieder

    The following improvised code replaces words which are set in the config file with "***".

    Code:java
    1. List<String> list = getConfig().getStringList("word-filter");
    2. String msg = event.getMessage();
    3.  
    4. for(String s : list)
    5. if(msg.toLowerCase().contains(s))
    6. msg = msg.replace(s, "***");
    7.  
    8. event.setMessage(msg);
     
Thread Status:
Not open for further replies.

Share This Page