Java Code Examples for org.bukkit.event.inventory.InventoryClickEvent#getClickedInventory()

The following examples show how to use org.bukkit.event.inventory.InventoryClickEvent#getClickedInventory() . 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: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (event.getClickedInventory() == null) {
        return;
    }

    if (event.getClickedInventory().getType() == InventoryType.PLAYER) {
        Player p = (Player) event.getWhoClicked();
        if (Main.isPlayerInGame(p)) {
            GamePlayer gPlayer = Main.getPlayerGameProfile(p);
            Game game = gPlayer.getGame();
            if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 2
Source File: IslandMenuGUI.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@Override
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        Player p = (Player) e.getWhoClicked();
        for(Inventories.Item item : IridiumSkyblock.getInventories().menu.keySet()){
            if(item.slot==e.getSlot()){
                p.closeInventory();
                Bukkit.getServer().dispatchCommand(e.getWhoClicked(), IridiumSkyblock.getInventories().menu.get(item));
                return;
            }
        }
    }
}
 
Example 3
Source File: CoopGUI.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@Override
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        if (islands.containsKey(e.getSlot())) {
            Island island = IridiumSkyblock.getIslandManager().getIslandViaId(islands.get(e.getSlot()));
            User u = User.getUser((OfflinePlayer) e.getWhoClicked());
            if (e.getClick().equals(ClickType.RIGHT)) {
                if (u.bypassing || u.getIsland().getPermissions(u.getRole()).coop) {
                    getIsland().removeCoop(island);
                } else {
                    e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
            } else {
                if (island.isVisit() || u.bypassing) {
                    island.teleportHome((Player) e.getWhoClicked());
                } else {
                    e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().playersIslandIsPrivate.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
            }
        }
    }
}
 
Example 4
Source File: LanguagesGUI.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@Override
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        if (languages.containsKey(e.getSlot())) {
            IridiumSkyblock.getInstance().setLanguage(languages.get(e.getSlot()), (Player) e.getWhoClicked());
        } else if (e.getSlot() == getInventory().getSize() - 7) {
            if (root.pages.containsKey(page - 1)) {
                e.getWhoClicked().openInventory(root.pages.get(page - 1).getInventory());
            }
        } else if (e.getSlot() == getInventory().getSize() - 3) {
            if (root.pages.containsKey(page + 1)) {
                e.getWhoClicked().openInventory(root.pages.get(page + 1).getInventory());
            }
        }
    }
}
 
Example 5
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (event.getClickedInventory() == null) {
        return;
    }

    if (event.getClickedInventory().getType() == InventoryType.PLAYER) {
        Player p = (Player) event.getWhoClicked();
        if (Main.isPlayerInGame(p)) {
            GamePlayer gPlayer = Main.getPlayerGameProfile(p);
            Game game = gPlayer.getGame();
            if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 6
Source File: EnhancedItemListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Prevents enhanced item from glitching.
 *
 * @param inventoryClickEvent
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onItemGlitch(InventoryClickEvent inventoryClickEvent) {
    ItemStack currentItem = inventoryClickEvent.getCurrentItem();
    ItemStack cursor = inventoryClickEvent.getCursor();
    try {
        if (inventoryClickEvent.getClickedInventory() != null && inventoryClickEvent.getClickedInventory().firstEmpty() == -1) {
            if (currentItem != null && currentItem.hasItemMeta() && (currentItem.getItemMeta().hasLore())) {
                if (currentItem.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) {
                    inventoryClickEvent.setCancelled(true);
                    Util.sendMessage(SettingsManager.lang.getString("messages.noDrop"), inventoryClickEvent.getWhoClicked());
                }
            }
            if (cursor != null && cursor.hasItemMeta() && (cursor.getItemMeta().hasLore())) {
                if (cursor.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) {
                    inventoryClickEvent.setCancelled(true);
                    Util.sendMessage(SettingsManager.lang.getString("messages.noDrop"), inventoryClickEvent.getWhoClicked());
                }
            }
        }
    } catch (NoSuchMethodError ex) {
        // craftbukkit
    }
}
 
Example 7
Source File: InventoryForItemStorage.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void inventoryClick(InventoryClickEvent event) {
	Inventory inventory = event.getClickedInventory();
	if (inventory != null) {
		InventoryAction action = event.getAction();
		if (action == InventoryAction.COLLECT_TO_CURSOR) {
			event.setCancelled(true);
		} else if (inventory.getType() == InventoryType.PLAYER) {
			if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
				event.setCancelled(true);
			}
		} else {
			event.setCancelled(true);
			int slot = event.getSlot();
			if (slot < ITEMS_PER_PAGE) {
				if (event.getCursor().getType() == Material.AIR && _originaItems[slot] != null) {
					event.getView().setCursor(_originaItems[slot]);
				}
			} else if (slot == 52) {
				// previous page
				changePage(-1);
			} else if (slot == 53) {
				// next page
				changePage(1);
			}
		}
	}
	
}
 
Example 8
Source File: BiomeGUI.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
@Override
public void onInventoryClick(InventoryClickEvent e) {
    if (getInventory() == null) {
        for (BiomeGUI gui : pages.values()) {
            gui.onInventoryClick(e);
        }
    } else {
        if (e.getInventory().equals(getInventory())) {
            e.setCancelled(true);
            if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
            if (e.getSlot() == getInventory().getSize() - 3) {
                if (root.pages.containsKey(page + 1)) {
                    e.getWhoClicked().openInventory(root.pages.get(page + 1).getInventory());
                }
            }
            if (e.getSlot() == getInventory().getSize() - 7) {
                if (root.pages.containsKey(page - 1)) {
                    e.getWhoClicked().openInventory(root.pages.get(page - 1).getInventory());
                }
            }
            if (biomes.containsKey(e.getSlot())) {
                getIsland().setBiome(biomes.get(e.getSlot()));
            }
        }
    }
}
 
Example 9
Source File: ConfirmationGUI.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
@Override
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        if (e.getSlot() == 12) {
            e.getWhoClicked().closeInventory();
            runnable.run();
        } else if (e.getSlot() == 14) {
            e.getWhoClicked().closeInventory();
        }
    }
}
 
Example 10
Source File: VisitGUI.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
@Override
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        if (islands.containsKey(e.getSlot())) {
            Island island = IridiumSkyblock.getIslandManager().getIslandViaId(islands.get(e.getSlot()));
            User u = User.getUser((OfflinePlayer) e.getWhoClicked());
            if (island.isVisit() || u.bypassing) {
                if (e.getClick() == ClickType.RIGHT) {
                    if (island.hasVoted(u)) {
                        island.removeVote(u);
                    } else {
                        island.addVote(u);
                    }
                } else {
                    e.getWhoClicked().closeInventory();
                    island.teleportHome((Player) e.getWhoClicked());
                }
            } else {
                e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().playersIslandIsPrivate.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
        } else if (e.getSlot() == getInventory().getSize() - 7) {
            if (IridiumSkyblock.visitGUI.containsKey(page - 1))
                e.getWhoClicked().openInventory(IridiumSkyblock.visitGUI.get(page - 1).getInventory());
        } else if (e.getSlot() == getInventory().getSize() - 3) {
            if (IridiumSkyblock.visitGUI.containsKey(page + 1))
                e.getWhoClicked().openInventory(IridiumSkyblock.visitGUI.get(page + 1).getInventory());
        }
    }
}
 
Example 11
Source File: InventoryClickListener.java    From black with GNU General Public License v3.0 5 votes vote down vote up
/**
 * the listener that listens for inventory clicks and informs the pages associated with them.
 *
 * @param event the event that happened
 * @see InventoryClickEvent
 */
@EventHandler
public void listener(final InventoryClickEvent event) {
    if (event.getInventory().getHolder() instanceof Page &&
            !(event.getClickedInventory() instanceof PlayerInventory)) {

        ((Page) event.getInventory().getHolder()).accept(event);
    }
}
 
Example 12
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteractInventoryClick(InventoryClickEvent event) {
    final HumanEntity player = event.getWhoClicked();
    GDCauseStackManager.getInstance().pushCause(player);
    if (!GDFlags.INTERACT_INVENTORY_CLICK || event.getClickedInventory() == null || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.startTiming();
    final Location location = player.getLocation();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    final ItemStack cursorItem = event.getCursor();
    final Inventory source = event.getInventory();
    final ItemStack target = event.getCurrentItem();

    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_INVENTORY_CLICK.getName(), target, player.getWorld().getUID())) {
        GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTiming();
        return;
    }

    final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(player.getUniqueId());
    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_INVENTORY_CLICK, source, target, user, TrustTypes.CONTAINER, true);
    if (result == Tristate.FALSE) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_INTERACT_ITEM,
                ImmutableMap.of(
                "player", claim.getOwnerDisplayName(),
                "item", ItemTypeRegistryModule.getInstance().getNMSKey(target)));
        GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }
    GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTiming();
}
 
Example 13
Source File: PotionFuelsListener.java    From UHC with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void on(InventoryClickEvent event) {
    if (event.getInventory().getType() != InventoryType.BREWING) return;

    // quick exit
    if (disabled.size() == 0) return;

    // clicked outside of the window
    if (event.getClickedInventory() == null) return;

    final InventoryType clicked = event.getClickedInventory().getType();

    // get any relevant stack to check the type of based on the action took
    Optional<ItemStack> relevant = Optional.absent();
    switch (event.getAction()) {
        case MOVE_TO_OTHER_INVENTORY:
            // only worry about player -> stand
            if (clicked == InventoryType.PLAYER) {
                relevant = Optional.fromNullable(event.getCurrentItem());
            }
            break;
        case PLACE_ALL:
        case PLACE_SOME:
        case PLACE_ONE:
        case SWAP_WITH_CURSOR:
            // only worry about within a stand
            if (clicked == InventoryType.BREWING) {
                relevant = Optional.fromNullable(event.getCursor());
            }
            break;
        case HOTBAR_SWAP:
            // only worry about within a stand
            if (clicked == InventoryType.BREWING) {
                relevant = Optional.fromNullable(
                        event.getWhoClicked().getInventory().getItem(event.getHotbarButton())
                );
            }
            break;
        default:
    }

    if (relevant.isPresent() && disabled.contains(relevant.get().getType())) {
        event.getWhoClicked().sendMessage(messages.get(relevant.get().getType()));
        event.setCancelled(true);
    }
}
 
Example 14
Source File: AnvilListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
	HumanEntity he = event.getWhoClicked();

	if (!(he instanceof Player && event.getClickedInventory() instanceof AnvilInventory)) {
		return;
	}

	AnvilInventory inv = (AnvilInventory) event.getClickedInventory();
	Player player = (Player) he;

	ItemStack tool = inv.getItem(0);
	ItemStack modifier = inv.getItem(1);
	ItemStack newTool = inv.getItem(2);

	if (tool == null || modifier == null || newTool == null) {
		return;
	}

	if (event.getSlot() != 2) {
		return;
	}

	if (Lists.WORLDS.contains(player.getWorld().getName())) {
		return;
	}

	if (!(modManager.isToolViable(tool) || modManager.isArmorViable(tool))) {
		return;
	}

	//boolean deleteAllItems = false;
	if (event.getCursor() != null && !event.getCursor().getType().equals(Material.AIR)) {
		return;
	}

	if (!modManager.isModifierItem(modifier)) { //upgrade
		if (tool.getType().equals(newTool.getType())) return; //Not an upgrade

		if (new Random().nextInt(100) < MineTinker.getPlugin().getConfig().getInt("ChanceToFailToolUpgrade")) {
			newTool = tool;
			Bukkit.getPluginManager().callEvent(new ToolUpgradeEvent(player, newTool, false));
		} else {
			Bukkit.getPluginManager().callEvent(new ToolUpgradeEvent(player, newTool, true));
		}

		// ------ upgrade
		if (event.isShiftClick()) {
			if (player.getInventory().addItem(newTool).size() != 0) { //adds items to (full) inventory and then case if inventory is full
				event.setCancelled(true); //cancels the event if the player has a full inventory
				return;
			} // no else as it gets added in if-clause

			inv.clear();
			return;
		}

		player.setItemOnCursor(newTool);
		inv.clear();
	} else { //is modifier
		Modifier mod = modManager.getModifierFromItem(modifier);

		if (mod == null) {
			return;
		}

		modifier.setAmount(modifier.getAmount() - 1);

		if (new Random().nextInt(100) < MineTinker.getPlugin().getConfig().getInt("ChanceToFailModifierApply")) {
			newTool = tool;
			Bukkit.getPluginManager().callEvent(new ModifierFailEvent(player, tool, mod, ModifierFailCause.PLAYER_FAILURE, false));
		} else {
			Bukkit.getPluginManager().callEvent(new ModifierApplyEvent(player, tool, mod, modManager.getFreeSlots(newTool), false));
		}

		if (event.isShiftClick()) {
			if (player.getInventory().addItem(newTool).size() != 0) { //adds items to (full) inventory and then case if inventory is full
				event.setCancelled(true); //cancels the event if the player has a full inventory
				return;
			} // no else as it gets added in if-clause

			inv.clear();
			inv.setItem(1, modifier);

			return;
		}

		player.setItemOnCursor(newTool);

		inv.clear();
		inv.setItem(1, modifier);
	}
}
 
Example 15
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true) @SuppressWarnings("unused")
public void onCivilianClickItem(InventoryClickEvent event) {
    if (event.getClickedInventory() != null) {
        Location inventoryLocation = event.getClickedInventory().getLocation();
        UnloadedInventoryHandler.getInstance().updateInventoryAtLocation(inventoryLocation);
    }
    handleCustomItem(event.getCurrentItem(), event.getWhoClicked().getUniqueId());
    if (ConfigManager.getInstance().getAllowSharingCivsItems()) {
        return;
    }
    boolean shiftClick = event.getClick().isShiftClick() && event.getClickedInventory() != null &&
            event.getClickedInventory().equals(event.getWhoClicked().getInventory());
    boolean dragToChest = event.getClickedInventory() != null &&
            !event.getClickedInventory().equals(event.getWhoClicked().getInventory());

    if (event.getView().getTopInventory().getHolder() instanceof DoubleChest) {
        DoubleChest doubleChest = (DoubleChest) event.getView().getTopInventory().getHolder();
        Location leftLocation = ((Chest) doubleChest.getLeftSide()).getLocation();
        Location rightLocation = ((Chest) doubleChest.getRightSide()).getLocation();
        RegionManager.getInstance().removeCheckedRegion(leftLocation);
        RegionManager.getInstance().removeCheckedRegion(rightLocation);
    } else {
        if (event.getClickedInventory() != null &&
                event.getClickedInventory().getType() != InventoryType.ENDER_CHEST &&
                event.getView().getTopInventory().getType() != InventoryType.ENDER_CHEST) {
            try {
                RegionManager.getInstance().removeCheckedRegion(event.getView().getTopInventory().getLocation());
            } catch (NullPointerException npe) {
                // Doesn't matter if there's an error here
            }
        }
    }

    ItemStack stackInQuestion = shiftClick ? event.getCurrentItem() : event.getCursor();

    if (stackInQuestion == null || (!shiftClick && !dragToChest)) {
        return;
    }

    if (!CVItem.isCivsItem(stackInQuestion) || MenuManager.getInstance().hasMenuOpen(event.getWhoClicked().getUniqueId())) {
        return;
    }
    HumanEntity humanEntity = event.getWhoClicked();
    event.setCancelled(true);
    humanEntity.sendMessage(Civs.getPrefix() +
            LocaleManager.getInstance().getTranslationWithPlaceholders((Player) humanEntity, LocaleConstants.PREVENT_CIVS_ITEM_SHARE));
}
 
Example 16
Source File: ListenerMenuAction.java    From TrMenu with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onClick(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();

    Notifys.debug(p, "Clicked raw slot §f{0}", e.getRawSlot());

    long start = System.currentTimeMillis();

    if (e.isCancelled() && TrMenu.SETTINGS.getBoolean("OPTIONS.IGNORE-CANCELLED")) {
        Notifys.debug(p, "Ignored cancelled");
        return;
    }
    if (!(e.getInventory().getHolder() instanceof MenuHolder)) {
        Notifys.debug(p, "Not a MenuHolder");
        return;
    }

    Menu menu = ((MenuHolder) e.getInventory().getHolder()).getMenu();
    Button button = menu.getButton(p, e.getRawSlot());

    // Anti ClickSpam
    clickTimes.putIfAbsent(p.getUniqueId(), 0L);
    if (System.currentTimeMillis() - clickTimes.get(p.getUniqueId()) < TrMenu.SETTINGS.getLong("OPTIONS.ANTI-CLICK-SPAM")) {
        e.setCancelled(true);
        Notifys.debug(p, "Anti-Spam, event cancelled.");
        return;
    } else {
        clickTimes.put(p.getUniqueId(), System.currentTimeMillis());
    }
    if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY || e.getAction() == InventoryAction.HOTBAR_SWAP) {
        e.setCancelled(true);
    }
    // Lock PLayer's Inventory
    if (button == null) {
        if (e.getClickedInventory() == p.getInventory() && menu.isLockPlayerInv()) {
            e.setCancelled(true);
        }
        Notifys.debug(p, "Null button");
        return;
    } else {
        e.setCancelled(true);
    }

    button.getIcon(p).onClick(p, button, e.getClick(), e);
    Notifys.debug(p, "§6InventoryClickEvent Took §e{0}ms§6.", System.currentTimeMillis() - start);
}
 
Example 17
Source File: Listeners.java    From PlayerVaults with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onClick(InventoryClickEvent event) {
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getWhoClicked();

    Inventory clickedInventory = event.getClickedInventory();
    if (clickedInventory != null) {
        VaultViewInfo info = PlayerVaults.getInstance().getInVault().get(player.getUniqueId().toString());
        if (info != null) {
            int num = info.getNumber();
            String inventoryTitle = event.getView().getTitle();
            String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(num)).replace("%p", info.getVaultName());
            if (inventoryTitle.equalsIgnoreCase(title)) {
                ItemStack[] items = new ItemStack[2];
                items[0] = event.getCurrentItem();
                if (event.getHotbarButton() > -1 && event.getWhoClicked().getInventory().getItem(event.getHotbarButton()) != null) {
                    items[1] = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
                }

                for (ItemStack item : items) {
                    if (item == null) {
                        continue;
                    }
                    try {
                        item.toString();
                    } catch (Exception e) {
                        player.sendMessage(Lang.TITLE.toString() + Lang.BLOCKED_BAD_ITEM);
                        event.setCancelled(true);
                        return;
                    }
                    if (!player.hasPermission("playervaults.bypassblockeditems") && PlayerVaults.getInstance().isBlockedMaterial(item.getType())) {
                        event.setCancelled(true);
                        player.sendMessage(Lang.TITLE.toString() + Lang.BLOCKED_ITEM.toString().replace("%m", item.getType().name()));
                        return;
                    }
                }
            }
        }
    }
}
 
Example 18
Source File: HorseArmourModule.java    From UHC with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void on(InventoryClickEvent event) {
    if (isEnabled()) return;

    if (!(event.getView().getTopInventory() instanceof HorseInventory)) return;

    // clicked outside of the window
    if (event.getClickedInventory() == null) return;

    final InventoryType clicked = event.getClickedInventory().getType();

    // get any relevant stack to check the type of based on the action took
    Optional<ItemStack> relevant = Optional.absent();
    switch (event.getAction()) {
        case MOVE_TO_OTHER_INVENTORY:
            // only worry about player -> horse
            if (clicked == InventoryType.PLAYER) {
                relevant = Optional.fromNullable(event.getCurrentItem());
            }
            break;
        case PLACE_ALL:
        case PLACE_SOME:
        case PLACE_ONE:
        case SWAP_WITH_CURSOR:
            // only worry about within the horse
            if (clicked != InventoryType.PLAYER) {
                relevant = Optional.fromNullable(event.getCursor());
            }
            break;
        case HOTBAR_SWAP:
            // only worry about within a horse
            if (clicked != InventoryType.PLAYER) {
                relevant = Optional.fromNullable(
                        event.getWhoClicked().getInventory().getItem(event.getHotbarButton())
                );
            }
            break;
        default:
    }

    if (relevant.isPresent() && DISABLED.contains(relevant.get().getType())) {
        event.getWhoClicked().sendMessage(messages.getRaw("disabled message"));
        event.setCancelled(true);
    }
}
 
Example 19
Source File: BoosterGUI.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
@Override
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        Player p = (Player) e.getWhoClicked();
        Island island = IridiumSkyblock.getIslandManager().islands.get(islandID);
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        if (e.getSlot() == IridiumSkyblock.getBoosters().spawnerBooster.slot && IridiumSkyblock.getBoosters().spawnerBooster.enabled) {
            if (getIsland().getSpawnerBooster() == 0) {
                if (Utils.canBuy(p, IridiumSkyblock.getBoosters().spawnerBooster.vaultCost, IridiumSkyblock.getBoosters().spawnerBooster.crystalsCost)) {
                    getIsland().setSpawnerBooster(IridiumSkyblock.getBoosters().spawnerBooster.time);
                } else {
                    e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().notEnoughCrystals.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
            } else {
                e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().spawnerBoosterActive.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
        }
        if (e.getSlot() == IridiumSkyblock.getBoosters().farmingBooster.slot && IridiumSkyblock.getBoosters().farmingBooster.enabled) {
            if (getIsland().getFarmingBooster() == 0) {
                if (Utils.canBuy(p, IridiumSkyblock.getBoosters().farmingBooster.vaultCost, IridiumSkyblock.getBoosters().farmingBooster.crystalsCost)) {
                    getIsland().setFarmingBooster(IridiumSkyblock.getBoosters().farmingBooster.time);
                } else {
                    e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().notEnoughCrystals.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
            } else {
                e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().farmingBoosterActive.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
        }
        if (e.getSlot() == IridiumSkyblock.getBoosters().experianceBooster.slot && IridiumSkyblock.getBoosters().experianceBooster.enabled) {
            if (getIsland().getExpBooster() == 0) {
                if (Utils.canBuy(p, IridiumSkyblock.getBoosters().experianceBooster.vaultCost, IridiumSkyblock.getBoosters().experianceBooster.crystalsCost)) {
                    getIsland().setExpBooster(IridiumSkyblock.getBoosters().experianceBooster.time);
                } else {
                    e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().notEnoughCrystals.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
            } else {
                e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().expBoosterActive.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
        }
        if (e.getSlot() == IridiumSkyblock.getBoosters().flightBooster.slot && IridiumSkyblock.getBoosters().flightBooster.enabled) {
            if (getIsland().getFlightBooster() == 0) {
                if (Utils.canBuy(p, IridiumSkyblock.getBoosters().flightBooster.vaultCost, IridiumSkyblock.getBoosters().flightBooster.crystalsCost)) {
                    getIsland().setFlightBooster(IridiumSkyblock.getBoosters().flightBooster.time);
                } else {
                    e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().notEnoughCrystals.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
            } else {
                e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().flightBoosterActive.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
        }
    }
}
 
Example 20
Source File: Recipes.java    From ProRecipes with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void noClickFurnace(InventoryClickEvent event){
	if(event.getClickedInventory() != null && event.getClickedInventory().getType().equals(InventoryType.FURNACE)){
		//System.out.println(event.getAction());
		if(event.getRawSlot() == 0){
			//System.out.println(event.getRawSlot());

			//System.out.println(event.getAction());
			switch(event.getAction()){
				case PLACE_ONE:
				case PLACE_SOME:
				case PLACE_ALL:
				case UNKNOWN:
				case DROP_ALL_CURSOR:
				case DROP_ALL_SLOT:
				case DROP_ONE_CURSOR:
				case DROP_ONE_SLOT:
				case MOVE_TO_OTHER_INVENTORY:
				case SWAP_WITH_CURSOR:
					boolean match = false;
					RecipeFurnace rec = null;
					if(event.getCursor() == null || event.getCursor().getType() == Material.AIR){
						
						return;
					}
					ItemStack c = event.getCursor().clone();
					for(RecipeFurnace r : fur){
						if(r.match(c)){
							if(r.hasPermission()){
								if(!((Player)event.getWhoClicked()).hasPermission(r.getPermission())){
									event.setCancelled(true);
									event.getWhoClicked().sendMessage(ProRecipes.getPlugin().ms.getMessage("no_permission_smelt", ChatColor.RED + "You do not have permission to smelt this item."));
									return;
								}
							}
						}
					}
			}
		}
		
	}
}