mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-09-06 05:17:05 +02:00
Compare commits
98 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fc1a2af011 | ||
|
82e92ce777 | ||
|
9b317c2210 | ||
|
927f942236 | ||
|
75c3027e05 | ||
|
a2d408aea9 | ||
|
5386b7c23d | ||
|
a741f35139 | ||
|
1e25f35aac | ||
|
3042e49ddb | ||
|
6495a386a0 | ||
|
cee214cc98 | ||
|
41390d8ef4 | ||
|
c0f6cf225f | ||
|
16d0a4f690 | ||
|
8f600aec25 | ||
|
2c15b4dfcf | ||
|
b943c6fd21 | ||
|
15b142ed64 | ||
|
b2a488c694 | ||
|
8447395c7b | ||
|
0ad11cd755 | ||
|
29c61373b0 | ||
|
e53cad219e | ||
|
c7d05eff24 | ||
|
540a0952e7 | ||
|
cef0a203dc | ||
|
8f1ba895b2 | ||
|
4d570aa526 | ||
|
4c127f325b | ||
|
71f5e11b03 | ||
|
1129f3d902 | ||
|
84a8029d7d | ||
|
dd6d90dbb6 | ||
|
0df9eeb2cc | ||
|
05ce2fb5bf | ||
|
cb7fbb7820 | ||
|
ce5bb28247 | ||
|
639b7967e3 | ||
|
90bc3c8da1 | ||
|
556faf4290 | ||
|
4af2a1c7be | ||
|
6ff7be5d64 | ||
|
80c6a6d377 | ||
|
27f8586d76 | ||
|
d0b4669d1f | ||
|
c205a9a1b9 | ||
|
ce1ca35ee5 | ||
|
0bfd42d607 | ||
|
197aa5dfe0 | ||
|
efa97ce049 | ||
|
e2423cdd70 | ||
|
0d30c8ac50 | ||
|
589712f7e4 | ||
|
dd5ec37055 | ||
|
49eceaae50 | ||
|
7ea2bd94a7 | ||
|
736b8ada3d | ||
|
d08de32852 | ||
|
83e64ee883 | ||
|
27ca32b14c | ||
|
838f947a05 | ||
|
efc6a6337b | ||
|
9cc5a9678f | ||
|
bc915af13e | ||
|
43b8013c29 | ||
|
adca215ea7 | ||
|
d0445e231d | ||
|
be96238800 | ||
|
0f51b4f2a5 | ||
|
287ab16d3a | ||
|
e4a672e57e | ||
|
46839c4bf2 | ||
|
2894d525f2 | ||
|
53fb678035 | ||
|
86a1fe862f | ||
|
eba181d04d | ||
|
25758ee653 | ||
|
a50212e395 | ||
|
cfccc69839 | ||
|
659af4833e | ||
|
e1ba07b7bd | ||
|
d5146ea3e5 | ||
|
3a5e3ed950 | ||
|
763c0aabc1 | ||
|
6eaad829cf | ||
|
dd45bc16d0 | ||
|
7900ee71e0 | ||
|
6825c9afc1 | ||
|
1a905f88a9 | ||
|
796136982a | ||
|
3ada9d988b | ||
|
1504972e51 | ||
|
1789c3b183 | ||
|
e336eccd9a | ||
|
d256286a02 | ||
|
81aaef2319 | ||
|
b7003c5142 |
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: Bug Report
|
||||
about: Found a bug with PlaceholderAPI? Report it through this form!
|
||||
|
||||
---
|
||||
|
||||
[New placeholders/plugin]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?template=feature_request.md
|
||||
[Request change]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?template=change_request.md
|
||||
[Spigot page]: https://www.spigotmc.org/resources/6245/
|
||||
[Jenkins page]: http://ci.extendedclip.com/job/PlaceholderAPI/
|
||||
[issue]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
|
||||
|
||||
### Notes
|
||||
This template is for **reporting a bug** and not for requesting changes to the wiki!
|
||||
If you want your placeholders added or updated, use the [New placeholders/plugin] or [Request change] template.
|
||||
|
||||
Also make sure, that you use the latest version of PlaceholderAPI from either the [Spigot page] or the [Jenkins page] and that your
|
||||
issue isn't already listed in the [issue] page.
|
||||
|
||||
### Issue
|
||||
> What is the issue? Describe it like you would tell a friend.
|
||||
<!-- Please type below this like -->
|
||||
|
||||
|
||||
### Expected behaviour
|
||||
> What should PlaceholderAPI do?
|
||||
<!-- Please type below this like -->
|
||||
|
||||
|
||||
### Actual behaviour
|
||||
> What does PlaceholderAPI actually do?
|
||||
<!-- Please type below this like -->
|
||||
|
||||
|
||||
### How to reproduce
|
||||
> What steps did you made, to get this bug?
|
||||
<!-- Please type below this like -->
|
||||
1.
|
36
.github/ISSUE_TEMPLATE/change_request.md
vendored
Normal file
36
.github/ISSUE_TEMPLATE/change_request.md
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
name: Request change
|
||||
about: Request a update/change of a wiki-page
|
||||
|
||||
---
|
||||
|
||||
[New placeholders/plugin]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?template=feature_request.md
|
||||
[Bug report]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?template=bug_report.md
|
||||
[issues]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
|
||||
[wiki]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki
|
||||
|
||||
### Notes
|
||||
This template is for **requesting changes to the wiki** and not for reporting bugs or requesting additions for the wiki!
|
||||
If you want your placeholders added, use the [New placeholders/plugin] template.
|
||||
For bug reports, use the [Bug report] template.
|
||||
|
||||
Also make sure, that your requested change isn't already made in the [wiki] or listed in the [issues] page.
|
||||
|
||||
### Type
|
||||
> What kind of change is it? (Multiple selections possible)
|
||||
<!-- Please select the right one, by changing the [ ] to [x] -->
|
||||
|
||||
- [ ] Placeholder(s) changed.
|
||||
- [ ] New placeholder(s).
|
||||
- [ ] Plugin no longer supports PlaceholderAPI and/or was deleted.
|
||||
|
||||
### Plugin
|
||||
> What is the name of the plugin?
|
||||
<!-- Please type below this line -->
|
||||
|
||||
|
||||
### What is the new value?
|
||||
> **Placeholder(s) changed**: Type what the old and the new placeholder(s) is/are.
|
||||
> **New Placeholder(s)**: Type the new placeholder(s).
|
||||
> **Plugin no longer supports PlaceholderAPI**: Leave this blank.
|
||||
<!-- Please type below this line -->
|
35
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
35
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
name: New placeholders/plugin
|
||||
about: Do you have a plugin that supports and/or adds placeholders from/to PlaceholderAPI and that isn't on the wiki? Use this template!
|
||||
|
||||
---
|
||||
|
||||
[Request change]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?template=change_request.md
|
||||
[Bug report]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?template=bug_report.md
|
||||
[issues]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
|
||||
[wiki]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki
|
||||
|
||||
### Notes
|
||||
This template is for **requesting additions for the wiki** and not for reporting bugs or requesting changes for the wiki!
|
||||
If you want changes to be made to the wiki, use the [Request change] template.
|
||||
For bug reports, use the [Bug report] template.
|
||||
|
||||
Also make sure, that your requested placeholders/plugin isn't already added in the [wiki] or listed in the [issues] page.
|
||||
|
||||
### Type
|
||||
> What kind of request is this? (Multiple selections possible)
|
||||
<!-- Select the right option by replacing [ ] with [x] -->
|
||||
<!-- For an update of an already listed plugin, use the "Request change" template -->
|
||||
|
||||
- [ ] New expansion providing placeholders.
|
||||
- [ ] New plugin providing placeholders.
|
||||
- [ ] New plugin supporting PlaceholderAPI.
|
||||
|
||||
### Plugin
|
||||
> What is the name of the plugin/expansion?
|
||||
> Provide also a link to it.
|
||||
<!-- Please type below this line -->
|
||||
|
||||
### Placeholders/others
|
||||
> What are the new placeholders/Any additional info?
|
||||
<!-- Please type below this line -->
|
4
.gitignore
vendored
4
.gitignore
vendored
@@ -114,7 +114,7 @@ fabric.properties
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
*.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
@@ -143,4 +143,4 @@ nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
nbactions.xml
|
||||
nbactions.xml
|
||||
|
41
README.md
41
README.md
@@ -1,6 +1,26 @@
|
||||
[][spigot]
|
||||
[issues]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
|
||||
[licenseImg]: https://img.shields.io/github/license/PlaceholderAPI/PlaceholderAPI.svg
|
||||
[license]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/LICENSE
|
||||
|
||||
[][ci]
|
||||
[releaseImg]: https://img.shields.io/github/release/PlaceholderAPI/PlaceholderAPI.svg?label=github%20release
|
||||
[release]: https://github.com/PlaceholderAPI/PlaceholderAPI/releases/latest
|
||||
|
||||
[discord]: https://helpch.at/discord
|
||||
[spigot]: https://www.spigotmc.org/resources/6245/
|
||||
[Expansions cloud]: https://api.extendedclip.com/home
|
||||
[placeholder list]: https://helpch.at/placeholders
|
||||
[statistics]: https://bstats.org/plugin/bukkit/PlaceholderAPI
|
||||
|
||||
[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
|
||||
[logo]: https://i.imgur.com/Ea4PURv.png
|
||||
<!-- The stuff above isn't visible in the readme -->
|
||||
|
||||
[![logo]][spigot]
|
||||
|
||||
[![ciImg]][ci] [![releaseImg]][release] ![APIversionImg] [![licenseImg]][license]
|
||||
|
||||
# Information
|
||||
[PlaceholderAPI][spigot] is a plugin for Spigot servers that allows server owners to display information from various plugins with a uniform format.
|
||||
@@ -18,20 +38,7 @@ PlaceholderAPI has been downloaded over 100,000 times and has been used concurre
|
||||
|
||||
## Quick Links
|
||||
- [CI Server][ci]
|
||||
- [Expansions Website][expansions]
|
||||
- [Placeholder List][placeholder-list]
|
||||
- [Expansions cloud]
|
||||
- [Placeholder List]
|
||||
- [Spigot Page][spigot]
|
||||
- [Plugin Statistics][statistics]
|
||||
|
||||
## License
|
||||
PlaceholderAPI is licensed under the __GNU GPLv3__ license. Refer to the [LICENSE](LICENSE) file for more information.
|
||||
|
||||
<!-- Page Links - Placed here to be easier to change later on. -->
|
||||
|
||||
[issues]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
|
||||
[discord]: https://discord.gg/7sndK3q
|
||||
[spigot]: https://www.spigotmc.org/resources/placeholderapi.6245/
|
||||
[ci]: http://ci.extendedclip.com/job/PlaceholderAPI/
|
||||
[expansions]: https://api.extendedclip.com/all/
|
||||
[placeholder-list]: https://www.spigotmc.org/wiki/placeholderapi-placeholders/
|
||||
[statistics]: https://bstats.org/plugin/bukkit/PlaceholderAPI
|
||||
|
215
pom.xml
215
pom.xml
@@ -1,108 +1,119 @@
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<version>2.8.6</version>
|
||||
<name>PlaceholderAPI</name>
|
||||
<description>An awesome placeholder provider!</description>
|
||||
<url>http://extendedclip.com</url>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<version>2.10.1</version>
|
||||
<name>PlaceholderAPI</name>
|
||||
<description>An awesome placeholder provider!</description>
|
||||
<url>http://extendedclip.com</url>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bstats-repo</id>
|
||||
<url>http://repo.bstats.org/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>rayzr-repo</id>
|
||||
<url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.rayzr522</groupId>
|
||||
<artifactId>jsonmessage</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bstats-repo</id>
|
||||
<url>http://repo.bstats.org/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>rayzr-repo</id>
|
||||
<url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.rayzr522</groupId>
|
||||
<artifactId>jsonmessage</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.clip.placeholderapi.metrics</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>me.rayzr522</pattern>
|
||||
<shadedPattern>me.clip.placeholderapi.util</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.clip.placeholderapi.metrics</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>me.rayzr522</pattern>
|
||||
<shadedPattern>me.clip.placeholderapi.util</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.google.code.gson</pattern>
|
||||
<shadedPattern>me.clip.placeholderapi.libs.gson</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
||||
|
@@ -20,304 +20,372 @@
|
||||
*/
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import static me.clip.placeholderapi.util.Msg.color;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import me.clip.placeholderapi.events.ExpansionRegisterEvent;
|
||||
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
|
||||
import me.clip.placeholderapi.events.PlaceholderHookUnloadEvent;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Relational;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlaceholderAPI {
|
||||
|
||||
private PlaceholderAPI() {
|
||||
}
|
||||
|
||||
private final static Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
|
||||
private final static Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]");
|
||||
private final static Pattern RELATIONAL_PLACEHOLDER_PATTERN = Pattern.compile("[%](rel_)([^%]+)[%]");
|
||||
private final static Map<String, PlaceholderHook> placeholders = new HashMap<>();
|
||||
|
||||
/**
|
||||
* check if a specific placeholder identifier is currently registered
|
||||
* @param identifier to check
|
||||
* @return true if identifier is already registered
|
||||
*/
|
||||
public static boolean isRegistered(String identifier) {
|
||||
return !placeholders.isEmpty() && getRegisteredIdentifiers().stream().filter(id -> id.equalsIgnoreCase(identifier)).findFirst().orElse(null) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new placeholder hook
|
||||
* @param identifier Identifier of the placeholder -> "%(identifier)_(args...)%
|
||||
*
|
||||
* @param placeholderHook implementing class that contains the onPlaceholderRequest method which is called when a value is needed for the specific placeholder
|
||||
* @return true if the hook was successfully registered, false if there is already a hook registered for the specified identifier
|
||||
*/
|
||||
public static boolean registerPlaceholderHook(String identifier, PlaceholderHook placeholderHook) {
|
||||
Validate.notNull(identifier, "Identifier can not be null");
|
||||
Validate.notNull(placeholderHook, "Placeholderhook can not be null");
|
||||
if (isRegistered(identifier)) return false;
|
||||
placeholders.put(identifier.toLowerCase(), placeholderHook);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister a placeholder hook by identifier
|
||||
* @param identifier the identifier for the placeholder hook to unregister
|
||||
* @return true if the placeholder hook was successfully unregistered, false if there was no placeholder hook registered for the identifier specified
|
||||
*/
|
||||
public static boolean unregisterPlaceholderHook(String identifier) {
|
||||
Validate.notNull(identifier, "Identifier can not be null");
|
||||
return placeholders.remove(identifier.toLowerCase()) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all registered placeholder identifiers
|
||||
* @return all registered placeholder identifiers
|
||||
*/
|
||||
public static Set<String> getRegisteredIdentifiers() {
|
||||
if (placeholders.isEmpty()) return new HashSet<>();
|
||||
return new HashSet<>(placeholders.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get map of registered placeholders
|
||||
* @return copy of the internal placeholder map
|
||||
*/
|
||||
public static Map<String, PlaceholderHook> getPlaceholders() {
|
||||
return new HashMap<>(placeholders);
|
||||
}
|
||||
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
|
||||
private static final Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]");
|
||||
private static final Pattern RELATIONAL_PLACEHOLDER_PATTERN = Pattern.compile("[%](rel_)([^%]+)[%]");
|
||||
private static final Map<String, PlaceholderHook> placeholders = new HashMap<>();
|
||||
|
||||
public static Set<PlaceholderExpansion> getExpansions() {
|
||||
return getPlaceholders().values().stream().filter(PlaceholderExpansion.class::isInstance).map(PlaceholderExpansion.class::cast).collect(Collectors.toCollection(HashSet::new));
|
||||
private PlaceholderAPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a specific placeholder identifier is currently registered
|
||||
*
|
||||
* @param identifier to check
|
||||
* @return true if identifier is already registered
|
||||
*/
|
||||
public static boolean isRegistered(String identifier) {
|
||||
return getRegisteredIdentifiers().stream().filter(id -> id.equalsIgnoreCase(identifier))
|
||||
.findFirst().orElse(null) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new placeholder hook
|
||||
*
|
||||
* @param identifier Identifier of the placeholder -> "%(identifier)_(args...)%
|
||||
* @param placeholderHook implementing class that contains the onPlaceholderRequest method which
|
||||
* is called when a value is needed for the specific placeholder
|
||||
* @return true if the hook was successfully registered, false if there is already a hook
|
||||
* registered for the specified identifier
|
||||
*/
|
||||
public static boolean registerPlaceholderHook(String identifier,
|
||||
PlaceholderHook placeholderHook) {
|
||||
Validate.notNull(identifier, "Identifier can not be null");
|
||||
Validate.notNull(placeholderHook, "Placeholderhook can not be null");
|
||||
if (isRegistered(identifier)) {
|
||||
return false;
|
||||
}
|
||||
placeholders.put(identifier.toLowerCase(), placeholderHook);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a String contains any PlaceholderAPI placeholders
|
||||
* @param text String to check
|
||||
* @return true if String contains any registered placeholder identifiers, false otherwise
|
||||
*/
|
||||
public static boolean containsPlaceholders(String text) {
|
||||
return text != null && PLACEHOLDER_PATTERN.matcher(text).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a String contains any PlaceholderAPI bracket placeholders
|
||||
* @param text String to check
|
||||
* @return true if String contains any registered placeholder identifiers, false otherwise
|
||||
*/
|
||||
public static boolean containsBracketPlaceholders(String text) {
|
||||
return text != null && BRACKET_PLACEHOLDER_PATTERN.matcher(text).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the list<String> text provided
|
||||
* placeholders are matched with the pattern {<placeholder>} when set with this method
|
||||
* @param p Player to parse the placeholders for
|
||||
* @param text text to set the placeholder values in
|
||||
* @return modified list with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static List<String> setBracketPlaceholders(Player p, List<String> text) {
|
||||
return setPlaceholders(p, text, BRACKET_PLACEHOLDER_PATTERN);
|
||||
}
|
||||
/**
|
||||
* unregister a placeholder hook by identifier
|
||||
*
|
||||
* @param identifier the identifier for the placeholder hook to unregister
|
||||
* @return true if the placeholder hook was successfully unregistered, false if there was no
|
||||
* placeholder hook registered for the identifier specified
|
||||
*/
|
||||
public static boolean unregisterPlaceholderHook(String identifier) {
|
||||
Validate.notNull(identifier, "Identifier can not be null");
|
||||
return placeholders.remove(identifier.toLowerCase()) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the list<String> text provided
|
||||
* placeholders are matched with the pattern %(identifier)_(params)>% when set with this method
|
||||
* @param p Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values in
|
||||
* @return modified list with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static List<String> setPlaceholders(Player p, List<String> text) {
|
||||
return setPlaceholders(p, text, PLACEHOLDER_PATTERN);
|
||||
}
|
||||
/**
|
||||
* Get all registered placeholder identifiers
|
||||
*
|
||||
* @return all registered placeholder identifiers
|
||||
*/
|
||||
public static Set<String> getRegisteredIdentifiers() {
|
||||
return ImmutableSet.copyOf(placeholders.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the list<String> text provided
|
||||
* placeholders are matched with the pattern %(identifier)_(params)>% when set with this method
|
||||
* @param p Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values in
|
||||
* @return modified list with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static List<String> setPlaceholders(Player p, List<String> text, Pattern pattern) {
|
||||
if (text == null) return null;
|
||||
List<String> temp = new ArrayList<>();
|
||||
text.forEach(line -> {
|
||||
temp.add(setPlaceholders(p, line, pattern));
|
||||
});
|
||||
return temp;
|
||||
/**
|
||||
* Get map of registered placeholders
|
||||
*
|
||||
* @return copy of the internal placeholder map
|
||||
*/
|
||||
public static Map<String, PlaceholderHook> getPlaceholders() {
|
||||
return ImmutableMap.copyOf(placeholders);
|
||||
}
|
||||
|
||||
public static Set<PlaceholderExpansion> getExpansions() {
|
||||
Set<PlaceholderExpansion> set = getPlaceholders().values().stream()
|
||||
.filter(PlaceholderExpansion.class::isInstance).map(PlaceholderExpansion.class::cast)
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
return ImmutableSet.copyOf(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a String contains any PlaceholderAPI placeholders
|
||||
*
|
||||
* @param text String to check
|
||||
* @return true if String contains any registered placeholder identifiers, false otherwise
|
||||
*/
|
||||
public static boolean containsPlaceholders(String text) {
|
||||
return text != null && PLACEHOLDER_PATTERN.matcher(text).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a String contains any PlaceholderAPI bracket placeholders
|
||||
*
|
||||
* @param text String to check
|
||||
* @return true if String contains any registered placeholder identifiers, false otherwise
|
||||
*/
|
||||
public static boolean containsBracketPlaceholders(String text) {
|
||||
return text != null && BRACKET_PLACEHOLDER_PATTERN.matcher(text).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the list<String> text provided placeholders are matched with the pattern
|
||||
* {<placeholder>} when set with this method
|
||||
*
|
||||
* @param p Player to parse the placeholders for
|
||||
* @param text text to set the placeholder values in
|
||||
* @return modified list with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static List<String> setBracketPlaceholders(OfflinePlayer p, List<String> text) {
|
||||
return setPlaceholders(p, text, BRACKET_PLACEHOLDER_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the list<String> text provided placeholders are matched with the pattern
|
||||
* %(identifier)_(params)>% when set with this method
|
||||
*
|
||||
* @param p Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values in
|
||||
* @return modified list with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static List<String> setPlaceholders(OfflinePlayer p, List<String> text) {
|
||||
return setPlaceholders(p, text, PLACEHOLDER_PATTERN);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set placeholders in the list<String> text provided placeholders are matched with the pattern
|
||||
* %(identifier)_(params)>% when set with this method
|
||||
*
|
||||
* @param p Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values in
|
||||
* @return modified list with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static List<String> setPlaceholders(OfflinePlayer p, List<String> text, Pattern pattern) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
return text.stream().map(line -> setPlaceholders(p, line, pattern))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the text specified
|
||||
* placeholders are matched with the pattern {<placeholder>} when set with this method
|
||||
* @param player Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return modified text with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setBracketPlaceholders(Player player, String text) {
|
||||
return setPlaceholders(player, text, BRACKET_PLACEHOLDER_PATTERN);
|
||||
/**
|
||||
* set placeholders in the text specified placeholders are matched with the pattern
|
||||
* {<placeholder>} when set with this method
|
||||
*
|
||||
* @param player Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return modified text with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setBracketPlaceholders(OfflinePlayer player, String text) {
|
||||
return setPlaceholders(player, text, BRACKET_PLACEHOLDER_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the text specified placeholders are matched with the pattern
|
||||
* %<(identifier)_(params)>% when set with this method
|
||||
*
|
||||
* @param player Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return text with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setPlaceholders(OfflinePlayer player, String text) {
|
||||
return setPlaceholders(player, text, PLACEHOLDER_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the text specified placeholders are matched with the pattern
|
||||
* %<(identifier)_(params)>% when set with this method
|
||||
*
|
||||
* @param player Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values to
|
||||
* @param placeholderPattern the pattern to match placeholders to. Capture group 1 must contain an
|
||||
* underscore separating the identifier from the params
|
||||
* @return text with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setPlaceholders(OfflinePlayer player, String text,
|
||||
Pattern placeholderPattern) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the text specified
|
||||
* placeholders are matched with the pattern %<(identifier)_(params)>% when set with this method
|
||||
* @param player Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return text with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setPlaceholders(Player player, String text) {
|
||||
return setPlaceholders(player, text, PLACEHOLDER_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
* set placeholders in the text specified
|
||||
* placeholders are matched with the pattern %<(identifier)_(params)>% when set with this method
|
||||
* @param player Player to parse the placeholders for
|
||||
* @param text text to parse the placeholder values to
|
||||
* @param placeholderPattern the pattern to match placeholders to. Capture group 1 must contain an underscore separating the identifier from the params
|
||||
* @return text with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setPlaceholders(Player player, String text, Pattern placeholderPattern) {
|
||||
if (text == null) return null;
|
||||
if (placeholders.isEmpty()) return colorize(text);
|
||||
Matcher m = placeholderPattern.matcher(text);
|
||||
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
||||
while (m.find()) {
|
||||
String format = m.group(1);
|
||||
int index = format.indexOf("_");
|
||||
if (index <= 0 || index >= format.length()) continue;
|
||||
String identifier = format.substring(0, index).toLowerCase();
|
||||
String params = format.substring(index+1);
|
||||
if (hooks.containsKey(identifier)) {
|
||||
String value = hooks.get(identifier).onPlaceholderRequest(player, params);
|
||||
if (value != null) {
|
||||
text = text.replaceAll(Pattern.quote(m.group()), Matcher.quoteReplacement(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
return colorize(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* set relational placeholders in the text specified
|
||||
* placeholders are matched with the pattern %<rel_(identifier)_(params)>% when set with this method
|
||||
* @param one Player to compare
|
||||
* @param two Player to compare
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return text with all relational placeholders set to the corresponding values
|
||||
*/
|
||||
public static List<String> setRelationalPlaceholders(Player one, Player two, List<String> text) {
|
||||
if (text == null) return null;
|
||||
List<String> temp = new ArrayList<>();
|
||||
text.forEach(line -> {
|
||||
temp.add(setRelationalPlaceholders(one, two, line));
|
||||
});
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* set relational placeholders in the text specified
|
||||
* placeholders are matched with the pattern %<rel_(identifier)_(params)>% when set with this method
|
||||
* @param one Player to compare
|
||||
* @param two Player to compare
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return text with all relational placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setRelationalPlaceholders(Player one, Player two, String text) {
|
||||
if (text == null) return null;
|
||||
if (placeholders.isEmpty()) return colorize(text);
|
||||
Matcher m = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
|
||||
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
||||
while (m.find()) {
|
||||
String format = m.group(2);
|
||||
int index = format.indexOf("_");
|
||||
if (index <= 0 || index >= format.length()) continue;
|
||||
String identifier = format.substring(0, index).toLowerCase();
|
||||
String params = format.substring(index+1);
|
||||
if (hooks.containsKey(identifier)) {
|
||||
if (!(hooks.get(identifier) instanceof Relational)) {
|
||||
continue;
|
||||
}
|
||||
Relational rel = (Relational) hooks.get(identifier);
|
||||
String value = rel.onPlaceholderRequest(one, two, params);
|
||||
if (value != null) {
|
||||
text = text.replaceAll(Pattern.quote(m.group()), Matcher.quoteReplacement(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
return colorize(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister ALL placeholder hooks that are currently registered
|
||||
*/
|
||||
protected static void unregisterAll() {
|
||||
unregisterAllProvidedExpansions();
|
||||
placeholders.clear();
|
||||
if (placeholders.isEmpty()) {
|
||||
return color(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister all expansions provided by PlaceholderAPI
|
||||
*/
|
||||
public static void unregisterAllProvidedExpansions() {
|
||||
if (placeholders.isEmpty()) return;
|
||||
getPlaceholders().forEach((key, value) -> {
|
||||
if (value instanceof PlaceholderExpansion) {
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) value;
|
||||
if (!ex.persist()) {
|
||||
unregisterExpansion(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean unregisterExpansion(PlaceholderExpansion ex) {
|
||||
if (unregisterPlaceholderHook(ex.getIdentifier())) {
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(ex));
|
||||
return true;
|
||||
Matcher m = placeholderPattern.matcher(text);
|
||||
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
||||
while (m.find()) {
|
||||
String format = m.group(1);
|
||||
int index = format.indexOf("_");
|
||||
if (index <= 0 || index >= format.length()) {
|
||||
continue;
|
||||
}
|
||||
String identifier = format.substring(0, index).toLowerCase();
|
||||
String params = format.substring(index + 1);
|
||||
if (hooks.containsKey(identifier)) {
|
||||
String value = hooks.get(identifier).onRequest(player, params);
|
||||
if (value != null) {
|
||||
text = text.replaceAll(Pattern.quote(m.group()), Matcher.quoteReplacement(value));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Pattern getPlaceholderPattern() {
|
||||
return PLACEHOLDER_PATTERN;
|
||||
}
|
||||
|
||||
public static Pattern getBracketPlaceholderPattern() {
|
||||
return BRACKET_PLACEHOLDER_PATTERN;
|
||||
}
|
||||
|
||||
public static Pattern getRelationalPlaceholderPattern() {
|
||||
return RELATIONAL_PLACEHOLDER_PATTERN;
|
||||
}
|
||||
|
||||
public static String colorize(String text) {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Set<String> getRegisteredPlaceholderPlugins() {
|
||||
return getRegisteredIdentifiers();
|
||||
}
|
||||
@Deprecated
|
||||
public static Set<String> getExternalPlaceholderPlugins() {
|
||||
return null;
|
||||
}
|
||||
@Deprecated
|
||||
public static boolean registerPlaceholderHook(Plugin plugin, PlaceholderHook placeholderHook) {
|
||||
return plugin != null && registerPlaceholderHook(plugin.getName(), placeholderHook);
|
||||
}
|
||||
@Deprecated
|
||||
public static boolean unregisterPlaceholderHook(Plugin plugin) {
|
||||
return plugin != null && unregisterPlaceholderHook(plugin.getName());
|
||||
}
|
||||
return color(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* set relational placeholders in the text specified placeholders are matched with the pattern
|
||||
* %<rel_(identifier)_(params)>% when set with this method
|
||||
*
|
||||
* @param one Player to compare
|
||||
* @param two Player to compare
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return text with all relational placeholders set to the corresponding values
|
||||
*/
|
||||
public static List<String> setRelationalPlaceholders(Player one, Player two, List<String> text) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* set relational placeholders in the text specified placeholders are matched with the pattern
|
||||
* %<rel_(identifier)_(params)>% when set with this method
|
||||
*
|
||||
* @param one Player to compare
|
||||
* @param two Player to compare
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return text with all relational placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setRelationalPlaceholders(Player one, Player two, String text) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholders.isEmpty()) {
|
||||
return color(text);
|
||||
}
|
||||
Matcher m = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
|
||||
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
||||
while (m.find()) {
|
||||
String format = m.group(2);
|
||||
int index = format.indexOf("_");
|
||||
if (index <= 0 || index >= format.length()) {
|
||||
continue;
|
||||
}
|
||||
String identifier = format.substring(0, index).toLowerCase();
|
||||
String params = format.substring(index + 1);
|
||||
if (hooks.containsKey(identifier)) {
|
||||
if (!(hooks.get(identifier) instanceof Relational)) {
|
||||
continue;
|
||||
}
|
||||
Relational rel = (Relational) hooks.get(identifier);
|
||||
String value = rel.onPlaceholderRequest(one, two, params);
|
||||
if (value != null) {
|
||||
text = text.replaceAll(Pattern.quote(m.group()), Matcher.quoteReplacement(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
return color(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister ALL placeholder hooks that are currently registered
|
||||
*/
|
||||
protected static void unregisterAll() {
|
||||
unregisterAllProvidedExpansions();
|
||||
placeholders.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister all expansions provided by PlaceholderAPI
|
||||
*/
|
||||
public static void unregisterAllProvidedExpansions() {
|
||||
if (placeholders.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
getPlaceholders().forEach((key, value) -> {
|
||||
if (value instanceof PlaceholderExpansion) {
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) value;
|
||||
if (!ex.persist()) {
|
||||
unregisterExpansion(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean registerExpansion(PlaceholderExpansion ex) {
|
||||
if (registerPlaceholderHook(ex.getIdentifier(), ex)) {
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionRegisterEvent(ex));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean unregisterExpansion(PlaceholderExpansion ex) {
|
||||
if (unregisterPlaceholderHook(ex.getIdentifier())) {
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(ex));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Pattern getPlaceholderPattern() {
|
||||
return PLACEHOLDER_PATTERN;
|
||||
}
|
||||
|
||||
public static Pattern getBracketPlaceholderPattern() {
|
||||
return BRACKET_PLACEHOLDER_PATTERN;
|
||||
}
|
||||
|
||||
public static Pattern getRelationalPlaceholderPattern() {
|
||||
return RELATIONAL_PLACEHOLDER_PATTERN;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Set<String> getRegisteredPlaceholderPlugins() {
|
||||
return getRegisteredIdentifiers();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Set<String> getExternalPlaceholderPlugins() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean registerPlaceholderHook(Plugin plugin, PlaceholderHook placeholderHook) {
|
||||
return plugin != null && registerPlaceholderHook(plugin.getName(), placeholderHook);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean unregisterPlaceholderHook(Plugin plugin) {
|
||||
return plugin != null && unregisterPlaceholderHook(plugin.getName());
|
||||
}
|
||||
|
||||
public static String setPlaceholders(Player p, String text) {
|
||||
return setPlaceholders((OfflinePlayer) p, text, PLACEHOLDER_PATTERN);
|
||||
}
|
||||
|
||||
public static List<String> setPlaceholders(Player p, List<String> text) {
|
||||
return setPlaceholders((OfflinePlayer) p, text, PLACEHOLDER_PATTERN);
|
||||
}
|
||||
|
||||
public static String setBracketPlaceholders(Player p, String text) {
|
||||
return setPlaceholders((OfflinePlayer) p, text, BRACKET_PLACEHOLDER_PATTERN);
|
||||
}
|
||||
|
||||
public static List<String> setBracketPlaceholders(Player p, List<String> text) {
|
||||
return setPlaceholders((OfflinePlayer) p, text, BRACKET_PLACEHOLDER_PATTERN);
|
||||
}
|
||||
}
|
||||
|
@@ -20,12 +20,17 @@
|
||||
*/
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import me.clip.placeholderapi.commands.PlaceholderAPICommands;
|
||||
import me.clip.placeholderapi.configuration.PlaceholderAPIConfig;
|
||||
import me.clip.placeholderapi.expansion.ExpansionManager;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Version;
|
||||
import me.clip.placeholderapi.expansion.cloud.ExpansionCloudManager;
|
||||
import me.clip.placeholderapi.external.EZPlaceholderHook;
|
||||
import me.clip.placeholderapi.updatechecker.UpdateChecker;
|
||||
import me.clip.placeholderapi.util.TimeUtil;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@@ -34,235 +39,253 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* Yes I have a shit load of work to do...
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
|
||||
private static PlaceholderAPIPlugin instance;
|
||||
private static PlaceholderAPIPlugin instance;
|
||||
private static SimpleDateFormat dateFormat;
|
||||
private static String booleanTrue;
|
||||
private static String booleanFalse;
|
||||
private static Version serverVersion;
|
||||
private PlaceholderAPIConfig config;
|
||||
private ExpansionManager expansionManager;
|
||||
private ExpansionCloudManager expansionCloud;
|
||||
private long startTime;
|
||||
|
||||
private PlaceholderAPIConfig config;
|
||||
private static Version getVersion() {
|
||||
String v = "unknown";
|
||||
boolean spigot = false;
|
||||
try {
|
||||
v = Bukkit.getServer().getClass().getPackage().getName()
|
||||
.split("\\.")[3];
|
||||
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||
}
|
||||
try {
|
||||
Class.forName("org.spigotmc.SpigotConfig");
|
||||
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
|
||||
spigot = true;
|
||||
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
||||
}
|
||||
return new Version(v, spigot);
|
||||
}
|
||||
|
||||
private ExpansionManager expansionManager;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static PlaceholderAPIPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ExpansionCloudManager expansionCloud;
|
||||
/**
|
||||
* Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for
|
||||
* generic time based placeholders
|
||||
*
|
||||
* @return date format
|
||||
*/
|
||||
public static SimpleDateFormat getDateFormat() {
|
||||
return dateFormat != null ? dateFormat : new SimpleDateFormat(
|
||||
"MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
|
||||
private static SimpleDateFormat dateFormat;
|
||||
/**
|
||||
* Get the configurable {@linkplain String} value that should be returned when a boolean is true
|
||||
*
|
||||
* @return string value of true
|
||||
*/
|
||||
public static String booleanTrue() {
|
||||
return booleanTrue != null ? booleanTrue : "true";
|
||||
}
|
||||
|
||||
private static String booleanTrue;
|
||||
/**
|
||||
* Get the configurable {@linkplain String} value that should be returned when a boolean is false
|
||||
*
|
||||
* @return string value of false
|
||||
*/
|
||||
public static String booleanFalse() {
|
||||
return booleanFalse != null ? booleanFalse : "false";
|
||||
}
|
||||
|
||||
private static String booleanFalse;
|
||||
public static Version getServerVersion() {
|
||||
return serverVersion != null ? serverVersion : getVersion();
|
||||
}
|
||||
|
||||
private static Version serverVersion;
|
||||
@Override
|
||||
public void onLoad() {
|
||||
startTime = System.currentTimeMillis();
|
||||
instance = this;
|
||||
serverVersion = getVersion();
|
||||
config = new PlaceholderAPIConfig(this);
|
||||
expansionManager = new ExpansionManager(this);
|
||||
}
|
||||
|
||||
private long startTime;
|
||||
@Override
|
||||
public void onEnable() {
|
||||
config.loadDefConfig();
|
||||
setupOptions();
|
||||
getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this));
|
||||
new PlaceholderListener(this);
|
||||
try {
|
||||
Class.forName("org.bukkit.event.server.ServerLoadEvent");
|
||||
new ServerLoadEventListener(this);
|
||||
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
||||
Bukkit.getScheduler().runTaskLater(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getLogger().info("Placeholder expansion registration initializing...");
|
||||
//fetch any hooks that may have registered externally onEnable first otherwise they will be lost
|
||||
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
||||
getExpansionManager().registerAllExpansions();
|
||||
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
||||
alreadyRegistered.entrySet().stream().forEach(hook -> PlaceholderAPI.registerPlaceholderHook(hook.getKey(), hook.getValue()));
|
||||
}
|
||||
}
|
||||
}, 20*15);
|
||||
}
|
||||
if (config.checkUpdates()) {
|
||||
new UpdateChecker(this).fetch();
|
||||
}
|
||||
if (config.isCloudEnabled()) {
|
||||
enableCloud();
|
||||
}
|
||||
setupMetrics();
|
||||
getServer().getScheduler().runTaskLater(this, this::checkHook, 20 * 30);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
startTime = System.currentTimeMillis();
|
||||
instance = this;
|
||||
serverVersion = getVersion();
|
||||
config = new PlaceholderAPIConfig(this);
|
||||
expansionManager = new ExpansionManager(this);
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
disableCloud();
|
||||
PlaceholderAPI.unregisterAll();
|
||||
expansionManager = null;
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
serverVersion = null;
|
||||
instance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
config.loadDefConfig();
|
||||
setupOptions();
|
||||
getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this));
|
||||
new PlaceholderListener(this);
|
||||
getLogger().info("Placeholder expansion registration initializing...");
|
||||
expansionManager.registerAllExpansions();
|
||||
if (config.checkUpdates()) {
|
||||
new UpdateChecker(this);
|
||||
}
|
||||
if (config.isCloudEnabled()) {
|
||||
enableCloud();
|
||||
}
|
||||
setupMetrics();
|
||||
}
|
||||
public void reloadConf(CommandSender s) {
|
||||
boolean cloudEnabled = this.expansionCloud != null;
|
||||
PlaceholderAPI.unregisterAllProvidedExpansions();
|
||||
reloadConfig();
|
||||
setupOptions();
|
||||
expansionManager.registerAllExpansions();
|
||||
if (!config.isCloudEnabled()) {
|
||||
disableCloud();
|
||||
} else if (!cloudEnabled) {
|
||||
enableCloud();
|
||||
}
|
||||
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
PlaceholderAPI.getRegisteredIdentifiers().size()
|
||||
+ " &aplaceholder hooks successfully registered!"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
disableCloud();
|
||||
PlaceholderAPI.unregisterAll();
|
||||
expansionManager.clean();
|
||||
expansionManager = null;
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
serverVersion = null;
|
||||
instance = null;
|
||||
}
|
||||
private void checkHook() {
|
||||
Map<String, PlaceholderHook> loaded = PlaceholderAPI.getPlaceholders();
|
||||
loaded.values().forEach(h -> {
|
||||
if (h instanceof EZPlaceholderHook) {
|
||||
String author;
|
||||
try {
|
||||
author = Bukkit.getPluginManager().getPlugin(((EZPlaceholderHook) h).getPluginName()).getDescription().getAuthors().toString();
|
||||
} catch (Exception ex) {
|
||||
author = "the author of the hook's plugin";
|
||||
}
|
||||
getLogger().warning(((EZPlaceholderHook) h).getPluginName() + " is currently using a deprecated method to hook into PlaceholderAPI. This will be disabled after the next update. " +
|
||||
"Please consult {author} and urge them to update it ASAP.".replace("{author}", author));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void reloadConf(CommandSender s) {
|
||||
boolean cloudEnabled = this.expansionCloud != null;
|
||||
expansionManager.clean();
|
||||
PlaceholderAPI.unregisterAllProvidedExpansions();
|
||||
reloadConfig();
|
||||
setupOptions();
|
||||
expansionManager.registerAllExpansions();
|
||||
if (!config.isCloudEnabled()) {
|
||||
disableCloud();
|
||||
} else if (!cloudEnabled) {
|
||||
enableCloud();
|
||||
}
|
||||
s.sendMessage(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.getRegisteredIdentifiers().size() + " &aplaceholder hooks successfully registered!"));
|
||||
}
|
||||
private void setupOptions() {
|
||||
booleanTrue = config.booleanTrue();
|
||||
if (booleanTrue == null) {
|
||||
booleanTrue = "true";
|
||||
}
|
||||
booleanFalse = config.booleanFalse();
|
||||
if (booleanFalse == null) {
|
||||
booleanFalse = "false";
|
||||
}
|
||||
try {
|
||||
dateFormat = new SimpleDateFormat(config.dateFormat());
|
||||
} catch (Exception e) {
|
||||
dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupOptions() {
|
||||
booleanTrue = config.booleanTrue();
|
||||
if (booleanTrue == null) {
|
||||
booleanTrue = "true";
|
||||
}
|
||||
booleanFalse = config.booleanFalse();
|
||||
if (booleanFalse == null) {
|
||||
booleanFalse = "false";
|
||||
}
|
||||
try {
|
||||
dateFormat = new SimpleDateFormat(config.dateFormat());
|
||||
} catch (Exception e) {
|
||||
dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
}
|
||||
private void setupMetrics() {
|
||||
Metrics m = new Metrics(this);
|
||||
m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud",
|
||||
() -> getExpansionCloud() != null ? "yes" : "no"));
|
||||
|
||||
private void setupMetrics() {
|
||||
Metrics m = new Metrics(this);
|
||||
m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", () -> getExpansionCloud() != null ? "yes" : "no"));
|
||||
|
||||
m.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
||||
m.addCustomChart(
|
||||
new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
||||
|
||||
m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders();
|
||||
m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders();
|
||||
|
||||
if (!p.isEmpty()) {
|
||||
if (!p.isEmpty()) {
|
||||
|
||||
for (PlaceholderHook hook : p.values()) {
|
||||
if (hook instanceof PlaceholderExpansion) {
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) hook;
|
||||
map.put(ex.getPlugin() == null ? ex.getIdentifier()
|
||||
: ex.getPlugin(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
for (PlaceholderHook hook : p.values()) {
|
||||
if (hook instanceof PlaceholderExpansion) {
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) hook;
|
||||
map.put(ex.getRequiredPlugin() == null ? ex.getIdentifier()
|
||||
: ex.getRequiredPlugin(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
||||
}));
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static Version getVersion() {
|
||||
String v = "unknown";
|
||||
boolean spigot = false;
|
||||
try {
|
||||
v = Bukkit.getServer().getClass().getPackage().getName()
|
||||
.split("\\.")[3];
|
||||
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||
}
|
||||
try {
|
||||
Class.forName("org.spigotmc.SpigotConfig");
|
||||
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
|
||||
spigot = true;
|
||||
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
||||
}
|
||||
return new Version(v, spigot);
|
||||
}
|
||||
public void enableCloud() {
|
||||
if (expansionCloud == null) {
|
||||
expansionCloud = new ExpansionCloudManager(this);
|
||||
expansionCloud.fetch(config.cloudAllowUnverifiedExpansions());
|
||||
} else {
|
||||
expansionCloud.clean();
|
||||
expansionCloud.fetch(config.cloudAllowUnverifiedExpansions());
|
||||
}
|
||||
}
|
||||
|
||||
public void enableCloud() {
|
||||
if (expansionCloud == null) {
|
||||
expansionCloud = new ExpansionCloudManager(this);
|
||||
expansionCloud.fetch();
|
||||
} else {
|
||||
expansionCloud.clean();
|
||||
expansionCloud.fetch();
|
||||
}
|
||||
}
|
||||
public void disableCloud() {
|
||||
if (expansionCloud != null) {
|
||||
expansionCloud.clean();
|
||||
expansionCloud = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void disableCloud() {
|
||||
if (expansionCloud != null) {
|
||||
expansionCloud.clean();
|
||||
expansionCloud = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Obtain the configuration class for PlaceholderAPI.
|
||||
*
|
||||
* @return PlaceholderAPIConfig instance
|
||||
*/
|
||||
public PlaceholderAPIConfig getPlaceholderAPIConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static PlaceholderAPIPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
public ExpansionManager getExpansionManager() {
|
||||
return expansionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain SimpleDateFormat} object that is used to
|
||||
* parse time for generic time based placeholders
|
||||
*
|
||||
* @return date format
|
||||
*/
|
||||
public static SimpleDateFormat getDateFormat() {
|
||||
return dateFormat != null ? dateFormat : new SimpleDateFormat(
|
||||
"MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
public ExpansionCloudManager getExpansionCloud() {
|
||||
return expansionCloud;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain String} value that should be returned
|
||||
* when a boolean is true
|
||||
*
|
||||
* @return string value of true
|
||||
*/
|
||||
public static String booleanTrue() {
|
||||
return booleanTrue != null ? booleanTrue : "true";
|
||||
}
|
||||
public String getUptime() {
|
||||
return TimeUtil
|
||||
.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain String} value that should be returned
|
||||
* when a boolean is false
|
||||
*
|
||||
* @return string value of false
|
||||
*/
|
||||
public static String booleanFalse() {
|
||||
return booleanFalse != null ? booleanFalse : "false";
|
||||
}
|
||||
|
||||
public static Version getServerVersion() {
|
||||
return serverVersion != null ? serverVersion : getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the configuration class for PlaceholderAPI.
|
||||
*
|
||||
* @return PlaceholderAPIConfig instance
|
||||
*/
|
||||
public PlaceholderAPIConfig getPlaceholderAPIConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public ExpansionManager getExpansionManager() {
|
||||
return expansionManager;
|
||||
}
|
||||
|
||||
public ExpansionCloudManager getExpansionCloud() {
|
||||
return expansionCloud;
|
||||
}
|
||||
|
||||
public String getUptime() {
|
||||
return TimeUtil.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
public long getUptimeMillis() {
|
||||
return (System.currentTimeMillis() - startTime);
|
||||
}
|
||||
public long getUptimeMillis() {
|
||||
return (System.currentTimeMillis() - startTime);
|
||||
}
|
||||
}
|
||||
|
@@ -20,15 +20,34 @@
|
||||
*/
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class PlaceholderHook {
|
||||
|
||||
/**
|
||||
* called when a placeholder is requested from this PlaceholderHook
|
||||
* @param p Player requesting the placeholder value for, null if not needed for a player
|
||||
* @param params String passed for the placeholder hook to determine what value to return
|
||||
* @return value for the requested player and params
|
||||
*/
|
||||
public abstract String onPlaceholderRequest(Player p, String params);
|
||||
/**
|
||||
* called when a placeholder value is requested from this hook
|
||||
*
|
||||
* @param p {@link OfflinePlayer} to request the placeholder value for, null if not needed for a
|
||||
* player
|
||||
* @param params String passed to the hook to determine what value to return
|
||||
* @return value for the requested player and params
|
||||
*/
|
||||
public String onRequest(OfflinePlayer p, String params) {
|
||||
if (p != null && p.isOnline()) {
|
||||
return onPlaceholderRequest((Player) p, params);
|
||||
}
|
||||
return onPlaceholderRequest(null, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* called when a placeholder is requested from this hook
|
||||
*
|
||||
* @param p {@link Player} to request the placeholder value for, null if not needed for a player
|
||||
* @param params String passed to the hook to determine what value to return
|
||||
* @return value for the requested player and params
|
||||
*/
|
||||
public String onPlaceholderRequest(Player p, String params) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -20,11 +20,15 @@
|
||||
*/
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
|
||||
import me.clip.placeholderapi.events.PlaceholderHookUnloadEvent;
|
||||
import me.clip.placeholderapi.expansion.*;
|
||||
import me.clip.placeholderapi.expansion.Cacheable;
|
||||
import me.clip.placeholderapi.expansion.Cleanable;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Taskable;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
import me.clip.placeholderapi.external.EZPlaceholderHook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -32,122 +36,93 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class PlaceholderListener implements Listener {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
public PlaceholderListener(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
Bukkit.getPluginManager().registerEvents(this, instance);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExpansionUnregister(ExpansionUnregisterEvent event) {
|
||||
|
||||
if (event.getExpansion() instanceof Listener) {
|
||||
HandlerList.unregisterAll((Listener)event.getExpansion());
|
||||
}
|
||||
|
||||
if (event.getExpansion() instanceof Taskable) {
|
||||
((Taskable) event.getExpansion()).stop();
|
||||
}
|
||||
|
||||
if (event.getExpansion() instanceof Cacheable) {
|
||||
((Cacheable) event.getExpansion()).clear();
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud() != null) {
|
||||
|
||||
CloudExpansion ex = plugin.getExpansionCloud().getCloudExpansion(event.getExpansion().getName());
|
||||
|
||||
if (ex != null) {
|
||||
ex.setHasExpansion(false);
|
||||
ex.setShouldUpdate(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEnable(PluginEnableEvent event) {
|
||||
ExpansionManager m = plugin.getExpansionManager();
|
||||
PlaceholderExpansion e = m.getCachedExpansion(event.getPlugin().getName().toLowerCase());
|
||||
if (e != null && e.canRegister()) {
|
||||
if (e.isRegistered() || m.registerExpansion(e)) {
|
||||
m.removeCachedExpansion(e.getPlugin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPluginUnload(PluginDisableEvent e) {
|
||||
|
||||
String n = e.getPlugin().getName();
|
||||
|
||||
if (n == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (n.equals(plugin.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();
|
||||
|
||||
for (Entry<String, PlaceholderHook> hook : hooks.entrySet()) {
|
||||
|
||||
PlaceholderHook i = hook.getValue();
|
||||
|
||||
if (i instanceof EZPlaceholderHook) {
|
||||
|
||||
EZPlaceholderHook h = (EZPlaceholderHook) i;
|
||||
|
||||
if (h.getPluginName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (h.getPluginName().equalsIgnoreCase(n)) {
|
||||
if (PlaceholderAPI.unregisterPlaceholderHook(hook.getKey())) {
|
||||
plugin.getLogger().info("Unregistered placeholder hook for placeholder: " + h.getPlaceholderName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (i instanceof PlaceholderExpansion) {
|
||||
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) i;
|
||||
|
||||
if (ex.getPlugin() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ex.getPlugin().equalsIgnoreCase(n)) {
|
||||
if (PlaceholderAPI.unregisterExpansion(ex)) {
|
||||
plugin.getLogger().info("Unregistered placeholder expansion: " + ex.getIdentifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
|
||||
Set<PlaceholderExpansion> expansions = PlaceholderAPI.getExpansions();
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
if (expansions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (PlaceholderExpansion ex : expansions) {
|
||||
if (ex instanceof Cleanable) {
|
||||
((Cleanable) ex).cleanup(e.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
public PlaceholderListener(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
Bukkit.getPluginManager().registerEvents(this, instance);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExpansionUnregister(ExpansionUnregisterEvent event) {
|
||||
|
||||
if (event.getExpansion() instanceof Listener) {
|
||||
HandlerList.unregisterAll((Listener) event.getExpansion());
|
||||
}
|
||||
|
||||
if (event.getExpansion() instanceof Taskable) {
|
||||
((Taskable) event.getExpansion()).stop();
|
||||
}
|
||||
|
||||
if (event.getExpansion() instanceof Cacheable) {
|
||||
((Cacheable) event.getExpansion()).clear();
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud() != null) {
|
||||
|
||||
CloudExpansion ex = plugin.getExpansionCloud()
|
||||
.getCloudExpansion(event.getExpansion().getName());
|
||||
|
||||
if (ex != null) {
|
||||
ex.setHasExpansion(false);
|
||||
ex.setShouldUpdate(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPluginUnload(PluginDisableEvent e) {
|
||||
|
||||
String n = e.getPlugin().getName();
|
||||
|
||||
if (n == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (n.equals(plugin.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();
|
||||
|
||||
for (Entry<String, PlaceholderHook> hook : hooks.entrySet()) {
|
||||
|
||||
PlaceholderHook i = hook.getValue();
|
||||
|
||||
if (i instanceof PlaceholderExpansion) {
|
||||
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) i;
|
||||
|
||||
if (ex.getRequiredPlugin() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ex.getRequiredPlugin().equalsIgnoreCase(n)) {
|
||||
if (PlaceholderAPI.unregisterExpansion(ex)) {
|
||||
plugin.getLogger().info("Unregistered placeholder expansion: " + ex.getIdentifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
|
||||
Set<PlaceholderExpansion> expansions = PlaceholderAPI.getExpansions();
|
||||
|
||||
if (expansions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (PlaceholderExpansion ex : expansions) {
|
||||
if (ex instanceof Cleanable) {
|
||||
((Cleanable) ex).cleanup(e.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,29 @@
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
|
||||
public class ServerLoadEventListener implements Listener {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
public ServerLoadEventListener(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
Bukkit.getPluginManager().registerEvents(this, instance);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerLoad(ServerLoadEvent e) {
|
||||
plugin.getLogger().info("Placeholder expansion registration initializing...");
|
||||
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
||||
plugin.getExpansionManager().registerAllExpansions();
|
||||
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
||||
alreadyRegistered.entrySet().stream().forEach(hook -> {
|
||||
PlaceholderAPI.registerPlaceholderHook(hook.getKey(), hook.getValue());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,383 +20,424 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import static me.clip.placeholderapi.util.Msg.color;
|
||||
import static me.clip.placeholderapi.util.Msg.msg;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static me.clip.placeholderapi.util.Msg.color;
|
||||
import static me.clip.placeholderapi.util.Msg.msg;
|
||||
|
||||
public class ExpansionCloudCommands implements CommandExecutor {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
public ExpansionCloudCommands(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
|
||||
|
||||
if (args.length == 1) {
|
||||
msg(s, "&bExpansion cloud commands",
|
||||
" ",
|
||||
"&b/papi ecloud status",
|
||||
"&fView status of the ecloud",
|
||||
"&b/papi ecloud list <all/author> (page)",
|
||||
"&fList all/author specific available expansions",
|
||||
"&b/papi ecloud info <expansion name>",
|
||||
"&fView information about a specific expansion available on the cloud",
|
||||
"&b/papi ecloud versioninfo <expansion name> <version>",
|
||||
"&fView information about a specific version of an expansion",
|
||||
"&b/papi ecloud placeholders <expansion name>",
|
||||
"&fView placeholders for an expansion",
|
||||
"&b/papi ecloud download <expansion name> (version)",
|
||||
"&fDownload an expansion from the ecloud",
|
||||
"&b/papi ecloud refresh",
|
||||
"&fFetch the most up to date list of expansions available.",
|
||||
"&b/papi ecloud clear",
|
||||
"&fClear the expansion cloud cache.");
|
||||
return true;
|
||||
}
|
||||
public ExpansionCloudCommands(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1].equalsIgnoreCase("fetch")) {
|
||||
msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!");
|
||||
plugin.getExpansionCloud().clean();
|
||||
plugin.getExpansionCloud().fetch();
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
|
||||
|
||||
if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) {
|
||||
msg(s, "&7No cloud expansions are available at this time.");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
msg(s, "&bExpansion cloud commands",
|
||||
" ",
|
||||
"&b/papi ecloud status",
|
||||
"&fView status of the ecloud",
|
||||
"&b/papi ecloud list <all/author> (page)",
|
||||
"&fList all/author specific available expansions",
|
||||
"&b/papi ecloud info <expansion name>",
|
||||
"&fView information about a specific expansion available on the cloud",
|
||||
"&b/papi ecloud versioninfo <expansion name> <version>",
|
||||
"&fView information about a specific version of an expansion",
|
||||
"&b/papi ecloud placeholders <expansion name>",
|
||||
"&fView placeholders for an expansion",
|
||||
"&b/papi ecloud download <expansion name> (version)",
|
||||
"&fDownload an expansion from the ecloud",
|
||||
"&b/papi ecloud refresh",
|
||||
"&fFetch the most up to date list of expansions available.",
|
||||
"&b/papi ecloud clear",
|
||||
"&fClear the expansion cloud cache.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("clear")) {
|
||||
plugin.getExpansionCloud().clean();
|
||||
msg(s, "&aThe cache has been cleared!!");
|
||||
return true;
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1]
|
||||
.equalsIgnoreCase("fetch")) {
|
||||
msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!");
|
||||
plugin.getExpansionCloud().clean();
|
||||
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("status")) {
|
||||
|
||||
msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size() + " &bexpansions available on the cloud.",
|
||||
"&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount() + " &7authors have contributed to the expansion cloud.");
|
||||
if (plugin.getExpansionCloud().getToUpdateCount() > 0) {
|
||||
msg(s, "&eYou have &f" + plugin.getExpansionCloud().getToUpdateCount()
|
||||
+ " &eexpansions installed that have updates available.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) {
|
||||
msg(s, "&7No cloud expansions are available at this time.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("info")) {
|
||||
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
msg(s, (expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion.getVersion().getUrl());
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
|
||||
msg(s, "&bExpansion&7: &f" + expansion.getName(),
|
||||
"&bAuthor: &f" + expansion.getAuthor(),
|
||||
"&bVerified: &f" + expansion.isVerified()
|
||||
);
|
||||
if (args[1].equalsIgnoreCase("clear")) {
|
||||
plugin.getExpansionCloud().clean();
|
||||
msg(s, "&aThe cache has been cleared!!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// latest version
|
||||
JSONMessage latestVersion = JSONMessage.create(color("&bLatest version: &f" + expansion.getLatestVersion()));
|
||||
latestVersion.tooltip(color("&bReleased: &f" + expansion.getTimeSinceLastUpdate()
|
||||
+ "\n&bUpdate information: &f" + expansion.getVersion().getReleaseNotes()
|
||||
));
|
||||
latestVersion.send(p);
|
||||
if (args[1].equalsIgnoreCase("status")) {
|
||||
|
||||
// versions
|
||||
JSONMessage versions = JSONMessage.create(color("&bVersions available: &f" + expansion.getVersions().size()));
|
||||
versions.tooltip(color(String.join("&b, &f", expansion.getAvailableVersions())));
|
||||
versions.suggestCommand("/papi ecloud versioninfo " + expansion.getName() + " " + expansion.getLatestVersion());
|
||||
versions.send(p);
|
||||
msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size()
|
||||
+ " &bexpansions available on the cloud.",
|
||||
"&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount()
|
||||
+ " &7authors have contributed to the expansion cloud.");
|
||||
if (plugin.getExpansionCloud().getToUpdateCount() > 0) {
|
||||
msg(s, "&eYou have &f" + plugin.getExpansionCloud().getToUpdateCount()
|
||||
+ " &eexpansions installed that have updates available.");
|
||||
}
|
||||
|
||||
// placeholders
|
||||
if (expansion.getPlaceholders() != null) {
|
||||
JSONMessage placeholders = JSONMessage.create(color("&bPlaceholders: &f" + expansion.getPlaceholders().size()));
|
||||
placeholders.tooltip(color(String.join("&b, &f", expansion.getPlaceholders())));
|
||||
placeholders.suggestCommand("/papi ecloud placeholders " + expansion.getName());
|
||||
placeholders.send(p);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("versioninfo")) {
|
||||
if (args[1].equalsIgnoreCase("info")) {
|
||||
|
||||
if (args.length < 4) {
|
||||
msg(s, "&cAn expansion name and version must be specified!");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion.Version version = expansion.getVersion(args[3]);
|
||||
if (!(s instanceof Player)) {
|
||||
msg(s,
|
||||
(expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion
|
||||
.getVersion().getUrl());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (version == null) {
|
||||
msg(s, "&cThe version specified does not exist for expansion: &f" + expansion.getName());
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) s;
|
||||
|
||||
msg(s, "&bExpansion: " + (expansion.shouldUpdate() ? "&e" : "&f") + expansion.getName(),
|
||||
"&bVersion: &f" + version.getVersion(),
|
||||
"&bVersion info: &f" + version.getReleaseNotes());
|
||||
msg(s, "&bExpansion&7: &f" + expansion.getName(),
|
||||
"&bAuthor: &f" + expansion.getAuthor(),
|
||||
"&bVerified: &f" + expansion.isVerified()
|
||||
);
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
msg(s, "&bDownload url: " + version.getUrl());
|
||||
return true;
|
||||
}
|
||||
// latest version
|
||||
JSONMessage latestVersion = JSONMessage
|
||||
.create(color("&bLatest version: &f" + expansion.getLatestVersion()));
|
||||
latestVersion.tooltip(color("&bReleased: &f" + expansion.getTimeSinceLastUpdate()
|
||||
+ "\n&bUpdate information: &f" + expansion.getVersion().getReleaseNotes()
|
||||
));
|
||||
latestVersion.send(p);
|
||||
|
||||
Player p = (Player) s;
|
||||
// versions
|
||||
JSONMessage versions = JSONMessage
|
||||
.create(color("&bVersions available: &f" + expansion.getVersions().size()));
|
||||
versions.tooltip(color(String.join("&b, &f", expansion.getAvailableVersions())));
|
||||
versions.suggestCommand(
|
||||
"/papi ecloud versioninfo " + expansion.getName() + " " + expansion.getLatestVersion());
|
||||
versions.send(p);
|
||||
|
||||
JSONMessage download = JSONMessage.create(color("&7Click to download this version"));
|
||||
download.suggestCommand("/papi ecloud download " + expansion.getName() + " " + version.getVersion());
|
||||
download.send(p);
|
||||
return true;
|
||||
// placeholders
|
||||
if (expansion.getPlaceholders() != null) {
|
||||
JSONMessage placeholders = JSONMessage
|
||||
.create(color("&bPlaceholders: &f" + expansion.getPlaceholders().size()));
|
||||
placeholders.tooltip(color(String.join("&b, &f", expansion.getPlaceholders())));
|
||||
placeholders.suggestCommand("/papi ecloud placeholders " + expansion.getName());
|
||||
placeholders.send(p);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("versioninfo")) {
|
||||
|
||||
if (args.length < 4) {
|
||||
msg(s, "&cAn expansion name and version must be specified!");
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion.Version version = expansion.getVersion(args[3]);
|
||||
|
||||
if (version == null) {
|
||||
msg(s, "&cThe version specified does not exist for expansion: &f" + expansion.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&bExpansion: " + (expansion.shouldUpdate() ? "&e" : "&f") + expansion.getName(),
|
||||
"&bVersion: &f" + version.getVersion(),
|
||||
"&bVersion info: &f" + version.getReleaseNotes());
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
msg(s, "&bDownload url: " + version.getUrl());
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
|
||||
JSONMessage download = JSONMessage.create(color("&7Click to download this version"));
|
||||
download.suggestCommand(
|
||||
"/papi ecloud download " + expansion.getName() + " " + version.getVersion());
|
||||
download.send(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("placeholders")) {
|
||||
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> placeholders = expansion.getPlaceholders();
|
||||
|
||||
if (placeholders == null) {
|
||||
msg(s, "&cThe expansion: &f" + expansion.getName()
|
||||
+ " &cdoes not have any placeholders listed.",
|
||||
"&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(s instanceof Player)
|
||||
|| plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) {
|
||||
msg(s, "&bPlaceholders: &f" + placeholders.size(),
|
||||
String.join("&a, &f", placeholders));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
JSONMessage message = JSONMessage.create(color("&bPlaceholders: &f" + placeholders.size()));
|
||||
message.then("\n");
|
||||
|
||||
for (int i = 0; i < placeholders.size(); i++) {
|
||||
if (i == placeholders.size() - 1) {
|
||||
message.then(placeholders.get(i));
|
||||
} else {
|
||||
message.then(color(placeholders.get(i) + "&b, &f"));
|
||||
}
|
||||
message.tooltip(PlaceholderAPI.setPlaceholders(p, placeholders.get(i)));
|
||||
}
|
||||
|
||||
message.send(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("list")) {
|
||||
|
||||
int page = 1;
|
||||
|
||||
String author;
|
||||
boolean installed = false;
|
||||
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cIncorrect usage! &7/papi ecloud list <all/author/installed> (page)");
|
||||
return true;
|
||||
}
|
||||
|
||||
author = args[2];
|
||||
|
||||
if (author.equalsIgnoreCase("all")) {
|
||||
author = null;
|
||||
} else if (author.equalsIgnoreCase("installed")) {
|
||||
author = null;
|
||||
installed = true;
|
||||
}
|
||||
|
||||
if (args.length >= 4) {
|
||||
try {
|
||||
page = Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException ex) {
|
||||
msg(s, "&cPage number must be an integer!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (page < 1) {
|
||||
msg(s, "&cPage must be greater than or equal to 1!");
|
||||
return true;
|
||||
}
|
||||
|
||||
int avail;
|
||||
|
||||
Map<Integer, CloudExpansion> ex;
|
||||
|
||||
if (installed) {
|
||||
ex = plugin.getExpansionCloud().getAllInstalled();
|
||||
} else if (author == null) {
|
||||
ex = plugin.getExpansionCloud().getCloudExpansions();
|
||||
} else {
|
||||
ex = plugin.getExpansionCloud().getAllByAuthor(author);
|
||||
}
|
||||
|
||||
if (ex == null || ex.isEmpty()) {
|
||||
msg(s, "&cNo expansions available" + (author != null ? " for author &f" + author : ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10);
|
||||
|
||||
if (page > avail) {
|
||||
msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!"
|
||||
: "are only &f" + avail + " &cpages available!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&bShowing expansions for&7: &f" + (author != null ? author
|
||||
: (installed ? "all installed" : "all available")) + " &8&m--&r &bamount&7: &f" + ex
|
||||
.size() + " &bpage&7: &f" + page + "&7/&f" + avail);
|
||||
|
||||
ex = plugin.getExpansionCloud().getPage(ex, page, 10);
|
||||
|
||||
if (ex == null) {
|
||||
msg(s, "&cThere was a problem getting the requested page...");
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&aGreen = Expansions you have");
|
||||
msg(s, "&6Gold = Expansions which need updated");
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||
for (CloudExpansion exp : ex.values()) {
|
||||
if (exp == null || exp.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||
int i = 1;
|
||||
for (String name : ce) {
|
||||
if (expansions.get(name) == null) {
|
||||
continue;
|
||||
}
|
||||
CloudExpansion expansion = expansions.get(name);
|
||||
msg(s,
|
||||
"&b" + i + "&7: " + (expansion.shouldUpdate() ? "&6"
|
||||
: (expansion.hasExpansion() ? "&a" : "&7")) + expansion
|
||||
.getName() + " &8&m-- &r" + expansion.getVersion().getUrl());
|
||||
i++;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("placeholders")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) s;
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> placeholders = expansion.getPlaceholders();
|
||||
|
||||
if (placeholders == null) {
|
||||
msg(s, "&cThe expansion: &f" + expansion.getName() + " &cdoes not have any placeholders listed.",
|
||||
"&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(s instanceof Player) || plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) {
|
||||
msg(s, "&bPlaceholders: &f" + placeholders.size(),
|
||||
String.join("&a, &f"));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
JSONMessage message = JSONMessage.create(color("&bPlaceholders: &f" + placeholders.size()));
|
||||
message.then("\n");
|
||||
|
||||
for (int i = 0 ; i < placeholders.size() ; i++) {
|
||||
if (i == placeholders.size()-1) {
|
||||
message.then(placeholders.get(i));
|
||||
} else {
|
||||
message.then(color(placeholders.get(i) + "&b, &f"));
|
||||
}
|
||||
message.tooltip(PlaceholderAPI.setPlaceholders(p, placeholders.get(i)));
|
||||
}
|
||||
|
||||
message.send(p);
|
||||
return true;
|
||||
Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||
for (CloudExpansion exp : ex.values()) {
|
||||
if (exp == null || exp.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||
int i = 1;
|
||||
for (String name : ce) {
|
||||
if (expansions.get(name) == null) {
|
||||
continue;
|
||||
}
|
||||
CloudExpansion expansion = expansions.get(name);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (expansion.shouldUpdate()) {
|
||||
sb.append("&6Click to update to the latest version of this expansion\n\n");
|
||||
} else if (!expansion.hasExpansion()) {
|
||||
sb.append("&bClick to download this expansion\n\n");
|
||||
} else {
|
||||
sb.append("&aYou have the latest version of this expansion\n\n");
|
||||
}
|
||||
sb.append("&bAuthor&7: &f" + expansion.getAuthor() + "\n");
|
||||
sb.append("&bVerified&7: &f" + expansion.isVerified() + "\n");
|
||||
sb.append("&bLatest version&7: &f" + expansion.getVersion().getVersion() + "\n");
|
||||
sb.append(
|
||||
"&bLast updated&7: &f" + expansion.getTimeSinceLastUpdate() + " ago\n");
|
||||
sb.append("\n" + expansion.getDescription());
|
||||
|
||||
if (args[1].equalsIgnoreCase("list")) {
|
||||
|
||||
int page = 1;
|
||||
|
||||
String author;
|
||||
boolean installed = false;
|
||||
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cIncorrect usage! &7/papi ecloud list <all/author/installed> (page)");
|
||||
return true;
|
||||
}
|
||||
|
||||
author = args[2];
|
||||
|
||||
if (author.equalsIgnoreCase("all")) {
|
||||
author = null;
|
||||
} else if (author.equalsIgnoreCase("installed")) {
|
||||
author = null;
|
||||
installed = true;
|
||||
}
|
||||
|
||||
if (args.length >= 4) {
|
||||
try {
|
||||
page = Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException ex) {
|
||||
msg(s, "&cPage number must be an integer!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (page < 1) {
|
||||
msg(s, "&cPage must be greater than or equal to 1!");
|
||||
return true;
|
||||
}
|
||||
|
||||
int avail;
|
||||
|
||||
Map<Integer, CloudExpansion> ex;
|
||||
|
||||
if (installed) {
|
||||
ex = plugin.getExpansionCloud().getAllInstalled();
|
||||
} else if (author == null) {
|
||||
ex = plugin.getExpansionCloud().getCloudExpansions();
|
||||
} else {
|
||||
ex = plugin.getExpansionCloud().getAllByAuthor(author);
|
||||
}
|
||||
|
||||
if (ex == null || ex.isEmpty()) {
|
||||
msg(s, "&cNo expansions available" + (author != null ? " for author &f" + author : ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10);
|
||||
|
||||
if (page > avail) {
|
||||
msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!" : "are only &f" + avail + " &cpages available!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&bShowing expansions for&7: &f" + (author != null ? author : (installed ? "all installed" : "all available"))+ " &8&m--&r &bamount&7: &f" + ex.size() + " &bpage&7: &f" + page + "&7/&f" + avail);
|
||||
|
||||
ex = plugin.getExpansionCloud().getPage(ex, page, 10);
|
||||
|
||||
if (ex == null) {
|
||||
msg(s, "&cThere was a problem getting the requested page...");
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&aGreen = Expansions you have");
|
||||
msg(s, "&6Gold = Expansions which need updated");
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
|
||||
for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) {
|
||||
if (expansion == null || expansion.getValue() == null) continue;
|
||||
msg(s, "&b" + (expansion.getKey()+1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6" : (expansion.getValue().hasExpansion() ? "&a" : "&7")) + expansion.getValue().getName() + " &8&m-- &r" + expansion.getValue().getVersion().getUrl());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
|
||||
for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) {
|
||||
|
||||
if (expansion == null || expansion.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
String msg = color(
|
||||
"&b" + (i + 1) + "&7: " + (expansion.shouldUpdate() ? "&6"
|
||||
: (expansion.hasExpansion() ? "&a" : "")) + expansion.getName());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (expansion.getValue().shouldUpdate()) {
|
||||
sb.append("&6Click to update to the latest version of this expansion\n\n");
|
||||
} else if (!expansion.getValue().hasExpansion()) {
|
||||
sb.append("&bClick to download this expansion\n\n");
|
||||
} else {
|
||||
sb.append("&aYou have the latest version of this expansion\n\n");
|
||||
}
|
||||
sb.append("&bAuthor&7: &f" + expansion.getValue().getAuthor() + "\n");
|
||||
sb.append("&bVerified&7: &f" + expansion.getValue().isVerified() + "\n");
|
||||
sb.append("&bLatest version&7: &f" + expansion.getValue().getVersion().getVersion() + "\n");
|
||||
sb.append("&bLast updated&7: &f" + expansion.getValue().getTimeSinceLastUpdate() + " ago\n");
|
||||
sb.append("\n" + expansion.getValue().getDescription());
|
||||
String hover = color(sb.toString());
|
||||
|
||||
String msg = color("&b" + (expansion.getKey()+1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6" : (expansion.getValue().hasExpansion() ? "&a" : "")) + expansion.getValue().getName());
|
||||
JSONMessage line = JSONMessage.create(msg);
|
||||
line.tooltip(hover);
|
||||
if (expansion.shouldUpdate()) {
|
||||
line.suggestCommand("/papi ecloud download " + expansion.getName());
|
||||
}
|
||||
else {
|
||||
line.suggestCommand("/papi ecloud info " + expansion.getName());
|
||||
}
|
||||
line.send(p);
|
||||
i++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
String hover = color(sb.toString());
|
||||
if (args[1].equalsIgnoreCase("download")) {
|
||||
|
||||
JSONMessage line = JSONMessage.create(msg);
|
||||
line.tooltip(hover);
|
||||
line.suggestCommand("/papi ecloud info " + expansion.getValue().getName());
|
||||
line.send(p);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (args[1].equalsIgnoreCase("download")) {
|
||||
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found with the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(args[2]);
|
||||
|
||||
if (loaded != null && loaded.isRegistered()) {
|
||||
PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier());
|
||||
}
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
return true;
|
||||
}
|
||||
|
||||
String version = expansion.getLatestVersion();
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
|
||||
if (args.length == 4) {
|
||||
version = args[3];
|
||||
if (expansion.getVersion(version) == null) {
|
||||
msg(s, "&cThe version you specified does not exist for &f" + expansion.getName());
|
||||
msg(s, "&7Available versions: &f" + expansion.getVersions().size());
|
||||
msg(s, String.join("&a, &f", expansion.getAvailableVersions()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found with the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(args[2]);
|
||||
|
||||
if (loaded != null && loaded.isRegistered()) {
|
||||
PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier());
|
||||
}
|
||||
|
||||
String version = expansion.getLatestVersion();
|
||||
|
||||
if (args.length == 4) {
|
||||
version = args[3];
|
||||
if (expansion.getVersion(version) == null) {
|
||||
msg(s, "&cThe version you specified does not exist for &f" + expansion.getName());
|
||||
msg(s, "&7Available versions: &f" + expansion.getVersions().size());
|
||||
msg(s, String.join("&a, &f", expansion.getAvailableVersions()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f"
|
||||
+ version);
|
||||
String player = ((s instanceof Player) ? s.getName() : null);
|
||||
plugin.getExpansionCloud().downloadExpansion(player, expansion, version);
|
||||
plugin.getExpansionCloud().clean();
|
||||
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&cIncorrect usage! &b/papi ecloud");
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" + version);
|
||||
String player = ((s instanceof Player) ? s.getName() : null);
|
||||
plugin.getExpansionCloud().downloadExpansion(player, expansion, version);
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&cIncorrect usage! &b/papi ecloud");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -20,246 +20,270 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class PlaceholderAPICommands implements CommandExecutor {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
private CommandExecutor eCloud;
|
||||
|
||||
public PlaceholderAPICommands(PlaceholderAPIPlugin i) {
|
||||
plugin = i;
|
||||
eCloud = new ExpansionCloudCommands(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
private CommandExecutor eCloud;
|
||||
|
||||
if (args.length == 0) {
|
||||
Msg.msg(s, "PlaceholderAPI &7version &b&o" + plugin.getDescription().getVersion(),
|
||||
"&fCreated by&7: &bextended_clip");
|
||||
return true;
|
||||
|
||||
} else {
|
||||
public PlaceholderAPICommands(PlaceholderAPIPlugin i) {
|
||||
plugin = i;
|
||||
eCloud = new ExpansionCloudCommands(i);
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
Msg.msg(s, "PlaceholderAPI &aHelp &e(&f" + plugin.getDescription().getVersion() + "&e)",
|
||||
"&b/papi",
|
||||
"&fView plugin info/version info",
|
||||
"&b/papi list",
|
||||
"&fList all placeholder expansions that are currently active",
|
||||
"&b/papi info <placeholder name>",
|
||||
"&fView information for a specific expansion",
|
||||
"&b/papi parse <...args>",
|
||||
"&fParse a String with placeholders",
|
||||
"&b/papi parserel <player one> <player two> <...args>",
|
||||
"&fParse a String with relational placeholders",
|
||||
"&b/papi reload",
|
||||
"&fReload the config settings");
|
||||
@Override
|
||||
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
|
||||
if (s.hasPermission("placeholderapi.ecloud")) {
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(s, "&b/papi enablecloud",
|
||||
"&fEnable the expansion cloud");
|
||||
} else {
|
||||
Msg.msg(s, "&b/papi disablecloud",
|
||||
"&fDisable the expansion cloud",
|
||||
"&b/papi ecloud",
|
||||
"&fView ecloud command usage");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} else if (args[0].equalsIgnoreCase("ecloud")) {
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(s, "&7The expansion cloud is not enabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
return eCloud.onCommand(s, c, label, args);
|
||||
|
||||
} else if (args[0].equalsIgnoreCase("enablecloud")) {
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud() != null) {
|
||||
Msg.msg(s, "&7The cloud is already enabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.enableCloud();
|
||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(true);
|
||||
Msg.msg(s, "&aThe cloud has been enabled!");
|
||||
return true;
|
||||
|
||||
} else if (args[0].equalsIgnoreCase("disablecloud")) {
|
||||
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(s, "&7The cloud is already disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.disableCloud();
|
||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(false);
|
||||
Msg.msg(s, "&aThe cloud has been disabled!");
|
||||
return true;
|
||||
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("info")) {
|
||||
Msg.msg(s, "PlaceholderAPI &7version &b&o" + plugin.getDescription().getVersion(),
|
||||
"&fCreated by&7: &bextended_clip",
|
||||
"&fPapi commands: &b/papi help",
|
||||
"&fEcloud commands: &b/papi ecloud");
|
||||
return true;
|
||||
} else {
|
||||
|
||||
if (!s.hasPermission("placeholderapi.info")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
||||
|
||||
if (ex == null) {
|
||||
Msg.msg(s, "&cThere is no expansion loaded with the identifier: &f" + args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
Msg.msg(s, "&7Placeholder expansion info for: &f" + ex.getName());
|
||||
|
||||
Msg.msg(s, "&7Status: " + (ex.isRegistered() ? "&aRegistered" : "&cNot registered"));
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
|
||||
if (ex.getAuthor() != null) {
|
||||
Msg.msg(s, "&7Created by: &f" + ex.getAuthor());
|
||||
}
|
||||
|
||||
if (ex.getVersion() != null) {
|
||||
Msg.msg(s, "&7Version: &f" + ex.getVersion());
|
||||
}
|
||||
|
||||
if (ex.getDescription() != null) {
|
||||
Msg.msg(s, ex.getDescription());
|
||||
}
|
||||
|
||||
if (ex.getLink() != null) {
|
||||
Msg.msg(s, "&7Link: &f" + ex.getLink());
|
||||
}
|
||||
|
||||
if (ex.getPlugin() != null) {
|
||||
Msg.msg(s, "&7Requires plugin: &f" + ex.getPlugin());
|
||||
}
|
||||
Msg.msg(s, "PlaceholderAPI &aHelp &e(&f" + plugin.getDescription().getVersion() + "&e)",
|
||||
"&b/papi",
|
||||
"&fView plugin info/version info",
|
||||
"&b/papi list",
|
||||
"&fList all placeholder expansions that are currently active",
|
||||
"&b/papi info <placeholder name>",
|
||||
"&fView information for a specific expansion",
|
||||
"&b/papi parse <(playername)/me> <...args>",
|
||||
"&fParse a String with placeholders",
|
||||
"&b/papi bcparse <(playername)/me> <...args>",
|
||||
"&fParse a String with placeholders and broadcast the message",
|
||||
"&b/papi parserel <player one> <player two> <...args>",
|
||||
"&fParse a String with relational placeholders",
|
||||
"&b/papi register <fileName>",
|
||||
"&fRegister an expansion by the name of the file",
|
||||
"&b/papi unregister <Expansion name>",
|
||||
"&fUnregister an expansion by name",
|
||||
"&b/papi reload",
|
||||
"&fReload the config settings");
|
||||
if (s.hasPermission("placeholderapi.ecloud")) {
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(s, "&b/papi enablecloud",
|
||||
"&fEnable the expansion cloud");
|
||||
} else {
|
||||
Msg.msg(s, "&b/papi disablecloud",
|
||||
"&fDisable the expansion cloud",
|
||||
"&b/papi ecloud",
|
||||
"&fView ecloud command usage");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("ecloud")) {
|
||||
|
||||
if (ex.getPlaceholders() != null) {
|
||||
Msg.msg(s, "&8&m-- &r&7Placeholders &8&m--");
|
||||
for (String placeholder : ex.getPlaceholders()) {
|
||||
Msg.msg(s, placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("parse")) {
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(s, "&7The expansion cloud is not enabled!");
|
||||
return true;
|
||||
}
|
||||
return eCloud.onCommand(s, c, label, args);
|
||||
} else if (args[0].equalsIgnoreCase("enablecloud")) {
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
Msg.msg(s, "&cThis command can only be used in game!");
|
||||
return true;
|
||||
} else {
|
||||
if (!s.hasPermission("placeholderapi.parse")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
|
||||
String parse = StringUtils.join(args, " ", 1, args.length);
|
||||
|
||||
Msg.msg(s, "&r" + PlaceholderAPI.setPlaceholders(p, parse));
|
||||
|
||||
return true;
|
||||
} else if (args.length > 3 && args[0].equalsIgnoreCase("parserel")) {
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
if (plugin.getExpansionCloud() != null) {
|
||||
Msg.msg(s, "&7The cloud is already enabled!");
|
||||
return true;
|
||||
}
|
||||
plugin.enableCloud();
|
||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(true);
|
||||
Msg.msg(s, "&aThe cloud has been enabled!");
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("disablecloud")) {
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
Msg.msg(s, "&cThis command can only be used in game!");
|
||||
return true;
|
||||
} else {
|
||||
if (!s.hasPermission("placeholderapi.parse")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Player one = Bukkit.getPlayer(args[1]);
|
||||
if (one == null) {
|
||||
Msg.msg(s, args[1] + " &cis not online!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player two = Bukkit.getPlayer(args[2]);
|
||||
|
||||
if (two == null) {
|
||||
Msg.msg(s, args[2] + " &cis not online!");
|
||||
return true;
|
||||
}
|
||||
|
||||
String parse = StringUtils.join(args, " ", 3, args.length);
|
||||
|
||||
Msg.msg(s, "&r" + PlaceholderAPI.setRelationalPlaceholders(one, two, parse));
|
||||
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(s, "&7The cloud is already disabled!");
|
||||
return true;
|
||||
}
|
||||
plugin.disableCloud();
|
||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(false);
|
||||
Msg.msg(s, "&aThe cloud has been disabled!");
|
||||
return true;
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("info")) {
|
||||
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.reload")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Msg.msg(s, "&fPlaceholder&7API &bconfiguration reloaded!");
|
||||
|
||||
plugin.reloadConf(s);
|
||||
if (!s.hasPermission("placeholderapi.info")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
||||
if (ex == null) {
|
||||
Msg.msg(s, "&cThere is no expansion loaded with the identifier: &f" + args[1]);
|
||||
return true;
|
||||
}
|
||||
Msg.msg(s, "&7Placeholder expansion info for: &f" + ex.getName());
|
||||
Msg.msg(s, "&7Status: " + (ex.isRegistered() ? "&aRegistered" : "&cNot registered"));
|
||||
if (ex.getAuthor() != null) {
|
||||
Msg.msg(s, "&7Created by: &f" + ex.getAuthor());
|
||||
}
|
||||
if (ex.getVersion() != null) {
|
||||
Msg.msg(s, "&7Version: &f" + ex.getVersion());
|
||||
}
|
||||
if (ex.getRequiredPlugin() != null) {
|
||||
Msg.msg(s, "&7Requires plugin: &f" + ex.getRequiredPlugin());
|
||||
}
|
||||
if (ex.getPlaceholders() != null) {
|
||||
Msg.msg(s, "&8&m-- &r&7Placeholders &8&m--");
|
||||
for (String placeholder : ex.getPlaceholders()) {
|
||||
Msg.msg(s, placeholder);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (args.length > 2 && args[0].equalsIgnoreCase("parse")
|
||||
|| args.length > 2 && args[0].equalsIgnoreCase("bcparse")) {
|
||||
|
||||
} else if (args[0].equalsIgnoreCase("list")) {
|
||||
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.list")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> registered = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
|
||||
if (registered.isEmpty()) {
|
||||
Msg.msg(s, "&7There are no placeholder hooks currently registered!");
|
||||
return true;
|
||||
}
|
||||
Msg.msg(s, registered.size()+" &7Placeholder hooks registered:");
|
||||
Msg.msg(s, registered.toString());
|
||||
} else {
|
||||
Msg.msg(s, "&cIncorrect usage! &7/papi help");
|
||||
}
|
||||
}
|
||||
if (!s.hasPermission("placeholderapi.parse")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
OfflinePlayer pl = null;
|
||||
if (args[1].equalsIgnoreCase("me")) {
|
||||
if (s instanceof Player) {
|
||||
pl = (Player) s;
|
||||
} else {
|
||||
Msg.msg(s, "&cThis command must target a player when used by console");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (Bukkit.getPlayer(args[1]) != null) {
|
||||
pl = Bukkit.getPlayer(args[1]);
|
||||
} else {
|
||||
pl = Bukkit.getOfflinePlayer(args[1]);
|
||||
}
|
||||
}
|
||||
if (pl == null || !pl.hasPlayedBefore()) {
|
||||
Msg.msg(s, "&cFailed to find player: &f" + args[1]);
|
||||
return true;
|
||||
}
|
||||
String parse = StringUtils.join(args, " ", 2, args.length);
|
||||
if (args[0].equalsIgnoreCase("bcparse")) {
|
||||
Msg.broadcast("&r" + PlaceholderAPI.setPlaceholders(pl, parse));
|
||||
} else {
|
||||
Msg.msg(s, "&r" + PlaceholderAPI.setPlaceholders(pl, parse));
|
||||
}
|
||||
return true;
|
||||
} else if (args.length > 3 && args[0].equalsIgnoreCase("parserel")) {
|
||||
|
||||
return true;
|
||||
}
|
||||
if (!(s instanceof Player)) {
|
||||
Msg.msg(s, "&cThis command can only be used in game!");
|
||||
return true;
|
||||
} else {
|
||||
if (!s.hasPermission("placeholderapi.parse")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Player one = Bukkit.getPlayer(args[1]);
|
||||
if (one == null) {
|
||||
Msg.msg(s, args[1] + " &cis not online!");
|
||||
return true;
|
||||
}
|
||||
Player two = Bukkit.getPlayer(args[2]);
|
||||
if (two == null) {
|
||||
Msg.msg(s, args[2] + " &cis not online!");
|
||||
return true;
|
||||
}
|
||||
String parse = StringUtils.join(args, " ", 3, args.length);
|
||||
Msg.msg(s, "&r" + PlaceholderAPI.setRelationalPlaceholders(one, two, parse));
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.reload")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Msg.msg(s, "&fPlaceholder&7API &bconfiguration reloaded!");
|
||||
plugin.reloadConf(s);
|
||||
} else if (args[0].equalsIgnoreCase("list")) {
|
||||
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.list")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> registered = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
if (registered.isEmpty()) {
|
||||
Msg.msg(s, "&7There are no placeholder hooks currently registered!");
|
||||
return true;
|
||||
}
|
||||
Msg.msg(s, registered.size() + " &7Placeholder hooks registered:");
|
||||
Msg.msg(s, registered.stream().sorted().collect(Collectors.joining(", ")));
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("register")) {
|
||||
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.register")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
String fileName = args[1].replace(".jar", "");
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().registerExpansion(fileName);
|
||||
|
||||
if (ex == null) {
|
||||
Msg.msg(s, "&cFailed to register expansion from " + fileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
Msg.msg(s, "&aSuccessfully registered expansion: &f" + ex.getName());
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("unregister")) {
|
||||
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.register")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
||||
|
||||
if (ex == null) {
|
||||
Msg.msg(s, "&cFailed to find expansion: &f" + args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PlaceholderAPI.unregisterExpansion(ex)) {
|
||||
Msg.msg(s, "&aSuccessfully unregistered expansion: &f" + ex.getName());
|
||||
} else {
|
||||
Msg.msg(s, "&cFailed to unregister expansion: &f" + ex.getName());
|
||||
}
|
||||
|
||||
} else {
|
||||
Msg.msg(s, "&cIncorrect usage! &7/papi help");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,43 +24,43 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
|
||||
public class PlaceholderAPIConfig {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
public PlaceholderAPIConfig(PlaceholderAPIPlugin i) {
|
||||
plugin = i;
|
||||
}
|
||||
|
||||
public void loadDefConfig() {
|
||||
plugin.saveDefaultConfig();
|
||||
plugin.reloadConfig();
|
||||
}
|
||||
|
||||
public boolean checkUpdates() {
|
||||
return plugin.getConfig().getBoolean("check_updates");
|
||||
}
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
public boolean cloudAllowUnverifiedExpansions() {
|
||||
return plugin.getConfig().getBoolean("cloud_allow_unverified_expansions");
|
||||
}
|
||||
|
||||
public boolean isCloudEnabled() {
|
||||
return plugin.getConfig().getBoolean("cloud_enabled");
|
||||
}
|
||||
|
||||
public void setCloudEnabled(boolean b) {
|
||||
plugin.getConfig().set("cloud_enabled", b);
|
||||
plugin.reloadConfig();
|
||||
}
|
||||
|
||||
public String booleanTrue() {
|
||||
return plugin.getConfig().getString("boolean.true");
|
||||
}
|
||||
|
||||
public String booleanFalse() {
|
||||
return plugin.getConfig().getString("boolean.false");
|
||||
}
|
||||
|
||||
public String dateFormat() {
|
||||
return plugin.getConfig().getString("date_format");
|
||||
}
|
||||
public PlaceholderAPIConfig(PlaceholderAPIPlugin i) {
|
||||
plugin = i;
|
||||
}
|
||||
|
||||
public void loadDefConfig() {
|
||||
plugin.saveDefaultConfig();
|
||||
plugin.reloadConfig();
|
||||
}
|
||||
|
||||
public boolean checkUpdates() {
|
||||
return plugin.getConfig().getBoolean("check_updates");
|
||||
}
|
||||
|
||||
public boolean cloudAllowUnverifiedExpansions() {
|
||||
return plugin.getConfig().getBoolean("cloud_allow_unverified_expansions");
|
||||
}
|
||||
|
||||
public boolean isCloudEnabled() {
|
||||
return plugin.getConfig().getBoolean("cloud_enabled");
|
||||
}
|
||||
|
||||
public void setCloudEnabled(boolean b) {
|
||||
plugin.getConfig().set("cloud_enabled", b);
|
||||
plugin.reloadConfig();
|
||||
}
|
||||
|
||||
public String booleanTrue() {
|
||||
return plugin.getConfig().getString("boolean.true");
|
||||
}
|
||||
|
||||
public String booleanFalse() {
|
||||
return plugin.getConfig().getString("boolean.false");
|
||||
}
|
||||
|
||||
public String dateFormat() {
|
||||
return plugin.getConfig().getString("date_format");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (C) 2018 Ryan McCarthy
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package me.clip.placeholderapi.events;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class ExpansionRegisterEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private PlaceholderExpansion expansion;
|
||||
|
||||
public ExpansionRegisterEvent(PlaceholderExpansion expansion) {
|
||||
this.expansion = expansion;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public PlaceholderExpansion getExpansion() {
|
||||
return expansion;
|
||||
}
|
||||
}
|
@@ -20,30 +20,29 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.events;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class ExpansionUnregisterEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private PlaceholderExpansion expansion;
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private PlaceholderExpansion expansion;
|
||||
|
||||
public ExpansionUnregisterEvent(PlaceholderExpansion expansion) {
|
||||
this.expansion = expansion;
|
||||
}
|
||||
public ExpansionUnregisterEvent(PlaceholderExpansion expansion) {
|
||||
this.expansion = expansion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public PlaceholderExpansion getExpansion() {
|
||||
return expansion;
|
||||
}
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public PlaceholderExpansion getExpansion() {
|
||||
return expansion;
|
||||
}
|
||||
}
|
||||
|
@@ -27,29 +27,29 @@ import org.bukkit.event.HandlerList;
|
||||
@Deprecated
|
||||
public class PlaceholderHookUnloadEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String plugin;
|
||||
private PlaceholderHook hook;
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private String plugin;
|
||||
private PlaceholderHook hook;
|
||||
|
||||
public PlaceholderHookUnloadEvent(String plugin, PlaceholderHook placeholderHook) {
|
||||
this.plugin = plugin;
|
||||
this.hook = placeholderHook;
|
||||
}
|
||||
public PlaceholderHookUnloadEvent(String plugin, PlaceholderHook placeholderHook) {
|
||||
this.plugin = plugin;
|
||||
this.hook = placeholderHook;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public String getHookName() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public PlaceholderHook getHook() {
|
||||
return hook;
|
||||
}
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public String getHookName() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public PlaceholderHook getHook() {
|
||||
return hook;
|
||||
}
|
||||
}
|
||||
|
@@ -21,17 +21,16 @@
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
/**
|
||||
* This interface allows a class which extends a {@link PlaceholderExpansion}
|
||||
* to have the clear method called when the implementing expansion is unregistered
|
||||
* from PlaceholderAPI.
|
||||
* This is useful if we want to do things when the implementing hook is unregistered
|
||||
* @author Ryan McCarthy
|
||||
* This interface allows a class which extends a {@link PlaceholderExpansion} to have the clear
|
||||
* method called when the implementing expansion is unregistered from PlaceholderAPI. This is useful
|
||||
* if we want to do things when the implementing hook is unregistered
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public interface Cacheable {
|
||||
|
||||
/**
|
||||
* Called when the implementing class is unregistered from PlaceholderAPI
|
||||
*/
|
||||
void clear();
|
||||
/**
|
||||
* Called when the implementing class is unregistered from PlaceholderAPI
|
||||
*/
|
||||
void clear();
|
||||
}
|
||||
|
@@ -23,17 +23,18 @@ package me.clip.placeholderapi.expansion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* This interface allows a class which extends a {@link PlaceholderExpansion}
|
||||
* to have the cleanup method called every time a player leaves the server.
|
||||
* This is useful if we want to clean up after the player
|
||||
* @author Ryan McCarthy
|
||||
* This interface allows a class which extends a {@link PlaceholderExpansion} to have the cleanup
|
||||
* method called every time a player leaves the server. This is useful if we want to clean up after
|
||||
* the player
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public interface Cleanable {
|
||||
|
||||
/**
|
||||
* Called when a player leaves the server
|
||||
* @param p (@link Player} who left the server
|
||||
*/
|
||||
void cleanup(Player p);
|
||||
/**
|
||||
* Called when a player leaves the server
|
||||
*
|
||||
* @param p (@link Player} who left the server
|
||||
*/
|
||||
void cleanup(Player p);
|
||||
}
|
||||
|
@@ -23,19 +23,21 @@ package me.clip.placeholderapi.expansion;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Any {@link PlaceholderExpansion} class which implements configurable will
|
||||
* have any options listed in the getDefaults map automatically added to the PlaceholderAPI config.yml file
|
||||
* @author Ryan McCarthy
|
||||
* Any {@link PlaceholderExpansion} class which implements configurable will have any options listed
|
||||
* in the getDefaults map automatically added to the PlaceholderAPI config.yml file
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public interface Configurable {
|
||||
|
||||
/**
|
||||
* This method will be called before the implementing class is registered
|
||||
* to obtain a map of configuration options that the implementing class needs
|
||||
* These paths and values will be added to the PlaceholderAPI config.yml in the configuration section
|
||||
* expansions.(placeholder identifier).(your key): (your value)
|
||||
* @return Map of config path / values which need to be added / removed from the PlaceholderAPI config.yml file
|
||||
*/
|
||||
Map<String, Object> getDefaults();
|
||||
/**
|
||||
* This method will be called before the implementing class is registered to obtain a map of
|
||||
* configuration options that the implementing class needs These paths and values will be added to
|
||||
* the PlaceholderAPI config.yml in the configuration section expansions.(placeholder
|
||||
* identifier).(your key): (your value)
|
||||
*
|
||||
* @return Map of config path / values which need to be added / removed from the PlaceholderAPI
|
||||
* config.yml file
|
||||
*/
|
||||
Map<String, Object> getDefaults();
|
||||
}
|
||||
|
@@ -20,6 +20,11 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
@@ -29,174 +34,150 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public final class ExpansionManager {
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
public ExpansionManager(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), "expansions");
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<String, PlaceholderExpansion> cache = new HashMap<>();
|
||||
public PlaceholderExpansion getRegisteredExpansion(String name) {
|
||||
for (Entry<String, PlaceholderHook> hook : PlaceholderAPI.getPlaceholders().entrySet()) {
|
||||
if (hook.getValue() instanceof PlaceholderExpansion) {
|
||||
if (name.equalsIgnoreCase(hook.getKey())) {
|
||||
return (PlaceholderExpansion) hook.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExpansionManager(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
public boolean registerExpansion(PlaceholderExpansion expansion) {
|
||||
if (expansion == null || expansion.getIdentifier() == null) {
|
||||
return false;
|
||||
}
|
||||
if (expansion instanceof Configurable) {
|
||||
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
|
||||
String pre = "expansions." + expansion.getIdentifier() + ".";
|
||||
FileConfiguration cfg = plugin.getConfig();
|
||||
boolean save = false;
|
||||
for (Entry<String, Object> entries : defaults.entrySet()) {
|
||||
if (entries.getKey() == null || entries.getKey().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (entries.getValue() == null) {
|
||||
if (cfg.contains(pre + entries.getKey())) {
|
||||
save = true;
|
||||
cfg.set(pre + entries.getKey(), null);
|
||||
}
|
||||
} else {
|
||||
if (!cfg.contains(pre + entries.getKey())) {
|
||||
save = true;
|
||||
cfg.set(pre + entries.getKey(), entries.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (save) {
|
||||
plugin.saveConfig();
|
||||
plugin.reloadConfig();
|
||||
}
|
||||
}
|
||||
if (expansion instanceof VersionSpecific) {
|
||||
VersionSpecific nms = (VersionSpecific) expansion;
|
||||
if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
|
||||
plugin.getLogger()
|
||||
.info(
|
||||
"Your server version is not compatible with expansion: " + expansion.getIdentifier()
|
||||
+ " version: " + expansion.getVersion());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!expansion.canRegister()) {
|
||||
return false;
|
||||
}
|
||||
if (!expansion.register()) {
|
||||
return false;
|
||||
}
|
||||
if (expansion instanceof Listener) {
|
||||
Listener l = (Listener) expansion;
|
||||
Bukkit.getPluginManager().registerEvents(l, plugin);
|
||||
}
|
||||
plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier());
|
||||
if (expansion instanceof Taskable) {
|
||||
((Taskable) expansion).start();
|
||||
}
|
||||
if (plugin.getExpansionCloud() != null) {
|
||||
CloudExpansion ce = plugin.getExpansionCloud().getCloudExpansion(expansion.getIdentifier());
|
||||
if (ce != null) {
|
||||
ce.setHasExpansion(true);
|
||||
if (!ce.getLatestVersion().equals(expansion.getVersion())) {
|
||||
ce.setShouldUpdate(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
public PlaceholderExpansion getCachedExpansion(String plugin) {
|
||||
return cache.getOrDefault(plugin, null);
|
||||
}
|
||||
public PlaceholderExpansion registerExpansion(String fileName) {
|
||||
List<Class<?>> subs = FileUtil.getClasses("expansions", fileName, PlaceholderExpansion.class);
|
||||
if (subs == null || subs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// only register the first instance found as an expansion jar should only have 1 class
|
||||
// extending PlaceholderExpansion
|
||||
PlaceholderExpansion ex = createInstance(subs.get(0));
|
||||
if (registerExpansion(ex)) {
|
||||
return ex;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean removeCachedExpansion(String identifier) {
|
||||
return cache.remove(identifier) != null;
|
||||
}
|
||||
public void registerAllExpansions() {
|
||||
if (plugin == null) {
|
||||
return;
|
||||
}
|
||||
List<Class<?>> subs = FileUtil.getClasses("expansions", null, PlaceholderExpansion.class);
|
||||
if (subs == null || subs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Class<?> klass : subs) {
|
||||
PlaceholderExpansion ex = createInstance(klass);
|
||||
if (ex != null) {
|
||||
registerExpansion(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PlaceholderExpansion getRegisteredExpansion(String name) {
|
||||
for (Entry<String, PlaceholderHook> hook : PlaceholderAPI.getPlaceholders().entrySet()) {
|
||||
if (hook.getValue() instanceof PlaceholderExpansion) {
|
||||
if (name.equalsIgnoreCase(hook.getKey())) {
|
||||
return (PlaceholderExpansion) hook.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean registerExpansion(PlaceholderExpansion c) {
|
||||
|
||||
if (c == null || c.getIdentifier() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (c instanceof Configurable) {
|
||||
|
||||
Map<String, Object> defaults = ((Configurable) c).getDefaults();
|
||||
String pre = "expansions." + c.getIdentifier() + ".";
|
||||
FileConfiguration cfg = plugin.getConfig();
|
||||
|
||||
boolean save = false;
|
||||
|
||||
for (Entry<String, Object> entries : defaults.entrySet()) {
|
||||
if (entries.getKey() == null || entries.getKey().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entries.getValue() == null) {
|
||||
if (cfg.contains(pre + entries.getKey())) {
|
||||
save = true;
|
||||
cfg.set(pre + entries.getKey(), null);
|
||||
}
|
||||
} else {
|
||||
if (!cfg.contains(pre + entries.getKey())) {
|
||||
save = true;
|
||||
cfg.set(pre + entries.getKey(), entries.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (save) {
|
||||
plugin.saveConfig();
|
||||
plugin.reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
if (c instanceof VersionSpecific) {
|
||||
VersionSpecific nms = (VersionSpecific) c;
|
||||
if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
|
||||
plugin.getLogger().info("Your server version is not compatible with expansion: " + c.getIdentifier()
|
||||
+ " version: " + c.getVersion());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!c.canRegister()) {
|
||||
if (c.getPlugin() != null) {
|
||||
cache.put(c.getPlugin().toLowerCase(), c);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!c.register()) {
|
||||
if (c.getPlugin() != null) {
|
||||
cache.put(c.getPlugin().toLowerCase(), c);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (c instanceof Listener) {
|
||||
Listener l = (Listener) c;
|
||||
Bukkit.getPluginManager().registerEvents(l, plugin);
|
||||
}
|
||||
|
||||
plugin.getLogger().info("Successfully registered expansion: " + c.getIdentifier());
|
||||
|
||||
if (c instanceof Taskable) {
|
||||
((Taskable) c).start();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void registerAllExpansions() {
|
||||
|
||||
if (plugin == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Class<?>> subs = FileUtil.getClasses("expansions", PlaceholderExpansion.class);
|
||||
|
||||
if (subs == null || subs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Class<?> klass : subs) {
|
||||
|
||||
if (klass == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
PlaceholderExpansion ex = null;
|
||||
|
||||
Constructor<?>[] c = klass.getConstructors();
|
||||
|
||||
if (c.length == 0) {
|
||||
ex = (PlaceholderExpansion) klass.newInstance();
|
||||
} else {
|
||||
for (Constructor<?> con : c) {
|
||||
if (con.getParameterTypes().length == 0) {
|
||||
ex = (PlaceholderExpansion) klass.newInstance();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ex == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (registerExpansion(ex)) {
|
||||
if (plugin.getExpansionCloud() != null) {
|
||||
CloudExpansion ce = plugin.getExpansionCloud().getCloudExpansion(ex.getIdentifier());
|
||||
if (ce != null) {
|
||||
ce.setHasExpansion(true);
|
||||
if (!ce.getVersion().equals(ex.getVersion())) {
|
||||
ce.setShouldUpdate(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
plugin.getLogger().severe("Failed to load placeholder expansion from class: " + klass.getName());
|
||||
plugin.getLogger().severe(t.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
private PlaceholderExpansion createInstance(Class<?> klass) {
|
||||
if (klass == null) {
|
||||
return null;
|
||||
}
|
||||
PlaceholderExpansion ex = null;
|
||||
if (!PlaceholderExpansion.class.isAssignableFrom(klass)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Constructor<?>[] c = klass.getConstructors();
|
||||
if (c.length == 0) {
|
||||
ex = (PlaceholderExpansion) klass.newInstance();
|
||||
} else {
|
||||
for (Constructor<?> con : c) {
|
||||
if (con.getParameterTypes().length == 0) {
|
||||
ex = (PlaceholderExpansion) klass.newInstance();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
plugin.getLogger()
|
||||
.severe("Failed to init placeholder expansion from class: " + klass.getName());
|
||||
plugin.getLogger().severe(t.getMessage());
|
||||
}
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
|
@@ -22,36 +22,40 @@ package me.clip.placeholderapi.expansion;
|
||||
|
||||
public enum NMSVersion {
|
||||
|
||||
UNKNOWN("unknown"),
|
||||
SPIGOT_1_7_R1("v1_7_R1"),
|
||||
SPIGOT_1_7_R2("v1_7_R2"),
|
||||
SPIGOT_1_7_R3("v1_7_R3"),
|
||||
SPIGOT_1_7_R4("v1_7_R4"),
|
||||
SPIGOT_1_8_R1("v1_8_R1"),
|
||||
SPIGOT_1_8_R2("v1_8_R2"),
|
||||
SPIGOT_1_8_R3("v1_8_R3"),
|
||||
SPIGOT_1_9_R1("v1_9_R1"),
|
||||
SPIGOT_1_9_R2("v1_9_R2"),
|
||||
SPIGOT_1_10_R1("v1_10_R1"),
|
||||
SPIGOT_1_11_R1("v1_11_R1"),
|
||||
SPIGOT_1_12_R1("v1_12_R1");
|
||||
|
||||
private String version;
|
||||
|
||||
NMSVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public static NMSVersion getVersion(String version) {
|
||||
for (NMSVersion v : values()) {
|
||||
if (v.getVersion().equalsIgnoreCase(version)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return NMSVersion.UNKNOWN;
|
||||
}
|
||||
UNKNOWN("unknown"),
|
||||
SPIGOT_1_7_R1("v1_7_R1"),
|
||||
SPIGOT_1_7_R2("v1_7_R2"),
|
||||
SPIGOT_1_7_R3("v1_7_R3"),
|
||||
SPIGOT_1_7_R4("v1_7_R4"),
|
||||
SPIGOT_1_8_R1("v1_8_R1"),
|
||||
SPIGOT_1_8_R2("v1_8_R2"),
|
||||
SPIGOT_1_8_R3("v1_8_R3"),
|
||||
SPIGOT_1_9_R1("v1_9_R1"),
|
||||
SPIGOT_1_9_R2("v1_9_R2"),
|
||||
SPIGOT_1_10_R1("v1_10_R1"),
|
||||
SPIGOT_1_11_R1("v1_11_R1"),
|
||||
SPIGOT_1_12_R1("v1_12_R1"),
|
||||
SPIGOT_1_13_R1("v1_13_R1"),
|
||||
SPIGOT_1_13_R2("v1_13_R2"),
|
||||
SPIGOT_1_14_R1("v1_14_R1");
|
||||
|
||||
private String version;
|
||||
|
||||
NMSVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public static NMSVersion getVersion(String version) {
|
||||
for (NMSVersion v : values()) {
|
||||
if (v.getVersion().equalsIgnoreCase(version)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return NMSVersion.UNKNOWN;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
import java.util.List;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
@@ -27,130 +28,172 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
|
||||
/**
|
||||
* The name of this expansion
|
||||
* @return identifier used for expansion if no name present
|
||||
*/
|
||||
public String getName() {
|
||||
return getIdentifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier that this placeholder expansion uses to be passed placeholder requests
|
||||
* @return placeholder identifier that is associated with this class
|
||||
*/
|
||||
public abstract String getIdentifier();
|
||||
|
||||
/**
|
||||
* Get the plugin that this expansion hooks into.
|
||||
* This will ensure the expansion is added to a cache if canRegister() returns false
|
||||
* get.
|
||||
* The expansion will be removed from the cache
|
||||
* once a plugin loads with the name that is here and the expansion is registered
|
||||
* @return placeholder identifier that is associated with this class
|
||||
*/
|
||||
public abstract String getPlugin();
|
||||
|
||||
/**
|
||||
* Get the author of this PlaceholderExpansion
|
||||
* @return name of the author for this expansion
|
||||
*/
|
||||
public abstract String getAuthor();
|
||||
|
||||
/**
|
||||
* Get the version of this PlaceholderExpansion
|
||||
* @return current version of this expansion
|
||||
*/
|
||||
public abstract String getVersion();
|
||||
/**
|
||||
* The name of this expansion
|
||||
*
|
||||
* @return {@link #getIdentifier()} by default, name of this expansion if specified
|
||||
*/
|
||||
public String getName() {
|
||||
return getIdentifier();
|
||||
}
|
||||
|
||||
public String getDescription() { return null; }
|
||||
/**
|
||||
* The placeholder identifier of this expanion
|
||||
*
|
||||
* @return placeholder identifier that is associated with this expansion
|
||||
*/
|
||||
public abstract String getIdentifier();
|
||||
|
||||
public String getLink() { return null; }
|
||||
/**
|
||||
* The author of this expansion
|
||||
*
|
||||
* @return name of the author for this expansion
|
||||
*/
|
||||
public abstract String getAuthor();
|
||||
|
||||
public List<String> getPlaceholders() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* The version of this expansion
|
||||
*
|
||||
* @return current version of this expansion
|
||||
*/
|
||||
public abstract String getVersion();
|
||||
|
||||
/**
|
||||
* Expansions that do not use the ecloud and instead register from the dependency should set this to true
|
||||
* to ensure that your placeholder expansion is not unregistered when the papi reload command is used
|
||||
* @return if the expansion should persist through reloads
|
||||
*/
|
||||
public boolean persist() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a placeholder has already been registered with this identifier
|
||||
* @return true if the identifier for this expansion has already been registered
|
||||
*/
|
||||
public boolean isRegistered() {
|
||||
Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!");
|
||||
return PlaceholderAPI.getRegisteredIdentifiers().contains(getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* If any requirements are required to be checked before this hook can register, add them here
|
||||
* @return true if this hook meets all the requirements to register
|
||||
*/
|
||||
public boolean canRegister() {
|
||||
return getPlugin() == null || Bukkit.getPluginManager().getPlugin(getPlugin()) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to register this PlaceholderExpansion with PlaceholderAPI
|
||||
* @return true if this class and identifier have been successfully registered with PlaceholderAPI
|
||||
*/
|
||||
public boolean register() {
|
||||
Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!");
|
||||
return PlaceholderAPI.registerPlaceholderHook(getIdentifier(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick getter for the {@link PlaceholderAPIPlugin} instance
|
||||
* @return {@link PlaceholderAPIPlugin} instance
|
||||
*/
|
||||
public PlaceholderAPIPlugin getPlaceholderAPI() {
|
||||
return PlaceholderAPIPlugin.getInstance();
|
||||
}
|
||||
|
||||
public String getString(String path, String def) {
|
||||
return getPlaceholderAPI().getConfig().getString("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return getPlaceholderAPI().getConfig().getInt("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public long getLong(String path, long def) {
|
||||
return getPlaceholderAPI().getConfig().getLong("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public double getDouble(String path, double def) {
|
||||
return getPlaceholderAPI().getConfig().getDouble("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public List<String> getStringList(String path) {
|
||||
return getPlaceholderAPI().getConfig().getStringList("expansions." + getIdentifier() + "." + path);
|
||||
}
|
||||
|
||||
public Object get(String path, Object def) {
|
||||
return getPlaceholderAPI().getConfig().get("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public ConfigurationSection getConfigSection(String path) {
|
||||
return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier() + "." + path);
|
||||
}
|
||||
|
||||
public ConfigurationSection getConfigSection() {
|
||||
return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier());
|
||||
}
|
||||
|
||||
public boolean configurationContains(String path) {
|
||||
return getPlaceholderAPI().getConfig().contains("expansions." + getIdentifier() + "." + path);
|
||||
}
|
||||
/**
|
||||
* The name of the plugin that this expansion hooks into. by default will return the deprecated
|
||||
* {@link #getPlugin()} method
|
||||
*
|
||||
* @return plugin name that this expansion requires to function
|
||||
*/
|
||||
public String getRequiredPlugin() {
|
||||
return getPlugin();
|
||||
}
|
||||
|
||||
/**
|
||||
* The placeholders associated with this expansion
|
||||
*
|
||||
* @return placeholder list that this expansion provides
|
||||
*/
|
||||
public List<String> getPlaceholders() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expansions that do not use the ecloud and instead register from the dependency should set this
|
||||
* to true to ensure that your placeholder expansion is not unregistered when the papi reload
|
||||
* command is used
|
||||
*
|
||||
* @return if this expansion should persist through placeholder reloads
|
||||
*/
|
||||
public boolean persist() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this placeholder identfier has already been registered
|
||||
*
|
||||
* @return true if the identifier for this expansion is already registered
|
||||
*/
|
||||
public boolean isRegistered() {
|
||||
Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!");
|
||||
return PlaceholderAPI.getRegisteredIdentifiers().contains(getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* If any requirements need to be checked before this expansion should register, you can check
|
||||
* them here
|
||||
*
|
||||
* @return true if this hook meets all the requirements to register
|
||||
*/
|
||||
public boolean canRegister() {
|
||||
return getRequiredPlugin() == null
|
||||
|| Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to register this PlaceholderExpansion
|
||||
*
|
||||
* @return true if this expansion is now registered with PlaceholderAPI
|
||||
*/
|
||||
public boolean register() {
|
||||
Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!");
|
||||
return PlaceholderAPI.registerExpansion(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick getter for the {@link PlaceholderAPIPlugin} instance
|
||||
*
|
||||
* @return {@link PlaceholderAPIPlugin} instance
|
||||
*/
|
||||
public PlaceholderAPIPlugin getPlaceholderAPI() {
|
||||
return PlaceholderAPIPlugin.getInstance();
|
||||
}
|
||||
|
||||
public String getString(String path, String def) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getString("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getInt("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public long getLong(String path, long def) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getLong("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public double getDouble(String path, double def) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getDouble("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public List<String> getStringList(String path) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getStringList("expansions." + getIdentifier() + "." + path);
|
||||
}
|
||||
|
||||
public Object get(String path, Object def) {
|
||||
return getPlaceholderAPI().getConfig().get("expansions." + getIdentifier() + "." + path, def);
|
||||
}
|
||||
|
||||
public ConfigurationSection getConfigSection(String path) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getConfigurationSection("expansions." + getIdentifier() + "." + path);
|
||||
}
|
||||
|
||||
public ConfigurationSection getConfigSection() {
|
||||
return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier());
|
||||
}
|
||||
|
||||
public boolean configurationContains(String path) {
|
||||
return getPlaceholderAPI().getConfig().contains("expansions." + getIdentifier() + "." + path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated As of versions greater than 2.8.7, use {@link #getRequiredPlugin()}
|
||||
*/
|
||||
@Deprecated
|
||||
public String getPlugin() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of versions greater than 2.8.7, use the expansion cloud to show a description
|
||||
*/
|
||||
@Deprecated
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of versions greater than 2.8.7, use the expansion cloud to display a link
|
||||
*/
|
||||
@Deprecated
|
||||
public String getLink() {
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -23,5 +23,6 @@ package me.clip.placeholderapi.expansion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Relational {
|
||||
String onPlaceholderRequest(Player one, Player two, String identifier);
|
||||
|
||||
String onPlaceholderRequest(Player one, Player two, String identifier);
|
||||
}
|
||||
|
@@ -22,16 +22,16 @@ package me.clip.placeholderapi.expansion;
|
||||
|
||||
|
||||
public interface Taskable {
|
||||
|
||||
/**
|
||||
* Called when the implementing class has successfully been registered to the placeholder map
|
||||
* Tasks that need to be performed when this expansion is registered should go here
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Called when the implementing class has been unregistered from PlaceholderAPI
|
||||
* Tasks that need to be performed when this expansion has unregistered should go here
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Called when the implementing class has successfully been registered to the placeholder map
|
||||
* Tasks that need to be performed when this expansion is registered should go here
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Called when the implementing class has been unregistered from PlaceholderAPI Tasks that need to
|
||||
* be performed when this expansion has unregistered should go here
|
||||
*/
|
||||
void stop();
|
||||
}
|
||||
|
@@ -20,22 +20,27 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
public class Version {
|
||||
public final class Version {
|
||||
|
||||
private boolean isSpigot;
|
||||
|
||||
private String version;
|
||||
|
||||
public Version(String version, boolean isSpigot) {
|
||||
this.version = version;
|
||||
this.isSpigot = isSpigot;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version == null ? "unknown" : version;
|
||||
}
|
||||
|
||||
public boolean isSpigot() {
|
||||
return isSpigot;
|
||||
}
|
||||
|
||||
public boolean compareTo(String version) {
|
||||
return getVersion().equalsIgnoreCase(version);
|
||||
}
|
||||
|
||||
private boolean isSpigot;
|
||||
|
||||
private String version;
|
||||
|
||||
public Version(String version, boolean isSpigot) {
|
||||
this.version = version;
|
||||
this.isSpigot = isSpigot;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version == null ? "unknown" : version;
|
||||
}
|
||||
|
||||
public boolean isSpigot() {
|
||||
return isSpigot;
|
||||
}
|
||||
}
|
||||
|
@@ -21,19 +21,20 @@
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
/**
|
||||
* Placeholder expansions which use NMS code should be version specific.
|
||||
* Implementing this class allows you to perform checks based on the version the server is running.
|
||||
* The isCompatibleWith method will be passed the server version and allow you to return if your expansion is compatible with that version.
|
||||
* @author Ryan McCarthy
|
||||
* Placeholder expansions which use NMS code should be version specific. Implementing this class
|
||||
* allows you to perform checks based on the version the server is running. The isCompatibleWith
|
||||
* method will be passed the server version and allow you to return if your expansion is compatible
|
||||
* with that version.
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public interface VersionSpecific {
|
||||
|
||||
/**
|
||||
* This method is called before the expansion is attempted to be registered
|
||||
* The server version will be passed to this method so you know what version the server is currently running.
|
||||
*
|
||||
* @return true if your expansion is compatible with the version the server is running.
|
||||
*/
|
||||
boolean isCompatibleWith(Version v);
|
||||
/**
|
||||
* This method is called before the expansion is attempted to be registered The server version
|
||||
* will be passed to this method so you know what version the server is currently running.
|
||||
*
|
||||
* @return true if your expansion is compatible with the version the server is running.
|
||||
*/
|
||||
boolean isCompatibleWith(Version v);
|
||||
}
|
||||
|
@@ -20,185 +20,183 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.expansion.cloud;
|
||||
|
||||
import me.clip.placeholderapi.util.TimeUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import me.clip.placeholderapi.util.TimeUtil;
|
||||
|
||||
|
||||
public class CloudExpansion {
|
||||
|
||||
private String name,
|
||||
author,
|
||||
latest_version,
|
||||
description,
|
||||
source_url,
|
||||
dependency_url;
|
||||
private String name,
|
||||
author,
|
||||
latest_version,
|
||||
description,
|
||||
source_url,
|
||||
dependency_url;
|
||||
|
||||
private boolean hasExpansion,
|
||||
shouldUpdate,
|
||||
verified;
|
||||
private boolean hasExpansion,
|
||||
shouldUpdate,
|
||||
verified;
|
||||
|
||||
private long last_update,
|
||||
ratings_count;
|
||||
private long last_update,
|
||||
ratings_count;
|
||||
|
||||
private double average_rating;
|
||||
private double average_rating;
|
||||
|
||||
private List<String> placeholders;
|
||||
private List<String> placeholders;
|
||||
|
||||
private List<Version> versions;
|
||||
private List<Version> versions;
|
||||
|
||||
public CloudExpansion() {
|
||||
}
|
||||
public CloudExpansion() {
|
||||
}
|
||||
|
||||
public String getTimeSinceLastUpdate() {
|
||||
int time = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getLastUpdate());
|
||||
return TimeUtil.getTime(time);
|
||||
}
|
||||
public String getTimeSinceLastUpdate() {
|
||||
int time = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getLastUpdate());
|
||||
return TimeUtil.getTime(time);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return getLatestVersion() == null ? null : getVersion(getLatestVersion());
|
||||
}
|
||||
|
||||
public Version getVersion(String version) {
|
||||
return versions == null ? null : versions.stream()
|
||||
.filter(v -> v.getVersion().equals(version))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public List<String> getAvailableVersions() {
|
||||
return versions.stream().map(Version::getVersion).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String getLatestVersion() {
|
||||
return latest_version;
|
||||
}
|
||||
|
||||
public void setLatestVersion(String latest_version) {
|
||||
this.latest_version = latest_version;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getSourceUrl() {
|
||||
return source_url;
|
||||
}
|
||||
|
||||
public void setSourceUrl(String source_url) {
|
||||
this.source_url = source_url;
|
||||
}
|
||||
|
||||
public String getDependencyUrl() {
|
||||
return dependency_url;
|
||||
}
|
||||
|
||||
public void setDependencyUrl(String dependency_url) {
|
||||
this.dependency_url = dependency_url;
|
||||
}
|
||||
|
||||
public boolean hasExpansion() {
|
||||
return hasExpansion;
|
||||
}
|
||||
|
||||
public void setHasExpansion(boolean hasExpansion) {
|
||||
this.hasExpansion = hasExpansion;
|
||||
}
|
||||
|
||||
public boolean shouldUpdate() {
|
||||
return shouldUpdate;
|
||||
}
|
||||
|
||||
public void setShouldUpdate(boolean shouldUpdate) {
|
||||
this.shouldUpdate = shouldUpdate;
|
||||
}
|
||||
|
||||
public boolean isVerified() {
|
||||
return verified;
|
||||
}
|
||||
|
||||
public long getLastUpdate() {
|
||||
return last_update;
|
||||
}
|
||||
|
||||
public void setLastUpdate(long last_update) {
|
||||
this.last_update = last_update;
|
||||
}
|
||||
|
||||
public long getRatingsCount() {
|
||||
return ratings_count;
|
||||
}
|
||||
|
||||
public double getAverage_rating() {
|
||||
return average_rating;
|
||||
}
|
||||
|
||||
public List<String> getPlaceholders() {
|
||||
return placeholders;
|
||||
}
|
||||
|
||||
public void setPlaceholders(List<String> placeholders) {
|
||||
this.placeholders = placeholders;
|
||||
}
|
||||
|
||||
public List<Version> getVersions() {
|
||||
return versions;
|
||||
}
|
||||
|
||||
public void setVersions(List<Version> versions) {
|
||||
this.versions = versions;
|
||||
}
|
||||
|
||||
public class Version {
|
||||
|
||||
private String url, version, release_notes;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return getLatestVersion() == null ? null : getVersion(getLatestVersion());
|
||||
public String getReleaseNotes() {
|
||||
return release_notes;
|
||||
}
|
||||
|
||||
public Version getVersion(String version) {
|
||||
return versions == null ? null : versions.stream()
|
||||
.filter(v -> v.getVersion().equals(version))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public List<String> getAvailableVersions() {
|
||||
return versions.stream().map(Version::getVersion).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String getLatestVersion() {
|
||||
return latest_version;
|
||||
}
|
||||
|
||||
public void setLatestVersion(String latest_version) {
|
||||
this.latest_version = latest_version;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getSourceUrl() {
|
||||
return source_url;
|
||||
}
|
||||
|
||||
public void setSourceUrl(String source_url) {
|
||||
this.source_url = source_url;
|
||||
}
|
||||
|
||||
public String getDependencyUrl() {
|
||||
return dependency_url;
|
||||
}
|
||||
|
||||
public void setDependencyUrl(String dependency_url) {
|
||||
this.dependency_url = dependency_url;
|
||||
}
|
||||
|
||||
public boolean hasExpansion() {
|
||||
return hasExpansion;
|
||||
}
|
||||
|
||||
public void setHasExpansion(boolean hasExpansion) {
|
||||
this.hasExpansion = hasExpansion;
|
||||
}
|
||||
|
||||
public boolean shouldUpdate() {
|
||||
return shouldUpdate;
|
||||
}
|
||||
|
||||
public void setShouldUpdate(boolean shouldUpdate) {
|
||||
this.shouldUpdate = shouldUpdate;
|
||||
}
|
||||
|
||||
public boolean isVerified() {
|
||||
return verified;
|
||||
}
|
||||
|
||||
public long getLastUpdate() {
|
||||
return last_update;
|
||||
}
|
||||
|
||||
public void setLastUpdate(long last_update) {
|
||||
this.last_update = last_update;
|
||||
}
|
||||
|
||||
public long getRatingsCount() {
|
||||
return ratings_count;
|
||||
}
|
||||
|
||||
public double getAverage_rating() {
|
||||
return average_rating;
|
||||
}
|
||||
|
||||
public List<String> getPlaceholders() {
|
||||
return placeholders;
|
||||
}
|
||||
|
||||
public void setPlaceholders(List<String> placeholders) {
|
||||
this.placeholders = placeholders;
|
||||
}
|
||||
|
||||
public List<Version> getVersions() {
|
||||
return versions;
|
||||
}
|
||||
|
||||
public void setVersions(List<Version> versions) {
|
||||
this.versions = versions;
|
||||
}
|
||||
|
||||
public class Version {
|
||||
private String url, version, release_notes;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getReleaseNotes() {
|
||||
return release_notes;
|
||||
}
|
||||
|
||||
public void setReleaseNotes(String release_notes) {
|
||||
this.release_notes = release_notes;
|
||||
}
|
||||
public void setReleaseNotes(String release_notes) {
|
||||
this.release_notes = release_notes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,310 +21,262 @@
|
||||
package me.clip.placeholderapi.expansion.cloud;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ExpansionCloudManager {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
private final String API = "http://api.extendedclip.com/v2/";
|
||||
private final File dir;
|
||||
private final TreeMap<Integer, CloudExpansion> remote = new TreeMap<>();
|
||||
private final List<String> downloading = new ArrayList<>();
|
||||
private Gson gson;
|
||||
private static final String API_URL = "http://api.extendedclip.com/v2/";
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
public ExpansionCloudManager(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
gson = new Gson();
|
||||
dir = new File(instance.getDataFolder() + File.separator + "expansions");
|
||||
if (!dir.exists()) {
|
||||
try {
|
||||
dir.mkdirs();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
private final File expansionsDir;
|
||||
|
||||
private final List<String> downloading = new ArrayList<>();
|
||||
private final Map<Integer, CloudExpansion> remote = new TreeMap<>();
|
||||
|
||||
|
||||
public ExpansionCloudManager(PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
expansionsDir = new File(plugin.getDataFolder(), "expansions");
|
||||
|
||||
final boolean result = expansionsDir.mkdirs();
|
||||
if (result) {
|
||||
plugin.getLogger().info("Created Expansions Directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
remote.clear();
|
||||
downloading.clear();
|
||||
gson = null;
|
||||
}
|
||||
|
||||
public boolean isDownloading(String expansion) {
|
||||
return downloading.contains(expansion);
|
||||
}
|
||||
|
||||
public Map<Integer, CloudExpansion> getCloudExpansions() {
|
||||
return remote;
|
||||
}
|
||||
|
||||
public CloudExpansion getCloudExpansion(String name) {
|
||||
return remote.values().stream().filter(ex -> ex.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public int getCloudAuthorCount() {
|
||||
return remote.values().stream().collect(Collectors.groupingBy(CloudExpansion::getAuthor, Collectors.counting())).size();
|
||||
}
|
||||
|
||||
public long getToUpdateCount() {
|
||||
return PlaceholderAPI.getExpansions().stream().filter(ex -> getCloudExpansion(ex.getName()) != null && getCloudExpansion(ex.getName()).shouldUpdate()).count();
|
||||
|
||||
}
|
||||
|
||||
public Map<Integer, CloudExpansion> getAllByAuthor(String author) {
|
||||
if (remote.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
TreeMap<Integer, CloudExpansion> byAuthor = new TreeMap<>();
|
||||
boolean first = true;
|
||||
for (CloudExpansion ex : remote.values()) {
|
||||
if (ex.getAuthor().equalsIgnoreCase(author)) {
|
||||
if (first) {
|
||||
first = false;
|
||||
byAuthor.put(0, ex);
|
||||
} else {
|
||||
byAuthor.put(byAuthor.lastKey()+1, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (byAuthor.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return byAuthor;
|
||||
}
|
||||
|
||||
public Map<Integer, CloudExpansion> getAllInstalled() {
|
||||
if (remote.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
TreeMap<Integer, CloudExpansion> has = new TreeMap<>();
|
||||
boolean first = true;
|
||||
for (CloudExpansion ex : remote.values()) {
|
||||
if (ex.hasExpansion()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
has.put(1, ex);
|
||||
} else {
|
||||
has.put(has.lastKey()+1, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (has.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return has;
|
||||
}
|
||||
|
||||
public int getPagesAvailable(Map<Integer, CloudExpansion> map, int amount) {
|
||||
if (map == null) {
|
||||
return 0;
|
||||
}
|
||||
int pages = map.size() > 0 ? 1 : 0;
|
||||
if (pages == 0) {
|
||||
return pages;
|
||||
}
|
||||
if (map.size() > amount) {
|
||||
pages = map.size()/amount;
|
||||
if (map.size() % amount > 0) {
|
||||
pages++;
|
||||
}
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
public Map<Integer, CloudExpansion> getPage(Map<Integer, CloudExpansion> map, int page, int size) {
|
||||
if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) {
|
||||
return null;
|
||||
}
|
||||
int end = size*page;
|
||||
int start = end-size;
|
||||
TreeMap<Integer, CloudExpansion> ex = new TreeMap<>();
|
||||
|
||||
public void clean() {
|
||||
remote.clear();
|
||||
downloading.clear();
|
||||
}
|
||||
|
||||
|
||||
public Map<Integer, CloudExpansion> getCloudExpansions() {
|
||||
return remote;
|
||||
}
|
||||
|
||||
public CloudExpansion getCloudExpansion(String name) {
|
||||
return remote.values()
|
||||
.stream()
|
||||
.filter(ex -> ex.getName().equalsIgnoreCase(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
public int getCloudAuthorCount() {
|
||||
return remote.values()
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(CloudExpansion::getAuthor, Collectors.counting()))
|
||||
.size();
|
||||
}
|
||||
|
||||
public int getToUpdateCount() {
|
||||
return ((int) PlaceholderAPI.getExpansions()
|
||||
.stream()
|
||||
.filter(ex -> getCloudExpansion(ex.getName()) != null && getCloudExpansion(ex.getName()).shouldUpdate())
|
||||
.count());
|
||||
}
|
||||
|
||||
|
||||
public Map<Integer, CloudExpansion> getAllByAuthor(String author) {
|
||||
if (remote.isEmpty()) return new HashMap<>();
|
||||
|
||||
Map<Integer, CloudExpansion> byAuthor = new TreeMap<>();
|
||||
|
||||
for (CloudExpansion ex : remote.values()) {
|
||||
if (!ex.getAuthor().equalsIgnoreCase(author)) continue;
|
||||
|
||||
byAuthor.put(byAuthor.size(), ex);
|
||||
}
|
||||
|
||||
return byAuthor;
|
||||
}
|
||||
|
||||
public Map<Integer, CloudExpansion> getAllInstalled() {
|
||||
if (remote.isEmpty()) return new HashMap<>();
|
||||
|
||||
Map<Integer, CloudExpansion> has = new TreeMap<>();
|
||||
|
||||
for (CloudExpansion ex : remote.values()) {
|
||||
if (!ex.hasExpansion()) continue;
|
||||
|
||||
has.put(has.size(), ex);
|
||||
}
|
||||
|
||||
return has;
|
||||
}
|
||||
|
||||
|
||||
public int getPagesAvailable(Map<Integer, CloudExpansion> map, int amount) {
|
||||
if (map == null) {
|
||||
return 0;
|
||||
}
|
||||
int pages = map.size() > 0 ? 1 : 0;
|
||||
if (pages == 0) {
|
||||
return pages;
|
||||
}
|
||||
if (map.size() > amount) {
|
||||
pages = map.size() / amount;
|
||||
if (map.size() % amount > 0) {
|
||||
pages++;
|
||||
}
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
public Map<Integer, CloudExpansion> getPage(Map<Integer, CloudExpansion> map, int page, int size) {
|
||||
if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
int end = size * page;
|
||||
int start = end - size;
|
||||
|
||||
Map<Integer, CloudExpansion> ex = new TreeMap<>();
|
||||
IntStream.range(start, end).forEach(n -> ex.put(n, map.get(n)));
|
||||
return ex;
|
||||
}
|
||||
|
||||
public void fetch() {
|
||||
|
||||
plugin.getLogger().info("Fetching available expansion information...");
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
StringBuilder sb;
|
||||
|
||||
try {
|
||||
|
||||
URL site = new URL(API);
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) site.openConnection();
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
|
||||
connection.connect();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
|
||||
sb = new StringBuilder();
|
||||
|
||||
String line;
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
br.close();
|
||||
connection.disconnect();
|
||||
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
|
||||
String json = sb.toString();
|
||||
JSONParser parser = new JSONParser();
|
||||
Object obj = null;
|
||||
|
||||
try {
|
||||
obj = parser.parse(json);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<CloudExpansion> unsorted = new ArrayList<>();
|
||||
|
||||
if (obj instanceof JSONObject) {
|
||||
|
||||
JSONObject jo = (JSONObject) obj;
|
||||
|
||||
for (Object o : jo.keySet()) {
|
||||
|
||||
JSONObject sub = (JSONObject) jo.get(o);
|
||||
|
||||
CloudExpansion ce = gson.fromJson(sub.toJSONString(), CloudExpansion.class);
|
||||
|
||||
if (ce.getLatestVersion() == null || ce.getVersion(ce.getLatestVersion()) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ce.setName(o.toString());
|
||||
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(ce.getName());
|
||||
|
||||
if (ex != null && ex.isRegistered()) {
|
||||
ce.setHasExpansion(true);
|
||||
if (!ex.getVersion().equals(ce.getLatestVersion())) {
|
||||
ce.setShouldUpdate(true);
|
||||
}
|
||||
}
|
||||
|
||||
unsorted.add(ce);
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
|
||||
unsorted.sort(Comparator.comparing(CloudExpansion::getLastUpdate).reversed());
|
||||
|
||||
for (CloudExpansion e : unsorted) {
|
||||
remote.put(count, e);
|
||||
count++;
|
||||
}
|
||||
|
||||
plugin.getLogger().info(count + " placeholder expansions are available on the cloud.");
|
||||
|
||||
long updates = getToUpdateCount();
|
||||
|
||||
if (updates > 0) {
|
||||
plugin.getLogger().info(updates + " installed expansions have updates available.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
private void download(URL url, String name) throws IOException {
|
||||
|
||||
InputStream is = null;
|
||||
|
||||
FileOutputStream fos = null;
|
||||
|
||||
try {
|
||||
|
||||
URLConnection urlConn = url.openConnection();
|
||||
|
||||
is = urlConn.getInputStream();
|
||||
|
||||
fos = new FileOutputStream(dir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar");
|
||||
|
||||
byte[] buffer = new byte[is.available()];
|
||||
|
||||
int l;
|
||||
|
||||
while ((l = is.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, l);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void downloadExpansion(final String player, final CloudExpansion ex) {
|
||||
downloadExpansion(player, ex, ex.getLatestVersion());
|
||||
return ex;
|
||||
}
|
||||
|
||||
public void downloadExpansion(final String player, final CloudExpansion ex, final String version) {
|
||||
|
||||
if (downloading.contains(ex.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CloudExpansion.Version ver = ex.getVersions()
|
||||
.stream()
|
||||
.filter(v -> v.getVersion().equals(version))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
|
||||
if (ver == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
downloading.add(ex.getName());
|
||||
|
||||
plugin.getLogger().info("Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " + player : "") + " from url: " + ver.getUrl());
|
||||
public void fetch(boolean allowUnverified) {
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
plugin.getLogger().info("Fetching available expansion information...");
|
||||
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
|
||||
final String readJson = URLReader.read(API_URL);
|
||||
final Map<String, CloudExpansion> data = GSON.fromJson(readJson, new TypeToken<Map<String, CloudExpansion>>() {
|
||||
}.getType());
|
||||
|
||||
final List<CloudExpansion> unsorted = new ArrayList<>();
|
||||
|
||||
data.forEach((name, cexp) -> {
|
||||
|
||||
if ((allowUnverified || cexp.isVerified()) && cexp.getLatestVersion() != null && cexp.getVersion(cexp.getLatestVersion()) != null) {
|
||||
cexp.setName(name);
|
||||
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(cexp.getName());
|
||||
|
||||
if (ex != null && ex.isRegistered()) {
|
||||
cexp.setHasExpansion(true);
|
||||
if (!ex.getVersion().equals(cexp.getLatestVersion())) {
|
||||
cexp.setShouldUpdate(true);
|
||||
}
|
||||
}
|
||||
|
||||
unsorted.add(cexp);
|
||||
}
|
||||
});
|
||||
|
||||
unsorted.sort(Comparator.comparing(CloudExpansion::getLastUpdate).reversed());
|
||||
|
||||
int count = 0;
|
||||
for (CloudExpansion e : unsorted) {
|
||||
remote.put(count++, e);
|
||||
}
|
||||
|
||||
plugin.getLogger().info(count + " placeholder expansions are available on the cloud.");
|
||||
|
||||
long updates = getToUpdateCount();
|
||||
|
||||
if (updates > 0) {
|
||||
plugin.getLogger().info(updates + " installed expansions have updates available.");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public boolean isDownloading(String expansion) {
|
||||
return downloading.contains(expansion);
|
||||
}
|
||||
|
||||
private void download(URL url, String name) throws IOException {
|
||||
|
||||
InputStream is = null;
|
||||
|
||||
FileOutputStream fos = null;
|
||||
|
||||
try {
|
||||
|
||||
URLConnection urlConn = url.openConnection();
|
||||
|
||||
is = urlConn.getInputStream();
|
||||
|
||||
fos = new FileOutputStream(
|
||||
expansionsDir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar");
|
||||
|
||||
byte[] buffer = new byte[is.available()];
|
||||
|
||||
int l;
|
||||
|
||||
while ((l = is.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, l);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void downloadExpansion(final String player, final CloudExpansion ex) {
|
||||
downloadExpansion(player, ex, ex.getLatestVersion());
|
||||
}
|
||||
|
||||
public void downloadExpansion(final String player, final CloudExpansion ex, final String version) {
|
||||
|
||||
if (downloading.contains(ex.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CloudExpansion.Version ver = ex.getVersions()
|
||||
.stream()
|
||||
.filter(v -> v.getVersion().equals(version))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (ver == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
downloading.add(ex.getName());
|
||||
|
||||
plugin.getLogger().info("Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " + player : "") + " from url: " + ver.getUrl());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
|
||||
try {
|
||||
|
||||
@@ -334,7 +286,8 @@ public class ExpansionCloudManager {
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
plugin.getLogger().warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl());
|
||||
plugin.getLogger()
|
||||
.warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl());
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
|
||||
@@ -367,5 +320,26 @@ public class ExpansionCloudManager {
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class URLReader {
|
||||
|
||||
static String read(String url) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
|
||||
|
||||
String inputLine;
|
||||
while ((inputLine = reader.readLine()) != null) {
|
||||
builder.append(inputLine);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
builder.setLength(0);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -28,30 +28,30 @@ import org.bukkit.plugin.Plugin;
|
||||
@Deprecated
|
||||
public abstract class EZPlaceholderHook extends PlaceholderHook {
|
||||
|
||||
private String identifier;
|
||||
|
||||
private String plugin;
|
||||
|
||||
public EZPlaceholderHook(Plugin plugin, String identifier) {
|
||||
Validate.notNull(plugin, "Plugin can not be null!");
|
||||
Validate.notNull(identifier, "Placeholder name can not be null!");
|
||||
this.identifier = identifier;
|
||||
this.plugin = plugin.getName();
|
||||
}
|
||||
|
||||
public boolean isHooked() {
|
||||
return PlaceholderAPI.getRegisteredPlaceholderPlugins().contains(identifier);
|
||||
}
|
||||
|
||||
public boolean hook() {
|
||||
return PlaceholderAPI.registerPlaceholderHook(identifier, this);
|
||||
}
|
||||
|
||||
public String getPlaceholderName() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return plugin;
|
||||
}
|
||||
private String identifier;
|
||||
|
||||
private String plugin;
|
||||
|
||||
public EZPlaceholderHook(Plugin plugin, String identifier) {
|
||||
Validate.notNull(plugin, "Plugin can not be null!");
|
||||
Validate.notNull(identifier, "Placeholder name can not be null!");
|
||||
this.identifier = identifier;
|
||||
this.plugin = plugin.getName();
|
||||
}
|
||||
|
||||
public boolean isHooked() {
|
||||
return PlaceholderAPI.getRegisteredPlaceholderPlugins().contains(identifier);
|
||||
}
|
||||
|
||||
public boolean hook() {
|
||||
return PlaceholderAPI.registerPlaceholderHook(identifier, this);
|
||||
}
|
||||
|
||||
public String getPlaceholderName() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
@@ -1,105 +1,93 @@
|
||||
package me.clip.placeholderapi.updatechecker;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* thanks maxim
|
||||
*/
|
||||
public class UpdateChecker implements Listener {
|
||||
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
|
||||
private final int resourceId = 6245;
|
||||
|
||||
private static String latestVersion = "";
|
||||
|
||||
private static boolean updateAvailable = false;
|
||||
private final int RESOURCE_ID = 6245;
|
||||
private PlaceholderAPIPlugin plugin;
|
||||
private String spigotVersion, pluginVersion;
|
||||
private boolean updateAvailable;
|
||||
|
||||
public UpdateChecker(PlaceholderAPIPlugin i) {
|
||||
plugin = i;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
if (checkForUpdate()) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
plugin.getLogger().info("An update for PlaceholderAPI (v" + getLatestVersion() + ") is available at:");
|
||||
plugin.getLogger().info("https://www.spigotmc.org/resources/placeholderapi." + resourceId + "/");
|
||||
register();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void register() {
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (e.getPlayer().hasPermission("placeholderapi.updatenotify")) {
|
||||
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getLatestVersion() + "&e)"));
|
||||
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bis available at &ehttps://www.spigotmc.org/resources/placeholderapi." + resourceId + "/"));
|
||||
}
|
||||
}
|
||||
public UpdateChecker(PlaceholderAPIPlugin i) {
|
||||
plugin = i;
|
||||
pluginVersion = i.getDescription().getVersion();
|
||||
}
|
||||
|
||||
private String getSpigotVersion() {
|
||||
try {
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=" + resourceId).openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
||||
if (version.length() <= 7) {
|
||||
return version;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
plugin.getLogger().info("Failed to check for a update on spigot.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean hasUpdateAvailable() {
|
||||
return updateAvailable;
|
||||
}
|
||||
|
||||
private boolean checkHigher(String currentVersion, String newVersion) {
|
||||
String current = toReadable(currentVersion);
|
||||
String newVers = toReadable(newVersion);
|
||||
return current.compareTo(newVers) < 0;
|
||||
}
|
||||
public String getSpigotVersion() {
|
||||
return spigotVersion;
|
||||
}
|
||||
|
||||
public boolean checkForUpdate() {
|
||||
String version = getSpigotVersion();
|
||||
if (version != null) {
|
||||
if (checkHigher(plugin.getDescription().getVersion(), version)) {
|
||||
latestVersion = version;
|
||||
updateAvailable = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void fetch() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(
|
||||
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
||||
} catch (Exception ex) {
|
||||
plugin.getLogger().info("Failed to check for updates on spigot.");
|
||||
return;
|
||||
}
|
||||
|
||||
public static boolean updateAvailable() {
|
||||
return updateAvailable;
|
||||
}
|
||||
if (spigotVersion == null || spigotVersion.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static String getLatestVersion() {
|
||||
return latestVersion;
|
||||
}
|
||||
updateAvailable = spigotIsNewer();
|
||||
|
||||
private String toReadable(String version) {
|
||||
String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", ""));
|
||||
version = "";
|
||||
for (String s : split) {
|
||||
version += String.format("%4s", s);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
if (!updateAvailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
plugin.getLogger()
|
||||
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
|
||||
plugin.getLogger()
|
||||
.info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/");
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private boolean spigotIsNewer() {
|
||||
if (spigotVersion == null || spigotVersion.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String plV = toReadable(pluginVersion);
|
||||
String spV = toReadable(spigotVersion);
|
||||
return plV.compareTo(spV) < 0;
|
||||
}
|
||||
|
||||
private String toReadable(String version) {
|
||||
if (version.contains("-DEV-")) {
|
||||
version = version.split("-DEV-")[0];
|
||||
}
|
||||
return version.replaceAll("\\.", "");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (e.getPlayer().hasPermission("placeholderapi.updatenotify")) {
|
||||
Msg.msg(e.getPlayer(),
|
||||
"&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getSpigotVersion()
|
||||
+ "&e)"
|
||||
, "&bis available at &ehttps://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID
|
||||
+ "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,8 +20,6 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.util;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.net.URL;
|
||||
@@ -30,64 +28,66 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
public static List<Class<?>> getClasses(String folder, Class<?> type) {
|
||||
List<Class<?>> list = new ArrayList<>();
|
||||
try {
|
||||
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
|
||||
if (!f.exists()) {
|
||||
if (!f.mkdir()) {
|
||||
PlaceholderAPIPlugin.getInstance().getLogger().severe("Failed to create " + folder + " folder!");
|
||||
}
|
||||
return list;
|
||||
}
|
||||
FilenameFilter fileNameFilter = (dir, name) -> {
|
||||
int i = name.lastIndexOf('.');
|
||||
return i > 0 && name.substring(i).equals(".jar");
|
||||
};
|
||||
File[] jars = f.listFiles(fileNameFilter);
|
||||
if (jars == null) {
|
||||
return list;
|
||||
}
|
||||
for (File file : jars) {
|
||||
list = gather(file.toURI().toURL(), list, type);
|
||||
}
|
||||
return list;
|
||||
} catch (Throwable t) {}
|
||||
return null;
|
||||
}
|
||||
public static List<Class<?>> getClasses(String folder, Class<?> type) {
|
||||
return getClasses(folder, null, type);
|
||||
}
|
||||
|
||||
private static List<Class<?>> gather(URL jar, List<Class<?>> list, Class<?> clazz) {
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
try {
|
||||
URLClassLoader cl = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader());
|
||||
JarInputStream jis = new JarInputStream(jar.openStream());
|
||||
while (true) {
|
||||
JarEntry j = jis.getNextJarEntry();
|
||||
if (j == null) {
|
||||
break;
|
||||
}
|
||||
String name = j.getName();
|
||||
if (name == null || name.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (name.endsWith(".class")) {
|
||||
name = name.replace("/", ".");
|
||||
String cname = name.substring(0, name.lastIndexOf(".class"));
|
||||
Class<?> c = cl.loadClass(cname);
|
||||
if (clazz.isAssignableFrom(c)) {
|
||||
list.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
cl.close();
|
||||
jis.close();
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
public static List<Class<?>> getClasses(String folder, String fileName, Class<?> type) {
|
||||
List<Class<?>> list = new ArrayList<>();
|
||||
try {
|
||||
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
|
||||
if (!f.exists()) {
|
||||
return list;
|
||||
}
|
||||
FilenameFilter fileNameFilter = (dir, name) -> {
|
||||
if (fileName != null) {
|
||||
return name.endsWith(".jar") && name.replace(".jar", "")
|
||||
.equalsIgnoreCase(fileName.replace(".jar", ""));
|
||||
}
|
||||
return name.endsWith(".jar");
|
||||
};
|
||||
File[] jars = f.listFiles(fileNameFilter);
|
||||
if (jars == null) {
|
||||
return list;
|
||||
}
|
||||
for (File file : jars) {
|
||||
list = gather(file.toURI().toURL(), list, type);
|
||||
}
|
||||
return list;
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<Class<?>> gather(URL jar, List<Class<?>> list, Class<?> clazz) {
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
try (URLClassLoader cl = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader()); JarInputStream jis = new JarInputStream(jar.openStream())) {
|
||||
while (true) {
|
||||
JarEntry j = jis.getNextJarEntry();
|
||||
if (j == null) {
|
||||
break;
|
||||
}
|
||||
String name = j.getName();
|
||||
if (name == null || name.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (name.endsWith(".class")) {
|
||||
name = name.replace("/", ".");
|
||||
String cname = name.substring(0, name.lastIndexOf(".class"));
|
||||
Class<?> c = cl.loadClass(cname);
|
||||
if (clazz.isAssignableFrom(c)) {
|
||||
list.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@@ -20,18 +20,22 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Msg {
|
||||
|
||||
public static void msg(CommandSender s, String... msg) {
|
||||
Arrays.stream(msg).forEach(text -> s.sendMessage(color(text)));
|
||||
}
|
||||
public static void msg(CommandSender s, String... msg) {
|
||||
Arrays.stream(msg).map(Msg::color).forEach(s::sendMessage);
|
||||
}
|
||||
|
||||
public static String color(String text) {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
public static void broadcast(String... msg) {
|
||||
Arrays.stream(msg).map(Msg::color).forEach(Bukkit::broadcastMessage);
|
||||
}
|
||||
|
||||
public static String color(String text) {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
}
|
||||
|
@@ -22,8 +22,8 @@ package me.clip.placeholderapi.util;
|
||||
|
||||
public enum TimeFormat {
|
||||
|
||||
DAYS,
|
||||
HOURS,
|
||||
MINUTES,
|
||||
SECONDS
|
||||
DAYS,
|
||||
HOURS,
|
||||
MINUTES,
|
||||
SECONDS
|
||||
}
|
||||
|
@@ -22,141 +22,141 @@ package me.clip.placeholderapi.util;
|
||||
|
||||
public class TimeUtil {
|
||||
|
||||
public static String getRemaining(int seconds, TimeFormat type) {
|
||||
|
||||
if (seconds < 60) {
|
||||
switch(type) {
|
||||
case DAYS:
|
||||
return "0";
|
||||
case HOURS:
|
||||
return "0";
|
||||
case MINUTES:
|
||||
return "0";
|
||||
case SECONDS:
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
|
||||
int minutes = seconds / 60;
|
||||
int s = 60 * minutes;
|
||||
int secondsLeft = seconds - s;
|
||||
if (minutes < 60) {
|
||||
switch(type) {
|
||||
case DAYS:
|
||||
return "0";
|
||||
case HOURS:
|
||||
return "0";
|
||||
case MINUTES:
|
||||
return String.valueOf(minutes);
|
||||
case SECONDS:
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
|
||||
if (minutes < 1440) {
|
||||
int hours = minutes / 60;
|
||||
int inMins = 60 * hours;
|
||||
int leftOver = minutes - inMins;
|
||||
switch(type) {
|
||||
case DAYS:
|
||||
return "0";
|
||||
case HOURS:
|
||||
return String.valueOf(hours);
|
||||
case MINUTES:
|
||||
return String.valueOf(leftOver);
|
||||
case SECONDS:
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
|
||||
int days = minutes / 1440;
|
||||
int inMins = 1440 * days;
|
||||
int leftOver = minutes - inMins;
|
||||
|
||||
if (leftOver < 60) {
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return String.valueOf(days);
|
||||
case HOURS:
|
||||
return String.valueOf(0);
|
||||
case MINUTES:
|
||||
return String.valueOf(leftOver);
|
||||
case SECONDS:
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
public static String getRemaining(int seconds, TimeFormat type) {
|
||||
|
||||
} else {
|
||||
int hours = leftOver / 60;
|
||||
int hoursInMins = 60 * hours;
|
||||
int minsLeft = leftOver - hoursInMins;
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return String.valueOf(days);
|
||||
case HOURS:
|
||||
return String.valueOf(hours);
|
||||
case MINUTES:
|
||||
return String.valueOf(minsLeft);
|
||||
case SECONDS:
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTime(int seconds) {
|
||||
|
||||
if (seconds < 60) {
|
||||
return seconds+"s";
|
||||
}
|
||||
|
||||
int minutes = seconds / 60;
|
||||
int s = 60 * minutes;
|
||||
int secondsLeft = seconds - s;
|
||||
if (minutes < 60) {
|
||||
if (secondsLeft > 0) {
|
||||
return String.valueOf(minutes+"m "+secondsLeft+"s");
|
||||
} else {
|
||||
return String.valueOf(minutes+"m");
|
||||
}
|
||||
}
|
||||
if (minutes < 1440) {
|
||||
String time;
|
||||
int hours = minutes / 60;
|
||||
time = hours+"h";
|
||||
int inMins = 60 * hours;
|
||||
int leftOver = minutes - inMins;
|
||||
if (leftOver >= 1) {
|
||||
time = time+" "+leftOver+"m";
|
||||
}
|
||||
if (secondsLeft > 0) {
|
||||
time = time+" "+secondsLeft+"s";
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
String time;
|
||||
int days = minutes / 1440;
|
||||
time = days+"d";
|
||||
int inMins = 1440 * days;
|
||||
int leftOver = minutes - inMins;
|
||||
if (leftOver >= 1) {
|
||||
if (leftOver < 60) {
|
||||
time = time+" "+leftOver+"m";
|
||||
} else {
|
||||
int hours = leftOver / 60;
|
||||
time = time+" "+hours+"h";
|
||||
int hoursInMins = 60 * hours;
|
||||
int minsLeft = leftOver - hoursInMins;
|
||||
time = time+" "+minsLeft+"m";
|
||||
}
|
||||
}
|
||||
if (secondsLeft > 0) {
|
||||
time = time+" "+secondsLeft+"s";
|
||||
}
|
||||
return time;
|
||||
}
|
||||
if (seconds < 60) {
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return "0";
|
||||
case HOURS:
|
||||
return "0";
|
||||
case MINUTES:
|
||||
return "0";
|
||||
case SECONDS:
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
|
||||
int minutes = seconds / 60;
|
||||
int s = 60 * minutes;
|
||||
int secondsLeft = seconds - s;
|
||||
if (minutes < 60) {
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return "0";
|
||||
case HOURS:
|
||||
return "0";
|
||||
case MINUTES:
|
||||
return String.valueOf(minutes);
|
||||
case SECONDS:
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
|
||||
if (minutes < 1440) {
|
||||
int hours = minutes / 60;
|
||||
int inMins = 60 * hours;
|
||||
int leftOver = minutes - inMins;
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return "0";
|
||||
case HOURS:
|
||||
return String.valueOf(hours);
|
||||
case MINUTES:
|
||||
return String.valueOf(leftOver);
|
||||
case SECONDS:
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
|
||||
int days = minutes / 1440;
|
||||
int inMins = 1440 * days;
|
||||
int leftOver = minutes - inMins;
|
||||
|
||||
if (leftOver < 60) {
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return String.valueOf(days);
|
||||
case HOURS:
|
||||
return String.valueOf(0);
|
||||
case MINUTES:
|
||||
return String.valueOf(leftOver);
|
||||
case SECONDS:
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
|
||||
} else {
|
||||
int hours = leftOver / 60;
|
||||
int hoursInMins = 60 * hours;
|
||||
int minsLeft = leftOver - hoursInMins;
|
||||
switch (type) {
|
||||
case DAYS:
|
||||
return String.valueOf(days);
|
||||
case HOURS:
|
||||
return String.valueOf(hours);
|
||||
case MINUTES:
|
||||
return String.valueOf(minsLeft);
|
||||
case SECONDS:
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTime(int seconds) {
|
||||
|
||||
if (seconds < 60) {
|
||||
return seconds + "s";
|
||||
}
|
||||
|
||||
int minutes = seconds / 60;
|
||||
int s = 60 * minutes;
|
||||
int secondsLeft = seconds - s;
|
||||
if (minutes < 60) {
|
||||
if (secondsLeft > 0) {
|
||||
return String.valueOf(minutes + "m " + secondsLeft + "s");
|
||||
} else {
|
||||
return String.valueOf(minutes + "m");
|
||||
}
|
||||
}
|
||||
if (minutes < 1440) {
|
||||
String time;
|
||||
int hours = minutes / 60;
|
||||
time = hours + "h";
|
||||
int inMins = 60 * hours;
|
||||
int leftOver = minutes - inMins;
|
||||
if (leftOver >= 1) {
|
||||
time = time + " " + leftOver + "m";
|
||||
}
|
||||
if (secondsLeft > 0) {
|
||||
time = time + " " + secondsLeft + "s";
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
String time;
|
||||
int days = minutes / 1440;
|
||||
time = days + "d";
|
||||
int inMins = 1440 * days;
|
||||
int leftOver = minutes - inMins;
|
||||
if (leftOver >= 1) {
|
||||
if (leftOver < 60) {
|
||||
time = time + " " + leftOver + "m";
|
||||
} else {
|
||||
int hours = leftOver / 60;
|
||||
time = time + " " + hours + "h";
|
||||
int hoursInMins = 60 * hours;
|
||||
int minsLeft = leftOver - hoursInMins;
|
||||
time = time + " " + minsLeft + "m";
|
||||
}
|
||||
}
|
||||
if (secondsLeft > 0) {
|
||||
time = time + " " + secondsLeft + "s";
|
||||
}
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@
|
||||
# Issues: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
|
||||
# Expansions: https://api.extendedclip.com/all/
|
||||
# Wiki: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki
|
||||
# Discord: https://discordapp.com/invite/7sndK3q
|
||||
# Discord: https://helpch.at/discord
|
||||
# No placeholders are provided with this plugin by default.
|
||||
# Download placeholders: /papi ecloud
|
||||
check_updates: true
|
||||
|
@@ -3,6 +3,7 @@ main: me.clip.placeholderapi.PlaceholderAPIPlugin
|
||||
version: ${project.version}
|
||||
author: [extended_clip]
|
||||
description: ${project.description}
|
||||
api-version: 1.13
|
||||
permissions:
|
||||
placeholderapi.*:
|
||||
description: ability to use all commands
|
||||
@@ -15,9 +16,7 @@ permissions:
|
||||
placeholderapi.reload: true
|
||||
placeholderapi.ecloud: true
|
||||
placeholderapi.parse: true
|
||||
placeholderapi.injector.chat.bypass: true
|
||||
placeholderapi.injector.signs.bypass: true
|
||||
placeholderapi.injector.anvil.bypass: true
|
||||
placeholderapi.register: true
|
||||
placeholderapi.updatenotify: true
|
||||
placeholderapi.list:
|
||||
description: ability to use the list command
|
||||
@@ -28,6 +27,9 @@ permissions:
|
||||
placeholderapi.parse:
|
||||
description: ability to use parse command
|
||||
default: op
|
||||
placeholderapi.register:
|
||||
description: ability to register or unregister placeholder expansions
|
||||
default: op
|
||||
placeholderapi.ecloud:
|
||||
description: allows the usage of ecloud commands
|
||||
default: op
|
||||
|
Reference in New Issue
Block a user