event.setCancelled(true);

Discussion in 'Plugin Development' started by ChrystianSandu, Jul 20, 2014.

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

    ChrystianSandu

    I want to add a mute script to my plugin, but here is a problem.
    I try this (in a listener class):
    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent event)
    3. {
    4. Player p = event.getPlayer();
    5. for (String s : bannedFromChat)
    6. {
    7. if (s.equals(p.getName())) {
    8. event.setCancelled(true);
    9. p.sendMessage(ChatColor.RED + "[BanVote] You have been muted. You can not chat.");
    10. }
    11. }
    12. }
    13.  
    14. }

    But player isn`t muted. Any help? (sorry for my english)
     
  2. Offline

    ReadySetPawn

    Are you getting any errors in your stacktrace?
     
  3. Offline

    Flegyas

    Hi ChrystianSandu, are you getting any error? Is the Listener right registered? Are you sure that "bannedFromChat" contains the name of the player you're trying to mute? You can try adding a System.out.println(something) as first instruction in the if-block to check if the code enters there.
     
  4. Offline

    ChrystianSandu

    I haven`t a error, I will check this.
     
  5. ChrystianSandu
    Though this isn't related to your problem, I'd suggest checking the player's UUID instead of their name, as they can simply bypass the mute by changing their name.
     
  6. Offline

    ChrystianSandu

    Hm... well this is other problem. OK, ;)
     
  7. Offline

    xTrollxDudex

    ChrystianSandu
    Have you added anything to bannedFromChat? If so, make sure it is on the correct instance of your listener. You could also use a contains check instead of iteration, since you aren't implementing it correctly anyways.
     
  8. Offline

    ChrystianSandu

    I will try.
     
Thread Status:
Not open for further replies.

Share This Page