Check if chat is disabled? (boolean)

Discussion in 'Plugin Development' started by Forscom, Feb 4, 2017.

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


     private boolean chat = true;
        FileConfiguration config = null;
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            config = getConfig();
        public void onDisable() {
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player p = (Player) sender;
            if (label.equalsIgnoreCase("mutechat") || label.equalsIgnoreCase("mc")) {
                if (p.hasPermission("server.mutechat")) {
                    chat = false;
                            ChatColor.translateAlternateColorCodes('&', getConfig().getString("chat-disabled")));
                }else {
                            ChatColor.translateAlternateColorCodes('&', getConfig().getString("no-permission")));
            }else if (chat == false) {
                        ChatColor.translateAlternateColorCodes('&', getConfig().getString("chat-already-disabled")));
    I don't really wanna be spoonfed. But I literally can not figure out where if (chat == false) { goes.
  2. Offline


    I believe I saw you on spigot.. haha ^-^

    If I connected the brackets correctly it leads to the if permisson check..
  3. Offline


    you never checked if chat is equal to true so you cant make an else if for if it's equal to false. Check if its equal to true first
  4. Offline


    So, a few things:
    1. chat == false is equivalent to !chat (not chat), so you could use that unless you like the way chat == false looks.
    2. As @kameronn said, you never created the initial if for the true chest (if(chat) or if(chat == true)), so you can't use an else that would catch the false case.
    3. Your next question would be where the if statement for the true check would go, and that would be right underneath your permissions check
    Click if you want to see how you'd do #3. (open)
    if(player.hasPermission("mutechat")) {
      if(chat == true) {
        chat = false;
        //Do whatever else
      else {
        //Chat was false
        chat = true; //unmute chat
Thread Status:
Not open for further replies.

Share This Page