Quick Question

Discussion in 'Plugin Development' started by ZodiacTheories, Aug 1, 2014.

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

    ZodiacTheories

    Hi, which event is fired when an Inventory changes?

    I looked on the javadocs, there are so many inventory events I didn't know which one to use

    -Zodiac
     
  2. Offline

    DigitalSniperz

    Do you mean a inventory as changed? or the player has changed inventorys example, player1 looked inside a chest quit it and looked inside a furnace.
     
  3. Offline

    ZodiacTheories

  4. Offline

    TheMcScavenger

  5. Offline

    Woef2001

    Maybe when - for example - the chest closes, save the inventory and every time you close the chest again check if the inventory equals the saved one
     
  6. Offline

    TheMcScavenger

    That'd work if he was talking about chests, he's talking about inventories.. Seeing as he didn't specify it properly, it could mean player inventories, chests, furnaces, brewing stands, hoppers, etc.
     
  7. Offline

    ZodiacTheories

  8. Offline

    TheMcScavenger

    If you want help, I suggest using more than one word per post, and actually showing effort.
     
  9. Offline

    McMhz

    TheMcScavenger
    Don't be a meanie.
    --

    Anyway, ZodiacTheories
    I think what you're trying to do is to have a kind-of item-menu?

    If so, I think that's done with the InventoryClickEvent.
    If not please explain to me what exactly you're trying to do.
     
  10. Offline

    TheMcScavenger

    I'm not "a meanie". If you expect people to spend their time to help you you should at least spend your time to properly explain the situation.
     
  11. Offline

    McMhz

    True, but still, that was kind-of a ""Meanie"" way of saying "Care to explain?"
     
  12. Offline

    TheMcScavenger

    Honestly, if people don't feel like putting effort into their posts, I don't feel to put effort into my post. If they don't take the time to properly explain, I won't take the time to post without being a meanie.
     
    TigerHix likes this.
  13. Offline

    ZodiacTheories

    McMhz

    I already have an inventory which has different icons to do with the specified Player. There is a item where I click, I go to the player's inventory, in a new gui. Then, when the players with a certain permission change the inventory around, the player's actual inventory gets changed to that. My event doesn't seem to work. I have tried saving the inventory and everything.

    TheMcScavenger

    Custom as in I create a new GUI, not an already-existing one.
     
  14. Offline

    McMhz

    Don't bother tagging him.

    Anyway, So you're just making a bunch of gui's and sub-gui's?
    And the event that doesnt work is the clicking one?

    ZodiacTheories
    ^^ Forgot to tag him, and my browser wont let me edit my msg.

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

    ZodiacTheories

    McMhz

    When I edit the GUI of the specified Player's inventory nothing happens to the Player's inventory
     
  16. Offline

    TheMcScavenger

    Now who's rude...

    Anyways, what I think isn't working is the part where you should be able to change the inventory from the other person, if you're allowed to do so (permissions wise). I would suggest creating a copy of the inventory, and replacing the inventory of the person with that when it gets changed.

    EDIT: Don't forget to update the copied inventory if the actual inventory gets updated (using any event; click event, drop event, pickup event, etc.).
     
  17. Offline

    McMhz

    As scavenger said you have to update the inventory.
    Are you closing the inventory before opening the new one? That may be the problem.

    If you'd send me the part of the code that you think isn't working I could probably help you fix it quickly.
    You can send it in pm or here, but if you don't want to share the code with anyone, I understand that perfectly.

    Anyway, It'd be alot quicker if you shared a little piece of the code with us.


    TheMcScavenger
    I assumed you called quits on this thread, sorry.

    I understand what you're trying to do now, I *think*
    So you're trying to make something like the /invsee of essentials?

    ZodiacTheories

    In that case, you probably just have to do something like this:
    player.setInventory(inv); //<--- I had no gui, so idk what method it is.
    and if that doesn't do it, use updateInventory();

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
    TheMcScavenger likes this.
  18. Offline

    TheMcScavenger

    As far as I know, he's got multiple inventories linked with items in inventories (being, you click on an item, and it opens another inventory). When you click on one of the items, it opens the inventory of one specific player that is online at that time. When you have permission to do so, you can rearrange his inventory, take things out, put things in, etc., which isn't working (it's not updating the player's inventory).
     
  19. Offline

    McMhz

    ZodiacTheories
    You should try what I did if you haven't already.
     
  20. Offline

    ZodiacTheories

    TheMcScavenger McMhz

    I do target.getInventory().setContents(updateditems);

    Updated items is an ItemStack[] of supposedly the updated items?
     
  21. Offline

    xTigerRebornx

  22. Offline

    ZodiacTheories

    xTigerRebornx

    Thanks, I will try that

    xTigerRebornx McMhz

    This just removes the items from the target's inventory:

    items is an ItemStack array

    Code:java
    1. @EventHandler
    2. public void onClick(InventoryClickEvent e) {
    3. Player p = (Player) e.getWhoClicked();
    4. if(e.getInventory().getName().equalsIgnoreCase(ChatColor.GREEN + "Inventory 2")) {
    5. if(p.hasPermission("healthmenu.edit.player")) {
    6. items = e.getInventory().getContents();
    7. }
    8. }
    9. }
    10. @EventHandler
    11. public void onClose(InventoryCloseEvent e) {
    12. if(e.getInventory().getName().equalsIgnoreCase(ChatColor.GREEN + "Inventory 2")) {
    13. for(Player player : GUI.target) {
    14. player.getInventory().setContents(items);
    15. }
    16. }
    17. }


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

    McMhz

    Is there an error message, or does it just not do anything?
    Also did you put the player.updateInventory(); under the player.getInventory().setContents(items);?
     
  24. Offline

    ZodiacTheories

    McMhz

    Didn't use .updateInventory();

    I will see if there are any errors, what it does, it just removes the clicked item from the target's inventory

    McMhz

    Yep, nothing, it just gets removed from my inventory when I exit the inventory, probably because the array contains nothing, although the inventory is not empty

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

    xTigerRebornx

    ZodiacTheories Have you tried what I showed at the links? Opening the target's inventory and then simply calling updateInventory() on the target Player whenever the sender clicks with a delay?
     
Thread Status:
Not open for further replies.

Share This Page