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

The following examples show how to use org.bukkit.event.inventory.InventoryClickEvent#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: AnvilRenameListener.java    From MineableSpawners with MIT License 6 votes vote down vote up
@EventHandler (ignoreCancelled = true)
public void onAnvilRename(InventoryClickEvent e) {
  if (e.getInventory() == null || e.getInventory().getType() == null) {
    return;
  }

  if (e.getCurrentItem() == null || e.getCurrentItem().getType() == null) {
    return;
  }

  if (e.getInventory().getType() != InventoryType.ANVIL || e.getCurrentItem().getType() != XMaterial.SPAWNER.parseMaterial()) {
    return;
  }

  if (!plugin.getConfigurationHandler().getBoolean("anvil", "prevent-anvil")) {
    return;
  }

  Player player = (Player) e.getWhoClicked();
  e.setCancelled(true);
  player.sendMessage(plugin.getConfigurationHandler().getMessage("anvil", "prevented"));
}
 
Example 2
Source File: RepairListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onAnvilGUIClick(final InventoryClickEvent event) {
    if (event.getInventory().getType() == InventoryType.ANVIL && event.getWhoClicked() instanceof Player) {
        if (!(event.getInventory() instanceof AnvilInventory)) {
            return;
        }
        final Player player = (Player) event.getWhoClicked();
        final AnvilInventory inv = (AnvilInventory) event.getInventory();
        AnvilTask task = AnvilTask.getTask(inv);
        if (task == null) {
            task = new AnvilTask(inv, player);
        }
        if (event.getRawSlot() == 2) {
            final ItemStack translatedItem = ColorHandler.getTranslatedItem(player, inv, task);
            event.setCurrentItem(translatedItem);
        }
    }
}
 
Example 3
Source File: CutCleanListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent e){
    Inventory inv = e.getInventory();
    ItemStack item = e.getCurrentItem();
    if (!unlimitedLapis) return;
    if (inv == null || item == null) return;

    if (inv instanceof EnchantingInventory){

        if (item.getType().equals(lapis.getType())){
            e.setCancelled(true);
        }else {
            e.getInventory().setItem(1, lapis);
        }
    }
}
 
Example 4
Source File: IconInventory.java    From UHC with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void on(InventoryClickEvent event) {
    final Inventory inventory = event.getInventory();
    if (!inventory.getTitle().equals(title)) return;

    event.setCancelled(true);

    final int slot = event.getRawSlot();

    if (slot < 0 || slot >= inventory.getSize() || slot >= icons.size()) return;

    // call event
    final IconStack icon = icons.get(slot);

    if (icon != null) {
        icon.onClick((Player) event.getWhoClicked());
    }
}
 
Example 5
Source File: ArmorListener.java    From ViaVersion with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e) {
    HumanEntity human = e.getWhoClicked();
    if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
        final Player player = (Player) human;
        if (e.getCurrentItem() != null) {
            if (ArmorType.isArmor(e.getCurrentItem().getTypeId())) {
                sendDelayedArmorUpdate(player);
                return;
            }
        }
        if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) {
            sendDelayedArmorUpdate(player);
        }
    }
}
 
Example 6
Source File: VanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPreBrew(InventoryClickEvent e) {
    Inventory inventory = e.getInventory();

    if (inventory.getType() == InventoryType.BREWING && e.getRawSlot() < inventory.getSize() && inventory.getHolder() instanceof BrewingStand) {
        e.setCancelled(isUnallowed(SlimefunItem.getByItem(e.getCursor())));
    }
}
 
Example 7
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 8
Source File: VaultListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent event) {
	if(event.getInventory() == null) {
		return;
	}

	NovaPlayer nPlayer = PlayerManager.getPlayer(event.getWhoClicked());
	String nameVault = Config.VAULT_ITEM.getItemStack().getItemMeta().getDisplayName();

	if(event.getInventory().getTitle() == null || !event.getInventory().getTitle().equals(nameVault)) {
		return;
	}

	if(!event.getView().getTopInventory().equals(CompatibilityUtils.getClickedInventory(event))) {
		return;
	}

	if(!disallowedActions.contains(event.getAction()) && nPlayer.hasPermission(GuildPermission.VAULT_PUT)) {
		return;
	}

	if(nPlayer.hasPermission(GuildPermission.VAULT_TAKE)) {
		return;
	}

	if(nPlayer.getPreferences().getBypass()) {
		return;
	}

	event.setCancelled(true);
}
 
Example 9
Source File: ShopInteractListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e) {
    if (!plugin.getHologramFormat().isDynamic()) return;

    Inventory chestInv = e.getInventory();

    if (!(chestInv.getHolder() instanceof Chest || chestInv.getHolder() instanceof DoubleChest)) {
        return;
    }

    Location loc = null;
    if (chestInv.getHolder() instanceof Chest) {
        loc = ((Chest) chestInv.getHolder()).getLocation();
    } else if (chestInv.getHolder() instanceof DoubleChest) {
        loc = ((DoubleChest) chestInv.getHolder()).getLocation();
    }

    final Shop shop = plugin.getShopUtils().getShop(loc);
    if (shop == null) return;

    new BukkitRunnable() {
        @Override
        public void run() {
            shop.updateHologramText();
        }
    }.runTaskLater(plugin, 1L);
}
 
Example 10
Source File: TradingPlayerShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onInventoryClick(InventoryClickEvent event, Player player) {
	final TradingPlayerShopkeeper shopkeeper = this.getShopkeeper();
	event.setCancelled(true);
	final int slot = event.getRawSlot();
	if (slot >= 0 && slot <= 7) {
		// handle changing sell stack size:
		this.handleUpdateItemAmountOnClick(event, 1);
	} else if ((slot >= 9 && slot <= 16) || (slot >= 18 && slot <= 25)) {
		if (shopkeeper.clickedItem != null) {
			// placing item:
			final Inventory inventory = event.getInventory();
			Bukkit.getScheduler().runTaskLater(ShopkeepersPlugin.getInstance(), new Runnable() {
				public void run() {
					inventory.setItem(slot, shopkeeper.clickedItem);
					shopkeeper.clickedItem = null;
				}
			}, 1);
		} else {
			// changing stack size of clicked item:
			this.handleUpdateItemAmountOnClick(event, 0);
		}
	} else if (slot >= 27) {
		// clicking in player inventory:
		if (event.isShiftClick() || !event.isLeftClick()) {
			return;
		}
		ItemStack cursor = event.getCursor();
		if (!Utils.isEmpty(cursor)) {
			return;
		}
		ItemStack current = event.getCurrentItem();
		if (!Utils.isEmpty(current)) {
			shopkeeper.clickedItem = current.clone();
			shopkeeper.clickedItem.setAmount(1);
		}
	} else {
		super.onInventoryClick(event, player);
	}
}
 
Example 11
Source File: Preview.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    if (e.getInventory() != null && playerCrate.get(player.getUniqueId()) != null) {
        Crate crate = playerCrate.get(player.getUniqueId());
        if (crate.isPreview(e.getView())) {
            e.setCancelled(true);
            if (e.getCurrentItem() != null) {
                if (e.getRawSlot() == crate.getAbsoluteItemPosition(4)) {// Clicked the menu button.
                    if (playerInMenu(player)) {
                        GUIMenu.openGUI(player);
                    }
                } else if (e.getRawSlot() == crate.getAbsoluteItemPosition(5)) {// Clicked the next button.
                    if (getPage(player) < crate.getMaxPage()) {
                        nextPage(player);
                        openPreview(player, crate);
                    }
                } else if (e.getRawSlot() == crate.getAbsoluteItemPosition(3)) {// Clicked the back button.
                    if (getPage(player) > 1 && getPage(player) <= crate.getMaxPage()) {
                        backPage(player);
                        openPreview(player, crate);
                    }
                }
            }
        }
    }
}
 
Example 12
Source File: CrateControl.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@EventHandler
public void onAdminMenuClick(InventoryClickEvent e) {
    Inventory inv = e.getInventory();
    Player player = (Player) e.getWhoClicked();
    if (inv != null && e.getView().getTitle().equals(Methods.sanitizeColor("&4&lAdmin Keys"))) {
        e.setCancelled(true);
        if (!Methods.permCheck(player, "admin")) {
            player.closeInventory();
            return;
        }
        //Added the >= due to an error about a raw slot set at -999.
        if (e.getRawSlot() < inv.getSize() && e.getRawSlot() >= 0) {//Clicked in the admin menu.
            ItemStack item = inv.getItem(e.getRawSlot());
            if (cc.isKey(item)) {
                Crate crate = cc.getCrateFromKey(item);
                if (e.getAction() == InventoryAction.PICKUP_ALL) {
                    player.getInventory().addItem(crate.getKey());
                } else if (e.getAction() == InventoryAction.PICKUP_HALF) {
                    cc.addKeys(1, player, crate, KeyType.VIRTUAL_KEY);
                    String name = null;
                    ItemStack key = crate.getKey();
                    if (key.hasItemMeta() && key.getItemMeta().hasDisplayName()) {
                        name = key.getItemMeta().getDisplayName();
                    }
                    player.sendMessage(Methods.getPrefix() + Methods.color("&a&l+1 " + (name != null ? name : crate.getName())));
                }
            }
        }
    }
}
 
Example 13
Source File: TopTen.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
public void onInventoryClick(InventoryClickEvent event) {
    Inventory inventory = event.getInventory(); // The inventory that was clicked in
    if (inventory.getName() == null) {
        return;
    }
    // The player that clicked the item
    Player player = (Player) event.getWhoClicked();
    if (!inventory.getTitle().equals(plugin.myLocale().topTenGuiTitle)) {
        return;
    }
    event.setCancelled(true);
    player.updateInventory();
    if(event.getCurrentItem() != null && !event.getCurrentItem().getType().equals(Material.AIR) && event.getRawSlot() < 26) {
        event.getCurrentItem().setType(Material.AIR);
        player.closeInventory();
        String playerName = getPlayer(event.getRawSlot());
        UUID uuid = plugin.getPlayers().getUUID(playerName);
        if (uuid != null && plugin.getWarpSignsListener().getWarp(uuid) != null) {
            Util.runCommand(player, "is warp " + playerName);
        }
    }
    if (event.getSlotType().equals(SlotType.OUTSIDE)) {
        player.closeInventory();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        return;
    }
}
 
Example 14
Source File: DuctSettingsInventory.java    From Transport-Pipes with MIT License 5 votes vote down vote up
@EventHandler
public void onInvClick(InventoryClickEvent e) {
    if (e.getInventory() != null && e.getInventory().equals(inv) && e.getWhoClicked() instanceof Player) {
        if (itemService.isItemWildcardOrBarrier(e.getCurrentItem())) {
            e.setCancelled(true);
            return;
        }
        //don't call click method when double clicked, because before a double click, left click was already registered twice
        if (e.getClick() != ClickType.DOUBLE_CLICK && click((Player) e.getWhoClicked(), e.getRawSlot(), e.getClick())) {
            e.setCancelled(true);
        } else if (e.getClick() == ClickType.DOUBLE_CLICK && e.getAction() == InventoryAction.COLLECT_TO_CURSOR && collect_to_cursor((Player) e.getWhoClicked(), e.getCursor(), e.getRawSlot())) {
            e.setCancelled(true);
        }
    }
}
 
Example 15
Source File: War.java    From Crazy-Crates with MIT License 4 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    final Player player = (Player) e.getWhoClicked();
    final Inventory inv = e.getInventory();
    if (inv != null && canPick.containsKey(player) && cc.isInOpeningList(player)) {
        Crate crate = cc.getOpeningCrate(player);
        if (crate.getCrateType() == CrateType.WAR && canPick.get(player)) {
            ItemStack item = e.getCurrentItem();
            if (item != null && item.getType().toString().contains("STAINED_GLASS_PANE")) {
                final int slot = e.getRawSlot();
                Prize prize = crate.pickPrize(player);
                inv.setItem(slot, prize.getDisplayItem());
                if (cc.hasCrateTask(player)) {
                    cc.endCrate(player);
                }
                canPick.remove(player);
                canClose.put(player, true);
                cc.givePrize(player, prize);
                if (prize.useFireworks()) {
                    Methods.fireWork(player.getLocation().add(0, 1, 0));
                }
                Bukkit.getPluginManager().callEvent(new PlayerPrizeEvent(player, crate, crate.getName(), prize));
                cc.removePlayerFromOpeningList(player);
                player.playSound(player.getLocation(), cc.getSound("BLOCK_ANVIL_PLACE", "ANVIL_LAND"), 1, 1);
                //Sets all other non picked prizes to show what they could have been.
                cc.addCrateTask(player, new BukkitRunnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i < 9; i++) {
                            if (i != slot) {
                                inv.setItem(i, crate.pickPrize(player).getDisplayItem());
                            }
                        }
                        if (cc.hasCrateTask(player)) {
                            cc.endCrate(player);
                        }
                        //Removing other items then the prize.
                        cc.addCrateTask(player, new BukkitRunnable() {
                            @Override
                            public void run() {
                                for (int i = 0; i < 9; i++) {
                                    if (i != slot) {
                                        inv.setItem(i, new ItemStack(Material.AIR));
                                    }
                                }
                                if (cc.hasCrateTask(player)) {
                                    cc.endCrate(player);
                                }
                                //Closing the inventory when finished.
                                cc.addCrateTask(player, new BukkitRunnable() {
                                    @Override
                                    public void run() {
                                        if (cc.hasCrateTask(player)) {
                                            cc.endCrate(player);
                                        }
                                        player.closeInventory();
                                    }
                                }.runTaskLater(cc.getPlugin(), 30));
                            }
                        }.runTaskLater(cc.getPlugin(), 30));
                    }
                }.runTaskLater(cc.getPlugin(), 30));
            }
        }
    }
}
 
Example 16
Source File: WarpPanel.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
public void onInventoryClick(InventoryClickEvent event) {
    Inventory inventory = event.getInventory(); // The inventory that was clicked in
    if (inventory.getName() == null) {
        return;
    }
    // The player that clicked the item
    final Player player = (Player) event.getWhoClicked();
    String title = inventory.getTitle();
    if (!inventory.getTitle().startsWith(plugin.myLocale().warpsTitle + " #")) {
        return;
    }
    event.setCancelled(true);
    if (event.getSlotType().equals(SlotType.OUTSIDE)) {
        player.closeInventory();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        player.updateInventory();
        return;
    }
    ItemStack clicked = event.getCurrentItem(); // The item that was clicked
    if (DEBUG)
        plugin.getLogger().info("DEBUG: inventory size = " + inventory.getSize());
    if (DEBUG)
        plugin.getLogger().info("DEBUG: clicked = " + clicked);
    if (DEBUG)
        plugin.getLogger().info("DEBUG: rawslot = " + event.getRawSlot());
    if (event.getRawSlot() >= event.getInventory().getSize() || clicked.getType() == Material.AIR) {
        return;
    }
    int panelNumber = 0;
    try {
        panelNumber = Integer.valueOf(title.substring(title.indexOf('#')+ 1));
    } catch (Exception e) {
        panelNumber = 0;
    }
    if (clicked.getItemMeta().hasDisplayName()) {
        String command = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
        if (DEBUG)
            plugin.getLogger().info("DEBUG: command = " + command);
        if (command != null) {
            if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsNext))) {
                player.closeInventory();
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber+1));
            } else if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsPrevious))) {
                player.closeInventory();
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber-1));
            } else {
                player.closeInventory();
                Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpswarpToPlayersSign.replace("<player>", command));
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warp " + command);
            }
        }
    }
}
 
Example 17
Source File: InvClick.java    From WildernessTp with MIT License 4 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory() == null)
        return;
    if (e.getView().getTitle() == null)
        return;
    if (e.getView().getTitle().equalsIgnoreCase("wildtp")) {
        if (e.getCurrentItem() == null)
            return;
        e.setCancelled(true);
        ItemStack item = e.getCurrentItem();
        ItemMeta meta = item.getItemMeta();
        String name = meta.getDisplayName().toUpperCase().replace("/","_").replace("-","_");
        BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
        name = name.replace(" ","_");
        String toDo = ItemNames.valueOf(name).getSet();
        switch (toDo.toLowerCase()){
            case "hooks":
                e.getWhoClicked().closeInventory();
                HookGui.openHook((Player) e.getWhoClicked());
                break;
            case "back":
                e.getWhoClicked().closeInventory();
                MainGui.OpenGUI((Player)e.getWhoClicked());
                set.remove(e.getWhoClicked().getUniqueId());
                add.remove(e.getWhoClicked().getUniqueId());
                messages.remove(e.getWhoClicked().getUniqueId());
                sounds.remove(e.getWhoClicked().getUniqueId());
                break;
            case "close":
                scheduler.runTask(wild, () -> e.getWhoClicked().closeInventory());
                MainGui.removeEdit((Player) e.getWhoClicked());
                set.remove(e.getWhoClicked().getUniqueId());
                add.remove(e.getWhoClicked().getUniqueId());
                messages.remove(e.getWhoClicked().getUniqueId());
                sounds.remove(e.getWhoClicked().getUniqueId());
                break;
            case "add":
                e.getWhoClicked().closeInventory();
                AddGui.openMessGui((Player) e.getWhoClicked());
                add.add(e.getWhoClicked().getUniqueId());
                break;
            case "messages":
                e.getWhoClicked().closeInventory();
                MessageGui.openMessGui((Player) e.getWhoClicked());
                messages.add(e.getWhoClicked().getUniqueId());
                break;
            case "set":
                e.getWhoClicked().closeInventory();
                SetGui.OpenSet((Player) e.getWhoClicked());
                set.add(e.getWhoClicked().getUniqueId());
                break;
            default:
                if(toDo.contains("Min")||toDo.contains("Max"))
                    worlds.add(e.getWhoClicked().getUniqueId());
                toSet.put(e.getWhoClicked().getUniqueId(),toDo);
                e.getWhoClicked().closeInventory();
                break;
        }
    }
}
 
Example 18
Source File: InventoryClick.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
public static InventoryClick fromClickEvent(final InventoryClickEvent event)
{
    return new InventoryClick(event.getInventory(), InventoryUtils.locateSlot(event.getRawSlot(), event.getClickedInventory().getType()), event.getClick());
}
 
Example 19
Source File: ItemBuilder.java    From ProRecipes with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event){
	if(event.getInventory() == null || event.getClickedInventory() == null)return;
	if(event.getSlot() == -999)return;
	if(!event.getInventory().getType().equals(InventoryType.WORKBENCH))return;
	if(!event.getWhoClicked().hasMetadata("itemBuilder"))return;
	//////////////////System.out.println("Called");
	//////////////////System.out.println(event.getInventory().getTitle());
	//////////////////System.out.println(event.getAction());
	if(((Player)event.getWhoClicked()).isSneaking()){
		event.setCancelled(true);
		return;
	}
	//////////////////System.out.println(event.getAction());
	String step = event.getWhoClicked().getMetadata("itemBuilder").get(0).asString();
	if(step.equalsIgnoreCase("itemRequest")){
		
		switch(event.getAction()){
		case PLACE_ONE:
		case PLACE_SOME:
		case PLACE_ALL:
		case DROP_ALL_CURSOR:
		case DROP_ALL_SLOT:
		case DROP_ONE_CURSOR:
		case DROP_ONE_SLOT:
		case MOVE_TO_OTHER_INVENTORY:
			event.setCancelled(true);
			ItemStack i = event.getCursor().clone();
			event.setCursor(null);
			if(i == null){
				i = event.getCurrentItem().clone();
				event.setCurrentItem(null);
			}
			event.getInventory().setItem(0, i);
			openInterface((Player)event.getWhoClicked(), true);
		}
	}else if(step.equalsIgnoreCase("itemInterface")){
		if(event.getSlot() == 0){
			
		}else if(event.getSlot() == 1){
			openAddLore((Player)event.getWhoClicked());
		}else if(event.getSlot() == 3){
			openSetDisplayName((Player)event.getWhoClicked());
		}else if(event.getSlot() == 7){
			removeLore((Player)event.getWhoClicked());
		}else if(event.getSlot() == 9){
			finish((Player)event.getWhoClicked());
		}else if(event.getSlot() == 5){
			
		}else if(event.getSlot() == 8){
			
		}
		
		event.setCancelled(true);
	}
	
}
 
Example 20
Source File: ItemRenameListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
    public void onInventoryClick(InventoryClickEvent e) {
// check if the event has been cancelled by another plugin
        if (!e.isCancelled()) {
            HumanEntity ent = e.getWhoClicked();

// not really necessary
            if (ent instanceof Player) {
                Player player = (Player) ent;
                Inventory inv = e.getInventory();

// see if the event is about an anvil
                if (inv instanceof AnvilInventory) {
                    InventoryView view = e.getView();
                    int rawSlot = e.getRawSlot();

// compare the raw slot with the inventory view to make sure we are talking about the upper inventory
                    if (rawSlot == view.convertSlot(rawSlot)) {
/*
slot 0 = left item slot
slot 1 = right item slot
slot 2 = result item slot

see if the player clicked in the result item slot of the anvil inventory
*/
                        if (rawSlot == 2) {
/*
get the current item in the result slot
I think inv.getItem(rawSlot) would be possible too
*/
                            ItemStack item = e.getCurrentItem();

// check if there is an item in the result slot
                            if (item != null) {
                                ItemMeta meta = item.getItemMeta();

// it is possible that the item does not have meta data
                                if (meta != null) {
// see whether the item is beeing renamed
                                    if (meta.hasDisplayName()) {
                                        String displayName = meta.getDisplayName();
                                        ItemManager.setName(item, displayName);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }