1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

MUTE COMMAND

Discussion in 'Plugin Help' started by Willoxey, Aug 31, 2019.

  1. Willoxey

    Willoxey Spider Jockey

    Messages:
    33
    Hi! is there any way to make a mute plugin? (i'm a noob developer)

    Thanks if you contribuite!
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Cancelling the PlayerChatEvent will hinder the chat message from being shown.
     
  3. Willoxey

    Willoxey Spider Jockey

    Messages:
    33
    But could you explain me how i can make like a list of players that are muted? like if i do /mute player1 that player1 even if disconect's and reconnect he will be mutted until i do /unmute player1
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    You can put the player into an array.
    PHP:
    // In the class
    private $mutedPlayers = [];
    // In the mute command
    $this->mutedPlayers[] = $playerName;
    // In the unmute command
    unset($this->mutedPlayers[$playerName]);
    // In the PlayerChatEvent handler
    $playerName $event->getPlayer()->getName();
    if (
    in_array($playerName$this->mutedPlayers)) {
      
    $event->setCancelled(true);
    }
    In order to keep it persistent across server reboots, you will need to save the player data somewhere.
    PHP:
    // in onEnable
    if ($this->getConfig()->get("mutedPlayers")) {
      
    $this->mutedPlayers $this->getConfig()->get("mutedPlayers");
    }
    // in onDisable
    $this->getConfig()->set("mutedPlayers"array_values($this->mutedPlayers));
    $this->getConfig()->save();
    // array_values because using unset messes up the keys
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.