From d56fc7d192ae88b7be16c4d139c7aaf6c818208a Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Mon, 8 Jun 2020 11:31:01 +0200 Subject: [PATCH] ClickEvent now work --- config.yml | 7 +++++-- src/fr/topeka/HelpRulesBook/Book.java | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config.yml b/config.yml index 5410d25..172efc3 100644 --- a/config.yml +++ b/config.yml @@ -11,7 +11,7 @@ book: # 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 + #colors are also supported with & and §, help available on https://minecraft.tools/en/color-code.php - | Premiere page C'est beau tu trouve pas ? @@ -26,4 +26,7 @@ book: 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 \ No newline at end of file + 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)} diff --git a/src/fr/topeka/HelpRulesBook/Book.java b/src/fr/topeka/HelpRulesBook/Book.java index a7a592d..9bcb18a 100644 --- a/src/fr/topeka/HelpRulesBook/Book.java +++ b/src/fr/topeka/HelpRulesBook/Book.java @@ -28,16 +28,16 @@ public class Book { BookMeta meta = (BookMeta) book.getItemMeta(); meta.setTitle(_title); meta.setAuthor(_author); - ComponentBuilder page = new ComponentBuilder(""); for (String rawPage: _pages){ - rawPage = rawPage.replace("&", "§"); + 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(message); + message.addExtra(section); }else { String[] elements = section.split(","); TextComponent eventBuilder = new TextComponent(elements[0]); @@ -45,26 +45,28 @@ public class Book { 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() - 2))); + 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() - 2))); + 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() - 2))); + 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() - 2))); + eventBuilder.setClickEvent(new ClickEvent(ClickEvent.Action.CHANGE_PAGE, elements[2].substring(elements[2].indexOf(".") + 1, elements[2].length() - 1))); } - page.append(eventBuilder); } + message.addExtra(eventBuilder); } edit = !edit; } + page.append(message); }else { page.append(rawPage); }