@Override @Utility public String toString() { StringBuilder toString = new StringBuilder("ItemStack{").append(getType().name()).append(" x ").append(getAmount()); if (hasItemMeta()) { toString.append(", ").append(getItemMeta()); } return toString.append('}').toString(); }
@Override @Utility public final int hashCode() { int hash = 1; hash = hash * 31 + getTypeId(); hash = hash * 31 + getAmount(); hash = hash * 31 + (getDurability() & 0xffff); hash = hash * 31 + (hasItemMeta() ? (meta == null ? getItemMeta().hashCode() : meta.hashCode()) : 0); return hash; }
/** * This method is the same as equals, but does not consider stack size * (amount). * * @param stack the item stack to compare to * @return true if the two stacks are equal, ignoring the amount */ @Utility public boolean isSimilar(ItemStack stack) { if (stack == null) { return false; } if (stack == this) { return true; } return getTypeId() == stack.getTypeId() && getDurability() == stack.getDurability() && hasItemMeta() == stack.hasItemMeta() && (hasItemMeta() ? Bukkit.getItemFactory().equals(getItemMeta(), stack.getItemMeta()) : true); }
/** * Write an item stack to the buffer. * * @param buf The buffer. * @param stack The stack to write, or null. */ public static void writeSlot(ByteBuf buf, ItemStack stack) { if (InventoryUtil.isEmpty(stack)) { buf.writeShort(-1); } else { buf.writeShort(stack.getTypeId()); buf.writeByte(stack.getAmount()); buf.writeShort(stack.getDurability()); if (stack.hasItemMeta()) { CompoundTag tag = GlowItemFactory.instance().writeNbt(stack.getItemMeta()); writeCompound(buf, tag); } else { writeCompound(buf, null); } } }
/** * Creates a new item stack derived from the specified stack * * @param stack the stack to copy * @throws IllegalArgumentException if the specified stack is null or * returns an item meta not created by the item factory */ public ItemStack(final ItemStack stack) throws IllegalArgumentException { Validate.notNull(stack, "Cannot copy null stack"); this.type = stack.getTypeId(); this.amount = stack.getAmount(); this.durability = stack.getDurability(); this.data = stack.getData(); if (stack.hasItemMeta()) { setItemMeta0(stack.getItemMeta(), getType0()); } }
@Override public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) { Location location = against.getLocation() .add(face.getModX(), face.getModY(), face.getModZ()); // TODO: change mob spawner when clicked by monster egg if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) { GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta(); EntityType type = meta.getSpawnedType(); CompoundTag tag = meta.getEntityTag(); // TODO: check for fence/wall //if (face == BlockFace.UP && against instanceof BlockFence) { //location.add(0, 0.5, 0); //} if (type != null) { GlowEntity entity = against.getWorld() .spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG); if (tag != null) { EntityStorage.load(entity, tag); } if (player.getGameMode() != GameMode.CREATIVE) { holding.setAmount(holding.getAmount() - 1); } } } } }
@Override public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) { if (!super.entityInteract(player, message) && message.getAction() == InteractEntityMessage.Action.INTERACT.ordinal()) { ItemStack item = InventoryUtil .itemOrEmpty(player.getInventory().getItem(message.getHandSlot())); int growthAmount = computeGrowthAmount(item.getType()); // Spawn eggs are used to spawn babies if (item.getType() == Material.MONSTER_EGG && item.hasItemMeta()) { GlowMetaSpawn meta = (GlowMetaSpawn) item.getItemMeta(); if (meta.hasSpawnedType() && meta.getSpawnedType() == this.getType()) { this.createBaby(); if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) { player.getInventory().consumeItemInHand(message.getHandSlot()); } return true; } } else if (growthAmount > 0) { grow(growthAmount); world.spawnParticle(Particle.VILLAGER_HAPPY, location, 5); if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) { player.getInventory().consumeItemInHand(message.getHandSlot()); } return true; } } return false; }
@Override @Utility public String toString() { StringBuilder toString = new StringBuilder("ItemStack{").append(getType().name()).append(" x ").append(getAmount()); if (hasItemMeta()) { toString.append(", ").append(getItemMeta()); } return toString.append('}').toString(); }
@Override public void run() { // Try to prevent quick-clicking dupe exploits ItemStack item = inventory.getItem(0); if (item != null && item.hasItemMeta()) { inventory.setItem(0, finalItem); } } }, 1);
public static boolean isMcMMOItem(ItemStack item) { if (!item.hasItemMeta()) { return false; } ItemMeta itemMeta = item.getItemMeta(); return itemMeta.hasLore() && itemMeta.getLore().contains("mcMMO Item"); }
ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); if (itemInMainHand != null && itemInMainHand.hasItemMeta()) { ItemMeta metaOfItemInHand = itemInMainHand.getItemMeta(); if (metaOfItemInHand.hasLore() && String.join(" ", metaOfItemInHand.getLore()).contains("lore")) { //do stuff } }
public static float getMaxEnergy(ItemStack item) { if (item == null || item.getType() == null || item.getType().equals(Material.AIR)) return 0F; if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F; for (String line: item.getItemMeta().getLore()) { if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) { return Float.valueOf(line.split(" / ")[1].replace(" J", "")); } } return 0F; }
public static float getStoredEnergy(ItemStack item) { if (item == null || item.getType() == null || item.getType().equals(Material.AIR)) return 0F; if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F; for (String line: item.getItemMeta().getLore()) { if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) { return Float.valueOf(line.split(" / ")[0].replace(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7"), "")); } } return 0F; }
ItemStack item = player.getInventory().getItemInHand(); if(item != null && item.getType() == Material.EGG) { if(item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals("PartyEgg")) { .... } }
private boolean matrixContains(CraftingInventory inventory, String circuit) { for (ItemStack is : inventory.getMatrix()) { if (is != null && is.getType().equals(Material.FILLED_MAP) && is.hasItemMeta() && is.getItemMeta().hasDisplayName() && is.getItemMeta().getDisplayName().equals(circuit)) { return true; } } return false; } }
@SuppressWarnings("unchecked") private static <T extends ItemMeta> T ensureMeta(ItemStack stack) { if (!stack.hasItemMeta()) { stack.setItemMeta(Bukkit.getServer().getItemFactory().getItemMeta(stack.getType())); } return (T) stack.getItemMeta(); }
private void twaOff(Player player) { ItemStack chest = player.getInventory().getChestplate(); if (chest != null && chest.hasItemMeta() && chest.getItemMeta().hasDisplayName()) { String metaName = chest.getItemMeta().getDisplayName(); if (twaChests.contains(metaName)) { plugin.getServer().dispatchCommand(plugin.getConsole(), "twad ANGEL off " + player.getUniqueId()); } } } }
@EventHandler(ignoreCancelled = true) public void onPlayerDropAreaDisk(PlayerDropItemEvent event) { ItemStack stack = event.getItemDrop().getItemStack(); if (stack != null && stack.getType().equals(Material.MUSIC_DISC_BLOCKS) && stack.hasItemMeta()) { ItemMeta ims = stack.getItemMeta(); if (ims.hasDisplayName() && ims.getDisplayName().equals("Area Storage Disk")) { event.setCancelled(true); Player p = event.getPlayer(); TARDISMessage.send(p, "ADV_NO_DROP"); } } }
@EventHandler public void onPickup(EntityPickupItemEvent e) { if (e.getItem().hasMetadata("no_pickup")) e.setCancelled(true); else if (!e.getItem().hasMetadata("no_pickup") && e.getItem().getItemStack().hasItemMeta() && e.getItem().getItemStack().getItemMeta().hasDisplayName() && e.getItem().getItemStack().getItemMeta().getDisplayName().startsWith(ChatColor.translateAlternateColorCodes('&', "&5&dALTAR &3Probe - &e"))) { e.setCancelled(true); e.getItem().remove(); } }
@EventHandler public void onMinecartPickup(InventoryPickupItemEvent e) { if (e.getItem().hasMetadata("no_pickup")) e.setCancelled(true); else if (!e.getItem().hasMetadata("no_pickup") && e.getItem().getItemStack().hasItemMeta() && e.getItem().getItemStack().getItemMeta().hasDisplayName() && e.getItem().getItemStack().getItemMeta().getDisplayName().startsWith(ChatColor.translateAlternateColorCodes('&', "&5&dALTAR &3Probe - &e"))) { e.setCancelled(true); e.getItem().remove(); } } }