Disable swearing for some players.

Discussion in 'Plugin Development' started by CrazyGuy3000, Oct 19, 2013.

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


    Hi there,
    Just wondering how I go about stopping some players from seeing messages with swears in them but other players who have it turned to see the message. Thanks for your help.

    - Twipply
  2. Offline


    Enjoy, just modify the Arrays.
    1. public String[] BannedWords = {"word1", "word2", "word3", "etc"};
    2. public String[] PlayersWhoCantSwear = {"Aengo", "Notch", "Dinnerbone"};
    4. @EventHandler
    5. public void ChatEvent(AsyncPlayerChatEvent e){
    6. String msg = e.getMessage();
    7. msg=msg.toLowerCase();
    8. for(String p:PlayersWhoCantSwear){
    9. if(e.getPlayer().getName()==p){
    10. for(String s:BannedWords){
    11. if(msg.contains(s)){
    12. e.setCancelled(true);
    13. e.getPlayer().sendMessage(ChatColor.RED+"You cannot swear!");
    14. }
    15. }
    16. }
    17. }
    18. }
  3. Offline


    You can't compare strings with == and I'm pretty sure that's not what OP meant.

    As far as the post, I don't think it's possible to do this without canceling the chat event altogether and sending the chat out as messages to other people(essentially screwing up other plugins' control of the chat). Now if you meant just removing the message for some, simply remove the people who can't see swears from event.getRecepients().
  4. Offline


    The solution is actually pretty easy. This code is off the top of my head, so some things might need to be changed
    2. Public String[] players = {"Drepic26","crazy297","SpaceGk"};
    3. Public String[] badwords = {"these","are","bad","words"}
    5. @EventHandler
    6. Public void onChat(AsyncPlayerChatEvent e) {
    7. String msg = e.getMessage();
    8. for (String s:players ){
    9. If (badwords.contains(msg)) {
    10. e.getRecipients.remove(s);
    11. }
    12. }
    13. }

    I hope this helps.
    swampshark19 likes this.
Thread Status:
Not open for further replies.

Share This Page