commit
7c35c54e4a
22
config.yml
22
config.yml
@ -2,8 +2,18 @@ book:
|
||||
title: "Un magnifique titre"
|
||||
author: "Auteur du livre"
|
||||
pages:
|
||||
#You can add clickable text by writing it like the following example
|
||||
#random_text {your_text_with_abilities,hover_message,click_event<true or false>(action,argument)} other_random_text
|
||||
# ACTION_LIST: CHANGE_PAGE, COPY_TO_CLIPBOARD, OPEN_URL, RUN_COMMAND, SUGGEST_COMMAND
|
||||
#examples:
|
||||
# - This is an example
|
||||
# if a player click {here,he would see this message by hovering,true(CHANGE_PAGE.4)}
|
||||
# he would open page 4
|
||||
# if she exist
|
||||
#note that if you want to write an { or } in your text put a \ before
|
||||
#colors are also supported with & and §, help available on https://minecraft.tools/en/color-code.php
|
||||
- |
|
||||
Premier page
|
||||
Premiere page
|
||||
C'est beau tu trouve pas ?
|
||||
- |
|
||||
ça c'est Seconde page.
|
||||
@ -11,4 +21,12 @@ book:
|
||||
- |
|
||||
Et cette troisème alors ?
|
||||
la meilleure de toutes !
|
||||
Tu trouves pas ?
|
||||
Tu trouves pas ?
|
||||
- |
|
||||
This is an example
|
||||
if a player click {here,he would see this message by hovering,true(CHANGE_PAGE.1)}
|
||||
he would open page 1
|
||||
if she exist
|
||||
{Link,he would see this message by hovering,true(OPEN_URL.https://spigotmc.org)}
|
||||
{Command,he would see this message by hovering,true(RUN_COMMAND./say salut)}
|
||||
{Suggest,he would see this message by hovering,true(SUGGEST_COMMAND./say salut)}
|
||||
|
@ -7,6 +7,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class Book {
|
||||
|
||||
private ItemStack book;
|
||||
@ -23,10 +28,53 @@ public class Book {
|
||||
BookMeta meta = (BookMeta) book.getItemMeta();
|
||||
meta.setTitle(_title);
|
||||
meta.setAuthor(_author);
|
||||
for(int i=0;i<_pages.size();i++)
|
||||
meta.addPage(_pages.get(i).replace("&", "§"));
|
||||
if(book.setItemMeta(meta))
|
||||
for (String rawPage: _pages){
|
||||
ComponentBuilder page = new ComponentBuilder("");
|
||||
rawPage = rawPage.replace("&", "§");
|
||||
if (rawPage.contains("{") && rawPage.contains("}")) {
|
||||
String[] sections = rawPage.split("\\{|\\}");
|
||||
boolean edit = false;
|
||||
TextComponent message = new TextComponent();
|
||||
for(String section : sections) {
|
||||
if(!edit) {
|
||||
message.addExtra(section);
|
||||
}else {
|
||||
String[] elements = section.split(",");
|
||||
TextComponent eventBuilder = new TextComponent(elements[0]);
|
||||
if(!elements[1].equals("")) {
|
||||
eventBuilder.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(elements[1]).create()));
|
||||
}
|
||||
if(elements[2].startsWith("true")) {
|
||||
// System.out.println(elements[2].substring(5, elements[2].length() - 1));
|
||||
if(elements[2].startsWith("OPEN_URL", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, elements[2].substring(elements[2].indexOf(".") + 1, elements[2].length() - 1)));
|
||||
}
|
||||
if(elements[2].startsWith("RUN_COMMAND", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, elements[2].substring(elements[2].indexOf(".") + 1, elements[2].length() - 1)));
|
||||
|
||||
}
|
||||
if(elements[2].startsWith("SUGGEST_COMMAND", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, elements[2].substring(elements[2].indexOf(".") + 1, elements[2].length() - 1)));
|
||||
|
||||
}
|
||||
if(elements[2].startsWith("CHANGE_PAGE", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, elements[2].substring(elements[2].indexOf(".") + 1, elements[2].length() - 1)));
|
||||
|
||||
}
|
||||
}
|
||||
message.addExtra(eventBuilder);
|
||||
}
|
||||
edit = !edit;
|
||||
}
|
||||
page.append(message);
|
||||
}else {
|
||||
page.append(rawPage);
|
||||
}
|
||||
meta.spigot().addPage(page.create());
|
||||
}
|
||||
if(book.setItemMeta(meta)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -39,5 +87,4 @@ public class Book {
|
||||
public void openBook(Player player) {
|
||||
player.openBook(book);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user