本文整理汇总了Java中org.bukkit.inventory.ItemStack.hasItemMeta方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.hasItemMeta方法的具体用法?Java ItemStack.hasItemMeta怎么用?Java ItemStack.hasItemMeta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.hasItemMeta方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockPlace
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
ItemStack stack = event.getItemInHand();
BlockState state = event.getBlock().getState();
if (state instanceof Sign && stack.hasItemMeta()) {
ItemMeta meta = stack.getItemMeta();
if (meta.hasDisplayName() && meta.getDisplayName().equals(DEATH_SIGN_ITEM_NAME)) {
Sign sign = (Sign) state;
List<String> lore = meta.getLore();
int count = 0;
for (String loreLine : lore) {
sign.setLine(count++, loreLine);
if (count == 4)
break;
}
sign.update();
//sign.setEditible(false);
}
}
}
示例2: onInteract
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
ItemStack stack = es.equals(EquipmentSlot.HAND) ? e.getPlayer().getInventory().getItemInMainHand() : e.getPlayer().getInventory().getItemInOffHand();
if(stack.hasItemMeta() ? !stack.getItemMeta().getDisplayName().equals(Translation.get(name)) : false)
{
if(stack.getItemMeta().getDisplayName().startsWith(ChatColor.RESET.toString()))
{
ItemMeta im = stack.getItemMeta();
if(!im.getDisplayName().startsWith(ChatColor.ITALIC.toString()))
im.setDisplayName(ChatColor.RESET + Translation.get(name));
stack.setItemMeta(im);
if(es.equals(EquipmentSlot.HAND))
e.getPlayer().getInventory().setItemInMainHand(stack);
else
e.getPlayer().getInventory().setItemInOffHand(stack);
}
}
super.onInteract(e, es);
}
示例3: onClick
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onClick(PlayerInteractEvent e) {
Action act = e.getAction();
if (!(act.equals(Action.RIGHT_CLICK_AIR) || act.equals(Action.RIGHT_CLICK_BLOCK)))
return;
ItemStack item = e.getItem();
if (item == null)
return;
if (!item.hasItemMeta())
return;
if (!item.getItemMeta().hasDisplayName())
return;
if (!item.getItemMeta().getDisplayName().contains(ConfigManager.getInstance().getBackpackName()))
return;
Player p = e.getPlayer();
String name = p.getName();
if (BackpackCooldown.getInstance().isReady(name, 500)) {
BackpackCooldown.getInstance().put(name);
} else {
e.setCancelled(true);
p.closeInventory();
p.sendMessage(Messages.getMessages().getNoQuickOpen().replace("&", "§"));
}
}
示例4: isGun
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public boolean isGun(ItemStack toCheck) {
if (!enabled || toCheck == null)
return false;
if (!Material.DIAMOND_HOE.equals(toCheck.getType()))
return false;
if (!toCheck.hasItemMeta())
return false;
ItemMeta meta = toCheck.getItemMeta();
if (meta.getLore().contains(gunTag()))
return true;
return false;
}
示例5: InteractCheck
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void InteractCheck(PlayerInteractEvent evt){
if(ConfigPatch.AntiLongStringCrashenable == true){
ItemStack item = evt.getItem();
Player player = evt.getPlayer();
if(item != null){
if(item.hasItemMeta() && item.getItemMeta().getDisplayName() != null){
if(item.getItemMeta().getDisplayName().length() >= 127){
evt.setCancelled(true);
player.setItemInHand(null);
AzureAPI.log(player, ConfigPatch.AntiLongStringCrashWarnMessage);
}
}
}
}
}
示例6: isBottledExperience
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
* Checks if an {@link ItemStack} is bottled exp.
*
* @param stack
* the {@link ItemStack} to check
* @return true if is bottled exp
*/
private boolean isBottledExperience(ItemStack stack) {
if (stack == null || !stack.hasItemMeta()) {
return false;
}
ItemMeta meta = stack.getItemMeta();
return meta.hasDisplayName() && meta.getDisplayName().equals(BOTTLED_EXP_DISPLAY_NAME);
}
示例7: onBlockPlace
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (event.getItemInHand().getType() != Material.MOB_SPAWNER)
return;
ItemStack is = event.getItemInHand();
if (!is.hasItemMeta())
return;
ItemMeta im = is.getItemMeta();
if (!im.hasLore())
return;
String lore = im.getLore().toString();
if (!lore.contains("Spawner:"))
return;
EntityType entity = getEntity(lore);
if (entity == EntityType.AREA_EFFECT_CLOUD) {
event.setCancelled(true);
return;
}
setSpawner(event.getBlock(), entity);
}
示例8: onItemSpawn
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onItemSpawn(ItemSpawnEvent event) {
Item item = event.getEntity();
ItemStack stack = item.getItemStack();
World world = item.getWorld();
if (world.getEnvironment() != Environment.THE_END || stack.getType() != Material.DRAGON_EGG
|| stack.hasItemMeta()) return;
DragonTemplate dragon = plugin.getDEDManager().getWorldWrapper(world).getActiveBattle();
DragonLoot loot = dragon.getLoot();
String eggName = loot.getEggName().replace("%dragon%", dragon.getName());
List<String> eggLore = loot.getEggLore().stream()
.map(s -> s.replace("%dragon%", dragon.getName()))
.collect(Collectors.toList());
ItemMeta eggMeta = stack.getItemMeta();
if (eggName != null && !eggName.isEmpty()) {
eggMeta.setDisplayName(eggName);
}
if (eggLore != null && !eggLore.isEmpty()) {
eggMeta.setLore(eggLore);
}
stack.setItemMeta(eggMeta);
}
示例9: addStoredEnergy
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static float addStoredEnergy(ItemStack item, float energy)
{
if(item == null || item.getType() == null || item.getType().equals(Material.AIR))
return 0.0F;
if(!item.hasItemMeta() || !item.getItemMeta().hasLore())
return 0.0F;
float rest = 0.0F;
float capacity = getMaxEnergy(item);
if(capacity == 0.0F)
return rest;
float stored = getStoredEnergy(item);
if(stored + energy > capacity)
{
rest = (stored + energy) - capacity;
stored = capacity;
} else
if(stored + energy < 0.0F)
stored = 0.0F;
else
stored += energy;
List lore = item.getItemMeta().getLore();
int index = -1;
for(int i = 0; i < lore.size(); i++)
{
String line = (String)lore.get(i);
if(!line.startsWith(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")) || !line.contains(" / ") || !line.endsWith(" J"))
continue;
index = i;
break;
}
BigDecimal decimal = (new BigDecimal(stored)).setScale(2, 4);
lore.set(index, (new StringBuilder(String.valueOf(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")))).append(decimal.floatValue()).append(" / ").append(capacity).append(" J").toString());
ItemMeta im = item.getItemMeta();
im.setLore(lore);
item.setItemMeta(im);
return rest;
}
示例10: hasDisplayName
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean hasDisplayName(ItemStack item) {
if (item == null)
return false;
if (!item.hasItemMeta())
return false;
return item.getItemMeta().hasDisplayName();
}
示例11: getKey
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
* Gets a {@link Key} from an {@link ItemStack}.
*
* @param stack
* the {@link ItemStack} to get from
* @return the {@link Key}, or null if is not a {@link Key}
*/
public Key getKey(ItemStack stack) {
if (stack == null || !stack.hasItemMeta()) {
return null;
}
for (Key key : keys) {
ItemStack item = key.getItemStack();
if (item.getItemMeta().getDisplayName().equals(stack.getItemMeta().getDisplayName())) {
return key;
}
}
return null;
}
示例12: isPetItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean isPetItem(@Nullable ItemStack item) {
if (item == null || !item.hasItemMeta() || !item.getItemMeta().hasLore()) {
return false;
}
List<String> itemLore = item.getItemMeta().getLore();
for (PetType petType : PETS.values()) {
List<String> petItemLore = petType.getSpawnItem().getItemMeta().getLore();
if (itemLore.equals(petItemLore)) {
return true;
}
}
return false;
}
示例13: isItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean isItem(ItemStack item, String target) {
if (item == null)
return false;
if (!item.hasItemMeta())
return false;
if (!item.getItemMeta().hasDisplayName())
return false;
String disp = item.getItemMeta().getDisplayName().replace(ChatColor.RESET.toString(), "");
String identifier = itemNameToIdentifierMap.get(disp);
if (identifier == null)
return false;
return identifier.equals(target);
}
示例14: setInventoryItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
* Save a {@link InventoryItem} inside this {@link SimpleFile}
*
* @param path where to save the {@link ItemStack}
* @param itemStack the {@link ItemStack} to save
* @param slot the slot where the {@link ItemStack} is inside the {@link Inventory}
*/
public void setInventoryItem(String path, ItemStack itemStack, int slot) {
setDefault(path + ".name", "null");
setMaterial(path + ".type", itemStack.getType());
setDefault(path + ".amount", itemStack.getAmount());
setDefault(path + ".damage", itemStack.getDurability());
setDefault(path + ".slot", slot);
if (getValue(path + ".enchantments") == null)
setMap(path + ".enchantments", new HashMap<>());
if (getValue(path + ".lore") == null)
setArgumentList(path + ".lore", "");
if (getValue(path + ".flags") == null)
setArgumentList(path + ".flags", "");
if (itemStack.hasItemMeta()) {
if (itemStack.getItemMeta().hasDisplayName()) {
setDefault(path + ".name", itemStack.getItemMeta().getDisplayName());
}
if (itemStack.getItemMeta().hasLore()) {
setArgumentList(path + ".lore", itemStack.getItemMeta().getLore().toArray(new String[itemStack.getItemMeta().getLore().size()]));
}
if (itemStack.getItemMeta().hasEnchants()) {
setMap(path + ".enchantments", itemStack.getItemMeta().getEnchants());
}
for (ItemFlag flag : itemStack.getItemMeta().getItemFlags()) {
addArgumentsToList(path + ".flags", flag.name());
}
}
}
示例15: run
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public void run(PlayerInteractEvent evt) {
Player player = evt.getPlayer();
Inventory inv = player.getInventory();
if (!inv.contains(Material.FIREWORK_CHARGE)) {
AzureAPI.log(player, "你没有弹药! 需要 " + ChatColor.RED + "迷你核弹" + ChatColor.GOLD + " 作为弹药");
AzureAPI.playSound(player, Sound.ENTITY_ITEM_BREAK);
return;
}
int slot = inv.first(Material.FIREWORK_CHARGE);
ItemStack ammo = inv.getItem(slot);
if (ammo.hasItemMeta()) {
if (!ammo.getItemMeta().hasLore()) return;
if (!ammo.getItemMeta().getLore().contains("弹药")) return;
} else {
return;
}
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
Location eye = player.getEyeLocation();
Vector direction = eye.getDirection().multiply(2);
Projectile projectile = player.getWorld().spawn(eye.add(direction), DragonFireball.class);
projectile.setBounce(true);
projectile.setGravity(true);
projectile.setShooter(player);
projectile.setVelocity(direction);
projectile.setCustomName("recreator.item.fatman");
AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
}