本文整理汇总了Java中org.bukkit.inventory.ItemStack.addEnchantment方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.addEnchantment方法的具体用法?Java ItemStack.addEnchantment怎么用?Java ItemStack.addEnchantment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.addEnchantment方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public void run(WCUser user, String label, String[] args){
if (args.length == 2){
boolean unsafe = plugin.getConfig().getBoolean("allowUnsafeEnchantment");
ItemStack i = user.getPlayer().getInventory().getItemInMainHand();
Enchantment enchantment;
int level;
if (!Utils.isInt(args[1])) return;
enchantment = getEnchantment(args[0]);
level = Integer.parseInt(args[1]);
if (enchantment == null) return;
if (unsafe){
i.addUnsafeEnchantment(enchantment, level);
return;
}
if (level > enchantment.getMaxLevel()) return;
i.addEnchantment(enchantment, level);
}
}
示例2: onCraftItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onCraftItem(CraftItemEvent event)
{
if (event.getRecipe().getResult().getType() == Material.DIAMOND_PICKAXE)
{
ItemStack pickaxe = new ItemStack(Material.DIAMOND_PICKAXE, 1);
pickaxe.addEnchantment(Enchantment.DIG_SPEED, 3);
event.getInventory().setResult(pickaxe);
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () ->
{
for (ItemStack stack : event.getWhoClicked().getInventory().getContents())
if (stack != null && stack.getType() == Material.DIAMOND_PICKAXE && !stack.containsEnchantment(Enchantment.DIG_SPEED))
stack.addEnchantment(Enchantment.DIG_SPEED, 3);
}, 5L);
}
}
示例3: createItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static ItemStack createItem(Material material, List<Enchantment> enchantments) {
ItemStack itemStack = createItem(material);
for (Enchantment enchantment : enchantments) {
if (itemStack.getEnchantments().containsKey(enchantment)) {
itemStack.getEnchantments().put(enchantment, itemStack.getEnchantmentLevel(enchantment));
} else {
itemStack.addEnchantment(enchantment, 1);
}
}
return itemStack;
}
示例4: addGlow
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
* Add glow effect to an ItemStack {@link ItemStack}
*
* @param item Object
*
* @return Object with glow effect
*/
public static ItemStack addGlow(ItemStack item)
{
if(item == null)
return null;
Enchantment glow = getGlow();
if(glow != null)
item.addEnchantment(glow, 1);
return item;
}
示例5: getItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public ItemStack getItem(Material m, String name, int amount, ArrayList<String> lore, Enchantment e,
int enchLevel) {
ItemStack i = new ItemStack(m, amount);
ItemMeta im = i.getItemMeta();
im.setDisplayName(name);
im.setLore(lore);
i.setItemMeta(im);
i.addEnchantment(e, enchLevel);
return i;
}
示例6: addEnchantments
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void addEnchantments(String enchantments, String level, ItemStack is) {
try {
if (enchantments == null || level == null)
return;
ArrayList<String> enchants = new ArrayList<String>(Arrays.asList(enchantments.split("!")));
ArrayList<String> levels = new ArrayList<String>(Arrays.asList(level.split("!")));
if (enchantments.isEmpty())
return;
for (int i = 0; i < enchants.size(); i++) {
if (!enchants.get(i).equalsIgnoreCase(" ") && !enchants.get(i).equalsIgnoreCase("")) {
if (is.getType() == Material.ENCHANTED_BOOK) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) is.getItemMeta();
meta.addStoredEnchant(Enchantment.getByName(enchants.get(i)), Integer.parseInt(levels.get(i)), true);
is.setItemMeta(meta);
} else
is.addEnchantment(Enchantment.getByName(enchants.get(i)), Integer.parseInt(levels.get(i)));
}
}
enchants.clear();
levels.clear();
} catch(Exception e) {
if(e instanceof java.lang.IllegalArgumentException) {
Logger.ERROR.log("couldn't add enchantment " + enchantments + " level " + level + " to " + is.getType().toString());
Logger.ERROR.log("Cause: java.lang.IllegalArgumentException");
} else {
e.printStackTrace();
}
}
}
示例7: addGlow
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static void addGlow(ItemStack item) {
item.addEnchantment(new EnchantGlow() , 1);
}
示例8: addGlow
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static void addGlow(ItemStack item) {
Enchantment glow = getGlow();
item.addEnchantment(glow, 1);
}
示例9: BasicKitHandler
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public BasicKitHandler()
{
this.kits = new HashSet<>();
if (MWAPI.getConfig().isDefaultKitsEnabled())
{
// *** FIGHTER KIT *** //
// Fighter Armor
ItemStack fighterHelmet = new ItemStack(Material.IRON_HELMET, 1);
fighterHelmet.addEnchantment(Enchantment.DAMAGE_ALL, 1);
KitItem fighterHelmetKitItem = MWAPI.getKitItemBuilder()
.stack(fighterHelmet)
.drop(false)
.unbreakable(true)
.create();
ItemStack fighterChestplate = new ItemStack(Material.IRON_CHESTPLATE, 1);
fighterChestplate.addEnchantment(Enchantment.DAMAGE_ALL, 1);
KitItem fighterChestplateKitItem = MWAPI.getKitItemBuilder()
.stack(fighterChestplate)
.drop(false)
.unbreakable(true)
.create();
ItemStack fighterPants = new ItemStack(Material.IRON_LEGGINGS, 1);
fighterPants.addEnchantment(Enchantment.DAMAGE_ALL, 1);
KitItem fighterPantsKitItem = MWAPI.getKitItemBuilder()
.stack(fighterPants)
.drop(false)
.unbreakable(true)
.create();
ItemStack fighterBoots = new ItemStack(Material.IRON_BOOTS, 1);
fighterBoots.addEnchantment(Enchantment.DAMAGE_ALL, 1);
KitItem fighterBootsKitItem = MWAPI.getKitItemBuilder()
.stack(fighterPants)
.drop(false)
.unbreakable(true)
.create();
// Fighter Items
ItemStack fighterSword = new ItemStack(Material.IRON_SWORD, 1);
fighterSword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
KitItem fighterSwordKitItem = MWAPI.getKitItemBuilder()
.stack(fighterSword)
.drop(false)
.unbreakable(true)
.create();
ItemStack fighterFood = new ItemStack(Material.GOLDEN_APPLE, 10);
KitItem fighterFoodKitItem = MWAPI.getKitItemBuilder()
.stack(fighterSword)
.drop(true)
.unbreakable(true)
.create();
registerKit(MWAPI.getKitBuilder("Fighter")
.setBoots(fighterBootsKitItem)
.setPants(fighterPantsKitItem)
.setChestPlate(fighterChestplateKitItem)
.setHelmet(fighterHelmetKitItem)
.setItemAt(0, fighterSwordKitItem)
.setItemAt(1, fighterFoodKitItem)
.create());
}
}