當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。