本文整理匯總了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);
}