Block Item Movement

Discussion in 'Plugin Development' started by MrKravis, Jan 16, 2017.

Thread Status:
Not open for further replies.
  1. Hello,

    Before I begin my question, I would like to add that I've searched intensively on the forums for a solution and I did not find one which is working for Spigot 1.11.2

    I am trying to block players moving an specific item from their inventory. At the moment, I am succeding this but with a side effect: it duplicates the item that you are holding on your cursor when you press the blocked from movement item.

    P.S: Wrote the code back in 1.8 and worked perfectly till this version but now it has that side effect.

    Code: (added on InventoryClickEvent event)
    Code:
    event.setCancelled(true);
    player.getInventory().setItem(7, event.getCursor());
    player.setItemOnCursor(new ItemStack(Material.AIR));
    player.updateInventory();
    
     
  2. Offline

    JanTuck

    Whole class?

    Sendt fra min ALE-L21 med Tapatalk
     
  3. Why do you require the whole class?

    Those four lines are the only ones that matter.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @MrKravis Is it really duplicated or is this a visual glitch?
     
  5. Offline

    JanTuck

    Nvm i see the problem.

    event.setCancelled(true);
    player.getInventory().setItem(7, event.getCursor());
    player.setItemOnCursor(new ItemStack(Material.AIR));
    player.updateInventory();

    You would only need event.setCancelled(true) to stop movement

    the event.getCursor() gets what the player is currently holding not what is clicked for this do event.getCurrentItem()

    Sendt fra min ALE-L21 med Tapatalk
     
    Last edited: Jan 16, 2017
  6. @JanTuck Yes, that is what I am trying to say as well, that is the only piece of code that affects it. I commented out all the lines except event.setCancelled(true) but it still happens, I will check it in more detail as soon as possible.

    @timtower It is not a visual glitch, items do get duplicated
     
  7. Offline

    Zombie_Striker

    @MrKravis
    Have you tried always canceling the event and immediately returning (moving the cancel line to the very top if the event and then add return;)? If you do that, does that fix the issue?

    If that fixes the issue, then there is an issue somewhere else in your code that is causing the duplication. In that case, post the whole method or try removing lines until you find what is causing the problem.

    If that does not fix your problem, it may be an issue with the event, with another plugin you have online, or with the spigot jar itself. If this is the case, you will have to do some more testing.
     
Thread Status:
Not open for further replies.

Share This Page