/** * Cancel players from removing, picking the item in their inventory. * * @param event */ @EventHandler public void cancelMove(InventoryDragEvent event) { Player player = (Player) event.getWhoClicked(); for (ItemStack item : event.getNewItems().values()) { if (item != null && player == getPlayer() && item.equals(itemStack)) { event.setCancelled(true); ((Player) event.getWhoClicked()).updateInventory(); return; } } }
private static boolean isEmpty(Inventory inv) { for (int i = 0; i < inv.getSize(); i++) { ItemStack item = inv.getItem(i); if (item == null) continue; if (item.equals(backShop)) continue; return false; } return true; }
public static int amountCanHold(ItemStack[] items, ItemStack check, boolean extraStack) { int amt = 0; if (items == null) { return 0; } else if (check == null) { return emptySlots(items); } else { int max = !extraStack || noStack.contains(check.getTypeId()) ? JItems.getMaxStack(check) : 64; for (ItemStack item : items) { if (item == null || item.getAmount() == 0 || (check.equals(item) && item.getAmount() <= max)) { amt += max - (item == null ? 0 : item.getAmount()); } } } return amt; }
public static boolean equals(ItemStack one, ItemStack two) { if (isNothing(one)) return isNothing(two); if (isNothing(two)) return false; return one.equals(two); }
// Command public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { // Check for player if (sender instanceof Player) { // Store player and command Player player = (Player) sender; String command = cmd.getName().toUpperCase(); // Check command if (command.equals("CHECKWEAPON")) { // Check for perms if (player.hasPermission("iweapons.checkweapon")) { // Check for player argument if (args.length >= 1) { // Try to store player Player checkPlayer; for (Player p : Bukkit.getOnlinePlayers()) { if (p.getName().equals(args[0])) { checkPlayer = p; // Get the item in slot 9 of the player's htbar ItemStack item = checkPlayer.getInventory().getItem(8); try { if (!item.equals(null)) { // Check for an iWeapon item WeaponItems wi = new WeaponItems(plugin); if (wi.isWeapon(item)) { player.sendMessage( ChatColor.GOLD + "" + ChatColor.BOLD + "[iWeapons] " + ChatColor.GREEN + checkPlayer.getName() + " has the " + item.getItemMeta().getDisplayName() + ChatColor.GREEN + " weapon!"); } else { player.sendMessage( ChatColor.GOLD + "" + ChatColor.BOLD + "[iWeapons] " + ChatColor.GREEN + checkPlayer.getName() + " does not have a weapon!"); } return true; } } catch (NullPointerException npe) { player.sendMessage( ChatColor.GOLD + "" + ChatColor.BOLD + "[iWeapons] " + ChatColor.GREEN + checkPlayer.getName() + " does not have a weapon!"); return true; } } } // The player is not online player.sendMessage( ChatColor.GOLD + "" + ChatColor.BOLD + "[iWeapons] " + ChatColor.RED + "The specified player is not online!"); return true; } else { player.sendMessage( ChatColor.GOLD + "" + ChatColor.BOLD + "[iWeapons] " + ChatColor.GREEN + "You must specify a player!"); } } else { player.sendMessage( ChatColor.GOLD + "" + ChatColor.BOLD + "[iWeapons] " + ChatColor.RED + "You do not have permission to use this command."); } } } else { sender.sendMessage("[iWeapons] This command is only for players!"); } return true; }
public static boolean equals(ItemStack first, ItemStack second) { if (first == null) return second == null; return first.equals(second); }