当前位置: 首页>>代码示例>>Java>>正文


Java BookMeta类代码示例

本文整理汇总了Java中org.bukkit.inventory.meta.BookMeta的典型用法代码示例。如果您正苦于以下问题:Java BookMeta类的具体用法?Java BookMeta怎么用?Java BookMeta使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BookMeta类属于org.bukkit.inventory.meta包,在下文中一共展示了BookMeta类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleEditBookEvent

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.itemInHandIndex;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == Items.WRITTEN_BOOK);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == Items.BOOK_AND_QUILL) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.setItem(Items.WRITTEN_BOOK);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.activeContainer.getSlot(player.inventory, itemInHandIndex);
        player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.activeContainer.windowId, slot.rawSlotIndex, itemInHand));
    }
}
 
开发者ID:OvercastNetwork,项目名称:CraftBukkit,代码行数:22,代码来源:CraftEventFactory.java

示例2: serializeBookMeta

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
/**
 * Gets a JSONObject representation of a BookMeta. Book and Quills books will have a pages key, while
 * finished, written, books will also have an author and title key.
 *
 * @param meta The BookMeta to serialize
 * @return A JSON Representation of the give BookMeta
 */
public static JSONObject serializeBookMeta(BookMeta meta) {
    try {
        JSONObject root = new JSONObject();
        if (meta.hasTitle())
            root.put("title", meta.getTitle());
        if (meta.hasAuthor())
            root.put("author", meta.getAuthor());
        if (meta.hasPages()) {
            String[] pages = meta.getPages().toArray(new String[]{});
            root.put("pages", pages);
        }
        return root;
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:ThisIzEthan,项目名称:NexusInventory,代码行数:25,代码来源:BookSerialization.java

示例3: handleEditBookEvent

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:22,代码来源:CraftEventFactory.java

示例4: getSpellTome

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public static ItemStack getSpellTome(String label, Player crafter) {
	ItemStack i = new ItemStack(MATERIAL);
	Spell spell = MystiCraft.getSpellManager().getSpell(label);
	BookMeta meta = (BookMeta)i.getItemMeta();
	meta.setDisplayName(DISPLAY_NAME + StringUtils.capitalize(label));
	if (crafter != null)
		meta.setAuthor(crafter.getName());
	else
		meta.setAuthor("unknown");
	meta.setGeneration(Generation.TATTERED);
	meta.setLore(Arrays.asList(new String[]{ChatColor.GRAY + spell.getDescription(), ChatColor.GRAY + "Mana Cost: " + spell.getManaCost()}));
	// TODO Add description
	meta.addPage("-------------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
	i.setItemMeta(meta);
	return i;
}
 
开发者ID:mcardy,项目名称:MystiCraft,代码行数:17,代码来源:SpellTome.java

示例5: onPlayerInteract

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    Location location = player.getLocation();
    ItemStack item = event.getItem();
    if (isBull(item) && event.getAction() == Action.RIGHT_CLICK_AIR | event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (!FactionsXL.getInstance().getBoard().isAnnexable(location)) {
            ParsingUtil.sendMessage(player, FMessage.ERROR_LAND_NOT_FOR_SALE.getMessage());
            return;
        }
        FactionCache factions = FactionsXL.getInstance().getFactionCache();
        BookMeta meta = ((BookMeta) item.getItemMeta());
        String title = meta.getTitle().replace(" ", "-");
        if (factions.getByName(title) != null) {
            title += NumberUtil.generateRandomInt(0, 100);
        }
        FireworkUtil.spawnRandom(location);
        FactionsXL.getInstance().getFactionCache().create(player, title);
        player.getInventory().remove(item);
    }
}
 
开发者ID:DRE2N,项目名称:FactionsXL,代码行数:22,代码来源:FBull.java

示例6: updateItem

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
@Override
public void updateItem() {

    if (getTitle() != null)
        getMeta().setTitle(getTitle());
    if (getAuthor() != null)
        getMeta().setAuthor(getAuthor());

    getMeta().setPages(new ArrayList<>()); // A book needs its page tag, so we'll default to an empty one.
    if (isWriteLines())// Save the book pages to the item.
        getMeta().pages.addAll(getPages().stream().map(TextBuilder::create)
                .map(TextUtils::toNMSComponent).collect(Collectors.toList()));

    if (getMeta().pages.isEmpty()) // Allow the book to be opened / editted.
        getMeta().addPage("");

    getMeta().setGeneration(BookMeta.Generation.TATTERED);
    this.page = 0; // Reset writer.
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:20,代码来源:ItemBook.java

示例7: createBook

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public static ItemStack createBook(String name, List<String> lore, String... pages) {
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) book.getItemMeta();
    ItemMeta bookMeta = book.getItemMeta();

    bookMeta.setDisplayName(Utils.colorize(name));
    ArrayList<String> colorLore = new ArrayList<>();
    if (lore != null) lore.forEach(str -> colorLore.add(Utils.colorize(str)));
    bookMeta.setLore(colorLore);

    meta.addPage(pages);
    meta.setAuthor(Utils.colorize("&6ProjectAlpha"));

    book.setItemMeta(bookMeta);

    return book;
}
 
开发者ID:cadox8,项目名称:PA,代码行数:18,代码来源:ItemUtil.java

示例8: parse

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public static ItemMeta parse(Element xml, ItemMeta source) {
    if (source instanceof BannerMeta) {
        return parseBanner(xml, (BannerMeta) source);
    } else if (source instanceof BookMeta) {
        return parseBook(xml, (BookMeta) source);
    } else if (source instanceof EnchantmentStorageMeta) {
        return parseEnchantmentStorage(xml, (EnchantmentStorageMeta) source);
    } else if (source instanceof FireworkMeta) {
        return parseFirework(xml, (FireworkMeta) source);
    } else if (source instanceof FireworkEffectMeta) {
        return parseFireworkEffect(xml, (FireworkEffectMeta) source);
    } else if (source instanceof LeatherArmorMeta) {
        return parseLeatherArmor(xml, (LeatherArmorMeta) source);
    } else if (source instanceof MapMeta) {
        return parseMap(xml, (MapMeta) source);
    } else if (source instanceof PotionMeta) {
        return parsePotion(xml, (PotionMeta) source);
    } else if (source instanceof SkullMeta) {
        return parseSkull(xml, (SkullMeta) source);
    } else if (source instanceof SpawnEggMeta) {
        return parseSpawnEgg(xml, (SpawnEggMeta) source);
    }

    return source;
}
 
开发者ID:ShootGame,项目名称:Arcade2,代码行数:26,代码来源:XMLItemMeta.java

示例9: parseBook

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public static BookMeta parseBook(Element xml, BookMeta source) {
    Element book = xml.getChild("book");
    if (book != null) {
        Attribute author = book.getAttribute("author");
        if (author != null) {
            source.setAuthor(parseMessage(author.getValue()));
        }

        Attribute title = book.getAttribute("title");
        if (title != null) {
            source.setTitle(parseMessage(title.getValue()));
        }

        for (Element page : book.getChildren("page")) {
            source.addPage(parseMessage(page.getTextNormalize()));
        }
    }

    return source;
}
 
开发者ID:ShootGame,项目名称:Arcade2,代码行数:21,代码来源:XMLItemMeta.java

示例10: loadWikiBook

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public static BookMeta loadWikiBook(BookMeta im)
{
	String path = "plugins/Breakpoint/wikiBook/";
	List<String> contents = new ArrayList<String>();
	int page = 0;
	File file = new File(path + page + ".txt");
	while (file.exists())
	{
		String pageContent = getString(file);
		contents.add(pageContent);
		page++;
		file = new File(path + page + ".txt");
	}
	im.setPages(contents);
	
	return im;
}
 
开发者ID:Limeth,项目名称:Breakpoint,代码行数:18,代码来源:FileManager.java

示例11: saveWikiBook

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public static void saveWikiBook()
{
	String path = "plugins/Breakpoint/wikiBook/";
	BookMeta im = (BookMeta) InventoryMenuManager.wikiBook.getItemMeta();
	List<String> contents = im.getPages();
	for (int page = 0; page < contents.size(); page++)
	{
		File file = new File(path + page + ".txt");
		File pathFile = new File(path);
		pathFile.mkdirs();
		try
		{
			if (!file.exists())
				file.createNewFile();
			setString(file, contents.get(page));
		}
		catch (IOException e)
		{
			Breakpoint.warn("Wiki book did not save properly.");
			e.printStackTrace();
		}
	}
}
 
开发者ID:Limeth,项目名称:Breakpoint,代码行数:24,代码来源:FileManager.java

示例12: CustomBookOverlay

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
public CustomBookOverlay(String title, String author, TellRawMessage... pages) {
	this.book = new ItemStack(Material.WRITTEN_BOOK);

	BookMeta meta = (BookMeta) this.book.getItemMeta();
	meta.setTitle(title);
	meta.setAuthor(author);

	for (TellRawMessage page: pages) {
		try {
			addPage(meta, page);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	this.book.setItemMeta(meta);
}
 
开发者ID:TheBusyBiscuit,项目名称:CS-CoreLib,代码行数:18,代码来源:CustomBookOverlay.java

示例13: onItemPickup

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
@EventHandler
public void onItemPickup(PlayerPickupItemEvent e) {
	
	if (e.isCancelled()) {
		return;
	}
	
	ItemStack item = e.getItem().getItemStack();
	
	if (item.getType().equals(Material.WRITTEN_BOOK)) {
		BookMeta meta = (BookMeta) item.getItemMeta();
		
		if (meta.getTitle().equals("Quest Log")) {
			e.getItem().remove();
			e.setCancelled(true);
			
			QuestManagerPlugin.questManagerPlugin.getPlayerManager().getPlayer(
					e.getPlayer().getUniqueId()).addQuestBook();
			
		}
	}
	
}
 
开发者ID:Dove-Bren,项目名称:QuestManager,代码行数:24,代码来源:QuestManager.java

示例14: setbookauthor

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
@SubCommand(value = "setbookauthor", permission = "nu.setbook")
public void setbookauthor(CommandSender sender, Arguments args) {
    if (!(args.length() > 1)) {
        msg(sender, "manual.setbookauthor.usage");
        return;
    }
    String author = args.next();
    Player p = asPlayer(sender);
    author = ChatColor.translateAlternateColorCodes('&', author);
    ItemStack item = p.getInventory().getItemInMainHand();
    if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) {
        msg(sender, "user.setbook.no_book");
        return;
    }
    BookMeta meta = (BookMeta) item.getItemMeta();
    meta.setAuthor(author);
    item.setItemMeta(meta);
    msg(sender, "user.setbook.success");
}
 
开发者ID:NyaaCat,项目名称:NyaaUtils,代码行数:20,代码来源:CommandHandler.java

示例15: setbooktitle

import org.bukkit.inventory.meta.BookMeta; //导入依赖的package包/类
@SubCommand(value = "setbooktitle", permission = "nu.setbook")
public void setbooktitle(CommandSender sender, Arguments args) {
    if (!(args.length() > 1)) {
        msg(sender, "manual.setbooktitle.usage");
        return;
    }
    String title = args.next();
    Player p = asPlayer(sender);
    title = ChatColor.translateAlternateColorCodes('&', title);

    ItemStack item = p.getInventory().getItemInMainHand();
    if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) {
        msg(sender, "user.setbook.no_book");
        return;
    }
    BookMeta meta = (BookMeta) item.getItemMeta();
    meta.setTitle(title);
    item.setItemMeta(meta);
    msg(sender, "user.setbook.success");
}
 
开发者ID:NyaaCat,项目名称:NyaaUtils,代码行数:21,代码来源:CommandHandler.java


注:本文中的org.bukkit.inventory.meta.BookMeta类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。