当前位置: 首页>>代码示例>>Java>>正文


Java ItemMeta.hasDisplayName方法代码示例

本文整理汇总了Java中org.bukkit.inventory.meta.ItemMeta.hasDisplayName方法的典型用法代码示例。如果您正苦于以下问题:Java ItemMeta.hasDisplayName方法的具体用法?Java ItemMeta.hasDisplayName怎么用?Java ItemMeta.hasDisplayName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.inventory.meta.ItemMeta的用法示例。


在下文中一共展示了ItemMeta.hasDisplayName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: CustomItem

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
public CustomItem(ItemStack item) {
    type = item.getType();
    data = PlaceholderValue.shortValue(String.valueOf(item.getData().getData()));
    amount = PlaceholderValue.intValue(String.valueOf(item.getAmount()));

    ItemMeta meta = item.getItemMeta();
    if(meta != null) {
        displayName = meta.hasDisplayName() ? PlaceholderValue.stringValue(meta.getDisplayName()) : null;
        lore = meta.hasLore() ? meta.getLore().stream().map(PlaceholderValue::stringValue).collect(Collectors.toList()) : new ArrayList<>();
        flags = new ArrayList<>(meta.getItemFlags());
        for (Map.Entry<Enchantment, Integer> entry : meta.getEnchants().entrySet())
            enchantments.put(entry.getKey(), PlaceholderValue.intValue(String.valueOf(entry.getValue())));
    } else {
        displayName = PlaceholderValue.fake("");
        lore = Collections.emptyList();
    }
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:18,代码来源:CustomItem.java

示例2: addSet

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
private void addSet(ItemStack item) {
    if (item == null)
        return;
    ItemMeta im = item.getItemMeta();
    if (im == null)
        return;
    if (!im.hasDisplayName())
        return;
    if (im.getDisplayName().startsWith("*"))
        return;
    String name = im.getDisplayName();
    for (String s : ItemBalance.SET_PREFIXES) {
        if (name.contains(s)) {
            if (armorSetCounter.containsKey(s))
                armorSetCounter.put(s, armorSetCounter.get(s) + 1);
            else
                armorSetCounter.put(s, 1);
            break;
        }
    }
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:22,代码来源:PlayerDataRPG.java

示例3: isShardType

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
private static boolean isShardType(ItemStack item, ItemStack type) {
    if (item == null)
        return false;
    if (type == null)
        return false;
    if (item.getType() != type.getType())
        return false;
    if (!item.hasItemMeta())
        return false;
    ItemMeta im = item.getItemMeta();
    if (!im.hasDisplayName())
        return false;
    if (im.getDisplayName().equals(type.getItemMeta().getDisplayName())) {
        im.setLore(type.getItemMeta().getLore());
        item.setItemMeta(im);
        return true;
    }
    return false;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:20,代码来源:ShardManager.java

示例4: serializeForMenu

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
private static String serializeForMenu(ItemStack item) {
    StringBuilder sb = new StringBuilder();
    sb.append(item.getType());
    sb.append('$');
    sb.append(item.getAmount());
    if (item.hasItemMeta()) {
        ItemMeta im = item.getItemMeta();
        if (im.hasDisplayName()) {
            sb.append('#');
            sb.append(im.getDisplayName());
        }
        if (im.hasLore()) {
            sb.append('#');
            sb.append(im.getLore().toString());
        }
        if (im.hasEnchants()) {
            sb.append('#');
            sb.append(im.getEnchants().toString());
        }
    }
    return sb.toString();
}
 
开发者ID:edasaki,项目名称:ZentrelaCore,代码行数:23,代码来源:MenuManager.java

示例5: equals

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
@Override
public boolean equals(Object obj)
{
	if (obj instanceof ItemMeta)
	{
		ItemMeta meta = (ItemMeta) obj;
		if (displayName != null)
		{
			return displayName.equals(meta.getDisplayName());
		}
		else
		{
			return !meta.hasDisplayName();
		}
	}
	else
	{
		return false;
	}
}
 
开发者ID:seeseemelk,项目名称:MockBukkit,代码行数:21,代码来源:ItemMetaMock.java

示例6: onBlockPlace

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlockPlaced();
    ItemStack stack = event.getItemInHand();
    Player player = event.getPlayer();
    if (block.getState() instanceof CreatureSpawner && stack.hasItemMeta()) {
        ItemMeta meta = stack.getItemMeta();

        if (meta.hasLore() && meta.hasDisplayName()) {
            CreatureSpawner spawner = (CreatureSpawner) block.getState();
            List<String> lore = meta.getLore();
            if (!lore.isEmpty()) {
                String spawnerName = ChatColor.stripColor(lore.get(0).toUpperCase());
                Optional<EntityType> entityTypeOptional = GuavaCompat.getIfPresent(EntityType.class, spawnerName);
                if (entityTypeOptional.isPresent()) {
                    spawner.setSpawnedType(entityTypeOptional.get());
                    spawner.update(true, true);
                    player.sendMessage(ChatColor.AQUA + "Placed a " + ChatColor.BLUE + spawnerName + ChatColor.AQUA + " spawner.");
                }
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:24,代码来源:CrowbarListener.java

示例7: onBlockPlace

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的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(EVENT_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();
    }
  }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:25,代码来源:EventSignListener.java

示例8: onBlockPlace

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的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);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:23,代码来源:DeathSignListener.java

示例9: onButtonClick

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
@EventHandler
public void onButtonClick(final InventoryClickEvent event) {
    ItemStack stack = event.getCurrentItem();
    final MatchPlayer player = this.getMatch().getPlayer(event.getWhoClicked());

    if(stack == null || player == null) return;
    if(stack.getType() != Material.WOOL && stack.getType() != Material.CARPET) return;
    ItemMeta meta = stack.getItemMeta();
    if(!meta.hasDisplayName()) return;
    String name = meta.getDisplayName();
    if(!name.startsWith(BUTTON_PREFIX)) return;

    event.setCancelled(true);

    final int score = stack.getAmount();
    if(!isScoreValid(score)) return;

    this.getMatch().getScheduler(MatchScope.LOADED).createTask(() -> {
        Integer oldScore = playerRatings.get(player);
        if(oldScore == null || oldScore != score) {
            player.playSound(Sound.UI_BUTTON_CLICK, 1, 2);
            rate(player, score);
        }
        else {
            player.getBukkit().closeInventory();
        }
    });
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:29,代码来源:MapRatingsMatchModule.java

示例10: serialize

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
@Override
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject result = new JsonObject();
    JsonArray enchantments = new JsonArray();

    for (Enchantment e : src.getEnchantments().keySet()) {
        JsonObject ench = new JsonObject();

        ench.addProperty("id", e.getName());
        ench.addProperty("lvl", src.getEnchantments().get(e));

        enchantments.add(ench);
    }

    result.addProperty("type", src.getType().name());
    result.addProperty("amount", src.getAmount());
    result.addProperty("durability", src.getDurability());
    result.add("enchantments", enchantments);

    if (src.hasItemMeta()) {
        JsonObject meta = new JsonObject();
        ItemMeta itemMeta = src.getItemMeta();

        if (itemMeta.hasDisplayName())
            meta.addProperty("displayName", itemMeta.getDisplayName().replace("§", "&"));

        if (itemMeta.hasLore())
            meta.add("lore", JSONUtil.getGson().toJsonTree(Arrays.asList(Util.replaceInArray("§", "&", itemMeta.getLore().toArray(new String[itemMeta.getLore().size()])))));

        meta.add("flags", JSONUtil.getGson().toJsonTree(itemMeta.getItemFlags()));

        result.add("meta", meta);
    }

    return result;
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:37,代码来源:JSONUtil.java

示例11: addLootItem

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
/**
 * Add a loot item to the random loot collection
 * 
 * @param item the item to add
 * @param weight the generation weight of the item
 * @param updateFile whether to update the dragon file or not
 */
@SuppressWarnings("deprecation")
public void addLootItem(ItemStack item, double weight, boolean updateFile) {
	Validate.notNull(item, "Cannot add null ItemStack to loot");
	if (weight < 0) weight = 0;
	
	this.loot.add(weight, item);
	
	if (updateFile && template.configFile != null) {
		FileConfiguration config = template.configFile;
		int itemID = loot.size();
		
		config.set("loot." + itemID + ".weight", weight);
		config.set("loot." + itemID + ".type", item.getType().name());
		if (item.getData().getData() != 0) config.set("loot." + itemID + ".data", item.getData().getData());
		if (item.getDurability() != 0) config.set("loot." + itemID + ".damage", item.getDurability());
		config.set("loot." + itemID + ".amount", item.getAmount());
		
		if (item.hasItemMeta()) {
			ItemMeta meta = item.getItemMeta();
			
			if (meta.hasDisplayName()) config.set("loot." + itemID + ".display-name", meta.getDisplayName());
			if (meta.hasLore()) config.set("loot." + itemID + ".lore", meta.getLore());
			if (meta.hasEnchants()) {
				for (Enchantment enchant : meta.getEnchants().keySet()) {
					config.set("loot." + itemID + ".enchantments." + enchant.getName(), meta.getEnchantLevel(enchant));
				}
			}
		}
		
		try {
			config.save(template.file);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:2008Choco,项目名称:DragonEggDrop,代码行数:44,代码来源:DragonLoot.java

示例12: isBottledExperience

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的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);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:16,代码来源:BottledExpListener.java

示例13: fromStack

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
/**
 * Parses an {@link Crowbar} from a given {@link ItemStack}.
 *
 * @param stack
 *            the stack to parse from
 * @return the {@link Crowbar} instance
 */
public static Optional<Crowbar> fromStack(ItemStack stack) {
    if (stack == null || !stack.hasItemMeta()) {
        return Optional.absent();
    }

    ItemMeta meta = stack.getItemMeta();
    if (!meta.hasDisplayName() || !meta.hasLore() || !meta.getDisplayName().equals(CROWBAR_NAME)) {
        return Optional.absent();
    }

    Crowbar crowbar = new Crowbar();
    List<String> loreList = meta.getLore();
    for (String lore : loreList) {
        lore = ChatColor.stripColor(lore);
        int length = lore.length();
        for (int i = 0; i < length; i++) {
            char character = lore.charAt(i);
            if (Character.isDigit(character)) {
                int amount = Integer.parseInt(String.valueOf(character));
                if (lore.startsWith(END_FRAME_USE_TAG)) {
                    crowbar.setEndFrameUses(amount);
                    break;
                } else if (lore.startsWith(SPAWNER_USE_TAG)) {
                    crowbar.setSpawnerUses(amount);
                    break;
                }
            }
        }
    }

    return Optional.of(crowbar);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:40,代码来源:Crowbar.java

示例14: itemStackToString

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static String itemStackToString(ItemStack item) {
    StringBuilder builder = new StringBuilder();

    if (item != null) {
        String isType = String.valueOf(item.getType().getId());
        builder.append("[email protected]").append(isType);

        if (item.getDurability() != 0) {
            String isDurability = String.valueOf(item.getDurability());
            builder.append(":[email protected]").append(isDurability);
        }

        if (item.getAmount() != 1) {
            String isAmount = String.valueOf(item.getAmount());
            builder.append(":[email protected]").append(isAmount);
        }

        Map<Enchantment, Integer> isEnch = (Map<Enchantment, Integer>) item.getEnchantments();
        if (isEnch.size() > 0) {
            for (Map.Entry<Enchantment, Integer> ench : isEnch.entrySet()) {
                builder.append(":[email protected]").append(ench.getKey().getId()).append("@").append(ench.getValue());
            }
        }

        if (item.hasItemMeta()) {
            ItemMeta imeta = item.getItemMeta();
            if (imeta.hasDisplayName()) {
                builder.append(":[email protected]").append(imeta.getDisplayName());
            }
            if (imeta.hasLore()) {
                builder.append(":[email protected]").append(imeta.getLore());
            }
        }
    }

    return builder.toString();
}
 
开发者ID:ijoeleoli,项目名称:ZorahPractice,代码行数:39,代码来源:InventoryUtils.java

示例15: matches

import org.bukkit.inventory.meta.ItemMeta; //导入方法依赖的package包/类
public boolean matches(ItemStack tool) {
	ItemStack compare = this.getTemplate();
	if (compare == null) {
		return true; // this is catchall! matches everything.
	}
	if (compare.getType() != tool.getType()) return false;
	if (!ignoreDurability() && 
			compare.getDurability() != tool.getDurability()) return false;
	if (!ignoreAmount() && compare.getAmount() != tool.getAmount()) return false;

	// Short circuit of metachecks.
	if (ignoreMeta()) return true;

	// Metachecks.
	ItemMeta compmeta = compare.getItemMeta();
	ItemMeta toolmeta = tool.getItemMeta();
	if (toolmeta == null && toolmeta == compmeta) return true; // equal but no further compare
	
	if (compmeta == null) return false; // toolmeta != null but compmeta == null
	
	// both non-null.
	if (!ignoreName() && !(toolmeta.hasDisplayName() ? 
			toolmeta.getDisplayName().equals(compmeta.getDisplayName()) : !compmeta.hasDisplayName() ) ) return false;
	if (!ignoreLore() &&
			!(toolmeta.hasLore() ? toolmeta.getLore().equals(compmeta.getLore()) : !compmeta.hasLore())) return false;
	
	// Expensive enchantment checks.
	if (!ignoreEnchants()) {
		Map<Enchantment, Integer> compench = compmeta.getEnchants();
		Map<Enchantment, Integer> toolench = toolmeta.getEnchants();

		// check that set of enchants is same (both null or both not null and same) else bail
		if (!ignoreOtherEnchants() && !((compench == null && toolench == null) || 
				(compench != null && toolench != null && compench.keySet().equals(toolench.keySet()) ) ) ) return false; 

		// check that tool has at least the enchantments specified; ignore the rest.
		if (ignoreOtherEnchants() && !(compench == null || 
				(toolench != null && toolench.keySet().containsAll(compench.keySet()) ) ) ) return false; 

		// also check _level_ of enchants
		if (!ignoreEnchantsLvl() && compench != null) { 
			boolean fail = false;
			for(Enchantment ech : compench.keySet()) {
				if (!compench.get(ech).equals(toolench.get(ech))) {
					fail = true;
					break;
				}
			}
			if (fail) return false;
		}
	}
	return true;
}
 
开发者ID:DevotedMC,项目名称:CropControl,代码行数:54,代码来源:ToolConfig.java


注:本文中的org.bukkit.inventory.meta.ItemMeta.hasDisplayName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。