From fa7c30df806cb79326651fe5a9ccbbfa8b7e53e9 Mon Sep 17 00:00:00 2001 From: Andre_601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 1 Jul 2021 21:03:01 +0200 Subject: [PATCH 1/4] Sync Dev with master (#659) * Add contributing and expansion section * Start using new Issue template system * Create bug_report.yml * Rename feature_request.md to feature_request_old.md * Create feature_request.yml * fix unique name * Update feature_request_old.md * Add Checkboxes * Add checkboxes * disable default issue body * Delete bug_report_old.md * Delete feature_request_old.md * Rename bug_report_new.yml to bug_report.yml * Check if deleting this fixed the PR... * Use description in favour of about * improve feature_request.md * Update bug_report.yml * Assign "Type: Issue (Unconfirmed)" label * Use lists and not comma-separated string * Update feature_request.yml * Use id option for error and dump fields * Add field for logs * Remove deprecated issue_body type * Update feature_request.yml * Improve description of bug_report.yml * Initial 1.17 Changes * add render * Revert build.gradle dependencies change * Fixed duplicate files Co-authored-by: PiggyPiglet Co-authored-by: darbyjack --- .github/ISSUE_TEMPLATE/bug_report.md | 43 -------- .github/ISSUE_TEMPLATE/bug_report.yml | 101 ++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 31 ------ .github/ISSUE_TEMPLATE/feature_request.yml | 62 +++++++++++ README.md | 10 +- build.gradle | 24 ++--- gradle/wrapper/gradle-wrapper.jar | Bin 58910 -> 59203 bytes gradle/wrapper/gradle-wrapper.properties | 5 +- gradlew | 2 +- gradlew.bat | 21 +--- .../placeholderapi/PlaceholderAPIPlugin.java | 11 +- 11 files changed, 195 insertions(+), 115 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index c4ab045..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -name: Bug Report -about: Report bugs of PlaceholderAPI with this template - ---- - - -## Bug Report - -### Issue - - - -### Expected behaviour - - - -### Actual behaviour - - - -### How to reproduce - - -1. - -### `/papi dump` output - diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..bb353aa --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,101 @@ +name: Bug Report +description: Found a Bug about PlaceholderAPI? Use this template to report it! +labels: +- "Type: Issue (Unconfirmed)" +body: +- type: markdown + attributes: + value: |- + Thank you for taking your time and opening a Bug Report. + In order for us to process this Bug Report as fast and efficient as possible do we ask you to read the form carefully and provide any requested information. + Required fields are marked with an asterisk symbol (`*`) + + Also, always make sure to use the latest Release from [Spigot](https://www.spigotmc.org/resources/6245/) or the latest Development Build from our [Jenkins Server](http://ci.extendedclip.com/job/PlaceholderAPI/) to make sure that your issue isn't already fixed. + + **DO NOT REPORT ISSUES WITH EXPANSIONS AND/OR PLACEHOLDERS. USE THE APPROPRIATE ISSUE TRACKER FOR THOSE!** +- type: checkboxes + attributes: + label: Confirmation + description: Please make sure to have followed the following checks. + options: + - label: My issue isn't already found on the Issue tracker. + required: true + - label: My issue is about **PlaceholderAPI** and not any expansion or external plugin + required: true + - label: The issue isn't already fixed in a Spigot Release or Development Build. + required: true +- type: dropdown + attributes: + label: "Type" + description: |- + What kind of Bug do you encounter? + + - `Plugin Bug`: PlaceholderAPI doesn't startup properly. + - `API Bug`: A method you use didn't work or has an unexpected result. + - `Plugin/Server Incompatability`: PlaceholderAPI either doesn't support a specific Server Type/Version or has conflicts with another plugin. + multiple: false + options: + - "Plugin Bug" + - "API Bug" + - "Plugin/Server Incompatability" + validations: + required: true +- type: textarea + attributes: + label: "What happens?" + description: "What bug are you encountering? Try to explain it as detailed as possible." + placeholder: "PlaceholderAPI does this when I do that..." + validations: + required: true +- type: textarea + attributes: + label: "Expected Behaviour" + description: "What behaviour did you expect from PlaceholderAPI?" + placeholder: "PlaceholderAPI should actually do..." + validations: + required: true +- type: textarea + attributes: + label: "How to Reproduce" + description: |- + List the steps on how to reproduce this Bug. + Post any Code-examples in the `Additional Information` field below when you selected `API Bug`. + placeholder: |- + 1. Do this + 2. ... + 3. Profit! + validations: + required: true +- type: input + id: "dump" + attributes: + label: "`/papi dump` Output" + description: |- + Please execute the `/papi dump` command and provide the generated URL from it. + If you can't execute the command (i.e. PlaceholderAPI doesn't start up) can you put N/A here and mention the issue in the `Additional Information` field. + placeholder: "https://paste.helpch.at/dump.log" + validations: + required: true +- type: input + id: "console" + attributes: + label: "Console Log" + description: |- + Get the latest content of your `latest.log` file an upload it to https://paste.helpch.at + Take the generated URL and paste it into this field. + placeholder: "https://paste.helpch.at/latest.log" +- type: input + id: "error" + attributes: + label: "Errors" + description: |- + Upload any errors you find to https://paste.helpch.at and post the link in the field below. + placeholder: "https://paste.helpch.at/error.log" +- type: textarea + attributes: + label: "Additional Info" + description: |- + Add any extra info you think is nessesary for this Bug report. + - If you selected `API Bug` will you need to include code-examples here to reproduce the issue. + - If you selected `Plugin/Server Incompatability` should you include extra Server info such as a Timings or Spark-Report or info about the plugin in question. + placeholder: "Put any extra info you like into this field..." diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index c66b3e4..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -name: Feature Request -about: Request a update/change of the PlaceholderAPI-code - ---- - - - -## Feature Request - -### Type - - - -- [ ] New function for PlaceholderAPI. -A new function that developers could use. -- [ ] Change to code (Internal). -Changes to code that won't affect the end-user. -- [ ] Change to code (External). -Changes to code that will affect the end-user (breaks stuff). -- [ ] Other: __________ - -### Description - - diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..d6f6087 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,62 @@ +name: Feature Request +description: Suggest a new Feature for PlaceholderAPI +labels: +- "Type: Enhancement" +body: +- type: markdown + attributes: + value: |- + Thank you for taking the time in creating this Feature Request. + In order to process your feature request as fast and efficiently as possible do we ask you to fill out any required fields (Indicated with a red asterisk (`*`)) with the requested information. + + If you have any further questions should you either [join our Discord Server](https://helpch.at/discord) or [ask in our Discussions](https://github.com/PlaceholderAPI/PlaceholderAPI/discussions). +- type: checkboxes + attributes: + label: Confirmation + description: Please make sure to have followed the following checks. + options: + - label: I checked the Issues and Pull request tab for any existing issues or PRs. + required: true + - label: My Feature Request is for **PlaceholderAPI** and not any expansion or other plugin. + required: true +- type: dropdown + attributes: + label: "Type" + description: "What type is your Suggestion? Select all that match." + multiple: true + options: + - "New API feature" + - "New config option" + - "Minor Code improvement (Won't affect Servers)" + - "Major Code improvement (Will affect Servers)" + validations: + required: true +- type: textarea + attributes: + label: "Description" + description: |- + Give a detailed explanation about your Feature request and why it would be beneficial for PlaceholderAPI. + Just saying "It's cool!" or "I need it" don't count as valid reasons. It needs to have a clear benefit for **other** players too. + validations: + required: true +- type: textarea + attributes: + label: "Code Example" + description: |- + Do you have any Code Snippets that you want to share with us? Paste it here! + Note that the input will automatically be rendered as Java code, so you won't need to put it into a code block yourself. + render: java +- type: input + attributes: + label: "Jar file" + description: |- + If you already have a PlaceholderAPI Jar with the requested changes would we love to get a download link for it. + If you don't have a download link can you leave this field empty or provide "N/A" as a response. + placeholder: "https://cdn.discordapp.com/..." +- type: textarea + attributes: + label: "Additional Information" + description: |- + Add any extra info you think is nessesary for this Feature request. + - When you selected `Major Code improvement (Will affect Servers)` should you mention what will break when people update. + placeholder: "Put any extra info you like into this field..." diff --git a/README.md b/README.md index a6c7930..2ea8404 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ [APIversionImg]: https://img.shields.io/nexus/placeholderapi/me.clip/placeholderapi?server=https%3A%2F%2Frepo.extendedclip.com&label=API%20Version [logo]: https://i.imgur.com/Ea4PURv.png + +[contributing]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/.github/CONTRIBUTING.md +[placeholderexpansion]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/PlaceholderExpansion [![logo]][spigot] @@ -29,8 +32,11 @@ Support for specific plugins are provided either by the plugin itself or through PlaceholderAPI has been downloaded over 500,000 times and has been used concurrently on over 20,000 servers, which makes it a must-have for a server of any type or scale. - - +## Contribute +If you would like to contribute towards PlaceholderAPI should you take a look at our [Contributing file][contributing] for the ins and outs on how you can do that and what you need to keep in mind. + +## Create an Expansion +If you would like to create your own Placeholder Expansion for PlaceholderAPI, take a look at our [Wiki][placeholderexpansion] which contains a detailed tutorial on how you can achieve this. ## Support - [Issue Tracker][issues] diff --git a/build.gradle b/build.gradle index b1c6b8a..f38ba27 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ import org.apache.tools.ant.filters.ReplaceTokens plugins { id "java" id "maven-publish" - id "net.minecrell.licenser" version "0.4.1" - id "com.github.johnrengelman.shadow" version "6.0.0" + id "org.cadixdev.licenser" version "0.6.0" + id "com.github.johnrengelman.shadow" version "7.0.0" } group "me.clip" @@ -20,22 +20,21 @@ repositories { } dependencies { - implementation "org.bstats:bstats-bukkit:1.5" + implementation "com.google.code.gson:gson:2.8.6" + implementation "org.bstats:bstats-bukkit:2.2.1" - compileOnly "org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT" + compileOnly "org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT" compileOnly "org.jetbrains:annotations:19.0.0" testImplementation "org.openjdk.jmh:jmh-core:1.23" testImplementation "org.openjdk.jmh:jmh-generator-annprocess:1.23" - testCompile "org.junit.jupiter:junit-jupiter-engine:5.6.2" - testRuntime "org.junit.jupiter:junit-jupiter-engine:5.6.2" + testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.6.2" } processResources { - from(sourceSets.main.resources.srcDirs) { - filter ReplaceTokens, tokens: [name: rootProject.name, version: project.version.toString(), description: project.description] - } + filter ReplaceTokens, tokens: [name: rootProject.name, version: project.version.toString(), description: project.description] } java { @@ -83,9 +82,10 @@ test { useJUnitPlatform() } -sourceSets { - test.compileClasspath += configurations.compileOnly - test.runtimeClasspath += configurations.compileOnly +configurations { + testImplementation { + extendsFrom(compileOnly) + } } publishing { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 62d4c053550b91381bbd28b1afc82d634bf73a8a..e708b1c023ec8b20f512888fe07c5bd3ff77bb8f 100644 GIT binary patch delta 6656 zcmY+Ibx_pN*Z*PZ4(U#j1qtbvrOTyO8fghZ8kYJfEe%U|$dV!@ASKczEZq$fg48M@ z;LnHO_j#Uq?%bL4dY^md%$$4Y+&@nKC|1uHR&59YNhubGh72|a#ylPdh9V+akp|I; zPk^W-a00GrFMkz_NSADdv2G2-i6rb=cB_@WnG(**4ZO$=96R=t|NZ@|0_z&q3GwO^ ziUFcuj$a9QaZ3j?xt`5#q`sT-ufrtBP0nt3IA&dr*+VCsBzBVW?vZ6eZr0oD%t33z zm~-5IVsjy(F>;S~Pm@bxX85>Z*@(QL6i3JQc?1ryQFcC@X^2^mZWhFv|v? z49>l|nA&XNQ6#OvccUTyBMB*WO#NA;FW5|eE_K6dtVYP2G?uUZ09!`Iq1IF2gA(aS zLu@G^cQJmh=x?-YsYa@E6QnE5+1@ds&0f#OQRDl^GnIT_m84G5XY%W z;Ck6bk^Oeu*Ma-XmxI5GjqzWNbJMsQF4)WfMZEA{oxW0E32e)*JfG}3otPishIQBw zkBe6N#4pKPN>q1R6G1@5&(u#5yPEToMBB6_oEK|q z@(i5j!?;NNCv~=HvW%zF&1yWBq(nJa_#``G&SRmQvE|jePUPs{J!$TacM|e}Fsceb zx+76|mDp6@w>)^DIl{8?)6XYNRU|2plG8Jy&7(^9SdOWNKKJK&>0!z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-#6ZHJqKh|SVuO|>Yrv+m30+!|sK<-|E z=)5E->#y<_1V|T1f%Af!ZYqXg}`O zI$qKOWdnclF`%_Z`WGOe{`A`l-#a?s=Q1a#@BOWmExH2;Wl`OB!B-%lq3nO{4=WO& z#k_x|N&(qzm*6S{G*|GCegF2N2ulC+(58z2DG~yUs}i8zvRf&$CJCaexJ6Xu!`qz( z)*v8*kAE#D0KCo*s{8^Rbg=`*E2MzeIt0|x55%n-gO&yX#$l=3W7-_~&(G8j1E(XB hw}tl`5K!1C(72%nnjQrp<7@!WCh47rWB+@R{{wClNUHz< diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c78a2b9..0f80bbf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Tue Jul 14 23:27:02 AWST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index fbd7c51..4f906e0 100644 --- a/gradlew +++ b/gradlew @@ -130,7 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index 5093609..107acd3 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,21 +64,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line @@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index 7472076..094bddf 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -33,6 +33,8 @@ import me.clip.placeholderapi.expansion.manager.LocalExpansionManager; import me.clip.placeholderapi.listeners.ServerLoadEventListener; import me.clip.placeholderapi.updatechecker.UpdateChecker; import org.bstats.bukkit.Metrics; +import org.bstats.charts.AdvancedPie; +import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; @@ -205,14 +207,13 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { } private void setupMetrics() { - final Metrics metrics = new Metrics(this); - metrics.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", + final Metrics metrics = new Metrics(this, 438); + metrics.addCustomChart(new SimplePie("using_expansion_cloud", () -> getPlaceholderAPIConfig().isCloudEnabled() ? "yes" : "no")); - metrics.addCustomChart( - new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no")); + metrics.addCustomChart(new SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no")); - metrics.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> { + metrics.addCustomChart(new AdvancedPie("expansions_used", () -> { final Map values = new HashMap<>(); for (final PlaceholderExpansion expansion : getLocalExpansionManager().getExpansions()) { From dd7751332f42eebed79a41365b8a081ec4b097fc Mon Sep 17 00:00:00 2001 From: darbyjack Date: Tue, 6 Jul 2021 11:59:17 -0500 Subject: [PATCH 2/4] Initial test on adventure --- build.gradle | 10 +- .../placeholderapi/PlaceholderAPIPlugin.java | 13 + .../cloud/CommandECloudExpansionList.java | 87 +- .../clip/placeholderapi/libs/JSONMessage.java | 1120 ----------------- 4 files changed, 74 insertions(+), 1156 deletions(-) delete mode 100644 src/main/java/me/clip/placeholderapi/libs/JSONMessage.java diff --git a/build.gradle b/build.gradle index f38ba27..31065ec 100644 --- a/build.gradle +++ b/build.gradle @@ -17,12 +17,16 @@ repositories { maven({ url = "https://repo.codemc.org/repository/maven-public" }) maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }) + maven({ url = "https://oss.sonatype.org/content/repositories/snapshots/" }) } dependencies { implementation "com.google.code.gson:gson:2.8.6" implementation "org.bstats:bstats-bukkit:2.2.1" + implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT" + implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT" + compileOnly "org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT" compileOnly "org.jetbrains:annotations:19.0.0" @@ -60,6 +64,8 @@ shadowJar { archiveClassifier.set("") relocate "org.bstats", "me.clip.placeholderapi.metrics" + relocate "com.google.gson", "me.clip.placeholderapi.libs.gson" + relocate "net.kyori", "me.clip.placeholderapi.libs.kyori" } license { @@ -69,10 +75,6 @@ license { header = file('config/headers/main.txt') } - matching('**/JSONMessage.java') { - header = file('config/headers/jsonmessage.txt') - } - ext { year = 2021 } diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index 094bddf..ca79d7e 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -32,6 +32,7 @@ import me.clip.placeholderapi.expansion.manager.CloudExpansionManager; import me.clip.placeholderapi.expansion.manager.LocalExpansionManager; import me.clip.placeholderapi.listeners.ServerLoadEventListener; import me.clip.placeholderapi.updatechecker.UpdateChecker; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bstats.bukkit.Metrics; import org.bstats.charts.AdvancedPie; import org.bstats.charts.SimplePie; @@ -74,6 +75,8 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this); @NotNull private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this); + @NotNull + private BukkitAudiences adventure; /** * Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API @@ -140,6 +143,8 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { setupMetrics(); setupExpansions(); + this.adventure = BukkitAudiences.create(this); + if (config.isCloudEnabled()) { getCloudExpansionManager().load(); } @@ -185,6 +190,14 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { return cloudExpansionManager; } + @NotNull + public BukkitAudiences adventure() { + if(this.adventure == null) { + throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); + } + return this.adventure; + } + /** * Obtain the configuration class for PlaceholderAPI. * diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java index e35d846..4bb96c2 100644 --- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java @@ -43,9 +43,11 @@ import me.clip.placeholderapi.commands.PlaceholderCommand; import me.clip.placeholderapi.configuration.ExpansionSort; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import me.clip.placeholderapi.expansion.cloud.CloudExpansion; -import me.clip.placeholderapi.libs.JSONMessage; import me.clip.placeholderapi.util.Format; import me.clip.placeholderapi.util.Msg; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -136,73 +138,93 @@ public final class CommandECloudExpansionList extends PlaceholderCommand { .append('\n'); } - @NotNull - private static JSONMessage getMessage(@NotNull final List expansions, - final int page, final int limit, @NotNull final String target) { + private static Component getMessage(@NotNull final List expansions, + final int page, final int limit, @NotNull final String target) { final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat(); - final StringBuilder tooltip = new StringBuilder(); - final JSONMessage message = JSONMessage.create(); + // Overall being send + final StringBuilder sb = new StringBuilder(); for (int index = 0; index < expansions.size(); index++) { final CloudExpansion expansion = expansions.get(index); - tooltip.append("&bClick to download this expansion!") + // Hover desc per expansion + final StringBuilder desc = new StringBuilder(); + + desc.append("Click to download this expansion!") .append('\n') .append('\n') - .append("&bAuthor: &f") + .append("Author: ") .append(expansion.getAuthor()) .append('\n') - .append("&bVerified: ") - .append(expansion.isVerified() ? "&a&l✔&r" : "&c&l❌&r") + .append("Verified: ") + .append(expansion.isVerified() ? "" : "") .append('\n') - .append("&bLatest Version: &f") + .append("Latest Version: ") .append(expansion.getLatestVersion()) .append('\n') - .append("&bReleased: &f") + .append("Released: ") .append(format.format(expansion.getLastUpdate())); final String description = expansion.getDescription(); if (description != null && !description.isEmpty()) { - tooltip.append('\n') + desc.append('\n') .append('\n') - .append("&f") + .append("") .append(description.replace("\r", "").trim()); } - message.then(Msg.color( - "&8" + (index + ((page - 1) * PAGE_SIZE) + 1) + ".&r " + (expansion.shouldUpdate() ? "&6" - : expansion.hasExpansion() ? "&a" : "&7") + expansion.getName())); + StringBuilder content = new StringBuilder(); - message.tooltip(Msg.color(tooltip.toString())); - message.suggestCommand("/papi ecloud download " + expansion.getName()); + content.append("") + .append(index + ((page - 1) * PAGE_SIZE) + 1) + .append(". ") + .append(expansion.shouldUpdate() ? "" : expansion.hasExpansion() ? "" : "") + .append(expansion.getName()); + +// message.append(Component.text(Msg.color( +// "&8" + (index + ((page - 1) * PAGE_SIZE) + 1) + ".&r " + (expansion.shouldUpdate() ? "&6" +// : expansion.hasExpansion() ? "&a" : "&7") + expansion.getName())); + + sb.append("") + .append(content) + .append(""); + + // message.tooltip(Msg.color(tooltip.toString())); + // message.suggestCommand("/papi ecloud download " + expansion.getName()); if (index < expansions.size() - 1) { - message.newline(); + sb.append("\n"); } - tooltip.setLength(0); + //tooltip.setLength(0); } if (limit > 1) { - message.newline(); + // message.newline(); + sb.append("\n"); - message.then("◀") - .color(page > 1 ? ChatColor.GRAY : ChatColor.DARK_GRAY); + // message.then("◀").color(page > 1 ? ChatColor.GRAY : ChatColor.DARK_GRAY); + sb.append(page > 1 ? "" : "").append("◀"); if (page > 1) { - message.runCommand("/papi ecloud list " + target + " " + (page - 1)); + // message.runCommand("/papi ecloud list " + target + " " + (page - 1)); } - message.then(" " + page + " ").color(ChatColor.GREEN); + // message.then(" " + page + " ").color(ChatColor.GREEN); + sb.append(" " + page + " "); - message.then("▶") - .color(page < limit ? ChatColor.GRAY : ChatColor.DARK_GRAY); + // message.then("▶").color(page < limit ? ChatColor.GRAY : ChatColor.DARK_GRAY); + sb.append(page < limit ? "" : "").append("▶"); if (page < limit) { - message.runCommand("/papi ecloud list " + target + " " + (page + 1)); + // message.runCommand("/papi ecloud list " + target + " " + (page + 1)); } } - return message; + return MiniMessage.get().parse(sb.toString()); } private static void addExpansionTable(@NotNull final List expansions, @@ -321,8 +343,9 @@ public final class CommandECloudExpansionList extends PlaceholderCommand { final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE); - final JSONMessage message = getMessage(values, page, limit, params.get(0)); - message.send(((Player) sender)); + final Component message = getMessage(values, page, limit, params.get(0)); + plugin.adventure().player((Player) sender).sendMessage(message); + //message.send(((Player) sender)); } @Override diff --git a/src/main/java/me/clip/placeholderapi/libs/JSONMessage.java b/src/main/java/me/clip/placeholderapi/libs/JSONMessage.java deleted file mode 100644 index 07c100d..0000000 --- a/src/main/java/me/clip/placeholderapi/libs/JSONMessage.java +++ /dev/null @@ -1,1120 +0,0 @@ -/* - * Copyright (c) 2018-2021 Peter Blood - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package me.clip.placeholderapi.libs; - -import com.google.common.base.Strings; -import com.google.common.collect.BiMap; -import com.google.common.collect.ImmutableBiMap; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.UUID; -import java.util.Vector; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -/** - * This is a complete JSON message builder class. To create a new JSONMessage do {@link - * #create(String)} - * - * @author Rayzr - */ -@SuppressWarnings({"WeakerAccess", "unused"}) -public class JSONMessage { - - private static final BiMap stylesToNames; - - static { - ImmutableBiMap.Builder builder = ImmutableBiMap.builder(); - for (final ChatColor style : ChatColor.values()) { - if (!style.isFormat()) { - continue; - } - - String styleName; - switch (style) { - case MAGIC: - styleName = "obfuscated"; - break; - case UNDERLINE: - styleName = "underlined"; - break; - default: - styleName = style.name().toLowerCase(); - break; - } - - builder.put(style, styleName); - } - stylesToNames = builder.build(); - } - - - private final List parts = new ArrayList<>(); - private int centeringStartIndex = -1; - - /** - * Creates a new {@link JSONMessage} object - * - * @param text The text to start with - */ - private JSONMessage(String text) { - parts.add(new MessagePart(text)); - } - - /** - * Creates a new {@link JSONMessage} object - * - * @param text The text to start with - * @return A new {@link JSONMessage} object - */ - public static JSONMessage create(String text) { - return new JSONMessage(text); - } - - /** - * Creates a new {@link JSONMessage} object - * - * @return A new {@link JSONMessage} object - */ - public static JSONMessage create() { - return create(""); - } - - /** - * Sends an action bar message - * - * @param message The message to send - * @param players The players you want to send it to - */ - public static void actionbar(String message, Player... players) { - ReflectionHelper.sendPacket(ReflectionHelper - .createActionbarPacket(ChatColor.translateAlternateColorCodes('&', message)), players); - } - - /** - * @return The latest {@link MessagePart} - * @throws ArrayIndexOutOfBoundsException If {@code parts.size() <= 0}. - */ - public MessagePart last() { - if (parts.size() <= 0) { - throw new ArrayIndexOutOfBoundsException("No MessageParts exist!"); - } - return parts.get(parts.size() - 1); - } - - /** - * Converts this {@link JSONMessage} instance to actual JSON - * - * @return The JSON representation of this {@link JSONMessage} - */ - public JsonObject toJSON() { - JsonObject obj = new JsonObject(); - - obj.addProperty("text", ""); - - JsonArray array = new JsonArray(); - - parts.stream() - .map(MessagePart::toJSON) - .forEach(array::add); - - obj.add("extra", array); - - return obj; - } - - /** - * Converts this {@link JSONMessage} object to a String representation of the JSON. This is an - * alias of {@code toJSON().toString()}. - */ - @Override - public String toString() { - return toJSON().toString(); - } - - /** - * Converts this {@link JSONMessage} object to the legacy formatting system, which uses formatting - * codes (like &6, &l, &4, etc.) - * - * @return This {@link JSONMessage} instance {@link JSONMessage} in legacy format - */ - public String toLegacy() { - StringBuilder output = new StringBuilder(); - - parts.stream() - .map(MessagePart::toLegacy) - .forEach(output::append); - - return output.toString(); - } - - /** - * Sends this {@link JSONMessage} to all the players specified - * - * @param players The players you want to send this to - */ - public void send(Player... players) { - if (ReflectionHelper.MAJOR_VER >= 16) { -// ReflectionHelper.sendTextPacket(toString(), players); -// return; - } - - ReflectionHelper.sendPacket(ReflectionHelper.createTextPacket(toString()), players); - } - - /** - * Sends this as a title to all the players specified - * - * @param fadeIn How many ticks to fade in - * @param stay How many ticks to stay - * @param fadeOut How many ticks to fade out - * @param players The players to send this to - */ - public void title(int fadeIn, int stay, int fadeOut, Player... players) { - ReflectionHelper - .sendPacket(ReflectionHelper.createTitleTimesPacket(fadeIn, stay, fadeOut), players); - ReflectionHelper.sendPacket(ReflectionHelper.createTitlePacket(toString()), players); - } - - /** - * Sends this as a subtitle to all the players specified. Must be used after sending a {@link - * #title(int, int, int, Player...) title}. - * - * @param players The players to send this to - */ - public void subtitle(Player... players) { - ReflectionHelper.sendPacket(ReflectionHelper.createSubtitlePacket(toString()), players); - } - - /** - * Sends an action bar message - * - * @param players The players you want to send this to - */ - public void actionbar(Player... players) { - actionbar(toLegacy(), players); - } - - /** - * Sets the color of the current message part. - * - * @param color The color to set - * @return This {@link JSONMessage} instance - */ - public JSONMessage color(ChatColor color) { - if (!color.isColor()) { - throw new IllegalArgumentException(color.name() + " is not a color."); - } - - last().setColor(color); - return this; - } - - /** - * Sets the color of the current message part. - *
If the provided color is a hex color ({@code #rrggbb}) but the major version of MC is older - * than 1.16 will this - * default to the color WHITE. - * - * @param color The color to set - * @return This {@link JSONMessage} instance - */ - public JSONMessage color(String color) { - return color(color, ChatColor.WHITE); - } - - /** - * Sets the color of the current message part. - *
If the provided color is a hex color ({@code #rrggbb}) but the major version of MC is older - * than 1.16 will the provided - * default ChatColor be used instead. - * - * @param color The color to set - * @param def The default ChatColor to use, when MC version is older than 1.16 - * @return This {@link JSONMessage} instance - */ - public JSONMessage color(String color, ChatColor def) { - if (color.startsWith("#") && ReflectionHelper.MAJOR_VER < 16) { - return color(def); - } - - last().setColor(color); - return this; - } - - /** - * Sets the font of the current message part. - *
When this is used on versions older than 1.16 will this do nothing. - * - * @param font The font to set - * @return This {@link JSONMessage} instance - */ - public JSONMessage font(String font) { - if (ReflectionHelper.MAJOR_VER < 16) { - return this; - } - - last().setFont(font); - return this; - } - - /** - * Adds a style to the current message part. - * - * @param style The style to add - * @return This {@link JSONMessage} instance - */ - public JSONMessage style(ChatColor style) { - last().addStyle(style); - return this; - } - - /** - * Makes the text run a command. - * - * @param command The command to run - * @return This {@link JSONMessage} instance - */ - public JSONMessage runCommand(String command) { - last().setOnClick(ClickEvent.runCommand(command)); - return this; - } - - /** - * Makes the text suggest a command. - * - * @param command The command to suggest - * @return This {@link JSONMessage} instance - */ - public JSONMessage suggestCommand(String command) { - last().setOnClick(ClickEvent.suggestCommand(command)); - return this; - } - - /** - * Opens a URL. - * - * @param url The url to open - * @return This {@link JSONMessage} instance - */ - public JSONMessage openURL(String url) { - last().setOnClick(ClickEvent.openURL(url)); - return this; - } - - /** - * Copies the provided text to the Clipboard of the player. - *
When this is used on versions older than 1.15 will this default to {@link - * #suggestCommand(String) suggestCommand(String)}. - * - * @param text The text to copy - * @return This {@link JSONMessage} instance - */ - public JSONMessage copyText(String text) { - last().setOnClick(ClickEvent.copyText(text)); - return this; - } - - /** - * Changes the page of a book. Using this in a non-book context is useless and will probably - * error. - * - * @param page The page to change to - * @return This {@link JSONMessage} instance - */ - public JSONMessage changePage(int page) { - last().setOnClick(ClickEvent.changePage(page)); - return this; - } - - /** - * Shows text when you hover over it - * - * @param text The text to show - * @return This {@link JSONMessage} instance - */ - public JSONMessage tooltip(String text) { - last().setOnHover(HoverEvent.showText(text)); - return this; - } - - /** - * Shows text when you hover over it - * - * @param message The text to show - * @return This {@link JSONMessage} instance - */ - public JSONMessage tooltip(JSONMessage message) { - last().setOnHover(HoverEvent.showText(message)); - return this; - } - - /** - * Shows an achievement when you hover over it - * - * @param id The id of the achievement - * @return This {@link JSONMessage} instance - */ - public JSONMessage achievement(String id) { - last().setOnHover(HoverEvent.showAchievement(id)); - return this; - } - - /** - * Adds another part to this {@link JSONMessage} - * - * @param text The text to start the next {@link MessagePart} with - * @return This {@link JSONMessage} instance - */ - public JSONMessage then(String text) { - return then(new MessagePart(text)); - } - - /** - * Adds another part to this {@link JSONMessage} - * - * @param nextPart The next {@link MessagePart} - * @return This {@link JSONMessage} instance - */ - public JSONMessage then(MessagePart nextPart) { - parts.add(nextPart); - return this; - } - - /** - * Adds a horizontal bar to the message of the given length - * - * @param length The length of the horizontal bar - * @return This {@link JSONMessage} instance - */ - public JSONMessage bar(int length) { - return then(Strings.repeat("-", length)).color(ChatColor.DARK_GRAY) - .style(ChatColor.STRIKETHROUGH); - } - - /** - * Adds a horizontal bar to the message that's 53 characters long. This is the default width of - * the player's chat window. - * - * @return This {@link JSONMessage} instance - */ - public JSONMessage bar() { - return bar(53); - } - - /** - * Adds a blank line to the message - * - * @return This {@link JSONMessage} instance - */ - public JSONMessage newline() { - return then("\n"); - } - - /** - * Sets the starting point to begin centering JSONMessages. - * - * @return This {@link JSONMessage} instance - */ - public JSONMessage beginCenter() { - // Start with the NEXT message part. - centeringStartIndex = parts.size(); - return this; - } - - /** - * Ends the centering of the JSONMessage text. - * - * @return This {@link JSONMessage} instance - */ - public JSONMessage endCenter() { - int current = centeringStartIndex; - - while (current < parts.size()) { - Vector currentLine = new Vector<>(); - int totalLineLength = 0; - - for (; ; current++) { - MessagePart part = current < parts.size() ? parts.get(current) : null; - String raw = part == null ? null : ChatColor.stripColor(part.toLegacy()); - int rawLength = raw == null ? 0 : raw.length(); - - if (current >= parts.size() || totalLineLength + rawLength >= 53) { - int padding = Math.max(0, (53 - totalLineLength) / 2); - currentLine.firstElement() - .setText(Strings.repeat(" ", padding) + currentLine.firstElement().getText()); - currentLine.lastElement().setText(currentLine.lastElement().getText() + "\n"); - currentLine.clear(); - break; - } - - totalLineLength += rawLength; - currentLine.add(part); - } - } - - MessagePart last = parts.get(parts.size() - 1); - last.setText(last.getText().substring(0, last.getText().length() - 1)); - - centeringStartIndex = -1; - - return this; - } - - /////////////////////////// - // BEGIN UTILITY CLASSES // - /////////////////////////// - - /** - * Represents the JSON format that all click/hover events in JSON messages must follow. - *
- *
- * Reference - * - * @author Rayzr - */ - public static class MessageEvent { - - private String action; - private Object value; - - public MessageEvent(String action, Object value) { - this.action = action; - this.value = value; - } - - /** - * @return A {@link JsonObject} representing the properties of this {@link MessageEvent} - */ - public JsonObject toJSON() { - JsonObject obj = new JsonObject(); - obj.addProperty("action", action); - /* - * MC 1.16 changed "value" to "contents", but only for Hover events... Don't ask why. - * Since this lib only has tooltip and achievement can we simply check if action starts with "show_" - */ - String valueType = - (ReflectionHelper.MAJOR_VER >= 16 && action.startsWith("show_")) ? "contents" : "value"; - - if (value instanceof JsonElement) { - obj.add(valueType, (JsonElement) value); - } else { - obj.addProperty(valueType, value.toString()); - } - return obj; - } - - /** - * @return The action - */ - public String getAction() { - return action; - } - - /** - * @param action The action to set - */ - public void setAction(String action) { - this.action = action; - } - - /** - * @return The value - */ - public Object getValue() { - return value; - } - - /** - * @param value The value to set - */ - public void setValue(Object value) { - this.value = value; - } - - } - - public static class ClickEvent { - - /** - * Runs a command. - * - * @param command The command to run - * @return The {@link MessageEvent} - */ - public static MessageEvent runCommand(String command) { - return new MessageEvent("run_command", command); - } - - /** - * Suggests a command by inserting it in chat. - * - * @param command The command to suggest - * @return The {@link MessageEvent} - */ - public static MessageEvent suggestCommand(String command) { - return new MessageEvent("suggest_command", command); - } - - /** - * Requires web links to be enabled on the client. - * - * @param url The url to open - * @return The {@link MessageEvent} - */ - public static MessageEvent openURL(String url) { - return new MessageEvent("open_url", url); - } - - /** - * Only used with written books. - * - * @param page The page to switch to - * @return The {@link MessageEvent} - */ - public static MessageEvent changePage(int page) { - return new MessageEvent("change_page", page); - } - - /** - * Copies the provided text to the clipboard of the player. - *
When used on versions older than 1.15 will this {@link #suggestCommand(String) suggest - * the text} instead. - * - * @param text The text to copy. - * @return The {@link MessageEvent} - */ - public static MessageEvent copyText(String text) { - if (ReflectionHelper.MAJOR_VER < 15) { - return suggestCommand(text); - } - - return new MessageEvent("copy_to_clipboard", text); - } - - } - - public static class HoverEvent { - - /** - * Shows text when you hover over it - * - * @param text The text to show - * @return The {@link MessageEvent} - */ - public static MessageEvent showText(String text) { - return new MessageEvent("show_text", text); - } - - /** - * Shows text when you hover over it - * - * @param message The {@link JSONMessage} to show - * @return The {@link MessageEvent} - */ - public static MessageEvent showText(JSONMessage message) { - JsonArray arr = new JsonArray(); - arr.add(new JsonPrimitive("")); - arr.add(message.toJSON()); - return new MessageEvent("show_text", arr); - } - - /** - * Shows an achievement when you hover over it - * - * @param id The id of the achievement - * @return The {@link MessageEvent} - */ - public static MessageEvent showAchievement(String id) { - return new MessageEvent("show_achievement", id); - } - - } - - private static class ReflectionHelper { - - private static final String version; - private static Constructor chatComponentText; - - private static Class packetPlayOutChat; - private static Field packetPlayOutChatComponent; - private static Field packetPlayOutChatMessageType; - private static Field packetPlayOutChatUuid; - private static Object enumChatMessageTypeMessage; - private static Object enumChatMessageTypeActionbar; - - private static Constructor titlePacketConstructor; - private static Constructor titleTimesPacketConstructor; - private static Object enumActionTitle; - private static Object enumActionSubtitle; - - private static Field connection; - private static MethodHandle GET_HANDLE; - private static MethodHandle SEND_PACKET; - private static MethodHandle STRING_TO_CHAT; - private static boolean SETUP; - private static int MAJOR_VER = -1; - - static { - String[] split = Bukkit.getServer().getClass().getPackage().getName().split("\\."); - version = split[split.length - 1]; - - try { - MAJOR_VER = Integer.parseInt(version.split("_")[1]); - - final Class craftPlayer = getClass("{obc}.entity.CraftPlayer"); - Method getHandle = craftPlayer.getMethod("getHandle"); - connection = getHandle.getReturnType().getField("playerConnection"); - Method sendPacket = connection.getType().getMethod("sendPacket", getClass("{nms}.Packet")); - - chatComponentText = getClass("{nms}.ChatComponentText").getConstructor(String.class); - - final Class iChatBaseComponent = getClass("{nms}.IChatBaseComponent"); - - Method stringToChat; - - if (MAJOR_VER < 8) { - stringToChat = getClass("{nms}.ChatSerializer").getMethod("a", String.class); - } else { - stringToChat = getClass("{nms}.IChatBaseComponent$ChatSerializer") - .getMethod("a", String.class); - } - - GET_HANDLE = MethodHandles.lookup().unreflect(getHandle); - SEND_PACKET = MethodHandles.lookup().unreflect(sendPacket); - STRING_TO_CHAT = MethodHandles.lookup().unreflect(stringToChat); - - packetPlayOutChat = getClass("{nms}.PacketPlayOutChat"); - packetPlayOutChatComponent = getField(packetPlayOutChat, "a"); - packetPlayOutChatMessageType = getField(packetPlayOutChat, "b"); - packetPlayOutChatUuid = MAJOR_VER >= 16 ? getField(packetPlayOutChat, "c") : null; - - Class packetPlayOutTitle = getClass("{nms}.PacketPlayOutTitle"); - Class titleAction = getClass("{nms}.PacketPlayOutTitle$EnumTitleAction"); - - titlePacketConstructor = packetPlayOutTitle.getConstructor(titleAction, iChatBaseComponent); - titleTimesPacketConstructor = packetPlayOutTitle - .getConstructor(int.class, int.class, int.class); - - enumActionTitle = titleAction.getField("TITLE").get(null); - enumActionSubtitle = titleAction.getField("SUBTITLE").get(null); - - if (MAJOR_VER >= 12) { - Method getChatMessageType = getClass("{nms}.ChatMessageType").getMethod("a", byte.class); - - enumChatMessageTypeMessage = getChatMessageType.invoke(null, (byte) 1); - enumChatMessageTypeActionbar = getChatMessageType.invoke(null, (byte) 2); - } - - SETUP = true; - } catch (Exception e) { - e.printStackTrace(); - SETUP = false; - } - } - - static void sendPacket(Object packet, Player... players) { - assertIsSetup(); - - if (packet == null) { - return; - } - - for (Player player : players) { - try { - SEND_PACKET.bindTo(connection.get(GET_HANDLE.bindTo(player).invoke())).invoke(packet); - } catch (Throwable e) { - System.err.println("Failed to send packet"); - e.printStackTrace(); - } - } - - } - - static Object createActionbarPacket(String message) { - assertIsSetup(); - - Object packet = createTextPacket(message); - setType(packet, (byte) 2); - return packet; - } - - static Object createTextPacket(String message) { - assertIsSetup(); - - try { - Object packet = packetPlayOutChat.newInstance(); - setFieldValue(packetPlayOutChatComponent, packet, fromJson(message)); - setFieldValue(packetPlayOutChatUuid, packet, UUID.randomUUID()); - setType(packet, (byte) 1); - return packet; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - static Object createTitlePacket(String message) { - assertIsSetup(); - - try { - return titlePacketConstructor.newInstance(enumActionTitle, fromJson(message)); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - static Object createTitleTimesPacket(int fadeIn, int stay, int fadeOut) { - assertIsSetup(); - - try { - return titleTimesPacketConstructor.newInstance(fadeIn, stay, fadeOut); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - static Object createSubtitlePacket(String message) { - assertIsSetup(); - - try { - return titlePacketConstructor.newInstance(enumActionSubtitle, fromJson(message)); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - private static void setType(Object chatPacket, byte type) { - assertIsSetup(); - - if (MAJOR_VER < 12) { - setFieldValue(packetPlayOutChatMessageType, chatPacket, type); - return; - } - - switch (type) { - case 1: - setFieldValue(packetPlayOutChatMessageType, chatPacket, enumChatMessageTypeMessage); - break; - case 2: - setFieldValue(packetPlayOutChatMessageType, chatPacket, enumChatMessageTypeActionbar); - break; - default: - throw new IllegalArgumentException("type must be 1 or 2"); - } - } - - /** - * Creates a ChatComponentText from plain text - * - * @param message The text to convert to a chat component - * @return The chat component - */ - static Object componentText(String message) { - assertIsSetup(); - - try { - return chatComponentText.newInstance(message); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - - } - - /** - * Attempts to convert a String representing a JSON message into a usable object - * - * @param json The JSON to attempt to parse - * @return The object representing the text in JSON form, or null if something went - * wrong converting the String to JSON data - */ - static Object fromJson(String json) { - assertIsSetup(); - - if (!json.trim().startsWith("{")) { - return componentText(json); - } - - try { - return STRING_TO_CHAT.invoke(json); - } catch (Throwable e) { - e.printStackTrace(); - return null; - } - } - - private static void assertIsSetup() { - if (!SETUP) { - throw new IllegalStateException("JSONMessage.ReflectionHelper is not set up yet!"); - } - } - - private static Class getClass(String path) throws ClassNotFoundException { - return Class.forName(path.replace("{nms}", "net.minecraft.server." + version) - .replace("{obc}", "org.bukkit.craftbukkit." + version)); - } - - private static void setFieldValue(Field field, Object instance, Object value) { - if (field == null) { - // useful for fields that might not exist - return; - } - - try { - field.set(instance, value); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - private static Field getField(Class classObject, String fieldName) { - try { - Field field = classObject.getDeclaredField(fieldName); - field.setAccessible(true); - return field; - } catch (NoSuchFieldException e) { - e.printStackTrace(); - return null; - } - } - - private static int getVersion() { - return MAJOR_VER; - } - } - - /** - * Defines a section of the message, and represents the format that all JSON messages must follow - * in Minecraft. - *
- *
- * Reference - * - * @author Rayzr - */ - public static class MessagePart { - - private final List styles = new ArrayList<>(); - private MessageEvent onClick; - private MessageEvent onHover; - private String color; - private ChatColor legacyColor; - private String font; - private String text; - - public MessagePart(String text) { - this.text = text == null ? "null" : text; - } - - /** - * Converts this {@link MessagePart} into a {@link JsonObject} - * - * @return The Minecraft-compatible {@link JsonObject} - */ - public JsonObject toJSON() { - Objects.requireNonNull(text); - - JsonObject obj = new JsonObject(); - obj.addProperty("text", text); - - if (color != null && !color.isEmpty()) { - obj.addProperty("color", color.toLowerCase()); - } - - for (ChatColor style : styles) { - obj.addProperty(stylesToNames.get(style), true); - } - - if (onClick != null) { - obj.add("clickEvent", onClick.toJSON()); - } - - if (onHover != null) { - obj.add("hoverEvent", onHover.toJSON()); - } - - if (font != null) { - obj.addProperty("font", font); - } - - return obj; - - } - - /** - * @return This {@link MessagePart} in legacy-style color/formatting codes - */ - public String toLegacy() { - StringBuilder output = new StringBuilder(); - ChatColor legacyColor = getColor(); - - if (legacyColor != null) { - output.append(legacyColor); - } - - styles.stream() - .map(ChatColor::toString) - .forEach(output::append); - - return output.append(text).toString(); - } - - /** - * @return The click event bound - */ - public MessageEvent getOnClick() { - return onClick; - } - - /** - * @param onClick The new click event to bind - */ - public void setOnClick(MessageEvent onClick) { - this.onClick = onClick; - } - - /** - * @return The hover event bound - */ - public MessageEvent getOnHover() { - return onHover; - } - - /** - * @param onHover The new hover event to bind - */ - public void setOnHover(MessageEvent onHover) { - this.onHover = onHover; - } - - /** - * @return The color - */ - public String getColorValue() { - return color; - } - - /** - * @return The color - * @deprecated Use {@link #getColorValue()} instead - */ - @Deprecated - public ChatColor getColor() { - if (legacyColor != null) { - return legacyColor; - } - - if (this.color.startsWith("#") && ReflectionHelper.MAJOR_VER < 16) { - throw new IllegalStateException( - "Custom Hex colors can only be used in Minecraft 1.16 or newer!"); - } - - try { - return ChatColor.valueOf(this.color.toUpperCase()); - } catch (Exception ex) { - return null; - } - } - - /** - * @param color The color to set - * @deprecated Use {@link #setColor(String)} instead - */ - @Deprecated - public void setColor(ChatColor color) { - setColor(color == null ? null : color.name().toLowerCase()); - setLegacyColor(color); - } - - /** - * @param color The color to set - */ - public void setColor(String color) { - if (color != null && color.isEmpty()) { - throw new IllegalArgumentException("Color cannot be null!"); - } - this.color = color; - } - - /** - * @param color The legacy ChatColor to set - * @deprecated Use {@link #setColor(String)} instead - */ - @Deprecated - public void setLegacyColor(ChatColor color) { - legacyColor = color; - } - - /** - * @return The list of styles - */ - public List getStyles() { - return styles; - } - - /** - * @param style The new style to add - */ - public void addStyle(ChatColor style) { - if (style == null) { - throw new IllegalArgumentException("Style cannot be null!"); - } - if (!style.isFormat()) { - throw new IllegalArgumentException(style.name() + " is not a style!"); - } - styles.add(style); - } - - /** - * @return The font used - */ - public String getFont() { - return font; - } - - /** - * @param font The font to use - */ - public void setFont(String font) { - this.font = font; - } - - /** - * @return The raw text - */ - public String getText() { - return text; - } - - /** - * @param text The raw text to set - */ - public void setText(String text) { - this.text = text; - } - - } -} \ No newline at end of file From d7a4acc2f54ab67c607f8d7aeb153aa889603796 Mon Sep 17 00:00:00 2001 From: PiggyPiglet Date: Wed, 7 Jul 2021 15:37:35 +0800 Subject: [PATCH 3/4] started moving to pure adventure --- build.gradle | 16 ++- .../placeholderapi/PlaceholderAPIPlugin.java | 14 +- .../cloud/CommandECloudExpansionList.java | 130 +++++++----------- 3 files changed, 74 insertions(+), 86 deletions(-) diff --git a/build.gradle b/build.gradle index 31065ec..1654574 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ description "An awesome placeholder provider!" repositories { mavenCentral() + mavenLocal() maven({ url = "https://repo.codemc.org/repository/maven-public" }) maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }) @@ -24,10 +25,9 @@ dependencies { implementation "com.google.code.gson:gson:2.8.6" implementation "org.bstats:bstats-bukkit:2.2.1" - implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT" implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT" - compileOnly "org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT" + compileOnly "org.spigotmc:spigot:+" compileOnly "org.jetbrains:annotations:19.0.0" testImplementation "org.openjdk.jmh:jmh-core:1.23" @@ -63,6 +63,18 @@ tasks.withType(Javadoc) { shadowJar { archiveClassifier.set("") +// destinationDirectory.set(file("server/1.17/plugins")) +// doLast { +// def path = "build/libs/PlaceholderAPI-2.10.10-DEV-null.jar" +// +// ["1.17", "1.8"].each {dest -> +// copy { +// from path +// into "server/${dest}/plugins/" +// } +// } +// } + relocate "org.bstats", "me.clip.placeholderapi.metrics" relocate "com.google.gson", "me.clip.placeholderapi.libs.gson" relocate "net.kyori", "me.clip.placeholderapi.libs.kyori" diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index ca79d7e..3314caf 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -75,7 +75,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this); @NotNull private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this); - @NotNull + private BukkitAudiences adventure; /** @@ -143,7 +143,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { setupMetrics(); setupExpansions(); - this.adventure = BukkitAudiences.create(this); + adventure = BukkitAudiences.create(this); if (config.isCloudEnabled()) { getCloudExpansionManager().load(); @@ -163,6 +163,9 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { Bukkit.getScheduler().cancelTasks(this); + adventure.close(); + adventure = null; + instance = null; } @@ -191,11 +194,12 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { } @NotNull - public BukkitAudiences adventure() { - if(this.adventure == null) { + public BukkitAudiences getAdventure() { + if(adventure == null) { throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); } - return this.adventure; + + return adventure; } /** diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java index 4bb96c2..a3ce804 100644 --- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java @@ -26,14 +26,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.primitives.Ints; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.stream.Collectors; @@ -47,12 +40,23 @@ import me.clip.placeholderapi.util.Format; import me.clip.placeholderapi.util.Msg; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.minimessage.MiniMessage; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.network.chat.ChatMessageType; +import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.network.protocol.game.PacketPlayOutChat; import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; +import org.w3c.dom.Text; + +import static net.kyori.adventure.text.Component.*; +import static net.kyori.adventure.text.format.NamedTextColor.*; public final class CommandECloudExpansionList extends PlaceholderCommand { @@ -139,92 +143,58 @@ public final class CommandECloudExpansionList extends PlaceholderCommand { } private static Component getMessage(@NotNull final List expansions, - final int page, final int limit, @NotNull final String target) { + final int page, final int limit, @NotNull final String target) { final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat(); - // Overall being send - final StringBuilder sb = new StringBuilder(); + final TextComponent.Builder message = text(); for (int index = 0; index < expansions.size(); index++) { final CloudExpansion expansion = expansions.get(index); + final TextComponent.Builder line = text(); - // Hover desc per expansion - final StringBuilder desc = new StringBuilder(); + final int expansionNumber = index + ((page - 1) * PAGE_SIZE) + 1; + line.append(text(expansionNumber + ". ", DARK_GRAY)); - desc.append("Click to download this expansion!") - .append('\n') - .append('\n') - .append("Author: ") - .append(expansion.getAuthor()) - .append('\n') - .append("Verified: ") - .append(expansion.isVerified() ? "" : "") - .append('\n') - .append("Latest Version: ") - .append(expansion.getLatestVersion()) - .append('\n') - .append("Released: ") - .append(format.format(expansion.getLastUpdate())); + final NamedTextColor expansionColour; - final String description = expansion.getDescription(); - if (description != null && !description.isEmpty()) { - desc.append('\n') - .append('\n') - .append("") - .append(description.replace("\r", "").trim()); + if (expansion.shouldUpdate()) { + expansionColour = GOLD; + } else { + if (expansion.hasExpansion()) { + expansionColour = GREEN; + } else { + expansionColour = GRAY; + } } - StringBuilder content = new StringBuilder(); + line.append(text(expansion.getName(), expansionColour)); - content.append("") - .append(index + ((page - 1) * PAGE_SIZE) + 1) - .append(". ") - .append(expansion.shouldUpdate() ? "" : expansion.hasExpansion() ? "" : "") - .append(expansion.getName()); + line.clickEvent(ClickEvent.suggestCommand("/papi ecloud download " + expansion.getName())); -// message.append(Component.text(Msg.color( -// "&8" + (index + ((page - 1) * PAGE_SIZE) + 1) + ".&r " + (expansion.shouldUpdate() ? "&6" -// : expansion.hasExpansion() ? "&a" : "&7") + expansion.getName())); + final TextComponent.Builder hoverText = text("Click to download this expansion!", AQUA) + .append(newline()).append(newline()) + .append(text("Author: ", AQUA)).append(text(expansion.getAuthor(), WHITE)) + .append(newline()) + .append(text("Verified: ", AQUA)).append(text(expansion.isVerified() ? "✔" : "❌", expansion.isVerified() ? GREEN : RED, TextDecoration.BOLD)) + .append(newline()) + .append(text("Released: ", AQUA)).append(text(format.format(expansion.getLastUpdate()), WHITE)) + .toBuilder(); - sb.append("") - .append(content) - .append(""); + Optional.ofNullable(expansion.getDescription()) + .filter(description -> !description.isEmpty()) + .ifPresent(description -> hoverText.append(newline()).append(newline()) + .append(text(description.replace("\r", "").trim(), WHITE)) + ); - // message.tooltip(Msg.color(tooltip.toString())); - // message.suggestCommand("/papi ecloud download " + expansion.getName()); + line.hoverEvent(HoverEvent.showText(hoverText.build())); + line.append(newline()); - if (index < expansions.size() - 1) { - sb.append("\n"); - } - - //tooltip.setLength(0); + message.append(line.build()); } - if (limit > 1) { - // message.newline(); - sb.append("\n"); + message.append(text("test").hoverEvent(HoverEvent.showText(text("testtt")))); - // message.then("◀").color(page > 1 ? ChatColor.GRAY : ChatColor.DARK_GRAY); - sb.append(page > 1 ? "" : "").append("◀"); - if (page > 1) { - // message.runCommand("/papi ecloud list " + target + " " + (page - 1)); - } - - // message.then(" " + page + " ").color(ChatColor.GREEN); - sb.append(" " + page + " "); - - // message.then("▶").color(page < limit ? ChatColor.GRAY : ChatColor.DARK_GRAY); - sb.append(page < limit ? "" : "").append("▶"); - if (page < limit) { - // message.runCommand("/papi ecloud list " + target + " " + (page + 1)); - } - } - - return MiniMessage.get().parse(sb.toString()); + return message.build(); } private static void addExpansionTable(@NotNull final List expansions, @@ -344,7 +314,9 @@ public final class CommandECloudExpansionList extends PlaceholderCommand { final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE); final Component message = getMessage(values, page, limit, params.get(0)); - plugin.adventure().player((Player) sender).sendMessage(message); +// plugin.getAdventure().player((Player) sender).sendMessage(message); + System.out.println(GsonComponentSerializer.gson().serialize(message)); + ((CraftPlayer) sender).getHandle().b.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(GsonComponentSerializer.gson().serialize(message)), ChatMessageType.a, ((CraftPlayer) sender).getUniqueId())); //message.send(((Player) sender)); } From c4789b7db028a3fea48b77d460a98e222b45786b Mon Sep 17 00:00:00 2001 From: PiggyPiglet Date: Fri, 9 Jul 2021 12:24:36 +0800 Subject: [PATCH 4/4] finished kyori impl --- build.gradle | 19 ++-------- gradlew | 0 .../placeholderapi/PlaceholderAPIPlugin.java | 1 + .../cloud/CommandECloudExpansionList.java | 37 ++++++++++++------- 4 files changed, 27 insertions(+), 30 deletions(-) mode change 100644 => 100755 gradlew diff --git a/build.gradle b/build.gradle index 1654574..5df263f 100644 --- a/build.gradle +++ b/build.gradle @@ -13,21 +13,21 @@ version "2.10.10-DEV-${System.getProperty("BUILD_NUMBER")}" description "An awesome placeholder provider!" repositories { + maven({ url = "https://oss.sonatype.org/content/repositories/snapshots/" }) + mavenCentral() mavenLocal() maven({ url = "https://repo.codemc.org/repository/maven-public" }) maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }) - maven({ url = "https://oss.sonatype.org/content/repositories/snapshots/" }) } dependencies { - implementation "com.google.code.gson:gson:2.8.6" implementation "org.bstats:bstats-bukkit:2.2.1" implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT" - compileOnly "org.spigotmc:spigot:+" + compileOnly "org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT" compileOnly "org.jetbrains:annotations:19.0.0" testImplementation "org.openjdk.jmh:jmh-core:1.23" @@ -63,20 +63,7 @@ tasks.withType(Javadoc) { shadowJar { archiveClassifier.set("") -// destinationDirectory.set(file("server/1.17/plugins")) -// doLast { -// def path = "build/libs/PlaceholderAPI-2.10.10-DEV-null.jar" -// -// ["1.17", "1.8"].each {dest -> -// copy { -// from path -// into "server/${dest}/plugins/" -// } -// } -// } - relocate "org.bstats", "me.clip.placeholderapi.metrics" - relocate "com.google.gson", "me.clip.placeholderapi.libs.gson" relocate "net.kyori", "me.clip.placeholderapi.libs.kyori" } diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index 3314caf..b121bd3 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -33,6 +33,7 @@ import me.clip.placeholderapi.expansion.manager.LocalExpansionManager; import me.clip.placeholderapi.listeners.ServerLoadEventListener; import me.clip.placeholderapi.updatechecker.UpdateChecker; import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.kyori.adventure.text.serializer.craftbukkit.MinecraftComponentSerializer; import org.bstats.bukkit.Metrics; import org.bstats.charts.AdvancedPie; import org.bstats.charts.SimplePie; diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java index a3ce804..cb4d38c 100644 --- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java @@ -44,16 +44,10 @@ import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.network.chat.ChatMessageType; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutChat; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; -import org.w3c.dom.Text; import static net.kyori.adventure.text.Component.*; import static net.kyori.adventure.text.format.NamedTextColor.*; @@ -138,8 +132,7 @@ public final class CommandECloudExpansionList extends PlaceholderCommand { builder.append(" &bPage&7: &a") .append(page) - .append("&r") - .append('\n'); + .append("&r"); } private static Component getMessage(@NotNull final List expansions, @@ -187,12 +180,31 @@ public final class CommandECloudExpansionList extends PlaceholderCommand { ); line.hoverEvent(HoverEvent.showText(hoverText.build())); - line.append(newline()); + + if (index != expansions.size() - 1) { + line.append(newline()); + } message.append(line.build()); } - message.append(text("test").hoverEvent(HoverEvent.showText(text("testtt")))); + if (limit > 1) { + message.append(newline()); + + final TextComponent.Builder left = text("◀", page > 1 ? GRAY : DARK_GRAY).toBuilder(); + + if (page > 1) { + left.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page - 1))); + } + + final TextComponent.Builder right = text("▶", page < limit ? GRAY : DARK_GRAY).toBuilder(); + + if (page < limit) { + right.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page + 1))); + } + + message.append(left, text(" " + page + " ", GREEN), right); + } return message.build(); } @@ -314,10 +326,7 @@ public final class CommandECloudExpansionList extends PlaceholderCommand { final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE); final Component message = getMessage(values, page, limit, params.get(0)); -// plugin.getAdventure().player((Player) sender).sendMessage(message); - System.out.println(GsonComponentSerializer.gson().serialize(message)); - ((CraftPlayer) sender).getHandle().b.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(GsonComponentSerializer.gson().serialize(message)), ChatMessageType.a, ((CraftPlayer) sender).getUniqueId())); - //message.send(((Player) sender)); + plugin.getAdventure().player((Player) sender).sendMessage(message); } @Override