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

The following examples show how to use org.bukkit.event.inventory.InventoryClickEvent#getWhoClicked() . 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: 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 2
Source File: InventoryMenu.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInvClick(InventoryClickEvent event) {
    HumanEntity human = event.getWhoClicked();
    if (human instanceof Player) {
        Player player = (Player) human;
        Inventory inv = event.getView().getTopInventory();
        if (inv.getHolder() != null && inv.getHolder() instanceof InventoryMenu && event.getRawSlot() >= 0 && event.getRawSlot() < size) {
            InventoryMenu menu = (InventoryMenu) inv.getHolder();
            event.setCancelled(true);
            MenuIcon icon = slots.get(event.getSlot());
            if (icon != null) {
                icon.onClick(player);
                player.closeInventory();
            }
        }
    }
}
 
Example 3
Source File: ChestGUIListener.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
	Inventory inventory = CompatibilityUtils.getClickedInventory(event);
	if(inventory == null
			|| event.getCurrentItem() == null
			|| (!inventory.equals(event.getView().getTopInventory()) && event.getClick() != ClickType.SHIFT_LEFT && event.getClick() != ClickType.SHIFT_RIGHT)) {
		return;
	}

	Player player = (Player) event.getWhoClicked();
	NovaPlayer nPlayer = PlayerManager.getPlayer(player);
	GUIInventory guiInventory = nPlayer.getGuiInventory();

	if(guiInventory != null) {
		event.setCancelled(true);

		if(event.getSlot() == inventory.getSize() - 1 && event.getCurrentItem().equals(Message.INVENTORY_GUI_BACK.getItemStack())) {
			player.closeInventory();
			return;
		}

		if(event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR) {
			guiInventory.onClick(event);
		}
	}
}
 
Example 4
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 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: ViewInventoryMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void checkInventoryClick(final InventoryClickEvent event) {
  if (event.getWhoClicked() instanceof Player) {
    MatchPlayer player = this.match.getPlayer((Player) event.getWhoClicked());
    if (player == null) {
      return;
    }
    // we only cancel when the view is a chest because the other views tend to crash
    if (!allowedInventoryType(event.getInventory().getType())) {
      // cancel the click if the player cannot interact with the world or if the match has just
      // started
      if (!player.canInteract()
          || (player.getMatch().isRunning()
              && TimeUtils.isShorterThan(player.getMatch().getDuration(), CHEST_PROTECT_TIME))) {
        event.setCancelled(true);
      }
    }
  }
}
 
Example 7
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 8
Source File: InventoryConvIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }
    if (!event.getWhoClicked().equals(player)) {
        return;
    }
    event.setCancelled(true);
    if (processingLastClick) return;
    int slot = event.getRawSlot();
    // calculate the option number
    if (slot % 9 > 1) {
        int row = (int) Math.floor(slot / 9);
        // raw column number minus two columns (npc head an empty space)
        // and plus one (because options are indexed starting with 1)
        int col = (slot % 9) - 2 + 1;
        // each row can have 7 options, add column number to get an option
        int choosen = (row * 7) + col;
        String message = options.get(choosen);
        if (message != null) {
            processingLastClick = true;
            if (printMessages) conv.sendMessage(answerPrefix + message);
            conv.passPlayerAnswer(choosen);
        }
    }
}
 
Example 9
Source File: PlayerInteractListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInventoryClick(final InventoryClickEvent event) {
	if (event.getWhoClicked() instanceof Player) {
    	GameMap gMap = MatchManager.get().getPlayerMap((Player) event.getWhoClicked());
    	if (gMap == null) {
    		ItemStack item;
    		ItemStack item2;
    		if (event.getClick().equals(ClickType.NUMBER_KEY)) {
    			item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
    			item2 = event.getCurrentItem();
    		} else {
    			item = event.getCurrentItem();
    			item2 = event.getCurrentItem();
    		}
    		
    		if (item != null && (item.equals(SkyWarsReloaded.getIM().getItem("optionselect")) 
    				|| item.equals(SkyWarsReloaded.getIM().getItem("joinselect")) 
    				|| item.equals(SkyWarsReloaded.getIM().getItem("spectateselect"))) 
    				|| item2 != null && (item2.equals(SkyWarsReloaded.getIM().getItem("optionselect")) 
            		|| item2.equals(SkyWarsReloaded.getIM().getItem("joinselect")) 
            		|| item2.equals(SkyWarsReloaded.getIM().getItem("spectateselect"))) ) {
    			event.setCancelled(true);
    		}
    	} else {
    		if (gMap.getMatchState().equals(MatchState.WAITINGSTART) || gMap.getMatchState().equals(MatchState.ENDING)) {
    			event.setCancelled(true);
    		}
    	}
	}

}
 
Example 10
Source File: SmeltingObjective.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onShiftSmelting(InventoryClickEvent event) {
    if (event.getInventory().getType().equals(InventoryType.FURNACE) && event.getRawSlot() == 2
            && event.getClick().equals(ClickType.SHIFT_LEFT) && event.getWhoClicked() instanceof Player) {
        String playerID = PlayerConverter.getID((Player) event.getWhoClicked());
        if (containsPlayer(playerID))
            event.setCancelled(true);
    }
}
 
Example 11
Source File: LobbyListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
 public void onInventoryClick(final InventoryClickEvent e) {
 	Player player = (Player) e.getWhoClicked();
 	if (Util.get().isSpawnWorld(player.getWorld())) {
 		if (SkyWarsReloaded.getCfg().protectLobby()) {
         	if (!player.hasPermission("sw.alterlobby") && !SkyWarsReloaded.getIC().has(player)) {
         		e.setCancelled(true);
         	}
 		}
     	int rawSlot = e.getRawSlot();
if (e.getInventory().equals(joinMenu) && rawSlot < joinMenu.getSize() && rawSlot >= 0) {
	e.setCancelled(true);
	SWRServer server = SWRServer.getServerByDisplayName(ChatColor.stripColor(SkyWarsReloaded.getNMS().getItemName(e.getCurrentItem())));
             if (server == null) {
                 return;
             }
             
             if (server.getMatchState() != MatchState.WAITINGSTART) {
             	Util.get().playSound(player, player.getLocation(), SkyWarsReloaded.getCfg().getErrorSound(), 1, 1);
             	return;
             }
             
             if (player.hasPermission("sw.join")) {
              if (player!= null) {
              	if (server.getMatchState() == MatchState.WAITINGSTART && server.getPlayerCount() < server.getMaxPlayers()) {
               	player.closeInventory();
               	server.setPlayerCount(server.getPlayerCount() + 1);
     			    	server.updateSigns();
 			    		SkyWarsReloaded.get().sendBungeeMsg(player, "Connect", server.getServerName());
              	}
              }
             }
} 
 	}
 }
 
Example 12
Source File: LobbyListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
  public void onInventoryClick(final InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
if (SkyWarsReloaded.getCfg().protectLobby() && Util.get().isSpawnWorld(player.getWorld())) {
	if (!player.hasPermission("sw.alterlobby") && !SkyWarsReloaded.getIC().has(player)) {
		e.setCancelled(true);
	}
}
  }
 
Example 13
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public void onClick(InventoryClickEvent event) {
    ItemStack currentItem = event != null ? event.getCurrentItem() : null;
    if (event == null || currentItem == null) {
        return; // Bail out, nothing we can do anyway
    }
    Player p = (Player) event.getWhoClicked();
    ItemMeta meta = currentItem.getItemMeta();
    SkullMeta skull = meta instanceof SkullMeta ? (SkullMeta) meta : null;
    if (!(event.getInventory().getHolder() instanceof UltimateHolder))
    	return;
    String inventoryName = stripFormatting(((UltimateHolder) event.getInventory().getHolder()).getTitle());
    int slotIndex = event.getSlot();
    int menuSize = event.getInventory().getSize();
    if (inventoryName.equalsIgnoreCase(stripFormatting(tr("Island Group Members")))) {
        onClickPartyMenu(event, currentItem, p, meta, skull, slotIndex);
    } else if (inventoryName.contains(stripFormatting(tr("Permissions")))) {
        onClickPermissionMenu(event, currentItem, p, inventoryName, slotIndex);
    } else if (inventoryName.equalsIgnoreCase(stripFormatting(tr("Island Biome")))) {
        onClickBiomeMenu(event, currentItem, p, slotIndex);
    } else if (inventoryName.contains(stripFormatting(tr("Challenge Menu")))) {
        onClickChallengeMenu(event, currentItem, p, inventoryName);
    } else if (inventoryName.equalsIgnoreCase(stripFormatting(tr("Island Log")))) {
        onClickLogMenu(event, p, slotIndex);
    } else if (inventoryName.equalsIgnoreCase(stripFormatting(tr("Island Menu")))) {
        onClickMainMenu(event, currentItem, p, slotIndex);
    } else if (inventoryName.equalsIgnoreCase(stripFormatting(tr("Island Create Menu")))) {
        onClickCreateMenu(event, p, meta, slotIndex, menuSize);
    } else if (inventoryName.equalsIgnoreCase(stripFormatting(tr("Island Restart Menu")))) {
        onClickRestartMenu(event, p, meta, slotIndex, currentItem);
    } else if (inventoryName.startsWith(stripFormatting(tr("Config:"))) && event.getWhoClicked() instanceof Player) {
        plugin.getConfigMenu().onClick(event);
    }
}
 
Example 14
Source File: KitMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
  if (event instanceof InventoryCreativeEvent
      || event.getWhoClicked() != event.getInventory().getHolder()
      || !ArmorType.isArmorSlot(event.getSlot())) {
    return;
  }

  MatchPlayer player = this.match.getPlayer((Player) event.getWhoClicked());
  if (player == null
      || !this.lockedArmorSlots.containsEntry(
          player, ArmorType.byInventorySlot(event.getSlot()))) {
    return;
  }

  switch (event.getAction()) {
    case PICKUP_ALL:
    case PICKUP_HALF:
    case PICKUP_SOME:
    case PICKUP_ONE:
    case SWAP_WITH_CURSOR:
    case MOVE_TO_OTHER_INVENTORY:
    case DROP_ONE_SLOT:
    case DROP_ALL_SLOT:
    case HOTBAR_SWAP:
    case HOTBAR_MOVE_AND_READD:
    case COLLECT_TO_CURSOR:
      event.setCancelled(true);
      player.sendWarning("This piece of armor cannot be removed", true);
      break;
  }
}
 
Example 15
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 16
Source File: MenuManager.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inv = player.getOpenInventory().getTopInventory();
    for (Menu menu : menus.values()) {
        if (menu.getInventory().getName().equals(inv.getName())) {
            e.setCancelled(true);
            menu.click(player, e.getCurrentItem());
        }
    }
}
 
Example 17
Source File: MenuListener.java    From AmpMenus with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    if (event.getWhoClicked() instanceof Player && event.getInventory().getHolder() instanceof MenuHolder) {
        event.setCancelled(true);
        ((MenuHolder) event.getInventory().getHolder()).getMenu().onInventoryClick(event);
    }
}
 
Example 18
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 19
Source File: StringEditMenu.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onClick(InventoryClickEvent e) {
    if (!(e.getInventory().getHolder() instanceof UltimateHolder) ||
            !stripFormatting(((UltimateHolder) e.getInventory().getHolder()).getTitle()).equals(stripFormatting(getTitle()))) {
        return false;
    }
    Player player = (Player) e.getWhoClicked();
    ItemStack returnItem = e.getInventory().getItem(0);
    String configName = returnItem.getItemMeta().getLore().get(0);
    String path = returnItem.getItemMeta().getLore().get(1);
    int page = getPage(returnItem.getItemMeta().getLore().get(2));
    ItemStack currentItem = e.getCurrentItem();
    boolean isCaps = e.getInventory().getItem(capsIndex).getItemMeta().getDisplayName().equals(tr("Caps On"));
    if (currentItem != null) {
        YmlConfiguration config = FileUtil.getYmlConfiguration(configName);
        String value = config.getString(path);
        if (e.getSlot() == capsIndex) {
            // Toggle caps
            ItemStack capsItem = isCaps ? capsOff.clone() : capsOn.clone();
            ItemMeta meta = capsItem.getItemMeta();
            meta.setLore(Arrays.asList(value));
            capsItem.setItemMeta(meta);
            e.getInventory().setItem(capsIndex, capsItem);
            isCaps = !isCaps;
        } else if (e.getSlot() == backspaceIndex) {
            if (value.length() > 0) {
                value = value.substring(0, value.length() - 1);
                config.set(path, value);
                config.set("dirty", true);
            }
        } else if (e.getSlot() == returnIndex) {
            player.openInventory(parent.createEditMenu(configName, path, page));
            return true;
        } else if (currentItem.getType() == Material.PLAYER_HEAD) {
            String character = stripFormatting(currentItem.getItemMeta().getDisplayName());
            if (character.isEmpty()) {
                character = " ";
            }
            value += isCaps ? character.toUpperCase() : character.toLowerCase();
            config.set(path, value);
            config.set("dirty", true);
        }
        // re-load the ui (refresh)
        player.openInventory(createEditMenuInternal(configName, path, page, isCaps));
    }
    return true;
}
 
Example 20
Source File: VaultBlacklistListener.java    From Guilds with MIT License 4 votes vote down vote up
/**
 * Check if their item is on the vault blacklist
 *
 * @param event the click event
 */
@EventHandler
public void onItemClick(InventoryClickEvent event) {
    // Check if the event was already cancelled before going through this all
    if (event.isCancelled()) {
        return;
    }

    // get the player who is clicking
    Player player = (Player) event.getWhoClicked();

    // check if they are in the list of open vaults
    if (!guildHandler.getOpened().contains(player))
        return;

    // get the item clicked
    ItemStack item = event.getCurrentItem();

    // check if null
    if (item == null)
        return;

    // set cancelled if it contains material name
    event.setCancelled(settingsManager.getProperty(GuildVaultSettings.BLACKLIST_MATERIALS).stream().anyMatch(m ->
            m.equalsIgnoreCase(item.getType().name())));

    // check if event is cancelled, if not, check name
    if (event.isCancelled()) {
        guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.VAULTS__BLACKLISTED);
        return;
    }

    // Make sure item has item meta
    if (!item.hasItemMeta())
        return;

    // Check if it has a display name
    if (item.getItemMeta().hasDisplayName()) {
        // set cancelled if contains name
        event.setCancelled(settingsManager.getProperty(GuildVaultSettings.BLACKLIST_NAMES).stream().anyMatch(m ->
                m.equalsIgnoreCase(ACFBukkitUtil.removeColors(item.getItemMeta().getDisplayName()))));
    }

    // check if event is cancelled
    if (event.isCancelled()) {
        guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.VAULTS__BLACKLISTED);
        return;
    }

    // check if item has lore
    if (!item.getItemMeta().hasLore())
        return;

    // set cancelled if contains lore
    List<String> lore = item.getItemMeta().getLore().stream()
            .map(ACFBukkitUtil::removeColors).collect(Collectors.toList());

    // loop through string list
    for (String check : settingsManager.getProperty(GuildVaultSettings.BLACKLIST_LORES)) {
        // check if the lore contains it
        if (!check.equalsIgnoreCase("")) {
            if (lore.stream().anyMatch(l -> l.contains(check))) {
                // cancel the event
                event.setCancelled(true);
                break;
            }
        }
    }

    // check if event is cancelled, if not, check name
    if (event.isCancelled()) {
        guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.VAULTS__BLACKLISTED);
    }
}