本文整理匯總了Java中org.bukkit.inventory.meta.ItemMeta.hasLore方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemMeta.hasLore方法的具體用法?Java ItemMeta.hasLore怎麽用?Java ItemMeta.hasLore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.inventory.meta.ItemMeta
的用法示例。
在下文中一共展示了ItemMeta.hasLore方法的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();
}
}
示例2: executePlayer
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
@Override
public void executePlayer(Player p, PlayerDataRPG pd, String[] args) {
ItemStack item = p.getInventory().getItemInMainHand();
if (item.hasItemMeta()) {
ItemMeta im = item.getItemMeta();
ArrayList<String> lore = new ArrayList<String>();
if (im.hasLore())
lore.addAll(im.getLore());
StringBuilder sb = new StringBuilder();
for (int k = 1; k < args.length; k++) {
sb.append(args[k]);
sb.append(' ');
}
String newLine = ChatColor.translateAlternateColorCodes('&', sb.toString().trim());
if (args[0].equalsIgnoreCase("append")) {
lore.add(newLine);
} else {
lore.set(Integer.parseInt(args[0]), newLine);
}
im.setLore(lore);
item.setItemMeta(im);
p.sendMessage("Updated item.");
}
}
示例3: 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();
}
示例4: open
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
public void open(Player p){
Inventory inv = Bukkit.createInventory(null, 54, getInventoryName());
Set<String> list = config.getConfigurationSection("items").getKeys(false);
int slot = 0;
for(String name : list){
ItemStack is = ItemHelper.toItemStack(name);
ItemMeta im = is.getItemMeta();
List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<>();
lore.add("§f");
lore.add("§7아이템 이름: " + name);
Util.setItem(im.getDisplayName(),is.getType(),is.getDurability(),is.getAmount(),lore,is.getEnchantments(),slot,inv);
slot++;
}
p.openInventory(inv);
}
示例5: removeFromItem
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
public ItemStack removeFromItem(ItemStack item)
{
ItemMeta meta = item.getItemMeta();
if (meta == null) return item;
if (!meta.hasLore()) return item;
List<String> metaLore = meta.getLore();
// Make sure the enchantment doesn't already exist on the item
for (Map.Entry<CustomEnchantment, Integer> entry : getEnchantments(item).entrySet())
{
if (entry.getKey().getName().equals(getName()))
{
metaLore.remove(ChatColor.GRAY + getName() + " " + RomanNumerals.numeralOf(entry.getValue()));
}
}
return item;
}
示例6: getEnchantments
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
public static Map<CustomEnchantment, Integer> getEnchantments(ItemStack item) {
HashMap<CustomEnchantment, Integer> list = new HashMap<>();
if (item == null) return list;
ItemMeta meta = item.getItemMeta();
if (meta == null) return list;
if (!meta.hasLore()) return list;
for (String lore : meta.getLore()) {
String name = EnchantUtils.parseName(lore);
int level = EnchantUtils.parseLevel(lore);
if (name == null) continue;
if (level == 0) continue;
if (Main.isEnchantmentRegistered(name)) {
CustomEnchantment enchant = Main.getEnchantment(name);
if (enchant.isStackable() && list.containsKey(enchant)) {
level += list.get(enchant);
}
list.put(enchant, level);
}
}
return list;
}
示例7: 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.");
}
}
}
}
}
示例8: 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();
}
}
}
示例9: addLore
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
public ItemStack addLore(SpawnLocation spawnLocation, ItemStack itemStack) {
ItemMeta meta = itemStack.getItemMeta();
List<String> lore;
if (meta.hasLore()) {
lore = meta.getLore();
} else {
lore = new ArrayList<>();
}
meta.setDisplayName(I18n.format("user.select.gui.item.name", spawnLocation.getName()));
if (spawnLocation.getDescription().length() > 0) {
String[] split = spawnLocation.getDescription().split("\\\\n");
for (String s : split) {
lore.add(market_lore_code + ChatColor.RESET +
I18n.format("user.select.gui.item.description", ChatColor.translateAlternateColorCodes('&', s)));
}
}
if (!spawnLocation.isAvailable()) {
lore.add(I18n.format("user.select.gui.item.unavailable"));
}
if (!currentSpawn.getName().equals(spawnLocation.getName())) {
if (spawnLocation.isAvailable()) {
if (!plugin.config.lock_spawn && plugin.config.select_fee > 0) {
if (plugin.hasSpawn(player)) {
lore.add(I18n.format("user.select.gui.item.fee", plugin.config.select_fee));
}
}
lore.add(I18n.format("user.select.gui.item.click", player.getName()));
}
} else {
lore.add(I18n.format("user.select.gui.item.selected"));
}
meta.setLore(lore);
itemStack.setItemMeta(meta);
return itemStack;
}
示例10: unplaceable
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void unplaceable(BlockPlaceEvent evt) {
ItemStack stack = evt.getItemInHand();
if (stack == null) return;
ItemMeta meta = stack.getItemMeta();
if (!meta.hasLore()) return;
for (String lore : meta.getLore()) {
Item item = ItemFactory.items.get(lore);
if (item instanceof UnplaceableItem) {
evt.setCancelled(true);
}
}
}
示例11: applyAbility
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
public void applyAbility(Player player, ItemStack item, Ability ability, boolean temporary) {
// Adding lore
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.hasLore() ?
meta.getLore() : new ArrayList<>();
lore.add(ChatColor.GRAY + "Ability: " + ChatColor.RED + ability.getName());
if(temporary)
lore.add(ChatColor.GRAY + "Temporary");
meta.setLore(lore);
item.setItemMeta(meta);
player.getInventory().setItemInMainHand(item);
if(!temporary)
return;
// Adding timer for temporary abilities
new BukkitRunnable() {
@Override
public void run() {
if(!isActive(player, item)) {
this.cancel();
}
updateTemporaryItem(player, item, ability);
player.sendMessage(Lang.HEADERS_TOKENS.toString()
+ Lang.TOKENS_SHOP_EXPIRED.toString()
.replaceAll("%s", ability.getName()));
}
}.runTaskLater(plugin, 100 * 60 * 20);
}
示例12: onBlockPlace
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的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);
}
示例13: 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;
}
示例14: isSameMeta
import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
private static boolean isSameMeta(ItemMeta a, ItemMeta b) {
if (a == null || b == null) return false;
boolean dn = a.hasDisplayName() == b.hasDisplayName();
boolean l = a.hasLore() == b.hasLore();
boolean hdn = a.hasDisplayName();
boolean hl = a.hasLore();
if (dn) {
if (l) {
if (hdn) {
if (hl) {
return a.getDisplayName().equals(b.getDisplayName()) && a.getLore().equals(b.getLore());
} else { //only name
return a.getDisplayName().equals(b.getDisplayName());
}
} else { //maybe lore
return !hl || a.getLore().equals(b.getLore());
}
} else { //maybe name
return !hdn || a.getDisplayName().equals(b.getDisplayName());
}
} else if (l) {
return !hl || a.getLore().equals(b.getLore());
}
return false;
}
示例15: 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();
}