本文整理了Java中org.bukkit.inventory.ItemStack.hasItemMeta()
方法的一些代码示例,展示了ItemStack.hasItemMeta()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.hasItemMeta()
方法的具体详情如下:
包路径:org.bukkit.inventory.ItemStack
类名称:ItemStack
方法名:hasItemMeta
[英]Checks to see if any meta data has been defined.
[中]检查是否定义了元数据。
代码示例来源:origin: Bukkit/Bukkit
@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();
}
代码示例来源:origin: Bukkit/Bukkit
@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;
}
代码示例来源:origin: Bukkit/Bukkit
/**
* 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);
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* 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);
}
}
}
代码示例来源:origin: Bukkit/Bukkit
/**
* 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());
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@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);
}
}
}
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@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;
}
代码示例来源:origin: SpigotMC/Spigot-API
@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();
}
代码示例来源:origin: elBukkit/MagicPlugin
@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);
代码示例来源:origin: mcMMO-Dev/mcMMO
public static boolean isMcMMOItem(ItemStack item) {
if (!item.hasItemMeta()) {
return false;
}
ItemMeta itemMeta = item.getItemMeta();
return itemMeta.hasLore() && itemMeta.getLore().contains("mcMMO Item");
}
代码示例来源:origin: stackoverflow.com
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
}
}
代码示例来源:origin: TheBusyBiscuit/Slimefun4
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;
}
代码示例来源:origin: TheBusyBiscuit/Slimefun4
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;
}
代码示例来源:origin: stackoverflow.com
ItemStack item = player.getInventory().getItemInHand();
if(item != null && item.getType() == Material.EGG) {
if(item.hasItemMeta() &&
item.getItemMeta().hasDisplayName() &&
item.getItemMeta().getDisplayName().equals("PartyEgg")) {
....
}
}
代码示例来源:origin: eccentricdevotion/TARDIS
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;
}
}
代码示例来源:origin: CitizensDev/CitizensAPI
@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();
}
代码示例来源:origin: eccentricdevotion/TARDIS
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());
}
}
}
}
代码示例来源:origin: eccentricdevotion/TARDIS
@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");
}
}
}
代码示例来源:origin: TheBusyBiscuit/Slimefun4
@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();
}
}
代码示例来源:origin: TheBusyBiscuit/Slimefun4
@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();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!