Solved equalsIgnoreCase() in events?

Discussion in 'Plugin Development' started by x_Jake_s, Feb 20, 2015.

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

    x_Jake_s

    So here is my code:
    Code:
       @EventHandler(priority=EventPriority.HIGH)
       public void onSwearChat(AsyncPlayerChatEvent e)
       {
         for (String word : e.getMessage().split(" ")) {
             if (plugin.getConfig().getStringList("Blacklist").contains(word))
           if ((e.getPlayer().isOp()) ||
          
             (e.getPlayer().hasPermission("chatadmin.swear.bypass")))
           {
             e.setCancelled(false);
           }
           else
           {
             e.setCancelled(true);
             String Curse = plugin.getConfig().getString("CurseMSG");
             String curse = ChatColor.translateAlternateColorCodes('&', Curse);
             String Prefix = plugin.getConfig().getString("Prafix");
             String prefix = ChatColor.translateAlternateColorCodes('&', Prefix);
             e.getPlayer().sendMessage(prefix + " " +
               curse);
           }
         }
       }
    I need to know how to make it so even if the player types a blocked word like CuRsE or any other combonation they still wont be able to do it? please help
     
  2. Offline

    Infuzion

    Simply convert it to lower case:
    "CuRSe".toLowerCase() and compare this to the lower-case version of the blocked word.
     
  3. Offline

    WesJD

    Does your IDE not give you errors with that code?
     
  4. Offline

    Infuzion

    @WesJD
    Neither posted codes give me errors. I am using Java 1.8.
     
  5. Offline

    Konato_K

    @x_Jake_s Regex has a case insesitive flag (which I think it's "(?i)" but you can still compile a Pattern and set it yourself), I would go with regex for this.
     
  6. Offline

    x_Jake_s

    When i do this it gives me a error inside the game with an internal problem which is why i posted here.

    thank you i got it to work.

    no, i use java 7 since most servers dont run java 8 yet aswell as some hosting services.
     
Thread Status:
Not open for further replies.

Share This Page