Item removed on Interact

Discussion in 'Spigot Plugin Development' started by liwaa, Jun 13, 2016.

  1. hello, I have a problem with the Interact event and stuff.
    So I give the player 2 items, with costum names etc...
    and whenever player interacts, the items in his hand are removed.
    I don't remove the item from the hand, and I didn't write that in the code, it only does it.
    I tried many ways in the interact event, but still does the same, heres my code:

    Code (Text):
        public void onInteract(PlayerInteractEvent e) {

            if (Main.a.getSpectators().contains(e.getPlayer())) {
                if (e.getPlayer().getItemInHand().getType() != Material.AIR) {
                    if (e.getPlayer().getInventory().getHeldItemSlot() == 0) {
                    } else if (e.getPlayer().getInventory().getHeldItemSlot() == 8) {



    Code (Text):
          public static void giveSpectatorItems(Player p)
              ItemStack stack = new ItemStack(Material.WATCH);
              ItemMeta stackm = stack.getItemMeta();

              ItemStack stack2 = new ItemStack(Material.SLIME_BALL);
              ItemMeta stackm2 = stack.getItemMeta();
              stackm2.setDisplayName(methods.inColors("&cQuit Game"));

              p.getInventory().setItem(0, stack);
              p.getInventory().setItem(8, stack2);

    Note: I tried putting normal items in slots 1 & 8, and the code worked fine, only the items that are given from the code are removed.
  2. Please don't bump within 24 hours. Be patient.
  3. Code (Java):
  4. why do you do /leave on the player, you can kick him too,
    I assume that is for another plugin?

    and are you sure about what

    because that is the only thing I see that could cause your problem.

    As far as I know the spectator inventory isn't the normal one so the items probably aren't removed, you just don't see them

    try to change to normal gamemode during your test to proof this

    Edit: Don't forget to do what AtlasTech just said, it really could be the problem
  5. Items are given, whenever player nteracts wth the item in hand, item is removed

    I am sure of what methods.openSpectatorGUI(e.getPlayer()) does
    I tested it using a command it works, the thing is that whenever a player interacts, the event is called, but instead of open the spectator gui, item in hand is removed, same thing for Leave
  6. You are canceling the interact event when a player clicks with a slot thats has an item, i think thats your problem.
  7. nope, whenever I put any item in slot #1 the gui opens, and event is cancelled, but If the item given was in slot #1, it is removed