本文整理汇总了Java中org.bukkit.Material.ENCHANTED_BOOK属性的典型用法代码示例。如果您正苦于以下问题:Java Material.ENCHANTED_BOOK属性的具体用法?Java Material.ENCHANTED_BOOK怎么用?Java Material.ENCHANTED_BOOK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bukkit.Material
的用法示例。
在下文中一共展示了Material.ENCHANTED_BOOK属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerInteract
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
// The player didn't click an enchantment table, Creative players will instantly destroy.
Player player = event.getPlayer();
if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {
// The player didn't click with an enchanted book.
ItemStack stack = event.getItem();
if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
ItemMeta meta = stack.getItemMeta();
if (meta instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
enchantmentStorageMeta.removeStoredEnchant(enchantment);
}
event.setCancelled(true);
player.setItemInHand(EMPTY_BOOK);
player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
}
}
}
}
}
示例2: getRandomEnchant
public static ItemStack getRandomEnchant(List<Enchantment>enchants, int amount){
ItemStack result = new ItemStack(Material.ENCHANTED_BOOK);
List<Enchantment>left = new ArrayList<Enchantment>(enchants);
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) result.getItemMeta();
if(amount > left.size())
amount = left.size();
for(int i = 0 ; i < amount && !left.isEmpty() ; i++){
Enchantment e = VanillaPlusCore.getRandom(left);
left.remove(e);
int level = VanillaPlusCore.getRandom().nextInt(100);
level = level % (e.getMaxLevel()+1-e.getStartLevel())+e.getStartLevel();
meta.addStoredEnchant(e, level, false);
}
result.setItemMeta(meta);
return result;
}
示例3: getItem
public static ItemStack getItem(BookDesign design) {
switch (design) {
case BOOK: {
return new CustomItem(new MaterialData(Material.ENCHANTED_BOOK), "&a粘液科技指南 &7(书与笔版式)", "", "&e右键 &8\u21E8 &7浏览粘液科技物品", "&eShift + 右键 &8\u21E8 &7打开设置 / 制作人员页面");
}
case CHEAT_SHEET: {
return new CustomItem(new MaterialData(Material.ENCHANTED_BOOK), "&a粘液科技指南 &7(作弊版式)", "", "&4&l仅限管理员使用!", "", "&e右键 &8\u21E8 &7浏览粘液科技物品", "&eShift + 右键 &8\u21E8 &7打开设置 / 制作人员页面");
}
case CHEST: {
return new CustomItem(new MaterialData(Material.ENCHANTED_BOOK), "&a粘液科技指南 &7(箱子版式)", "", "&e右键 &8\u21E8 &7浏览粘液科技物品", "&eShift + 右键 &8\u21E8 &7打开设置 / 制作人员页面");
}
default:
return null;
}
}
示例4: addEnchantments
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();
}
}
}
示例5: fill
public static void fill(Random random, List<WeightedRandomItem> list, Inventory inventory, int amount) {
for (int j = 0; j < amount; ++j) {
WeightedRandomItem loot = (WeightedRandomItem) WeightedRandom.getChoice(random, list);
int k = loot.min + random.nextInt(loot.max - loot.min + 1);
for (int l = 0; l < k; l += loot.loot.getMaxStackSize()) {
ItemStack item = loot.loot.clone();
if(item.getType() == Material.ENCHANTED_BOOK && ! item.hasItemMeta())
item = MinecraftUtils.getDongeonBook();
item.setAmount(loot.loot.getMaxStackSize() > k ? k : loot.loot.getMaxStackSize());
inventory.setItem(random.nextInt(inventory.getSize()), item);
}
}
}
示例6: EnchantedBookMaker
public EnchantedBookMaker() {
itemStack = new ItemStack(Material.ENCHANTED_BOOK);
}