Solved How to Mute Chat

Discussion in 'Spigot Plugin Development' started by Yazability, May 30, 2017.

Thread Status:
Not open for further replies.
  1. I've been trying to figure out how to mute the chat so no one except those with a permission are able to talk. Any help is appreciated.
     
    • Agree Agree x 1
  2. So I did this:
    Code (Text):

        @EventHandler
        public void onMuteChat(AsyncPlayerChatEvent e) {
            if(ChatEnabled == false) {
                if(!e.getPlayer().hasPermission("handychat.mutechat.bypass")) {
                    e.getPlayer().sendMessage(ChatMuted);
                }
            }
        }
       
     
    But I don't know how to set the variable ChatEnabled to true or false with a command.
     
  3. first of all, please don't use == false. use !ChatEnabled. second:
    Code (Text):
        private static boolean muted = false;

        @EventHandler
        public void onMuteChat(AsyncPlayerChatEvent e) {
            if(muted && !e.getPlayer().hasPermission("handychat.mutechat.bypass"))
               event.setCancelled(true);
        }

       @Command(permission = "handychat.mutechat.mute")
       public void mute(){
           muted = !muted;
       }
     
    #4 Erezbiox1, May 30, 2017
    Last edited: May 30, 2017
  4. Change the command format to the regular ( spigot ) one or use my CommandsAPI.
     
  5. Add feedback message, and also change the event name to onChat ( because it's not "onMuteChat". )
     
  6. Just invoke setCancelled(true) on the event if you don't write them to send messages.
     
  7. Thanks for all the help, managed to fix it from the examples you gave me!
     
    • Agree Agree x 1
Thread Status:
Not open for further replies.