Solved Anti-phrase help?

Discussion in 'Plugin Development' started by pinkitty1, Jun 13, 2015.

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

    pinkitty1

    So I have been trying to add a feature to my warn plugin that automatically catches phrases that is normally said when another player is advertising a different server.
    This is what the code looks like so far
    Code:
    @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e) {
            Player target = e.getPlayer();
            String uuid = target.getUniqueId().toString();
            String message = e.getMessage().toLowerCase();
            String AntiPhraseKickMsg =  ChatColor.RED + " You Have Been Auto-Banned For Advertising!";
         
         
            if(message.contains("comeandjoin")){
                getConfig().set(uuid, 20);
                target.kickPlayer(ChatWarnPrefix + AntiPhraseKickMsg);
            }
         
            if(message.contains("joinnow")){
                getConfig().set(uuid, 20);
                target.kickPlayer(ChatWarnPrefix + AntiPhraseKickMsg);
            }
         
            if(message.contains("freeop")){
                getConfig().set(uuid, 20);
                target.kickPlayer(ChatWarnPrefix + AntiPhraseKickMsg);
            }
         
            if(message.contains("joinmyserver")){
                getConfig().set(uuid, 20);
                target.kickPlayer(ChatWarnPrefix + AntiPhraseKickMsg);
             
                Bukkit.broadcast(ChatWarnPrefix + " " + ChatColor.RED + target + " Has Been Auto Banned For Advertising!", "chatwarn.notify");
            }
         
        }
    But what I am trying to do is disable people saying such things like "free op", "join now", "come and join", and "join my server" so what can I do to be able to do this (I am still fairly new to java so if any code for such things will be greatly appreciated)
    Edit: just added a ")" it was annoying me without it
     
    Last edited: Jun 13, 2015
  2. Offline

    TomTheDeveloper

    Don't use contains("comeandjoin") because then it will check if the sentence contains the world "comeandjoin". You'll have to check it like this: message.contains("come") && message.contains("and") && message.contains("join")

    However making a seperate method that loops through a list and checks if the sentence contains a word or few words from that list is much easier.

    You can also make a sort of seperate config for all the words, etc...
     
Thread Status:
Not open for further replies.

Share This Page