Java Code Examples for org.bukkit.inventory.ItemStack#equals()
The following examples show how to use
org.bukkit.inventory.ItemStack#equals() .
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: SwapHandListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void playerSwapHand(PlayerSwapHandItemsEvent event) { GameMap gMap = MatchManager.get().getPlayerMap(event.getPlayer()); if (gMap == null) { ItemStack item = event.getOffHandItem(); if (item.equals(SkyWarsReloaded.getIM().getItem("optionselect")) || item.equals(SkyWarsReloaded.getIM().getItem("joinselect")) || item.equals(SkyWarsReloaded.getIM().getItem("spectateselect"))) { event.setCancelled(true); } } else { if (gMap.getMatchState().equals(MatchState.WAITINGSTART) || gMap.getMatchState().equals(MatchState.ENDING)) { event.setCancelled(true); } } }
Example 2
Source File: InventoryForSpecialVariable.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
@Override protected void inventoryClick(InventoryClickEvent event) { int slot = event.getRawSlot(); if (slot >= 0 && slot < getInventory().getSize()) { ItemStack item = _inventory.getItem(slot); if (item != null) { if (item.equals(_placeholders.get(slot))) { event.setCurrentItem(null); } else if (item.equals(ITEM_FILLER)) { event.setCancelled(true); } } } if (!_allowBos && BookOfSouls.isValidBook(event.getCurrentItem())) { event.setCancelled(true); } }
Example 3
Source File: InventoryForPassengers.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
@Override protected void inventoryClick(InventoryClickEvent event) { super.inventoryClick(event); ItemStack item = event.getCurrentItem(); if (item != null && item.getType() != Material.AIR) { Player player = (Player) event.getWhoClicked(); if (item.equals(((EntityNBT) _wrapper)._bos.getBook())) { event.setCancelled(true); } else if (!BookOfSouls.isValidBook(item)) { event.setCancelled(true); player.sendMessage("§cYou can only put Books of Souls."); } else { EntityNBT entityNbt = BookOfSouls.bookToEntityNBT(item); if (entityNbt == null) { player.sendMessage("§cThat Book of Souls is corrupted!"); event.setCancelled(true); } } } }
Example 4
Source File: JavaUtils.java From StaffPlus with GNU General Public License v3.0 | 6 votes |
/** * Gets the slot of the given item through iteration. * * @param player The inventory to iterate through. * @param item The ItemStack to check for. * @return The found slot in the inventory. */ public static int getItemSlot(PlayerInventory inventory, ItemStack item) { int slot = 0; ItemStack[] contents = inventory.getContents(); for(int i = 0; i < contents.length; i++) { ItemStack current = contents[i]; if(current == null) { continue; } if(current.equals(item)) { slot = i; break; } } return slot; }
Example 5
Source File: DurabilityBar.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onItemBreak(PlayerItemBreakEvent event) { ItemStack broken = event.getBrokenItem(); Player player = event.getPlayer(); PlayerInventory inv = player.getInventory(); if (broken.equals(inv.getItemInMainHand())) hideDurabilityBossBar(player, EquipmentSlot.HAND); else if (broken.equals(inv.getItemInOffHand())) hideDurabilityBossBar(player, EquipmentSlot.OFF_HAND); }
Example 6
Source File: MobFlagGui.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) void onInventoryClick(InventoryClickEvent event) { InventoryHolder holder = event.getInventory().getHolder(); if (holder instanceof Player && holder.equals(this.player)) { if (event.getInventory().equals(this.player.getOpenInventory().getTopInventory())) { event.setCancelled(true); if (event.getRawSlot() == 0) { setFlagValue(true); close(true); return; } if (event.getRawSlot() == 1) { setFlagValue(false); close(true); return; } ItemStack item = event.getCurrentItem(); if (item != null && !item.equals(RedProtect.get().config.getGuiSeparator()) && !item.getType().equals(Material.AIR) && event.getRawSlot() >= 0 && event.getRawSlot() <= this.size - 1) { ItemMeta itemMeta = item.getItemMeta(); List<String> lore = itemMeta.getLore(); if (lore.get(0).equalsIgnoreCase(translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + RedProtect.get().guiLang.getFlagString("true")))) { lore.set(0, translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + RedProtect.get().guiLang.getFlagString("false"))); item.setAmount(1); } else { lore.set(0, translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + RedProtect.get().guiLang.getFlagString("true"))); item.setAmount(2); } itemMeta.setLore(lore); item.setItemMeta(itemMeta); } } } }
Example 7
Source File: TeamPicker.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerLocaleChange(PlayerLocaleChangeEvent event) { ItemStack oldItem = getTeamPicker(event.getOldLocale() != null ? event.getOldLocale() : "en_US"); ItemStack newItem = getTeamPicker(event.getNewLocale()); for (ItemStack item : event.getPlayer().getInventory().getContents()) { if (item != null && item.equals(oldItem)) { item.setItemMeta(newItem.getItemMeta()); } } }
Example 8
Source File: NewItemShop.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
private VillagerTrade getTradingItem(MerchantCategory category, ItemStack stack, Game game, Player player) { for (VillagerTrade trade : category.getOffers()) { if (trade.getItem1().getType() == Material.AIR && trade.getRewardItem().getType() == Material.AIR) { continue; } ItemStack iStack = this.toItemStack(trade, player, game); if (iStack.getType() == Material.ENDER_CHEST && stack.getType() == Material.ENDER_CHEST) { return trade; } else if ((iStack.getType() == Material.POTION || (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8") && (iStack.getType().equals(Material.valueOf("TIPPED_ARROW")) || iStack.getType().equals(Material.valueOf("LINGERING_POTION")) || iStack.getType().equals(Material.valueOf("SPLASH_POTION")))))) { if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) { if (iStack.getItemMeta().equals(stack.getItemMeta())) { return trade; } } else { PotionMeta iStackMeta = (PotionMeta) iStack.getItemMeta(); PotionMeta stackMeta = (PotionMeta) stack.getItemMeta(); if (iStackMeta.getBasePotionData().equals(stackMeta.getBasePotionData()) && iStackMeta .getCustomEffects().equals(stackMeta.getCustomEffects())) { return trade; } } } else if (iStack.equals(stack)) { return trade; } } return null; }
Example 9
Source File: CraftInventory.java From Thermos with GNU General Public License v3.0 | 5 votes |
private int first(ItemStack item, boolean withAmount) { if (item == null) { return -1; } ItemStack[] inventory = getContents(); for (int i = 0; i < inventory.length; i++) { if (inventory[i] == null) continue; if (withAmount ? item.equals(inventory[i]) : item.isSimilar(inventory[i])) { return i; } } return -1; }
Example 10
Source File: CraftInventory.java From Thermos with GNU General Public License v3.0 | 5 votes |
public HashMap<Integer, ItemStack> all(ItemStack item) { HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>(); if (item != null) { ItemStack[] inventory = getContents(); for (int i = 0; i < inventory.length; i++) { if (item.equals(inventory[i])) { slots.put(i, inventory[i]); } } } return slots; }
Example 11
Source File: CraftInventory.java From Thermos with GNU General Public License v3.0 | 5 votes |
public boolean contains(ItemStack item, int amount) { if (item == null) { return false; } if (amount <= 0) { return true; } for (ItemStack i : getContents()) { if (item.equals(i) && --amount <= 0) { return true; } } return false; }
Example 12
Source File: PlayerInteractListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
@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 13
Source File: CraftingObjective.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
private int countRemainingSpace(Player player) { int remainingSpace = 0; for (ItemStack i : player.getInventory().getStorageContents()) { if (i == null || i.getType().equals(Material.AIR)) { remainingSpace += item.getMaterial().getMaxStackSize(); } else if (i.equals(item.generate(i.getAmount()))) { remainingSpace += item.getMaterial().getMaxStackSize() - i.getAmount(); } } return remainingSpace; }
Example 14
Source File: InventoryImpl.java From Civs with GNU General Public License v3.0 | 5 votes |
private int first(ItemStack item, boolean withAmount) { if (item == null) { return -1; } else { ItemStack[] inventory = this.getStorageContents(); int i = 0; while(true) { if (i >= inventory.length) { return -1; } if (inventory[i] != null) { if (withAmount) { if (item.equals(inventory[i])) { break; } } else if (item.isSimilar(inventory[i])) { break; } } ++i; } return i; } }
Example 15
Source File: DropTools.java From StackMob-3 with GNU General Public License v3.0 | 5 votes |
private boolean dropIsArmor(LivingEntity entity, ItemStack drop){ if(entity.getEquipment().getItemInMainHand().equals(drop) || entity.getEquipment().getItemInOffHand().equals(drop)){ return true; } for(ItemStack itemStack : entity.getEquipment().getArmorContents()){ if(itemStack.equals(drop)){ return true; } } return false; }
Example 16
Source File: NineSlotsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent e){ ItemStack item = e.getCurrentItem(); // Only handle clicked items. if (item == null){ return; } if (item.equals(fillItem)){ e.setCancelled(true); } }
Example 17
Source File: InventoryForSpecialVariable.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
protected final ItemStack[] getContents() { ItemStack[] items = _inventory.getContents(); for (Entry<Integer, ItemStack> entry : _placeholders.entrySet()) { ItemStack item = items[entry.getKey()]; if (item != null && item.equals(entry.getValue())) { items[entry.getKey()] = null; } } return items; }
Example 18
Source File: CraftInventory.java From Kettle with GNU General Public License v3.0 | 5 votes |
private int first(ItemStack item, boolean withAmount) { if (item == null) { return -1; } ItemStack[] inventory = getStorageContents(); for (int i = 0; i < inventory.length; i++) { if (inventory[i] == null) continue; if (withAmount ? item.equals(inventory[i]) : item.isSimilar(inventory[i])) { return i; } } return -1; }
Example 19
Source File: CraftInventory.java From Kettle with GNU General Public License v3.0 | 5 votes |
public boolean contains(ItemStack item, int amount) { if (item == null) { return false; } if (amount <= 0) { return true; } for (ItemStack i : getStorageContents()) { if (item.equals(i) && --amount <= 0) { return true; } } return false; }
Example 20
Source File: CraftInventory.java From Kettle with GNU General Public License v3.0 | 5 votes |
public boolean contains(ItemStack item) { if (item == null) { return false; } for (ItemStack i : getStorageContents()) { if (item.equals(i)) { return true; } } return false; }