Getting stored items in fake chest

Discussion in 'Plugin Development' started by randomman159, Nov 19, 2011.

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

    randomman159

    So i have this code :

    Code:
    public void DisplayChest(Player player, List<ItemStack> items)
        {
            EntityPlayer eplayer = ((CraftPlayer)player).getHandle();
            TileEntityChest c = new TileEntityChest();
            for (int i = 0; i < c.getSize() && i < items.size(); i++)
            {
                c.setItem(i, items.get(i));
            }
            eplayer.a(c);
        }
    How can i check what items a player would store in this chest? Either when he closes it, or as he stores/removes?
     
  2. Offline

    Nitnelave

    I'm not sure, but you may need spout as they have some inventory events that are really what you need.
    You should ask @Afforess
     
  3. Offline

    ZNickq

    use spout, and it's splayer.openInventoryWindow(inv);
     
  4. Offline

    Arkel

    Spout can offer you both onInventoryClose and onInventoryClick events.
     
  5. Offline

    randomman159

    I absolutely love spout, but i would much rather not use it for this plugin. This sort of plugin needs to be accessible to everyone, and i don't want to therefore have it limited to only a few servers.

    There is the chest.getContents() function, all i need is some way of efficiently and flawlessly calling it at the right times.
     
  6. Offline

    Afforess

    Because it's "fake" (aka, not saved/managed in notch's world) you have to do all the handling. You need to always keep a reference to the inventory, be it in some hashmap or other collection. If you remove your references, the inventory is gone.

    As for determining the results after the inventory has been opened - you really need an onInventoryClose event. Sadly, there is none. Spout is the only real way forward here.
     
  7. The only way to efficiently and flawlessly know when is to monitor the inventory interaction events which require you touching Notch code or using Spout.

    Curse you @Afforess and your ability to post about your own plugin seconds before I do.
     
  8. Offline

    randomman159

    What does the InventoryListener do then?
     
  9. In Bukkit? Not much actually. I don't think half of the events even fire.
     
  10. Offline

    bleachisback

    You could send a Packet100OpenWindow with CraftBukkit, however I don't know how to catch Packets (there is a Packet102WindowClick which keeps track of items placed inside it)
     
  11. You can't trap packets without modifying the core code. Bukkit alone doesn't provide that feature. Spout does and it's wrapped nicely.
     
  12. Offline

    randomman159

    So the simplest method would be to check the chest items on the disabling of the plugin? Or would this not occur if the server crashed?
     
  13. /me facepalms
     
  14. Offline

    Nitnelave

    Or you could set up a repeating task to check the chest contents every 10 sec, for example. Or schedule the save 5 min after he opened the chest, or something.
     
Thread Status:
Not open for further replies.

Share This Page