001    
002    package org.bukkit.event.inventory;
003    
004    import java.util.List;
005    
006    import org.bukkit.event.HandlerList;
007    import org.bukkit.entity.HumanEntity;
008    import org.bukkit.event.Event;
009    import org.bukkit.inventory.Inventory;
010    import org.bukkit.inventory.InventoryView;
011    
012    /**
013     * Represents a player related inventory event
014     */
015    public class InventoryEvent extends Event {
016        private static final HandlerList handlers = new HandlerList();
017        protected InventoryView transaction;
018    
019        public InventoryEvent(InventoryView transaction) {
020            this.transaction = transaction;
021        }
022    
023        /**
024         * Gets the primary Inventory involved in this transaction
025         *
026         * @return The upper inventory.
027         */
028        public Inventory getInventory() {
029            return transaction.getTopInventory();
030        }
031    
032        /**
033         * Gets the list of players viewing the primary (upper) inventory involved
034         * in this event
035         *
036         * @return A list of people viewing.
037         */
038        public List<HumanEntity> getViewers() {
039            return transaction.getTopInventory().getViewers();
040        }
041    
042        /**
043         * Gets the view object itself
044         *
045         * @return InventoryView
046         */
047        public InventoryView getView() {
048            return transaction;
049        }
050    
051        @Override
052        public HandlerList getHandlers() {
053            return handlers;
054        }
055    
056        public static HandlerList getHandlerList() {
057            return handlers;
058        }
059    }