testing but nothing works
(for now)
This commit is contained in:
parent
74f125d32b
commit
4ec4c7641a
19
config.yml
19
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 &, 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,9 @@ 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
|
@ -1,5 +1,6 @@
|
||||
package fr.topeka.HelpRulesBook;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
@ -7,6 +8,12 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
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 +30,64 @@ 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))
|
||||
int lastCaracter = 0;
|
||||
BaseComponent[] page = new ComponentBuilder().create();
|
||||
List<String> subPage = new ArrayList<String>();
|
||||
for (String rawPage: _pages){
|
||||
if (rawPage.contains("{") && rawPage.contains("}")) {
|
||||
while (rawPage.length() != 0) {
|
||||
if (!rawPage.substring(rawPage.indexOf("{", lastCaracter)-1, rawPage.indexOf("{", lastCaracter)+1).contains("\\")) {
|
||||
subPage.add(rawPage.substring(0, rawPage.indexOf("{", lastCaracter)));
|
||||
rawPage = rawPage.substring(rawPage.indexOf("{", lastCaracter), rawPage.length());
|
||||
while (!rawPage.substring(rawPage.indexOf("}", lastCaracter)-1, rawPage.indexOf("}", lastCaracter)+1).contains("\\")) {
|
||||
lastCaracter = rawPage.indexOf("}", lastCaracter)+1;
|
||||
}
|
||||
subPage.add(rawPage.substring(0, rawPage.indexOf("}", lastCaracter)));
|
||||
rawPage = rawPage.substring(rawPage.indexOf("}", lastCaracter), rawPage.length());
|
||||
}
|
||||
else if (rawPage.substring(rawPage.indexOf("{", lastCaracter)-1, rawPage.indexOf("{", lastCaracter)+1).contains("\\")) {
|
||||
lastCaracter = rawPage.indexOf("{", lastCaracter);
|
||||
}
|
||||
else {
|
||||
subPage.add(rawPage.replace("&", "§"));
|
||||
rawPage = "";
|
||||
}
|
||||
}
|
||||
for (int i = subPage.size()-1; i != 0; i--) {
|
||||
if (!subPage.get(i).startsWith("{")) {
|
||||
page = new ComponentBuilder(subPage.get(i)).append(page).create();
|
||||
}
|
||||
else if (subPage.get(i).startsWith("{")) {
|
||||
TextComponent eventBuilder = new TextComponent(subPage.get(i).split(",")[0].substring(1));
|
||||
if (!subPage.get(i).split(",")[1].equals("")) {
|
||||
eventBuilder.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(subPage.get(i).split(",")[1]).create()));
|
||||
}
|
||||
if(subPage.get(i).split(",")[2].startsWith("true")) {
|
||||
if (subPage.get(i).split(",")[2].startsWith("CHANGE_PAGE", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, subPage.get(i).split(",")[2].substring(subPage.get(i).split(",")[2].indexOf(".") + 1, subPage.get(i).split(",")[2].length() - 2)));
|
||||
}
|
||||
else if (subPage.get(i).split(",")[2].startsWith("COPY_TO_CLIPBOARD", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, subPage.get(i).split(",")[2].substring(subPage.get(i).split(",")[2].indexOf(".") + 1, subPage.get(i).split(",")[2].length() - 2)));
|
||||
}
|
||||
else if (subPage.get(i).split(",")[2].startsWith("OPEN_URL", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, subPage.get(i).split(",")[2].substring(subPage.get(i).split(",")[2].indexOf(".") + 1, subPage.get(i).split(",")[2].length() - 2)));
|
||||
}
|
||||
else if (subPage.get(i).split(",")[2].startsWith("RUN_COMMAND", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, subPage.get(i).split(",")[2].substring(subPage.get(i).split(",")[2].indexOf(".") + 1, subPage.get(i).split(",")[2].length() - 2)));
|
||||
}
|
||||
else if (subPage.get(i).split(",")[2].startsWith("SUGGEST_COMMAND", 5)) {
|
||||
eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, subPage.get(i).split(",")[2].substring(subPage.get(i).split(",")[2].indexOf(".") + 1, subPage.get(i).split(",")[2].length() - 2)));
|
||||
}
|
||||
}
|
||||
page = new ComponentBuilder(eventBuilder).append(page).create();
|
||||
}
|
||||
}
|
||||
}
|
||||
meta.spigot().addPage(page);
|
||||
}
|
||||
if(book.setItemMeta(meta)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -39,5 +100,4 @@ public class Book {
|
||||
public void openBook(Player player) {
|
||||
player.openBook(book);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user