diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 9c3768a..c4ab045 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -23,25 +23,21 @@ about: Report bugs of PlaceholderAPI with this template
## Bug Report
### Issue
-> What is the issue? Describe it like you would tell a friend.
-
+
### Expected behaviour
-> What should PlaceholderAPI do?
-
+
### Actual behaviour
-> What does PlaceholderAPI actually do?
-
+
### How to reproduce
-> What steps did you made, to get this bug?
-
+
+
1.
-### Installed expansions
-> Please list all expansions that are displayed when running `/papi list`
-
+### `/papi dump` output
+
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
index 0e16cfa..c66b3e4 100644
--- a/.github/ISSUE_TEMPLATE/feature_request.md
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -15,10 +15,9 @@ about: Request a update/change of the PlaceholderAPI-code
## Feature Request
### Type
-> What kind of request is this? (Multiple selections possible)
-
+
+
+
- [ ] New function for PlaceholderAPI.
A new function that developers could use.
- [ ] Change to code (Internal).
@@ -27,7 +26,6 @@ Changes to code that won't affect the end-user.
Changes to code that will affect the end-user (breaks stuff).
- [ ] Other: __________
-### Info
-> What is the change?
-> Please provide as much information (including links, images and code-snippeds) as possible.
-
+### Description
+
+
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index f0bd977..87244dc 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -1,8 +1,13 @@
-## Please read
-Please make sure you checked the following:
-- You checked the [Pull requests] page for any upcoming changes.
-- You documented any public code that the end-user might use.
-- You followed the [contributing file]
+
+
+## Pull Request
### Type
### Description
-> Provide additional information if needed.
-
+
+
+Closes N/A
-
-[Pull requests]: https://github.com/PlaceholderAPI/PlaceholderAPI/pulls
-[contributing file]: https://github.com/PlaceholderAPI/PlaceholderAPI/tree/master/.github/CONTRIBUTING.md
[Wiki]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki
diff --git a/.github/workflows/wiki.yml b/.github/workflows/wiki.yml
index 97be2c0..02864b8 100644
--- a/.github/workflows/wiki.yml
+++ b/.github/workflows/wiki.yml
@@ -10,43 +10,43 @@ on:
# Only trigger when the push changes any files in the wiki-folder.
#
paths:
- - 'wiki/**'
+ - 'wiki/**'
branches:
- - 'docs/wiki'
+ - 'docs/wiki'
#
# Releases cause this action to also fire.
# Using this prevents this problem.
#
tags-ignore:
- - '**'
+ - '**'
jobs:
update:
runs-on: ubuntu-latest
steps:
- - name: 'Checkout Code'
- uses: actions/Checkout@v2
- - name: 'Update Wiki'
- uses: docker://decathlon/wiki-page-creator-action:latest
- env:
- #
- # We can use the E-Mail and Name of the GitHub Actions account
- # for our convenience.
- #
- ACTION_MAIL: 'actions@github.com'
- ACTION_NAME: 'github-actions[bot]'
- #
- # We (sadly) have to use a PAT (Personal Access Token) for this action.
- #
- GH_PAT: '${{ secrets.WORKFLOWPAT }}'
- OWNER: 'PlaceholderAPI'
- REPO_NAME: 'PlaceholderAPI'
- #
- # We only want to target files in the wiki folder
- #
- MD_FOLDER: 'wiki'
- WIKI_PUSH_MESSAGE: '${{ github.event.commits[0].message }}'
- #
- # We skip/ignore the README.md file in the Wiki folder
- #
- SKIP_MD: README.md
+ - name: 'Checkout Code'
+ uses: actions/Checkout@v2
+ - name: 'Update Wiki'
+ uses: docker://decathlon/wiki-page-creator-action:latest
+ env:
+ #
+ # We can use the E-Mail and Name of the GitHub Actions account
+ # for our convenience.
+ #
+ ACTION_MAIL: 'actions@github.com'
+ ACTION_NAME: 'github-actions[bot]'
+ #
+ # We (sadly) have to use a PAT (Personal Access Token) for this action.
+ #
+ GH_PAT: '${{ secrets.WORKFLOWPAT }}'
+ OWNER: 'PlaceholderAPI'
+ REPO_NAME: 'PlaceholderAPI'
+ #
+ # We only want to target files in the wiki folder
+ #
+ MD_FOLDER: 'wiki'
+ WIKI_PUSH_MESSAGE: '${{ github.event.commits[0].message }}'
+ #
+ # We skip/ignore the README.md file in the Wiki folder
+ #
+ SKIP_MD: README.md
diff --git a/README.md b/README.md
index 1ee5df0..7711ae7 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
[ci]: http://ci.extendedclip.com/job/PlaceholderAPI/
[ciImg]: http://ci.extendedclip.com/buildStatus/icon?job=PlaceholderAPI
-[APIversionImg]: https://img.shields.io/nexus/r/http/repo.extendedclip.com/me.clip/placeholderapi.svg?label=API-Version
+[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
@@ -27,7 +27,7 @@
Support for specific plugins are provided either by the plugin itself or through expansions. The expansions may be downloaded in-game through the PAPI Expansion Cloud. There are currently over 150+ expansions that support a wide variety of plugins, such as Essentials, Factions, LuckPerms, and Vault.
-PlaceholderAPI has been downloaded over 300,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.
+PlaceholderAPI has been downloaded over 400,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.
diff --git a/build.gradle b/build.gradle
index 55dcf7a..bda91d8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,105 +1,119 @@
plugins {
- id "java"
- id "maven-publish"
- id "net.minecrell.licenser" version "0.4.1"
- id "com.github.johnrengelman.shadow" version "6.0.0"
+ id "java"
+ id "maven-publish"
+ id "net.minecrell.licenser" version "0.4.1"
+ id "com.github.johnrengelman.shadow" version "6.0.0"
}
group "me.clip"
-version "2.10.8-DEV-${System.getProperty("BUILD_NUMBER")}"
+version "2.10.10-DEV-${System.getProperty("BUILD_NUMBER")}"
description "An awesome placeholder provider!"
repositories {
- mavenCentral()
+ mavenCentral()
- maven({ url = "https://repo.codemc.org/repository/maven-public" })
- maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" })
+ maven({ url = "https://repo.codemc.org/repository/maven-public" })
+ maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" })
}
dependencies {
- implementation "com.google.code.gson:gson:2.8.6"
- implementation "org.bstats:bstats-bukkit:1.5"
-
- compileOnly "org.spigotmc:spigot-api:1.16.1-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"
+ implementation "com.google.code.gson:gson:2.8.6"
+ implementation "org.bstats:bstats-bukkit:1.5"
+
+ compileOnly "org.spigotmc:spigot-api:1.16.1-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"
}
processResources {
- from(sourceSets.main.resources.srcDirs) {
- filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [name: rootProject.name, version: project.version.toString(), description: project.description]
- }
+ from(sourceSets.main.resources.srcDirs) {
+ filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [name: rootProject.name, version: project.version.toString(), description: project.description]
+ }
}
tasks.withType(JavaCompile) {
- options.encoding = "UTF-8"
-
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
+ options.encoding = "UTF-8"
+
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
}
shadowJar {
- archiveClassifier.set("")
+ archiveClassifier.set("")
- relocate "org.bstats", "me.clip.placeholderapi.metrics"
- relocate "com.google.gson", "me.clip.placeholderapi.libs.gson"
+ relocate "org.bstats", "me.clip.placeholderapi.metrics"
+ relocate "com.google.gson", "me.clip.placeholderapi.libs.gson"
}
license {
- matching('**/*.java') {
- header = file('headers/main.txt')
- }
+ include '**/*.java'
- matching('**/JSONMessage.java') {
- header = file('headers/jsonmessage.txt')
- }
+ matching('**/*.java') {
+ header = file('config/headers/main.txt')
+ }
- ext {
- year = 2020
- }
+ matching('**/JSONMessage.java') {
+ header = file('config/headers/jsonmessage.txt')
+ }
+
+ ext {
+ year = 2020
+ }
}
test {
- useJUnitPlatform()
+ useJUnitPlatform()
}
sourceSets {
- test.compileClasspath += configurations.compileOnly
- test.runtimeClasspath += configurations.compileOnly
+ test.compileClasspath += configurations.compileOnly
+ test.runtimeClasspath += configurations.compileOnly
}
publishing {
- repositories {
- maven {
- if (version.contains("-DEV-")) {
- url = uri("https://repo.extendedclip.com/content/repositories/dev/")
- } else {
- url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")
- }
-
- credentials {
- username = System.getenv("JENKINS_USER")
- password = System.getenv("JENKINS_PASS")
- }
- }
- }
-
- publications {
- mavenJava(MavenPublication) {
- from components.java
+ repositories {
+ maven {
+ if (version.contains("-DEV-")) {
+ url = uri("https://repo.extendedclip.com/content/repositories/dev/")
+ } else {
+ url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")
+ }
- pom.withXml {
- asNode().appendNode("packaging", "jar")
- asNode().remove(asNode().get("dependencies"))
- }
- }
- }
+ credentials {
+ username = System.getenv("JENKINS_USER")
+ password = System.getenv("JENKINS_PASS")
+ }
+ }
+ }
+
+ publications {
+ mavenJava(MavenPublication) {
+ artifactId = "placeholderapi"
+
+ from components.java
+
+ pom.withXml {
+
+ // some are having issues with bstats so we might need to add that to the pom as well
+
+ asNode().appendNode("packaging", "jar")
+ asNode().remove(asNode().get("dependencies"))
+
+ def dependenciesNode = asNode().appendNode("dependencies")
+ // jetbrains annotations
+ def jetbrainsAnnotations = dependenciesNode.appendNode("dependency")
+ jetbrainsAnnotations.appendNode("groupId", "org.jetbrains")
+ jetbrainsAnnotations.appendNode("artifactId", "annotations")
+ jetbrainsAnnotations.appendNode("version", "19.0.0")
+ }
+ }
+ }
}
publish.dependsOn clean, test, jar
\ No newline at end of file
diff --git a/headers/jsonmessage.txt b/config/headers/jsonmessage.txt
similarity index 100%
rename from headers/jsonmessage.txt
rename to config/headers/jsonmessage.txt
diff --git a/headers/main.txt b/config/headers/main.txt
similarity index 100%
rename from headers/main.txt
rename to config/headers/main.txt
diff --git a/config/style/daddystyle.xml b/config/style/daddystyle.xml
new file mode 100644
index 0000000..378d25e
--- /dev/null
+++ b/config/style/daddystyle.xml
@@ -0,0 +1,569 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:.*Style
+
+ http://schemas.android.com/apk/res/android
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:layout_width
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_height
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_weight
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_margin
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_marginTop
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_marginBottom
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_marginStart
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_marginEnd
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_marginLeft
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_marginRight
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_.*
+
+ http://schemas.android.com/apk/res/android
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:padding
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:paddingTop
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:paddingBottom
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:paddingStart
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:paddingEnd
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:paddingLeft
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:paddingRight
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*
+ http://schemas.android.com/apk/res/android
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+ http://schemas.android.com/apk/res-auto
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+ http://schemas.android.com/tools
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 76ba08b..c4faa33 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1 @@
-rootProject.name = 'placeholderapi'
+rootProject.name = 'PlaceholderAPI'
diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPI.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPI.java
index 1d57c37..ea29cfe 100644
--- a/src/main/java/me/clip/placeholderapi/PlaceholderAPI.java
+++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPI.java
@@ -22,6 +22,7 @@ package me.clip.placeholderapi;
import com.google.common.collect.ImmutableSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -37,7 +38,6 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
public final class PlaceholderAPI {
@@ -64,7 +64,7 @@ public final class PlaceholderAPI {
* @return String containing all translated placeholders
*/
@NotNull
- public static String setPlaceholders(@Nullable final OfflinePlayer player,
+ public static String setPlaceholders(final OfflinePlayer player,
@NotNull final String text) {
return REPLACER_PERCENT.apply(text, player,
PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion);
@@ -79,11 +79,37 @@ public final class PlaceholderAPI {
* @return String containing all translated placeholders
*/
@NotNull
- public static List setPlaceholders(@Nullable final OfflinePlayer player,
+ public static List setPlaceholders(final OfflinePlayer player,
@NotNull final List<@NotNull String> text) {
return text.stream().map(line -> setPlaceholders(player, line)).collect(Collectors.toList());
}
+ /**
+ * Translates all placeholders into their corresponding values.
+ * The pattern of a valid placeholder is {@literal %_%}.
+ *
+ * @param player Player to parse the placeholders against
+ * @param text Text to set the placeholder values in
+ * @return String containing all translated placeholders
+ */
+ @NotNull
+ public static String setPlaceholders(final Player player, @NotNull String text) {
+ return setPlaceholders(((OfflinePlayer) player), text);
+ }
+
+ /**
+ * Translates all placeholders into their corresponding values.
+ * The pattern of a valid placeholder is {@literal %_%}.
+ *
+ * @param player Player to parse the placeholders against
+ * @param text List of Strings to set the placeholder values in
+ * @return String containing all translated placeholders
+ */
+ @NotNull
+ public static List setPlaceholders(final Player player, @NotNull List<@NotNull String> text) {
+ return setPlaceholders(((OfflinePlayer) player), text);
+ }
+
/**
* Translates all placeholders into their corresponding values.
* The pattern of a valid placeholder is {@literal {_}}.
@@ -93,7 +119,7 @@ public final class PlaceholderAPI {
* @return String containing all translated placeholders
*/
@NotNull
- public static String setBracketPlaceholders(@Nullable final OfflinePlayer player,
+ public static String setBracketPlaceholders(final OfflinePlayer player,
@NotNull final String text) {
return REPLACER_BRACKET.apply(text, player,
PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion);
@@ -108,12 +134,72 @@ public final class PlaceholderAPI {
* @return String containing all translated placeholders
*/
@NotNull
- public static List setBracketPlaceholders(@Nullable final OfflinePlayer player,
+ public static List setBracketPlaceholders(final OfflinePlayer player,
@NotNull final List<@NotNull String> text) {
return text.stream().map(line -> setBracketPlaceholders(player, line))
.collect(Collectors.toList());
}
+ public static String setBracketPlaceholders(Player player, String text) {
+ return setBracketPlaceholders((OfflinePlayer) player, text);
+ }
+
+ public static List setBracketPlaceholders(Player player, List text) {
+ return setPlaceholders((OfflinePlayer) player, text);
+ }
+
+ /**
+ * set relational placeholders in the text specified placeholders are matched with the pattern
+ * %% when set with this method
+ *
+ * @param one First player to compare
+ * @param two Second player to compare
+ * @param text Text to parse the placeholders in
+ * @return The text containing the parsed relational placeholders
+ */
+ public static String setRelationalPlaceholders(Player one, Player two, String text) {
+ final Matcher matcher = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
+
+ while (matcher.find()) {
+ final String format = matcher.group(2);
+ final int index = format.indexOf("_");
+
+ if (index <= 0 || index >= format.length()) {
+ continue;
+ }
+
+ String identifier = format.substring(0, index).toLowerCase();
+ String params = format.substring(index + 1);
+ final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance()
+ .getLocalExpansionManager().getExpansion(identifier);
+
+ if (!(expansion instanceof Relational)) {
+ continue;
+ }
+
+ final String value = ((Relational) expansion).onPlaceholderRequest(one, two, params);
+
+ if (value != null) {
+ text = text.replaceAll(Pattern.quote(matcher.group()), Matcher.quoteReplacement(value));
+ }
+ }
+
+ return Msg.color(text);
+ }
+
+ /**
+ * Translate placeholders in the provided List based on the relation of the two provided players.
+ * The pattern of a valid placeholder is {@literal %rel__ %}.
+ *
+ * @param one Player to compare
+ * @param two Player to compare
+ * @param text text to parse the placeholder values to
+ * @return The text containing the parsed relational placeholders
+ */
+ public static List setRelationalPlaceholders(Player one, Player two, List text) {
+ return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
+ .collect(Collectors.toList());
+ }
/**
* Check if a specific placeholder identifier is currently registered
@@ -126,7 +212,6 @@ public final class PlaceholderAPI {
.findExpansionByIdentifier(identifier).isPresent();
}
-
/**
* Get all registered placeholder identifiers
*
@@ -183,111 +268,33 @@ public final class PlaceholderAPI {
// === Deprecated API ===
- /**
- * set relational placeholders in the text specified placeholders are matched with the pattern
- * %% when set with this method
- *
- * @param one First player to compare
- * @param two Second player to compare
- * @param text Text to parse the placeholders in
- * @return The text containing the parsed relational placeholders
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
- */
@Deprecated
- public static String setRelationalPlaceholders(Player one, Player two, String text) {
- return setRelationalPlaceholders(one, two, text, true);
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static boolean registerExpansion(PlaceholderExpansion expansion)
+ {
+ return expansion.register();
+ }
+
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static boolean unregisterExpansion(PlaceholderExpansion expansion)
+ {
+ return expansion.unregister();
}
/**
- * Translate placeholders in the provided List based on the relation of the two provided players.
- * The pattern of a valid placeholder is {@literal %rel__ %}.
+ * Get map of registered placeholders
*
- * @param one Player to compare
- * @param two Player to compare
- * @param text text to parse the placeholder values to
- * @return The text containing the parsed relational placeholders
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
- */
- @Deprecated
- public static List setRelationalPlaceholders(Player one, Player two, List text) {
- return setRelationalPlaceholders(one, two, text, true);
- }
-
- /**
- * Translate placeholders in the provided list based on the relation of the two provided players.
- * The pattern of a valid placeholder is {@literal %rel__%}.
- *
- * @param one First player to compare
- * @param two Second player to compare
- * @param text Text to parse the placeholders in
- * @param colorize If color codes (&[0-1a-fk-o]) should be translated
- * @return The text containing the parsed relational placeholders
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
+ * @return Map of registered placeholders
+ * @deprecated Use {@link me.clip.placeholderapi.PlaceholderAPIPlugin().getLocalExpansionManager()
+ * .getExpansions()} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static List setRelationalPlaceholders(Player one, Player two, List text,
- boolean colorize) {
- if (text == null) {
- return null;
- }
-
- return text.stream()
- .map(line -> setRelationalPlaceholders(one, two, line, colorize))
- .collect(Collectors.toList());
- }
-
- /**
- * set relational placeholders in the text specified placeholders are matched with the pattern
- * %% when set with this method
- *
- * @param one Player to compare
- * @param two Player to compare
- * @param text Text to parse the placeholders in
- * @param colorize If color codes (&[0-1a-fk-o]) should be translated
- * @return The text containing the parsed relational placeholders
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
- */
- @Deprecated
- @SuppressWarnings("DuplicatedCode")
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static String setRelationalPlaceholders(Player one, Player two, String text,
- boolean colorize) {
- if (text == null) {
- return null;
- }
-
- if (PlaceholderAPIPlugin.getInstance().getLocalExpansionManager().getExpansionsCount() == 0) {
- return colorize ? Msg.color(text) : text;
- }
-
- final Matcher matcher = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
-
- while (matcher.find()) {
- final String format = matcher.group(2);
- final int index = format.indexOf("_");
-
- if (index <= 0 || index >= format.length()) {
- continue;
- }
-
- String identifier = format.substring(0, index).toLowerCase();
- String params = format.substring(index + 1);
- final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance()
- .getLocalExpansionManager().getExpansion(identifier);
-
- if (!(expansion instanceof Relational)) {
- continue;
- }
-
- final String value = ((Relational) expansion).onPlaceholderRequest(one, two, params);
-
- if (value != null) {
- text = text.replaceAll(Pattern.quote(matcher.group()), Matcher.quoteReplacement(value));
- }
- }
-
- return colorize ? Msg.color(text) : text;
+ public static Map getPlaceholders() {
+ return PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()
+ .getExpansions().stream()
+ .collect(Collectors.toMap(PlaceholderExpansion::getIdentifier, ex -> ex));
}
/**
@@ -317,7 +324,6 @@ public final class PlaceholderAPI {
return false;
}
-
/**
* @deprecated Please use {@link me.clip.placeholderapi.expansion.PlaceholderExpansion} to
* unregister placeholders instead
@@ -344,86 +350,6 @@ public final class PlaceholderAPI {
return false;
}
- /**
- * @deprecated Please use {@link #setPlaceholders(OfflinePlayer, String)} instead
- */
- @NotNull
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static String setPlaceholders(@Nullable final OfflinePlayer player,
- @NotNull final String text, @NotNull final Pattern pattern, final boolean colorize) {
- return setPlaceholders(player, text);
- }
-
- /**
- * @deprecated Please use {@link #setPlaceholders(OfflinePlayer, List)} instead
- */
- @NotNull
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static List setPlaceholders(@Nullable final OfflinePlayer player,
- @NotNull final List text, @NotNull final Pattern pattern, final boolean colorize) {
- return setPlaceholders(player, text);
- }
-
- /**
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
- */
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static List setBracketPlaceholders(OfflinePlayer player, List text,
- boolean colorize) {
- return setPlaceholders(player, text, BRACKET_PLACEHOLDER_PATTERN, colorize);
- }
-
- /**
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
- */
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static List setPlaceholders(OfflinePlayer player, List text,
- boolean colorize) {
- return setPlaceholders(player, text, PLACEHOLDER_PATTERN, colorize);
- }
-
- /**
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
- */
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static List setPlaceholders(OfflinePlayer player, List text,
- Pattern pattern) {
- return setPlaceholders(player, text, pattern, true);
- }
-
-
- /**
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
- */
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static String setBracketPlaceholders(OfflinePlayer player, String text, boolean colorize) {
- return setPlaceholders(player, text, BRACKET_PLACEHOLDER_PATTERN, colorize);
- }
-
- /**
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
- */
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static String setPlaceholders(OfflinePlayer player, String text, boolean colorize) {
- return setPlaceholders(player, text, PLACEHOLDER_PATTERN, colorize);
- }
-
- /**
- * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
- */
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static String setPlaceholders(OfflinePlayer player, String text, Pattern pattern) {
- return setPlaceholders(player, text, pattern, true);
- }
-
/**
* @deprecated Will be removed in a future release.
*/
@@ -443,30 +369,51 @@ public final class PlaceholderAPI {
}
/**
- * @deprecated Will be removed in a future release.
+ * @deprecated Please use {@link #setPlaceholders(OfflinePlayer, String)} instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static String setPlaceholders(Player player, String text) {
- return setPlaceholders(((OfflinePlayer) player), text);
+ public static String setPlaceholders(OfflinePlayer player,
+ String text, Pattern pattern, boolean colorize) {
+ return setPlaceholders(player, text);
}
+ /**
+ * @deprecated Please use {@link #setPlaceholders(OfflinePlayer, List)} instead
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static List setPlaceholders(OfflinePlayer player,
+ List text, Pattern pattern, boolean colorize) {
+ return setPlaceholders(player, text);
+ }
+
+ /**
+ * @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static List setPlaceholders(OfflinePlayer player, List text,
+ boolean colorize) {
+ return setPlaceholders(player, text);
+ }
+
+ /**
+ * @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static List setPlaceholders(OfflinePlayer player, List text,
+ Pattern pattern) {
+ return setPlaceholders(player, text);
+ }
/**
* @deprecated Will be removed in a future release.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
public static String setPlaceholders(Player player, String text, boolean colorize) {
- return setPlaceholders(player, text, PLACEHOLDER_PATTERN, colorize);
- }
-
- /**
- * @deprecated Will be removed in a future release.
- */
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static List setPlaceholders(Player player, List text) {
- return setPlaceholders(player, text, PLACEHOLDER_PATTERN, true);
+ return setPlaceholders(player, text);
}
/**
@@ -475,16 +422,44 @@ public final class PlaceholderAPI {
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
public static List setPlaceholders(Player player, List text, boolean colorize) {
- return setPlaceholders(player, text, PLACEHOLDER_PATTERN, colorize);
+ return setPlaceholders(player, text);
}
/**
- * @deprecated Will be removed in a future release.
+ * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static String setBracketPlaceholders(Player player, String text) {
- return setPlaceholders(player, text, BRACKET_PLACEHOLDER_PATTERN, true);
+ public static String setPlaceholders(OfflinePlayer player, String text, boolean colorize) {
+ return setPlaceholders(player, text);
+ }
+
+ /**
+ * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static String setPlaceholders(OfflinePlayer player, String text, Pattern pattern) {
+ return setPlaceholders(player, text);
+ }
+
+ /**
+ * @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static List setBracketPlaceholders(OfflinePlayer player, List text,
+ boolean colorize) {
+ return setBracketPlaceholders(player, text);
+ }
+
+ /**
+ * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static String setBracketPlaceholders(OfflinePlayer player, String text, boolean colorize) {
+ return setBracketPlaceholders(player, text);
}
/**
@@ -493,16 +468,7 @@ public final class PlaceholderAPI {
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
public static String setBracketPlaceholders(Player player, String text, boolean colorize) {
- return setPlaceholders(player, text, BRACKET_PLACEHOLDER_PATTERN, colorize);
- }
-
- /**
- * @deprecated Will be removed in a future release.
- */
- @Deprecated
- @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
- public static List setBracketPlaceholders(Player player, List text) {
- return setPlaceholders(player, text, BRACKET_PLACEHOLDER_PATTERN, true);
+ return setBracketPlaceholders(player, text);
}
/**
@@ -512,7 +478,42 @@ public final class PlaceholderAPI {
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
public static List setBracketPlaceholders(Player player, List text,
boolean colorize) {
- return setPlaceholders(player, text, BRACKET_PLACEHOLDER_PATTERN, colorize);
+ return setBracketPlaceholders(player, text);
}
+ /**
+ * set relational placeholders in the text specified placeholders are matched with the pattern
+ * %% when set with this method
+ *
+ * @param one Player to compare
+ * @param two Player to compare
+ * @param text Text to parse the placeholders in
+ * @param colorize If color codes (&[0-1a-fk-o]) should be translated
+ * @return The text containing the parsed relational placeholders
+ * @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static String setRelationalPlaceholders(Player one, Player two, String text,
+ boolean colorize) {
+ return setRelationalPlaceholders(one, two, text);
+ }
+
+ /**
+ * Translate placeholders in the provided list based on the relation of the two provided players.
+ * The pattern of a valid placeholder is {@literal %rel__%}.
+ *
+ * @param one First player to compare
+ * @param two Second player to compare
+ * @param text Text to parse the placeholders in
+ * @param colorize If color codes (&[0-1a-fk-o]) should be translated
+ * @return The text containing the parsed relational placeholders
+ * @deprecated Use {@link #setRelationalPlaceholders(Player, Player, List)} instead.
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
+ public static List setRelationalPlaceholders(Player one, Player two, List text,
+ boolean colorize) {
+ return setRelationalPlaceholders(one, two, text);
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java
index 32a2f74..fe07931 100644
--- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java
+++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java
@@ -20,6 +20,10 @@
package me.clip.placeholderapi;
+import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
import me.clip.placeholderapi.commands.PlaceholderCommandRouter;
import me.clip.placeholderapi.configuration.PlaceholderAPIConfig;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
@@ -36,243 +40,200 @@ import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
-import java.text.SimpleDateFormat;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-
/**
* Yes I have a shit load of work to do...
*
* @author Ryan McCarthy
*/
-public final class PlaceholderAPIPlugin extends JavaPlugin
-{
+public final class PlaceholderAPIPlugin extends JavaPlugin {
- @NotNull
- private static final Version VERSION;
+ @NotNull
+ private static final Version VERSION;
+ private static PlaceholderAPIPlugin instance;
- static
- {
- final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
+ static {
+ final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
- boolean isSpigot;
- try
- {
- Class.forName("org.spigotmc.SpigotConfig");
- isSpigot = true;
- }
- catch (final ExceptionInInitializerError | ClassNotFoundException ignored)
- {
- isSpigot = false;
- }
+ boolean isSpigot;
+ try {
+ Class.forName("org.spigotmc.SpigotConfig");
+ isSpigot = true;
+ } catch (final ExceptionInInitializerError | ClassNotFoundException ignored) {
+ isSpigot = false;
+ }
- VERSION = new Version(version, isSpigot);
- }
+ VERSION = new Version(version, isSpigot);
+ }
- private static PlaceholderAPIPlugin instance;
+ @NotNull
+ private final PlaceholderAPIConfig config = new PlaceholderAPIConfig(this);
- @NotNull
- private final PlaceholderAPIConfig config = new PlaceholderAPIConfig(this);
+ @NotNull
+ private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
+ @NotNull
+ private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
- @NotNull
- private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
- @NotNull
- private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
+ /**
+ * Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
+ * class, this is the main class that extends JavaPlugin. For most API methods, use static methods
+ * available from the class: {@link PlaceholderAPI}
+ *
+ * @return PlaceholderAPIPlugin instance
+ */
+ @NotNull
+ public static PlaceholderAPIPlugin getInstance() {
+ return instance;
+ }
+ /**
+ * Get the configurable {@linkplain String} value that should be returned when a boolean is true
+ *
+ * @return string value of true
+ */
+ @NotNull
+ public static String booleanTrue() {
+ return getInstance().getPlaceholderAPIConfig().booleanTrue();
+ }
- @Override
- public void onLoad()
- {
- instance = this;
+ /**
+ * Get the configurable {@linkplain String} value that should be returned when a boolean is false
+ *
+ * @return string value of false
+ */
+ @NotNull
+ public static String booleanFalse() {
+ return getInstance().getPlaceholderAPIConfig().booleanFalse();
+ }
- saveDefaultConfig();
- }
+ /**
+ * Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for
+ * generic time based placeholders
+ *
+ * @return date format
+ */
+ @NotNull
+ public static SimpleDateFormat getDateFormat() {
+ try {
+ return new SimpleDateFormat(getInstance().getPlaceholderAPIConfig().dateFormat());
+ } catch (final IllegalArgumentException ex) {
+ getInstance().getLogger().log(Level.WARNING, "configured date format is invalid", ex);
+ return new SimpleDateFormat("MM/dd/yy HH:mm:ss");
+ }
+ }
- @Override
- public void onEnable()
- {
- setupCommand();
- setupMetrics();
- setupExpansions();
+ public static Version getServerVersion() {
+ return VERSION;
+ }
- if (config.isCloudEnabled())
- {
- getCloudExpansionManager().load();
- }
+ @Override
+ public void onLoad() {
+ instance = this;
- if (config.checkUpdates())
- {
- new UpdateChecker(this).fetch();
- }
- }
+ saveDefaultConfig();
+ }
- @Override
- public void onDisable()
- {
- getCloudExpansionManager().kill();
- getLocalExpansionManager().kill();
+ @Override
+ public void onEnable() {
+ setupCommand();
+ setupMetrics();
+ setupExpansions();
- HandlerList.unregisterAll(this);
+ if (config.isCloudEnabled()) {
+ getCloudExpansionManager().load();
+ }
- Bukkit.getScheduler().cancelTasks(this);
+ if (config.checkUpdates()) {
+ new UpdateChecker(this).fetch();
+ }
+ }
- instance = null;
- }
+ @Override
+ public void onDisable() {
+ getCloudExpansionManager().kill();
+ getLocalExpansionManager().kill();
+ HandlerList.unregisterAll(this);
- public void reloadConf(@NotNull final CommandSender sender)
- {
- getLocalExpansionManager().kill();
+ Bukkit.getScheduler().cancelTasks(this);
- reloadConfig();
+ instance = null;
+ }
- getLocalExpansionManager().load(sender);
+ public void reloadConf(@NotNull final CommandSender sender) {
+ getLocalExpansionManager().kill();
- if (config.isCloudEnabled())
- {
- getCloudExpansionManager().load();
- }
- else
- {
- getCloudExpansionManager().kill();
- }
- }
+ reloadConfig();
+ getLocalExpansionManager().load(sender);
- @NotNull
- public LocalExpansionManager getLocalExpansionManager()
- {
- return localExpansionManager;
- }
+ if (config.isCloudEnabled()) {
+ getCloudExpansionManager().load();
+ } else {
+ getCloudExpansionManager().kill();
+ }
+ }
- @NotNull
- public CloudExpansionManager getCloudExpansionManager()
- {
- return cloudExpansionManager;
- }
+ @NotNull
+ public LocalExpansionManager getLocalExpansionManager() {
+ return localExpansionManager;
+ }
+ @NotNull
+ public CloudExpansionManager getCloudExpansionManager() {
+ return cloudExpansionManager;
+ }
- /**
- * Obtain the configuration class for PlaceholderAPI.
- *
- * @return PlaceholderAPIConfig instance
- */
- @NotNull
- public PlaceholderAPIConfig getPlaceholderAPIConfig()
- {
- return config;
- }
+ /**
+ * Obtain the configuration class for PlaceholderAPI.
+ *
+ * @return PlaceholderAPIConfig instance
+ */
+ @NotNull
+ public PlaceholderAPIConfig getPlaceholderAPIConfig() {
+ return config;
+ }
+ private void setupCommand() {
+ final PluginCommand pluginCommand = getCommand("placeholderapi");
+ if (pluginCommand == null) {
+ return;
+ }
- private void setupCommand()
- {
- final PluginCommand pluginCommand = getCommand("placeholderapi");
- if (pluginCommand == null)
- {
- return;
- }
+ final PlaceholderCommandRouter router = new PlaceholderCommandRouter(this);
+ pluginCommand.setExecutor(router);
+ pluginCommand.setTabCompleter(router);
+ }
- final PlaceholderCommandRouter router = new PlaceholderCommandRouter(this);
- pluginCommand.setExecutor(router);
- pluginCommand.setTabCompleter(router);
- }
+ private void setupMetrics() {
+ final Metrics metrics = new Metrics(this);
+ metrics.addCustomChart(new Metrics.SimplePie("using_expansion_cloud",
+ () -> getPlaceholderAPIConfig().isCloudEnabled() ? "yes" : "no"));
- private void setupMetrics()
- {
- final Metrics metrics = new Metrics(this);
- metrics.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", () -> getPlaceholderAPIConfig().isCloudEnabled() ? "yes" : "no"));
+ metrics.addCustomChart(
+ new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
- metrics.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
+ metrics.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
+ final Map values = new HashMap<>();
- metrics.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
- final Map values = new HashMap<>();
+ for (final PlaceholderExpansion expansion : getLocalExpansionManager().getExpansions()) {
+ values.put(expansion.getRequiredPlugin() == null ? expansion.getIdentifier()
+ : expansion.getRequiredPlugin(), 1);
+ }
- for (final PlaceholderExpansion expansion : getLocalExpansionManager().getExpansions())
- {
- values.put(expansion.getRequiredPlugin() == null ? expansion.getIdentifier() : expansion.getRequiredPlugin(), 1);
- }
+ return values;
+ }));
+ }
- return values;
- }));
- }
+ private void setupExpansions() {
+ Bukkit.getPluginManager().registerEvents(getLocalExpansionManager(), this);
- private void setupExpansions()
- {
- Bukkit.getPluginManager().registerEvents(getLocalExpansionManager(), this);
-
- try
- {
- Class.forName("org.bukkit.event.server.ServerLoadEvent");
- new ServerLoadEventListener(this);
- }
- catch (final ExceptionInInitializerError | ClassNotFoundException ignored)
- {
- Bukkit.getScheduler().runTaskLater(this, () -> getLocalExpansionManager().load(Bukkit.getConsoleSender()), 1);
- }
- }
-
-
- /**
- * Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
- * class, this is the main class that extends JavaPlugin. For most API methods, use static methods
- * available from the class: {@link PlaceholderAPI}
- *
- * @return PlaceholderAPIPlugin instance
- */
- @NotNull
- public static PlaceholderAPIPlugin getInstance()
- {
- return instance;
- }
-
-
- /**
- * Get the configurable {@linkplain String} value that should be returned when a boolean is true
- *
- * @return string value of true
- */
- @NotNull
- public static String booleanTrue()
- {
- return getInstance().getPlaceholderAPIConfig().booleanTrue();
- }
-
- /**
- * Get the configurable {@linkplain String} value that should be returned when a boolean is false
- *
- * @return string value of false
- */
- @NotNull
- public static String booleanFalse()
- {
- return getInstance().getPlaceholderAPIConfig().booleanFalse();
- }
-
- /**
- * Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for
- * generic time based placeholders
- *
- * @return date format
- */
- @NotNull
- public static SimpleDateFormat getDateFormat()
- {
- try
- {
- return new SimpleDateFormat(getInstance().getPlaceholderAPIConfig().dateFormat());
- }
- catch (final IllegalArgumentException ex)
- {
- getInstance().getLogger().log(Level.WARNING, "configured date format is invalid", ex);
- return new SimpleDateFormat("MM/dd/yy HH:mm:ss");
- }
- }
-
-
- public static Version getServerVersion()
- {
- return VERSION;
- }
+ try {
+ Class.forName("org.bukkit.event.server.ServerLoadEvent");
+ new ServerLoadEventListener(this);
+ } catch (final ExceptionInInitializerError | ClassNotFoundException ignored) {
+ Bukkit.getScheduler()
+ .runTaskLater(this, () -> getLocalExpansionManager().load(Bukkit.getConsoleSender()), 1);
+ }
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderHook.java b/src/main/java/me/clip/placeholderapi/PlaceholderHook.java
index 0b045a9..0087590 100644
--- a/src/main/java/me/clip/placeholderapi/PlaceholderHook.java
+++ b/src/main/java/me/clip/placeholderapi/PlaceholderHook.java
@@ -22,38 +22,19 @@ package me.clip.placeholderapi;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
-import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-/**
- * @deprecated This class will be completely removed in the next release, please use {@link me.clip.placeholderapi.expansion.PlaceholderExpansion}
- */
-@Deprecated
-@ApiStatus.NonExtendable
-@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
-public abstract class PlaceholderHook
-{
+public abstract class PlaceholderHook {
- @Nullable
- public String onRequest(@Nullable final OfflinePlayer player, @NotNull final String params)
- {
- if (player != null && player.isOnline())
- {
- return onPlaceholderRequest((Player) player, params);
- }
+ public String onRequest(final OfflinePlayer player, @NotNull final String params) {
+ if (player != null && player.isOnline()) {
+ return onPlaceholderRequest((Player) player, params);
+ }
- return onPlaceholderRequest(null, params);
- }
-
- /**
- * @deprecated This method will be completely removed, please use {@link me.clip.placeholderapi.expansion.PlaceholderExpansion#onRequest(OfflinePlayer, String)}
- */
- @Nullable
- @Deprecated
- public String onPlaceholderRequest(@Nullable final Player player, @NotNull final String params)
- {
- return null;
- }
+ return onPlaceholderRequest(null, params);
+ }
+ public String onPlaceholderRequest(final Player player, @NotNull final String params) {
+ return null;
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommand.java b/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommand.java
index 6497824..016a37c 100644
--- a/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommand.java
+++ b/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommand.java
@@ -22,97 +22,86 @@ package me.clip.placeholderapi.commands;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Stream;
+public abstract class PlaceholderCommand {
-public abstract class PlaceholderCommand
-{
+ @NotNull
+ private final String label;
+ @NotNull
+ private final Set alias;
- @NotNull
- private final String label;
- @NotNull
- private final Set alias;
-
- @Nullable
- private String permission;
+ @Nullable
+ private String permission;
- protected PlaceholderCommand(@NotNull final String label, @NotNull final String... alias)
- {
- this.label = label;
- this.alias = Sets.newHashSet(alias);
+ protected PlaceholderCommand(@NotNull final String label, @NotNull final String... alias) {
+ this.label = label;
+ this.alias = Sets.newHashSet(alias);
- setPermission("placeholderapi." + label);
- }
+ setPermission("placeholderapi." + label);
+ }
+ @NotNull
+ public static Stream filterByPermission(@NotNull final CommandSender sender,
+ @NotNull final Stream commands) {
+ return commands.filter(
+ target -> target.getPermission() == null || sender.hasPermission(target.getPermission()));
+ }
- @NotNull
- public final String getLabel()
- {
- return label;
- }
+ public static void suggestByParameter(@NotNull final Stream possible,
+ @NotNull final List suggestions, @Nullable final String parameter) {
+ if (parameter == null) {
+ possible.forEach(suggestions::add);
+ } else {
+ possible.filter(suggestion -> suggestion.toLowerCase().startsWith(parameter.toLowerCase()))
+ .forEach(suggestions::add);
+ }
+ }
- @NotNull
- @Unmodifiable
- public final Set getAlias()
- {
- return ImmutableSet.copyOf(alias);
- }
+ @NotNull
+ public final String getLabel() {
+ return label;
+ }
- @NotNull
- @Unmodifiable
- public final Set getLabels()
- {
- return ImmutableSet.builder().add(label).addAll(alias).build();
- }
+ @NotNull
+ @Unmodifiable
+ public final Set getAlias() {
+ return ImmutableSet.copyOf(alias);
+ }
+ @NotNull
+ @Unmodifiable
+ public final Set getLabels() {
+ return ImmutableSet.builder().add(label).addAll(alias).build();
+ }
- @Nullable
- public final String getPermission()
- {
- return permission;
- }
+ @Nullable
+ public final String getPermission() {
+ return permission;
+ }
- public void setPermission(@NotNull final String permission)
- {
- this.permission = permission;
- }
+ public void setPermission(@NotNull final String permission) {
+ this.permission = permission;
+ }
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
+ }
- }
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
-
- }
-
-
- @NotNull
- public static Stream filterByPermission(@NotNull final CommandSender sender, @NotNull final Stream commands)
- {
- return commands.filter(target -> target.getPermission() == null || sender.hasPermission(target.getPermission()));
- }
-
- public static void suggestByParameter(@NotNull final Stream possible, @NotNull final List suggestions, @Nullable final String parameter)
- {
- if (parameter == null)
- {
- possible.forEach(suggestions::add);
- }
- else
- {
- possible.filter(suggestion -> suggestion.toLowerCase().startsWith(parameter.toLowerCase())).forEach(suggestions::add);
- }
- }
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommandRouter.java b/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommandRouter.java
index 8e0e26f..3c32314 100644
--- a/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommandRouter.java
+++ b/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommandRouter.java
@@ -22,6 +22,13 @@ package me.clip.placeholderapi.commands;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.impl.cloud.CommandECloud;
import me.clip.placeholderapi.commands.impl.local.CommandDump;
@@ -41,103 +48,95 @@ import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.*;
-import java.util.stream.Stream;
+public final class PlaceholderCommandRouter implements CommandExecutor, TabCompleter {
-public final class PlaceholderCommandRouter implements CommandExecutor, TabCompleter
-{
-
- @Unmodifiable
- private static final List COMMANDS = ImmutableList.of(new CommandHelp(),
- new CommandInfo(),
- new CommandList(),
- new CommandDump(),
- new CommandECloud(),
- new CommandParse(),
- new CommandReload(),
- new CommandVersion(),
- new CommandExpansionRegister(),
- new CommandExpansionUnregister());
+ @Unmodifiable
+ private static final List COMMANDS = ImmutableList.of(new CommandHelp(),
+ new CommandInfo(),
+ new CommandList(),
+ new CommandDump(),
+ new CommandECloud(),
+ new CommandParse(),
+ new CommandReload(),
+ new CommandVersion(),
+ new CommandExpansionRegister(),
+ new CommandExpansionUnregister());
- @NotNull
- private final PlaceholderAPIPlugin plugin;
- @NotNull
- @Unmodifiable
- private final Map commands;
+ @NotNull
+ private final PlaceholderAPIPlugin plugin;
+ @NotNull
+ @Unmodifiable
+ private final Map commands;
- public PlaceholderCommandRouter(@NotNull final PlaceholderAPIPlugin plugin)
- {
- this.plugin = plugin;
+ public PlaceholderCommandRouter(@NotNull final PlaceholderAPIPlugin plugin) {
+ this.plugin = plugin;
- final ImmutableMap.Builder commands = ImmutableMap.builder();
+ final ImmutableMap.Builder commands = ImmutableMap.builder();
- for (final PlaceholderCommand command : COMMANDS)
- {
- command.getLabels().forEach(label -> commands.put(label, command));
- }
+ for (final PlaceholderCommand command : COMMANDS) {
+ command.getLabels().forEach(label -> commands.put(label, command));
+ }
- this.commands = commands.build();
- }
+ this.commands = commands.build();
+ }
- @Override
- public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Command command, @NotNull final String alias, @NotNull final String[] args)
- {
- if (args.length == 0)
- {
- final PlaceholderCommand fallback = commands.get("version");
- if (fallback != null)
- {
- fallback.evaluate(plugin, sender, "", Collections.emptyList());
- }
+ @Override
+ public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Command command,
+ @NotNull final String alias, @NotNull final String[] args) {
+ if (args.length == 0) {
+ final PlaceholderCommand fallback = commands.get("version");
+ if (fallback != null) {
+ fallback.evaluate(plugin, sender, "", Collections.emptyList());
+ }
- return true;
- }
+ return true;
+ }
- final String search = args[0].toLowerCase();
- final PlaceholderCommand target = commands.get(search);
+ final String search = args[0].toLowerCase();
+ final PlaceholderCommand target = commands.get(search);
- if (target == null)
- {
- Msg.msg(sender, "&cUnknown command &7" + search);
- return true;
- }
+ if (target == null) {
+ Msg.msg(sender, "&cUnknown command &7" + search);
+ return true;
+ }
- final String permission = target.getPermission();
- if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission))
- {
- Msg.msg(sender, "&cYou do not have permission to do this!");
- return true;
- }
+ final String permission = target.getPermission();
+ if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) {
+ Msg.msg(sender, "&cYou do not have permission to do this!");
+ return true;
+ }
- target.evaluate(plugin, sender, search, Arrays.asList(Arrays.copyOfRange(args, 1, args.length)));
+ target
+ .evaluate(plugin, sender, search, Arrays.asList(Arrays.copyOfRange(args, 1, args.length)));
- return true;
- }
+ return true;
+ }
- @Override
- public List onTabComplete(@NotNull final CommandSender sender, @NotNull final Command command, @NotNull final String alias, @NotNull final String[] args)
- {
- final List suggestions = new ArrayList<>();
+ @Override
+ public List onTabComplete(@NotNull final CommandSender sender,
+ @NotNull final Command command, @NotNull final String alias, @NotNull final String[] args) {
+ final List suggestions = new ArrayList<>();
- if (args.length > 1)
- {
- final PlaceholderCommand target = this.commands.get(args[0].toLowerCase());
+ if (args.length > 1) {
+ final PlaceholderCommand target = this.commands.get(args[0].toLowerCase());
- if (target != null)
- {
- target.complete(plugin, sender, args[0].toLowerCase(), Arrays.asList(Arrays.copyOfRange(args, 1, args.length)), suggestions);
- }
+ if (target != null) {
+ target.complete(plugin, sender, args[0].toLowerCase(),
+ Arrays.asList(Arrays.copyOfRange(args, 1, args.length)), suggestions);
+ }
- return suggestions;
- }
+ return suggestions;
+ }
- final Stream targets = PlaceholderCommand.filterByPermission(sender, commands.values().stream()).map(PlaceholderCommand::getLabels).flatMap(Collection::stream);
- PlaceholderCommand.suggestByParameter(targets, suggestions, args.length == 0 ? null : args[0]);
+ final Stream targets = PlaceholderCommand
+ .filterByPermission(sender, commands.values().stream()).map(PlaceholderCommand::getLabels)
+ .flatMap(Collection::stream);
+ PlaceholderCommand.suggestByParameter(targets, suggestions, args.length == 0 ? null : args[0]);
- return suggestions;
- }
+ return suggestions;
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloud.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloud.java
index 347f9ba..7a89a34 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloud.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloud.java
@@ -22,6 +22,10 @@ package me.clip.placeholderapi.commands.impl.cloud;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -29,126 +33,117 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Stream;
+public final class CommandECloud extends PlaceholderCommand {
-public final class CommandECloud extends PlaceholderCommand
-{
+ @Unmodifiable
+ private static final List COMMANDS = ImmutableList
+ .of(new CommandECloudClear(),
+ new CommandECloudToggle(),
+ new CommandECloudStatus(),
+ new CommandECloudUpdate(),
+ new CommandECloudRefresh(),
+ new CommandECloudDownload(),
+ new CommandECloudExpansionInfo(),
+ new CommandECloudExpansionList(),
+ new CommandECloudExpansionPlaceholders());
- @Unmodifiable
- private static final List COMMANDS = ImmutableList.of(new CommandECloudClear(),
- new CommandECloudToggle(),
- new CommandECloudStatus(),
- new CommandECloudUpdate(),
- new CommandECloudRefresh(),
- new CommandECloudDownload(),
- new CommandECloudExpansionInfo(),
- new CommandECloudExpansionList(),
- new CommandECloudExpansionPlaceholders());
+ static {
+ COMMANDS
+ .forEach(command -> command.setPermission("placeholderapi.ecloud." + command.getLabel()));
+ }
- static
- {
- COMMANDS.forEach(command -> command.setPermission("placeholderapi.ecloud." + command.getLabel()));
- }
-
- @NotNull
- @Unmodifiable
- private final Map commands;
+ @NotNull
+ @Unmodifiable
+ private final Map commands;
- public CommandECloud()
- {
- super("ecloud");
+ public CommandECloud() {
+ super("ecloud");
- final ImmutableMap.Builder commands = ImmutableMap.builder();
+ final ImmutableMap.Builder commands = ImmutableMap.builder();
- for (final PlaceholderCommand command : COMMANDS)
- {
- command.getLabels().forEach(label -> commands.put(label, command));
- }
+ for (final PlaceholderCommand command : COMMANDS) {
+ command.getLabels().forEach(label -> commands.put(label, command));
+ }
- this.commands = commands.build();
- }
+ this.commands = commands.build();
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- if (params.isEmpty())
- {
- Msg.msg(sender,
- "&b&lPlaceholderAPI &8- &7eCloud Help Menu &8- ",
- " ",
- "&b/papi &fenable/disable/toggle",
- " &7&oEnable or disable the eCloud",
- "&b/papi &fecloud status",
- " &7&oView status of the eCloud",
- "&b/papi &fecloud list {page}",
- " &7&oList all/author specific available expansions",
- "&b/papi &fecloud info {version}",
- " &7&oView information about a specific expansion available on the eCloud",
- "&b/papi &fecloud placeholders ",
- " &7&oView placeholders for an expansion",
- "&b/papi &fecloud download {version}",
- " &7&oDownload an expansion from the eCloud",
- "&b/papi &fecloud update ",
- " &7&oUpdate a specific/all installed expansions",
- "&b/papi &fecloud refresh",
- " &7&oFetch the most up to date list of expansions available.",
- "&b/papi &fecloud clear",
- " &7&oClear the expansion cloud cache.");
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ if (params.isEmpty()) {
+ Msg.msg(sender,
+ "&b&lPlaceholderAPI &8- &7eCloud Help Menu &8- ",
+ " ",
+ "&b/papi &fenable/disable/toggle",
+ " &7&oEnable or disable the eCloud",
+ "&b/papi &fecloud status",
+ " &7&oView status of the eCloud",
+ "&b/papi &fecloud list {page}",
+ " &7&oList all/author specific available expansions",
+ "&b/papi &fecloud info {version}",
+ " &7&oView information about a specific expansion available on the eCloud",
+ "&b/papi &fecloud placeholders ",
+ " &7&oView placeholders for an expansion",
+ "&b/papi &fecloud download {version}",
+ " &7&oDownload an expansion from the eCloud",
+ "&b/papi &fecloud update ",
+ " &7&oUpdate a specific/all installed expansions",
+ "&b/papi &fecloud refresh",
+ " &7&oFetch the most up to date list of expansions available.",
+ "&b/papi &fecloud clear",
+ " &7&oClear the expansion cloud cache.");
- return;
- }
+ return;
+ }
- final String search = params.get(0).toLowerCase();
- final PlaceholderCommand target = commands.get(search);
+ final String search = params.get(0).toLowerCase();
+ final PlaceholderCommand target = commands.get(search);
- if (target == null)
- {
- Msg.msg(sender, "&cUnknown command &7ecloud " + search);
- return;
- }
+ if (target == null) {
+ Msg.msg(sender, "&cUnknown command &7ecloud " + search);
+ return;
+ }
- final String permission = target.getPermission();
- if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission))
- {
- Msg.msg(sender, "&cYou do not have permission to do this!");
- return;
- }
+ final String permission = target.getPermission();
+ if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) {
+ Msg.msg(sender, "&cYou do not have permission to do this!");
+ return;
+ }
- if (!(target instanceof CommandECloudToggle) && !plugin.getPlaceholderAPIConfig().isCloudEnabled())
- {
- Msg.msg(sender,
- "&cThe eCloud Manager is not enabled!");
- return;
- }
+ if (!(target instanceof CommandECloudToggle) && !plugin.getPlaceholderAPIConfig()
+ .isCloudEnabled()) {
+ Msg.msg(sender,
+ "&cThe eCloud Manager is not enabled!");
+ return;
+ }
- target.evaluate(plugin, sender, search, params.subList(1, params.size()));
- }
+ target.evaluate(plugin, sender, search, params.subList(1, params.size()));
+ }
- @Override
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
- if (params.size() <= 1)
- {
- final Stream targets = filterByPermission(sender, commands.values().stream()).map(PlaceholderCommand::getLabels).flatMap(Collection::stream);
- suggestByParameter(targets, suggestions, params.isEmpty() ? null : params.get(0));
+ @Override
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
+ if (params.size() <= 1) {
+ final Stream targets = filterByPermission(sender, commands.values().stream())
+ .map(PlaceholderCommand::getLabels).flatMap(Collection::stream);
+ suggestByParameter(targets, suggestions, params.isEmpty() ? null : params.get(0));
- return; // send sub commands
- }
+ return; // send sub commands
+ }
- final String search = params.get(0).toLowerCase();
- final PlaceholderCommand target = commands.get(search);
+ final String search = params.get(0).toLowerCase();
+ final PlaceholderCommand target = commands.get(search);
- if (target == null)
- {
- return;
- }
+ if (target == null) {
+ return;
+ }
- target.complete(plugin, sender, search, params.subList(1, params.size()), suggestions);
- }
+ target.complete(plugin, sender, search, params.subList(1, params.size()), suggestions);
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudClear.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudClear.java
index a87ce91..251ae43 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudClear.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudClear.java
@@ -20,6 +20,7 @@
package me.clip.placeholderapi.commands.impl.cloud;
+import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -27,22 +28,19 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
+public final class CommandECloudClear extends PlaceholderCommand {
-public final class CommandECloudClear extends PlaceholderCommand
-{
+ public CommandECloudClear() {
+ super("clear");
+ }
- public CommandECloudClear()
- {
- super("clear");
- }
-
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- plugin.getCloudExpansionManager().clean();
- Msg.msg(sender,
- "&aThe eCloud cache has been cleared!");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ plugin.getCloudExpansionManager().clean();
+ Msg.msg(sender,
+ "&aThe eCloud cache has been cleared!");
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudDownload.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudDownload.java
index 543a72a..7bbb872 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudDownload.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudDownload.java
@@ -20,6 +20,9 @@
package me.clip.placeholderapi.commands.impl.cloud;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
@@ -28,98 +31,89 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Stream;
+public final class CommandECloudDownload extends PlaceholderCommand {
-public final class CommandECloudDownload extends PlaceholderCommand
-{
+ public CommandECloudDownload() {
+ super("download");
+ }
- public CommandECloudDownload()
- {
- super("download");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ if (params.isEmpty()) {
+ Msg.msg(sender,
+ "&cYou must supply the name of an expansion.");
+ return;
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- if (params.isEmpty())
- {
- Msg.msg(sender,
- "&cYou must supply the name of an expansion.");
- return;
- }
+ final CloudExpansion expansion = plugin.getCloudExpansionManager()
+ .findCloudExpansionByName(params.get(0)).orElse(null);
+ if (expansion == null) {
+ Msg.msg(sender,
+ "&cFailed to find an expansion named: &f" + params.get(0));
+ return;
+ }
- final CloudExpansion expansion = plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0)).orElse(null);
- if (expansion == null)
- {
- Msg.msg(sender,
- "&cFailed to find an expansion named: &f" + params.get(0));
- return;
- }
+ final CloudExpansion.Version version;
+ if (params.size() < 2) {
+ version = expansion.getVersion(expansion.getLatestVersion());
+ if (version == null) {
+ Msg.msg(sender,
+ "&cCould not find latest version for expansion.");
+ return;
+ }
+ } else {
+ version = expansion.getVersion(params.get(1));
+ if (version == null) {
+ Msg.msg(sender,
+ "&cCould not find specified version: &f" + params.get(1),
+ "&7Available versions: &f" + expansion.getAvailableVersions());
+ return;
+ }
+ }
- final CloudExpansion.Version version;
- if (params.size() < 2)
- {
- version = expansion.getVersion(expansion.getLatestVersion());
- if (version == null)
- {
- Msg.msg(sender,
- "&cCould not find latest version for expansion.");
- return;
- }
- }
- else
- {
- version = expansion.getVersion(params.get(1));
- if (version == null)
- {
- Msg.msg(sender,
- "&cCould not find specified version: &f" + params.get(1),
- "&7Available versions: &f" + expansion.getAvailableVersions());
- return;
- }
- }
+ plugin.getCloudExpansionManager().downloadExpansion(expansion, version)
+ .whenComplete((file, exception) -> {
+ if (exception != null) {
+ Msg.msg(sender,
+ "&cFailed to download expansion: &f" + exception.getMessage());
+ return;
+ }
- plugin.getCloudExpansionManager().downloadExpansion(expansion, version).whenComplete((file, exception) -> {
- if (exception != null)
- {
- Msg.msg(sender,
- "&cFailed to download expansion: &f" + exception.getMessage());
- return;
- }
+ Msg.msg(sender,
+ "&aSuccessfully downloaded expansion &f" + expansion.getName() + " [" + version
+ .getVersion() + "] &ato file: &f" + file.getName(),
+ "&aMake sure to type &f/papi reload &ato enable your new expansion!");
- Msg.msg(sender,
- "&aSuccessfully downloaded expansion &f" + expansion.getName() + " [" + version.getVersion() + "] &ato file: &f" + file.getName(),
- "&aMake sure to type &f/papi reload &ato enable your new expansion!");
+ plugin.getCloudExpansionManager().clean();
+ plugin.getCloudExpansionManager()
+ .fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
+ });
+ }
- plugin.getCloudExpansionManager().clean();
- plugin.getCloudExpansionManager().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
- });
- }
+ @Override
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
+ if (params.size() > 2) {
+ return;
+ }
- @Override
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
- if (params.size() > 2)
- {
- return;
- }
+ if (params.size() <= 1) {
+ final Stream names = plugin.getCloudExpansionManager().getCloudExpansions().values()
+ .stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
+ suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
+ return;
+ }
- if (params.size() <= 1)
- {
- final Stream names = plugin.getCloudExpansionManager().getCloudExpansions().values().stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
- suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
- return;
- }
+ final Optional expansion = plugin.getCloudExpansionManager()
+ .findCloudExpansionByName(params.get(0));
+ if (!expansion.isPresent()) {
+ return;
+ }
- final Optional expansion = plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0));
- if (!expansion.isPresent())
- {
- return;
- }
-
- suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
- }
+ suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionInfo.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionInfo.java
index 1d21d4e..569c0ce 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionInfo.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionInfo.java
@@ -20,6 +20,9 @@
package me.clip.placeholderapi.commands.impl.cloud;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
@@ -28,109 +31,99 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Stream;
+public final class CommandECloudExpansionInfo extends PlaceholderCommand {
-public final class CommandECloudExpansionInfo extends PlaceholderCommand
-{
+ public CommandECloudExpansionInfo() {
+ super("info");
+ }
- public CommandECloudExpansionInfo()
- {
- super("info");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ if (params.isEmpty()) {
+ Msg.msg(sender,
+ "&cYou must specify the name of the expansion.");
+ return;
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- if (params.isEmpty())
- {
- Msg.msg(sender,
- "&cYou must specify the name of the expansion.");
- return;
- }
+ final CloudExpansion expansion = plugin.getCloudExpansionManager()
+ .findCloudExpansionByName(params.get(0)).orElse(null);
+ if (expansion == null) {
+ Msg.msg(sender,
+ "&cThere is no expansion with the name: &f" + params.get(0));
+ return;
+ }
- final CloudExpansion expansion = plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0)).orElse(null);
- if (expansion == null)
- {
- Msg.msg(sender,
- "&cThere is no expansion with the name: &f" + params.get(0));
- return;
- }
+ final StringBuilder builder = new StringBuilder();
- final StringBuilder builder = new StringBuilder();
+ builder.append("&bExpansion: &f")
+ .append(expansion.shouldUpdate() ? "&e" : "&a")
+ .append(expansion.getName())
+ .append('\n')
+ .append("&bAuthor: &f")
+ .append(expansion.getAuthor())
+ .append('\n')
+ .append("&bVerified: ")
+ .append(expansion.isVerified() ? "&a&l✔" : "&c&l❌")
+ .append('\n');
- builder.append("&bExpansion: &f")
- .append(expansion.shouldUpdate() ? "&e" : "&a")
- .append(expansion.getName())
- .append('\n')
- .append("&bAuthor: &f")
- .append(expansion.getAuthor())
- .append('\n')
- .append("&bVerified: ")
- .append(expansion.isVerified() ? "&a&l✔" : "&c&l❌")
- .append('\n');
+ if (params.size() < 2) {
+ builder.append("&bLatest Version: &f")
+ .append(expansion.getLatestVersion())
+ .append('\n')
+ .append("&bReleased: &f")
+ .append(expansion.getTimeSinceLastUpdate())
+ .append(" ago")
+ .append('\n')
+ .append("&bRelease Notes: &f")
+ .append(expansion.getVersion().getReleaseNotes())
+ .append('\n');
+ } else {
+ final CloudExpansion.Version version = expansion.getVersion(params.get(1));
+ if (version == null) {
+ Msg.msg(sender,
+ "&cCould not find specified version: &f" + params.get(1),
+ "&aVersions: &f" + expansion.getAvailableVersions());
+ return;
+ }
- if (params.size() < 2)
- {
- builder.append("&bLatest Version: &f")
- .append(expansion.getLatestVersion())
- .append('\n')
- .append("&bReleased: &f")
- .append(expansion.getTimeSinceLastUpdate())
- .append(" ago")
- .append('\n')
- .append("&bRelease Notes: &f")
- .append(expansion.getVersion().getReleaseNotes())
- .append('\n');
- }
- else
- {
- final CloudExpansion.Version version = expansion.getVersion(params.get(1));
- if (version == null)
- {
- Msg.msg(sender,
- "&cCould not find specified version: &f" + params.get(1),
- "&aVersions: &f" + expansion.getAvailableVersions());
- return;
- }
+ builder.append("&bVersion: &f")
+ .append(version.getVersion())
+ .append('\n')
+ .append("&bRelease Notes: &f")
+ .append(version.getReleaseNotes())
+ .append('\n')
+ .append("&bDownload URL: &f")
+ .append(version.getUrl())
+ .append('\n');
+ }
- builder.append("&bVersion: &f")
- .append(version.getVersion())
- .append('\n')
- .append("&bRelease Notes: &f")
- .append(version.getReleaseNotes())
- .append('\n')
- .append("&bDownload URL: &f")
- .append(version.getUrl())
- .append('\n');
- }
+ Msg.msg(sender, builder.toString());
+ }
- Msg.msg(sender, builder.toString());
- }
+ @Override
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
+ if (params.size() > 2) {
+ return;
+ }
- @Override
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
- if (params.size() > 2)
- {
- return;
- }
+ if (params.size() <= 1) {
+ final Stream names = plugin.getCloudExpansionManager().getCloudExpansions().values()
+ .stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
+ suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
+ return;
+ }
- if (params.size() <= 1)
- {
- final Stream names = plugin.getCloudExpansionManager().getCloudExpansions().values().stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
- suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
- return;
- }
+ final Optional expansion = plugin.getCloudExpansionManager()
+ .findCloudExpansionByName(params.get(0));
+ if (!expansion.isPresent()) {
+ return;
+ }
- final Optional expansion = plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0));
- if (!expansion.isPresent())
- {
- return;
- }
-
- suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
- }
+ suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
+ }
}
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 373901e..e4cb193 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
@@ -25,6 +25,19 @@ import com.google.common.collect.ImmutableSet;
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.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.configuration.ExpansionSort;
@@ -39,322 +52,297 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-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.concurrent.atomic.AtomicInteger;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
+public final class CommandECloudExpansionList extends PlaceholderCommand {
-public final class CommandECloudExpansionList extends PlaceholderCommand
-{
+ private static final int PAGE_SIZE = 10;
- private static final int PAGE_SIZE = 10;
-
- @NotNull
- private static final Function EXPANSION_NAME =
- expansion -> (expansion.shouldUpdate() ? "&6" : expansion.hasExpansion() ? "&a" : "&7") + expansion.getName();
- @NotNull
- private static final Function EXPANSION_AUTHOR =
- expansion -> "&f" + expansion.getAuthor();
- @NotNull
- private static final Function EXPANSION_VERIFIED =
- expansion -> expansion.isVerified() ? "&aY" : "&cN";
- @NotNull
- private static final Function EXPANSION_LATEST_VERSION =
- expansion -> "&f" + expansion.getLatestVersion();
- @NotNull
- private static final Function EXPANSION_CURRENT_VERSION =
- expansion -> "&f" + PlaceholderAPIPlugin.getInstance().getLocalExpansionManager().findExpansionByName(expansion.getName()).map(PlaceholderExpansion::getVersion).orElse("Unknown");
+ @NotNull
+ private static final Function EXPANSION_NAME =
+ expansion -> (expansion.shouldUpdate() ? "&6" : expansion.hasExpansion() ? "&a" : "&7")
+ + expansion.getName();
+ @NotNull
+ private static final Function EXPANSION_AUTHOR =
+ expansion -> "&f" + expansion.getAuthor();
+ @NotNull
+ private static final Function EXPANSION_VERIFIED =
+ expansion -> expansion.isVerified() ? "&aY" : "&cN";
+ @NotNull
+ private static final Function EXPANSION_LATEST_VERSION =
+ expansion -> "&f" + expansion.getLatestVersion();
+ @NotNull
+ private static final Function EXPANSION_CURRENT_VERSION =
+ expansion -> "&f" + PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()
+ .findExpansionByName(expansion.getName()).map(PlaceholderExpansion::getVersion)
+ .orElse("Unknown");
- @Unmodifiable
- private static final Set OPTIONS = ImmutableSet.of("all", "installed");
+ @Unmodifiable
+ private static final Set OPTIONS = ImmutableSet.of("all", "installed");
- public CommandECloudExpansionList()
- {
- super("list");
- }
+ public CommandECloudExpansionList() {
+ super("list");
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- if (params.isEmpty())
- {
- Msg.msg(sender,
- "&cYou must specify an option. [all, {author}, installed]");
- return;
- }
+ @NotNull
+ private static Collection getExpansions(@NotNull final String target,
+ @NotNull final PlaceholderAPIPlugin plugin) {
+ switch (target.toLowerCase()) {
+ case "all":
+ return plugin.getCloudExpansionManager().getCloudExpansions().values();
+ case "installed":
+ return plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values();
+ default:
+ return plugin.getCloudExpansionManager().getCloudExpansionsByAuthor(target).values();
+ }
+ }
+ @NotNull
+ private static List getPage(@NotNull final List expansions,
+ final int page) {
+ final int head = (page * PAGE_SIZE);
+ final int tail = Math.min(expansions.size(), head + PAGE_SIZE);
- final boolean installed = params.get(0).equalsIgnoreCase("installed");
- final List expansions = Lists.newArrayList(getExpansions(params.get(0), plugin));
+ if (expansions.size() < head) {
+ return Collections.emptyList();
+ }
- if (expansions.isEmpty())
- {
- Msg.msg(sender,
- "&cNo expansions available to list.");
- return;
- }
+ return expansions.subList(head, tail);
+ }
- expansions.sort(plugin.getPlaceholderAPIConfig().getExpansionSort().orElse(ExpansionSort.LATEST));
+ public static void addExpansionTitle(@NotNull final StringBuilder builder,
+ @NotNull final String target, final int page) {
+ switch (target.toLowerCase()) {
+ case "all":
+ builder.append("&bAll Expansions");
+ break;
+ case "installed":
+ builder.append("&bInstalled Expansions");
+ break;
+ default:
+ builder.append("&bExpansions by &f")
+ .append(target);
+ break;
+ }
- if (!(sender instanceof Player) && params.size() < 2)
- {
- final StringBuilder builder = new StringBuilder();
+ if (page == -1) {
+ builder.append('\n');
+ return;
+ }
- addExpansionTitle(builder, params.get(0), -1);
- addExpansionTable(expansions,
- builder,
- 1,
- installed ? "&9Version" : "&9Latest Version",
- installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
+ builder.append(" &bPage&7: &a")
+ .append(page)
+ .append("&r")
+ .append('\n');
+ }
- Msg.msg(sender, builder.toString());
- return;
- }
+ @NotNull
+ private static JSONMessage getMessage(@NotNull final List expansions,
+ final int page, final int limit, @NotNull final String target) {
+ final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat();
- final int page;
+ final StringBuilder tooltip = new StringBuilder();
+ final JSONMessage message = JSONMessage.create();
- if (params.size() < 2)
- {
- page = 1;
- }
- else
- {
- //noinspection UnstableApiUsage
- final Integer parsed = Ints.tryParse(params.get(1));
- if (parsed == null)
- {
- Msg.msg(sender,
- "&cPage number must be an integer.");
- return;
- }
+ for (int index = 0; index < expansions.size(); index++) {
+ final CloudExpansion expansion = expansions.get(index);
- final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
+ tooltip.append("&bClick to download this expansion!")
+ .append('\n')
+ .append('\n')
+ .append("&bAuthor: &f")
+ .append(expansion.getAuthor())
+ .append('\n')
+ .append("&bVerified: ")
+ .append(expansion.isVerified() ? "&a&l✔&r" : "&c&l❌&r")
+ .append('\n')
+ .append("&bLatest Version: &f")
+ .append(expansion.getLatestVersion())
+ .append('\n')
+ .append("&bReleased: &f")
+ .append(format.format(expansion.getLastUpdate()));
- if (parsed < 1 || parsed > limit)
- {
- Msg.msg(sender,
- "&cPage number must be in the range &8[&a1&7..&a" + limit + "&8]");
- return;
- }
+ final String description = expansion.getDescription();
+ if (description != null && !description.isEmpty()) {
+ tooltip.append('\n')
+ .append('\n')
+ .append("&f")
+ .append(description.replace("\r", "").trim());
+ }
- page = parsed;
- }
+ message.then(Msg.color(
+ "&8" + (index + ((page - 1) * PAGE_SIZE) + 1) + ".&r " + (expansion.shouldUpdate() ? "&6"
+ : expansion.hasExpansion() ? "&a" : "&7") + expansion.getName()));
- final StringBuilder builder = new StringBuilder();
- final List values = getPage(expansions, page - 1);
+ message.tooltip(Msg.color(tooltip.toString()));
+ message.suggestCommand("/papi ecloud download " + expansion.getName());
- addExpansionTitle(builder, params.get(0), page);
+ if (index < expansions.size() - 1) {
+ message.newline();
+ }
- if (!(sender instanceof Player))
- {
- addExpansionTable(values,
- builder,
- ((page - 1) * PAGE_SIZE) + 1,
- installed ? "&9Version" : "&9Latest Version",
- installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
+ tooltip.setLength(0);
+ }
- Msg.msg(sender, builder.toString());
+ if (limit > 1) {
+ message.newline();
- return;
- }
+ message.then("◀")
+ .color(page > 1 ? ChatColor.GRAY : ChatColor.DARK_GRAY);
+ if (page > 1) {
+ message.runCommand("/papi ecloud list " + target + " " + (page - 1));
+ }
- Msg.msg(sender, builder.toString());
+ message.then(" " + page + " ").color(ChatColor.GREEN);
- final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
+ message.then("▶")
+ .color(page < limit ? ChatColor.GRAY : ChatColor.DARK_GRAY);
+ if (page < limit) {
+ message.runCommand("/papi ecloud list " + target + " " + (page + 1));
+ }
+ }
- final JSONMessage message = getMessage(values, page, limit, params.get(0));
- message.send(((Player) sender));
- }
+ return message;
+ }
- @Override
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
- if (params.size() > 2)
- {
- return;
- }
+ private static void addExpansionTable(@NotNull final List expansions,
+ @NotNull final StringBuilder message, final int startIndex,
+ @NotNull final String versionTitle,
+ @NotNull final Function versionFunction) {
+ final Map> functions = new LinkedHashMap<>();
- if (params.size() <= 1)
- {
- suggestByParameter(Sets.union(OPTIONS, plugin.getCloudExpansionManager().getCloudExpansionAuthors()).stream(), suggestions, params.isEmpty() ? null : params.get(0));
- return;
- }
+ final AtomicInteger counter = new AtomicInteger(startIndex);
+ functions.put("&f", expansion -> "&8" + counter.getAndIncrement() + ".");
- suggestByParameter(IntStream.rangeClosed(1, (int) Math.ceil((double) getExpansions(params.get(0), plugin).size() / PAGE_SIZE)).mapToObj(Objects::toString), suggestions, params.get(1));
- }
+ functions.put("&9Name", EXPANSION_NAME);
+ functions.put("&9Author", EXPANSION_AUTHOR);
+ functions.put("&9Verified", EXPANSION_VERIFIED);
+ functions.put(versionTitle, versionFunction);
+ final List> rows = new ArrayList<>();
- @NotNull
- private static Collection getExpansions(@NotNull final String target, @NotNull final PlaceholderAPIPlugin plugin)
- {
- switch (target.toLowerCase())
- {
- case "all":
- return plugin.getCloudExpansionManager().getCloudExpansions().values();
- case "installed":
- return plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values();
- default:
- return plugin.getCloudExpansionManager().getCloudExpansionsByAuthor(target).values();
- }
- }
+ rows.add(0, new ArrayList<>(functions.keySet()));
- @NotNull
- private static List getPage(@NotNull final List expansions, final int page)
- {
- final int head = (page * PAGE_SIZE);
- final int tail = Math.min(expansions.size(), head + PAGE_SIZE);
+ for (final CloudExpansion expansion : expansions) {
+ rows.add(functions.values().stream().map(function -> function.apply(expansion))
+ .map(Objects::toString).collect(Collectors.toList()));
+ }
- if (expansions.size() < head)
- {
- return Collections.emptyList();
- }
+ final List table = Format.tablify(Format.Align.LEFT, rows)
+ .orElse(Collections.emptyList());
+ if (table.isEmpty()) {
+ return;
+ }
- return expansions.subList(head, tail);
- }
+ table.add(1, "&8" + Strings.repeat("-", table.get(0).length() - (rows.get(0).size() * 2)));
- public static void addExpansionTitle(@NotNull final StringBuilder builder, @NotNull final String target, final int page)
- {
- switch (target.toLowerCase())
- {
- case "all":
- builder.append("&bAll Expansions");
- break;
- case "installed":
- builder.append("&bInstalled Expansions");
- break;
- default:
- builder.append("&bExpansions by &f")
- .append(target);
- break;
- }
+ message.append(String.join("\n", table));
+ }
- if (page == -1)
- {
- builder.append('\n');
- return;
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ if (params.isEmpty()) {
+ Msg.msg(sender,
+ "&cYou must specify an option. [all, {author}, installed]");
+ return;
+ }
- builder.append(" &bPage&7: &a")
- .append(page)
- .append("&r")
- .append('\n');
- }
+ final boolean installed = params.get(0).equalsIgnoreCase("installed");
+ final List expansions = Lists
+ .newArrayList(getExpansions(params.get(0), plugin));
+ if (expansions.isEmpty()) {
+ Msg.msg(sender,
+ "&cNo expansions available to list.");
+ return;
+ }
- @NotNull
- private static JSONMessage getMessage(@NotNull final List expansions, final int page, final int limit, @NotNull final String target)
- {
- final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat();
+ expansions
+ .sort(plugin.getPlaceholderAPIConfig().getExpansionSort().orElse(ExpansionSort.LATEST));
- final StringBuilder tooltip = new StringBuilder();
- final JSONMessage message = JSONMessage.create();
+ if (!(sender instanceof Player) && params.size() < 2) {
+ final StringBuilder builder = new StringBuilder();
- for (int index = 0; index < expansions.size(); index++)
- {
- final CloudExpansion expansion = expansions.get(index);
+ addExpansionTitle(builder, params.get(0), -1);
+ addExpansionTable(expansions,
+ builder,
+ 1,
+ installed ? "&9Version" : "&9Latest Version",
+ installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
- tooltip.append("&bClick to download this expansion!")
- .append('\n')
- .append('\n')
- .append("&bAuthor: &f")
- .append(expansion.getAuthor())
- .append('\n')
- .append("&bVerified: ")
- .append(expansion.isVerified() ? "&a&l✔&r" : "&c&l❌&r")
- .append('\n')
- .append("&bLatest Version: &f")
- .append(expansion.getLatestVersion())
- .append('\n')
- .append("&bReleased: &f")
- .append(format.format(expansion.getLastUpdate()));
+ Msg.msg(sender, builder.toString());
+ return;
+ }
- final String description = expansion.getDescription();
- if (description != null && !description.isEmpty())
- {
- tooltip.append('\n')
- .append('\n')
- .append("&f")
- .append(description.replace("\r", "").trim());
- }
+ final int page;
- message.then(Msg.color("&8" + (index + ((page - 1) * PAGE_SIZE) + 1) + ".&r " + (expansion.shouldUpdate() ? "&6" : expansion.hasExpansion() ? "&a" : "&7") + expansion.getName()));
+ if (params.size() < 2) {
+ page = 1;
+ } else {
+ //noinspection UnstableApiUsage
+ final Integer parsed = Ints.tryParse(params.get(1));
+ if (parsed == null) {
+ Msg.msg(sender,
+ "&cPage number must be an integer.");
+ return;
+ }
- message.tooltip(Msg.color(tooltip.toString()));
- message.suggestCommand("/papi ecloud download " + expansion.getName());
+ final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
- if (index < expansions.size() - 1)
- {
- message.newline();
- }
+ if (parsed < 1 || parsed > limit) {
+ Msg.msg(sender,
+ "&cPage number must be in the range &8[&a1&7..&a" + limit + "&8]");
+ return;
+ }
- tooltip.setLength(0);
- }
+ page = parsed;
+ }
- if (limit > 1)
- {
- message.newline();
+ final StringBuilder builder = new StringBuilder();
+ final List values = getPage(expansions, page - 1);
- message.then("◀")
- .color(page > 1 ? ChatColor.GRAY : ChatColor.DARK_GRAY);
- if (page > 1)
- {
- message.runCommand("/papi ecloud list " + target + " " + (page - 1));
- }
+ addExpansionTitle(builder, params.get(0), page);
- message.then(" " + page + " ").color(ChatColor.GREEN);
+ if (!(sender instanceof Player)) {
+ addExpansionTable(values,
+ builder,
+ ((page - 1) * PAGE_SIZE) + 1,
+ installed ? "&9Version" : "&9Latest Version",
+ installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
- message.then("▶")
- .color(page < limit ? ChatColor.GRAY : ChatColor.DARK_GRAY);
- if (page < limit)
- {
- message.runCommand("/papi ecloud list " + target + " " + (page + 1));
- }
- }
+ Msg.msg(sender, builder.toString());
- return message;
- }
+ return;
+ }
- private static void addExpansionTable(@NotNull final List expansions, @NotNull final StringBuilder message, final int startIndex, @NotNull final String versionTitle, @NotNull final Function versionFunction)
- {
- final Map> functions = new LinkedHashMap<>();
+ Msg.msg(sender, builder.toString());
- final AtomicInteger counter = new AtomicInteger(startIndex);
- functions.put("&f", expansion -> "&8" + counter.getAndIncrement() + ".");
+ final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
- functions.put("&9Name", EXPANSION_NAME);
- functions.put("&9Author", EXPANSION_AUTHOR);
- functions.put("&9Verified", EXPANSION_VERIFIED);
- functions.put(versionTitle, versionFunction);
+ final JSONMessage message = getMessage(values, page, limit, params.get(0));
+ message.send(((Player) sender));
+ }
- final List> rows = new ArrayList<>();
+ @Override
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
+ if (params.size() > 2) {
+ return;
+ }
- rows.add(0, new ArrayList<>(functions.keySet()));
+ if (params.size() <= 1) {
+ suggestByParameter(
+ Sets.union(OPTIONS, plugin.getCloudExpansionManager().getCloudExpansionAuthors())
+ .stream(), suggestions, params.isEmpty() ? null : params.get(0));
+ return;
+ }
- for (final CloudExpansion expansion : expansions)
- {
- rows.add(functions.values().stream().map(function -> function.apply(expansion)).map(Objects::toString).collect(Collectors.toList()));
- }
-
- final List table = Format.tablify(Format.Align.LEFT, rows).orElse(Collections.emptyList());
- if (table.isEmpty())
- {
- return;
- }
-
- table.add(1, "&8" + Strings.repeat("-", table.get(0).length() - (rows.get(0).size() * 2)));
-
- message.append(String.join("\n", table));
- }
+ suggestByParameter(IntStream.rangeClosed(1,
+ (int) Math.ceil((double) getExpansions(params.get(0), plugin).size() / PAGE_SIZE))
+ .mapToObj(Objects::toString), suggestions, params.get(1));
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionPlaceholders.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionPlaceholders.java
index e4177b0..9d51966 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionPlaceholders.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionPlaceholders.java
@@ -21,6 +21,9 @@
package me.clip.placeholderapi.commands.impl.cloud;
import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
@@ -29,68 +32,63 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
+public final class CommandECloudExpansionPlaceholders extends PlaceholderCommand {
-public final class CommandECloudExpansionPlaceholders extends PlaceholderCommand
-{
+ public CommandECloudExpansionPlaceholders() {
+ super("placeholders");
+ }
- public CommandECloudExpansionPlaceholders()
- {
- super("placeholders");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ if (params.isEmpty()) {
+ Msg.msg(sender,
+ "&cYou must specify the name of the expansion.");
+ return;
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- if (params.isEmpty())
- {
- Msg.msg(sender,
- "&cYou must specify the name of the expansion.");
- return;
- }
+ final CloudExpansion expansion = plugin.getCloudExpansionManager()
+ .findCloudExpansionByName(params.get(0)).orElse(null);
+ if (expansion == null) {
+ Msg.msg(sender,
+ "&cThere is no expansion with the name: &f" + params.get(0));
+ return;
+ }
- final CloudExpansion expansion = plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0)).orElse(null);
- if (expansion == null)
- {
- Msg.msg(sender,
- "&cThere is no expansion with the name: &f" + params.get(0));
- return;
- }
+ final List placeholders = expansion.getPlaceholders();
+ if (placeholders == null || placeholders.isEmpty()) {
+ Msg.msg(sender,
+ "&cThe expansion specified does not have placeholders listed.");
+ return;
+ }
- final List placeholders = expansion.getPlaceholders();
- if (placeholders == null || placeholders.isEmpty())
- {
- Msg.msg(sender,
- "&cThe expansion specified does not have placeholders listed.");
- return;
- }
+ final List> partitions = Lists
+ .partition(placeholders.stream().sorted().collect(Collectors.toList()), 10);
- final List> partitions = Lists.partition(placeholders.stream().sorted().collect(Collectors.toList()), 10);
+ Msg.msg(sender,
+ "&6" + placeholders.size() + "&7 placeholders: &a",
+ partitions.stream().map(partition -> String.join(", ", partition))
+ .collect(Collectors.joining("\n")));
- Msg.msg(sender,
- "&6" + placeholders.size() + "&7 placeholders: &a",
- partitions.stream().map(partition -> " " + String.join(", ", partition)).collect(Collectors.joining("\n")));
+ }
- }
+ @Override
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
+ if (params.size() > 1) {
+ return;
+ }
- @Override
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
- if (params.size() > 1)
- {
- return;
- }
+ final Stream names = plugin.getCloudExpansionManager()
+ .getCloudExpansions()
+ .values()
+ .stream()
+ .map(CloudExpansion::getName)
+ .map(name -> name.replace(' ', '_'));
- final Stream names = plugin.getCloudExpansionManager()
- .getCloudExpansions()
- .values()
- .stream()
- .map(CloudExpansion::getName)
- .map(name -> name.replace(' ', '_'));
-
- suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
- }
+ suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudRefresh.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudRefresh.java
index 39dadcb..2185d88 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudRefresh.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudRefresh.java
@@ -20,6 +20,7 @@
package me.clip.placeholderapi.commands.impl.cloud;
+import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -27,24 +28,22 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
+public final class CommandECloudRefresh extends PlaceholderCommand {
-public final class CommandECloudRefresh extends PlaceholderCommand
-{
+ public CommandECloudRefresh() {
+ super("refresh");
+ }
- public CommandECloudRefresh()
- {
- super("refresh");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ plugin.getCloudExpansionManager().clean();
+ plugin.getCloudExpansionManager()
+ .fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- plugin.getCloudExpansionManager().clean();
- plugin.getCloudExpansionManager().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
-
- Msg.msg(sender,
- "&aThe eCloud Manager has been refreshed!");
- }
+ Msg.msg(sender,
+ "&aThe eCloud manager has been refreshed!");
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudStatus.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudStatus.java
index c1e3e66..47aafa6 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudStatus.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudStatus.java
@@ -20,6 +20,7 @@
package me.clip.placeholderapi.commands.impl.cloud;
+import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.manager.CloudExpansionManager;
@@ -28,36 +29,36 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
+public final class CommandECloudStatus extends PlaceholderCommand {
-public final class CommandECloudStatus extends PlaceholderCommand
-{
+ public CommandECloudStatus() {
+ super("status");
+ }
- public CommandECloudStatus()
- {
- super("status");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ final CloudExpansionManager manager = plugin.getCloudExpansionManager();
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- final CloudExpansionManager manager = plugin.getCloudExpansionManager();
+ final int updateCount = manager.getCloudUpdateCount();
+ final int authorCount = manager.getCloudExpansionAuthorCount();
+ final int expansionCount = manager.getCloudExpansions().size();
- final int updateCount = manager.getCloudUpdateCount();
- final int authorCount = manager.getCloudExpansionAuthorCount();
- final int expansionCount = manager.getCloudExpansions().size();
+ final StringBuilder builder = new StringBuilder();
- final StringBuilder builder = new StringBuilder();
+ builder.append("&bThere are &a").append(expansionCount)
+ .append("&b expansions available on the eCloud.").append('\n');
+ builder.append("&7A total of &f").append(authorCount)
+ .append("&7 authors have contributed to the eCloud.").append('\n');
- builder.append("&bThere are &a").append(expansionCount).append("&b expansions available on the eCloud.").append('\n');
- builder.append("&7A total of &f").append(authorCount).append("&7 authors have contributed to the eCloud.").append('\n');
+ if (updateCount > 0) {
+ builder.append("&eYou have &f").append(updateCount)
+ .append(updateCount > 1 ? "&e expansions" : "&e expansion").append("installed that ")
+ .append(updateCount > 1 ? "have an" : "has an").append(" update available.");
+ }
- if (updateCount > 0)
- {
- builder.append("&eYou have &a").append(updateCount).append("&e expansions installed that have updates available.");
- }
-
- Msg.msg(sender,builder.toString());
- }
+ Msg.msg(sender, builder.toString());
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudToggle.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudToggle.java
index 3dd211d..5cbd754 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudToggle.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudToggle.java
@@ -20,6 +20,7 @@
package me.clip.placeholderapi.commands.impl.cloud;
+import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -27,53 +28,45 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
+public final class CommandECloudToggle extends PlaceholderCommand {
-public final class CommandECloudToggle extends PlaceholderCommand
-{
+ public CommandECloudToggle() {
+ super("toggle", "enable", "disable");
+ }
- public CommandECloudToggle()
- {
- super("toggle", "enable", "disable");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ final boolean desiredState;
+ final boolean currentState = plugin.getPlaceholderAPIConfig().isCloudEnabled();
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- final boolean desiredState;
- final boolean currentState = plugin.getPlaceholderAPIConfig().isCloudEnabled();
+ switch (alias.toLowerCase()) {
+ case "enable":
+ desiredState = true;
+ break;
+ case "disable":
+ desiredState = false;
+ break;
+ default:
+ desiredState = !currentState;
+ break;
+ }
- switch (alias.toLowerCase())
- {
- case "enable":
- desiredState = true;
- break;
- case "disable":
- desiredState = false;
- break;
- default:
- desiredState = !currentState;
- break;
- }
+ if (desiredState == currentState) {
+ Msg.msg(sender, "&7The eCloud Manager is already " + (desiredState ? "enabled" : "disabled"));
+ return;
+ }
- if (desiredState == currentState)
- {
- Msg.msg(sender, "&7The eCloud Manager is already " + (desiredState ? "enabled" : "disabled"));
- return;
- }
+ plugin.getPlaceholderAPIConfig().setCloudEnabled(desiredState);
- plugin.getPlaceholderAPIConfig().setCloudEnabled(desiredState);
+ if (desiredState) {
+ plugin.getCloudExpansionManager().load();
+ } else {
+ plugin.getCloudExpansionManager().kill();
+ }
- if (desiredState)
- {
- plugin.getCloudExpansionManager().load();
- }
- else
- {
- plugin.getCloudExpansionManager().kill();
- }
-
- Msg.msg(sender, "&aThe eCloud Manager has been " + (desiredState ? "enabled" : "disabled"));
- }
+ Msg.msg(sender, "&aThe eCloud Manager has been " + (desiredState ? "enabled" : "disabled"));
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudUpdate.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudUpdate.java
index 2e94c6b..6b4d21a 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudUpdate.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudUpdate.java
@@ -21,6 +21,12 @@
package me.clip.placeholderapi.commands.impl.cloud;
import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
@@ -32,114 +38,103 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.concurrent.CompletableFuture;
-import java.util.stream.Collectors;
-
/**
* please don't flame me for this code, I will fix this shit later.
*/
-public final class CommandECloudUpdate extends PlaceholderCommand
-{
+public final class CommandECloudUpdate extends PlaceholderCommand {
- public CommandECloudUpdate()
- {
- super("update");
- }
+ public CommandECloudUpdate() {
+ super("update");
+ }
+ private static CompletableFuture>> downloadAndDiscover(
+ @NotNull final List expansions, @NotNull final PlaceholderAPIPlugin plugin) {
+ return expansions.stream()
+ .map(expansion -> plugin.getCloudExpansionManager()
+ .downloadExpansion(expansion, expansion.getVersion()))
+ .map(future -> future.thenCompose(plugin.getLocalExpansionManager()::findExpansionInFile))
+ .collect(Futures.collector());
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- if (params.isEmpty())
- {
- Msg.msg(sender,
- "&cYou must define 'all' or the name of an expansion to update.");
- return;
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ if (params.isEmpty()) {
+ Msg.msg(sender,
+ "&cYou must define 'all' or the name of an expansion to update.");
+ return;
+ }
- final boolean multiple = params.get(0).equalsIgnoreCase("all");
- final List expansions = new ArrayList<>();
+ final boolean multiple = params.get(0).equalsIgnoreCase("all");
+ final List expansions = new ArrayList<>();
- // gather target expansions
- if (multiple)
- {
- expansions.addAll(plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values());
- }
- else
- {
- plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0)).ifPresent(expansions::add);
- }
+ // gather target expansions
+ if (multiple) {
+ expansions.addAll(plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values());
+ } else {
+ plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0))
+ .ifPresent(expansions::add);
+ }
- // remove the ones that are the latest version
- expansions.removeIf(expansion -> !expansion.shouldUpdate());
+ // remove the ones that are the latest version
+ expansions.removeIf(expansion -> !expansion.shouldUpdate());
- if (expansions.isEmpty())
- {
- Msg.msg(sender,
- "&cNo updates available for " + (!multiple ? "this expansion." : "your active expansions."));
- return;
- }
+ if (expansions.isEmpty()) {
+ Msg.msg(sender,
+ "&cNo updates available for " + (!multiple ? "this expansion."
+ : "your active expansions."));
+ return;
+ }
- Msg.msg(sender,
- "&aUpdating expansions: " + expansions.stream().map(CloudExpansion::getName).collect(Collectors.joining("&7, &6", "&8[&6", "&8]&r")));
+ Msg.msg(sender,
+ "&aUpdating expansions: " + expansions.stream().map(CloudExpansion::getName)
+ .collect(Collectors.joining("&7, &6", "&8[&6", "&8]&r")));
+ Futures.onMainThread(plugin, downloadAndDiscover(expansions, plugin), (classes, exception) -> {
+ if (exception != null) {
+ Msg.msg(sender,
+ "&cFailed to update expansions: &e" + exception.getMessage());
+ return;
+ }
- Futures.onMainThread(plugin, downloadAndDiscover(expansions, plugin), (classes, exception) -> {
- if (exception != null)
- {
- Msg.msg(sender,
- "&cFailed to update expansions: &e" + exception.getMessage());
- return;
- }
+ Msg.msg(sender,
+ "&aSuccessfully downloaded updates, registering new versions.");
- Msg.msg(sender,
- "&aSuccessfully downloaded updates, registering new versions.");
+ final String message = classes.stream()
+ .filter(Objects::nonNull)
+ .map(plugin.getLocalExpansionManager()::register)
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .map(expansion -> " &a" + expansion.getName() + " &f" + expansion.getVersion())
+ .collect(Collectors.joining("\n"));
+ Msg.msg(sender,
+ "&7Registered expansions:", message);
- final String message = classes.stream()
- .filter(Objects::nonNull)
- .map(plugin.getLocalExpansionManager()::register)
- .filter(Optional::isPresent)
- .map(Optional::get)
- .map(expansion -> " &a" + expansion.getName() + " &f" + expansion.getVersion())
- .collect(Collectors.joining("\n"));
+ });
+ }
- Msg.msg(sender,
- "&7Registered expansions:", message);
+ @Override
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
+ if (params.size() > 1) {
+ return;
+ }
- });
- }
+ final List installed = Lists
+ .newArrayList(plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values());
+ installed.removeIf(expansion -> !expansion.shouldUpdate());
- @Override
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
- if (params.size() > 1)
- {
- return;
- }
+ if (!installed.isEmpty() && (params.isEmpty() || "all"
+ .startsWith(params.get(0).toLowerCase()))) {
+ suggestions.add("all");
+ }
- final List installed = Lists.newArrayList(plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values());
- installed.removeIf(expansion -> !expansion.shouldUpdate());
-
- if (!installed.isEmpty() && (params.isEmpty() || "all".startsWith(params.get(0).toLowerCase())))
- {
- suggestions.add("all");
- }
-
- suggestByParameter(installed.stream().map(CloudExpansion::getName).map(name -> name.replace(" ", "_")), suggestions, params.isEmpty() ? null : params.get(0));
- }
-
-
- private static CompletableFuture>> downloadAndDiscover(@NotNull final List expansions, @NotNull final PlaceholderAPIPlugin plugin)
- {
- return expansions.stream()
- .map(expansion -> plugin.getCloudExpansionManager().downloadExpansion(expansion, expansion.getVersion()))
- .map(future -> future.thenCompose(plugin.getLocalExpansionManager()::findExpansionInFile))
- .collect(Futures.collector());
- }
+ suggestByParameter(
+ installed.stream().map(CloudExpansion::getName).map(name -> name.replace(" ", "_")),
+ suggestions, params.isEmpty() ? null : params.get(0));
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java
index 9f14b1a..d3c3637 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java
@@ -22,15 +22,6 @@ package me.clip.placeholderapi.commands.impl.local;
import com.google.common.io.CharStreams;
import com.google.gson.JsonParser;
-import me.clip.placeholderapi.PlaceholderAPIPlugin;
-import me.clip.placeholderapi.commands.PlaceholderCommand;
-import me.clip.placeholderapi.expansion.PlaceholderExpansion;
-import me.clip.placeholderapi.util.Msg;
-import org.bukkit.command.CommandSender;
-import org.bukkit.plugin.Plugin;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Unmodifiable;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -42,158 +33,173 @@ import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
+import java.util.Arrays;
+import java.util.Comparator;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.logging.Level;
import java.util.stream.Collectors;
+import me.clip.placeholderapi.PlaceholderAPIPlugin;
+import me.clip.placeholderapi.commands.PlaceholderCommand;
+import me.clip.placeholderapi.expansion.PlaceholderExpansion;
+import me.clip.placeholderapi.util.Msg;
+import org.bukkit.command.CommandSender;
+import org.bukkit.plugin.Plugin;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Unmodifiable;
-public final class CommandDump extends PlaceholderCommand
-{
+public final class CommandDump extends PlaceholderCommand {
- @NotNull
- private static final String URL = "https://paste.helpch.at/";
+ @NotNull
+ private static final String URL = "https://paste.helpch.at/";
- @NotNull
- private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
- .withLocale(Locale.US)
- .withZone(ZoneId.of("UTC"));
+ @NotNull
+ private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
+ .ofLocalizedDateTime(FormatStyle.LONG)
+ .withLocale(Locale.US)
+ .withZone(ZoneId.of("UTC"));
- public CommandDump()
- {
- super("dump");
- }
+ public CommandDump() {
+ super("dump");
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- postDump(makeDump(plugin)).whenComplete((key, exception) -> {
- if (exception != null)
- {
- plugin.getLogger().log(Level.WARNING, "failed to post dump details", exception);
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ postDump(makeDump(plugin)).whenComplete((key, exception) -> {
+ if (exception != null) {
+ plugin.getLogger().log(Level.WARNING, "failed to post dump details", exception);
- Msg.msg(sender,
- "&cFailed to post dump details, check console.");
- return;
- }
+ Msg.msg(sender,
+ "&cFailed to post dump details, check console.");
+ return;
+ }
- Msg.msg(sender,
- "&aSuccessfully posted dump: " + URL + key);
- });
- }
+ Msg.msg(sender,
+ "&aSuccessfully posted dump: " + URL + key);
+ });
+ }
- @NotNull
- private CompletableFuture postDump(@NotNull final String dump)
- {
- return CompletableFuture.supplyAsync(() -> {
- try
- {
- final HttpURLConnection connection = ((HttpURLConnection) new URL(URL + "documents").openConnection());
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
- connection.setDoOutput(true);
+ @NotNull
+ private CompletableFuture postDump(@NotNull final String dump) {
+ return CompletableFuture.supplyAsync(() -> {
+ try {
+ final HttpURLConnection connection = ((HttpURLConnection) new URL(URL + "documents")
+ .openConnection());
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
+ connection.setDoOutput(true);
- connection.connect();
+ connection.connect();
- try (final OutputStream stream = connection.getOutputStream())
- {
- stream.write(dump.getBytes(StandardCharsets.UTF_8));
- }
+ try (final OutputStream stream = connection.getOutputStream()) {
+ stream.write(dump.getBytes(StandardCharsets.UTF_8));
+ }
- try (final InputStream stream = connection.getInputStream())
- {
- //noinspection UnstableApiUsage
- final String json = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8));
- return JsonParser.parseString(json).getAsJsonObject().get("key").getAsString();
- }
- }
- catch (final IOException ex)
- {
- throw new CompletionException(ex);
- }
- });
- }
+ try (final InputStream stream = connection.getInputStream()) {
+ //noinspection UnstableApiUsage
+ final String json = CharStreams
+ .toString(new InputStreamReader(stream, StandardCharsets.UTF_8));
+ return JsonParser.parseString(json).getAsJsonObject().get("key").getAsString();
+ }
+ } catch (final IOException ex) {
+ throw new CompletionException(ex);
+ }
+ });
+ }
- @NotNull
- private String makeDump(@NotNull final PlaceholderAPIPlugin plugin)
- {
- final StringBuilder builder = new StringBuilder();
+ @NotNull
+ private String makeDump(@NotNull final PlaceholderAPIPlugin plugin) {
+ final StringBuilder builder = new StringBuilder();
- builder.append("Generated: ")
- .append(DATE_FORMAT.format(Instant.now()))
- .append("\n\n");
+ builder.append("Generated: ")
+ .append(DATE_FORMAT.format(Instant.now()))
+ .append("\n\n");
- builder.append("PlaceholderAPI: ")
- .append(plugin.getDescription().getVersion())
- .append("\n\n");
+ builder.append("PlaceholderAPI: ")
+ .append(plugin.getDescription().getVersion())
+ .append("\n\n");
- builder.append("Expansions Registered:")
- .append('\n');
+ builder.append("Expansions Registered:")
+ .append('\n');
+ final List expansions = plugin.getLocalExpansionManager()
+ .getExpansions()
+ .stream()
+ .sorted(Comparator.comparing(PlaceholderExpansion::getIdentifier))
+ .sorted(Comparator.comparing(PlaceholderExpansion::getAuthor))
+ .collect(Collectors.toList());
- final Map> expansions = plugin.getLocalExpansionManager()
- .getExpansions()
- .stream()
- .collect(Collectors.groupingBy(PlaceholderExpansion::getAuthor));
+ int size = 0;
- for (final Map.Entry> expansionsByAuthor : expansions.entrySet())
- {
- builder.append(" ")
- .append(expansionsByAuthor.getKey())
- .append(": ")
- .append('\n');
+ for (final String name : expansions.stream().map(PlaceholderExpansion::getIdentifier)
+ .collect(Collectors.toList())) {
+ if (name.length() > size) {
+ size = name.length();
+ }
+ }
- for (final PlaceholderExpansion expansion : expansionsByAuthor.getValue())
- {
- builder.append(" ")
- .append(expansion.getName())
- .append(':')
- .append(expansion.getVersion())
- .append('\n');
- }
- }
+ for (final PlaceholderExpansion expansion : expansions) {
+ builder.append(" ")
+ .append(String.format("%-" + size + "s", expansion.getIdentifier()))
+ .append(" [Author: ")
+ .append(expansion.getAuthor())
+ .append(", Version: ")
+ .append(expansion.getVersion())
+ .append("]\n");
- builder.append('\n');
+ }
- builder.append("Expansions Directory:")
- .append('\n');
+ builder.append('\n');
- final String[] jars = plugin.getLocalExpansionManager()
- .getExpansionsFolder()
- .list((dir, name) -> name.toLowerCase().endsWith(".jar"));
+ builder.append("Expansions Directory:")
+ .append('\n');
- for (final String jar : jars)
- {
- builder.append(" ")
- .append(jar)
- .append('\n');
- }
+ final String[] jars = plugin.getLocalExpansionManager()
+ .getExpansionsFolder()
+ .list((dir, name) -> name.toLowerCase().endsWith(".jar"));
- builder.append('\n');
+ for (final String jar : jars) {
+ builder.append(" ")
+ .append(jar)
+ .append('\n');
+ }
+ builder.append('\n');
- builder.append("Server Info: ")
- .append(plugin.getServer().getBukkitVersion())
- .append('/')
- .append(plugin.getServer().getVersion())
- .append("\n\n");
+ builder.append("Server Info: ")
+ .append(plugin.getServer().getBukkitVersion())
+ .append('/')
+ .append(plugin.getServer().getVersion())
+ .append("\n\n");
- builder.append("Plugin Info:")
- .append('\n');
+ builder.append("Plugin Info:")
+ .append('\n');
- for (final Plugin other : plugin.getServer().getPluginManager().getPlugins())
- {
- builder.append(" ")
- .append(other.getName())
- .append(": ")
- .append(other.getDescription().getVersion())
- .append('\n');
- }
+ List plugins = Arrays.stream(plugin.getServer().getPluginManager().getPlugins())
+ .sorted(Comparator.comparing(Plugin::getName))
+ .collect(Collectors.toList());
- return builder.toString();
- }
+ for (final String pluginName : plugins.stream().map(Plugin::getName)
+ .collect(Collectors.toList())) {
+ if (pluginName.length() > size) {
+ size = pluginName.length();
+ }
+ }
+ for (final Plugin other : plugins) {
+ builder.append(" ")
+ .append(String.format("%-" + size + "s", other.getName()))
+ .append(" [Version: ")
+ .append(other.getDescription().getVersion())
+ .append("]")
+ .append("\n");
+ }
+
+ return builder.toString();
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionRegister.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionRegister.java
index f884c82..84cf1bf 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionRegister.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionRegister.java
@@ -20,6 +20,11 @@
package me.clip.placeholderapi.commands.impl.local;
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.logging.Level;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
@@ -30,88 +35,76 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-import java.util.logging.Level;
+public final class CommandExpansionRegister extends PlaceholderCommand {
-public final class CommandExpansionRegister extends PlaceholderCommand
-{
+ public CommandExpansionRegister() {
+ super("register");
+ }
- public CommandExpansionRegister()
- {
- super("register");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ if (params.size() < 1) {
+ Msg.msg(sender,
+ "&cYou must specify the name of an expansion file.");
+ return;
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- if (params.size() < 1)
- {
- Msg.msg(sender,
- "&cYou must specify the name of an expansion file.");
- return;
- }
+ final LocalExpansionManager manager = plugin.getLocalExpansionManager();
+ final File file = new File(manager.getExpansionsFolder(), params.get(0));
+ if (!file.exists()) {
+ Msg.msg(sender,
+ "&cThe file &f" + file.getName() + "&c doesn't exist!");
+ return;
+ }
- final LocalExpansionManager manager = plugin.getLocalExpansionManager();
+ Futures.onMainThread(plugin, manager.findExpansionInFile(file), (clazz, exception) -> {
+ if (exception != null) {
+ Msg.msg(sender,
+ "&cFailed to find expansion in file: &f" + file);
- final File file = new File(manager.getExpansionsFolder(), params.get(0));
- if (!file.exists())
- {
- Msg.msg(sender,
- "&cThe file &f" + file.getName() + "&c doesn't exist!");
- return;
- }
+ plugin.getLogger()
+ .log(Level.WARNING, "failed to find expansion in file: " + file, exception);
+ return;
+ }
- Futures.onMainThread(plugin, manager.findExpansionInFile(file), (clazz, exception) -> {
- if (exception != null)
- {
- Msg.msg(sender,
- "&cFailed to find expansion in file: &f" + file);
+ if (clazz == null) {
+ Msg.msg(sender,
+ "&cNo expansion class found in file: &f" + file);
+ return;
+ }
- plugin.getLogger().log(Level.WARNING, "failed to find expansion in file: " + file, exception);
- return;
- }
+ final Optional expansion = manager.register(clazz);
+ if (!expansion.isPresent()) {
+ Msg.msg(sender,
+ "&cFailed to register expansion from &f" + params.get(0));
+ return;
+ }
- if (clazz == null)
- {
- Msg.msg(sender,
- "&cNo expansion class found in file: &f" + file);
- return;
- }
+ Msg.msg(sender,
+ "&aSuccessfully registered expansion: &f" + expansion.get().getName());
+ });
+ }
- final Optional expansion = manager.register(clazz);
- if (!expansion.isPresent())
- {
- Msg.msg(sender,
- "&cFailed to register expansion from &f" + params.get(0));
- return;
- }
+ @Override
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
+ if (params.size() > 1) {
+ return;
+ }
- Msg.msg(sender,
- "&aSuccessfully registered expansion: &f" + expansion.get().getName());
+ final String[] fileNames = plugin.getLocalExpansionManager().getExpansionsFolder()
+ .list((dir, name) -> name.endsWith(".jar"));
+ if (fileNames == null || fileNames.length == 0) {
+ return;
+ }
- });
- }
-
- @Override
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
- if (params.size() > 1)
- {
- return;
- }
-
- final String[] fileNames = plugin.getLocalExpansionManager().getExpansionsFolder().list((dir, name) -> name.endsWith(".jar"));
- if (fileNames == null || fileNames.length == 0)
- {
- return;
- }
-
- suggestByParameter(Arrays.stream(fileNames), suggestions, params.isEmpty() ? null : params.get(0));
- }
+ suggestByParameter(Arrays.stream(fileNames), suggestions,
+ params.isEmpty() ? null : params.get(0));
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionUnregister.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionUnregister.java
index 6cd32ed..4b59fac 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionUnregister.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionUnregister.java
@@ -20,6 +20,8 @@
package me.clip.placeholderapi.commands.impl.local;
+import java.util.List;
+import java.util.Optional;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
@@ -29,52 +31,47 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
-import java.util.Optional;
+public final class CommandExpansionUnregister extends PlaceholderCommand {
-public final class CommandExpansionUnregister extends PlaceholderCommand
-{
+ public CommandExpansionUnregister() {
+ super("unregister");
+ }
- public CommandExpansionUnregister()
- {
- super("unregister");
- }
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ if (params.isEmpty()) {
+ Msg.msg(sender,
+ "&cYou must specify the name of the expansion.");
+ return;
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- if (params.isEmpty())
- {
- Msg.msg(sender,
- "&cYou must specify the name of the expansion.");
- return;
- }
+ final Optional expansion = plugin.getLocalExpansionManager()
+ .findExpansionByName(params.get(0));
+ if (!expansion.isPresent()) {
+ Msg.msg(sender,
+ "&cThere is no expansion loaded with the identifier: &f" + params.get(0));
+ return;
+ }
- final Optional expansion = plugin.getLocalExpansionManager().findExpansionByName(params.get(0));
- if (!expansion.isPresent())
- {
- Msg.msg(sender,
- "&cThere is no expansion loaded with the identifier: &f" + params.get(0));
- return;
- }
+ final String message = !expansion.get().unregister() ?
+ "&cFailed to unregister expansion: &f" :
+ "&aSuccessfully unregistered expansion: &f";
+ Msg.msg(sender, message + expansion.get().getName());
+ }
- final String message = !expansion.get().unregister() ?
- "&cFailed to unregister expansion: &f" :
- "&aSuccessfully unregistered expansion: &f";
+ @Override
+ public void complete(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params, @NotNull final List suggestions) {
+ if (params.size() > 1) {
+ return;
+ }
- Msg.msg(sender, message + expansion.get().getName());
- }
-
- @Override
- public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions)
- {
- if (params.size() > 1)
- {
- return;
- }
-
- suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions, params.isEmpty() ? null : params.get(0));
- }
+ suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions,
+ params.isEmpty() ? null : params.get(0));
+ }
}
diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandHelp.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandHelp.java
index c1a56de..d43e2fe 100644
--- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandHelp.java
+++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandHelp.java
@@ -20,6 +20,7 @@
package me.clip.placeholderapi.commands.impl.local;
+import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -28,47 +29,44 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
-import java.util.List;
+public final class CommandHelp extends PlaceholderCommand {
-public final class CommandHelp extends PlaceholderCommand
-{
-
- public CommandHelp()
- {
- super("help");
- }
+ public CommandHelp() {
+ super("help");
+ }
- @Override
- public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params)
- {
- final PluginDescriptionFile description = plugin.getDescription();
+ @Override
+ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
+ @NotNull final CommandSender sender, @NotNull final String alias,
+ @NotNull @Unmodifiable final List params) {
+ final PluginDescriptionFile description = plugin.getDescription();
- Msg.msg(sender,
- "&b&lPlaceholderAPI &8- &7Help Menu &8- &7(&f" + description.getVersion() + "&7)",
- " ",
- "&b/papi &fversion",
- " &7&oView plugin info/version",
- "&b/papi &freload",
- " &7&oReload the config of PAPI",
- "&b/papi &flist",
- " &7&oList active expansions",
- "&b/papi &finfo &9",
- " &7&oView information for a specific expansion",
- "&b/papi &fparse &9 ",
- " &7&oParse a message with placeholders",
- "&b/papi &fbcparse &9 ",
- " &7&oParse a message with placeholders and broadcast it",
- "&b/papi &fparserel &9 ",
- " &7&oParse a message with relational placeholders",
- "&b/papi &fcmdparse &9 ",
- " &7&oParse a message with relational placeholders",
- "&b/papi &fregister &9",
- " &7&oRegister an expansion by the name of the file",
- "&b/papi &funregister &9",
- " &7&oUnregister an expansion by name",
- "&b/papi &fdump",
- " &7&oDump all relevant information needed to help debug issues into a paste link.");
- }
+ Msg.msg(sender,
+ "&b&lPlaceholderAPI &8- &7Help Menu &8- &7(&f" + description.getVersion() + "&7)",
+ " ",
+ "&b/papi &fbcparse &9 ",
+ " &7&oParse a message with placeholders and broadcast it",
+ "&b/papi &fcmdparse &9 ",
+ " &7&oParse a message with relational placeholders",
+ "&b/papi &fdump",
+ " &7&oDump all relevant information needed to help debug issues into a paste link.",
+ "&b/papi &finfo &9",
+ " &7&oView information for a specific expansion",
+ "&b/papi &flist",
+ " &7&oList active expansions",
+ "&b/papi &fparse &9