title: Bukkit Development - Doesn't Remove Item In Hand on Sign Interact
body: <p>Basically I am trying to have a kit system where the player gets items from a defined kit in the config and which pulls in fine first time, but if the user then wants to change the kit, the item that the user currently holds remains the same as it changes all the other items.</p>
  
  <p>The onSignInteract event:</p>
  
  <pre><code>@EventHandler
  public void onSignInteract(PlayerInteractEvent e)
  {
      Player player = e.getPlayer();
  
      if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
      {
          Block block = e.getClickedBlock();
  
          if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN)
          {
              Sign sign = (Sign)block.getState();
  
              String[] line = sign.getLines();
  
              if (line[0].equalsIgnoreCase("[C KIT]"))
              {               
                  for (String kit : Main.kits)
                  {
                      if (line[1].equalsIgnoreCase(kit)) // The power is strong with this one
                      {
                          //for testing purposes
                          Main.logger.info("BEFORE CLEAR: " + player.getInventory().getItemInHand().toString());
  
                          clearInv(player);
                          e.getPlayer().setItemInHand(null);
                          // for testing purposes
                          Main.logger.info("AFTER CLEAR: " + player.getInventory().getItemInHand().toString());
  
                          List&lt;String&gt; ids = Main.config.getStringList("kits." + kit);
  
                          for (String id : ids)
                          {
                              // ItemSlot-ItemID-Amount-Enchantments(comma separate)-PotionDetails
                              String[] split = id.split("-");
                              ItemStack item = new ItemStack(Main.getMaterialById(Integer.parseInt(split[1])), Integer.parseInt(split[2]));
  
                              if (split[1].equals(String.valueOf(373)))
                              {
                                  String[] potDet = split[4].split("\\.");
  
                                  String potType = potDet[0];
                                  String potName = potDet[1];
                                  String potLvl;
  
                                  if (potDet.length == 3)
                                  {
                                      potLvl = potDet[2];
                                  }
                                  else
                                  {
                                      potLvl = "1";
                                  }
  
                                  boolean splash;
  
                                  if (potType.equals("sp"))
                                  {
                                      splash = true;
                                  }
                                  else
                                  {
                                      splash = false;
                                  }
  
                                  int potLevel = Integer.parseInt(potLvl);
  
                                  Potion potion = new Potion(Main.getPotion(potName));
  
                                  potion.setSplash(splash);
                                  potion.setLevel(potLevel);
                                  item = potion.toItemStack(Integer.parseInt(split[2]));
  
                                  player.getInventory().addItem(item);
                              }
                              else if (!split[3].equals(null) &amp;&amp; !split[3].equalsIgnoreCase("") &amp;&amp; !split[3].equalsIgnoreCase("0.0"))
                              {
                                  item = new ItemStack(Main.getMaterialById(Integer.parseInt(split[1])), Integer.parseInt(split[2]));
  
                                  String[] enchants = split[3].split(",");
  
                                  for (String s : enchants)
                                  {
                                      String[] enchant = s.split("\\.");
  
                                      int level = Integer.parseInt(enchant[1]);
                                      Enchantment en = Main.getEnchantment(enchant[0]);
  
                                      if (en != null)
                                      {
                                          item.addEnchantment(en, level);
                                      }
                                  }
  
                                  // Check for Armour
                                  if (split[0].equals(String.valueOf(103)))
                                  {
                                      player.getInventory().setHelmet(item);
                                  }
                                  else if (split[0].equals(String.valueOf(102)))
                                  {
                                      player.getInventory().setChestplate(item);
                                  }
                                  else if (split[0].equals(String.valueOf(101)))
                                  {
                                      player.getInventory().setLeggings(item);
                                  }
                                  else if (split[0].equals(String.valueOf(100)))
                                  {
                                      player.getInventory().setBoots(item);
                                  }
                                  else
                                  {
                                      player.getInventory().addItem(item);
                                  }
                              }
                              else
                              {
  
                                  player.getInventory().addItem(item);
                              }
                          }
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>clearInv(Player player) method:</p>
  
  <pre><code>public static void clearInv(Player p)
  {
      PlayerInventory pi = p.getInventory();
  
      p.setHealth(20.0);
      p.setFoodLevel(20);
      pi.clear();
      pi.setArmorContents(null);
      p.getItemInHand().setType(Material.AIR);
  
      for (PotionEffect effect : p.getActivePotionEffects())
      {
          p.removePotionEffect(effect.getType());
      }       
  }
  </code></pre>