Java Code Examples for org.bukkit.event.inventory.InventoryOpenEvent#getInventory()

The following examples show how to use org.bukkit.event.inventory.InventoryOpenEvent#getInventory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorthListener.java    From factions-top with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void checkWorth(InventoryOpenEvent event) {
    // Do nothing if a player did not open the inventory or if chest events
    // are disabled.
    if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) {
        return;
    }

    Inventory inventory = event.getInventory();

    // Set all default worth values for this chest.
    if (inventory.getHolder() instanceof DoubleChest) {
        DoubleChest chest = (DoubleChest) inventory.getHolder();
        checkWorth((Chest) chest.getLeftSide());
        checkWorth((Chest) chest.getRightSide());
    }

    if (inventory.getHolder() instanceof Chest) {
        checkWorth((Chest) inventory.getHolder());
    }
}
 
Example 2
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryOpenEvent(InventoryOpenEvent event) {
	if (event.getInventory() instanceof DoubleChestInventory) {
		DoubleChestInventory doubleInv = (DoubleChestInventory)event.getInventory();
					
		Chest leftChest = (Chest)doubleInv.getHolder().getLeftSide();			
		/*Generate a new player 'switch' event for the left and right chests. */
		PlayerInteractEvent interactLeft = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, leftChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactLeft);
		
		if (interactLeft.isCancelled()) {
			event.setCancelled(true);
			return;
		}
		
		Chest rightChest = (Chest)doubleInv.getHolder().getRightSide();
		PlayerInteractEvent interactRight = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, rightChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactRight);
		
		if (interactRight.isCancelled()) {
			event.setCancelled(true);
			return;
		}			
	}
}
 
Example 3
Source File: FillListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent event) {
    final MatchPlayer opener = playerFinder.getParticipant(event.getActor());
    if(opener == null) return;

    final Inventory inventory = event.getInventory();
    final Predicate<Filter> passesFilter = passesFilter(inventory.getHolder());
    if(passesFilter == null) return;

    logger.fine(() -> opener.getName() + " opened a " + inventory.getHolder().getClass().getSimpleName());

    // Find all Fillers that apply to the holder of the opened inventory
    final List<Filler> fillers = this.fillers.stream()
                                             .filter(filler -> passesFilter.test(filler.filter()))
                                             .collect(Collectors.toImmutableList());
    if(fillers.isEmpty()) return;

    logger.fine(() -> "Found fillers " + fillers.stream()
                                                .map(Filler::identify)
                                                .collect(java.util.stream.Collectors.joining(", ")));

    // Find all Caches that the opened inventory is part of
    final List<Fillable> fillables = new ArrayList<>();
    for(Cache cache : caches) {
        if(passesFilter.test(cache.region()) && passesFilter.test(cache.filter())) {
            fillables.add(new FillableCache(cache));
        }
    }
    // If the inventory is not in any Cache, just fill it directly
    if(fillables.isEmpty()) {
        fillables.add(new FillableInventory(inventory));
    }

    fillables.forEach(fillable -> fillable.fill(opener, fillers));
}
 
Example 4
Source File: CutCleanListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void openInventoryEvent(InventoryOpenEvent e){
    if (!unlimitedLapis) return;

    if (e.getInventory() instanceof EnchantingInventory){
        e.getInventory().setItem(1, lapis);
    }
}