title: Java boolean returning true when declared false
body: <p>I am currently making a plugin from the 1.8 Bukkit API. This question however, has to do with booleans. From the beginning of my class file, I have this declaration of a boolean</p>
  
  <pre><code>public static boolean lockchat = false;
  </code></pre>
  
  <p>Then I have another boolean in the class file that is used for Bukkit commands:</p>
  
  <pre><code>public boolean onCommand(CommandSender s, Command cmd, String label, String[] args)
  </code></pre>
  
  <p>This boolean returns true at the end, which I think is making the <code>lockchat</code> boolean return true also. If I return false, I am pretty sure that the command code will not return to the user.</p>
  
  <p>My problem is that in this part of my code:</p>
  
  <pre><code>if(lockchat == true)
  {
      s.sendMessage("unlocked.")
      lockchat = false;
  }
  else
  {
      s.sendMessage("locked.");
      lockchat = true;
  }
  </code></pre>
  
  <p>The declaration at the beginning does not seem to matter here, because this always sends me the message unlocked.</p>
  
  <p>I have <em>tried</em> to put the declaration inside of the second boolean, but it throws me errors and warnings.</p>
  
  <p>Since the second boolean is returning true, I think that the <code>lockchat</code> boolean is returning too. If I would change it to return false, <code>lockchat</code> would probably return false also, resulting in another problem.</p>
  
  <p>I want to find a way to have the boolean declaration stay false, while having it changed to true/false inside of the second boolean, as shown. How would I do this?</p>
  
  <p>NOTE: This variable is not used anywhere else in my code.</p>
  
  <p>EDIT: I don't think this will make a difference, but I am testing for the label string to be <code>"lockchat"</code>, the same as the boolean name. This probably wouldn't change anything, but just giving more information.</p>
  
  <p>FULL CLASS FILE CODE:</p>
  
  <pre><code>package dev.td6.duocraft.commands;
  
  import org.bukkit.Bukkit;
  import org.bukkit.command.Command;
  import org.bukkit.command.CommandExecutor;
  import org.bukkit.command.CommandSender;
  import org.bukkit.entity.Player;
  import org.bukkit.event.EventHandler;
  import org.bukkit.event.Listener;
  import org.bukkit.event.player.AsyncPlayerChatEvent;
  
  import dev.td6.duocraft.main.Duocraft;
  
  public class DCCommandLockChat implements CommandExecutor, Listener
  {
  
      Duocraft plugin;
  
      public DCCommandLockChat(Duocraft instance)
      {
          plugin = instance;
      }
  
      public String colorize(String msg)
      {
          String coloredMsg = "";
          for(int i = 0; i &lt; msg.length(); i++)
          {
              if(msg.charAt(i) == '&amp;')
                  coloredMsg += '§';
              else
                  coloredMsg += msg.charAt(i);
          }
          return coloredMsg;
      }
  
      public static boolean lockchat = false;
  
      @SuppressWarnings("deprecation")
      public boolean onCommand(CommandSender s, Command cmd, String label, String[] args)
      {
  
          if(s instanceof Player)
          {
              Player p = (Player) s;
  
              if(label.equalsIgnoreCase("lockchat"))
              {
                  if(p.hasPermission("duocraft.lockchat"))
                  {
                      if(args.length &gt;= 1)
                      {
                          if(args.length &gt;= 2)
                          {
                              s.sendMessage("Too many arguments. &lt;/lockchat [time]&gt;");
                          }
                          else
                          {
                              if(lockchat == true)
                              {
                                  int time = Integer.valueOf(args[0]);
                                  s.sendMessage("locked");
                                  lockchat = true;
                                  plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable()
                                  {
                                      @Override
                                      public void run()
                                      {
                                          Bukkit.broadcastMessage("unlocked.");
                                          lockchat = false;
                                          plugin.getServer().getScheduler().cancelTasks(plugin);
                                      }
                                  }
                                      , time*20, time*20);
                              }
                              else
                              {
                                  int time = Integer.valueOf(args[0]);
                                  s.sendMessage("locked.");
                                  lockchat = true;
                                  plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable()
                                  {
                                      @Override
                                      public void run()
                                      {
                                          Bukkit.broadcastMessage("unlocked.");
                                          lockchat = false;
                                          plugin.getServer().getScheduler().cancelTasks(plugin);
                                      }
                                  }
                                      , time*20, time*20);
                              }
                          }
                      }
                      else
                      {
                          if(lockchat == true)
                          {
                              s.sendMessage("unlocked");
                              lockchat = false;
                          }
                          else
                          {
                              s.sendMessage("unlocked");
                              lockchat = true;
                          }
                      }
                  }
                  else
                  {
                      p.sendMessage("no access");
                  }
              }
  
          }
          else
          {
              if(label.equalsIgnoreCase("lockchat"))
              {
                  if(args.length &gt;= 1)
                  {
                      if(args.length &gt;= 2)
                      {
                          s.sendMessage("Too many args. &lt;/lockchat [time]&gt;");
                      }
                      else
                      {
                          if(lockchat == true)
                          {
                              int time = Integer.valueOf(args[0]);
                              s.sendMessage("locked.");
                              lockchat = true;
                              plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable()
                              {
                                  @Override
                                  public void run()
                                  {
                                      Bukkit.broadcastMessage("unlocked.");
                                      lockchat = false;
                                      plugin.getServer().getScheduler().cancelTasks(plugin);
                                  }
                              }
                                  , time*20, time*20);
                          }
                          else
                          {
                              int time = Integer.valueOf(args[0]);
                              s.sendMessage("locked");
                              lockchat = true;
                              plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable()
                              {
                                  @Override
                                  public void run()
                                  {
                                      Bukkit.broadcastMessage("unlocked");
                                      lockchat = false;
                                      plugin.getServer().getScheduler().cancelTasks(plugin);
                                  }
                              }
                                  , time*20, time*20);
                          }
                      }
                  }
                  else
                  {
                      if(lockchat == true)
                      {
                          s.sendMessage("unlocked");
                          lockchat = false;
                      }
                      else
                      {
                          s.sendMessage("unlocked");
                          lockchat = true;
                      }
                  }
              }
          }
  
          return true;
      }
  
      @EventHandler
      public void chatLocked(AsyncPlayerChatEvent e)
      {
          if(lockchat==false)return;
          Player p = e.getPlayer();
          if(p.hasPermission("duocraft.lockchat.bypass"))return;
  
          p.sendMessage("chat is locked.");
          e.setCancelled(true);
  
      }
  
  }
  </code></pre>
  
  <p>EDIT: Also <code>public static boolean lockchat = false;</code> Is not being modified in any way by any other class files.</p>
  
  <p>EDIT: I am using Java 7 for this.</p>