Solved [Help] Refresh an Inventory

Discussion in 'Plugin Development' started by XvBaseballkidvX, Jan 18, 2014.

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

    XvBaseballkidvX

    Hello everyone!

    I just have a quick question. Is there an easy way to update an InventoryView?

    I need to be able to refresh a players open inventory in a task for an info block! (Like Scrolling Text)
    My lore changing method works but I just need to be able to update the open inventory in order to show the changes.

    Any ideas?

    Thank you for reading!
    All help is much appreciated!
     
  2. Offline

    MrInspector

    Code:java
    1. p.updateInventory();
    2. // Hopefully I read correctly, I'm pretty tired
     
    XvBaseballkidvX likes this.
  3. Offline

    Niknea

    XvBaseballkidvX player.updateInventory();

    EDIT: Ninja'd by MrInspector :p
     
    MrInspector likes this.
  4. Offline

    XvBaseballkidvX

  5. Offline

    MrInspector

    Code:java
    1. // not sure if this is how it would be done, worth a try.
    2. p.updateInventory(custominv);
     
    Niknea likes this.
  6. Offline

    XvBaseballkidvX

    MrInspector likes this.
  7. Offline

    MrInspector

    Hope it works. :p
     
  8. Offline

    XvBaseballkidvX

    MrInspector I have some unfortunate news...
    Code:
    The method updateInventory() in the type Player is not applicable for the arguments (Inventory)
    EDIT: The only way I can update the Inventory is by closing it a reopening it, but that messes with the cursor so I need to find an alternate way.
     
  9. Offline

    MrInspector

    I'm out of options ^ and yes, I do it by closing and reopening inventories, I don't spend too much time with custom inventories :l
     
  10. Offline

    XvBaseballkidvX

    MrInspector Eureka! I think we have it!

    Refresh Code:
    Code:java
    1. public static void refresh(){
    2. for(Player player : Bukkit.getOnlinePlayers()){
    3. InventoryView iview = player.getOpenInventory();
    4. if(iview.getTitle().equalsIgnoreCase("CustomInv")){
    5. Inventory contents = iview.getTopInventory();
    6. contents.setItem(0, Items.test);
    7. }
    8. }
    9. }


    Thank you guys for helping me! *Mission Accomplished!*
     
    MrInspector likes this.
Thread Status:
Not open for further replies.

Share This Page