本文整理汇总了Java中org.bukkit.inventory.meta.ItemMeta类的典型用法代码示例。如果您正苦于以下问题:Java ItemMeta类的具体用法?Java ItemMeta怎么用?Java ItemMeta使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ItemMeta类属于org.bukkit.inventory.meta包,在下文中一共展示了ItemMeta类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resetPlayer
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
public static void resetPlayer(Player player) {
player.setLevel(0);
player.setExp(0);
player.setFoodLevel(20);
player.setHealth(20);
player.setHealthScale(20);
player.setExhaustion(0);
player.getInventory().clear();
ItemStack blankItem = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
ItemMeta blankMeta = blankItem.getItemMeta();
blankMeta.setDisplayName("" + ChatColor.RED);
blankItem.setItemMeta(blankMeta);
for(int i=9; i<=35; i++) {
player.getInventory().setItem(i, blankItem);
}
player.getInventory().setHelmet(new ItemStack(Material.AIR, 1));
player.getInventory().setChestplate(new ItemStack(Material.AIR, 1));
player.getInventory().setLeggings(new ItemStack(Material.AIR, 1));
player.getInventory().setBoots(new ItemStack(Material.AIR, 1));
for(PotionEffect potionEffect : player.getActivePotionEffects()) {
player.removePotionEffect(potionEffect.getType());
}
player.setFireTicks(0);
}
示例2: getItem
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
public ItemStack getItem() {
List<String> lore = new ArrayList<String>();
for (int i=0; i<this.lore.length; i++) {
lore.add(ChatColor.translateAlternateColorCodes('&', this.lore[i]));
}
ItemStack item = new ItemStack(this.type, this.amount, this.data);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(lore);
meta.spigot().setUnbreakable(this.unbreakable);
item.setItemMeta(meta);
return item;
}
示例3: getEmpireWand
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
public ItemStack getEmpireWand() {
ItemStack empirewand = new ItemStack(Material.BLAZE_ROD, 1);
ItemMeta meta = empirewand.getItemMeta();
meta.setDisplayName(ChatColor.RED + "Empire Wand");
ArrayList<String> lore = new ArrayList<String>();
try {
lore.add(ChatColor.translateAlternateColorCodes('&', new Randomizer<String>(KingdomFactionsPlugin.getInstance()
.getDataManager().getArrayData("Empirewand.lores").getValue()).result()));
} catch (DataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
meta.setLore(lore);
meta.addEnchant(Enchantment.LURE, 1, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
empirewand.setItemMeta(meta);
return empirewand;
}
示例4: getCustomSkull
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
public static ItemStack getCustomSkull(String url) {
GameProfile profile = SkinChangeUtil.changeSkin(url);
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
ItemMeta headMeta = head.getItemMeta();
Class<?> headMetaClass = headMeta.getClass();
try {
Field f = headMetaClass.getDeclaredField("profile");
f.setAccessible(true);
f.set(headMeta, profile);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
head.setItemMeta(headMeta);
return head;
}
示例5: getItem
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
public ItemStack getItem() {
ItemStack is = new ItemStack(Material.PAPER);
ItemMeta im = is.getItemMeta();
/**
* Item:
*
* Name = Request #x
* Lore 1: Requested by: _name_
* Lore : Ban:
* Lore 2: Reason: reason
* Lore 3: Time: time
*/
im.setDisplayName(Messager.color("&eRequest #" + id));
im.setLore(Arrays.asList(Messager.color("&eRequested by: &7" + Bukkit.getOfflinePlayer(UUID.fromString(openerUUID)).getName()),
Messager.color("&eBan: &7" + Bukkit.getOfflinePlayer(UUID.fromString(playerToBanUUID)).getName()),
Messager.color("&eReason: &7" + banReason),
Messager.color("&eRequested at: &7" + timeOpenedFormatted)));
is.setItemMeta(im);
return is;
}
示例6: choosePartner
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
private Inventory choosePartner(Faction creator) {
int size = (int) (9 * Math.ceil(((double) factions.getActive().size() / 9)));
Inventory gui = Bukkit.createInventory(null, size, FMessage.TRADE_OFFER_CHOOSE_PARTNER.getMessage());
int i = 0;
for (Faction faction : factions.getActive()) {
ItemStack icon = faction.getBannerStack();
ItemMeta meta = icon.getItemMeta();
meta.setDisplayName(creator.getRelation(faction).getColor() + faction.getName());
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
icon.setItemMeta(meta);
gui.setItem(i, icon);
factionBySlot.put(i, faction);
i++;
}
return gui;
}
示例7: addLore
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
/**
* Adds lore after the index of a lore line
*
* @param index index
* @param lore lore
* @return builder
*/
public ItemStackBuilder addLore(int index, String... lore) {
final ItemMeta itemMeta = this.getItemMeta();
final List<String> data = new ArrayList<>();
for (int i = 0; i < itemMeta.getLore().size(); i++) {
data.add(itemMeta.getLore().get(0));
if (i == index) {
for (final String s : lore) {
data.add(ChatColor.translateAlternateColorCodes('&', s));
}
}
}
itemMeta.setLore(data);
this.setItemMeta(itemMeta);
return this;
}
示例8: giveKit
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
@EventHandler
public void giveKit(final ObserverKitApplyEvent event) {
final MatchPlayer player = mm.getPlayer(event.getPlayer());
if(player == null) return;
if(!player.isObservingType()) return;
if(!player.getBukkit().hasPermission("pgm.defuse")) return;
ItemStack shears = new ItemStack(DEFUSE_ITEM);
// TODO: Update information if locale changes
ItemMeta meta = shears.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(PGMTranslations.t("defuse.displayName", player));
meta.setLore(Lists.newArrayList(ChatColor.GRAY + PGMTranslations.t("defuse.tooltip", player)));
shears.setItemMeta(meta);
event.getPlayer().getInventory().setItem(DEFUSE_SLOT, shears);
}
示例9: LongRangeWeapon
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
public LongRangeWeapon(Material wep, String name, Material ammo, String desc, String type, double damage, int cooltime, boolean isCrit, int knockback, boolean silent, int shots, String proj) {
this.wep = wep;
this.name = name;
this.ammo = ammo;
this.desc = desc;
this.type = type;
this.damage = damage;
this.cooltime = cooltime;
this.isCrit = isCrit;
this.knockback = knockback;
this.silent = silent;
this.shots = shots;
this.proj = proj;
ItemStack item = new ItemStack(wep);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.BOLD + name);
ArrayList<String> lore = new ArrayList<String>();
lore.add(ChatColor.BOLD + desc);
lore.add(ChatColor.WHITE + type);
meta.setLore(lore);
item.setItemMeta(meta);
addWep(item);
}
示例10: onInteract
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的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);
}
示例11: testIsPick
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
@Test
public void testIsPick() {
//make a mock Xpick
ItemMeta i = mock(ItemMeta.class);
doReturn(true).when(i).hasLore();
doReturn(Material.DIAMOND_PICKAXE).when(tool).getType();
doReturn(true).when(tool).hasItemMeta();
doReturn(i).when(tool).getItemMeta();
//this should work
assertTrue(Pick.isPick(tool));
//no lore
doReturn(false).when(i).hasLore();
assertFalse(Pick.isPick(tool));
//no metadata
doReturn(false).when(tool).hasItemMeta();
assertFalse(Pick.isPick(tool));
}
示例12: 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.");
}
}
}
}
}
示例13: 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;
}
}
}
示例14: 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();
}
示例15: titaniumKitGlass
import org.bukkit.inventory.meta.ItemMeta; //导入依赖的package包/类
private ItemStack titaniumKitGlass(Player player) {
ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 14);
ItemMeta meta = stack.getItemMeta();
addGlow(stack);
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&4Titanium &7Kit"));
List<String> lore = new ArrayList<String>();
lore.add(ChatColor.translateAlternateColorCodes('&', "&7This is a kit contains:"));
lore.add(ChatColor.translateAlternateColorCodes('&', "&fGod Diamond kit!"));
lore.add("");
lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &cPurchase the Titanium Rank from store.hcriots.net"));
lore.add("");
lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7CoolDown: &c3 Days"));
if(cooldowns.containsKey(player.getUniqueId())) {
if(cooldowns.get(player.getUniqueId()).containsKey("TitaniumKit")) {
lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &c" + DurationFormatUtils.formatDurationWords(cooldowns.get(player.getUniqueId()).get("TitaniumKit"), true, true)));
} else {
lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
}
} else {
lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
}
meta.setLore(lore);
stack.setItemMeta(meta);
return stack;
}