Solved Command to mute

Discussion in 'Plugin Development' started by user_91277742, Feb 15, 2019.

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

    user_91277742

    Hi there!, so im trying to do a command to mute players if they are on a Hashmap, but currently my code doesnt works and im not really sure why.

    Code:
        @EventHandler
         public void mutearChat(AsyncPlayerChatEvent e) {
            Player p = (Player) e.getPlayer();
            if (estaMuteado == true) {
                System.out.println(main.oldLoc.containsKey(p.getUniqueId()));
                if (p.getWorld().getName() != null) {
                    if (main.oldLoc.containsKey(p.getUniqueId())) {
                        if (!(main.profesores.contains(p.getUniqueId()))) {
                            e.setCancelled(true);
                            p.sendMessage("You cant talk right now");
                        }
                    }
                }
            }
        }
    
    Code:
                        if (args[0].equalsIgnoreCase("mute")) {
                            if (player.hasPermission("class.professor")) {
                                if (main.oldLoc.containsKey(player.getUniqueId())) {
                                    if (evends.estaMuteado == false) {
                                        evends.estaMuteado = true;
                                        player.sendMessage(main.mensajesConfig.getString(main.color("class-muted")));
                                        return true;
                                    } else {
                                        world = null;
                                        evends.estaMuteado = false;
                                        player.sendMessage(main.mensajesConfig.getString(main.color("class-unmuted")));
                                        return true;
                                    }
                                }
                            }
                        }
    
     
  2. Offline

    KarimAKL

    What doesn't work?
     
    MightyOne likes this.
  3. Offline

    0-o

    Do you ever store the UUIDs in the hashmap? I don't see that in the code you posted, so I'm just wondering.
     
    KarimAKL likes this.
  4. Offline

    user_91277742

    The comamnd mute, when you talk, the event is not cancelled
     
  5. Offline

    KarimAKL

    @Ahrigumi Try printing messages to the console in between the lines to see where it stops and you can also print the contents of the map to see if the player is in the map.
     
  6. Offline

    idkG0D

    I really don't use a "boolean" to mute the player. Just add the player to a ArrayList and check if the ArrayList contains the player, then if he are in the ArrayList just mute the player...
    And in the boolean don't use if (boolean == false)...

    To check if's true use (boolean)
    To check if's false use (!boolean)
     
  7. Offline

    user_91277742

    was an other chat event in the same class :p, fixed and thanks!
     
Thread Status:
Not open for further replies.

Share This Page