Solved [Help] SoulBound Items?

Discussion in 'Plugin Development' started by XvBaseballkidvX, Dec 28, 2013.

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


    Hello everyone!
    I am trying to create some SoulBound items but have run into some problems (._.)
    If there anyway to detect when an item switches inventories and then cancel it (under the defined circumstances)?

    I want the player to be able to freely move the item around in their inventory, but I don't want it to be removed from it (Like placed in a Chest, or moved into a crafting table).

    NOTE: I have tried an InventoryClickEvent but it doesn't seem to work out to well :L .

    Thanks for reading!
    All help is much appreciated!
  2. Offline


    InventoryClickEvent is one of the trickiest events to deal with because there are so many different situations, but unfortunately that's the only one that is applicable for what you want :|
  3. Offline



    Check if the inventory viewer is instanceof Player, if not, cancel the event? Best I can think of at 01:18am
    XvBaseballkidvX likes this.
  4. Offline


    XvBaseballkidvX it's the InventoryMoveItemEvent. You can get the "getDestination()" and check if it is not the players inventory :)
    XvBaseballkidvX likes this.
  5. Offline


    WhatAaCow Thank you! :D Im going to try that out! If it works I'll mark this as solved! :p
  6. Offline


    WhatAaCow XvBaseballkidvX

    Don't go around spewing incorrect information... InventoryMoveItemEvent isn't even for players, and cannot be fired by HumanEntities (i.e. Players). It's for hoppers and stuff. You'll have to use InventoryClickEvent and InventoryDragEvent, those are the only two inventory-related events that can capture player clicks.
  7. Offline


    Ronbo calm down. thought it works. In JD: "Called when some entity or block (e.g. hopper) tries to move items directly from one inventory to another."

    XvBaseballkidvX try this:
    1. @EventHandler
    2. public void onInventoryInteract(InventoryClickEvent event) {
    3. if (event.getInventory() != event.getWhoClicked().getInventory()) {
    4. event.setCancelled(true);
    5. }
    6. }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 6, 2016
  8. Offline


    Ronbo WhatAaCow Thank you both :p I was trying to use the InventoryMoveEvent and it didn't work and I was wondering why, but you just explained it. Let me check out the InventoryClickEvent once more and I will post my results soon!

    EDIT: Fixed Type
  9. Offline


    InventoryDragEvent seems completely unreliable in my experience, it doesn't always fire (and when it does, bukkit does some screwy stuff) I think inventoryclickevent is what you want, you just need to check the destination inventory type. I have used this to prevent players putting certain items in the crafting slots, so I think you should be able to get it to do what you want.
    XvBaseballkidvX likes this.
  10. Offline


    Thank you everyone for your help! Marking this as Solved :p
    NathanWolf likes this.
Thread Status:
Not open for further replies.

Share This Page