mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-12-13 19:08:16 +01:00
Compare commits
7 Commits
feature/co
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3602e5aea | ||
|
|
b8d4dcd570 | ||
|
|
8a249a9a2e | ||
|
|
915166f78b | ||
|
|
533b892cf4 | ||
|
|
6676e2fa21 | ||
|
|
99e5752352 |
4
.github/CODEOWNERS
vendored
4
.github/CODEOWNERS
vendored
@@ -1,9 +1,9 @@
|
||||
#
|
||||
# Assigns extendedclip and PiggyPiglet for any PR unless a check below matches.
|
||||
#
|
||||
* @PiggyPiglet @darbyjack
|
||||
* @extendedclip @PiggyPiglet
|
||||
|
||||
#
|
||||
# Assigns Andre601 to any PR that targets the wiki folder.
|
||||
#
|
||||
*.md @Andre601
|
||||
/wiki/ @Andre601
|
||||
|
||||
31
.github/CONTRIBUTING.md
vendored
31
.github/CONTRIBUTING.md
vendored
@@ -1,9 +1,8 @@
|
||||
[issue]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new
|
||||
[discord]: https://helpch.at/discord
|
||||
[code of conduct]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/CODE_OF_CONDUCT.md
|
||||
[wiki]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/wiki
|
||||
[master]: https://github.com/PlaceholderAPI/PlaceholderAPI/tree/master
|
||||
[docs-wiki]: https://github.com/PlaceholderAPI/PlaceholderAPI/tree/docs/wiki
|
||||
[wiki]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/docs/wiki/wiki
|
||||
[dev]: https://github.com/PlaceholderAPI/PlaceholderAPI/tree/development
|
||||
[style]: https://github.com/PlaceholderAPI/PlaceholderAPI/tree/master/config/style
|
||||
|
||||
# Contributing Guidelines
|
||||
@@ -38,29 +37,15 @@ PlaceholderAPI provides a feature to have expansions (separate jar files) for pl
|
||||
In those cases should you report the issue to the issue tracker of the expansion or plugin.
|
||||
|
||||
## Pull requests
|
||||
As an open source project are we welcoming all contributions to improve PlaceholderAPI, being it changes to its code, or contributions to its documentation such as the [Wiki] or the Javadocs.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> When contributing, make sure to both base of and target the mentioned branch. Pull requests targeting the wrong branch may get closed without a warning.
|
||||
As an open source project are we welcoming all contributions to improve PlaceholderAPI, being it changes to its code like bug fixes or new features, or contributions to its documentation such as the [Wiki] or the Javadoc.
|
||||
|
||||
### Code contributions
|
||||
> **Source and Target Branch:** [`master`][master]
|
||||
Any contributions to PlaceholderAPI's code should be done towards the [`development`][dev] branch. Targeting the `master` branch in your Pull request may get it closed without warning.
|
||||
Additionally should you follow the project's codestyle which you can find in the [`config/style`][style] directory.
|
||||
|
||||
When contributing towards the code of PlaceholderAPI, be it new features or just bug fixes, your changes should follow the general code styling used in the project.
|
||||
You can find the necessary files in the [`config/style`][style] directory of this repository.
|
||||
|
||||
### Javadocs contributions
|
||||
> **Source and Target Branch:** [`master`][master]*
|
||||
|
||||
Javadocs changes should usually be combined with [code contributions](#code-contributions) when possible, but if not, make sure the changes are significant enough to warrant a new build on our CI server.
|
||||
|
||||
\*This branch may change in the future.
|
||||
|
||||
### Wiki contributions
|
||||
> **Source and Target Branch:** [`wiki`][docs-wiki]
|
||||
|
||||
The Wiki of PlaceholderAPI is located on its own dedicated branch, hosting all the assets and files that get used to create it through the usage of GitHub Actions and GitHub Pages.
|
||||
We welcome contributions that update outdated information, add new expansions/plugins supporting PlaceholderAPI or even correct spelling mistakes and typos.
|
||||
### Wiki/Javadoc contributions
|
||||
If your pull request only targets the [wiki] or only changes the javadoc comments of PlaceholderAPI (And not its actual code), it should be to `docs/wiki` branch.
|
||||
The develop branch should only be targeted when you also change some of PlaceholderAPI's code.
|
||||
|
||||
## Code of Conduct
|
||||
We have a [Code of Conduct] to maintain a welcoming atmosphere in this project.
|
||||
|
||||
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -24,8 +24,6 @@ body:
|
||||
required: true
|
||||
- label: The issue isn't already fixed in a Spigot Release or Development Build.
|
||||
required: true
|
||||
- label: The [Common Issues](https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/Common-Issues) page doesn't mention this issue.
|
||||
required: true
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: "Type"
|
||||
|
||||
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -25,4 +25,4 @@ Closes N/A <!-- If your PR is based on an issue, change "N/A" the the issue ID (
|
||||
|
||||
|
||||
<!-- DO NOT ALTER ANYTHING BELOW THIS LINE! -->
|
||||
[Wiki]: https://wiki.placeholderapi.com
|
||||
[Wiki]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki
|
||||
|
||||
46
.github/label-commenter-config.yml
vendored
46
.github/label-commenter-config.yml
vendored
@@ -1,8 +1,7 @@
|
||||
comment:
|
||||
footer: "\
|
||||
----\n\n
|
||||
> [!NOTE]\n
|
||||
> *This is an automated response created by a **GitHub Action***<br>
|
||||
> *This is an automated response created by a **GitHub Action***\n
|
||||
> *Mentioning the bot won't have any effect!*
|
||||
"
|
||||
|
||||
@@ -36,12 +35,11 @@ labels:
|
||||
Your issue unfortunately lacks certain information that we require in order to help you with your issue.
|
||||
Please make sure you provide the following information:
|
||||
|
||||
- Currently used Versions of your server (`/version`) and PlaceholderAPI (`/version PlaceholderAPI`)
|
||||
- Currently installed Expansions (`/papi list`)
|
||||
- Currently installed Plugins (`/pl`)
|
||||
- Any additional information requested by users in this issue.
|
||||
- Currently used Versions of your server and PlaceholderAPI
|
||||
- Currently installed Expansions
|
||||
- Currently installed Plugins
|
||||
|
||||
The easiest way to provide those information is through the `/papi dump` command which posts the required information to https://paste.helpch.at and gives a URL to share.
|
||||
The easiest way to provide those information is through the `/papi dumb` command which posts the required information to https://paste.helpch.at and gives a URL to share.
|
||||
unlabeled:
|
||||
issue:
|
||||
body: |-
|
||||
@@ -52,18 +50,18 @@ labels:
|
||||
issue:
|
||||
body: |-
|
||||
Your issue has beeen marked as invalid.
|
||||
This means that it either doesn't follow any provided template, or isn't related to PlaceholderAPI.
|
||||
This means that it either doesn't follow any provided template, or isn't related to PlaceholderAPI in any way.
|
||||
|
||||
Please make sure to use one of the issue templates and provide the requested information.
|
||||
Currently available Templates are:
|
||||
|
||||
- [Bug Report](https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?labels=Type%3A+Issue+%28Unconfirmed%29&template=bug_report.yml)
|
||||
- [Feature Request](https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?labels=Type%3A+Enhancement&template=feature_request.yml)
|
||||
- [Bug Report](https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?template=bug_report.md)
|
||||
- [Feature Request](https://github.com/PlaceholderAPI/PlaceholderAPI/issues/new?template=feature_request.md)
|
||||
|
||||
If you want changes to be made towards the Wiki, would we encourage you to [Make a Pull request](https://github.com/PlaceholderAPI/PlaceholderAPI/pulls).
|
||||
You can find more information about this process on the [Wiki's Readme](https://github.com/PlaceholderAPI/PlaceholderAPI/blob/wiki/README.md).
|
||||
You can find more information about this process on the [Wiki's Readme](https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/wiki/README.md).
|
||||
|
||||
It is recommended to [join our Discord Server](https://helpch.at/discord) as you often receive a faster response compared to the issue tracker here.
|
||||
It is recommended to [join our Discord Server](https://helpch.at/discord) as you often receive faster response compared to the issue tracker here.
|
||||
Questions about PlaceholderAPI should be asked in our [Discussions](https://github.com/PlaceholderAPI/PlaceholderAPI/discussions).
|
||||
action: close
|
||||
pr:
|
||||
@@ -73,20 +71,11 @@ labels:
|
||||
|
||||
Here is a small summary of what you should know:
|
||||
|
||||
- Pull requests for PlaceholderAPI should target the `master` branch.
|
||||
- Pull requests for the Wiki should target the `wiki` branch.
|
||||
- Pull requests for PlaceholderAPI should target the `development` branch.
|
||||
- Pull requests for the Wiki should target the `docs/wiki` branch.
|
||||
|
||||
Don't hesitate to ask us any questions.
|
||||
action: close
|
||||
- name: 'Type: Invalid (Wiki)'
|
||||
labeled:
|
||||
pr:
|
||||
body: |-
|
||||
Your Wiki Pull request has been marked as **invalid**.
|
||||
|
||||
Pull requests targeting the Wiki need to target the `wiki` branch.
|
||||
More information can be found on the [Wiki README](https://github.com/PlaceholderAPI/PlaceholderAPI/blob/wiki/README.md).
|
||||
action: close
|
||||
- name: 'Target: Wiki'
|
||||
labeled:
|
||||
issue:
|
||||
@@ -94,11 +83,12 @@ labels:
|
||||
Hello @{{ issue.user.login }},
|
||||
|
||||
Thank you for reaching out to us about the wiki.
|
||||
We would like to inform you, that you are able to directly commit your changes to the wiki through a Pull request.
|
||||
We would like to inform you, that you are now able to directly commit your changes to the wiki through a Pull request.
|
||||
When doing so, make sure you follow these steps:
|
||||
|
||||
- The Pull request is based on AND targets the [`wiki`](https://github.com/PlaceholderAPI/PlaceholderAPI/tree/wiki) branch of the Repository.
|
||||
- You followed the general Styling Guidelines mentioned in the wiki's [README](https://github.com/PlaceholderAPI/PlaceholderAPI/blob/wiki/README.md) file.
|
||||
- The Pull request is based on AND targets the [`docs/wiki`](https://github.com/PlaceholderAPI/PlaceholderAPI/tree/docs/wiki) branch of the Repository.
|
||||
- You only made changes to the files inside the [`wiki`](https://github.com/PlaceholderAPI/PlaceholderAPI/tree/docs/wiki/wiki) folder.
|
||||
- You followed the general Styling Guidelines mentioned in the wiki's [README](https://github.com/PlaceholderAPI/PlaceholderAPI/blob/docs/wiki/wiki/README.md) file.
|
||||
|
||||
If you have any questions about submitting a PR for the wiki or have any other questions don't hesitate to ask us about it.
|
||||
- name: 'Type: Not a bug'
|
||||
@@ -122,7 +112,7 @@ labels:
|
||||
The issue has been marked as **inactive** which means it didn't recieve any responses from the Author ({{ issue.user.login }}) for a long period of time.
|
||||
To keep the issue-tracker clean and up to date do we close issues that haven't received any responses for a long time.
|
||||
|
||||
If you're the Author of this issue and the reported problem is still present, make sure to respond with additional info to this issue, so that we can reopen it.
|
||||
If you're the Author of this issue and the reported problem is still present, make sure to respond with additional info to this issue.
|
||||
**Do not create a new issue for the same problem!**
|
||||
action: close
|
||||
unlabeled:
|
||||
@@ -136,7 +126,7 @@ labels:
|
||||
Hello @{{ issue.user.login }},
|
||||
|
||||
Thank you for reaching out to us for getting Support with PlaceholderAPI.
|
||||
We would like to inform you, that we have [Discussions](https://github.com/PlaceholderAPI/PlaceholderAPI/discussions) that you can use for asking questions.
|
||||
We would like to inform you, that we now have [Discussions](https://github.com/PlaceholderAPI/PlaceholderAPI/discussions) that you can use for asking questions.
|
||||
Just head over there and click the "New discussion" button to create a new post.
|
||||
|
||||
Remember to first read the [READ ME](https://github.com/PlaceholderAPI/PlaceholderAPI/discussions/507) post to not face any issues.
|
||||
|
||||
36
.github/workflows/wiki.yml
vendored
Normal file
36
.github/workflows/wiki.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# This is a GitHub Action that allows us to auto-update the wiki
|
||||
# when a Pull request changes specific files in a folder.
|
||||
#
|
||||
name: Update Wiki
|
||||
|
||||
on:
|
||||
push:
|
||||
#
|
||||
# Only trigger when the push changes any files in the wiki-folder.
|
||||
#
|
||||
paths:
|
||||
- 'wiki/**'
|
||||
branches:
|
||||
- 'docs/wiki'
|
||||
#
|
||||
# Releases cause this action to also fire.
|
||||
# Using this prevents this problem.
|
||||
#
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
update:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 'Checkout Code'
|
||||
uses: actions/Checkout@v2
|
||||
- name: 'Update Wiki'
|
||||
uses: Andrew-Chen-Wang/github-wiki-action@v2
|
||||
env:
|
||||
WIKI_DIR: wiki/
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GH_MAIL: 'actions@github.com'
|
||||
GH_NAME: 'github-actions[bot]'
|
||||
EXCLUDED_FILES: 'README.md'
|
||||
16
README.md
16
README.md
@@ -7,9 +7,6 @@
|
||||
|
||||
[discord]: https://helpch.at/discord
|
||||
[spigot]: https://www.spigotmc.org/resources/6245/
|
||||
[hangar]: https://hangar.papermc.io/HelpChat/PlaceholderAPI
|
||||
[bbb]: https://builtbybit.com/resources/placeholderapi.24306
|
||||
[modrinth]: https://modrinth.com/plugin/placeholderapi
|
||||
[Expansions cloud]: https://api.extendedclip.com/home
|
||||
[placeholder list]: https://helpch.at/placeholders
|
||||
[statistics]: https://bstats.org/plugin/bukkit/PlaceholderAPI
|
||||
@@ -17,11 +14,11 @@
|
||||
[ci]: http://ci.extendedclip.com/job/PlaceholderAPI/
|
||||
[ciImg]: http://ci.extendedclip.com/buildStatus/icon?job=PlaceholderAPI
|
||||
|
||||
[APIversionImg]: https://repo.extendedclip.com/api/badge/latest/releases/me/clip/placeholderapi?name=API%20Version
|
||||
[logo]: https://wiki.placeholderapi.com/assets/img/papi-logo.png
|
||||
[APIversionImg]: https://img.shields.io/nexus/placeholderapi/me.clip/placeholderapi?server=https%3A%2F%2Frepo.extendedclip.com&label=API%20Version
|
||||
[logo]: https://raw.githubusercontent.com/PlaceholderAPI/PlaceholderAPI/master/wiki/img/papi-logo.png
|
||||
|
||||
[contributing]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/.github/CONTRIBUTING.md
|
||||
[placeholderexpansion]: https://wiki.placeholderapi.com/developers/creating-a-placeholderexpansion/
|
||||
[placeholderexpansion]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/PlaceholderExpansion
|
||||
<!-- The stuff above isn't visible in the readme -->
|
||||
|
||||
[![logo]][spigot]
|
||||
@@ -31,9 +28,9 @@
|
||||
# Information
|
||||
[PlaceholderAPI][spigot] is a plugin for Spigot servers that allows server owners to display information from various plugins with a uniform format.
|
||||
|
||||
Support for specific plugins are provided either by the plugin itself or through expansions. The expansions may be downloaded in-game through the PAPI Expansion Cloud. There are currently over 240+ expansions that support a wide variety of plugins, such as Essentials, Factions, LuckPerms, and Vault.
|
||||
Support for specific plugins are provided either by the plugin itself or through expansions. The expansions may be downloaded in-game through the PAPI Expansion Cloud. There are currently over 150+ expansions that support a wide variety of plugins, such as Essentials, Factions, LuckPerms, and Vault.
|
||||
|
||||
PlaceholderAPI has been downloaded over 1,700,000 times on Spigot and has been used concurrently on over 45,000 servers, which makes it a must-have for a server of any type or scale.
|
||||
PlaceholderAPI has been downloaded over 750,000 times and has been used concurrently on over 35,000 servers, which makes it a must-have for a server of any type or scale.
|
||||
|
||||
## Contribute
|
||||
If you would like to contribute towards PlaceholderAPI should you take a look at our [Contributing file][contributing] for the ins and outs on how you can do that and what you need to keep in mind.
|
||||
@@ -50,7 +47,4 @@ If you would like to create your own Placeholder Expansion for PlaceholderAPI, t
|
||||
- [Expansions Cloud]
|
||||
- [Placeholder List]
|
||||
- [Spigot Page][spigot]
|
||||
- [Hangar Page][hangar]
|
||||
- [BuiltByBit Page][bbb]
|
||||
- [Modrinth Page][modrinth]
|
||||
- [Plugin Statistics][statistics]
|
||||
|
||||
132
build.gradle
Normal file
132
build.gradle
Normal file
@@ -0,0 +1,132 @@
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
plugins {
|
||||
id "java"
|
||||
id "maven-publish"
|
||||
id "org.cadixdev.licenser" version "0.6.0"
|
||||
id "com.github.johnrengelman.shadow" version "7.0.0"
|
||||
}
|
||||
|
||||
group "me.clip"
|
||||
version "2.10.10-DEV-${System.getProperty("BUILD_NUMBER")}"
|
||||
|
||||
description "An awesome placeholder provider!"
|
||||
|
||||
repositories {
|
||||
maven({ url = "https://oss.sonatype.org/content/repositories/snapshots/" })
|
||||
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
|
||||
maven({ url = "https://repo.codemc.org/repository/maven-public/" })
|
||||
maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" })
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.bstats:bstats-bukkit:2.2.1"
|
||||
|
||||
implementation "net.kyori:adventure-platform-bukkit:4.0.0"
|
||||
|
||||
compileOnly "org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT"
|
||||
compileOnly "org.jetbrains:annotations:22.0.0"
|
||||
|
||||
testImplementation "org.openjdk.jmh:jmh-core:1.32"
|
||||
testImplementation "org.openjdk.jmh:jmh-generator-annprocess:1.32"
|
||||
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.8.1"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.1"
|
||||
}
|
||||
|
||||
processResources {
|
||||
filter ReplaceTokens, tokens: [name: rootProject.name, version: project.version.toString(), description: project.description]
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
tasks.withType(Javadoc) {
|
||||
failOnError false
|
||||
options.addStringOption('Xdoclint:none', '-quiet')
|
||||
options.addStringOption('encoding', 'UTF-8')
|
||||
options.addStringOption('charSet', 'UTF-8')
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveClassifier.set("")
|
||||
|
||||
relocate "org.bstats", "me.clip.placeholderapi.metrics"
|
||||
relocate "net.kyori", "me.clip.placeholderapi.libs.kyori"
|
||||
}
|
||||
|
||||
license {
|
||||
include '**/*.java'
|
||||
|
||||
matching('**/*.java') {
|
||||
header = file('config/headers/main.txt')
|
||||
}
|
||||
|
||||
ext {
|
||||
year = 2021
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
configurations {
|
||||
testImplementation {
|
||||
extendsFrom(compileOnly)
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
if (version.contains("-DEV")) {
|
||||
url = uri("https://repo.extendedclip.com/content/repositories/dev/")
|
||||
} else {
|
||||
url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
||||
}
|
||||
|
||||
credentials {
|
||||
username = System.getenv("JENKINS_USER")
|
||||
password = System.getenv("JENKINS_PASS")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifactId = "placeholderapi"
|
||||
|
||||
from components.java
|
||||
|
||||
pom.withXml {
|
||||
|
||||
// some are having issues with bstats so we might need to add that to the pom as well
|
||||
|
||||
asNode().appendNode("packaging", "jar")
|
||||
asNode().remove(asNode().get("dependencies"))
|
||||
|
||||
def dependenciesNode = asNode().appendNode("dependencies")
|
||||
// jetbrains annotations
|
||||
def jetbrainsAnnotations = dependenciesNode.appendNode("dependency")
|
||||
jetbrainsAnnotations.appendNode("groupId", "org.jetbrains")
|
||||
jetbrainsAnnotations.appendNode("artifactId", "annotations")
|
||||
jetbrainsAnnotations.appendNode("version", "19.0.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publish.dependsOn clean, test, jar
|
||||
141
build.gradle.kts
141
build.gradle.kts
@@ -1,141 +0,0 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
id("com.github.hierynomus.license") version "0.16.1"
|
||||
id("io.github.goooler.shadow") version "8.1.7"
|
||||
}
|
||||
|
||||
group = "me.clip"
|
||||
version = "2.11.7-DEV-${System.getProperty("BUILD_NUMBER")}"
|
||||
|
||||
description = "An awesome placeholder provider!"
|
||||
|
||||
repositories {
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
|
||||
maven("https://repo.codemc.org/repository/maven-public/")
|
||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.bstats:bstats-bukkit:3.0.1")
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.4.1")
|
||||
|
||||
//compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT")
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||
compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT")
|
||||
compileOnlyApi("org.jetbrains:annotations:23.0.0")
|
||||
|
||||
testImplementation("org.openjdk.jmh:jmh-core:1.32")
|
||||
testImplementation("org.openjdk.jmh:jmh-generator-annprocess:1.32")
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.8.2")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
|
||||
}
|
||||
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
|
||||
disableAutoTargetJvm()
|
||||
}
|
||||
|
||||
license {
|
||||
header = rootProject.file("config/headers/main.txt")
|
||||
|
||||
include("**/*.java")
|
||||
mapping("java", "JAVADOC_STYLE")
|
||||
|
||||
encoding = "UTF-8"
|
||||
|
||||
ext {
|
||||
set("year", 2024)
|
||||
}
|
||||
}
|
||||
|
||||
val javaComponent: SoftwareComponent = components["java"]
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
eachFile { expand("version" to project.version) }
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(named("shadowJar"))
|
||||
}
|
||||
|
||||
withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
options.release = 8
|
||||
}
|
||||
|
||||
withType<Javadoc> {
|
||||
isFailOnError = false
|
||||
|
||||
with(options as StandardJavadocDocletOptions) {
|
||||
addStringOption("Xdoclint:none", "-quiet")
|
||||
addStringOption("encoding", "UTF-8")
|
||||
addStringOption("charSet", "UTF-8")
|
||||
}
|
||||
}
|
||||
|
||||
withType<ShadowJar> {
|
||||
archiveClassifier.set("")
|
||||
|
||||
relocate("org.bstats", "me.clip.placeholderapi.metrics")
|
||||
// relocate("net.kyori", "me.clip.placeholderapi.libs.kyori") {
|
||||
// exclude("me/clip/placeholderapi/PAPIComponents.java")
|
||||
// exclude("me/clip/placeholderapi/commands/TestCommand.java")
|
||||
// }
|
||||
|
||||
destinationDirectory = file("server/1.21/plugins/")
|
||||
|
||||
exclude("META-INF/versions/**")
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
artifactId = "placeholderapi"
|
||||
from(javaComponent)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
if ("-DEV" in version.toString()) {
|
||||
url = uri("https://repo.extendedclip.com/snapshots")
|
||||
} else {
|
||||
url = uri("https://repo.extendedclip.com/releases")
|
||||
}
|
||||
|
||||
credentials {
|
||||
username = System.getenv("JENKINS_USER")
|
||||
password = System.getenv("JENKINS_PASS")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publish.get().setDependsOn(listOf(build.get()))
|
||||
}
|
||||
|
||||
configurations {
|
||||
testImplementation {
|
||||
extendsFrom(compileOnly.get())
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2018-2024 Peter Blood
|
||||
Copyright (c) 2018-2021 Peter Blood
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
networkTimeout=10000
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
269
gradlew
vendored
269
gradlew
vendored
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -17,101 +17,67 @@
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
@@ -121,9 +87,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
@@ -132,7 +98,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
@@ -140,105 +106,80 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
15
gradlew.bat
vendored
15
gradlew.bat
vendored
@@ -14,7 +14,7 @@
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@@ -25,8 +25,7 @@
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@@ -41,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@@ -76,15 +75,13 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@@ -0,0 +1 @@
|
||||
rootProject.name = 'PlaceholderAPI'
|
||||
@@ -1 +0,0 @@
|
||||
rootProject.name = "PlaceholderAPI"
|
||||
@@ -1,121 +0,0 @@
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Relational;
|
||||
import me.clip.placeholderapi.replacer.ExactReplacer;
|
||||
import me.clip.placeholderapi.replacer.Replacer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.units.qual.N;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class PAPIComponents {
|
||||
private static final Replacer EXACT_REPLACER = new ExactReplacer();
|
||||
|
||||
@NotNull
|
||||
public static Component setPlaceholders(final OfflinePlayer player, @NotNull final Component component) {
|
||||
// TODO: explore a custom TextReplacementRenderer which doesn't use regex for performance benefits i.e. merge CharsReplacer with kyori TextReplacementRenderer
|
||||
return component.replaceText(config -> config.match(PlaceholderAPI.PLACEHOLDER_PATTERN).replacement((result, builder) ->
|
||||
builder.content(EXACT_REPLACER.apply(result.group(), player, PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion))));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Component> setPlaceholders(final OfflinePlayer player, @NotNull final List<Component> components) {
|
||||
return components.stream().map(component -> setPlaceholders(player, component)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Component setPlaceholders(final Player player, @NotNull final Component component) {
|
||||
return setPlaceholders((OfflinePlayer) player, component);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Component> setPlaceholders(final Player player, @NotNull final List<Component> components) {
|
||||
return setPlaceholders((OfflinePlayer) player, components);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Component setBracketPlaceholders(final OfflinePlayer player, @NotNull final Component component) {
|
||||
return component.replaceText(config -> config.match(PlaceholderAPI.BRACKET_PLACEHOLDER_PATTERN).replacement((result, builder) ->
|
||||
builder.content(EXACT_REPLACER.apply(result.group(), player, PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion))));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Component> setBracketPlaceholders(final OfflinePlayer player, @NotNull final List<Component> components) {
|
||||
return components.stream().map(component -> setBracketPlaceholders(player, component)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Component setBracketPlaceholders(final Player player, @NotNull final Component component) {
|
||||
return setBracketPlaceholders((OfflinePlayer) player, component);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Component> setBracketPlaceholders(final Player player, @NotNull final List<Component> components) {
|
||||
return setBracketPlaceholders((OfflinePlayer) player, components);
|
||||
}
|
||||
|
||||
// public static Component setRelationalPlaceholders(Player one, Player two, Component component) {
|
||||
// return component.replaceText(config -> config.match(PlaceholderAPI.RELATIONAL_PLACEHOLDER_PATTERN).replacement((result, builder) -> {
|
||||
//
|
||||
// final String format = result.group(2);
|
||||
// final int index = format.indexOf("_");
|
||||
//
|
||||
// if (index <= 0 || index >= format.length()) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// String identifier = format.substring(0, index).toLowerCase(Locale.ROOT);
|
||||
// String params = format.substring(index + 1);
|
||||
// final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance()
|
||||
// .getLocalExpansionManager().getExpansion(identifier);
|
||||
//
|
||||
// if (!(expansion instanceof Relational)) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// final String value = ((Relational) expansion).onPlaceholderRequest(one, two, params);
|
||||
//
|
||||
// if (value != null) {
|
||||
// text = text.replaceAll(Pattern.quote(matcher.group()), Matcher.quoteReplacement(value));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }));
|
||||
//
|
||||
// final Matcher matcher = PlaceholderAPI.RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
|
||||
//
|
||||
// while (matcher.find()) {
|
||||
// final String format = matcher.group(2);
|
||||
// final int index = format.indexOf("_");
|
||||
//
|
||||
// if (index <= 0 || index >= format.length()) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// String identifier = format.substring(0, index).toLowerCase(Locale.ROOT);
|
||||
// String params = format.substring(index + 1);
|
||||
// final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance()
|
||||
// .getLocalExpansionManager().getExpansion(identifier);
|
||||
//
|
||||
// if (!(expansion instanceof Relational)) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// final String value = ((Relational) expansion).onPlaceholderRequest(one, two, params);
|
||||
//
|
||||
// if (value != null) {
|
||||
// text = text.replaceAll(Pattern.quote(matcher.group()), Matcher.quoteReplacement(value));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return text;
|
||||
// }
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,21 +21,17 @@
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommandRouter;
|
||||
import me.clip.placeholderapi.commands.TestCommand;
|
||||
import me.clip.placeholderapi.configuration.PlaceholderAPIConfig;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Version;
|
||||
import me.clip.placeholderapi.expansion.manager.CloudExpansionManager;
|
||||
import me.clip.placeholderapi.expansion.manager.LocalExpansionManager;
|
||||
import me.clip.placeholderapi.listeners.ServerLoadEventListener;
|
||||
import me.clip.placeholderapi.scheduler.UniversalScheduler;
|
||||
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
|
||||
import me.clip.placeholderapi.updatechecker.UpdateChecker;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
@@ -54,229 +50,208 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public final class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
|
||||
@NotNull
|
||||
private static final Version VERSION;
|
||||
private static PlaceholderAPIPlugin instance;
|
||||
@NotNull
|
||||
private static final Version VERSION;
|
||||
private static PlaceholderAPIPlugin instance;
|
||||
|
||||
static {
|
||||
String version = Bukkit.getServer().getBukkitVersion().split("-")[0];
|
||||
String suffix;
|
||||
if (version.chars()
|
||||
.filter(c -> c == '.')
|
||||
.count() == 1) {
|
||||
suffix = "R1";
|
||||
version = 'v' + version.replace('.', '_') + '_' + suffix;
|
||||
} else {
|
||||
int minor = Integer.parseInt(version.split("\\.")[2].charAt(0) + "");
|
||||
version = 'v' + version.replace('.', '_').replace("_" + minor, "") + '_' + "R" + (minor - 1);
|
||||
}
|
||||
static {
|
||||
final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
boolean isSpigot;
|
||||
try {
|
||||
Class.forName("org.spigotmc.SpigotConfig");
|
||||
isSpigot = true;
|
||||
} catch (final ExceptionInInitializerError | ClassNotFoundException ignored) {
|
||||
isSpigot = false;
|
||||
}
|
||||
|
||||
VERSION = new Version(version, isSpigot);
|
||||
boolean isSpigot;
|
||||
try {
|
||||
Class.forName("org.spigotmc.SpigotConfig");
|
||||
isSpigot = true;
|
||||
} catch (final ExceptionInInitializerError | ClassNotFoundException ignored) {
|
||||
isSpigot = false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final PlaceholderAPIConfig config = new PlaceholderAPIConfig(this);
|
||||
VERSION = new Version(version, isSpigot);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
|
||||
@NotNull
|
||||
private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
|
||||
@NotNull
|
||||
private final TaskScheduler scheduler = UniversalScheduler.getScheduler(this);
|
||||
@NotNull
|
||||
private final PlaceholderAPIConfig config = new PlaceholderAPIConfig(this);
|
||||
|
||||
private BukkitAudiences adventure;
|
||||
@NotNull
|
||||
private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
|
||||
@NotNull
|
||||
private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
|
||||
|
||||
private BukkitAudiences adventure;
|
||||
|
||||
/**
|
||||
* Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
|
||||
* class, this is the main class that extends JavaPlugin. For most API methods, use static methods
|
||||
* available from the class: {@link PlaceholderAPI}
|
||||
*
|
||||
* @return PlaceholderAPIPlugin instance
|
||||
*/
|
||||
@NotNull
|
||||
public static PlaceholderAPIPlugin getInstance() {
|
||||
return instance;
|
||||
/**
|
||||
* Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
|
||||
* class, this is the main class that extends JavaPlugin. For most API methods, use static methods
|
||||
* available from the class: {@link PlaceholderAPI}
|
||||
*
|
||||
* @return PlaceholderAPIPlugin instance
|
||||
*/
|
||||
@NotNull
|
||||
public static PlaceholderAPIPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain String} value that should be returned when a boolean is true
|
||||
*
|
||||
* @return string value of true
|
||||
*/
|
||||
@NotNull
|
||||
public static String booleanTrue() {
|
||||
return getInstance().getPlaceholderAPIConfig().booleanTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain String} value that should be returned when a boolean is false
|
||||
*
|
||||
* @return string value of false
|
||||
*/
|
||||
@NotNull
|
||||
public static String booleanFalse() {
|
||||
return getInstance().getPlaceholderAPIConfig().booleanFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for
|
||||
* generic time based placeholders
|
||||
*
|
||||
* @return date format
|
||||
*/
|
||||
@NotNull
|
||||
public static SimpleDateFormat getDateFormat() {
|
||||
try {
|
||||
return new SimpleDateFormat(getInstance().getPlaceholderAPIConfig().dateFormat());
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
getInstance().getLogger().log(Level.WARNING, "configured date format is invalid", ex);
|
||||
return new SimpleDateFormat("MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
}
|
||||
|
||||
public static Version getServerVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
|
||||
saveDefaultConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
setupCommand();
|
||||
setupMetrics();
|
||||
setupExpansions();
|
||||
|
||||
adventure = BukkitAudiences.create(this);
|
||||
|
||||
if (config.isCloudEnabled()) {
|
||||
getCloudExpansionManager().load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain String} value that should be returned when a boolean is true
|
||||
*
|
||||
* @return string value of true
|
||||
*/
|
||||
@NotNull
|
||||
public static String booleanTrue() {
|
||||
return getInstance().getPlaceholderAPIConfig().booleanTrue();
|
||||
if (config.checkUpdates()) {
|
||||
new UpdateChecker(this).fetch();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getCloudExpansionManager().kill();
|
||||
getLocalExpansionManager().kill();
|
||||
|
||||
HandlerList.unregisterAll(this);
|
||||
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
|
||||
adventure.close();
|
||||
adventure = null;
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
||||
public void reloadConf(@NotNull final CommandSender sender) {
|
||||
getLocalExpansionManager().kill();
|
||||
|
||||
reloadConfig();
|
||||
|
||||
getLocalExpansionManager().load(sender);
|
||||
|
||||
if (config.isCloudEnabled()) {
|
||||
getCloudExpansionManager().load();
|
||||
} else {
|
||||
getCloudExpansionManager().kill();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LocalExpansionManager getLocalExpansionManager() {
|
||||
return localExpansionManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CloudExpansionManager getCloudExpansionManager() {
|
||||
return cloudExpansionManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitAudiences getAdventure() {
|
||||
if(adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain String} value that should be returned when a boolean is false
|
||||
*
|
||||
* @return string value of false
|
||||
*/
|
||||
@NotNull
|
||||
public static String booleanFalse() {
|
||||
return getInstance().getPlaceholderAPIConfig().booleanFalse();
|
||||
return adventure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the configuration class for PlaceholderAPI.
|
||||
*
|
||||
* @return PlaceholderAPIConfig instance
|
||||
*/
|
||||
@NotNull
|
||||
public PlaceholderAPIConfig getPlaceholderAPIConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
private void setupCommand() {
|
||||
final PluginCommand pluginCommand = getCommand("placeholderapi");
|
||||
if (pluginCommand == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for
|
||||
* generic time based placeholders
|
||||
*
|
||||
* @return date format
|
||||
*/
|
||||
@NotNull
|
||||
public static SimpleDateFormat getDateFormat() {
|
||||
try {
|
||||
return new SimpleDateFormat(getInstance().getPlaceholderAPIConfig().dateFormat());
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
Msg.warn("Configured date format ('%s') is invalid! Defaulting to 'MM/dd/yy HH:mm:ss'",
|
||||
ex, getInstance().getPlaceholderAPIConfig().dateFormat());
|
||||
return new SimpleDateFormat("MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Version getServerVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
|
||||
saveDefaultConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
registerCommand("test", new TestCommand());
|
||||
setupCommand();
|
||||
setupMetrics();
|
||||
setupExpansions();
|
||||
|
||||
adventure = BukkitAudiences.create(this);
|
||||
|
||||
if (config.isCloudEnabled()) {
|
||||
getCloudExpansionManager().load();
|
||||
}
|
||||
|
||||
if (config.checkUpdates()) {
|
||||
new UpdateChecker(this).fetch();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getCloudExpansionManager().kill();
|
||||
getLocalExpansionManager().kill();
|
||||
|
||||
HandlerList.unregisterAll(this);
|
||||
|
||||
scheduler.cancelTasks(this);
|
||||
|
||||
adventure.close();
|
||||
adventure = null;
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
||||
public void reloadConf(@NotNull final CommandSender sender) {
|
||||
getLocalExpansionManager().kill();
|
||||
|
||||
reloadConfig();
|
||||
|
||||
getLocalExpansionManager().load(sender);
|
||||
|
||||
if (config.isCloudEnabled()) {
|
||||
getCloudExpansionManager().load();
|
||||
} else {
|
||||
getCloudExpansionManager().kill();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LocalExpansionManager getLocalExpansionManager() {
|
||||
return localExpansionManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CloudExpansionManager getCloudExpansionManager() {
|
||||
return cloudExpansionManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitAudiences getAdventure() {
|
||||
if(adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
|
||||
return adventure;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public TaskScheduler getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the configuration class for PlaceholderAPI.
|
||||
*
|
||||
* @return PlaceholderAPIConfig instance
|
||||
*/
|
||||
@NotNull
|
||||
public PlaceholderAPIConfig getPlaceholderAPIConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
private void setupCommand() {
|
||||
final PluginCommand pluginCommand = getCommand("placeholderapi");
|
||||
if (pluginCommand == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PlaceholderCommandRouter router = new PlaceholderCommandRouter(this);
|
||||
pluginCommand.setExecutor(router);
|
||||
pluginCommand.setTabCompleter(router);
|
||||
}
|
||||
|
||||
private void setupMetrics() {
|
||||
final Metrics metrics = new Metrics(this, 438);
|
||||
metrics.addCustomChart(new SimplePie("using_expansion_cloud",
|
||||
() -> getPlaceholderAPIConfig().isCloudEnabled() ? "yes" : "no"));
|
||||
|
||||
metrics.addCustomChart(new SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
||||
|
||||
metrics.addCustomChart(new AdvancedPie("expansions_used", () -> {
|
||||
final Map<String, Integer> values = new HashMap<>();
|
||||
|
||||
for (final PlaceholderExpansion expansion : getLocalExpansionManager().getExpansions()) {
|
||||
values.put(expansion.getRequiredPlugin() == null ? expansion.getIdentifier()
|
||||
: expansion.getRequiredPlugin(), 1);
|
||||
}
|
||||
|
||||
return values;
|
||||
}));
|
||||
}
|
||||
|
||||
private void setupExpansions() {
|
||||
Bukkit.getPluginManager().registerEvents(getLocalExpansionManager(), this);
|
||||
|
||||
try {
|
||||
Class.forName("org.bukkit.event.server.ServerLoadEvent");
|
||||
new ServerLoadEventListener(this);
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
scheduler
|
||||
.runTaskLater(() -> getLocalExpansionManager().load(Bukkit.getConsoleSender()), 1);
|
||||
}
|
||||
final PlaceholderCommandRouter router = new PlaceholderCommandRouter(this);
|
||||
pluginCommand.setExecutor(router);
|
||||
pluginCommand.setTabCompleter(router);
|
||||
}
|
||||
|
||||
private void setupMetrics() {
|
||||
final Metrics metrics = new Metrics(this, 438);
|
||||
metrics.addCustomChart(new SimplePie("using_expansion_cloud",
|
||||
() -> getPlaceholderAPIConfig().isCloudEnabled() ? "yes" : "no"));
|
||||
|
||||
metrics.addCustomChart(new SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
||||
|
||||
metrics.addCustomChart(new AdvancedPie("expansions_used", () -> {
|
||||
final Map<String, Integer> values = new HashMap<>();
|
||||
|
||||
for (final PlaceholderExpansion expansion : getLocalExpansionManager().getExpansions()) {
|
||||
values.put(expansion.getRequiredPlugin() == null ? expansion.getIdentifier()
|
||||
: expansion.getRequiredPlugin(), 1);
|
||||
}
|
||||
|
||||
return values;
|
||||
}));
|
||||
}
|
||||
|
||||
private void setupExpansions() {
|
||||
Bukkit.getPluginManager().registerEvents(getLocalExpansionManager(), this);
|
||||
|
||||
try {
|
||||
Class.forName("org.bukkit.event.server.ServerLoadEvent");
|
||||
new ServerLoadEventListener(this);
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(this, () -> getLocalExpansionManager().load(Bukkit.getConsoleSender()), 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -20,19 +20,16 @@
|
||||
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class PlaceholderHook {
|
||||
@Nullable
|
||||
public String onRequest(final OfflinePlayer player, @NotNull final String params) {
|
||||
if (player != null && player.isOnline()) {
|
||||
return onPlaceholderRequest(player.getPlayer(), params);
|
||||
return onPlaceholderRequest((Player) player, params);
|
||||
}
|
||||
|
||||
return onPlaceholderRequest(null, params);
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -22,12 +22,9 @@ package me.clip.placeholderapi.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -36,75 +33,75 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public abstract class PlaceholderCommand {
|
||||
|
||||
@NotNull
|
||||
private final String label;
|
||||
@NotNull
|
||||
private final Set<String> alias;
|
||||
@NotNull
|
||||
private final String label;
|
||||
@NotNull
|
||||
private final Set<String> alias;
|
||||
|
||||
@Nullable
|
||||
private String permission;
|
||||
@Nullable
|
||||
private String permission;
|
||||
|
||||
|
||||
protected PlaceholderCommand(@NotNull final String label, @NotNull final String... alias) {
|
||||
this.label = label;
|
||||
this.alias = Sets.newHashSet(alias);
|
||||
protected PlaceholderCommand(@NotNull final String label, @NotNull final String... alias) {
|
||||
this.label = label;
|
||||
this.alias = Sets.newHashSet(alias);
|
||||
|
||||
setPermission("placeholderapi." + label);
|
||||
setPermission("placeholderapi." + label);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Stream<PlaceholderCommand> filterByPermission(@NotNull final CommandSender sender,
|
||||
@NotNull final Stream<PlaceholderCommand> commands) {
|
||||
return commands.filter(
|
||||
target -> target.getPermission() == null || sender.hasPermission(target.getPermission()));
|
||||
}
|
||||
|
||||
public static void suggestByParameter(@NotNull final Stream<String> possible,
|
||||
@NotNull final List<String> suggestions, @Nullable final String parameter) {
|
||||
if (parameter == null) {
|
||||
possible.forEach(suggestions::add);
|
||||
} else {
|
||||
possible.filter(suggestion -> suggestion.toLowerCase().startsWith(parameter.toLowerCase()))
|
||||
.forEach(suggestions::add);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Stream<PlaceholderCommand> filterByPermission(@NotNull final CommandSender sender,
|
||||
@NotNull final Stream<PlaceholderCommand> commands) {
|
||||
return commands.filter(
|
||||
target -> target.getPermission() == null || sender.hasPermission(target.getPermission()));
|
||||
}
|
||||
@NotNull
|
||||
public final String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public static void suggestByParameter(@NotNull final Stream<String> possible,
|
||||
@NotNull final List<String> suggestions, @Nullable final String parameter) {
|
||||
if (parameter == null) {
|
||||
possible.forEach(suggestions::add);
|
||||
} else {
|
||||
possible.filter(suggestion -> suggestion.toLowerCase(Locale.ROOT).startsWith(parameter.toLowerCase(Locale.ROOT)))
|
||||
.forEach(suggestions::add);
|
||||
}
|
||||
}
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public final Set<String> getAlias() {
|
||||
return ImmutableSet.copyOf(alias);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final String getLabel() {
|
||||
return label;
|
||||
}
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public final Set<String> getLabels() {
|
||||
return ImmutableSet.<String>builder().add(label).addAll(alias).build();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public final Set<String> getAlias() {
|
||||
return ImmutableSet.copyOf(alias);
|
||||
}
|
||||
@Nullable
|
||||
public final String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public final Set<String> getLabels() {
|
||||
return ImmutableSet.<String>builder().add(label).addAll(alias).build();
|
||||
}
|
||||
public void setPermission(@NotNull final String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public final String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
|
||||
public void setPermission(@NotNull final String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
}
|
||||
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
|
||||
}
|
||||
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -22,16 +22,13 @@ package me.clip.placeholderapi.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.impl.cloud.CommandECloud;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandDump;
|
||||
@@ -53,93 +50,93 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class PlaceholderCommandRouter implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Unmodifiable
|
||||
private static final List<PlaceholderCommand> COMMANDS = ImmutableList.of(new CommandHelp(),
|
||||
new CommandInfo(),
|
||||
new CommandList(),
|
||||
new CommandDump(),
|
||||
new CommandECloud(),
|
||||
new CommandParse(),
|
||||
new CommandReload(),
|
||||
new CommandVersion(),
|
||||
new CommandExpansionRegister(),
|
||||
new CommandExpansionUnregister());
|
||||
@Unmodifiable
|
||||
private static final List<PlaceholderCommand> COMMANDS = ImmutableList.of(new CommandHelp(),
|
||||
new CommandInfo(),
|
||||
new CommandList(),
|
||||
new CommandDump(),
|
||||
new CommandECloud(),
|
||||
new CommandParse(),
|
||||
new CommandReload(),
|
||||
new CommandVersion(),
|
||||
new CommandExpansionRegister(),
|
||||
new CommandExpansionUnregister());
|
||||
|
||||
|
||||
@NotNull
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
private final Map<String, PlaceholderCommand> commands;
|
||||
@NotNull
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
private final Map<String, PlaceholderCommand> commands;
|
||||
|
||||
|
||||
public PlaceholderCommandRouter(@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
public PlaceholderCommandRouter(@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
final ImmutableMap.Builder<String, PlaceholderCommand> commands = ImmutableMap.builder();
|
||||
final ImmutableMap.Builder<String, PlaceholderCommand> commands = ImmutableMap.builder();
|
||||
|
||||
for (final PlaceholderCommand command : COMMANDS) {
|
||||
command.getLabels().forEach(label -> commands.put(label, command));
|
||||
}
|
||||
|
||||
this.commands = commands.build();
|
||||
for (final PlaceholderCommand command : COMMANDS) {
|
||||
command.getLabels().forEach(label -> commands.put(label, command));
|
||||
}
|
||||
|
||||
this.commands = commands.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Command command,
|
||||
@NotNull final String alias, @NotNull final String[] args) {
|
||||
if (args.length == 0) {
|
||||
final PlaceholderCommand fallback = commands.get("version");
|
||||
if (fallback != null) {
|
||||
fallback.evaluate(plugin, sender, "", Collections.emptyList());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Command command,
|
||||
@NotNull final String alias, @NotNull final String[] args) {
|
||||
if (args.length == 0) {
|
||||
final PlaceholderCommand fallback = commands.get("version");
|
||||
if (fallback != null) {
|
||||
fallback.evaluate(plugin, sender, "", Collections.emptyList());
|
||||
}
|
||||
|
||||
final String search = args[0].toLowerCase(Locale.ROOT);
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
if (target == null) {
|
||||
Msg.msg(sender, "&cUnknown command &7" + search);
|
||||
return true;
|
||||
}
|
||||
|
||||
final String permission = target.getPermission();
|
||||
if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) {
|
||||
Msg.msg(sender, "&cYou do not have permission to do this!");
|
||||
return true;
|
||||
}
|
||||
|
||||
target
|
||||
.evaluate(plugin, sender, search, Arrays.asList(Arrays.copyOfRange(args, 1, args.length)));
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull final CommandSender sender,
|
||||
@NotNull final Command command, @NotNull final String alias, @NotNull final String[] args) {
|
||||
final List<String> suggestions = new ArrayList<>();
|
||||
final String search = args[0].toLowerCase();
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
if (args.length > 1) {
|
||||
final PlaceholderCommand target = this.commands.get(args[0].toLowerCase(Locale.ROOT));
|
||||
|
||||
if (target != null) {
|
||||
target.complete(plugin, sender, args[0].toLowerCase(Locale.ROOT),
|
||||
Arrays.asList(Arrays.copyOfRange(args, 1, args.length)), suggestions);
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
final Stream<String> targets = PlaceholderCommand
|
||||
.filterByPermission(sender, commands.values().stream()).map(PlaceholderCommand::getLabels)
|
||||
.flatMap(Collection::stream);
|
||||
PlaceholderCommand.suggestByParameter(targets, suggestions, args.length == 0 ? null : args[0]);
|
||||
|
||||
return suggestions;
|
||||
if (target == null) {
|
||||
Msg.msg(sender, "&cUnknown command &7" + search);
|
||||
return true;
|
||||
}
|
||||
|
||||
final String permission = target.getPermission();
|
||||
if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) {
|
||||
Msg.msg(sender, "&cYou do not have permission to do this!");
|
||||
return true;
|
||||
}
|
||||
|
||||
target
|
||||
.evaluate(plugin, sender, search, Arrays.asList(Arrays.copyOfRange(args, 1, args.length)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull final CommandSender sender,
|
||||
@NotNull final Command command, @NotNull final String alias, @NotNull final String[] args) {
|
||||
final List<String> suggestions = new ArrayList<>();
|
||||
|
||||
if (args.length > 1) {
|
||||
final PlaceholderCommand target = this.commands.get(args[0].toLowerCase());
|
||||
|
||||
if (target != null) {
|
||||
target.complete(plugin, sender, args[0].toLowerCase(),
|
||||
Arrays.asList(Arrays.copyOfRange(args, 1, args.length)), suggestions);
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
final Stream<String> targets = PlaceholderCommand
|
||||
.filterByPermission(sender, commands.values().stream()).map(PlaceholderCommand::getLabels)
|
||||
.flatMap(Collection::stream);
|
||||
PlaceholderCommand.suggestByParameter(targets, suggestions, args.length == 0 ? null : args[0]);
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import io.papermc.paper.command.brigadier.BasicCommand;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import me.clip.placeholderapi.PAPIComponents;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class TestCommand implements BasicCommand {
|
||||
private static final MiniMessage MINI = MiniMessage.miniMessage();
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSourceStack commandSourceStack, final String[] strings) {
|
||||
// final Component component = Component.text("Woo! Test: %player_name%").color(TextColor.color(50, 168, 82)).hoverEvent(HoverEvent.showText(Component.text("OMG %player_gamemode%")));
|
||||
final Component component = Component.text("Woo! Test: %player_name%");
|
||||
|
||||
String ser = MINI.serialize(component);
|
||||
System.out.println(ser);
|
||||
|
||||
commandSourceStack.getSender().sendMessage(
|
||||
PAPIComponents.setPlaceholders((OfflinePlayer) commandSourceStack.getSender(), component)
|
||||
);
|
||||
|
||||
long tmp = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100000; ++i) {
|
||||
PAPIComponents.setPlaceholders((OfflinePlayer) commandSourceStack.getSender(), component);
|
||||
}
|
||||
commandSourceStack.getSender().sendMessage(String.valueOf(System.currentTimeMillis() - tmp));
|
||||
|
||||
tmp = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100000; ++i) {
|
||||
PlaceholderAPI.setPlaceholders((OfflinePlayer) commandSourceStack.getSender(), "Woo! Test: %player_name%");
|
||||
}
|
||||
commandSourceStack.getSender().sendMessage(String.valueOf(System.currentTimeMillis() - tmp));
|
||||
|
||||
tmp = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100000; ++i) {
|
||||
final String serr = MINI.serialize(component);
|
||||
final String repl = PlaceholderAPI.setPlaceholders((OfflinePlayer) commandSourceStack.getSender(), serr);
|
||||
MINI.deserialize(repl);
|
||||
}
|
||||
commandSourceStack.getSender().sendMessage(String.valueOf(System.currentTimeMillis() - tmp));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -22,6 +22,10 @@ package me.clip.placeholderapi.commands.impl.cloud;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
@@ -29,118 +33,117 @@ import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class CommandECloud extends PlaceholderCommand {
|
||||
|
||||
@Unmodifiable
|
||||
private static final List<PlaceholderCommand> COMMANDS = ImmutableList
|
||||
.of(new CommandECloudClear(),
|
||||
new CommandECloudStatus(),
|
||||
new CommandECloudUpdate(),
|
||||
new CommandECloudRefresh(),
|
||||
new CommandECloudDownload(),
|
||||
new CommandECloudExpansionInfo(),
|
||||
new CommandECloudExpansionList(),
|
||||
new CommandECloudExpansionPlaceholders());
|
||||
@Unmodifiable
|
||||
private static final List<PlaceholderCommand> COMMANDS = ImmutableList
|
||||
.of(new CommandECloudClear(),
|
||||
new CommandECloudToggle(),
|
||||
new CommandECloudStatus(),
|
||||
new CommandECloudUpdate(),
|
||||
new CommandECloudRefresh(),
|
||||
new CommandECloudDownload(),
|
||||
new CommandECloudExpansionInfo(),
|
||||
new CommandECloudExpansionList(),
|
||||
new CommandECloudExpansionPlaceholders());
|
||||
|
||||
static {
|
||||
COMMANDS
|
||||
.forEach(command -> command.setPermission("placeholderapi.ecloud." + command.getLabel()));
|
||||
static {
|
||||
COMMANDS
|
||||
.forEach(command -> command.setPermission("placeholderapi.ecloud." + command.getLabel()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
private final Map<String, PlaceholderCommand> commands;
|
||||
|
||||
|
||||
public CommandECloud() {
|
||||
super("ecloud");
|
||||
|
||||
final ImmutableMap.Builder<String, PlaceholderCommand> commands = ImmutableMap.builder();
|
||||
|
||||
for (final PlaceholderCommand command : COMMANDS) {
|
||||
command.getLabels().forEach(label -> commands.put(label, command));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
private final Map<String, PlaceholderCommand> commands;
|
||||
this.commands = commands.build();
|
||||
}
|
||||
|
||||
|
||||
public CommandECloud() {
|
||||
super("ecloud");
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&b&lPlaceholderAPI &8- &7eCloud Help Menu &8- ",
|
||||
" ",
|
||||
"&b/papi &fenable/disable/toggle",
|
||||
" &7&oEnable or disable the eCloud",
|
||||
"&b/papi &fecloud status",
|
||||
" &7&oView status of the eCloud",
|
||||
"&b/papi &fecloud list <all/{author}/installed> {page}",
|
||||
" &7&oList all/author specific available expansions",
|
||||
"&b/papi &fecloud info <expansion name> {version}",
|
||||
" &7&oView information about a specific expansion available on the eCloud",
|
||||
"&b/papi &fecloud placeholders <expansion name>",
|
||||
" &7&oView placeholders for an expansion",
|
||||
"&b/papi &fecloud download <expansion name> {version}",
|
||||
" &7&oDownload an expansion from the eCloud",
|
||||
"&b/papi &fecloud update <expansion name/all>",
|
||||
" &7&oUpdate a specific/all installed expansions",
|
||||
"&b/papi &fecloud refresh",
|
||||
" &7&oFetch the most up to date list of expansions available.",
|
||||
"&b/papi &fecloud clear",
|
||||
" &7&oClear the expansion cloud cache.");
|
||||
|
||||
final ImmutableMap.Builder<String, PlaceholderCommand> commands = ImmutableMap.builder();
|
||||
|
||||
for (final PlaceholderCommand command : COMMANDS) {
|
||||
command.getLabels().forEach(label -> commands.put(label, command));
|
||||
}
|
||||
|
||||
this.commands = commands.build();
|
||||
return;
|
||||
}
|
||||
|
||||
final String search = params.get(0).toLowerCase();
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&b&lPlaceholderAPI &8- &7eCloud Help Menu &8- ",
|
||||
" ",
|
||||
"&b/papi &fecloud status",
|
||||
" &7&oView status of the eCloud",
|
||||
"&b/papi &fecloud list <all/{author}/installed> {page}",
|
||||
" &7&oList all/author specific available expansions",
|
||||
"&b/papi &fecloud info <expansion name> {version}",
|
||||
" &7&oView information about a specific expansion available on the eCloud",
|
||||
"&b/papi &fecloud placeholders <expansion name>",
|
||||
" &7&oView placeholders for an expansion",
|
||||
"&b/papi &fecloud download <expansion name> {version}",
|
||||
" &7&oDownload an expansion from the eCloud",
|
||||
"&b/papi &fecloud update <expansion name/all>",
|
||||
" &7&oUpdate a specific/all installed expansions",
|
||||
"&b/papi &fecloud refresh",
|
||||
" &7&oFetch the most up to date list of expansions available.",
|
||||
"&b/papi &fecloud clear",
|
||||
" &7&oClear the expansion cloud cache.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final String search = params.get(0).toLowerCase(Locale.ROOT);
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
if (target == null) {
|
||||
Msg.msg(sender, "&cUnknown command &7ecloud " + search);
|
||||
return;
|
||||
}
|
||||
|
||||
final String permission = target.getPermission();
|
||||
if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) {
|
||||
Msg.msg(sender, "&cYou do not have permission to do this!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.getPlaceholderAPIConfig().isCloudEnabled()) {
|
||||
Msg.msg(sender, "&cThe eCloud Manager is not enabled! To enable it, set 'cloud_enabled' to true and reload the plugin.");
|
||||
return;
|
||||
}
|
||||
|
||||
target.evaluate(plugin, sender, search, params.subList(1, params.size()));
|
||||
if (target == null) {
|
||||
Msg.msg(sender, "&cUnknown command &7ecloud " + search);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() <= 1) {
|
||||
final Stream<String> targets = filterByPermission(sender, commands.values().stream())
|
||||
.map(PlaceholderCommand::getLabels).flatMap(Collection::stream);
|
||||
suggestByParameter(targets, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
|
||||
return; // send sub commands
|
||||
}
|
||||
|
||||
final String search = params.get(0).toLowerCase(Locale.ROOT);
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
target.complete(plugin, sender, search, params.subList(1, params.size()), suggestions);
|
||||
final String permission = target.getPermission();
|
||||
if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) {
|
||||
Msg.msg(sender, "&cYou do not have permission to do this!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(target instanceof CommandECloudToggle) && !plugin.getPlaceholderAPIConfig()
|
||||
.isCloudEnabled()) {
|
||||
Msg.msg(sender,
|
||||
"&cThe eCloud Manager is not enabled!");
|
||||
return;
|
||||
}
|
||||
|
||||
target.evaluate(plugin, sender, search, params.subList(1, params.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() <= 1) {
|
||||
final Stream<String> targets = filterByPermission(sender, commands.values().stream())
|
||||
.map(PlaceholderCommand::getLabels).flatMap(Collection::stream);
|
||||
suggestByParameter(targets, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
|
||||
return; // send sub commands
|
||||
}
|
||||
|
||||
final String search = params.get(0).toLowerCase();
|
||||
final PlaceholderCommand target = commands.get(search);
|
||||
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
target.complete(plugin, sender, search, params.subList(1, params.size()), suggestions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.commands.impl.cloud;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
@@ -31,17 +30,17 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandECloudClear extends PlaceholderCommand {
|
||||
|
||||
public CommandECloudClear() {
|
||||
super("clear");
|
||||
}
|
||||
public CommandECloudClear() {
|
||||
super("clear");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
plugin.getCloudExpansionManager().clean();
|
||||
Msg.msg(sender,
|
||||
"&aThe eCloud cache has been cleared!");
|
||||
}
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
plugin.getCloudExpansionManager().clean();
|
||||
Msg.msg(sender,
|
||||
"&aThe eCloud cache has been cleared!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -20,11 +20,9 @@
|
||||
|
||||
package me.clip.placeholderapi.commands.impl.cloud;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
@@ -35,106 +33,87 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandECloudDownload extends PlaceholderCommand {
|
||||
|
||||
public CommandECloudDownload() {
|
||||
super("download");
|
||||
public CommandECloudDownload() {
|
||||
super("download");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must supply the name of an expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
private boolean isBlockedExpansion(String name) {
|
||||
String env = System.getenv("PAPI_BLOCKED_EXPANSIONS");
|
||||
if (env == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Arrays.stream(env.split(","))
|
||||
.anyMatch(s -> s.equalsIgnoreCase(name));
|
||||
final CloudExpansion expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0)).orElse(null);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender,
|
||||
"&cFailed to find an expansion named: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
final CloudExpansion.Version version;
|
||||
if (params.size() < 2) {
|
||||
version = expansion.getVersion(expansion.getLatestVersion());
|
||||
if (version == null) {
|
||||
Msg.msg(sender,
|
||||
"&cCould not find latest version for expansion.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
version = expansion.getVersion(params.get(1));
|
||||
if (version == null) {
|
||||
Msg.msg(sender,
|
||||
"&cCould not find specified version: &f" + params.get(1),
|
||||
"&7Available versions: &f" + expansion.getAvailableVersions());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
plugin.getCloudExpansionManager().downloadExpansion(expansion, version)
|
||||
.whenComplete((file, exception) -> {
|
||||
if (exception != null) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must supply the name of an expansion.");
|
||||
"&cFailed to download expansion: &f" + exception.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlockedExpansion(params.get(0))) {
|
||||
Msg.msg(sender,
|
||||
"&cThis expansion can't be downloaded.");
|
||||
return;
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&aSuccessfully downloaded expansion &f" + expansion.getName() + " [" + version
|
||||
.getVersion() + "] &ato file: &f" + file.getName(),
|
||||
"&aMake sure to type &f/papi reload &ato enable your new expansion!");
|
||||
|
||||
final CloudExpansion expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0)).orElse(null);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender,
|
||||
"&cFailed to find an expansion named: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
plugin.getCloudExpansionManager().clean();
|
||||
plugin.getCloudExpansionManager()
|
||||
.fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
});
|
||||
}
|
||||
|
||||
if (!expansion.isVerified()) {
|
||||
Msg.msg(sender, "&cThe expansion '&f" + params.get(0) + "&c' is not verified and can only be downloaded manually from &fhttps://placeholderapi.com/ecloud");
|
||||
return;
|
||||
}
|
||||
|
||||
final CloudExpansion.Version version;
|
||||
if (params.size() < 2) {
|
||||
version = expansion.getVersion(expansion.getLatestVersion());
|
||||
if (version == null) {
|
||||
Msg.msg(sender,
|
||||
"&cCould not find latest version for expansion.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
version = expansion.getVersion(params.get(1));
|
||||
if (version == null) {
|
||||
Msg.msg(sender,
|
||||
"&cCould not find specified version: &f" + params.get(1),
|
||||
"&7Available versions: &f" + expansion.getAvailableVersions());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
plugin.getCloudExpansionManager().downloadExpansion(expansion, version)
|
||||
.whenComplete((file, exception) -> {
|
||||
if (exception != null) {
|
||||
Msg.msg(sender,
|
||||
"&cFailed to download expansion: &f" + exception.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
Msg.msg(sender,
|
||||
"&aSuccessfully downloaded expansion &f" + expansion.getName() + " [" + version
|
||||
.getVersion() + "] &ato file: &f" + file.getName(),
|
||||
"&aMake sure to type &f/papi reload &ato enable your new expansion!");
|
||||
|
||||
plugin.getCloudExpansionManager().load();
|
||||
});
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.size() <= 1) {
|
||||
final Stream<String> names = plugin.getCloudExpansionManager().getCloudExpansions().values()
|
||||
.stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<CloudExpansion> expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0));
|
||||
if (!expansion.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
|
||||
if (params.size() <= 1) {
|
||||
final Stream<String> names = plugin.getCloudExpansionManager().getCloudExpansions().values()
|
||||
.stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<CloudExpansion> expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0));
|
||||
if (!expansion.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -23,7 +23,6 @@ package me.clip.placeholderapi.commands.impl.cloud;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
@@ -34,97 +33,97 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandECloudExpansionInfo extends PlaceholderCommand {
|
||||
|
||||
public CommandECloudExpansionInfo() {
|
||||
super("info");
|
||||
public CommandECloudExpansionInfo() {
|
||||
super("info");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of the expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of the expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
final CloudExpansion expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0)).orElse(null);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender,
|
||||
"&cThere is no expansion with the name: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("&bExpansion: &f")
|
||||
.append(expansion.shouldUpdate() ? "&e" : "&a")
|
||||
.append(expansion.getName())
|
||||
.append('\n')
|
||||
.append("&bAuthor: &f")
|
||||
.append(expansion.getAuthor())
|
||||
.append('\n')
|
||||
.append("&bVerified: ")
|
||||
.append(expansion.isVerified() ? "&a&l✔" : "&c&l❌")
|
||||
.append('\n');
|
||||
|
||||
if (params.size() < 2) {
|
||||
builder.append("&bLatest Version: &f")
|
||||
.append(expansion.getLatestVersion())
|
||||
.append('\n')
|
||||
.append("&bReleased: &f")
|
||||
.append(expansion.getTimeSinceLastUpdate())
|
||||
.append(" ago")
|
||||
.append('\n')
|
||||
.append("&bRelease Notes: &f")
|
||||
.append(expansion.getVersion().getReleaseNotes())
|
||||
.append('\n');
|
||||
} else {
|
||||
final CloudExpansion.Version version = expansion.getVersion(params.get(1));
|
||||
if (version == null) {
|
||||
Msg.msg(sender,
|
||||
"&cCould not find specified version: &f" + params.get(1),
|
||||
"&aVersions: &f" + expansion.getAvailableVersions());
|
||||
return;
|
||||
}
|
||||
|
||||
builder.append("&bVersion: &f")
|
||||
.append(version.getVersion())
|
||||
.append('\n')
|
||||
.append("&bRelease Notes: &f")
|
||||
.append(version.getReleaseNotes())
|
||||
.append('\n')
|
||||
.append("&bDownload URL: &f")
|
||||
.append(version.getUrl())
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
final CloudExpansion expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0)).orElse(null);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender,
|
||||
"&cThere is no expansion with the name: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 2) {
|
||||
return;
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (params.size() <= 1) {
|
||||
final Stream<String> names = plugin.getCloudExpansionManager().getCloudExpansions().values()
|
||||
.stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
return;
|
||||
}
|
||||
builder.append("&bExpansion: &f")
|
||||
.append(expansion.shouldUpdate() ? "&e" : "&a")
|
||||
.append(expansion.getName())
|
||||
.append('\n')
|
||||
.append("&bAuthor: &f")
|
||||
.append(expansion.getAuthor())
|
||||
.append('\n')
|
||||
.append("&bVerified: ")
|
||||
.append(expansion.isVerified() ? "&a&l✔" : "&c&l❌")
|
||||
.append('\n');
|
||||
|
||||
final Optional<CloudExpansion> expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0));
|
||||
if (!expansion.isPresent()) {
|
||||
return;
|
||||
}
|
||||
if (params.size() < 2) {
|
||||
builder.append("&bLatest Version: &f")
|
||||
.append(expansion.getLatestVersion())
|
||||
.append('\n')
|
||||
.append("&bReleased: &f")
|
||||
.append(expansion.getTimeSinceLastUpdate())
|
||||
.append(" ago")
|
||||
.append('\n')
|
||||
.append("&bRelease Notes: &f")
|
||||
.append(expansion.getVersion().getReleaseNotes())
|
||||
.append('\n');
|
||||
} else {
|
||||
final CloudExpansion.Version version = expansion.getVersion(params.get(1));
|
||||
if (version == null) {
|
||||
Msg.msg(sender,
|
||||
"&cCould not find specified version: &f" + params.get(1),
|
||||
"&aVersions: &f" + expansion.getAvailableVersions());
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
|
||||
builder.append("&bVersion: &f")
|
||||
.append(version.getVersion())
|
||||
.append('\n')
|
||||
.append("&bRelease Notes: &f")
|
||||
.append(version.getReleaseNotes())
|
||||
.append('\n')
|
||||
.append("&bDownload URL: &f")
|
||||
.append(version.getUrl())
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.size() <= 1) {
|
||||
final Stream<String> names = plugin.getCloudExpansionManager().getCloudExpansions().values()
|
||||
.stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<CloudExpansion> expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0));
|
||||
if (!expansion.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -25,14 +25,12 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.configuration.ExpansionSort;
|
||||
@@ -56,299 +54,299 @@ import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
|
||||
public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
|
||||
private static final int PAGE_SIZE = 10;
|
||||
private static final int PAGE_SIZE = 10;
|
||||
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_NAME =
|
||||
expansion -> (expansion.shouldUpdate() ? "&6" : expansion.hasExpansion() ? "&a" : "&7")
|
||||
+ expansion.getName();
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_AUTHOR =
|
||||
expansion -> "&f" + expansion.getAuthor();
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_VERIFIED =
|
||||
expansion -> expansion.isVerified() ? "&aY" : "&cN";
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_LATEST_VERSION =
|
||||
expansion -> "&f" + expansion.getLatestVersion();
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_CURRENT_VERSION =
|
||||
expansion -> "&f" + PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()
|
||||
.findExpansionByName(expansion.getName()).map(PlaceholderExpansion::getVersion)
|
||||
.orElse("Unknown");
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_NAME =
|
||||
expansion -> (expansion.shouldUpdate() ? "&6" : expansion.hasExpansion() ? "&a" : "&7")
|
||||
+ expansion.getName();
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_AUTHOR =
|
||||
expansion -> "&f" + expansion.getAuthor();
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_VERIFIED =
|
||||
expansion -> expansion.isVerified() ? "&aY" : "&cN";
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_LATEST_VERSION =
|
||||
expansion -> "&f" + expansion.getLatestVersion();
|
||||
@NotNull
|
||||
private static final Function<CloudExpansion, Object> EXPANSION_CURRENT_VERSION =
|
||||
expansion -> "&f" + PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()
|
||||
.findExpansionByName(expansion.getName()).map(PlaceholderExpansion::getVersion)
|
||||
.orElse("Unknown");
|
||||
|
||||
|
||||
@Unmodifiable
|
||||
private static final Set<String> OPTIONS = ImmutableSet.of("all", "installed");
|
||||
@Unmodifiable
|
||||
private static final Set<String> OPTIONS = ImmutableSet.of("all", "installed");
|
||||
|
||||
|
||||
public CommandECloudExpansionList() {
|
||||
super("list");
|
||||
public CommandECloudExpansionList() {
|
||||
super("list");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<CloudExpansion> getExpansions(@NotNull final String target,
|
||||
@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
switch (target.toLowerCase()) {
|
||||
case "all":
|
||||
return plugin.getCloudExpansionManager().getCloudExpansions().values();
|
||||
case "installed":
|
||||
return plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values();
|
||||
default:
|
||||
return plugin.getCloudExpansionManager().getCloudExpansionsByAuthor(target).values();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<CloudExpansion> getPage(@NotNull final List<CloudExpansion> expansions,
|
||||
final int page) {
|
||||
final int head = (page * PAGE_SIZE);
|
||||
final int tail = Math.min(expansions.size(), head + PAGE_SIZE);
|
||||
|
||||
if (expansions.size() < head) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<CloudExpansion> getExpansions(@NotNull final String target,
|
||||
@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
switch (target.toLowerCase(Locale.ROOT)) {
|
||||
case "all":
|
||||
return plugin.getCloudExpansionManager().getCloudExpansions().values();
|
||||
case "installed":
|
||||
return plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values();
|
||||
default:
|
||||
return plugin.getCloudExpansionManager().getCloudExpansionsByAuthor(target).values();
|
||||
}
|
||||
return expansions.subList(head, tail);
|
||||
}
|
||||
|
||||
public static void addExpansionTitle(@NotNull final StringBuilder builder,
|
||||
@NotNull final String target, final int page) {
|
||||
switch (target.toLowerCase()) {
|
||||
case "all":
|
||||
builder.append("&bAll Expansions");
|
||||
break;
|
||||
case "installed":
|
||||
builder.append("&bInstalled Expansions");
|
||||
break;
|
||||
default:
|
||||
builder.append("&bExpansions by &f")
|
||||
.append(target);
|
||||
break;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<CloudExpansion> getPage(@NotNull final List<CloudExpansion> expansions,
|
||||
final int page) {
|
||||
final int head = (page * PAGE_SIZE);
|
||||
final int tail = Math.min(expansions.size(), head + PAGE_SIZE);
|
||||
|
||||
if (expansions.size() < head) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return expansions.subList(head, tail);
|
||||
if (page == -1) {
|
||||
builder.append('\n');
|
||||
return;
|
||||
}
|
||||
|
||||
public static void addExpansionTitle(@NotNull final StringBuilder builder,
|
||||
@NotNull final String target, final int page) {
|
||||
switch (target.toLowerCase(Locale.ROOT)) {
|
||||
case "all":
|
||||
builder.append("&bAll Expansions");
|
||||
break;
|
||||
case "installed":
|
||||
builder.append("&bInstalled Expansions");
|
||||
break;
|
||||
default:
|
||||
builder.append("&bExpansions by &f")
|
||||
.append(target);
|
||||
break;
|
||||
}
|
||||
builder.append(" &bPage&7: &a")
|
||||
.append(page)
|
||||
.append("&r");
|
||||
}
|
||||
|
||||
if (page == -1) {
|
||||
builder.append('\n');
|
||||
return;
|
||||
}
|
||||
private static Component getMessage(@NotNull final List<CloudExpansion> expansions,
|
||||
final int page, final int limit, @NotNull final String target) {
|
||||
final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat();
|
||||
|
||||
builder.append(" &bPage&7: &a")
|
||||
.append(page)
|
||||
.append("&r");
|
||||
}
|
||||
final TextComponent.Builder message = text();
|
||||
|
||||
private static Component getMessage(@NotNull final List<CloudExpansion> expansions,
|
||||
final int page, final int limit, @NotNull final String target) {
|
||||
final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat();
|
||||
for (int index = 0; index < expansions.size(); index++) {
|
||||
final CloudExpansion expansion = expansions.get(index);
|
||||
final TextComponent.Builder line = text();
|
||||
|
||||
final TextComponent.Builder message = text();
|
||||
final int expansionNumber = index + ((page - 1) * PAGE_SIZE) + 1;
|
||||
line.append(text(expansionNumber + ". ", DARK_GRAY));
|
||||
|
||||
for (int index = 0; index < expansions.size(); index++) {
|
||||
final CloudExpansion expansion = expansions.get(index);
|
||||
final TextComponent.Builder line = text();
|
||||
final NamedTextColor expansionColour;
|
||||
|
||||
final int expansionNumber = index + ((page - 1) * PAGE_SIZE) + 1;
|
||||
line.append(text(expansionNumber + ". ", DARK_GRAY));
|
||||
|
||||
final NamedTextColor expansionColour;
|
||||
|
||||
if (expansion.shouldUpdate()) {
|
||||
expansionColour = GOLD;
|
||||
} else {
|
||||
if (expansion.hasExpansion()) {
|
||||
expansionColour = GREEN;
|
||||
} else {
|
||||
expansionColour = GRAY;
|
||||
}
|
||||
}
|
||||
|
||||
line.append(text(expansion.getName(), expansionColour));
|
||||
|
||||
line.clickEvent(ClickEvent.suggestCommand("/papi ecloud download " + expansion.getName()));
|
||||
|
||||
final TextComponent.Builder hoverText = text("Click to download this expansion!", AQUA)
|
||||
.append(newline()).append(newline())
|
||||
.append(text("Author: ", AQUA)).append(text(expansion.getAuthor(), WHITE))
|
||||
.append(newline())
|
||||
.append(text("Verified: ", AQUA)).append(text(expansion.isVerified() ? "✔" : "❌", expansion.isVerified() ? GREEN : RED, TextDecoration.BOLD))
|
||||
.append(newline())
|
||||
.append(text("Released: ", AQUA)).append(text(format.format(expansion.getLastUpdate()), WHITE))
|
||||
.toBuilder();
|
||||
|
||||
Optional.ofNullable(expansion.getDescription())
|
||||
.filter(description -> !description.isEmpty())
|
||||
.ifPresent(description -> hoverText.append(newline()).append(newline())
|
||||
.append(text(description.replace("\r", "").trim(), WHITE))
|
||||
);
|
||||
|
||||
line.hoverEvent(HoverEvent.showText(hoverText.build()));
|
||||
|
||||
if (index != expansions.size() - 1) {
|
||||
line.append(newline());
|
||||
}
|
||||
|
||||
message.append(line.build());
|
||||
}
|
||||
|
||||
if (limit > 1) {
|
||||
message.append(newline());
|
||||
|
||||
final TextComponent.Builder left = text("â—€", page > 1 ? GRAY : DARK_GRAY).toBuilder();
|
||||
|
||||
if (page > 1) {
|
||||
left.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page - 1)));
|
||||
}
|
||||
|
||||
final TextComponent.Builder right = text("â–¶", page < limit ? GRAY : DARK_GRAY).toBuilder();
|
||||
|
||||
if (page < limit) {
|
||||
right.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page + 1)));
|
||||
}
|
||||
|
||||
message.append(left, text(" " + page + " ", GREEN), right);
|
||||
}
|
||||
|
||||
return message.build();
|
||||
}
|
||||
|
||||
private static void addExpansionTable(@NotNull final List<CloudExpansion> expansions,
|
||||
@NotNull final StringBuilder message, final int startIndex,
|
||||
@NotNull final String versionTitle,
|
||||
@NotNull final Function<CloudExpansion, Object> versionFunction) {
|
||||
final Map<String, Function<CloudExpansion, Object>> functions = new LinkedHashMap<>();
|
||||
|
||||
final AtomicInteger counter = new AtomicInteger(startIndex);
|
||||
functions.put("&f", expansion -> "&8" + counter.getAndIncrement() + ".");
|
||||
|
||||
functions.put("&9Name", EXPANSION_NAME);
|
||||
functions.put("&9Author", EXPANSION_AUTHOR);
|
||||
functions.put("&9Verified", EXPANSION_VERIFIED);
|
||||
functions.put(versionTitle, versionFunction);
|
||||
|
||||
final List<List<String>> rows = new ArrayList<>();
|
||||
|
||||
rows.add(0, new ArrayList<>(functions.keySet()));
|
||||
|
||||
for (final CloudExpansion expansion : expansions) {
|
||||
rows.add(functions.values().stream().map(function -> function.apply(expansion))
|
||||
.map(Objects::toString).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
final List<String> table = Format.tablify(Format.Align.LEFT, rows)
|
||||
.orElse(Collections.emptyList());
|
||||
if (table.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
table.add(1, "&8" + Strings.repeat("-", table.get(0).length() - (rows.get(0).size() * 2)));
|
||||
|
||||
message.append(String.join("\n", table));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify an option. [all, {author}, installed]");
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean installed = params.get(0).equalsIgnoreCase("installed");
|
||||
final List<CloudExpansion> expansions = Lists
|
||||
.newArrayList(getExpansions(params.get(0), plugin));
|
||||
|
||||
if (expansions.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cNo expansions available to list.");
|
||||
return;
|
||||
}
|
||||
|
||||
expansions
|
||||
.sort(plugin.getPlaceholderAPIConfig().getExpansionSort().orElse(ExpansionSort.LATEST));
|
||||
|
||||
if (!(sender instanceof Player) && params.size() < 2) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
addExpansionTitle(builder, params.get(0), -1);
|
||||
addExpansionTable(expansions,
|
||||
builder,
|
||||
1,
|
||||
installed ? "&9Version" : "&9Latest Version",
|
||||
installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
final int page;
|
||||
|
||||
if (params.size() < 2) {
|
||||
page = 1;
|
||||
if (expansion.shouldUpdate()) {
|
||||
expansionColour = GOLD;
|
||||
} else {
|
||||
if (expansion.hasExpansion()) {
|
||||
expansionColour = GREEN;
|
||||
} else {
|
||||
//noinspection UnstableApiUsage
|
||||
final Integer parsed = Ints.tryParse(params.get(1));
|
||||
if (parsed == null) {
|
||||
Msg.msg(sender,
|
||||
"&cPage number must be an integer.");
|
||||
return;
|
||||
}
|
||||
|
||||
final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
|
||||
|
||||
if (parsed < 1 || parsed > limit) {
|
||||
Msg.msg(sender,
|
||||
"&cPage number must be in the range &8[&a1&7..&a" + limit + "&8]");
|
||||
return;
|
||||
}
|
||||
|
||||
page = parsed;
|
||||
expansionColour = GRAY;
|
||||
}
|
||||
}
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final List<CloudExpansion> values = getPage(expansions, page - 1);
|
||||
line.append(text(expansion.getName(), expansionColour));
|
||||
|
||||
addExpansionTitle(builder, params.get(0), page);
|
||||
line.clickEvent(ClickEvent.suggestCommand("/papi ecloud download " + expansion.getName()));
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
addExpansionTable(values,
|
||||
builder,
|
||||
((page - 1) * PAGE_SIZE) + 1,
|
||||
installed ? "&9Version" : "&9Latest Version",
|
||||
installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
|
||||
final TextComponent.Builder hoverText = text("Click to download this expansion!", AQUA)
|
||||
.append(newline()).append(newline())
|
||||
.append(text("Author: ", AQUA)).append(text(expansion.getAuthor(), WHITE))
|
||||
.append(newline())
|
||||
.append(text("Verified: ", AQUA)).append(text(expansion.isVerified() ? "✔" : "❌", expansion.isVerified() ? GREEN : RED, TextDecoration.BOLD))
|
||||
.append(newline())
|
||||
.append(text("Released: ", AQUA)).append(text(format.format(expansion.getLastUpdate()), WHITE))
|
||||
.toBuilder();
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
Optional.ofNullable(expansion.getDescription())
|
||||
.filter(description -> !description.isEmpty())
|
||||
.ifPresent(description -> hoverText.append(newline()).append(newline())
|
||||
.append(text(description.replace("\r", "").trim(), WHITE))
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
line.hoverEvent(HoverEvent.showText(hoverText.build()));
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
if (index != expansions.size() - 1) {
|
||||
line.append(newline());
|
||||
}
|
||||
|
||||
final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
|
||||
|
||||
final Component message = getMessage(values, page, limit, params.get(0));
|
||||
plugin.getAdventure().player((Player) sender).sendMessage(message);
|
||||
message.append(line.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 2) {
|
||||
return;
|
||||
}
|
||||
if (limit > 1) {
|
||||
message.append(newline());
|
||||
|
||||
if (params.size() <= 1) {
|
||||
suggestByParameter(
|
||||
Sets.union(OPTIONS, plugin.getCloudExpansionManager().getCloudExpansionAuthors())
|
||||
.stream(), suggestions, params.isEmpty() ? null : params.get(0));
|
||||
return;
|
||||
}
|
||||
final TextComponent.Builder left = text("â—€", page > 1 ? GRAY : DARK_GRAY).toBuilder();
|
||||
|
||||
suggestByParameter(IntStream.rangeClosed(1,
|
||||
(int) Math.ceil((double) getExpansions(params.get(0), plugin).size() / PAGE_SIZE))
|
||||
.mapToObj(Objects::toString), suggestions, params.get(1));
|
||||
if (page > 1) {
|
||||
left.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page - 1)));
|
||||
}
|
||||
|
||||
final TextComponent.Builder right = text("â–¶", page < limit ? GRAY : DARK_GRAY).toBuilder();
|
||||
|
||||
if (page < limit) {
|
||||
right.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page + 1)));
|
||||
}
|
||||
|
||||
message.append(left, text(" " + page + " ", GREEN), right);
|
||||
}
|
||||
|
||||
return message.build();
|
||||
}
|
||||
|
||||
private static void addExpansionTable(@NotNull final List<CloudExpansion> expansions,
|
||||
@NotNull final StringBuilder message, final int startIndex,
|
||||
@NotNull final String versionTitle,
|
||||
@NotNull final Function<CloudExpansion, Object> versionFunction) {
|
||||
final Map<String, Function<CloudExpansion, Object>> functions = new LinkedHashMap<>();
|
||||
|
||||
final AtomicInteger counter = new AtomicInteger(startIndex);
|
||||
functions.put("&f", expansion -> "&8" + counter.getAndIncrement() + ".");
|
||||
|
||||
functions.put("&9Name", EXPANSION_NAME);
|
||||
functions.put("&9Author", EXPANSION_AUTHOR);
|
||||
functions.put("&9Verified", EXPANSION_VERIFIED);
|
||||
functions.put(versionTitle, versionFunction);
|
||||
|
||||
final List<List<String>> rows = new ArrayList<>();
|
||||
|
||||
rows.add(0, new ArrayList<>(functions.keySet()));
|
||||
|
||||
for (final CloudExpansion expansion : expansions) {
|
||||
rows.add(functions.values().stream().map(function -> function.apply(expansion))
|
||||
.map(Objects::toString).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
final List<String> table = Format.tablify(Format.Align.LEFT, rows)
|
||||
.orElse(Collections.emptyList());
|
||||
if (table.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
table.add(1, "&8" + Strings.repeat("-", table.get(0).length() - (rows.get(0).size() * 2)));
|
||||
|
||||
message.append(String.join("\n", table));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify an option. [all, {author}, installed]");
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean installed = params.get(0).equalsIgnoreCase("installed");
|
||||
final List<CloudExpansion> expansions = Lists
|
||||
.newArrayList(getExpansions(params.get(0), plugin));
|
||||
|
||||
if (expansions.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cNo expansions available to list.");
|
||||
return;
|
||||
}
|
||||
|
||||
expansions
|
||||
.sort(plugin.getPlaceholderAPIConfig().getExpansionSort().orElse(ExpansionSort.LATEST));
|
||||
|
||||
if (!(sender instanceof Player) && params.size() < 2) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
addExpansionTitle(builder, params.get(0), -1);
|
||||
addExpansionTable(expansions,
|
||||
builder,
|
||||
1,
|
||||
installed ? "&9Version" : "&9Latest Version",
|
||||
installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
final int page;
|
||||
|
||||
if (params.size() < 2) {
|
||||
page = 1;
|
||||
} else {
|
||||
//noinspection UnstableApiUsage
|
||||
final Integer parsed = Ints.tryParse(params.get(1));
|
||||
if (parsed == null) {
|
||||
Msg.msg(sender,
|
||||
"&cPage number must be an integer.");
|
||||
return;
|
||||
}
|
||||
|
||||
final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
|
||||
|
||||
if (parsed < 1 || parsed > limit) {
|
||||
Msg.msg(sender,
|
||||
"&cPage number must be in the range &8[&a1&7..&a" + limit + "&8]");
|
||||
return;
|
||||
}
|
||||
|
||||
page = parsed;
|
||||
}
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final List<CloudExpansion> values = getPage(expansions, page - 1);
|
||||
|
||||
addExpansionTitle(builder, params.get(0), page);
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
addExpansionTable(values,
|
||||
builder,
|
||||
((page - 1) * PAGE_SIZE) + 1,
|
||||
installed ? "&9Version" : "&9Latest Version",
|
||||
installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
|
||||
final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
|
||||
|
||||
final Component message = getMessage(values, page, limit, params.get(0));
|
||||
plugin.getAdventure().player((Player) sender).sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.size() <= 1) {
|
||||
suggestByParameter(
|
||||
Sets.union(OPTIONS, plugin.getCloudExpansionManager().getCloudExpansionAuthors())
|
||||
.stream(), suggestions, params.isEmpty() ? null : params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(IntStream.rangeClosed(1,
|
||||
(int) Math.ceil((double) getExpansions(params.get(0), plugin).size() / PAGE_SIZE))
|
||||
.mapToObj(Objects::toString), suggestions, params.get(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,11 +21,9 @@
|
||||
package me.clip.placeholderapi.commands.impl.cloud;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
@@ -36,61 +34,61 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandECloudExpansionPlaceholders extends PlaceholderCommand {
|
||||
|
||||
public CommandECloudExpansionPlaceholders() {
|
||||
super("placeholders");
|
||||
public CommandECloudExpansionPlaceholders() {
|
||||
super("placeholders");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of the expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of the expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
final CloudExpansion expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0)).orElse(null);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender,
|
||||
"&cThere is no expansion with the name: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
final List<String> placeholders = expansion.getPlaceholders();
|
||||
if (placeholders == null || placeholders.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cThe expansion specified does not have placeholders listed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<List<String>> partitions = Lists
|
||||
.partition(placeholders.stream().sorted().collect(Collectors.toList()), 10);
|
||||
|
||||
Msg.msg(sender,
|
||||
"&6" + placeholders.size() + "&7 placeholders: &a",
|
||||
partitions.stream().map(partition -> String.join(", ", partition))
|
||||
.collect(Collectors.joining("\n")));
|
||||
|
||||
final CloudExpansion expansion = plugin.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(params.get(0)).orElse(null);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender,
|
||||
"&cThere is no expansion with the name: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Stream<String> names = plugin.getCloudExpansionManager()
|
||||
.getCloudExpansions()
|
||||
.values()
|
||||
.stream()
|
||||
.map(CloudExpansion::getName)
|
||||
.map(name -> name.replace(' ', '_'));
|
||||
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
final List<String> placeholders = expansion.getPlaceholders();
|
||||
if (placeholders == null || placeholders.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cThe expansion specified does not have placeholders listed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<List<String>> partitions = Lists
|
||||
.partition(placeholders.stream().sorted().collect(Collectors.toList()), 10);
|
||||
|
||||
Msg.msg(sender,
|
||||
"&6" + placeholders.size() + "&7 placeholders: &a",
|
||||
partitions.stream().map(partition -> String.join(", ", partition))
|
||||
.collect(Collectors.joining("\n")));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Stream<String> names = plugin.getCloudExpansionManager()
|
||||
.getCloudExpansions()
|
||||
.values()
|
||||
.stream()
|
||||
.map(CloudExpansion::getName)
|
||||
.map(name -> name.replace(' ', '_'));
|
||||
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.commands.impl.cloud;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
@@ -31,18 +30,20 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandECloudRefresh extends PlaceholderCommand {
|
||||
|
||||
public CommandECloudRefresh() {
|
||||
super("refresh");
|
||||
}
|
||||
public CommandECloudRefresh() {
|
||||
super("refresh");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
plugin.getCloudExpansionManager().load();
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
plugin.getCloudExpansionManager().clean();
|
||||
plugin.getCloudExpansionManager()
|
||||
.fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
|
||||
Msg.msg(sender,
|
||||
"&aThe eCloud manager has been refreshed!");
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&aThe eCloud manager has been refreshed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.commands.impl.cloud;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.expansion.manager.CloudExpansionManager;
|
||||
@@ -32,34 +31,34 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandECloudStatus extends PlaceholderCommand {
|
||||
|
||||
public CommandECloudStatus() {
|
||||
super("status");
|
||||
public CommandECloudStatus() {
|
||||
super("status");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final CloudExpansionManager manager = plugin.getCloudExpansionManager();
|
||||
|
||||
final int updateCount = manager.getCloudUpdateCount();
|
||||
final int authorCount = manager.getCloudExpansionAuthorCount();
|
||||
final int expansionCount = manager.getCloudExpansions().size();
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("&bThere are &a").append(expansionCount)
|
||||
.append("&b expansions available on the eCloud.").append('\n');
|
||||
builder.append("&7A total of &f").append(authorCount)
|
||||
.append("&7 authors have contributed to the eCloud.").append('\n');
|
||||
|
||||
if (updateCount > 0) {
|
||||
builder.append("&eYou have &f").append(updateCount)
|
||||
.append(updateCount > 1 ? "&e expansions" : "&e expansion").append("installed that ")
|
||||
.append(updateCount > 1 ? "have an" : "has an").append(" update available.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final CloudExpansionManager manager = plugin.getCloudExpansionManager();
|
||||
|
||||
final int updateCount = manager.getCloudUpdateCount();
|
||||
final int authorCount = manager.getCloudExpansionAuthorCount();
|
||||
final int expansionCount = manager.getCloudExpansions().size();
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("&bThere are &a").append(expansionCount)
|
||||
.append("&b expansions available on the eCloud.").append('\n');
|
||||
builder.append("&7A total of &f").append(authorCount)
|
||||
.append("&7 authors have contributed to the eCloud.").append('\n');
|
||||
|
||||
if (updateCount > 0) {
|
||||
builder.append("&eYou have &f").append(updateCount)
|
||||
.append(updateCount > 1 ? "&e expansions" : "&e expansion").append(" installed that ")
|
||||
.append(updateCount > 1 ? "have an" : "has an").append(" update available.");
|
||||
}
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
}
|
||||
Msg.msg(sender, builder.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI 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.
|
||||
*
|
||||
* PlaceholderAPI 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.commands.impl.cloud;
|
||||
|
||||
import java.util.List;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandECloudToggle extends PlaceholderCommand {
|
||||
|
||||
public CommandECloudToggle() {
|
||||
super("toggle", "enable", "disable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final boolean desiredState;
|
||||
final boolean currentState = plugin.getPlaceholderAPIConfig().isCloudEnabled();
|
||||
|
||||
switch (alias.toLowerCase()) {
|
||||
case "enable":
|
||||
desiredState = true;
|
||||
break;
|
||||
case "disable":
|
||||
desiredState = false;
|
||||
break;
|
||||
default:
|
||||
desiredState = !currentState;
|
||||
break;
|
||||
}
|
||||
|
||||
if (desiredState == currentState) {
|
||||
Msg.msg(sender, "&7The eCloud Manager is already " + (desiredState ? "enabled" : "disabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(desiredState);
|
||||
|
||||
if (desiredState) {
|
||||
plugin.getCloudExpansionManager().load();
|
||||
} else {
|
||||
plugin.getCloudExpansionManager().kill();
|
||||
}
|
||||
|
||||
Msg.msg(sender, "&aThe eCloud Manager has been " + (desiredState ? "enabled" : "disabled"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,15 +21,12 @@
|
||||
package me.clip.placeholderapi.commands.impl.cloud;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
@@ -46,98 +43,98 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
*/
|
||||
public final class CommandECloudUpdate extends PlaceholderCommand {
|
||||
|
||||
public CommandECloudUpdate() {
|
||||
super("update");
|
||||
public CommandECloudUpdate() {
|
||||
super("update");
|
||||
}
|
||||
|
||||
private static CompletableFuture<List<@Nullable Class<? extends PlaceholderExpansion>>> downloadAndDiscover(
|
||||
@NotNull final List<CloudExpansion> expansions, @NotNull final PlaceholderAPIPlugin plugin) {
|
||||
return expansions.stream()
|
||||
.map(expansion -> plugin.getCloudExpansionManager()
|
||||
.downloadExpansion(expansion, expansion.getVersion()))
|
||||
.map(future -> future.thenCompose(plugin.getLocalExpansionManager()::findExpansionInFile))
|
||||
.collect(Futures.collector());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must define 'all' or the name of an expansion to update.");
|
||||
return;
|
||||
}
|
||||
|
||||
private static CompletableFuture<List<@Nullable Class<? extends PlaceholderExpansion>>> downloadAndDiscover(
|
||||
@NotNull final List<CloudExpansion> expansions, @NotNull final PlaceholderAPIPlugin plugin) {
|
||||
return expansions.stream()
|
||||
.map(expansion -> plugin.getCloudExpansionManager()
|
||||
.downloadExpansion(expansion, expansion.getVersion()))
|
||||
.map(future -> future.thenCompose(plugin.getLocalExpansionManager()::findExpansionInFile))
|
||||
.collect(Futures.collector());
|
||||
final boolean multiple = params.get(0).equalsIgnoreCase("all");
|
||||
final List<CloudExpansion> expansions = new ArrayList<>();
|
||||
|
||||
// gather target expansions
|
||||
if (multiple) {
|
||||
expansions.addAll(plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values());
|
||||
} else {
|
||||
plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0))
|
||||
.ifPresent(expansions::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must define 'all' or the name of an expansion to update.");
|
||||
return;
|
||||
}
|
||||
// remove the ones that are the latest version
|
||||
expansions.removeIf(expansion -> !expansion.shouldUpdate());
|
||||
|
||||
final boolean multiple = params.get(0).equalsIgnoreCase("all");
|
||||
final List<CloudExpansion> expansions = new ArrayList<>();
|
||||
if (expansions.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cNo updates available for " + (!multiple ? "this expansion."
|
||||
: "your active expansions."));
|
||||
return;
|
||||
}
|
||||
|
||||
// gather target expansions
|
||||
if (multiple) {
|
||||
expansions.addAll(plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values());
|
||||
} else {
|
||||
plugin.getCloudExpansionManager().findCloudExpansionByName(params.get(0))
|
||||
.ifPresent(expansions::add);
|
||||
}
|
||||
|
||||
// remove the ones that are the latest version
|
||||
expansions.removeIf(expansion -> !expansion.shouldUpdate());
|
||||
|
||||
if (expansions.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cNo updates available for " + (!multiple ? "this expansion."
|
||||
: "your active expansions."));
|
||||
return;
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&aUpdating expansions: " + expansions.stream().map(CloudExpansion::getName)
|
||||
.collect(Collectors.joining("&7, &6", "&8[&6", "&8]&r")));
|
||||
|
||||
Futures.onMainThread(plugin, downloadAndDiscover(expansions, plugin), (classes, exception) -> {
|
||||
if (exception != null) {
|
||||
Msg.msg(sender,
|
||||
"&aUpdating expansions: " + expansions.stream().map(CloudExpansion::getName)
|
||||
.collect(Collectors.joining("&7, &6", "&8[&6", "&8]&r")));
|
||||
"&cFailed to update expansions: &e" + exception.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
Futures.onMainThread(plugin, downloadAndDiscover(expansions, plugin), (classes, exception) -> {
|
||||
if (exception != null) {
|
||||
Msg.msg(sender,
|
||||
"&cFailed to update expansions: &e" + exception.getMessage());
|
||||
return;
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&aSuccessfully downloaded updates, registering new versions.");
|
||||
|
||||
Msg.msg(sender,
|
||||
"&aSuccessfully downloaded updates, registering new versions.");
|
||||
final String message = classes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(plugin.getLocalExpansionManager()::register)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(expansion -> " &a" + expansion.getName() + " &f" + expansion.getVersion())
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
final String message = classes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(plugin.getLocalExpansionManager()::register)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(expansion -> " &a" + expansion.getName() + " &f" + expansion.getVersion())
|
||||
.collect(Collectors.joining("\n"));
|
||||
Msg.msg(sender,
|
||||
"&7Registered expansions:", message);
|
||||
|
||||
Msg.msg(sender,
|
||||
"&7Registered expansions:", message);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
final List<CloudExpansion> installed = Lists
|
||||
.newArrayList(plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values());
|
||||
installed.removeIf(expansion -> !expansion.shouldUpdate());
|
||||
|
||||
final List<CloudExpansion> installed = Lists
|
||||
.newArrayList(plugin.getCloudExpansionManager().getCloudExpansionsInstalled().values());
|
||||
installed.removeIf(expansion -> !expansion.shouldUpdate());
|
||||
|
||||
if (!installed.isEmpty() && (params.isEmpty() || "all"
|
||||
.startsWith(params.get(0).toLowerCase(Locale.ROOT)))) {
|
||||
suggestions.add("all");
|
||||
}
|
||||
|
||||
suggestByParameter(
|
||||
installed.stream().map(CloudExpansion::getName).map(name -> name.replace(" ", "_")),
|
||||
suggestions, params.isEmpty() ? null : params.get(0));
|
||||
if (!installed.isEmpty() && (params.isEmpty() || "all"
|
||||
.startsWith(params.get(0).toLowerCase()))) {
|
||||
suggestions.add("all");
|
||||
}
|
||||
|
||||
suggestByParameter(
|
||||
installed.stream().map(CloudExpansion::getName).map(name -> name.replace(" ", "_")),
|
||||
suggestions, params.isEmpty() ? null : params.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -54,160 +54,160 @@ import java.util.stream.Collectors;
|
||||
|
||||
public final class CommandDump extends PlaceholderCommand {
|
||||
|
||||
@NotNull
|
||||
private static final String URL = "https://paste.helpch.at/";
|
||||
@NotNull
|
||||
private static final String URL = "https://paste.helpch.at/";
|
||||
|
||||
@NotNull
|
||||
private static final Gson gson = new Gson();
|
||||
@NotNull
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
@NotNull
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
||||
.ofLocalizedDateTime(FormatStyle.LONG)
|
||||
.withLocale(Locale.US)
|
||||
.withZone(ZoneId.of("UTC"));
|
||||
@NotNull
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
||||
.ofLocalizedDateTime(FormatStyle.LONG)
|
||||
.withLocale(Locale.US)
|
||||
.withZone(ZoneId.of("UTC"));
|
||||
|
||||
|
||||
public CommandDump() {
|
||||
super("dump");
|
||||
}
|
||||
public CommandDump() {
|
||||
super("dump");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
postDump(makeDump(plugin)).whenComplete((key, exception) -> {
|
||||
if (exception != null) {
|
||||
plugin.getLogger().log(Level.WARNING, "failed to post dump details", exception);
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
postDump(makeDump(plugin)).whenComplete((key, exception) -> {
|
||||
if (exception != null) {
|
||||
plugin.getLogger().log(Level.WARNING, "failed to post dump details", exception);
|
||||
|
||||
Msg.msg(sender,
|
||||
"&cFailed to post dump details, check console.");
|
||||
return;
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&cFailed to post dump details, check console.");
|
||||
return;
|
||||
}
|
||||
|
||||
Msg.msg(sender,
|
||||
"&aSuccessfully posted dump: " + URL + key);
|
||||
});
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&aSuccessfully posted dump: " + URL + key);
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private CompletableFuture<String> postDump(@NotNull final String dump) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
final HttpURLConnection connection = ((HttpURLConnection) new URL(URL + "documents")
|
||||
.openConnection());
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
|
||||
connection.setDoOutput(true);
|
||||
@NotNull
|
||||
private CompletableFuture<String> postDump(@NotNull final String dump) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
final HttpURLConnection connection = ((HttpURLConnection) new URL(URL + "documents")
|
||||
.openConnection());
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
|
||||
connection.setDoOutput(true);
|
||||
|
||||
connection.connect();
|
||||
|
||||
try (final OutputStream stream = connection.getOutputStream()) {
|
||||
stream.write(dump.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
try (final InputStream stream = connection.getInputStream()) {
|
||||
final String json = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8));
|
||||
return gson.fromJson(json, JsonObject.class).get("key").getAsString();
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
throw new CompletionException(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String makeDump(@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("Generated: ")
|
||||
.append(DATE_FORMAT.format(Instant.now()))
|
||||
.append("\n\n");
|
||||
|
||||
builder.append("PlaceholderAPI: ")
|
||||
.append(plugin.getDescription().getVersion())
|
||||
.append("\n\n");
|
||||
|
||||
builder.append("Expansions Registered:")
|
||||
.append('\n');
|
||||
|
||||
final List<PlaceholderExpansion> expansions = plugin.getLocalExpansionManager()
|
||||
.getExpansions()
|
||||
.stream()
|
||||
.sorted(
|
||||
Comparator.comparing(PlaceholderExpansion::getIdentifier)
|
||||
.thenComparing(PlaceholderExpansion::getAuthor)
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
int size = expansions.stream().map(e -> e.getIdentifier().length())
|
||||
.max(Integer::compareTo)
|
||||
.orElse(0);
|
||||
|
||||
for (final PlaceholderExpansion expansion : expansions) {
|
||||
builder.append(" ")
|
||||
.append(String.format("%-" + size + "s", expansion.getIdentifier()))
|
||||
.append(" [Author: ")
|
||||
.append(expansion.getAuthor())
|
||||
.append(", Version: ")
|
||||
.append(expansion.getVersion())
|
||||
.append("]\n");
|
||||
connection.connect();
|
||||
|
||||
try (final OutputStream stream = connection.getOutputStream()) {
|
||||
stream.write(dump.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
builder.append('\n');
|
||||
|
||||
builder.append("Expansions Directory:")
|
||||
.append('\n');
|
||||
|
||||
final String[] jars = plugin.getLocalExpansionManager()
|
||||
.getExpansionsFolder()
|
||||
.list((dir, name) -> name.toLowerCase(Locale.ROOT).endsWith(".jar"));
|
||||
|
||||
|
||||
if (jars == null) {
|
||||
builder.append(" ¨[Warning]: Could not load jar files from expansions folder.");
|
||||
} else {
|
||||
for (final String jar : jars) {
|
||||
builder.append(" ")
|
||||
.append(jar)
|
||||
.append('\n');
|
||||
}
|
||||
try (final InputStream stream = connection.getInputStream()) {
|
||||
//noinspection UnstableApiUsage
|
||||
final String json = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8));
|
||||
return gson.fromJson(json, JsonObject.class).get("key").getAsString();
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
throw new CompletionException(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
builder.append('\n');
|
||||
@NotNull
|
||||
private String makeDump(@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("Server Info: ")
|
||||
.append(plugin.getServer().getBukkitVersion())
|
||||
.append('/')
|
||||
.append(plugin.getServer().getVersion())
|
||||
.append("\n");
|
||||
builder.append("Generated: ")
|
||||
.append(DATE_FORMAT.format(Instant.now()))
|
||||
.append("\n\n");
|
||||
|
||||
builder.append("Java Version: ")
|
||||
.append(System.getProperty("java.version"))
|
||||
.append("\n\n");
|
||||
builder.append("PlaceholderAPI: ")
|
||||
.append(plugin.getDescription().getVersion())
|
||||
.append("\n\n");
|
||||
|
||||
builder.append("Plugin Info:")
|
||||
.append('\n');
|
||||
builder.append("Expansions Registered:")
|
||||
.append('\n');
|
||||
|
||||
List<Plugin> plugins = Arrays.stream(plugin.getServer().getPluginManager().getPlugins())
|
||||
.sorted(Comparator.comparing(Plugin::getName))
|
||||
.collect(Collectors.toList());
|
||||
final List<PlaceholderExpansion> expansions = plugin.getLocalExpansionManager()
|
||||
.getExpansions()
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(PlaceholderExpansion::getIdentifier))
|
||||
.sorted(Comparator.comparing(PlaceholderExpansion::getAuthor))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
size = plugins.stream().map(pl -> pl.getName().length())
|
||||
.max(Integer::compareTo)
|
||||
.orElse(0);
|
||||
int size = 0;
|
||||
|
||||
for (final Plugin other : plugins) {
|
||||
builder.append(" ")
|
||||
.append(String.format("%-" + size + "s", other.getName()))
|
||||
.append(" [Authors: [")
|
||||
.append(String.join(", ", other.getDescription().getAuthors()))
|
||||
.append("], Version: ")
|
||||
.append(other.getDescription().getVersion())
|
||||
.append("]")
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
for (final String name : expansions.stream().map(PlaceholderExpansion::getIdentifier)
|
||||
.collect(Collectors.toList())) {
|
||||
if (name.length() > size) {
|
||||
size = name.length();
|
||||
}
|
||||
}
|
||||
|
||||
for (final PlaceholderExpansion expansion : expansions) {
|
||||
builder.append(" ")
|
||||
.append(String.format("%-" + size + "s", expansion.getIdentifier()))
|
||||
.append(" [Author: ")
|
||||
.append(expansion.getAuthor())
|
||||
.append(", Version: ")
|
||||
.append(expansion.getVersion())
|
||||
.append("]\n");
|
||||
|
||||
}
|
||||
|
||||
builder.append('\n');
|
||||
|
||||
builder.append("Expansions Directory:")
|
||||
.append('\n');
|
||||
|
||||
final String[] jars = plugin.getLocalExpansionManager()
|
||||
.getExpansionsFolder()
|
||||
.list((dir, name) -> name.toLowerCase().endsWith(".jar"));
|
||||
|
||||
for (final String jar : jars) {
|
||||
builder.append(" ")
|
||||
.append(jar)
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
builder.append('\n');
|
||||
|
||||
builder.append("Server Info: ")
|
||||
.append(plugin.getServer().getBukkitVersion())
|
||||
.append('/')
|
||||
.append(plugin.getServer().getVersion())
|
||||
.append("\n");
|
||||
|
||||
builder.append("Java Version: ")
|
||||
.append(System.getProperty("java.version"))
|
||||
.append("\n\n");
|
||||
|
||||
builder.append("Plugin Info:")
|
||||
.append('\n');
|
||||
|
||||
List<Plugin> plugins = Arrays.stream(plugin.getServer().getPluginManager().getPlugins())
|
||||
.sorted(Comparator.comparing(Plugin::getName))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (final String pluginName : plugins.stream().map(Plugin::getName)
|
||||
.collect(Collectors.toList())) {
|
||||
if (pluginName.length() > size) {
|
||||
size = pluginName.length();
|
||||
}
|
||||
}
|
||||
|
||||
for (final Plugin other : plugins) {
|
||||
builder.append(" ")
|
||||
.append(String.format("%-" + size + "s", other.getName()))
|
||||
.append(" [Version: ")
|
||||
.append(other.getDescription().getVersion())
|
||||
.append("]")
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -25,7 +25,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
@@ -38,74 +37,74 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandExpansionRegister extends PlaceholderCommand {
|
||||
|
||||
public CommandExpansionRegister() {
|
||||
super("register");
|
||||
public CommandExpansionRegister() {
|
||||
super("register");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.size() < 1) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of an expansion file.");
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.size() < 1) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of an expansion file.");
|
||||
return;
|
||||
}
|
||||
final LocalExpansionManager manager = plugin.getLocalExpansionManager();
|
||||
|
||||
final LocalExpansionManager manager = plugin.getLocalExpansionManager();
|
||||
|
||||
final File file = new File(manager.getExpansionsFolder(), params.get(0));
|
||||
if (!file.exists() || !file.getParentFile().equals(manager.getExpansionsFolder())) {
|
||||
Msg.msg(sender,
|
||||
"&cThe file &f" + file.getName() + "&c doesn't exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
Futures.onMainThread(plugin, manager.findExpansionInFile(file), (clazz, exception) -> {
|
||||
if (exception != null) {
|
||||
Msg.msg(sender,
|
||||
"&cFailed to find expansion in file: &f" + file);
|
||||
|
||||
plugin.getLogger()
|
||||
.log(Level.WARNING, "failed to find expansion in file: " + file, exception);
|
||||
return;
|
||||
}
|
||||
|
||||
if (clazz == null) {
|
||||
Msg.msg(sender,
|
||||
"&cNo expansion class found in file: &f" + file);
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<PlaceholderExpansion> expansion = manager.register(clazz);
|
||||
if (!expansion.isPresent()) {
|
||||
Msg.msg(sender,
|
||||
"&cFailed to register expansion from &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
Msg.msg(sender,
|
||||
"&aSuccessfully registered expansion: &f" + expansion.get().getName());
|
||||
|
||||
});
|
||||
final File file = new File(manager.getExpansionsFolder(), params.get(0));
|
||||
if (!file.exists()) {
|
||||
Msg.msg(sender,
|
||||
"&cThe file &f" + file.getName() + "&c doesn't exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
Futures.onMainThread(plugin, manager.findExpansionInFile(file), (clazz, exception) -> {
|
||||
if (exception != null) {
|
||||
Msg.msg(sender,
|
||||
"&cFailed to find expansion in file: &f" + file);
|
||||
|
||||
final String[] fileNames = plugin.getLocalExpansionManager().getExpansionsFolder()
|
||||
.list((dir, name) -> name.endsWith(".jar"));
|
||||
if (fileNames == null || fileNames.length == 0) {
|
||||
return;
|
||||
}
|
||||
plugin.getLogger()
|
||||
.log(Level.WARNING, "failed to find expansion in file: " + file, exception);
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(Arrays.stream(fileNames), suggestions,
|
||||
params.isEmpty() ? null : params.get(0));
|
||||
if (clazz == null) {
|
||||
Msg.msg(sender,
|
||||
"&cNo expansion class found in file: &f" + file);
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<PlaceholderExpansion> expansion = manager.register(clazz);
|
||||
if (!expansion.isPresent()) {
|
||||
Msg.msg(sender,
|
||||
"&cFailed to register expansion from &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
Msg.msg(sender,
|
||||
"&aSuccessfully registered expansion: &f" + expansion.get().getName());
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String[] fileNames = plugin.getLocalExpansionManager().getExpansionsFolder()
|
||||
.list((dir, name) -> name.endsWith(".jar"));
|
||||
if (fileNames == null || fileNames.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(Arrays.stream(fileNames), suggestions,
|
||||
params.isEmpty() ? null : params.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -22,7 +22,6 @@ package me.clip.placeholderapi.commands.impl.local;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
@@ -34,45 +33,45 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandExpansionUnregister extends PlaceholderCommand {
|
||||
|
||||
public CommandExpansionUnregister() {
|
||||
super("unregister");
|
||||
public CommandExpansionUnregister() {
|
||||
super("unregister");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of the expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of the expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<PlaceholderExpansion> expansion = plugin.getLocalExpansionManager()
|
||||
.findExpansionByName(params.get(0));
|
||||
if (!expansion.isPresent()) {
|
||||
Msg.msg(sender,
|
||||
"&cThere is no expansion loaded with the identifier: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
final String message = !expansion.get().unregister() ?
|
||||
"&cFailed to unregister expansion: &f" :
|
||||
"&aSuccessfully unregistered expansion: &f";
|
||||
|
||||
Msg.msg(sender, message + expansion.get().getName());
|
||||
final Optional<PlaceholderExpansion> expansion = plugin.getLocalExpansionManager()
|
||||
.findExpansionByName(params.get(0));
|
||||
if (!expansion.isPresent()) {
|
||||
Msg.msg(sender,
|
||||
"&cThere is no expansion loaded with the identifier: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
final String message = !expansion.get().unregister() ?
|
||||
"&cFailed to unregister expansion: &f" :
|
||||
"&aSuccessfully unregistered expansion: &f";
|
||||
|
||||
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions,
|
||||
params.isEmpty() ? null : params.get(0));
|
||||
Msg.msg(sender, message + expansion.get().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions,
|
||||
params.isEmpty() ? null : params.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.commands.impl.local;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
@@ -32,42 +31,42 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandHelp extends PlaceholderCommand {
|
||||
|
||||
public CommandHelp() {
|
||||
super("help");
|
||||
}
|
||||
public CommandHelp() {
|
||||
super("help");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final PluginDescriptionFile description = plugin.getDescription();
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final PluginDescriptionFile description = plugin.getDescription();
|
||||
|
||||
Msg.msg(sender,
|
||||
"&b&lPlaceholderAPI &8- &7Help Menu &8- &7(&f" + description.getVersion() + "&7)",
|
||||
" ",
|
||||
"&b/papi &fbcparse &9<me|--null|player name> <message>",
|
||||
" &7&oParse a message with placeholders and broadcast it",
|
||||
"&b/papi &fcmdparse &9<me|player> <command with placeholders>",
|
||||
" &7&oParse a message with relational placeholders",
|
||||
"&b/papi &fdump",
|
||||
" &7&oDump all relevant information needed to help debug issues into a paste link.",
|
||||
"&b/papi &finfo &9<placeholder name>",
|
||||
" &7&oView information for a specific expansion",
|
||||
"&b/papi &flist",
|
||||
" &7&oList active expansions",
|
||||
"&b/papi &fparse &9<me|--null|player name> <message>",
|
||||
" &7&oParse a message with placeholders",
|
||||
"&b/papi &fparserel &9<player one> <player two> <message>",
|
||||
" &7&oParse a message with relational placeholders",
|
||||
"&b/papi &fregister &9<file name>",
|
||||
" &7&oRegister an expansion by the name of the file",
|
||||
"&b/papi &freload",
|
||||
" &7&oReload the config of PAPI",
|
||||
"&b/papi &funregister &9<expansion name>",
|
||||
" &7&oUnregister an expansion by name",
|
||||
"&b/papi &fversion",
|
||||
" &7&oView plugin info/version");
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&b&lPlaceholderAPI &8- &7Help Menu &8- &7(&f" + description.getVersion() + "&7)",
|
||||
" ",
|
||||
"&b/papi &fbcparse &9<me/player name> <message>",
|
||||
" &7&oParse a message with placeholders and broadcast it",
|
||||
"&b/papi &fcmdparse &9<me/player> <command with placeholders>",
|
||||
" &7&oParse a message with relational placeholders",
|
||||
"&b/papi &fdump",
|
||||
" &7&oDump all relevant information needed to help debug issues into a paste link.",
|
||||
"&b/papi &finfo &9<placeholder name>",
|
||||
" &7&oView information for a specific expansion",
|
||||
"&b/papi &flist",
|
||||
" &7&oList active expansions",
|
||||
"&b/papi &fparse &9<me/player name> <message>",
|
||||
" &7&oParse a message with placeholders",
|
||||
"&b/papi &fparserel &9<player one> <player two> <message>",
|
||||
" &7&oParse a message with relational placeholders",
|
||||
"&b/papi &fregister &9<file name>",
|
||||
" &7&oRegister an expansion by the name of the file",
|
||||
"&b/papi &freload",
|
||||
" &7&oReload the config of PAPI",
|
||||
"&b/papi &funregister &9<expansion name>",
|
||||
" &7&oUnregister an expansion by name",
|
||||
"&b/papi &fversion",
|
||||
" &7&oView plugin info/version");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.commands.impl.local;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
@@ -33,82 +32,82 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandInfo extends PlaceholderCommand {
|
||||
|
||||
public CommandInfo() {
|
||||
super("info");
|
||||
public CommandInfo() {
|
||||
super("info");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of the expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.isEmpty()) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must specify the name of the expansion.");
|
||||
return;
|
||||
}
|
||||
|
||||
final PlaceholderExpansion expansion = plugin.getLocalExpansionManager()
|
||||
.findExpansionByIdentifier(params.get(0)).orElse(null);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender,
|
||||
"&cThere is no expansion loaded with the identifier: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("&7Placeholder expansion info for: &r")
|
||||
.append(expansion.getName())
|
||||
.append('\n')
|
||||
.append("&7Status: &r")
|
||||
.append(expansion.isRegistered() ? "&aRegistered" : "7cNotRegistered")
|
||||
.append('\n');
|
||||
|
||||
final String author = expansion.getAuthor();
|
||||
if (author != null) {
|
||||
builder.append("&7Author: &r")
|
||||
.append(author)
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
final String version = expansion.getVersion();
|
||||
if (version != null) {
|
||||
builder.append("&7Version: &r")
|
||||
.append(version)
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
final String requiredPlugin = expansion.getRequiredPlugin();
|
||||
if (requiredPlugin != null) {
|
||||
builder.append("&7Requires plugin: &r")
|
||||
.append(requiredPlugin)
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
final List<String> placeholders = expansion.getPlaceholders();
|
||||
if (placeholders != null && !placeholders.isEmpty()) {
|
||||
builder.append("&8&m-- &7Placeholders &8&m--&r")
|
||||
.append('\n');
|
||||
|
||||
for (final String placeholder : placeholders) {
|
||||
builder.append(placeholder)
|
||||
.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
final PlaceholderExpansion expansion = plugin.getLocalExpansionManager()
|
||||
.findExpansionByIdentifier(params.get(0)).orElse(null);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender,
|
||||
"&cThere is no expansion loaded with the identifier: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions,
|
||||
params.isEmpty() ? null : params.get(0));
|
||||
builder.append("&7Placeholder expansion info for: &r")
|
||||
.append(expansion.getName())
|
||||
.append('\n')
|
||||
.append("&7Status: &r")
|
||||
.append(expansion.isRegistered() ? "&aRegistered" : "7cNotRegistered")
|
||||
.append('\n');
|
||||
|
||||
final String author = expansion.getAuthor();
|
||||
if (author != null) {
|
||||
builder.append("&7Author: &r")
|
||||
.append(author)
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
final String version = expansion.getVersion();
|
||||
if (version != null) {
|
||||
builder.append("&7Version: &r")
|
||||
.append(version)
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
final String requiredPlugin = expansion.getRequiredPlugin();
|
||||
if (requiredPlugin != null) {
|
||||
builder.append("&7Requires plugin: &r")
|
||||
.append(requiredPlugin)
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
final List<String> placeholders = expansion.getPlaceholders();
|
||||
if (placeholders != null && !placeholders.isEmpty()) {
|
||||
builder.append("&8&m-- &7Placeholders &8&m--&r")
|
||||
.append('\n');
|
||||
|
||||
for (final String placeholder : placeholders) {
|
||||
builder.append(placeholder)
|
||||
.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
Msg.msg(sender, builder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions,
|
||||
params.isEmpty() ? null : params.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,11 +21,9 @@
|
||||
package me.clip.placeholderapi.commands.impl.local;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
@@ -36,28 +34,28 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandList extends PlaceholderCommand {
|
||||
|
||||
public CommandList() {
|
||||
super("list");
|
||||
public CommandList() {
|
||||
super("list");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final Set<String> identifiers = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
if (identifiers.isEmpty()) {
|
||||
Msg.msg(sender, "&cThere are no placeholder hooks active!");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<List<String>> partitions = Lists
|
||||
.partition(identifiers.stream().sorted().collect(Collectors.toList()), 10);
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final Set<String> identifiers = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
if (identifiers.isEmpty()) {
|
||||
Msg.msg(sender, "&cThere are no placeholder hooks active!");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<List<String>> partitions = Lists
|
||||
.partition(identifiers.stream().sorted().collect(Collectors.toList()), 10);
|
||||
|
||||
Msg.msg(sender,
|
||||
"&7A total of &f" + identifiers.size() + "&7 placeholder hook(s) are active: &a",
|
||||
partitions.stream().map(partition -> String.join("&7, &a", partition))
|
||||
.collect(Collectors.joining("\n")));
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&7A total of &f" + identifiers.size() + "&7 placeholder hook(s) are active: &a",
|
||||
partitions.stream().map(partition -> String.join("&7, &a", partition))
|
||||
.collect(Collectors.joining("\n")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -22,15 +22,14 @@ package me.clip.placeholderapi.commands.impl.local;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -41,217 +40,188 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandParse extends PlaceholderCommand {
|
||||
|
||||
public CommandParse() {
|
||||
super("parse", "bcparse", "parserel", "cmdparse");
|
||||
public CommandParse() {
|
||||
super("parse", "bcparse", "parserel", "cmdparse");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
switch (alias.toLowerCase()) {
|
||||
case "parserel":
|
||||
evaluateParseRelation(sender, params);
|
||||
break;
|
||||
case "parse":
|
||||
evaluateParseSingular(sender, params, false, false);
|
||||
break;
|
||||
case "bcparse":
|
||||
evaluateParseSingular(sender, params, true, false);
|
||||
break;
|
||||
case "cmdparse":
|
||||
evaluateParseSingular(sender, params, false, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
switch (alias.toLowerCase()) {
|
||||
case "parserel":
|
||||
completeParseRelation(params, suggestions);
|
||||
break;
|
||||
case "parse":
|
||||
case "bcparse":
|
||||
case "cmdparse":
|
||||
completeParseSingular(sender, params, suggestions);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void evaluateParseSingular(@NotNull final CommandSender sender,
|
||||
@NotNull @Unmodifiable final List<String> params, final boolean broadcast,
|
||||
final boolean command) {
|
||||
if (params.size() < 2) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must supply a target, and a message: &b/papi " + (broadcast ? "bcparse" : "parse")
|
||||
+ " &7{target} &a{message}");
|
||||
return;
|
||||
}
|
||||
|
||||
@NotNull final OfflinePlayer player;
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
switch (alias.toLowerCase(Locale.ROOT)) {
|
||||
case "parserel":
|
||||
evaluateParseRelation(sender, params);
|
||||
break;
|
||||
case "parse":
|
||||
evaluateParseSingular(sender, params, false, false);
|
||||
break;
|
||||
case "bcparse":
|
||||
evaluateParseSingular(sender, params, true, false);
|
||||
break;
|
||||
case "cmdparse":
|
||||
evaluateParseSingular(sender, params, false, true);
|
||||
break;
|
||||
}
|
||||
if ("me".equalsIgnoreCase(params.get(0))) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
|
||||
return;
|
||||
}
|
||||
|
||||
player = ((Player) sender);
|
||||
} else {
|
||||
final OfflinePlayer target = resolvePlayer(params.get(0));
|
||||
if (target == null) {
|
||||
Msg.msg(sender, "&cFailed to find player: &7" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
player = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
switch (alias.toLowerCase(Locale.ROOT)) {
|
||||
case "parserel":
|
||||
completeParseRelation(params, suggestions);
|
||||
break;
|
||||
case "parse":
|
||||
case "bcparse":
|
||||
case "cmdparse":
|
||||
completeParseSingular(sender, params, suggestions);
|
||||
break;
|
||||
}
|
||||
final String message = PlaceholderAPI
|
||||
.setPlaceholders(player, String.join(" ", params.subList(1, params.size())));
|
||||
|
||||
if (command) {
|
||||
Bukkit.dispatchCommand(sender, message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (broadcast) {
|
||||
Msg.broadcast(message);
|
||||
} else {
|
||||
if (!(sender instanceof Player)) {
|
||||
Msg.msg(sender, message);
|
||||
} else {
|
||||
((Player) sender).spigot().sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void evaluateParseSingular(@NotNull final CommandSender sender,
|
||||
@NotNull @Unmodifiable final List<String> params, final boolean broadcast,
|
||||
final boolean command) {
|
||||
if (params.size() < 2) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must provide a target and message: &b/papi "
|
||||
+ (command ? "cmdparse" : (broadcast ? "bcparse" : "parse"))
|
||||
+ " &7{target} &a{message}");
|
||||
return;
|
||||
}
|
||||
|
||||
OfflinePlayer player;
|
||||
|
||||
if ("me".equalsIgnoreCase(params.get(0))) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
|
||||
return;
|
||||
}
|
||||
|
||||
player = ((Player) sender);
|
||||
} else if ("--null".equalsIgnoreCase(params.get(0))) {
|
||||
player = null;
|
||||
} else {
|
||||
final OfflinePlayer target = resolvePlayer(params.get(0));
|
||||
if (target == null) {
|
||||
Msg.msg(sender, "&cFailed to find player: &7" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
player = target;
|
||||
}
|
||||
|
||||
final String message = PlaceholderAPI
|
||||
.setPlaceholders(player, String.join(" ", params.subList(1, params.size())));
|
||||
|
||||
if (command) {
|
||||
Bukkit.dispatchCommand(sender, message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (broadcast) {
|
||||
Bukkit.broadcastMessage(message);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
private void evaluateParseRelation(@NotNull final CommandSender sender,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.size() < 3) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must supply two targets, and a message: &b/papi parserel &7{target one} {target two} &a{message}");
|
||||
return;
|
||||
}
|
||||
|
||||
private void evaluateParseRelation(@NotNull final CommandSender sender,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
if (params.size() < 3) {
|
||||
Msg.msg(sender,
|
||||
"&cYou must supply two targets, and a message: &b/papi parserel &7{target one} "
|
||||
+ "{target two} &a{message}");
|
||||
return;
|
||||
}
|
||||
|
||||
OfflinePlayer playerOne;
|
||||
|
||||
if ("me".equalsIgnoreCase(params.get(0))) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
|
||||
return;
|
||||
}
|
||||
|
||||
playerOne = ((Player) sender);
|
||||
} else {
|
||||
playerOne = resolvePlayer(params.get(0));
|
||||
}
|
||||
|
||||
if (playerOne == null || !playerOne.isOnline()) {
|
||||
Msg.msg(sender, "&cFailed to find player: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
OfflinePlayer playerTwo;
|
||||
|
||||
if ("me".equalsIgnoreCase(params.get(1))) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
|
||||
return;
|
||||
}
|
||||
|
||||
playerTwo = ((Player) sender);
|
||||
} else {
|
||||
playerTwo = resolvePlayer(params.get(1));
|
||||
}
|
||||
|
||||
if (playerTwo == null || !playerTwo.isOnline()) {
|
||||
Msg.msg(sender, "&cFailed to find player: &f" + params.get(1));
|
||||
return;
|
||||
}
|
||||
|
||||
final String message = PlaceholderAPI
|
||||
.setRelationalPlaceholders((Player) playerOne, (Player) playerTwo,
|
||||
String.join(" ", params.subList(2, params.size())));
|
||||
|
||||
sender.sendMessage(message);
|
||||
final OfflinePlayer targetOne = resolvePlayer(params.get(0));
|
||||
if (targetOne == null || !targetOne.isOnline()) {
|
||||
Msg.msg(sender, "&cFailed to find player: &f" + params.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
private void completeParseSingular(@NotNull final CommandSender sender,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() <= 1) {
|
||||
if (sender instanceof Player && (params.isEmpty() || "me"
|
||||
.startsWith(params.get(0).toLowerCase(Locale.ROOT)))) {
|
||||
suggestions.add("me");
|
||||
}
|
||||
|
||||
if ("--null".startsWith(params.get(0).toLowerCase(Locale.ROOT))) {
|
||||
suggestions.add("--null");
|
||||
}
|
||||
|
||||
final Stream<String> names = Bukkit.getOnlinePlayers().stream().map(Player::getName);
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final String name = params.get(params.size() - 1);
|
||||
if (!name.startsWith("%") || name.endsWith("%")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int index = name.indexOf('_');
|
||||
if (index == -1) {
|
||||
return; // no arguments supplied yet
|
||||
}
|
||||
|
||||
final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance()
|
||||
.getLocalExpansionManager().findExpansionByIdentifier(name.substring(1, index))
|
||||
.orElse(null);
|
||||
if (expansion == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Set<String> possible = new HashSet<>(expansion.getPlaceholders());
|
||||
|
||||
PlaceholderAPIPlugin.getInstance()
|
||||
.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(expansion.getName())
|
||||
.ifPresent(cloud -> possible.addAll(cloud.getPlaceholders()));
|
||||
|
||||
suggestByParameter(possible.stream(), suggestions, params.get(params.size() - 1));
|
||||
final OfflinePlayer targetTwo = resolvePlayer(params.get(1));
|
||||
if (targetTwo == null || !targetTwo.isOnline()) {
|
||||
Msg.msg(sender, "&cFailed to find player: &f" + params.get(1));
|
||||
return;
|
||||
}
|
||||
|
||||
private void completeParseRelation(@NotNull @Unmodifiable final List<String> params,
|
||||
@NotNull final List<String> suggestions) {
|
||||
if (params.size() > 2) {
|
||||
return;
|
||||
}
|
||||
final String message = PlaceholderAPI
|
||||
.setRelationalPlaceholders(((Player) targetOne), ((Player) targetTwo),
|
||||
String.join(" ", params.subList(2, params.size())));
|
||||
Msg.msg(sender, message);
|
||||
}
|
||||
|
||||
final Stream<String> names = Bukkit.getOnlinePlayers().stream().map(Player::getName);
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(params.size() - 1));
|
||||
|
||||
private void completeParseSingular(@NotNull final CommandSender sender,
|
||||
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
|
||||
if (params.size() <= 1) {
|
||||
if (sender instanceof Player && (params.isEmpty() || "me"
|
||||
.startsWith(params.get(0).toLowerCase()))) {
|
||||
suggestions.add("me");
|
||||
}
|
||||
|
||||
final Stream<String> names = Bukkit.getOnlinePlayers().stream().map(Player::getName);
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private OfflinePlayer resolvePlayer(@NotNull final String name) {
|
||||
OfflinePlayer target = Bukkit.getPlayerExact(name);
|
||||
|
||||
if (target == null) {
|
||||
// Not the best option, but Spigot doesn't offer a good replacement (as usual)
|
||||
target = Bukkit.getOfflinePlayer(name);
|
||||
|
||||
return target.hasPlayedBefore() ? target : null;
|
||||
}
|
||||
|
||||
return target;
|
||||
|
||||
final String name = params.get(params.size() - 1);
|
||||
if (!name.startsWith("%") || name.endsWith("%")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int index = name.indexOf('_');
|
||||
if (index == -1) {
|
||||
return; // no arguments supplied yet
|
||||
}
|
||||
|
||||
final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance()
|
||||
.getLocalExpansionManager().findExpansionByIdentifier(name.substring(1, index))
|
||||
.orElse(null);
|
||||
if (expansion == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Set<String> possible = new HashSet<>(expansion.getPlaceholders());
|
||||
|
||||
PlaceholderAPIPlugin.getInstance()
|
||||
.getCloudExpansionManager()
|
||||
.findCloudExpansionByName(expansion.getName())
|
||||
.ifPresent(cloud -> possible.addAll(cloud.getPlaceholders()));
|
||||
|
||||
suggestByParameter(possible.stream(), suggestions, params.get(params.size() - 1));
|
||||
}
|
||||
|
||||
private void completeParseRelation(@NotNull @Unmodifiable final List<String> params,
|
||||
@NotNull final List<String> suggestions) {
|
||||
if (params.size() > 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Stream<String> names = Bukkit.getOnlinePlayers().stream().map(Player::getName);
|
||||
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(params.size() - 1));
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private OfflinePlayer resolvePlayer(@NotNull final String name) {
|
||||
OfflinePlayer target = Bukkit.getPlayerExact(name);
|
||||
|
||||
if (target == null) {
|
||||
// Not the best option, but Spigot doesn't offer a good replacement (as usual)
|
||||
target = Bukkit.getOfflinePlayer(name);
|
||||
|
||||
return target.hasPlayedBefore() ? target : null;
|
||||
}
|
||||
|
||||
return target;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.commands.impl.local;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -30,15 +29,15 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandReload extends PlaceholderCommand {
|
||||
|
||||
public CommandReload() {
|
||||
super("reload");
|
||||
}
|
||||
public CommandReload() {
|
||||
super("reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
plugin.reloadConf(sender);
|
||||
}
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
plugin.reloadConf(sender);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.commands.impl.local;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
@@ -32,22 +31,22 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CommandVersion extends PlaceholderCommand {
|
||||
|
||||
public CommandVersion() {
|
||||
super("version");
|
||||
}
|
||||
public CommandVersion() {
|
||||
super("version");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final PluginDescriptionFile description = plugin.getDescription();
|
||||
@Override
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
final PluginDescriptionFile description = plugin.getDescription();
|
||||
|
||||
Msg.msg(sender,
|
||||
"&b&lPlaceholderAPI &7(&f" + description.getVersion() + "&7)",
|
||||
"&7Author: &f" + description.getAuthors(),
|
||||
"&7PAPI Commands: &b/papi &fhelp",
|
||||
"&7eCloud Commands&8: &b/papi &fecloud");
|
||||
}
|
||||
Msg.msg(sender,
|
||||
"&b&lPlaceholderAPI &7(&f" + description.getVersion() + "&7)",
|
||||
"&7Author: &f" + description.getAuthors(),
|
||||
"&7PAPI Commands: &b/papi &fhelp",
|
||||
"&7eCloud Commands&8: &b/papi &fecloud");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -38,6 +38,10 @@ public final class PlaceholderAPIConfig {
|
||||
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");
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -27,63 +27,50 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This event indicates that a <b>single</b> {@link PlaceholderExpansion PlaceholderExpansion} has
|
||||
* been registered in PlaceholderAPI.
|
||||
*
|
||||
* <p>To know when <b>all</b> Expansions have been registered, use the
|
||||
* {@link me.clip.placeholderapi.events.ExpansionsLoadedEvent ExpansionsLoadedEvent} instead.
|
||||
* Indicates that a {@link PlaceholderExpansion} has been registered by
|
||||
* PlaceholderAPI.
|
||||
*/
|
||||
public final class ExpansionRegisterEvent extends Event implements Cancellable {
|
||||
|
||||
@NotNull
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@NotNull
|
||||
private final PlaceholderExpansion expansion;
|
||||
private boolean cancelled;
|
||||
@NotNull
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@NotNull
|
||||
private final PlaceholderExpansion expansion;
|
||||
private boolean cancelled;
|
||||
|
||||
public ExpansionRegisterEvent(@NotNull final PlaceholderExpansion expansion) {
|
||||
this.expansion = expansion;
|
||||
}
|
||||
public ExpansionRegisterEvent(@NotNull final PlaceholderExpansion expansion) {
|
||||
this.expansion = expansion;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link PlaceholderExpansion expansion} that was registered.
|
||||
*
|
||||
* @return The {@link PlaceholderExpansion} instance.
|
||||
*/
|
||||
@NotNull
|
||||
public PlaceholderExpansion getExpansion() {
|
||||
return expansion;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link PlaceholderExpansion PlaceholderExpansion} that was registered in PlaceholderAPI.
|
||||
* <br>The PlaceholderExpansion will be available for use when the event
|
||||
* {@link #isCancelled() was not cancelled}!
|
||||
*
|
||||
* @return Current instance of the registered {@link PlaceholderExpansion PlaceholderExpansion}
|
||||
*/
|
||||
@NotNull
|
||||
public PlaceholderExpansion getExpansion() {
|
||||
return expansion;
|
||||
}
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this event was cancelled or not.
|
||||
* <br>A cancelled Event will result in the {@link #getExpansion() PlaceholderExpansion} NOT
|
||||
* being added to PlaceholderAPI's internal list and will therefore be considered not registered
|
||||
* anymore.
|
||||
*
|
||||
* @return Whether the event has been cancelled or not.
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -26,45 +26,41 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This event indicates that a {@link PlaceholderExpansion PlaceholderExpansion} has been
|
||||
* unregistered by PlaceholderAPI.
|
||||
*
|
||||
* <p>Note that this event is triggered <b>before</b> the PlaceholderExpansion is completely
|
||||
* removed.
|
||||
* <br>This includes removing any Listeners, stopping active tasks and clearing the cache of
|
||||
* the PlaceholderExpansion.
|
||||
* Indicates that a {@link PlaceholderExpansion} had been unregistered by
|
||||
* PlaceholderAPI.
|
||||
*/
|
||||
public final class ExpansionUnregisterEvent extends Event {
|
||||
|
||||
@NotNull
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@NotNull
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
@NotNull
|
||||
private final PlaceholderExpansion expansion;
|
||||
|
||||
public ExpansionUnregisterEvent(@NotNull final PlaceholderExpansion expansion) {
|
||||
this.expansion = expansion;
|
||||
}
|
||||
@NotNull
|
||||
private final PlaceholderExpansion expansion;
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
public ExpansionUnregisterEvent(@NotNull final PlaceholderExpansion expansion) {
|
||||
this.expansion = expansion;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link PlaceholderExpansion PlaceholderExpansion} that was unregistered.
|
||||
*
|
||||
* @return The {@link PlaceholderExpansion PlaceholderExpansion} instance.
|
||||
*/
|
||||
@NotNull
|
||||
public PlaceholderExpansion getExpansion() {
|
||||
return expansion;
|
||||
}
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link PlaceholderExpansion expansion} that was unregistered.
|
||||
*
|
||||
* @return The {@link PlaceholderExpansion} instance.
|
||||
*/
|
||||
@NotNull
|
||||
public PlaceholderExpansion getExpansion() {
|
||||
return expansion;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,43 +21,18 @@
|
||||
package me.clip.placeholderapi.events;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This event indicated that <b>all</b> {@link PlaceholderExpansion PlaceholderExpansions} have
|
||||
* been registered in PlaceholderAPI and can now be used.
|
||||
* <br>This even will also be triggered whenever PlaceholderAPI gets reloaded.
|
||||
*
|
||||
* <p>All PlaceholderExpansions, except for those loaded by plugins, are loaded
|
||||
* after Spigot triggered its ServerLoadEvent (1.13+), or after PlaceholderAPI has been enabled.
|
||||
* Indicates that <b>all</b> {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlayceholderExpansions}
|
||||
* have been loaded.
|
||||
* <br/>This event is fired on Server load and when reloading the
|
||||
* confiuration.
|
||||
*/
|
||||
public class ExpansionsLoadedEvent extends Event {
|
||||
|
||||
private final List<PlaceholderExpansion> expansions;
|
||||
|
||||
public ExpansionsLoadedEvent(List<PlaceholderExpansion> expansions) {
|
||||
this.expansions = Collections.unmodifiableList(expansions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unmodifiable list of {@link PlaceholderExpansion PlaceholderExpansions} that
|
||||
* have been registered by PlaceholderAPI.
|
||||
*
|
||||
* <p><b>This list does not include manually registered PlaceholderExpansions.</b>
|
||||
*
|
||||
* @return List of {@link PlaceholderExpansion registered PlaceholderExpansions}.
|
||||
*/
|
||||
@NotNull
|
||||
public final List<PlaceholderExpansion> getExpansions() {
|
||||
return expansions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -31,40 +31,40 @@ import org.jetbrains.annotations.NotNull;
|
||||
@Deprecated
|
||||
public final class PlaceholderHookUnloadEvent extends Event {
|
||||
|
||||
@NotNull
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@NotNull
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
|
||||
@NotNull
|
||||
private final String plugin;
|
||||
@NotNull
|
||||
private final PlaceholderHook placeholderHook;
|
||||
@NotNull
|
||||
private final String plugin;
|
||||
@NotNull
|
||||
private final PlaceholderHook placeholderHook;
|
||||
|
||||
public PlaceholderHookUnloadEvent(@NotNull final String plugin,
|
||||
@NotNull final PlaceholderHook placeholderHook) {
|
||||
this.plugin = plugin;
|
||||
this.placeholderHook = placeholderHook;
|
||||
}
|
||||
public PlaceholderHookUnloadEvent(@NotNull final String plugin,
|
||||
@NotNull final PlaceholderHook placeholderHook) {
|
||||
this.plugin = plugin;
|
||||
this.placeholderHook = placeholderHook;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getHookName() {
|
||||
return plugin;
|
||||
}
|
||||
@NotNull
|
||||
public String getHookName() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PlaceholderHook getHook() {
|
||||
return placeholderHook;
|
||||
}
|
||||
@NotNull
|
||||
public PlaceholderHook getHook() {
|
||||
return placeholderHook;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,11 +21,9 @@
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
/**
|
||||
* Classes implementing this interface will have a {@link #clear() clear void} that is called
|
||||
* by PlaceholderAPI whenever the {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion}
|
||||
* is unregistered.
|
||||
*
|
||||
* <p>This allows you to execute things such as clearing internal caches, saving data to files, etc.
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -23,11 +23,9 @@ package me.clip.placeholderapi.expansion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Classes implementing this interface will have a {@link #cleanup(Player) cleanup void} that is
|
||||
* called by PlaceholderAPI whenever a Player leaves the server.
|
||||
*
|
||||
* <p>This can be useful for cases where you keep data of the player in a cache or similar
|
||||
* and want to free up space whenever they leave.
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -23,32 +23,18 @@ package me.clip.placeholderapi.expansion;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implementing this interface allows {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansions}
|
||||
* to set a list of default configuration values through the {@link #getDefaults() getDefaults method}
|
||||
* that should be added to the config.yml of PlaceholderAPI.
|
||||
*
|
||||
* <p>The entries will be added under {@code expansions} as their own section.
|
||||
* <h2>Example:</h2>
|
||||
* returning a Map with key {@code foo} and value {@code bar} will result in the following config entry:
|
||||
*
|
||||
* <pre><code>
|
||||
* expansions:
|
||||
* myexpansion:
|
||||
* foo: "bar"
|
||||
* </code></pre>
|
||||
*
|
||||
* <p><b>The configuration is set before the PlaceholderExpansion is registered!</b>
|
||||
* Any {@link PlaceholderExpansion} class which implements configurable will have any options listed
|
||||
* in the {@link #getDefaults()} map automatically added to the PlaceholderAPI config.yml file
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public interface Configurable {
|
||||
|
||||
/**
|
||||
* The map returned by this method will be used to set config options in PlaceholderAPI's config.yml.
|
||||
*
|
||||
* <p>The key and value pairs are set under a section named after your
|
||||
* {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion} in the
|
||||
* {@code expansions} section of the config.
|
||||
* 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
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -42,19 +42,7 @@ public enum NMSVersion {
|
||||
SPIGOT_1_16_R1("v1_16_R1"),
|
||||
SPIGOT_1_16_R2("v1_16_R2"),
|
||||
SPIGOT_1_16_R3("v1_16_R3"),
|
||||
SPIGOT_1_17_R1("v1_17_R1"),
|
||||
SPIGOT_1_18_R1("v1_18_R1"),
|
||||
SPIGOT_1_19_R1("v1_19_R1"),
|
||||
SPIGOT_1_19_R2("v1_19_R2"),
|
||||
SPIGOT_1_19_R3("v1_19_R3"),
|
||||
SPIGOT_1_20_R1("v1_20_R1"),
|
||||
SPIGOT_1_20_R2("v1_20_R2"),
|
||||
SPIGOT_1_20_R3("v1_20_R3"),
|
||||
SPIGOT_1_20_R4("v1_20_R4"),
|
||||
SPIGOT_1_21_R1("v1_21_R1"),
|
||||
SPIGOT_1_21_R2("V1_21_R2"),
|
||||
SPIGOT_1_21_R3("V1_21_R3"),
|
||||
SPIGOT_1_21_R4("V1_21_R4");
|
||||
SPIGOT_1_17_R1("v1_17_R1");
|
||||
|
||||
private final String version;
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -22,7 +22,6 @@ package me.clip.placeholderapi.expansion;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -40,14 +39,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
|
||||
/**
|
||||
* The type is {@link Type#INTERNAL} by default.
|
||||
* For external expansions, the type is updated on {@link me.clip.placeholderapi.expansion.manager.LocalExpansionManager#register(Class) register}.
|
||||
* @since 2.11.4
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
protected Type expansionType = Type.INTERNAL;
|
||||
|
||||
/**
|
||||
* The placeholder identifier of this expansion. May not contain {@literal %},
|
||||
* {@literal {}} or _
|
||||
@@ -167,27 +158,6 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
return PlaceholderAPIPlugin.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the expansion
|
||||
*
|
||||
* @return the type of the expansion
|
||||
* @since 2.11.4
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public Type getExpansionType() {
|
||||
return expansionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of the expansion
|
||||
* @param expansionType the new type
|
||||
* @since 2.11.4
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void setExpansionType(Type expansionType) {
|
||||
this.expansionType = expansionType;
|
||||
}
|
||||
|
||||
// === Configuration ===
|
||||
|
||||
/**
|
||||
@@ -195,7 +165,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
* null when not specified.
|
||||
* <br>You may use the {@link Configurable} interface to define default values set
|
||||
*
|
||||
* @return ConfigurationSection that this expansion has.
|
||||
* @return ConfigurationSection that this epxpansion has.
|
||||
*/
|
||||
@Nullable
|
||||
public final ConfigurationSection getConfigSection() {
|
||||
@@ -322,71 +292,6 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
final ConfigurationSection section = getConfigSection();
|
||||
return section != null && section.contains(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the provided message with the provided Level in the console.
|
||||
* <br>The message will be prefixed with {@link #getName() <code>[<expansion name>]</code>}
|
||||
*
|
||||
* @param level The Level at which the message should be logged with
|
||||
* @param msg The message to log
|
||||
*/
|
||||
public void log(Level level, String msg) {
|
||||
getPlaceholderAPI().getLogger().log(level, "[" + getName() + "] " + msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the provided message and Throwable with the provided Level in the console.
|
||||
* <br>The message will be prefixed with {@link #getName() <code>[<expansion name>]</code>}
|
||||
*
|
||||
* @param level The Level at which the message should be logged with
|
||||
* @param msg The message to log
|
||||
* @param throwable The Throwable to log
|
||||
*/
|
||||
public void log(Level level, String msg, Throwable throwable) {
|
||||
getPlaceholderAPI().getLogger().log(level, "[" + getName() + "] " + msg, throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the provided message with Level "info".
|
||||
* <br>The message will be prefixed with {@link #getName() <code>[<expansion name>]</code>}
|
||||
*
|
||||
* @param msg The message to log
|
||||
*/
|
||||
public void info(String msg) {
|
||||
log(Level.INFO, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the provided message with Level "warning".
|
||||
* <br>The message will be prefixed with {@link #getName() <code>[<expansion name>]</code>}
|
||||
*
|
||||
* @param msg The message to log
|
||||
*/
|
||||
public void warning(String msg) {
|
||||
log(Level.WARNING, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the provided message with Level "severe" (error).
|
||||
* <br>The message will be prefixed with {@link #getName() <code>[<expansion name>]</code>}
|
||||
*
|
||||
* @param msg The message to log
|
||||
*/
|
||||
public void severe(String msg) {
|
||||
log(Level.SEVERE, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the provided message and Throwable with Level "severe" (error).
|
||||
* <br>The message will be prefixed with {@link #getName() <code>[<expansion name>]</code>}
|
||||
*
|
||||
* @param msg The message to log
|
||||
* @param throwable The Throwable to log
|
||||
*/
|
||||
public void severe(String msg, Throwable throwable) {
|
||||
log(Level.SEVERE, msg, throwable);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether the provided Object is an instance of this PlaceholderExpansion.
|
||||
@@ -423,8 +328,8 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return String.format("PlaceholderExpansion[name: '%s', author: '%s', version: '%s', type: '%s']", getName(),
|
||||
getAuthor(), getVersion(), getExpansionType());
|
||||
return String.format("PlaceholderExpansion[name: '%s', author: '%s', version: '%s']", getName(),
|
||||
getAuthor(), getVersion());
|
||||
}
|
||||
|
||||
// === Deprecated API ===
|
||||
@@ -435,7 +340,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
* @return The plugin name.
|
||||
*/
|
||||
@Deprecated
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
|
||||
public String getPlugin() {
|
||||
return null;
|
||||
}
|
||||
@@ -446,7 +351,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
* @return The description of the expansion.
|
||||
*/
|
||||
@Deprecated
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
@@ -457,23 +362,8 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
* @return The link for the expansion.
|
||||
*/
|
||||
@Deprecated
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.11.0")
|
||||
public String getLink() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
|
||||
/**
|
||||
* An expansion provided by a plugin is considered internal
|
||||
*/
|
||||
INTERNAL,
|
||||
|
||||
/**
|
||||
* An expansion loaded from the expansions folder is considered external
|
||||
*/
|
||||
EXTERNAL
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -22,22 +22,7 @@ package me.clip.placeholderapi.expansion;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Implementing this interface allows your {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion}
|
||||
* to be used as a relational placeholder expansion.
|
||||
*
|
||||
* <p>Relational placeholders take two Players as input and are always prefixed with {@code rel_},
|
||||
* so {@code %foo_bar%} becomes {@code %rel_foo_bar%}
|
||||
*/
|
||||
public interface Relational {
|
||||
|
||||
/**
|
||||
* This method is called whenever a placeholder starting with {@code rel_} is called.
|
||||
*
|
||||
* @param one The first player used for the placeholder.
|
||||
* @param two The second player used for the placeholder.
|
||||
* @param identifier The text right after the expansion's name (%expansion_<b>identifier</b>%)
|
||||
* @return Parsed String from the expansion.
|
||||
*/
|
||||
String onPlaceholderRequest(Player one, Player two, String identifier);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -20,24 +20,18 @@
|
||||
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
/**
|
||||
* Implementing this interface adds the {@link #start() start} and {@link #stop() stop} void
|
||||
* methods to your {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion}.
|
||||
*
|
||||
* <p>This can be used to execute methods and tasks whenever the PlaceholderExpansion has been
|
||||
* successfully (un)registered.
|
||||
*/
|
||||
|
||||
public interface Taskable {
|
||||
|
||||
/**
|
||||
* Called when the implementing class has successfully been registered to the placeholder map.
|
||||
* <br>Tasks that need to be performed when this expansion is registered should go here
|
||||
* 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.
|
||||
* <br>Tasks that need to be performed when this expansion has unregistered should go here
|
||||
* 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();
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -20,27 +20,26 @@
|
||||
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
@Deprecated
|
||||
public final class Version {
|
||||
|
||||
private final boolean isSpigot;
|
||||
private final String version;
|
||||
private final boolean isSpigot;
|
||||
private final String version;
|
||||
|
||||
public Version(String version, boolean isSpigot) {
|
||||
this.version = version;
|
||||
this.isSpigot = isSpigot;
|
||||
}
|
||||
public Version(String version, boolean isSpigot) {
|
||||
this.version = version;
|
||||
this.isSpigot = isSpigot;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version == null ? "unknown" : version;
|
||||
}
|
||||
public String getVersion() {
|
||||
return version == null ? "unknown" : version;
|
||||
}
|
||||
|
||||
public boolean isSpigot() {
|
||||
return isSpigot;
|
||||
}
|
||||
public boolean isSpigot() {
|
||||
return isSpigot;
|
||||
}
|
||||
|
||||
public boolean compareTo(String version) {
|
||||
return getVersion().equalsIgnoreCase(version);
|
||||
}
|
||||
public boolean compareTo(String version) {
|
||||
return getVersion().equalsIgnoreCase(version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -27,10 +27,7 @@ package me.clip.placeholderapi.expansion;
|
||||
* with that version.
|
||||
*
|
||||
* @author Ryan McCarthy
|
||||
*
|
||||
* @deprecated Will be removed in a future release.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface VersionSpecific {
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -23,181 +23,180 @@ package me.clip.placeholderapi.expansion.cloud;
|
||||
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 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 static class Version {
|
||||
|
||||
private String url, version, release_notes;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getTimeSinceLastUpdate() {
|
||||
int time = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getLastUpdate());
|
||||
return TimeUtil.getTime(time);
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
public String getReleaseNotes() {
|
||||
return release_notes;
|
||||
}
|
||||
|
||||
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 static 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -25,7 +25,6 @@ import com.google.common.io.Resources;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -38,7 +37,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -51,228 +49,232 @@ import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class CloudExpansionManager {
|
||||
|
||||
@NotNull
|
||||
private static final String API_URL = "http://api.extendedclip.com/v2/";
|
||||
@NotNull
|
||||
private static final String API_URL = "http://api.extendedclip.com/v2/";
|
||||
|
||||
@NotNull
|
||||
private static final Gson GSON = new Gson();
|
||||
@NotNull
|
||||
private static final Type TYPE = new TypeToken<Map<String, CloudExpansion>>() {}.getType();
|
||||
@NotNull
|
||||
private static final Gson GSON = new Gson();
|
||||
@NotNull
|
||||
private static final Type TYPE = new TypeToken<Map<String, CloudExpansion>>() {}.getType();
|
||||
|
||||
@NotNull
|
||||
private final Collector<CloudExpansion, ?, Map<String, CloudExpansion>> INDEXED_NAME_COLLECTOR = Collectors
|
||||
.toMap(CloudExpansionManager::toIndexName, Function.identity());
|
||||
@NotNull
|
||||
private final Collector<CloudExpansion, ?, Map<String, CloudExpansion>> INDEXED_NAME_COLLECTOR = Collectors
|
||||
.toMap(CloudExpansionManager::toIndexName, Function.identity());
|
||||
|
||||
|
||||
@NotNull
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
@NotNull
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
|
||||
@NotNull
|
||||
private final Map<String, CloudExpansion> cache = new HashMap<>();
|
||||
@NotNull
|
||||
private final Map<String, CompletableFuture<File>> await = new ConcurrentHashMap<>();
|
||||
@NotNull
|
||||
private final Map<String, CloudExpansion> cache = new HashMap<>();
|
||||
@NotNull
|
||||
private final Map<String, CompletableFuture<File>> await = new ConcurrentHashMap<>();
|
||||
|
||||
private final ExecutorService ASYNC_EXECUTOR =
|
||||
Executors.newCachedThreadPool(
|
||||
new ThreadFactoryBuilder().setNameFormat("placeholderapi-io-#%1$d").build());
|
||||
private final ExecutorService ASYNC_EXECUTOR =
|
||||
Executors.newCachedThreadPool(
|
||||
new ThreadFactoryBuilder().setNameFormat("placeholderapi-io-#%1$d").build());
|
||||
|
||||
public CloudExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
public CloudExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String toIndexName(@NotNull final String name) {
|
||||
return name.toLowerCase().replace(' ', '_');
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String toIndexName(@NotNull final CloudExpansion expansion) {
|
||||
return toIndexName(expansion.getName());
|
||||
}
|
||||
|
||||
public void load() {
|
||||
clean();
|
||||
fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
clean();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Map<String, CloudExpansion> getCloudExpansions() {
|
||||
return ImmutableMap.copyOf(cache);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Map<String, CloudExpansion> getCloudExpansionsInstalled() {
|
||||
if (cache.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String toIndexName(@NotNull final String name) {
|
||||
return name.toLowerCase(Locale.ROOT).replace(' ', '_');
|
||||
return cache.values()
|
||||
.stream()
|
||||
.filter(CloudExpansion::hasExpansion)
|
||||
.collect(INDEXED_NAME_COLLECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Map<String, CloudExpansion> getCloudExpansionsByAuthor(@NotNull final String author) {
|
||||
if (cache.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String toIndexName(@NotNull final CloudExpansion expansion) {
|
||||
return toIndexName(expansion.getName());
|
||||
}
|
||||
return cache.values()
|
||||
.stream()
|
||||
.filter(expansion -> author.equalsIgnoreCase(expansion.getAuthor()))
|
||||
.collect(INDEXED_NAME_COLLECTOR);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
clean();
|
||||
fetch();
|
||||
}
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Set<String> getCloudExpansionAuthors() {
|
||||
return cache.values().stream().map(CloudExpansion::getAuthor).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
clean();
|
||||
}
|
||||
public int getCloudExpansionAuthorCount() {
|
||||
return getCloudExpansionAuthors().size();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Map<String, CloudExpansion> getCloudExpansions() {
|
||||
return ImmutableMap.copyOf(cache);
|
||||
}
|
||||
public int getCloudUpdateCount() {
|
||||
return ((int) plugin.getLocalExpansionManager()
|
||||
.getExpansions()
|
||||
.stream()
|
||||
.filter(expansion -> findCloudExpansionByName(expansion.getName())
|
||||
.map(CloudExpansion::shouldUpdate).orElse(false))
|
||||
.count());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Map<String, CloudExpansion> getCloudExpansionsInstalled() {
|
||||
if (cache.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
@NotNull
|
||||
public Optional<CloudExpansion> findCloudExpansionByName(@NotNull final String name) {
|
||||
return Optional.ofNullable(cache.get(toIndexName(name)));
|
||||
}
|
||||
|
||||
return cache.values()
|
||||
.stream()
|
||||
.filter(CloudExpansion::hasExpansion)
|
||||
.collect(INDEXED_NAME_COLLECTOR);
|
||||
}
|
||||
public void clean() {
|
||||
cache.clear();
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Map<String, CloudExpansion> getCloudExpansionsByAuthor(@NotNull final String author) {
|
||||
if (cache.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
await.values().forEach(future -> future.cancel(true));
|
||||
await.clear();
|
||||
}
|
||||
|
||||
return cache.values()
|
||||
.stream()
|
||||
.filter(expansion -> author.equalsIgnoreCase(expansion.getAuthor()))
|
||||
.collect(INDEXED_NAME_COLLECTOR);
|
||||
}
|
||||
public void fetch(final boolean allowUnverified) {
|
||||
plugin.getLogger().info("Fetching available expansion information...");
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Set<String> getCloudExpansionAuthors() {
|
||||
return cache.values().stream().map(CloudExpansion::getAuthor).collect(Collectors.toSet());
|
||||
}
|
||||
ASYNC_EXECUTOR.submit(
|
||||
() -> {
|
||||
// a defence tactic! use ConcurrentHashMap instead of normal HashMap
|
||||
Map<String, CloudExpansion> values = new ConcurrentHashMap<>();
|
||||
try {
|
||||
//noinspection UnstableApiUsage
|
||||
String json = Resources.toString(new URL(API_URL), StandardCharsets.UTF_8);
|
||||
values.putAll(GSON.fromJson(json, TYPE));
|
||||
|
||||
public int getCloudExpansionAuthorCount() {
|
||||
return getCloudExpansionAuthors().size();
|
||||
}
|
||||
List<String> toRemove = new ArrayList<>();
|
||||
|
||||
public int getCloudUpdateCount() {
|
||||
return ((int) plugin.getLocalExpansionManager()
|
||||
.getExpansions()
|
||||
.stream()
|
||||
.filter(expansion -> findCloudExpansionByName(expansion.getName())
|
||||
.map(CloudExpansion::shouldUpdate).orElse(false))
|
||||
.count());
|
||||
}
|
||||
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
|
||||
CloudExpansion expansion = entry.getValue();
|
||||
if (expansion.getLatestVersion() == null
|
||||
|| expansion.getVersion(expansion.getLatestVersion()) == null) {
|
||||
toRemove.add(entry.getKey());
|
||||
}
|
||||
if (!allowUnverified && !expansion.isVerified()) {
|
||||
toRemove.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Optional<CloudExpansion> findCloudExpansionByName(@NotNull final String name) {
|
||||
return Optional.ofNullable(cache.get(toIndexName(name)));
|
||||
}
|
||||
for (String name : toRemove) {
|
||||
values.remove(name);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// ugly swallowing of every throwable, but we have to be defensive
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e);
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
cache.clear();
|
||||
|
||||
await.values().forEach(future -> future.cancel(true));
|
||||
await.clear();
|
||||
}
|
||||
|
||||
public void fetch() {
|
||||
plugin.getLogger().info("Fetching available expansion information...");
|
||||
|
||||
ASYNC_EXECUTOR.submit(
|
||||
() -> {
|
||||
// a defence tactic! use ConcurrentHashMap instead of normal HashMap
|
||||
Map<String, CloudExpansion> values = new ConcurrentHashMap<>();
|
||||
// loop thru what's left on the main thread
|
||||
plugin
|
||||
.getServer()
|
||||
.getScheduler()
|
||||
.runTask(
|
||||
plugin,
|
||||
() -> {
|
||||
try {
|
||||
//noinspection UnstableApiUsage
|
||||
String json = Resources.toString(new URL(API_URL), StandardCharsets.UTF_8);
|
||||
values.putAll(GSON.fromJson(json, TYPE));
|
||||
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
CloudExpansion expansion = entry.getValue();
|
||||
|
||||
List<String> toRemove = new ArrayList<>();
|
||||
expansion.setName(name);
|
||||
|
||||
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
|
||||
CloudExpansion expansion = entry.getValue();
|
||||
if (expansion.getLatestVersion() == null
|
||||
|| expansion.getVersion(expansion.getLatestVersion()) == null) {
|
||||
toRemove.add(entry.getKey());
|
||||
}
|
||||
Optional<PlaceholderExpansion> localOpt =
|
||||
plugin.getLocalExpansionManager().findExpansionByName(name);
|
||||
if (localOpt.isPresent()) {
|
||||
PlaceholderExpansion local = localOpt.get();
|
||||
if (local.isRegistered()) {
|
||||
expansion.setHasExpansion(true);
|
||||
expansion.setShouldUpdate(
|
||||
!local.getVersion().equalsIgnoreCase(expansion.getLatestVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
for (String name : toRemove) {
|
||||
values.remove(name);
|
||||
}
|
||||
cache.put(toIndexName(expansion), expansion);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// ugly swallowing of every throwable, but we have to be defensive
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e);
|
||||
// ugly swallowing of every throwable, but we have to be defensive
|
||||
plugin
|
||||
.getLogger()
|
||||
.log(Level.WARNING, "Failed to download expansion information", e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// loop through what's left on the main thread
|
||||
plugin
|
||||
.getScheduler()
|
||||
.runTask(
|
||||
() -> {
|
||||
try {
|
||||
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
CloudExpansion expansion = entry.getValue();
|
||||
public boolean isDownloading(@NotNull final CloudExpansion expansion) {
|
||||
return await.containsKey(toIndexName(expansion));
|
||||
}
|
||||
|
||||
expansion.setName(name);
|
||||
|
||||
Optional<PlaceholderExpansion> localOpt =
|
||||
plugin.getLocalExpansionManager().findExpansionByName(name);
|
||||
if (localOpt.isPresent()) {
|
||||
PlaceholderExpansion local = localOpt.get();
|
||||
if (local.isRegistered()) {
|
||||
expansion.setHasExpansion(true);
|
||||
expansion.setShouldUpdate(
|
||||
!local.getVersion().equalsIgnoreCase(expansion.getLatestVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
cache.put(toIndexName(expansion), expansion);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// ugly swallowing of every throwable, but we have to be defensive
|
||||
plugin
|
||||
.getLogger()
|
||||
.log(Level.WARNING, "Failed to download expansion information", e);
|
||||
}
|
||||
});
|
||||
});
|
||||
@NotNull
|
||||
public CompletableFuture<File> downloadExpansion(@NotNull final CloudExpansion expansion,
|
||||
@NotNull final CloudExpansion.Version version) {
|
||||
final CompletableFuture<File> previous = await.get(toIndexName(expansion));
|
||||
if (previous != null) {
|
||||
return previous;
|
||||
}
|
||||
|
||||
public boolean isDownloading(@NotNull final CloudExpansion expansion) {
|
||||
return await.containsKey(toIndexName(expansion));
|
||||
}
|
||||
final File file = new File(plugin.getLocalExpansionManager().getExpansionsFolder(),
|
||||
"Expansion-" + toIndexName(expansion) + ".jar");
|
||||
|
||||
@NotNull
|
||||
public CompletableFuture<File> downloadExpansion(@NotNull final CloudExpansion expansion,
|
||||
@NotNull final CloudExpansion.Version version) {
|
||||
final CompletableFuture<File> previous = await.get(toIndexName(expansion));
|
||||
if (previous != null) {
|
||||
return previous;
|
||||
}
|
||||
final CompletableFuture<File> download = CompletableFuture.supplyAsync(() -> {
|
||||
try (final ReadableByteChannel source = Channels.newChannel(new URL(version.getUrl())
|
||||
.openStream()); final FileOutputStream target = new FileOutputStream(file)) {
|
||||
target.getChannel().transferFrom(source, 0, Long.MAX_VALUE);
|
||||
} catch (final IOException ex) {
|
||||
throw new CompletionException(ex);
|
||||
}
|
||||
return file;
|
||||
}, ASYNC_EXECUTOR);
|
||||
|
||||
final File file = new File(plugin.getLocalExpansionManager().getExpansionsFolder(),
|
||||
"Expansion-" + toIndexName(expansion) + ".jar");
|
||||
download.whenCompleteAsync((value, exception) -> {
|
||||
await.remove(toIndexName(expansion));
|
||||
|
||||
final CompletableFuture<File> download = CompletableFuture.supplyAsync(() -> {
|
||||
try (final ReadableByteChannel source = Channels.newChannel(new URL(version.getUrl())
|
||||
.openStream()); final FileOutputStream target = new FileOutputStream(file)) {
|
||||
target.getChannel().transferFrom(source, 0, Long.MAX_VALUE);
|
||||
} catch (final IOException ex) {
|
||||
throw new CompletionException(ex);
|
||||
}
|
||||
return file;
|
||||
}, ASYNC_EXECUTOR);
|
||||
if (exception != null) {
|
||||
plugin.getLogger().log(Level.SEVERE,
|
||||
"failed to download " + expansion.getName() + ":" + version.getVersion(), exception);
|
||||
}
|
||||
}, ASYNC_EXECUTOR);
|
||||
|
||||
download.whenCompleteAsync((value, exception) -> {
|
||||
await.remove(toIndexName(expansion));
|
||||
await.put(toIndexName(expansion), download);
|
||||
|
||||
if (exception != null) {
|
||||
Msg.severe("Failed to download %s:%s", exception, expansion.getName(), expansion.getVersion());
|
||||
}
|
||||
}, ASYNC_EXECUTOR);
|
||||
|
||||
await.put(toIndexName(expansion), download);
|
||||
|
||||
return download;
|
||||
}
|
||||
return download;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -22,34 +22,11 @@ package me.clip.placeholderapi.expansion.manager;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.events.ExpansionRegisterEvent;
|
||||
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
|
||||
import me.clip.placeholderapi.events.ExpansionsLoadedEvent;
|
||||
import me.clip.placeholderapi.expansion.Cacheable;
|
||||
import me.clip.placeholderapi.expansion.Cleanable;
|
||||
import me.clip.placeholderapi.expansion.Configurable;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Taskable;
|
||||
import me.clip.placeholderapi.expansion.VersionSpecific;
|
||||
import me.clip.placeholderapi.expansion.*;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
import me.clip.placeholderapi.util.FileUtil;
|
||||
import me.clip.placeholderapi.util.Futures;
|
||||
@@ -68,431 +45,390 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class LocalExpansionManager implements Listener {
|
||||
|
||||
@NotNull
|
||||
private static final String EXPANSIONS_FOLDER_NAME = "expansions";
|
||||
@NotNull
|
||||
private static final String EXPANSIONS_FOLDER_NAME = "expansions";
|
||||
|
||||
@NotNull
|
||||
private static final Set<MethodSignature> ABSTRACT_EXPANSION_METHODS = Arrays.stream(PlaceholderExpansion.class.getDeclaredMethods())
|
||||
.filter(method -> Modifier.isAbstract(method.getModifiers()))
|
||||
.map(method -> new MethodSignature(method.getName(), method.getParameterTypes()))
|
||||
.collect(Collectors.toSet());
|
||||
@NotNull
|
||||
private static final Set<MethodSignature> ABSTRACT_EXPANSION_METHODS = Arrays.stream(PlaceholderExpansion.class.getDeclaredMethods())
|
||||
.filter(method -> Modifier.isAbstract(method.getModifiers()))
|
||||
.map(method -> new MethodSignature(method.getName(), method.getParameterTypes()))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
@NotNull
|
||||
private final File folder;
|
||||
@NotNull
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
@NotNull
|
||||
private final File folder;
|
||||
@NotNull
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
|
||||
@NotNull
|
||||
private final Map<String, PlaceholderExpansion> expansions = new ConcurrentHashMap<>();
|
||||
private final ReentrantLock expansionsLock = new ReentrantLock();
|
||||
@NotNull
|
||||
private final Map<String, PlaceholderExpansion> expansions = new ConcurrentHashMap<>();
|
||||
private final ReentrantLock expansionsLock = new ReentrantLock();
|
||||
|
||||
|
||||
public LocalExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.folder = new File(plugin.getDataFolder(), EXPANSIONS_FOLDER_NAME);
|
||||
public LocalExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.folder = new File(plugin.getDataFolder(), EXPANSIONS_FOLDER_NAME);
|
||||
|
||||
if (!this.folder.exists() && !folder.mkdirs()) {
|
||||
Msg.warn("Failed to create expansions folder!");
|
||||
if (!this.folder.exists() && !folder.mkdirs()) {
|
||||
plugin.getLogger().log(Level.WARNING, "failed to create expansions folder!");
|
||||
}
|
||||
}
|
||||
|
||||
public void load(@NotNull final CommandSender sender) {
|
||||
registerAll(sender);
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
unregisterAll();
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public File getExpansionsFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Collection<String> getIdentifiers() {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
return ImmutableSet.copyOf(expansions.keySet());
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Collection<PlaceholderExpansion> getExpansions() {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
return ImmutableSet.copyOf(expansions.values());
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PlaceholderExpansion getExpansion(@NotNull final String identifier) {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
return expansions.get(identifier.toLowerCase());
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Optional<PlaceholderExpansion> findExpansionByName(@NotNull final String name) {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
PlaceholderExpansion bestMatch = null;
|
||||
for (Map.Entry<String, PlaceholderExpansion> entry : expansions.entrySet()) {
|
||||
PlaceholderExpansion expansion = entry.getValue();
|
||||
if (expansion.getName().equalsIgnoreCase(name)) {
|
||||
bestMatch = expansion;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Optional.ofNullable(bestMatch);
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void load(@NotNull final CommandSender sender) {
|
||||
registerAll(sender);
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
unregisterAll();
|
||||
}
|
||||
@NotNull
|
||||
public Optional<PlaceholderExpansion> findExpansionByIdentifier(
|
||||
@NotNull final String identifier) {
|
||||
return Optional.ofNullable(getExpansion(identifier));
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public File getExpansionsFolder() {
|
||||
return folder;
|
||||
}
|
||||
public Optional<PlaceholderExpansion> register(
|
||||
@NotNull final Class<? extends PlaceholderExpansion> clazz) {
|
||||
try {
|
||||
final PlaceholderExpansion expansion = createExpansionInstance(clazz);
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Collection<String> getIdentifiers() {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
return ImmutableSet.copyOf(expansions.keySet());
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Unmodifiable
|
||||
public Collection<PlaceholderExpansion> getExpansions() {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
return ImmutableSet.copyOf(expansions.values());
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PlaceholderExpansion getExpansion(@NotNull final String identifier) {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
return expansions.get(identifier.toLowerCase(Locale.ROOT));
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Optional<PlaceholderExpansion> findExpansionByName(@NotNull final String name) {
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
PlaceholderExpansion bestMatch = null;
|
||||
for (Map.Entry<String, PlaceholderExpansion> entry : expansions.entrySet()) {
|
||||
PlaceholderExpansion expansion = entry.getValue();
|
||||
if (expansion.getName().equalsIgnoreCase(name)) {
|
||||
bestMatch = expansion;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Optional.ofNullable(bestMatch);
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Optional<PlaceholderExpansion> findExpansionByIdentifier(
|
||||
@NotNull final String identifier) {
|
||||
return Optional.ofNullable(getExpansion(identifier));
|
||||
}
|
||||
|
||||
|
||||
public Optional<PlaceholderExpansion> register(
|
||||
@NotNull final Class<? extends PlaceholderExpansion> clazz) {
|
||||
try {
|
||||
final PlaceholderExpansion expansion = createExpansionInstance(clazz);
|
||||
|
||||
if (expansion == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Objects.requireNonNull(expansion.getAuthor(), "The expansion author is null!");
|
||||
Objects.requireNonNull(expansion.getIdentifier(), "The expansion identifier is null!");
|
||||
Objects.requireNonNull(expansion.getVersion(), "The expansion version is null!");
|
||||
|
||||
if (expansion.getRequiredPlugin() != null && !expansion.getRequiredPlugin().isEmpty()) {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled(expansion.getRequiredPlugin())) {
|
||||
Msg.warn("Cannot load expansion %s due to a missing plugin: %s", expansion.getIdentifier(),
|
||||
expansion.getRequiredPlugin());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
expansion.setExpansionType(PlaceholderExpansion.Type.EXTERNAL);
|
||||
|
||||
if (!expansion.register()) {
|
||||
Msg.warn("Cannot load expansion %s due to an unknown issue.", expansion.getIdentifier());
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(expansion);
|
||||
} catch (LinkageError | NullPointerException ex) {
|
||||
final String reason;
|
||||
|
||||
if (ex instanceof LinkageError) {
|
||||
reason = " (Is a dependency missing?)";
|
||||
} else {
|
||||
reason = " - One of its properties is null which is not allowed!";
|
||||
}
|
||||
|
||||
Msg.severe("Failed to load expansion class %s%s", ex, clazz.getSimpleName(), reason);
|
||||
}
|
||||
Objects.requireNonNull(expansion.getAuthor(), "The expansion author is null!");
|
||||
Objects.requireNonNull(expansion.getIdentifier(), "The expansion identifier is null!");
|
||||
Objects.requireNonNull(expansion.getVersion(), "The expansion version is null!");
|
||||
|
||||
if (!expansion.register()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(expansion);
|
||||
} catch (LinkageError | NullPointerException ex) {
|
||||
final String reason;
|
||||
|
||||
if (ex instanceof LinkageError) {
|
||||
reason = " (Is a dependency missing?)";
|
||||
} else {
|
||||
reason = " - One of its properties is null which is not allowed!";
|
||||
}
|
||||
|
||||
plugin.getLogger().severe("Failed to load expansion class " + clazz.getSimpleName() +
|
||||
reason);
|
||||
plugin.getLogger().log(Level.SEVERE, "", ex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to register a {@link PlaceholderExpansion}
|
||||
*
|
||||
* @param expansion the expansion to register
|
||||
* @return if the expansion was registered
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public boolean register(@NotNull final PlaceholderExpansion expansion) {
|
||||
final String identifier = expansion.getIdentifier().toLowerCase(Locale.ROOT);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
if (!expansion.canRegister()) {
|
||||
return false;
|
||||
}
|
||||
@ApiStatus.Internal
|
||||
public boolean register(@NotNull final PlaceholderExpansion expansion) {
|
||||
final String identifier = expansion.getIdentifier().toLowerCase();
|
||||
|
||||
// Avoid loading two external expansions with the same identifier
|
||||
if (expansion.getExpansionType() == PlaceholderExpansion.Type.EXTERNAL && expansions.containsKey(identifier)) {
|
||||
Msg.warn("Failed to load external expansion %s. Identifier is already in use.", expansion.getIdentifier());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expansion instanceof Configurable) {
|
||||
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
|
||||
String pre = "expansions." + identifier + ".";
|
||||
FileConfiguration cfg = plugin.getConfig();
|
||||
boolean save = false;
|
||||
|
||||
if (defaults != null) {
|
||||
for (Map.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())) {
|
||||
Msg.warn("Your server version is incompatible with expansion %s %s",
|
||||
expansion.getIdentifier(), expansion.getVersion());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final PlaceholderExpansion removed = getExpansion(identifier);
|
||||
if (removed != null && !removed.unregister()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ExpansionRegisterEvent event = new ExpansionRegisterEvent(expansion);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
expansions.put(identifier, expansion);
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
|
||||
if (expansion instanceof Listener) {
|
||||
Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin);
|
||||
}
|
||||
|
||||
Msg.info(
|
||||
"Successfully registered %s expansion: %s [%s]",
|
||||
expansion.getExpansionType().name().toLowerCase(),
|
||||
expansion.getIdentifier(),
|
||||
expansion.getVersion()
|
||||
);
|
||||
|
||||
if (expansion instanceof Taskable) {
|
||||
((Taskable) expansion).start();
|
||||
}
|
||||
|
||||
// Check eCloud for updates only if the expansion is external
|
||||
if (plugin.getPlaceholderAPIConfig().isCloudEnabled() && expansion.getExpansionType() == PlaceholderExpansion.Type.EXTERNAL) {
|
||||
final Optional<CloudExpansion> cloudExpansionOptional = plugin.getCloudExpansionManager().findCloudExpansionByName(identifier);
|
||||
if (cloudExpansionOptional.isPresent()) {
|
||||
CloudExpansion cloudExpansion = cloudExpansionOptional.get();
|
||||
cloudExpansion.setHasExpansion(true);
|
||||
cloudExpansion.setShouldUpdate(!cloudExpansion.getLatestVersion().equals(expansion.getVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
if (!expansion.canRegister()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public boolean unregister(@NotNull final PlaceholderExpansion expansion) {
|
||||
if (expansions.remove(expansion.getIdentifier().toLowerCase(Locale.ROOT)) == null) {
|
||||
return false;
|
||||
}
|
||||
if (expansion instanceof Configurable) {
|
||||
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
|
||||
String pre = "expansions." + identifier + ".";
|
||||
FileConfiguration cfg = plugin.getConfig();
|
||||
boolean save = false;
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(expansion));
|
||||
if (defaults != null) {
|
||||
for (Map.Entry<String, Object> entries : defaults.entrySet()) {
|
||||
if (entries.getKey() == null || entries.getKey().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (expansion instanceof Listener) {
|
||||
HandlerList.unregisterAll((Listener) expansion);
|
||||
}
|
||||
|
||||
if (expansion instanceof Taskable) {
|
||||
((Taskable) expansion).stop();
|
||||
}
|
||||
|
||||
if (expansion instanceof Cacheable) {
|
||||
((Cacheable) expansion).clear();
|
||||
}
|
||||
|
||||
if (plugin.getPlaceholderAPIConfig().isCloudEnabled()) {
|
||||
plugin.getCloudExpansionManager().findCloudExpansionByName(expansion.getName())
|
||||
.ifPresent(cloud -> {
|
||||
cloud.setHasExpansion(false);
|
||||
cloud.setShouldUpdate(false);
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void registerAll(@NotNull final CommandSender sender) {
|
||||
Msg.info("Placeholder expansion registration initializing...");
|
||||
|
||||
Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> {
|
||||
if (exception != null) {
|
||||
Msg.severe("Failed to load class files of expansion.", exception);
|
||||
return;
|
||||
if (entries.getValue() == null) {
|
||||
if (cfg.contains(pre + entries.getKey())) {
|
||||
save = true;
|
||||
cfg.set(pre + entries.getKey(), null);
|
||||
}
|
||||
|
||||
final List<PlaceholderExpansion> registered = classes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::register)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final long needsUpdate = registered.stream()
|
||||
.map(expansion -> plugin.getCloudExpansionManager().findCloudExpansionByName(expansion.getName()).orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.filter(CloudExpansion::shouldUpdate)
|
||||
.count();
|
||||
|
||||
StringBuilder message = new StringBuilder(registered.size() == 0 ? "&6" : "&a")
|
||||
.append(registered.size())
|
||||
.append(' ')
|
||||
.append("placeholder hook(s) registered!");
|
||||
|
||||
if (needsUpdate > 0) {
|
||||
message.append(' ')
|
||||
.append("&6")
|
||||
.append(needsUpdate)
|
||||
.append(' ')
|
||||
.append("placeholder hook(s) have an update available.");
|
||||
} else {
|
||||
if (!cfg.contains(pre + entries.getKey())) {
|
||||
save = true;
|
||||
cfg.set(pre + entries.getKey(), entries.getValue());
|
||||
}
|
||||
|
||||
|
||||
Msg.msg(sender, message.toString());
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionsLoadedEvent(registered));
|
||||
});
|
||||
}
|
||||
|
||||
private void unregisterAll() {
|
||||
for (final PlaceholderExpansion expansion : Sets.newHashSet(expansions.values())) {
|
||||
if (expansion.persist()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
expansion.unregister();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (save) {
|
||||
plugin.saveConfig();
|
||||
plugin.reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompletableFuture<@NotNull List<@Nullable Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() {
|
||||
File[] files = folder.listFiles((dir, name) -> name.endsWith(".jar"));
|
||||
if (files == null) {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
if (expansion instanceof VersionSpecific) {
|
||||
VersionSpecific nms = (VersionSpecific) expansion;
|
||||
if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
|
||||
plugin.getLogger().warning("Your server version is not compatible with expansion " +
|
||||
expansion.getIdentifier() + " " + expansion.getVersion());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final PlaceholderExpansion removed = getExpansion(identifier);
|
||||
if (removed != null && !removed.unregister()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ExpansionRegisterEvent event = new ExpansionRegisterEvent(expansion);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
expansionsLock.lock();
|
||||
try {
|
||||
expansions.put(identifier, expansion);
|
||||
} finally {
|
||||
expansionsLock.unlock();
|
||||
}
|
||||
|
||||
if (expansion instanceof Listener) {
|
||||
Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin);
|
||||
}
|
||||
|
||||
plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier());
|
||||
|
||||
if (expansion instanceof Taskable) {
|
||||
((Taskable) expansion).start();
|
||||
}
|
||||
|
||||
if (plugin.getPlaceholderAPIConfig().isCloudEnabled()) {
|
||||
final Optional<CloudExpansion> cloudExpansionOptional =
|
||||
plugin.getCloudExpansionManager().findCloudExpansionByName(identifier);
|
||||
if (cloudExpansionOptional.isPresent()) {
|
||||
CloudExpansion cloudExpansion = cloudExpansionOptional.get();
|
||||
cloudExpansion.setHasExpansion(true);
|
||||
cloudExpansion.setShouldUpdate(
|
||||
!cloudExpansion.getLatestVersion().equals(expansion.getVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public boolean unregister(@NotNull final PlaceholderExpansion expansion) {
|
||||
if (expansions.remove(expansion.getIdentifier()) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(expansion));
|
||||
|
||||
if (expansion instanceof Listener) {
|
||||
HandlerList.unregisterAll((Listener) expansion);
|
||||
}
|
||||
|
||||
if (expansion instanceof Taskable) {
|
||||
((Taskable) expansion).stop();
|
||||
}
|
||||
|
||||
if (expansion instanceof Cacheable) {
|
||||
((Cacheable) expansion).clear();
|
||||
}
|
||||
|
||||
if (plugin.getPlaceholderAPIConfig().isCloudEnabled()) {
|
||||
plugin.getCloudExpansionManager().findCloudExpansionByName(expansion.getName())
|
||||
.ifPresent(cloud -> {
|
||||
cloud.setHasExpansion(false);
|
||||
cloud.setShouldUpdate(false);
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void registerAll(@NotNull final CommandSender sender) {
|
||||
plugin.getLogger().info("Placeholder expansion registration initializing...");
|
||||
|
||||
Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> {
|
||||
if (exception != null) {
|
||||
plugin.getLogger().log(Level.SEVERE, "failed to load class files of expansions", exception);
|
||||
return;
|
||||
}
|
||||
|
||||
final long registered = classes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::register)
|
||||
.filter(Optional::isPresent)
|
||||
.count();
|
||||
|
||||
Msg.msg(sender,
|
||||
registered == 0 ? "&6No expansions were registered!"
|
||||
: registered + "&a placeholder hooks successfully registered!");
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionsLoadedEvent());
|
||||
});
|
||||
}
|
||||
|
||||
private void unregisterAll() {
|
||||
for (final PlaceholderExpansion expansion : Sets.newHashSet(expansions.values())) {
|
||||
if (expansion.persist()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
expansion.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompletableFuture<@NotNull List<@Nullable Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() {
|
||||
return Arrays.stream(folder.listFiles((dir, name) -> name.endsWith(".jar")))
|
||||
.map(this::findExpansionInFile)
|
||||
.collect(Futures.collector());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompletableFuture<@Nullable Class<? extends PlaceholderExpansion>> findExpansionInFile(
|
||||
@NotNull final File file) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class);
|
||||
|
||||
if (expansionClass == null) {
|
||||
plugin.getLogger().severe("Failed to load Expansion: " + file.getName() + ", as it does not have" +
|
||||
" a class which extends PlaceholderExpansion.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return Arrays.stream(files)
|
||||
.map(this::findExpansionInFile)
|
||||
.collect(Futures.collector());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompletableFuture<@Nullable Class<? extends PlaceholderExpansion>> findExpansionInFile(
|
||||
@NotNull final File file) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class);
|
||||
|
||||
if (expansionClass == null) {
|
||||
Msg.severe("Failed to load expansion %s, as it does not have a class which"
|
||||
+ " extends PlaceholderExpansion", file.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<MethodSignature> expansionMethods = Arrays.stream(expansionClass.getDeclaredMethods())
|
||||
.map(method -> new MethodSignature(method.getName(), method.getParameterTypes()))
|
||||
.collect(Collectors.toSet());
|
||||
if (!expansionMethods.containsAll(ABSTRACT_EXPANSION_METHODS)) {
|
||||
Msg.severe("Failed to load expansion %s, as it does not have the required"
|
||||
+ " methods declared for a PlaceholderExpansion.", file.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
return expansionClass;
|
||||
} catch (VerifyError | NoClassDefFoundError e) {
|
||||
Msg.severe("Failed to load expansion %s (is a dependency missing?)", e, file.getName());
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to load expansion file: " + file.getAbsolutePath(), e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public PlaceholderExpansion createExpansionInstance(
|
||||
@NotNull final Class<? extends PlaceholderExpansion> clazz) throws LinkageError {
|
||||
try {
|
||||
return clazz.getDeclaredConstructor().newInstance();
|
||||
} catch (final Exception ex) {
|
||||
if (ex.getCause() instanceof LinkageError) {
|
||||
throw ((LinkageError) ex.getCause());
|
||||
}
|
||||
|
||||
Msg.warn("There was an issue with loading an expansion.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(@NotNull final PlayerQuitEvent event) {
|
||||
for (final PlaceholderExpansion expansion : getExpansions()) {
|
||||
if (!(expansion instanceof Cleanable)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
((Cleanable) expansion).cleanup(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPluginDisable(@NotNull final PluginDisableEvent event) {
|
||||
final String name = event.getPlugin().getName();
|
||||
if (name.equals(plugin.getName())) {
|
||||
return;
|
||||
Set<MethodSignature> expansionMethods = Arrays.stream(expansionClass.getDeclaredMethods())
|
||||
.map(method -> new MethodSignature(method.getName(), method.getParameterTypes()))
|
||||
.collect(Collectors.toSet());
|
||||
if (!expansionMethods.containsAll(ABSTRACT_EXPANSION_METHODS)) {
|
||||
plugin.getLogger().severe("Failed to load Expansion: " + file.getName() + ", as it does not have the" +
|
||||
" required methods declared for a PlaceholderExpansion.");
|
||||
return null;
|
||||
}
|
||||
|
||||
for (final PlaceholderExpansion expansion : getExpansions()) {
|
||||
if (!name.equalsIgnoreCase(expansion.getRequiredPlugin())) {
|
||||
continue;
|
||||
}
|
||||
return expansionClass;
|
||||
} catch (final VerifyError ex) {
|
||||
plugin.getLogger().severe("Failed to load Expansion class " + file.getName() +
|
||||
" (Is a dependency missing?)");
|
||||
plugin.getLogger().severe("Cause: " + ex.getClass().getSimpleName() + " " + ex.getMessage());
|
||||
return null;
|
||||
} catch (final Exception ex) {
|
||||
throw new CompletionException(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
expansion.unregister();
|
||||
Msg.info("Unregistered placeholder expansion %s", expansion.getIdentifier());
|
||||
Msg.info("Reason: required plugin %s was disabled.", name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PlaceholderExpansion createExpansionInstance(
|
||||
@NotNull final Class<? extends PlaceholderExpansion> clazz) throws LinkageError {
|
||||
try {
|
||||
return clazz.getDeclaredConstructor().newInstance();
|
||||
} catch (final Exception ex) {
|
||||
if (ex.getCause() instanceof LinkageError) {
|
||||
throw ((LinkageError) ex.getCause());
|
||||
}
|
||||
|
||||
plugin.getLogger().warning("There was an issue with loading an expansion.");
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(@NotNull final PlayerQuitEvent event) {
|
||||
for (final PlaceholderExpansion expansion : getExpansions()) {
|
||||
if (!(expansion instanceof Cleanable)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
((Cleanable) expansion).cleanup(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPluginDisable(@NotNull final PluginDisableEvent event) {
|
||||
final String name = event.getPlugin().getName();
|
||||
if (name.equals(plugin.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final PlaceholderExpansion expansion : getExpansions()) {
|
||||
if (!name.equalsIgnoreCase(expansion.getRequiredPlugin())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
expansion.unregister();
|
||||
plugin.getLogger().info("Unregistered placeholder expansion: " + expansion.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
/*
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI 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.
|
||||
*
|
||||
* PlaceholderAPI 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.expansion.manager;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
|
||||
@@ -1,140 +1,178 @@
|
||||
/*
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI 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.
|
||||
*
|
||||
* PlaceholderAPI 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.replacer;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class CharsReplacer implements Replacer {
|
||||
|
||||
@NotNull
|
||||
private final Closure closure;
|
||||
|
||||
public CharsReplacer(@NotNull final Closure closure) {
|
||||
this.closure = closure;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
|
||||
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup) {
|
||||
final char[] chars = text.toCharArray();
|
||||
// Woo! Hlello %player_name%
|
||||
// Woo! GHsda PiggyPiglet
|
||||
final StringBuilder builder = new StringBuilder(text.length());
|
||||
|
||||
final StringBuilder identifier = new StringBuilder();
|
||||
final StringBuilder parameters = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
final char l = chars[i];
|
||||
|
||||
if (l != closure.head || i + 1 >= chars.length) {
|
||||
builder.append(l);
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean identified = false;
|
||||
boolean invalid = true;
|
||||
boolean hadSpace = false;
|
||||
|
||||
while (++i < chars.length) {
|
||||
final char p = chars[i];
|
||||
|
||||
if (p == ' ' && !identified) {
|
||||
hadSpace = true;
|
||||
break;
|
||||
}
|
||||
if (p == closure.tail) {
|
||||
invalid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (p == '_' && !identified) {
|
||||
identified = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identified) {
|
||||
parameters.append(p);
|
||||
} else {
|
||||
identifier.append(p);
|
||||
}
|
||||
}
|
||||
|
||||
final String identifierString = identifier.toString();
|
||||
final String lowercaseIdentifierString = identifierString.toLowerCase(Locale.ROOT);
|
||||
final String parametersString = parameters.toString();
|
||||
|
||||
identifier.setLength(0);
|
||||
parameters.setLength(0);
|
||||
|
||||
if (invalid) {
|
||||
builder.append(closure.head).append(identifierString);
|
||||
|
||||
if (identified) {
|
||||
builder.append('_').append(parametersString);
|
||||
}
|
||||
|
||||
if (hadSpace) {
|
||||
builder.append(' ');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
final PlaceholderExpansion placeholder = lookup.apply(lowercaseIdentifierString);
|
||||
if (placeholder == null) {
|
||||
builder.append(closure.head).append(identifierString);
|
||||
|
||||
if (identified) {
|
||||
builder.append('_');
|
||||
}
|
||||
|
||||
builder.append(parametersString).append(closure.tail);
|
||||
continue;
|
||||
}
|
||||
|
||||
final String replacement = placeholder.onRequest(player, parametersString);
|
||||
if (replacement == null) {
|
||||
builder.append(closure.head).append(identifierString);
|
||||
|
||||
if (identified) {
|
||||
builder.append('_');
|
||||
}
|
||||
|
||||
builder.append(parametersString).append(closure.tail);
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.append(replacement);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI 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.
|
||||
*
|
||||
* PlaceholderAPI 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.replacer;
|
||||
|
||||
import java.util.function.Function;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class CharsReplacer implements Replacer {
|
||||
|
||||
@NotNull
|
||||
private final Closure closure;
|
||||
|
||||
public CharsReplacer(@NotNull final Closure closure) {
|
||||
this.closure = closure;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
|
||||
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup) {
|
||||
final char[] chars = text.toCharArray();
|
||||
final StringBuilder builder = new StringBuilder(text.length());
|
||||
|
||||
final StringBuilder identifier = new StringBuilder();
|
||||
final StringBuilder parameters = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
final char l = chars[i];
|
||||
|
||||
if (l == '&' && ++i < chars.length) {
|
||||
final char c = Character.toLowerCase(chars[i]);
|
||||
|
||||
if (c != '0' && c != '1' && c != '2' && c != '3' && c != '4' && c != '5' && c != '6'
|
||||
&& c != '7' && c != '8' && c != '9' && c != 'a' && c != 'b' && c != 'c' && c != 'd'
|
||||
&& c != 'e' && c != 'f' && c != 'k' && c != 'l' && c != 'm' && c != 'n' && c != 'o' && c != 'r'
|
||||
&& c != 'x') {
|
||||
builder.append(l).append(chars[i]);
|
||||
} else {
|
||||
builder.append(ChatColor.COLOR_CHAR);
|
||||
|
||||
if (c != 'x') {
|
||||
builder.append(chars[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((i > 1 && chars[i - 2] == '\\') /*allow escaping &x*/) {
|
||||
builder.setLength(builder.length() - 2);
|
||||
builder.append('&').append(chars[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.append(c);
|
||||
|
||||
int j = 0;
|
||||
while (++j <= 6) {
|
||||
if (i + j >= chars.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
final char x = chars[i + j];
|
||||
builder.append(ChatColor.COLOR_CHAR).append(x);
|
||||
}
|
||||
|
||||
if (j == 7) {
|
||||
i += 6;
|
||||
} else {
|
||||
builder.setLength(builder.length() - (j * 2)); // undo &x parsing
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (l != closure.head || i + 1 >= chars.length) {
|
||||
builder.append(l);
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean identified = false;
|
||||
boolean oopsitsbad = true;
|
||||
boolean hadSpace = false;
|
||||
|
||||
while (++i < chars.length) {
|
||||
final char p = chars[i];
|
||||
|
||||
if (p == ' ' && !identified) {
|
||||
hadSpace = true;
|
||||
break;
|
||||
}
|
||||
if (p == closure.tail) {
|
||||
oopsitsbad = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (p == '_' && !identified) {
|
||||
identified = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identified) {
|
||||
parameters.append(p);
|
||||
} else {
|
||||
identifier.append(p);
|
||||
}
|
||||
}
|
||||
|
||||
final String identifierString = identifier.toString().toLowerCase();
|
||||
final String parametersString = parameters.toString();
|
||||
|
||||
identifier.setLength(0);
|
||||
parameters.setLength(0);
|
||||
|
||||
if (oopsitsbad) {
|
||||
builder.append(closure.head).append(identifier);
|
||||
|
||||
if (identified) {
|
||||
builder.append('_').append(parametersString);
|
||||
}
|
||||
|
||||
if (hadSpace) {
|
||||
builder.append(' ');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
final PlaceholderExpansion placeholder = lookup.apply(identifierString);
|
||||
if (placeholder == null) {
|
||||
builder.append(closure.head).append(identifierString);
|
||||
|
||||
if (identified) {
|
||||
builder.append('_');
|
||||
}
|
||||
|
||||
builder.append(parametersString).append(closure.tail);
|
||||
continue;
|
||||
}
|
||||
|
||||
final String replacement = placeholder.onRequest(player, parametersString);
|
||||
if (replacement == null) {
|
||||
builder.append(closure.head).append(identifierString);
|
||||
|
||||
if (identified) {
|
||||
builder.append('_');
|
||||
}
|
||||
|
||||
builder.append(parametersString).append(closure.tail);
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.append(ChatColor.translateAlternateColorCodes('&', replacement));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
package me.clip.placeholderapi.replacer;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.kyori.adventure.text.*;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class ComponentReplacer {
|
||||
public Component replace(Component component, OfflinePlayer player, Function<String, PlaceholderExpansion> function) {
|
||||
Component modified = component;
|
||||
|
||||
final List<Component> oldChildren = component.children();
|
||||
final int oldChildrenSize = oldChildren.size();
|
||||
List<Component> children = null;
|
||||
|
||||
if (component instanceof TextComponent) {
|
||||
TextComponent tc = (TextComponent) component;
|
||||
final String content = tc.content();
|
||||
|
||||
final char[] chars = content.toCharArray();
|
||||
|
||||
final StringBuilder identifier = new StringBuilder();
|
||||
final StringBuilder parameters = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
final char l = chars[i];
|
||||
|
||||
if (l != '%' || i + 1 >= chars.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int start = i;
|
||||
|
||||
boolean identified = false;
|
||||
boolean invalid = true;
|
||||
|
||||
while (++i < chars.length) {
|
||||
final char p = chars[i];
|
||||
|
||||
if (p == ' ' && !identified) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (p == '%') {
|
||||
invalid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (p == '_' && !identified) {
|
||||
identified = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identified) {
|
||||
parameters.append(p);
|
||||
} else {
|
||||
identifier.append(p);
|
||||
}
|
||||
}
|
||||
|
||||
final String identifierString = identifier.toString();
|
||||
final String lowercaseIdentifierString = identifierString.toLowerCase(Locale.ROOT);
|
||||
final String parametersString = parameters.toString();
|
||||
|
||||
identifier.setLength(0);
|
||||
parameters.setLength(0);
|
||||
|
||||
if (invalid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final PlaceholderExpansion expansion = function.apply(lowercaseIdentifierString);
|
||||
|
||||
if (expansion == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String placeholderValue = expansion.onRequest(player, parametersString);
|
||||
|
||||
if (placeholderValue == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (start == 0) {
|
||||
// if we're a full match, modify the component directly
|
||||
if (i == content.length() - 1) {
|
||||
final ComponentLike replacement = Component.text(placeholderValue).style(component.style());
|
||||
|
||||
modified = replacement.asComponent();
|
||||
Style modStyle = modified.style();
|
||||
|
||||
if (modStyle.hoverEvent() != null) {
|
||||
Object hoverValue = modStyle.hoverEvent().value();
|
||||
|
||||
if (hoverValue instanceof Component) {
|
||||
final Component replacedHoverComponent = replace((Component) hoverValue, player, function);
|
||||
|
||||
if (replacedHoverComponent != hoverValue) {
|
||||
modified.style();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (modStyle.clickEvent() != null) {
|
||||
String clickValue =
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (component instanceof TranslatableComponent) {
|
||||
TranslatableComponent tc = (TranslatableComponent) component;
|
||||
final List<TranslationArgument> args = tc.arguments();
|
||||
List<TranslationArgument> newArgs = null;
|
||||
for (int i = 0, size = args.size(); i < size; i++) {
|
||||
final TranslationArgument original = args.get(i);
|
||||
TranslationArgument replacement = original instanceof Component ? TranslationArgument.component(replace((Component) original, player, function)) : original;
|
||||
|
||||
if (original != replacement) {
|
||||
if (newArgs == null) {
|
||||
newArgs = new ArrayList<>(size);
|
||||
|
||||
if (i > 0) {
|
||||
newArgs.addAll(args.subList(0, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newArgs != null) {
|
||||
newArgs.add(replacement);
|
||||
}
|
||||
}
|
||||
|
||||
if (newArgs != null) {
|
||||
modified = ((TranslatableComponent) modified).arguments(newArgs);
|
||||
}
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package me.clip.placeholderapi.replacer;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ExactReplacer implements Replacer {
|
||||
private static final Pattern DELIMITER = Pattern.compile("_");
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String apply(@NotNull String text, @Nullable final OfflinePlayer player,
|
||||
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup) {
|
||||
text = text.substring(1, text.length() - 1);
|
||||
final String[] parts = DELIMITER.split(text);
|
||||
final PlaceholderExpansion expansion;
|
||||
|
||||
if (parts.length == 0) {
|
||||
expansion = lookup.apply(text);
|
||||
} else {
|
||||
expansion = lookup.apply(parts[0]);
|
||||
}
|
||||
|
||||
if (expansion == null) {
|
||||
return text;
|
||||
}
|
||||
|
||||
final String params;
|
||||
|
||||
if (text.endsWith("_")) {
|
||||
params = "";
|
||||
} else {
|
||||
params = text.substring(text.indexOf('_') + 1);
|
||||
}
|
||||
|
||||
final String result = expansion.onRequest(player, params);
|
||||
|
||||
if (result == null) {
|
||||
return text;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI 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.
|
||||
*
|
||||
* PlaceholderAPI 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.replacer;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class RegexReplacer implements Replacer {
|
||||
|
||||
@NotNull
|
||||
private final Pattern pattern;
|
||||
|
||||
public RegexReplacer(@NotNull final Closure closure) {
|
||||
this.pattern = Pattern.compile(String
|
||||
.format("\\%s((?<identifier>[a-zA-Z0-9]+)_)(?<parameters>[^%s%s]+)\\%s", closure.head,
|
||||
closure.head, closure.tail, closure.tail));
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
|
||||
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup) {
|
||||
final Matcher matcher = pattern.matcher(text);
|
||||
if (!matcher.find()) {
|
||||
return text;
|
||||
}
|
||||
|
||||
final StringBuffer builder = new StringBuffer();
|
||||
|
||||
do {
|
||||
final String identifier = matcher.group("identifier");
|
||||
final String parameters = matcher.group("parameters");
|
||||
|
||||
final PlaceholderExpansion expansion = lookup.apply(identifier);
|
||||
if (expansion == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String requested = expansion.onRequest(player, parameters);
|
||||
matcher.appendReplacement(builder, requested != null ? requested : matcher.group(0));
|
||||
}
|
||||
while (matcher.find());
|
||||
|
||||
return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(builder).toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.replacer;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,22 +28,22 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface Replacer {
|
||||
|
||||
@NotNull
|
||||
String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
|
||||
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup);
|
||||
@NotNull
|
||||
String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
|
||||
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup);
|
||||
|
||||
|
||||
enum Closure {
|
||||
BRACKET('{', '}'),
|
||||
PERCENT('%', '%');
|
||||
enum Closure {
|
||||
BRACKET('{', '}'),
|
||||
PERCENT('%', '%');
|
||||
|
||||
|
||||
public final char head, tail;
|
||||
public final char head, tail;
|
||||
|
||||
Closure(final char head, final char tail) {
|
||||
this.head = head;
|
||||
this.tail = tail;
|
||||
}
|
||||
Closure(final char head, final char tail) {
|
||||
this.head = head;
|
||||
this.tail = tail;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler;
|
||||
|
||||
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
|
||||
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/** Just modified BukkitRunnable */
|
||||
public abstract class UniversalRunnable implements Runnable {
|
||||
MyScheduledTask task;
|
||||
|
||||
public synchronized void cancel() throws IllegalStateException {
|
||||
checkScheduled();
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this task has been cancelled.
|
||||
*
|
||||
* @return true if the task has been cancelled
|
||||
* @throws IllegalStateException if task was not scheduled yet
|
||||
*/
|
||||
public synchronized boolean isCancelled() throws IllegalStateException {
|
||||
checkScheduled();
|
||||
return task.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules this in the Bukkit scheduler to run on next tick.
|
||||
*
|
||||
* @param plugin the reference to the plugin scheduling task
|
||||
* @return {@link MyScheduledTask}
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @see TaskScheduler#runTask(Runnable)
|
||||
*/
|
||||
|
||||
public synchronized MyScheduledTask runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
|
||||
checkNotYetScheduled();
|
||||
return setupTask(UniversalScheduler.getScheduler(plugin).runTask(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Asynchronous tasks should never access any API in Bukkit. Great care
|
||||
* should be taken to assure the thread-safety of asynchronous tasks.</b>
|
||||
* <p>
|
||||
* Schedules this in the Bukkit scheduler to run asynchronously.
|
||||
*
|
||||
* @param plugin the reference to the plugin scheduling task
|
||||
* @return {@link MyScheduledTask}
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @see TaskScheduler#runTaskAsynchronously(Runnable)
|
||||
*/
|
||||
|
||||
public synchronized MyScheduledTask runTaskAsynchronously(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
|
||||
checkNotYetScheduled();
|
||||
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskAsynchronously(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules this to run after the specified number of server ticks.
|
||||
*
|
||||
* @param plugin the reference to the plugin scheduling task
|
||||
* @param delay the ticks to wait before running the task
|
||||
* @return {@link MyScheduledTask}
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @see TaskScheduler#runTaskLater(Runnable, long)
|
||||
*/
|
||||
|
||||
public synchronized MyScheduledTask runTaskLater(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException {
|
||||
checkNotYetScheduled();
|
||||
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskLater(this, delay));
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Asynchronous tasks should never access any API in Bukkit. Great care
|
||||
* should be taken to assure the thread-safety of asynchronous tasks.</b>
|
||||
* <p>
|
||||
* Schedules this to run asynchronously after the specified number of
|
||||
* server ticks.
|
||||
*
|
||||
* @param plugin the reference to the plugin scheduling task
|
||||
* @param delay the ticks to wait before running the task
|
||||
* @return {@link MyScheduledTask}
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @see TaskScheduler#runTaskLaterAsynchronously(Runnable, long)
|
||||
*/
|
||||
|
||||
public synchronized MyScheduledTask runTaskLaterAsynchronously(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException {
|
||||
checkNotYetScheduled();
|
||||
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskLaterAsynchronously(this, delay));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules this to repeatedly run until cancelled, starting after the
|
||||
* specified number of server ticks.
|
||||
*
|
||||
* @param plugin the reference to the plugin scheduling task
|
||||
* @param delay the ticks to wait before running the task
|
||||
* @param period the ticks to wait between runs
|
||||
* @return {@link MyScheduledTask}
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @see TaskScheduler#runTaskTimer(Runnable, long, long)
|
||||
*/
|
||||
|
||||
public synchronized MyScheduledTask runTaskTimer(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException {
|
||||
checkNotYetScheduled();
|
||||
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskTimer(this, delay, period));
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Asynchronous tasks should never access any API in Bukkit. Great care
|
||||
* should be taken to assure the thread-safety of asynchronous tasks.</b>
|
||||
* <p>
|
||||
* Schedules this to repeatedly run asynchronously until cancelled,
|
||||
* starting after the specified number of server ticks.
|
||||
*
|
||||
* @param plugin the reference to the plugin scheduling task
|
||||
* @param delay the ticks to wait before running the task for the first
|
||||
* time
|
||||
* @param period the ticks to wait between runs
|
||||
* @return {@link MyScheduledTask}
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @see TaskScheduler#runTaskTimerAsynchronously(Runnable, long, long)
|
||||
*/
|
||||
|
||||
public synchronized MyScheduledTask runTaskTimerAsynchronously(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException {
|
||||
checkNotYetScheduled();
|
||||
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskTimerAsynchronously(this, delay, period));
|
||||
}
|
||||
|
||||
private void checkScheduled() {
|
||||
if (task == null) {
|
||||
throw new IllegalStateException("Not scheduled yet");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNotYetScheduled() {
|
||||
if (task != null) {
|
||||
throw new IllegalStateException("Already scheduled");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private MyScheduledTask setupTask(final MyScheduledTask task) {
|
||||
this.task = task;
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler;
|
||||
|
||||
import me.clip.placeholderapi.scheduler.bukkit.BukkitScheduler;
|
||||
import me.clip.placeholderapi.scheduler.folia.FoliaScheduler;
|
||||
import me.clip.placeholderapi.scheduler.paper.PaperScheduler;
|
||||
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
|
||||
import me.clip.placeholderapi.scheduler.utils.JavaUtil;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class UniversalScheduler {
|
||||
private static final boolean IS_FOLIA = JavaUtil.classExists("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
private static final boolean IS_CANVAS = JavaUtil.classExists("io.canvasmc.canvas.server.ThreadedServer");
|
||||
private static final boolean IS_EXPANDED_SCHEDULING_AVAILABLE = JavaUtil.classExists("io.papermc.paper.threadedregions.scheduler.ScheduledTask");
|
||||
|
||||
public static TaskScheduler getScheduler(Plugin plugin) {
|
||||
return IS_FOLIA || IS_CANVAS ? new FoliaScheduler(plugin) : (IS_EXPANDED_SCHEDULING_AVAILABLE ? new PaperScheduler(plugin) : new BukkitScheduler(plugin));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler.bukkit;
|
||||
|
||||
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class BukkitScheduledTask implements MyScheduledTask {
|
||||
|
||||
BukkitTask task;
|
||||
|
||||
boolean isRepeating;
|
||||
|
||||
public BukkitScheduledTask(final BukkitTask task) {
|
||||
this.task = task;
|
||||
this.isRepeating = false;
|
||||
}
|
||||
|
||||
public BukkitScheduledTask(final BukkitTask task, boolean isRepeating) {
|
||||
this.task = task;
|
||||
this.isRepeating = isRepeating;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return task.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getOwningPlugin() {
|
||||
return task.getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrentlyRunning() {
|
||||
return Bukkit.getServer().getScheduler().isCurrentlyRunning(this.task.getTaskId()); //There's no other way. Fuck bukkit
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRepeatingTask() {
|
||||
return isRepeating;
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler.bukkit;
|
||||
|
||||
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
|
||||
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class BukkitScheduler implements TaskScheduler {
|
||||
final Plugin plugin;
|
||||
|
||||
public BukkitScheduler(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlobalThread() {
|
||||
return Bukkit.getServer().isPrimaryThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityThread(Entity entity) {
|
||||
return Bukkit.getServer().isPrimaryThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegionThread(Location location) {
|
||||
return Bukkit.getServer().isPrimaryThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTask(Runnable runnable) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTask(plugin, runnable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLater(Runnable runnable, long delay) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskLater(plugin, runnable, delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimer(Runnable runnable, long delay, long period) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskAsynchronously(Runnable runnable) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLaterAsynchronously(Runnable runnable, long delay) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, runnable, delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimerAsynchronously(Runnable runnable, long delay, long period) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, delay, period));
|
||||
}
|
||||
|
||||
//Useless? Or...
|
||||
public MyScheduledTask runTask(Plugin plugin, Runnable runnable) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTask(plugin, runnable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskLater(plugin, runnable, delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskAsynchronously(Plugin plugin, Runnable runnable) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLaterAsynchronously(Plugin plugin, Runnable runnable, long delay) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, runnable, delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
|
||||
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, delay, period));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTasks() {
|
||||
Bukkit.getScheduler().cancelTasks(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTasks(Plugin plugin) {
|
||||
Bukkit.getScheduler().cancelTasks(plugin);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler.folia;
|
||||
|
||||
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class FoliaScheduledTask implements MyScheduledTask {
|
||||
private final ScheduledTask task;
|
||||
|
||||
public FoliaScheduledTask(final ScheduledTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
this.task.cancel();
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return this.task.isCancelled();
|
||||
}
|
||||
|
||||
public Plugin getOwningPlugin() {
|
||||
return this.task.getOwningPlugin();
|
||||
}
|
||||
|
||||
public boolean isCurrentlyRunning() {
|
||||
final ScheduledTask.ExecutionState state = this.task.getExecutionState();
|
||||
return state == ScheduledTask.ExecutionState.RUNNING || state == ScheduledTask.ExecutionState.CANCELLED_RUNNING;
|
||||
}
|
||||
|
||||
public boolean isRepeatingTask() {
|
||||
return this.task.isRepeatingTask();
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler.folia;
|
||||
|
||||
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
|
||||
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
|
||||
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler;
|
||||
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
|
||||
import io.papermc.paper.threadedregions.scheduler.RegionScheduler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FoliaScheduler implements TaskScheduler {
|
||||
|
||||
final Plugin plugin;
|
||||
|
||||
public FoliaScheduler(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private final RegionScheduler regionScheduler = Bukkit.getServer().getRegionScheduler();
|
||||
private final GlobalRegionScheduler globalRegionScheduler = Bukkit.getServer().getGlobalRegionScheduler();
|
||||
private final AsyncScheduler asyncScheduler = Bukkit.getServer().getAsyncScheduler();
|
||||
|
||||
@Override
|
||||
public boolean isGlobalThread() {
|
||||
return Bukkit.getServer().isGlobalTickThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTickThread() {
|
||||
return Bukkit.getServer().isPrimaryThread(); // The Paper implementation checks whether this is a tick thread, this method exists to avoid confusion.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityThread(Entity entity) {
|
||||
return Bukkit.getServer().isOwnedByCurrentRegion(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegionThread(Location location) {
|
||||
return Bukkit.getServer().isOwnedByCurrentRegion(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTask(Runnable runnable) {
|
||||
return new FoliaScheduledTask(globalRegionScheduler.run(plugin, task -> runnable.run()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLater(Runnable runnable, long delay) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
if (delay <= 0) {
|
||||
return runTask(runnable);
|
||||
}
|
||||
return new FoliaScheduledTask(globalRegionScheduler.runDelayed(plugin, task -> runnable.run(), delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimer(Runnable runnable, long delay, long period) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
delay = getOneIfNotPositive(delay);
|
||||
return new FoliaScheduledTask(globalRegionScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay, period));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTask(Plugin plugin, Runnable runnable) {
|
||||
return new FoliaScheduledTask(globalRegionScheduler.run(plugin, task -> runnable.run()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
if (delay <= 0) {
|
||||
return runTask(plugin, runnable);
|
||||
}
|
||||
return new FoliaScheduledTask(globalRegionScheduler.runDelayed(plugin, task -> runnable.run(), delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
delay = getOneIfNotPositive(delay);
|
||||
return new FoliaScheduledTask(globalRegionScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay, period));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTask(Location location, Runnable runnable) {
|
||||
return new FoliaScheduledTask(regionScheduler.run(plugin, location, task -> runnable.run()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLater(Location location, Runnable runnable, long delay) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
if (delay <= 0) {
|
||||
return runTask(runnable);
|
||||
}
|
||||
return new FoliaScheduledTask(regionScheduler.runDelayed(plugin, location, task -> runnable.run(), delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimer(Location location, Runnable runnable, long delay, long period) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
delay = getOneIfNotPositive(delay);
|
||||
return new FoliaScheduledTask(regionScheduler.runAtFixedRate(plugin, location, task -> runnable.run(), delay, period));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTask(Entity entity, Runnable runnable) {
|
||||
return new FoliaScheduledTask(entity.getScheduler().run(plugin, task -> runnable.run(), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLater(Entity entity, Runnable runnable, long delay) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
if (delay <= 0) {
|
||||
return runTask(entity, runnable);
|
||||
}
|
||||
return new FoliaScheduledTask(entity.getScheduler().runDelayed(plugin, task -> runnable.run(), null, delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimer(Entity entity, Runnable runnable, long delay, long period) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
delay = getOneIfNotPositive(delay);
|
||||
return new FoliaScheduledTask(entity.getScheduler().runAtFixedRate(plugin, task -> runnable.run(), null, delay, period));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskAsynchronously(Runnable runnable) {
|
||||
return new FoliaScheduledTask(asyncScheduler.runNow(plugin, task -> runnable.run()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLaterAsynchronously(Runnable runnable, long delay) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
delay = getOneIfNotPositive(delay);
|
||||
return new FoliaScheduledTask(asyncScheduler.runDelayed(plugin, task -> runnable.run(), delay * 50L, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimerAsynchronously(Runnable runnable, long delay, long period) {
|
||||
return new FoliaScheduledTask(asyncScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay * 50, period * 50, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskAsynchronously(Plugin plugin, Runnable runnable) {
|
||||
return new FoliaScheduledTask(asyncScheduler.runNow(plugin, task -> runnable.run()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskLaterAsynchronously(Plugin plugin, Runnable runnable, long delay) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
delay = getOneIfNotPositive(delay);
|
||||
return new FoliaScheduledTask(asyncScheduler.runDelayed(plugin, task -> runnable.run(), delay * 50L, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyScheduledTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
|
||||
//Folia exception: Delay ticks may not be <= 0
|
||||
delay = getOneIfNotPositive(delay);
|
||||
return new FoliaScheduledTask(asyncScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay * 50, period * 50, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable runnable) {
|
||||
globalRegionScheduler.execute(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Location location, Runnable runnable) {
|
||||
regionScheduler.execute(plugin, location, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Entity entity, Runnable runnable) {
|
||||
entity.getScheduler().execute(plugin, runnable, null, 1L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTasks() {
|
||||
globalRegionScheduler.cancelTasks(plugin);
|
||||
asyncScheduler.cancelTasks(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTasks(Plugin plugin) {
|
||||
globalRegionScheduler.cancelTasks(plugin);
|
||||
asyncScheduler.cancelTasks(plugin);
|
||||
}
|
||||
|
||||
private long getOneIfNotPositive(long x) {
|
||||
return x <= 0 ? 1L : x;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler.paper;
|
||||
|
||||
import me.clip.placeholderapi.scheduler.folia.FoliaScheduler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
//Thanks to Towny
|
||||
public class PaperScheduler extends FoliaScheduler {
|
||||
public PaperScheduler(Plugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlobalThread() {
|
||||
// isGlobalThread does not exist on paper, match the bukkit task scheduler's behaviour.
|
||||
return Bukkit.getServer().isPrimaryThread();
|
||||
}
|
||||
}
|
||||
@@ -1,346 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler.scheduling.schedulers;
|
||||
|
||||
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public interface TaskScheduler {
|
||||
|
||||
/**
|
||||
* <b>Folia</b>: Returns whether the current thread is ticking the global region <br>
|
||||
* <b>Paper & Bukkit</b>: Returns {@link org.bukkit.Server#isPrimaryThread}
|
||||
*/
|
||||
boolean isGlobalThread();
|
||||
|
||||
/**
|
||||
* @return {@link org.bukkit.Server#isPrimaryThread}
|
||||
*/
|
||||
default boolean isTickThread() {
|
||||
return Bukkit.getServer().isPrimaryThread();
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Folia & Paper</b>: Returns whether the current thread is ticking a region and that the region
|
||||
* being ticked owns the specified entity. Note that this function is the only appropriate method of
|
||||
* checking for ownership of an entity, as retrieving the entity's location is undefined unless the
|
||||
* entity is owned by the current region
|
||||
* <p>
|
||||
* <b>Bukkit</b>: returns {@link org.bukkit.Server#isPrimaryThread}
|
||||
*
|
||||
* @param entity Specified entity
|
||||
*/
|
||||
boolean isEntityThread(Entity entity);
|
||||
|
||||
/**
|
||||
* <b>Folia & Paper</b>: Returns whether the current thread is ticking a region and that the region
|
||||
* being ticked owns the chunk at the specified world and block position as included in the specified location
|
||||
* <p>
|
||||
* <b>Bukkit</b>: returns {@link org.bukkit.Server#isPrimaryThread}
|
||||
*
|
||||
* @param location Specified location, must have a non-null world.
|
||||
*/
|
||||
boolean isRegionThread(Location location);
|
||||
|
||||
/**
|
||||
* Schedules a task to be executed on the next tick <br>
|
||||
* <b>Folia & Paper</b>: ...on the global region <br>
|
||||
* <b>Bukkit</b>: ...on the main thread
|
||||
*
|
||||
* @param runnable The task to execute
|
||||
*/
|
||||
MyScheduledTask runTask(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Schedules a task to be executed after the specified delay in ticks <br>
|
||||
* <b>Folia & Paper</b>: ...on the global region <br>
|
||||
* <b>Bukkit</b>: ...on the main thread
|
||||
*
|
||||
* @param runnable The task to execute
|
||||
* @param delay The delay, in ticks
|
||||
*/
|
||||
MyScheduledTask runTaskLater(Runnable runnable, long delay);
|
||||
|
||||
/**
|
||||
* Schedules a repeating task to be executed after the initial delay with the specified period <br>
|
||||
* <b>Folia & Paper</b>: ...on the global region <br>
|
||||
* <b>Bukkit</b>: ...on the main thread
|
||||
*
|
||||
* @param runnable The task to execute
|
||||
* @param delay The initial delay, in ticks.
|
||||
* @param period The period, in ticks.
|
||||
*/
|
||||
MyScheduledTask runTaskTimer(Runnable runnable, long delay, long period);
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #runTask(Runnable)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask runTask(Plugin plugin, Runnable runnable) {
|
||||
return runTask(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #runTaskLater(Runnable, long)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
|
||||
return runTaskLater(runnable, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #runTaskTimer(Runnable, long, long)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
|
||||
return runTaskTimer(runnable, delay, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Folia & Paper</b>: Schedules a task to be executed on the region which owns the location on the next tick
|
||||
* <p>
|
||||
* <b>Bukkit</b>: same as {@link #runTask(Runnable)}
|
||||
*
|
||||
* @param location The location which the region executing should own
|
||||
* @param runnable The task to execute
|
||||
*/
|
||||
default MyScheduledTask runTask(Location location, Runnable runnable) {
|
||||
return runTask(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Folia & Paper</b>: Schedules a task to be executed on the region which owns the location after the
|
||||
* specified delay in ticks
|
||||
* <p>
|
||||
* <b>Bukkit</b>: same as {@link #runTaskLater(Runnable, long)}
|
||||
*
|
||||
* @param location The location which the region executing should own
|
||||
* @param runnable The task to execute
|
||||
* @param delay The delay, in ticks.
|
||||
*/
|
||||
default MyScheduledTask runTaskLater(Location location, Runnable runnable, long delay) {
|
||||
return runTaskLater(runnable, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Folia & Paper</b>: Schedules a repeating task to be executed on the region which owns the location
|
||||
* after the initial delay with the specified period
|
||||
* <p>
|
||||
* <b>Bukkit</b>: same as {@link #runTaskTimer(Runnable, long, long)}
|
||||
*
|
||||
* @param location The location which the region executing should own
|
||||
* @param runnable The task to execute
|
||||
* @param delay The initial delay, in ticks.
|
||||
* @param period The period, in ticks.
|
||||
*/
|
||||
default MyScheduledTask runTaskTimer(Location location, Runnable runnable, long delay, long period) {
|
||||
return runTaskTimer(runnable, delay, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #runTaskLater(Runnable, long)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask scheduleSyncDelayedTask(Runnable runnable, long delay) {
|
||||
return runTaskLater(runnable, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #execute(Runnable)} or {@link #runTask(Runnable)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask scheduleSyncDelayedTask(Runnable runnable) {
|
||||
return runTask(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #runTaskTimer(Runnable, long, long)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask scheduleSyncRepeatingTask(Runnable runnable, long delay, long period) {
|
||||
return runTaskTimer(runnable, delay, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Folia & Paper</b>: Schedules a task to be executed on the region which owns the location
|
||||
* of given entity on the next tick
|
||||
* <p>
|
||||
* <b>Bukkit</b>: same as {@link #runTask(Runnable)}
|
||||
*
|
||||
* @param entity The entity whose location the region executing should own
|
||||
* @param runnable The task to execute
|
||||
*/
|
||||
default MyScheduledTask runTask(Entity entity, Runnable runnable) {
|
||||
return runTask(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Folia & Paper</b>: Schedules a task to be executed on the region which owns the location
|
||||
* of given entity after the specified delay in ticks
|
||||
* <p>
|
||||
* <b>Bukkit</b>: same as {@link #runTaskLater(Runnable, long)}
|
||||
*
|
||||
* @param entity The entity whose location the region executing should own
|
||||
* @param runnable The task to execute
|
||||
* @param delay The delay, in ticks.
|
||||
*/
|
||||
default MyScheduledTask runTaskLater(Entity entity, Runnable runnable, long delay) {
|
||||
return runTaskLater(runnable, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Folia & Paper</b>: Schedules a repeating task to be executed on the region which owns the
|
||||
* location of given entity after the initial delay with the specified period
|
||||
* <p>
|
||||
* <b>Bukkit</b>: same as {@link #runTaskTimer(Runnable, long, long)}
|
||||
*
|
||||
* @param entity The entity whose location the region executing should own
|
||||
* @param runnable The task to execute
|
||||
* @param delay The initial delay, in ticks.
|
||||
* @param period The period, in ticks.
|
||||
*/
|
||||
default MyScheduledTask runTaskTimer(Entity entity, Runnable runnable, long delay, long period) {
|
||||
return runTaskTimer(runnable, delay, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the specified task to be executed asynchronously immediately
|
||||
*
|
||||
* @param runnable The task to execute
|
||||
* @return The {@link MyScheduledTask} that represents the scheduled task
|
||||
*/
|
||||
MyScheduledTask runTaskAsynchronously(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Schedules the specified task to be executed asynchronously after the time delay has passed
|
||||
*
|
||||
* @param runnable The task to execute
|
||||
* @param delay The time delay to pass before the task should be executed
|
||||
* @return The {@link MyScheduledTask} that represents the scheduled task
|
||||
*/
|
||||
MyScheduledTask runTaskLaterAsynchronously(Runnable runnable, long delay);
|
||||
|
||||
/**
|
||||
* Schedules the specified task to be executed asynchronously after the initial delay has passed,
|
||||
* and then periodically executed with the specified period
|
||||
*
|
||||
* @param runnable The task to execute
|
||||
* @param delay The time delay to pass before the first execution of the task, in ticks
|
||||
* @param period The time between task executions after the first execution of the task, in ticks
|
||||
* @return The {@link MyScheduledTask} that represents the scheduled task
|
||||
*/
|
||||
MyScheduledTask runTaskTimerAsynchronously(Runnable runnable, long delay, long period);
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #runTaskAsynchronously(Runnable)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask runTaskAsynchronously(Plugin plugin, Runnable runnable) {
|
||||
return runTaskAsynchronously(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #runTaskLaterAsynchronously(Runnable, long)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask runTaskLaterAsynchronously(Plugin plugin, Runnable runnable, long delay) {
|
||||
return runTaskLaterAsynchronously(runnable, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated: use {@link #runTaskTimerAsynchronously(Runnable, long, long)}
|
||||
*/
|
||||
@Deprecated
|
||||
default MyScheduledTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
|
||||
return runTaskTimerAsynchronously(runnable, delay, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a method on the main thread and returns a Future object. This task will be executed
|
||||
* by the main(Bukkit)/global(Folia&Paper) server thread.
|
||||
* <p>
|
||||
* Note: The Future.get() methods must NOT be called from the main thread.
|
||||
* <p>
|
||||
* Note2: There is at least an average of 10ms latency until the isDone() method returns true.
|
||||
*
|
||||
* @param task Task to be executed
|
||||
*/
|
||||
default <T> Future<T> callSyncMethod(final Callable<T> task) {
|
||||
CompletableFuture<T> completableFuture = new CompletableFuture<>();
|
||||
execute(() -> {
|
||||
try {
|
||||
completableFuture.complete(task.call());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a task to be executed on the global region
|
||||
*
|
||||
* @param runnable The task to execute
|
||||
*/
|
||||
void execute(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Schedules a task to be executed on the region which owns the location
|
||||
*
|
||||
* @param location The location which the region executing should own
|
||||
* @param runnable The task to execute
|
||||
*/
|
||||
default void execute(Location location, Runnable runnable) {
|
||||
execute(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a task to be executed on the region which owns the location of given entity
|
||||
*
|
||||
* @param entity The entity which location the region executing should own
|
||||
* @param runnable The task to execute
|
||||
*/
|
||||
default void execute(Entity entity, Runnable runnable) {
|
||||
execute(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to cancel all tasks scheduled by this plugin
|
||||
*/
|
||||
void cancelTasks();
|
||||
|
||||
/**
|
||||
* Attempts to cancel all tasks scheduled by the specified plugin
|
||||
*
|
||||
* @param plugin specified plugin
|
||||
*/
|
||||
void cancelTasks(Plugin plugin);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Sevastjan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.clip.placeholderapi.scheduler.scheduling.tasks;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public interface MyScheduledTask {
|
||||
/**
|
||||
* Cancels executing task
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* @return true if task is cancelled, false otherwise
|
||||
*/
|
||||
boolean isCancelled();
|
||||
|
||||
/**
|
||||
* @return The plugin under which the task was scheduled.
|
||||
*/
|
||||
Plugin getOwningPlugin();
|
||||
|
||||
/**
|
||||
* @return true if task is currently executing, false otherwise
|
||||
*/
|
||||
boolean isCurrentlyRunning();
|
||||
|
||||
/**
|
||||
* @return true if task is repeating, false otherwise
|
||||
*/
|
||||
boolean isRepeatingTask();
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package me.clip.placeholderapi.scheduler.utils;
|
||||
|
||||
public class JavaUtil {
|
||||
public static boolean classExists(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -26,7 +26,6 @@ import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -36,17 +35,15 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class UpdateChecker implements Listener {
|
||||
|
||||
private static final int RESOURCE_ID = 6245;
|
||||
private final int RESOURCE_ID = 6245;
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
private final TaskScheduler scheduler;
|
||||
private final String pluginVersion;
|
||||
private String spigotVersion;
|
||||
private boolean updateAvailable;
|
||||
|
||||
public UpdateChecker(PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
scheduler = plugin.getScheduler();
|
||||
pluginVersion = plugin.getDescription().getVersion();
|
||||
public UpdateChecker(PlaceholderAPIPlugin i) {
|
||||
plugin = i;
|
||||
pluginVersion = i.getDescription().getVersion();
|
||||
}
|
||||
|
||||
public boolean hasUpdateAvailable() {
|
||||
@@ -58,7 +55,7 @@ public class UpdateChecker implements Listener {
|
||||
}
|
||||
|
||||
public void fetch() {
|
||||
scheduler.runTaskAsynchronously(() -> {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(
|
||||
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
|
||||
@@ -79,7 +76,7 @@ public class UpdateChecker implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
scheduler.runTask(() -> {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
plugin.getLogger()
|
||||
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
|
||||
plugin.getLogger()
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -34,44 +34,44 @@ import java.util.jar.JarInputStream;
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
@Nullable
|
||||
public static <T> Class<? extends T> findClass(@NotNull final File file,
|
||||
@NotNull final Class<T> clazz) throws IOException, ClassNotFoundException {
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final URL jar = file.toURI().toURL();
|
||||
final URLClassLoader loader = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader());
|
||||
final List<String> matches = new ArrayList<>();
|
||||
final List<Class<? extends T>> classes = new ArrayList<>();
|
||||
|
||||
try (final JarInputStream stream = new JarInputStream(jar.openStream())) {
|
||||
JarEntry entry;
|
||||
while ((entry = stream.getNextJarEntry()) != null) {
|
||||
final String name = entry.getName();
|
||||
if (name.isEmpty() || !name.endsWith(".class")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
matches.add(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
|
||||
}
|
||||
|
||||
for (final String match : matches) {
|
||||
try {
|
||||
final Class<?> loaded = loader.loadClass(match);
|
||||
if (clazz.isAssignableFrom(loaded)) {
|
||||
classes.add(loaded.asSubclass(clazz));
|
||||
}
|
||||
} catch (final NoClassDefFoundError ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (classes.isEmpty()) {
|
||||
loader.close();
|
||||
return null;
|
||||
}
|
||||
return classes.get(0);
|
||||
@Nullable
|
||||
public static <T> Class<? extends T> findClass(@NotNull final File file,
|
||||
@NotNull final Class<T> clazz) throws IOException, ClassNotFoundException {
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final URL jar = file.toURI().toURL();
|
||||
final URLClassLoader loader = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader());
|
||||
final List<String> matches = new ArrayList<>();
|
||||
final List<Class<? extends T>> classes = new ArrayList<>();
|
||||
|
||||
try (final JarInputStream stream = new JarInputStream(jar.openStream())) {
|
||||
JarEntry entry;
|
||||
while ((entry = stream.getNextJarEntry()) != null) {
|
||||
final String name = entry.getName();
|
||||
if (name.isEmpty() || !name.endsWith(".class")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
matches.add(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
|
||||
}
|
||||
|
||||
for (final String match : matches) {
|
||||
try {
|
||||
final Class<?> loaded = loader.loadClass(match);
|
||||
if (clazz.isAssignableFrom(loaded)) {
|
||||
classes.add(loaded.asSubclass(clazz));
|
||||
}
|
||||
} catch (final NoClassDefFoundError ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (classes.isEmpty()) {
|
||||
loader.close();
|
||||
return null;
|
||||
}
|
||||
return classes.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -29,7 +29,6 @@ import static java.util.stream.IntStream.range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -37,35 +36,35 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public final class Format {
|
||||
|
||||
private Format() {}
|
||||
private Format() {}
|
||||
|
||||
@NotNull
|
||||
public static Optional<List<String>> tablify(@NotNull final Align align,
|
||||
@NotNull final List<List<String>> rows) {
|
||||
return findSpacing(rows)
|
||||
.map(spacing -> buildFormat(align, spacing))
|
||||
.map(format -> rows.stream()
|
||||
.map(
|
||||
row -> String.format(format, row.toArray()).substring(align == Align.RIGHT ? 2 : 0))
|
||||
.collect(toList()));
|
||||
}
|
||||
@NotNull
|
||||
public static Optional<List<String>> tablify(@NotNull final Align align,
|
||||
@NotNull final List<List<String>> rows) {
|
||||
return findSpacing(rows)
|
||||
.map(spacing -> buildFormat(align, spacing))
|
||||
.map(format -> rows.stream()
|
||||
.map(
|
||||
row -> String.format(format, row.toArray()).substring(align == Align.RIGHT ? 2 : 0))
|
||||
.collect(toList()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String buildFormat(@NotNull final Align align, final int[] spacing) {
|
||||
return stream(spacing)
|
||||
.mapToObj(space -> "%" + (align == Align.LEFT ? "-" : "") + (space + 2) + "s")
|
||||
.collect(joining());
|
||||
}
|
||||
@NotNull
|
||||
private static String buildFormat(@NotNull final Align align, final int[] spacing) {
|
||||
return stream(spacing)
|
||||
.mapToObj(space -> "%" + (align == Align.LEFT ? "-" : "") + (space + 2) + "s")
|
||||
.collect(joining());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Optional<int[]> findSpacing(@NotNull final List<List<String>> rows) {
|
||||
return rows.stream()
|
||||
.map(row -> row.stream().mapToInt(String::length).toArray())
|
||||
.reduce((l, r) -> range(0, min(l.length, r.length)).map(i -> max(l[i], r[i])).toArray());
|
||||
}
|
||||
@NotNull
|
||||
private static Optional<int[]> findSpacing(@NotNull final List<List<String>> rows) {
|
||||
return rows.stream()
|
||||
.map(row -> row.stream().mapToInt(String::length).toArray())
|
||||
.reduce((l, r) -> range(0, min(l.length, r.length)).map(i -> max(l[i], r[i])).toArray());
|
||||
}
|
||||
|
||||
public enum Align {
|
||||
LEFT, RIGHT
|
||||
}
|
||||
public enum Align {
|
||||
LEFT, RIGHT
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -27,53 +27,51 @@ import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class Futures {
|
||||
|
||||
private Futures() {}
|
||||
private Futures() {}
|
||||
|
||||
|
||||
public static <T> void onMainThread(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CompletableFuture<T> future,
|
||||
@NotNull final BiConsumer<T, Throwable> consumer) {
|
||||
future.whenComplete((value, exception) -> {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
consumer.accept(value, exception);
|
||||
} else {
|
||||
plugin.getScheduler().runTask(() -> consumer.accept(value, exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
public static <T> void onMainThread(@NotNull final Plugin plugin,
|
||||
@NotNull final CompletableFuture<T> future,
|
||||
@NotNull final BiConsumer<T, Throwable> consumer) {
|
||||
future.whenComplete((value, exception) -> {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
consumer.accept(value, exception);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(value, exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<List<T>>> collector() {
|
||||
return Collectors.collectingAndThen(Collectors.toList(), Futures::of);
|
||||
}
|
||||
@NotNull
|
||||
public static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<List<T>>> collector() {
|
||||
return Collectors.collectingAndThen(Collectors.toList(), Futures::of);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static <T> CompletableFuture<List<T>> of(
|
||||
@NotNull final Stream<CompletableFuture<T>> futures) {
|
||||
return of(futures.collect(Collectors.toList()));
|
||||
}
|
||||
@NotNull
|
||||
public static <T> CompletableFuture<List<T>> of(
|
||||
@NotNull final Stream<CompletableFuture<T>> futures) {
|
||||
return of(futures.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> CompletableFuture<List<T>> of(
|
||||
@NotNull final Collection<CompletableFuture<T>> futures) {
|
||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
|
||||
.thenApplyAsync($ -> awaitCompletion(futures));
|
||||
}
|
||||
@NotNull
|
||||
public static <T> CompletableFuture<List<T>> of(
|
||||
@NotNull final Collection<CompletableFuture<T>> futures) {
|
||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
|
||||
.thenApplyAsync($ -> awaitCompletion(futures));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <T> List<T> awaitCompletion(
|
||||
@NotNull final Collection<CompletableFuture<T>> futures) {
|
||||
return futures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||
}
|
||||
@NotNull
|
||||
private static <T> List<T> awaitCompletion(
|
||||
@NotNull final Collection<CompletableFuture<T>> futures) {
|
||||
return futures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,10 +21,7 @@
|
||||
package me.clip.placeholderapi.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -32,49 +29,25 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class Msg {
|
||||
|
||||
public static void log(Level level, String msg, Object... args) {
|
||||
PlaceholderAPIPlugin.getInstance().getLogger().log(level, String.format(msg, args));
|
||||
public static void msg(@NotNull final CommandSender sender, @NotNull final String... messages) {
|
||||
if (messages.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static void info(String msg, Object... args) {
|
||||
log(Level.INFO, msg, args);
|
||||
sender.sendMessage(Arrays.stream(messages).map(Msg::color).collect(Collectors.joining("\n")));
|
||||
}
|
||||
|
||||
public static void broadcast(@NotNull final String... messages) {
|
||||
if (messages.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static void warn(String msg, Object... args) {
|
||||
log(Level.WARNING, msg, args);
|
||||
}
|
||||
Bukkit.broadcastMessage(
|
||||
Arrays.stream(messages).map(Msg::color).collect(Collectors.joining("\n")));
|
||||
}
|
||||
|
||||
public static void warn(String msg, Throwable throwable, Object... args) {
|
||||
PlaceholderAPIPlugin.getInstance().getLogger().log(Level.WARNING, String.format(msg, args), throwable);
|
||||
}
|
||||
|
||||
public static void severe(String msg, Object... args) {
|
||||
log(Level.SEVERE, msg, args);
|
||||
}
|
||||
|
||||
public static void severe(String msg, Throwable throwable, Object... args) {
|
||||
PlaceholderAPIPlugin.getInstance().getLogger().log(Level.SEVERE, String.format(msg, args), throwable);
|
||||
}
|
||||
|
||||
public static void msg(@NotNull final CommandSender sender, @NotNull final String... messages) {
|
||||
if (messages.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(Arrays.stream(messages).map(Msg::color).collect(Collectors.joining("\n")));
|
||||
}
|
||||
|
||||
public static void broadcast(@NotNull final String... messages) {
|
||||
if (messages.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.broadcastMessage(
|
||||
Arrays.stream(messages).map(Msg::color).collect(Collectors.joining("\n")));
|
||||
}
|
||||
|
||||
public static String color(@NotNull final String text) {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
public static String color(@NotNull final String text) {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -21,8 +21,8 @@
|
||||
package me.clip.placeholderapi.util;
|
||||
|
||||
public enum TimeFormat {
|
||||
DAYS,
|
||||
HOURS,
|
||||
MINUTES,
|
||||
SECONDS
|
||||
DAYS,
|
||||
HOURS,
|
||||
MINUTES,
|
||||
SECONDS
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* PlaceholderAPI 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.
|
||||
@@ -26,71 +26,71 @@ import java.util.StringJoiner;
|
||||
|
||||
public class TimeUtil {
|
||||
|
||||
public static String getRemaining(final int seconds, final TimeFormat type) {
|
||||
return getRemaining((long) seconds, type);
|
||||
public static String getRemaining(final int seconds, final TimeFormat type) {
|
||||
return getRemaining((long) seconds, type);
|
||||
}
|
||||
|
||||
public static String getRemaining(final long seconds, final TimeFormat type) {
|
||||
switch (type) {
|
||||
default:
|
||||
return String.valueOf(seconds);
|
||||
|
||||
case SECONDS:
|
||||
return String.valueOf(seconds % 60);
|
||||
|
||||
case MINUTES:
|
||||
return String.valueOf((seconds / 60) % 60);
|
||||
|
||||
case HOURS:
|
||||
return String.valueOf((seconds / 3600) % 24);
|
||||
|
||||
case DAYS:
|
||||
return String.valueOf(seconds / 86400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given value with s, m, h and d (seconds, minutes, hours and days)
|
||||
*
|
||||
* @param duration {@link Duration} (eg, Duration.of(20, {@link ChronoUnit#SECONDS}) for 20
|
||||
* seconds)
|
||||
* @return formatted time
|
||||
*/
|
||||
public static String getTime(final Duration duration) {
|
||||
return getTime(duration.getSeconds());
|
||||
}
|
||||
|
||||
public static String getTime(final int seconds) {
|
||||
return getTime((long) seconds);
|
||||
}
|
||||
|
||||
public static String getTime(long seconds) {
|
||||
final StringJoiner joiner = new StringJoiner(" ");
|
||||
|
||||
long minutes = seconds / 60;
|
||||
long hours = minutes / 60;
|
||||
final long days = hours / 24;
|
||||
|
||||
seconds %= 60;
|
||||
minutes %= 60;
|
||||
hours %= 24;
|
||||
|
||||
if (days > 0) {
|
||||
joiner.add(days + "d");
|
||||
}
|
||||
|
||||
public static String getRemaining(final long seconds, final TimeFormat type) {
|
||||
switch (type) {
|
||||
default:
|
||||
return String.valueOf(seconds);
|
||||
|
||||
case SECONDS:
|
||||
return String.valueOf(seconds % 60);
|
||||
|
||||
case MINUTES:
|
||||
return String.valueOf((seconds / 60) % 60);
|
||||
|
||||
case HOURS:
|
||||
return String.valueOf((seconds / 3600) % 24);
|
||||
|
||||
case DAYS:
|
||||
return String.valueOf(seconds / 86400);
|
||||
}
|
||||
if (hours > 0) {
|
||||
joiner.add(hours + "h");
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given value with s, m, h and d (seconds, minutes, hours and days)
|
||||
*
|
||||
* @param duration {@link Duration} (eg, Duration.of(20, {@link ChronoUnit#SECONDS}) for 20
|
||||
* seconds)
|
||||
* @return formatted time
|
||||
*/
|
||||
public static String getTime(final Duration duration) {
|
||||
return getTime(duration.getSeconds());
|
||||
if (minutes > 0) {
|
||||
joiner.add(minutes + "m");
|
||||
}
|
||||
|
||||
public static String getTime(final int seconds) {
|
||||
return getTime((long) seconds);
|
||||
if (seconds > 0) {
|
||||
joiner.add(seconds + "s");
|
||||
}
|
||||
|
||||
public static String getTime(long seconds) {
|
||||
final StringJoiner joiner = new StringJoiner(" ");
|
||||
|
||||
long minutes = seconds / 60;
|
||||
long hours = minutes / 60;
|
||||
final long days = hours / 24;
|
||||
|
||||
seconds %= 60;
|
||||
minutes %= 60;
|
||||
hours %= 24;
|
||||
|
||||
if (days > 0) {
|
||||
joiner.add(days + "d");
|
||||
}
|
||||
|
||||
if (hours > 0) {
|
||||
joiner.add(hours + "h");
|
||||
}
|
||||
|
||||
if (minutes > 0) {
|
||||
joiner.add(minutes + "m");
|
||||
}
|
||||
|
||||
if (seconds > 0) {
|
||||
joiner.add(seconds + "s");
|
||||
}
|
||||
|
||||
return joiner.toString();
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
# PlaceholderAPI
|
||||
# Version: ${version}
|
||||
# Version: @version@
|
||||
# Created by: extended_clip
|
||||
# Contributors: https://github.com/PlaceholderAPI/PlaceholderAPI/graphs/contributors
|
||||
# Issues: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
|
||||
# Expansions: https://placeholderapi.com/ecloud
|
||||
# Wiki: https://wiki.placeholderapi.com/
|
||||
# Expansions: https://api.extendedclip.com/all/
|
||||
# Wiki: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki
|
||||
# Discord: https://helpch.at/discord
|
||||
# No placeholders are provided with this plugin by default.
|
||||
# Download placeholders: /papi ecloud
|
||||
check_updates: true
|
||||
cloud_enabled: true
|
||||
cloud_sorting: "name"
|
||||
cloud_allow_unverified_expansions: false
|
||||
boolean:
|
||||
'true': 'yes'
|
||||
'false': 'no'
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
name: PlaceholderAPI
|
||||
name: "@name@"
|
||||
main: "me.clip.placeholderapi.PlaceholderAPIPlugin"
|
||||
folia-supported: true
|
||||
|
||||
version: ${version}
|
||||
version: "@version@"
|
||||
author: HelpChat
|
||||
|
||||
api-version: "1.13"
|
||||
description: "An awesome placeholder provider!"
|
||||
description: "@description@"
|
||||
|
||||
commands:
|
||||
placeholderapi:
|
||||
description: "PlaceholderAPI Command"
|
||||
aliases: ["papi"]
|
||||
test:
|
||||
description: "yes"
|
||||
|
||||
permissions:
|
||||
placeholderapi.*:
|
||||
@@ -40,6 +37,7 @@ permissions:
|
||||
placeholderapi.ecloud.info: true
|
||||
placeholderapi.ecloud.list: true
|
||||
placeholderapi.ecloud.clear: true
|
||||
placeholderapi.ecloud.toggle: true
|
||||
placeholderapi.ecloud.status: true
|
||||
placeholderapi.ecloud.update: true
|
||||
placeholderapi.ecloud.refresh: true
|
||||
@@ -84,6 +82,9 @@ permissions:
|
||||
placeholderapi.ecloud.clear:
|
||||
default: "op"
|
||||
description: "Allows you to clear the local eCloud expansion cache"
|
||||
placeholderapi.ecloud.toggle:
|
||||
default: "op"
|
||||
description: "Allows you to toggle/enable/disable the eCloud manager"
|
||||
placeholderapi.ecloud.status:
|
||||
default: "op"
|
||||
description: "Allows you to view the status of eCloud expansions"
|
||||
@@ -98,4 +99,4 @@ permissions:
|
||||
description: "Allows you to download an expansion from the eCloud"
|
||||
placeholderapi.ecloud.placeholders:
|
||||
default: "op"
|
||||
description: "Allows you to view the placeholders of a eCloud expansion"
|
||||
description: "Allows you to view the placeholders of a eCloud expansion"
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -23,6 +23,7 @@ package me.clip.placeholderapi;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.replacer.CharsReplacer;
|
||||
import me.clip.placeholderapi.replacer.RegexReplacer;
|
||||
import me.clip.placeholderapi.replacer.Replacer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -39,6 +40,7 @@ public interface Values {
|
||||
|
||||
|
||||
Replacer CHARS_REPLACER = new CharsReplacer(Replacer.Closure.PERCENT);
|
||||
Replacer REGEX_REPLACER = new RegexReplacer(Replacer.Closure.PERCENT);
|
||||
|
||||
|
||||
final class MockPlayerPlaceholderExpansion extends PlaceholderExpansion {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -30,9 +30,19 @@ public class ReplacerBenchmarks {
|
||||
Values.CHARS_REPLACER.apply(Values.SMALL_TEXT, null, Values.PLACEHOLDERS::get);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void measureRegexReplacerSmallText() {
|
||||
Values.REGEX_REPLACER.apply(Values.SMALL_TEXT, null, Values.PLACEHOLDERS::get);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void measureCharsReplacerLargeText() {
|
||||
Values.CHARS_REPLACER.apply(Values.LARGE_TEXT, null, Values.PLACEHOLDERS::get);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void measureRegexReplacerLargeText() {
|
||||
Values.REGEX_REPLACER.apply(Values.LARGE_TEXT, null, Values.PLACEHOLDERS::get);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2024 PlaceholderAPI Team
|
||||
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -37,6 +37,12 @@ public final class ReplacerUnitTester {
|
||||
Values.CHARS_REPLACER.apply("%player_name%", null, Values.PLACEHOLDERS::get));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegexReplacerProducesExpectedSingleValue() {
|
||||
assertEquals(PLAYER_NAME,
|
||||
Values.REGEX_REPLACER.apply("%player_name%", null, Values.PLACEHOLDERS::get));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharsReplacerProducesExpectedSentence() {
|
||||
assertEquals(String.format(
|
||||
@@ -45,14 +51,36 @@ public final class ReplacerUnitTester {
|
||||
Values.CHARS_REPLACER.apply(Values.LARGE_TEXT, null, Values.PLACEHOLDERS::get));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegexReplacerProducesExpectedSentence() {
|
||||
assertEquals(String.format(
|
||||
"My name is %s and my location is (%s, %s, %s), this placeholder is invalid %%server_name%%",
|
||||
PLAYER_NAME, PLAYER_X, PLAYER_Y, PLAYER_Z),
|
||||
Values.REGEX_REPLACER.apply(Values.LARGE_TEXT, null, Values.PLACEHOLDERS::get));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResultsAreTheSameAsReplacement() {
|
||||
final String resultChars = Values.CHARS_REPLACER
|
||||
.apply("%player_name%", null, Values.PLACEHOLDERS::get);
|
||||
final String resultRegex = Values.REGEX_REPLACER
|
||||
.apply("%player_name%", null, Values.PLACEHOLDERS::get);
|
||||
|
||||
assertEquals(resultChars, resultRegex);
|
||||
|
||||
assertEquals(PLAYER_NAME, resultChars);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResultsAreTheSameNoReplacement() {
|
||||
final String resultChars = Values.CHARS_REPLACER
|
||||
.apply("%player_location%", null, Values.PLACEHOLDERS::get);
|
||||
final String resultRegex = Values.REGEX_REPLACER
|
||||
.apply("%player_location%", null, Values.PLACEHOLDERS::get);
|
||||
|
||||
assertEquals(resultChars, resultRegex);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharsReplacerIgnoresMalformed() {
|
||||
final String text = "10% and %hello world 15%";
|
||||
@@ -60,4 +88,12 @@ public final class ReplacerUnitTester {
|
||||
assertEquals(text, Values.CHARS_REPLACER.apply(text, null, Values.PLACEHOLDERS::get));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharsReplacerHandlesEscapedHex() {
|
||||
final String text = "\\&xffffffThis should not change.";
|
||||
|
||||
assertEquals(text.substring(1),
|
||||
Values.CHARS_REPLACER.apply(text, null, Values.PLACEHOLDERS::get));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
239
wiki/Commands.md
Normal file
239
wiki/Commands.md
Normal file
@@ -0,0 +1,239 @@
|
||||
This page shows all commands, including with a detailed description of what every command does.
|
||||
|
||||
## Overview
|
||||
|
||||
- **[Parse Commands](#parse-commands)**
|
||||
- [`/papi bcparse <player|me> <string>`](#papi-bcparse)
|
||||
- [`/papi cmdparse <player|me> <string>`](#papi-cmdparse)
|
||||
- [`/papi parse <player|me> <string>`](#papi-parse)
|
||||
- [`/papi parserel <player> <player> <string>`](#papi-parserel)
|
||||
|
||||
- **[eCloud Commands](#ecloud-commands)**
|
||||
- [`/papi ecloud clear`](#papi-ecloud-clear)
|
||||
- [`/papi ecloud disable`](#papi-ecloud-disable)
|
||||
- [`/papi ecloud download <expansion> [version]`](#papi-ecloud-download)
|
||||
- [`/papi ecloud enable`](#papi-ecloud-enable)
|
||||
- [`/papi ecloud info <expansion> [version]`](#papi-ecloud-info)
|
||||
- [`/papi ecloud list <all|<author>|installed>`](#papi-ecloud-list)
|
||||
- [`/papi ecloud placeholders <expansion>`](#papi-ecloud-placeholders)
|
||||
- [`/papi ecloud refresh`](#papi-ecloud-refresh)
|
||||
- [`/papi ecloud status`](#papi-ecloud-status)
|
||||
|
||||
- **[Expansion Commands](#expansion-commands)**
|
||||
- [`/papi info <expansion>`](#papi-info)
|
||||
- [`/papi list`](#papi-list)
|
||||
- [`/papi register <jar file>`](#papi-register)
|
||||
- [`/papi unregister <jar file>`](#papi-unregister)
|
||||
|
||||
- **[Other Commands](#other-commands)**
|
||||
- [`/papi dump`](#papi-dump)
|
||||
- [`/papi help`](#papi-help)
|
||||
- [`/papi reload`](#papi-reload)
|
||||
- [`/papi version`](#papi-version)
|
||||
|
||||
----
|
||||
|
||||
### Parse Commands
|
||||
These commands are used to parse placeholders into their respective values. Useful for debugging.
|
||||
|
||||
- #### `/papi bcparse`
|
||||
**Description**:
|
||||
Parses placeholders of a String and broadcasts the result to all players.
|
||||
|
||||
**Arguments**:
|
||||
* `<player|me>` - The Player to parse values of the placeholder (Use `me` for yourself).
|
||||
* `<Text with placeholders>` - The text to parse.
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi bcparse funnycube My name is %player_name%!
|
||||
```
|
||||
|
||||
- #### `/papi cmdparse`
|
||||
**Description**:
|
||||
Parses placeholders of a String and executes it as a command.
|
||||
|
||||
**Arguments**:
|
||||
- `<player|me>` - The player to parse placeholders against. Use `me` for yourself.
|
||||
- `<Command with placeholders>` - The Text to parse and execute as command. Please leave away the `/` of the command.
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi cmdparse funnycube say My name is %player_name%!
|
||||
```
|
||||
|
||||
- #### `/papi parse`
|
||||
**Description**:
|
||||
Parses the placeholders in a given text and shows the result.
|
||||
|
||||
**Arguments**:
|
||||
* `<player|me>` - The Player to parse values of the placeholder (Use `me` for yourself).
|
||||
* `<Text with placeholders>` - The text to parse.
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi parse funnycube My group is %vault_group%
|
||||
```
|
||||
|
||||
- #### `/papi parserel`
|
||||
**Description**:
|
||||
Parses a relational placeholder.
|
||||
|
||||
**Arguments**:
|
||||
* `<player1>` - The first player.
|
||||
* `<player2>` - the second player to compare with.
|
||||
* `<Text with placeholders>` - The actual placeholder to parse.
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi parserel funnycube extended_clip %placeholder%
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
### eCloud Commands
|
||||
These commands all start with `/papi ecloud` and are used for things related about the [[Expansion Cloud]].
|
||||
|
||||
- #### `/papi ecloud clear`
|
||||
**Description**:
|
||||
Clears the cache for the eCloud.
|
||||
|
||||
- #### `/papi ecloud disable`
|
||||
**Description**:
|
||||
Disables the connection to the eCloud.
|
||||
|
||||
- #### `/papi ecloud download`
|
||||
**Description**:
|
||||
Allows you to download an expansion from the eCloud
|
||||
|
||||
**Arguments**:
|
||||
- `<expansion>` - The expansion to download.
|
||||
- `[version]` - The specific version of the expansion to download (Optional)
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi ecloud download Vault
|
||||
/papi ecloud download Vault 1.5.2
|
||||
```
|
||||
|
||||
- #### `/papi ecloud enable`
|
||||
**Description**:
|
||||
Enables the connection to the eCloud
|
||||
|
||||
- #### `/papi ecloud info`
|
||||
**Description**:
|
||||
Gives information about a specific Expansion.
|
||||
|
||||
**Arguments**:
|
||||
- `<expansion>` - The Expansion to retrieve information from.
|
||||
- `[version]` - The Expansion's version to get information from.
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi ecloud info Vault
|
||||
```
|
||||
|
||||
- #### `/papi ecloud list`
|
||||
**Description**:
|
||||
Lists either all Expansions on the eCloud, only those by a specific author or only those that you have [installed](#papi-ecloud-download).
|
||||
Installed Expansions show as green in the list and Expansions that are installed and have an update available show as gold.
|
||||
|
||||
**Arguments**:
|
||||
- `<all|<author>|installed>` - List all Expansions, Expansions of a specific author or all Expnansions you have installed.
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi ecloud list all
|
||||
/papi ecloud list clip
|
||||
/papi ecloud list installed
|
||||
```
|
||||
|
||||
- #### `/papi ecloud placeholders`
|
||||
**Description**:
|
||||
List all placeholders of an Expansion.
|
||||
|
||||
**Arguments**:
|
||||
- `<expansion>` - The Expansion to list placeholders of.
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi ecloud placeholders Vault
|
||||
```
|
||||
|
||||
- #### `/papi ecloud refresh`
|
||||
**Description**:
|
||||
Refresh the cached data from the eCloud.
|
||||
|
||||
- #### `/papi ecloud status`
|
||||
**Description**:
|
||||
Displays the actual Status of the eCloud.
|
||||
|
||||
----
|
||||
|
||||
### Expansion Commands
|
||||
These commands can be used to manage the expansions that you have currently installed.
|
||||
|
||||
- #### `/papi info`
|
||||
**Description**:
|
||||
Gives you information about the specified Expansion.
|
||||
|
||||
**Argument(s)**:
|
||||
- `<expansion>` - The Expansion to get info from (Needs to be registered and active).
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi info Vault
|
||||
```
|
||||
|
||||
- #### `/papi list`
|
||||
**Description**:
|
||||
Lists all active/registered expansions.
|
||||
This is different to [/papi ecloud list installed](#papi-ecloud-list) in the fact, that it also includes expansions that were installed through a plugin (That aren't a separate jar-file) and it also doesn't show which one have updates available.
|
||||
|
||||
- #### `/papi register`
|
||||
**Description**:
|
||||
Registers an expansion from a specified filename.
|
||||
This is useful in cases, where you downloaded the expansion manually and don't want to restart the server.
|
||||
The file needs to be inside `/plugins/PlaceholderAPI/expansions`.
|
||||
|
||||
**Arguments**:
|
||||
- `<filename>` - The file to register (including the file-extension).
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi register MyExpansion.jar
|
||||
```
|
||||
|
||||
- #### `/papi unregister`
|
||||
**Description**:
|
||||
Unregisters the specified expansion.
|
||||
|
||||
**Arguments**:
|
||||
- `<filename>` - The expansion to unregister.
|
||||
|
||||
**Example**:
|
||||
```
|
||||
/papi unregister MyExpansion.jar
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
### Other Commands
|
||||
These are other commands of PlaceholderAPI that don't fit any of the above categories.
|
||||
|
||||
- #### `/papi dump`
|
||||
**Description**:
|
||||
Pastes useful information from PlaceholderAPI such as plugin version, server version and installed expansions to https://paste.helpch.at for simple sharing and support.
|
||||
|
||||
- #### `/papi help`
|
||||
**Description**:
|
||||
Displays all the commands PlaceholderAPI currently offers.
|
||||
|
||||
- #### `/papi reload`
|
||||
**Description**:
|
||||
Reloads the config settings.
|
||||
You need to use this command after [downloading Expansions](#papi-ecloud-download) from the eCloud or they won't be properly registered.
|
||||
|
||||
- #### `/papi version`
|
||||
**Description**:
|
||||
Shows the current version and authors of PlaceholderAPI.
|
||||
67
wiki/Expansion-cloud.md
Normal file
67
wiki/Expansion-cloud.md
Normal file
@@ -0,0 +1,67 @@
|
||||
## About
|
||||
PlaceholderAPI uses an expansion-cloud (A website that has all kinds of expansions stored), to download jar-files, that contain the placeholders for it to use.
|
||||
|
||||
The expansion-cloud can be seen under https://api.extendedclip.com/home
|
||||
|
||||
## How it works
|
||||
PlaceholderAPI connects to the ecloud on startup of your server, to check if the cloud is available and how many expansions are available on it.
|
||||
If you run `/papi ecloud download <expansion>` PlaceholderAPI will connect to the site to first check if the specified expansion exists and then downloads it if it does.
|
||||
Note that not all listed expansions are on the ecloud. Some are in the corresponding plugin itself and are registered on the startup of the server.
|
||||
|
||||
You can disable the connection to the cloud by setting `cloud_enabled` in the config.yml to false.
|
||||
|
||||
## Adding your own expansion
|
||||
You can add your own expansion to the expansion-cloud for others to use.
|
||||
In order to do that, you have to follow those steps:
|
||||
1. Make sure you have created a seperate jar-file like explained on the page [[PlaceholderExpansion]].
|
||||
2. Create an account on the site, or log in, if you already have one.
|
||||
3. Click on `Expansions` and then on [`Upload New`](https://api.extendedclip.com/manage/add/).
|
||||
4. Fill out the required information. `Source URL` and `Dependency URL` are optional.
|
||||
5. Click on the button that says `Choose an file...` and select the jar of your expansion.
|
||||
* **Important**! Make sure, that the name of the jar-file contains the same version like you set in the version-field!
|
||||
6. Click on `Submit Expansion`
|
||||
|
||||
Your expansion is now uploaded and will be reviewed by a moderator.
|
||||
If everything is ok will your expansion be approved and will be available on the ecloud for PlaceholderAPI*.
|
||||
|
||||
> *You can only download verified Expansions through PlaceholderAPIs command, unless you enable the option `cloud_allow_unverified_expansions` in the config.yml
|
||||
> Unverified expansions can be downloaded manually by going to the site and download it yourself.
|
||||
|
||||
## Updating your expansion
|
||||
Before you update, please note the following:
|
||||
If you aren't a verified dev and you upload an update, your expansion will become **unverified** until a moderator reviews the update and approves it!
|
||||
It is recommended to only update the expansion, if it contains huge changes or bug fixes.
|
||||
|
||||
To update your expansion, you first have to go to the list of [your expansions](https://api.extendedclip.com/manage/).
|
||||
For that click on `Expansions` and select `Your Expansions`.
|
||||
After that, follow those steps:
|
||||
1. Click the name of the expansion, that you want to update.
|
||||
2. Click on the button that says `Version`
|
||||
3. Click on `Add Version`
|
||||
4. Fill out the fields and upload the new jar.
|
||||
* **Important**! Make sure, that the name of the jar-file contains the same version like you set in the version-field!
|
||||
5. Click on `Save Changes`
|
||||
|
||||
If you're a verified dev, your version will be approved and is available directly.
|
||||
If you aren't a verified dev, you have to wait until a moderator approves the update.
|
||||
|
||||
## Downloading a specific expansion version
|
||||
In some cases, you may want to use a specific, older version of expansion. Such a case could be for example, when you run an old server version and the newest version of an expansion uses methods that aren't available on that particular server version.
|
||||
For that case is there a way, to download a specific version of expansion. You can download the expansion either manually, or through PlaceholderAPI itself.
|
||||
Here is how you can do it for each.
|
||||
|
||||
### Download with PlaceholderAPI
|
||||
This is the easiest of both methods since it requires the least amount of effort.
|
||||
Run the following command in-game or in your console to download a specific version:
|
||||
`/papi ecloud download <expansion> [version]`
|
||||
|
||||
To find out, what versions are available for the expansion, run `/papi ecloud info <expansion>`
|
||||
You can then run `/papi ecloud versioninfo <expansion> <version>` to receive more infor about a specific version.
|
||||
|
||||
After you downloaded the specific version, run `/papi reload` to refresh the installed expansions.
|
||||
|
||||
### Download manually
|
||||
To download an expansion manually, you first have to connect to the website and go to the expansion of your choice.
|
||||
There, you click on the button that says `Version` and click on the download-icon of the version you want to download.
|
||||
|
||||
Finally, stop your server, upload the jar to the folder in `/plugins/PlaceholderAPI/expansions` (Make sure to delete the old jar, if there's already one) and start the server again.
|
||||
55
wiki/FAQ.md
Normal file
55
wiki/FAQ.md
Normal file
@@ -0,0 +1,55 @@
|
||||
[readme]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/docs/wiki/wiki/README.md
|
||||
|
||||
Here are frequently asked questions about stuff related to PlaceholderAPI.
|
||||
|
||||
## It only shows `%placeholder%` and not the variable
|
||||
When a plugin or `/papi parse me %placeholder%` only returns the placeholder itself and no value should you check for the following things:
|
||||
|
||||
### The expansion is actually installed.
|
||||
In many cases is the cause that the expansion of the placeholder is missing.
|
||||
Just execute `/papi ecloud download <name of expansion>` followed by `/papi reload` to activate it. You can find a list of Expansions and their Placeholders [[on this page|Placeholders]].
|
||||
|
||||
**NOTE!**
|
||||
Not all placeholders come in their own expansion. Some plugins *hardcode* them in and load them on startup, when hooking into PlaceholderAPI.
|
||||
|
||||
### Plugin actualls supports PlaceholderAPI
|
||||
It can happen that the plugin you use to display the placeholder in doesn't support PlaceholderAPI. In such a case check, if the parse command returns the actual value of a placeholder.
|
||||
If that is the case while the plugin is still displaying the placeholder, can this be an indicator of the plugin not supporting PlaceholderAPI.
|
||||
|
||||
You can find a list of plugins supporting PlaceholderAPI [[here|Plugins-using-PlaceholderAPI]].
|
||||
Just make sure that "Supports placeholders" has a check mark in front of it.
|
||||
|
||||
### No typo in the placeholder
|
||||
Double-check that the placeholder you set doesn't contain a typo. You can use `/papi ecloud placeholders <expansion>` (replace `<expansion>` with the name of the expansion) to get a list of all the placeholders the expansion may have.
|
||||
Keep in mind that this only works for separate expansions on the eCloud and not for those that are loaded by plugins.
|
||||
|
||||
### Plugin is enabled
|
||||
If an expansion depends on a plugin, make sure you have the plugin installed and that it is enabled (Shows green in `/pl`).
|
||||
|
||||
## I can't download the expansion
|
||||
Make sure, that the connection to the cloud (https://api.extendedclip.com) isn't blocked by a firewall or similar.
|
||||
Next step would be to check if the expansion actually exists on the cloud. Not all plugins provide their placeholders through a separate jar on the cloud. Some have them build in and register them on startup.
|
||||
|
||||
If both checks failed, go to the cloud-page and download the jar manually. Put it then in the `expansions` folder of PlaceholderAPI (`/plugins/PlaceholderAPI/expansions`)
|
||||
|
||||
## How can other plugins use my placeholders with PlaceholderAPI?
|
||||
A tutorial can be found [[here|Hook into PlaceholderAPI]]!
|
||||
|
||||
## Can I help on this wiki?
|
||||
You sure can!
|
||||
We welcome contributions to our wiki by everyone. If you found a typo or want to improve this wiki in another way, head over to the [Wiki's readme file][readme] to find out about how you can contribute towards this wiki.
|
||||
|
||||
## PlaceholderAPI is posting an error about an outdated expansion?
|
||||
```
|
||||
[00:00:01 ERROR]: [PlaceholderAPI] Failed to load Expansion class <expansion> (Is a dependency missing?)
|
||||
[00:00:01 ERROR]: [PlaceholderAPI] Cause: NoClassDefFoundError <path>
|
||||
```
|
||||
|
||||
If you receive the above error, try to do the following steps:
|
||||
|
||||
- Make sure any required dependency of the mentioned expansion (e.g. a plugin) is installed.
|
||||
- Make sure you use the latest version supported for the server version you use.
|
||||
- If you downloaded the jar from the ecloud, make sure it isn't malformed/corrupted.
|
||||
|
||||
If the issue persists after you've done those checks, report it to the author of the expansion.
|
||||
In most cases is the issue that either a dependency is missing or that the expansion tries to use outdated methods from PlaceholderAPI.
|
||||
77
wiki/Home.md
Normal file
77
wiki/Home.md
Normal file
@@ -0,0 +1,77 @@
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/PlaceholderAPI/PlaceholderAPI/master/wiki/img/wiki-logo.png" alt="PlaceholderAPI">
|
||||
</p>
|
||||
This wiki gives you information on how to create placeholders in your plugin that can be used in other plugins, how to use other placeholders inside your plugin, or how to make an expansion.
|
||||
It also has a list with all available placeholders (Work in progress).
|
||||
|
||||
### Setup
|
||||
**[[Hook into PlaceholderAPI]]**
|
||||
- [[First steps|Hook-into-PlaceholderAPI#first-steps]]
|
||||
- [[Adding placeholders to PlaceholderAPI|PlaceholderExpansion]]
|
||||
- [[Common Parts|PlaceholderExpansion#common-parts]]
|
||||
- [[Without an external plugin|PlaceholderExpansion#without-a-plugin]]
|
||||
- [[With an external Plugin (Separate Jar)|PlaceholderExpansion#with-a-plugin-external-jar]]
|
||||
- [[With an external Plugin (Internal class)|PlaceholderExpansion#with-a-plugin-internal-class]]
|
||||
- [[Relational Placeholders|PlaceholderExpansion#relational-placeholders]]
|
||||
- [[Setting placeholders in your plugin|Hook-into-PlaceholderAPI#setting-placeholders-in-your-plugin]]
|
||||
|
||||
### Other
|
||||
**[[Commands]]**
|
||||
**[[Expansion cloud]]**
|
||||
**[[FAQ]]**
|
||||
**[[Plugins using PlaceholderAPI]]**
|
||||
**[[Placeholders]]**
|
||||
- [[Standalone|Placeholders#standalone]]
|
||||
- [[A|Placeholders#a]]
|
||||
- [[B|Placeholders#b]]
|
||||
- [[C|Placeholders#c]]
|
||||
- [[D|Placeholders#d]]
|
||||
- [[E|Placeholders#e]]
|
||||
- [[F|Placeholders#f]]
|
||||
- [[G|Placeholders#g]]
|
||||
- [[H|Placeholders#h]]
|
||||
- [[I|Placeholders#i]]
|
||||
- [[J|Placeholders#j]]
|
||||
- [[K|Placeholders#k]]
|
||||
- [[L|Placeholders#l]]
|
||||
- [[M|Placeholders#m]]
|
||||
- [[N|Placeholders#n]]
|
||||
- [[O|Placeholders#o]]
|
||||
- [[P|Placeholders#p]]
|
||||
- [[Q|Placeholders#q]]
|
||||
- [[R|Placeholders#r]]
|
||||
- [[S|Placeholders#s]]
|
||||
- [[T|Placeholders#t]]
|
||||
- [[U|Placeholders#u]]
|
||||
- [[V|Placeholders#v]]
|
||||
- [[W|Placeholders#w]]
|
||||
- [[X|Placeholders#x]]
|
||||
- [[Y|Placeholders#y]]
|
||||
- [[Z|Placeholders#z]]
|
||||
- [[Plugin-placeholders|Placeholders#plugin-placeholders-1]]
|
||||
- [[A|Placeholders#a-1]]
|
||||
- [[B|Placeholders#b-1]]
|
||||
- [[C|Placeholders#c-1]]
|
||||
- [[D|Placeholders#d-1]]
|
||||
- [[E|Placeholders#e-1]]
|
||||
- [[F|Placeholders#f-1]]
|
||||
- [[G|Placeholders#g-1]]
|
||||
- [[H|Placeholders#h-1]]
|
||||
- [[I|Placeholders#i-1]]
|
||||
- [[J|Placeholders#j-1]]
|
||||
- [[K|Placeholders#k-1]]
|
||||
- [[L|Placeholders#l-1]]
|
||||
- [[M|Placeholders#m-1]]
|
||||
- [[N|Placeholders#n-1]]
|
||||
- [[O|Placeholders#o-1]]
|
||||
- [[P|Placeholders#p-1]]
|
||||
- [[Q|Placeholders#q-1]]
|
||||
- [[R|Placeholders#r-1]]
|
||||
- [[S|Placeholders#s-1]]
|
||||
- [[T|Placeholders#t-1]]
|
||||
- [[U|Placeholders#u-1]]
|
||||
- [[V|Placeholders#v-1]]
|
||||
- [[W|Placeholders#w-1]]
|
||||
- [[X|Placeholders#x-1]]
|
||||
- [[Y|Placeholders#y-1]]
|
||||
- [[Z|Placeholders#z-1]]
|
||||
142
wiki/Hook-into-PlaceholderAPI.md
Normal file
142
wiki/Hook-into-PlaceholderAPI.md
Normal file
@@ -0,0 +1,142 @@
|
||||
[APIBadge]: https://img.shields.io/nexus/placeholderapi/me.clip/placeholderapi?server=https%3A%2F%2Frepo.extendedclip.com&label=API%20Version
|
||||
|
||||
[SpigotBadge]: https://img.shields.io/spiget/version/6245?label=Spigot
|
||||
[Spigot]: https://spigotmc.org/resources/6245
|
||||
|
||||
[GitHubBadge]: https://img.shields.io/github/v/release/PlaceholderAPI/PlaceholderAPI?label=GitHub%20Release
|
||||
[GitHub]: /PlaceholderAPI/PlaceholderAPI/releases/latest
|
||||
|
||||
> [![SpigotBadge]][Spigot] [![GitHubBadge]][GitHub]
|
||||
>
|
||||
> ![APIBadge]
|
||||
>
|
||||
> *The GitHub release may be different from the spigot release*
|
||||
|
||||
This page is about using PlaceholderAPI in your own plugin, to either let other plugins use your plugin, or just use placeholders from other plugins in your own.
|
||||
|
||||
Please note, that the examples in this page are only available for **PlaceholderAPI 2.10.0 or higher**!
|
||||
|
||||
## First steps
|
||||
Before you can actually make use of PlaceholderAPI, you first have to import it into your project.
|
||||
|
||||
### Import with Maven
|
||||
To import PlaceholderAPI, simply add the following code to your **pom.xml**
|
||||
Replace `{VERSION}` with the version listed at the top of this page.
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>{VERSION}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
### Import with Gradle
|
||||
Here is how you can import PlaceholderAPI through gradle.
|
||||
Put this into your **Gradle.build**.
|
||||
Replace `{VERSION}` with the version listed at the top of this page.
|
||||
```gradle
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'me.clip:placeholderapi:{VERSION}'
|
||||
}
|
||||
```
|
||||
|
||||
### Set PlaceholderAPI as (soft)depend
|
||||
Next step is to go to your plugin.yml and add PlaceholderAPI as a depend or softdepend, depending (no pun intended) on if it is optional or not.
|
||||
|
||||
**Example Softdepend**:
|
||||
```yaml
|
||||
name: ExamplePlugin
|
||||
version: 1.0
|
||||
author: author
|
||||
main: your.main.path.here
|
||||
|
||||
softdepend: [PlaceholderAPI] # This is used, if your plugin works without PlaceholderAPI.
|
||||
```
|
||||
|
||||
**Example Depend**:
|
||||
```yaml
|
||||
name: ExamplePlugin
|
||||
version: 1.0
|
||||
author: author
|
||||
main: your.main.path.here
|
||||
|
||||
depend: [PlaceholderAPI] # If your plugin requires PlaceholderAPI, to work, use this.
|
||||
```
|
||||
|
||||
## Adding placeholders to PlaceholderAPI
|
||||
|
||||
A full guide on how to create expansions can be found on the [[PlaceholderExpansion]] page of this wiki.
|
||||
|
||||
## Setting placeholders in your plugin
|
||||
PlaceholderAPI offers the ability, to automatically parse placeholders from other plugins within your own plugin, giving the ability for your plugin to support thousands of other placeholders without depending on each plugin individually.
|
||||
To use placeholders from other plugins in our own plugin, we simply have to [(soft)depend on PlaceholderAPI](#set-placeholderapi-as-softdepend) and use the `setPlaceholders` method.
|
||||
|
||||
It is also important to point out, that any required plugin/dependency for an expansion has to be on the server and enabled, or the `setPlaceholders` method will just return the placeholder itself (do nothing).
|
||||
|
||||
**Example**:
|
||||
Let's assume we want to send an own join message that shows the group a player has.
|
||||
To achieve that, we can do the following:
|
||||
```java
|
||||
package at.helpch.placeholderapi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
|
||||
public class JoinExample extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
/*
|
||||
* We register the EventListener here, when PlaceholderAPI is installed.
|
||||
* Since all events are in the main class (this class), we simply use "this"
|
||||
*/
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
} else {
|
||||
/*
|
||||
* We inform about the fact that PlaceholderAPI isn't installed and then
|
||||
* disable this plugin to prevent issues.
|
||||
*/
|
||||
getLogger().warn("Could not find PlaceholderAPI! This plugin is required.");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
String joinText = "%player_name% &ajoined the server! They are rank &f%vault_rank%";
|
||||
|
||||
/*
|
||||
* We parse the placeholders using "setPlaceholders"
|
||||
* This would turn %vault_rank% into the name of the Group, that the
|
||||
* joining player has.
|
||||
*/
|
||||
joinText = PlaceholderAPI.setPlaceholders(event.getPlayer(), joinText);
|
||||
|
||||
event.setJoinMessage(joinText);
|
||||
}
|
||||
}
|
||||
```
|
||||
381
wiki/PlaceholderExpansion.md
Normal file
381
wiki/PlaceholderExpansion.md
Normal file
@@ -0,0 +1,381 @@
|
||||
[placeholderexpansion]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java
|
||||
|
||||
[playerexpansion]: https://github.com/PlaceholderAPI/Player-Expansion
|
||||
[serverexpansion]: https://github.com/PlaceholderAPI/Server-Expansion
|
||||
[mathexpansion]: https://github.com/Andre601/Math-expansion
|
||||
|
||||
[relational]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/src/main/java/me/clip/placeholderapi/expansion/Relational.java
|
||||
|
||||
## Overview
|
||||
This page will cover how you can create your own [`PlaceholderExpansion`][placeholderexpansion] which you can either [[Upload to the eCloud|Expansion cloud]] or integrate into your own plugin.
|
||||
|
||||
It's worth noting that PlaceholderAPI relies on expansions being installed. PlaceholderAPI only acts as the core replacing utility while the expansions allow other plugins to use any installed placeholder in their own messages.
|
||||
You can download Expansions either directly from the eCloud yourself, or download them through the [[download command of PlaceholderAPI|Commands#papi-ecloud-download]].
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Getting started](#getting-started)
|
||||
- [Common Parts](#common-parts)
|
||||
- [Without a Plugin](#without-a-plugin)
|
||||
- [With a Plugin (External Jar)](#with-a-plugin-external-jar)
|
||||
- [With a Plugin (Internal Class)](#with-a-plugin-internal-class)
|
||||
- [Register the Expansion](#register-the-expansion)
|
||||
- [Relational Placeholders](#relational-placeholders)
|
||||
- [Notes about Relational Placeholders](#notes-about-relational-placeholders)
|
||||
|
||||
## Getting started
|
||||
For starters, you need to decide what type of [`PlaceholderExpansion`][placeholderexpansion] you want to create. There are various ways to create an expansion. This page will cover the most common ones.
|
||||
|
||||
### Common Parts
|
||||
All shown examples will share the same common parts that belong to the [`PlaceholderExpansion`][placeholderexpansion] class.
|
||||
In order to not repeat the same basic info for each method throughout this page, and to greatly reduce its overall length, we will cover the most basic/necessary ones here.
|
||||
|
||||
#### Basic PlaceholderExpansion Structure
|
||||
```java
|
||||
package at.helpch.placeholderapi.example.expansions;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "someauthor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
}
|
||||
```
|
||||
Let's quickly break down the different methods you have to implement.
|
||||
|
||||
- #### getAuthor
|
||||
This method allows you to set the name of the expansion's author.
|
||||
- #### getIdentifier
|
||||
The identifier is the part in the placeholder that is between the first `%` (Or `{` if bracket placeholders are used) and the first `_`.
|
||||
Because of that can you not use `%`, `{`, `}` or `_` in youd identifier.
|
||||
|
||||
If you still want to use those symbols can you override the `getName()` method to display a different name.
|
||||
- #### getVersion
|
||||
This is a string, which means it can contain more than just a number. This is used to determine if a new update is available or not when the expansion is shared on the eCloud.
|
||||
For expansions that are part of a plugin, this does not really matter.
|
||||
|
||||
Those are all the neccessary parts for your PlaceholderExpansion.
|
||||
Any other methods that are part of the [`PlaceholderExpansion`][placeholderexpansion] class are optional and will usually not be used, or will default to a specific value. Please read the Javadoc comments of those methods for more information.
|
||||
|
||||
You must choose between one of these two methods for handling the actual parsing of placeholders:
|
||||
|
||||
- #### onRequest(OfflinePlayer, String)
|
||||
If not explicitly set, this will automatically call [`onPlaceholderRequest(Player, String)`](#onplaceholderrequestplayer-string).
|
||||
This method is recommended as it allows the usage of `null` and can therefore be used in placeholders that don't require a valid player to be used.
|
||||
- #### onPlaceholderRequest(Player, String)
|
||||
If not set, this method will return `null` which PlaceholderAPI sees as an invalid placeholder.
|
||||
|
||||
----
|
||||
## Without a Plugin
|
||||
An expansion does not always need a plugin to rely on. If the placeholders it provides can return values from just the server itself or some other source (i.e. Java itself), then it can work independently.
|
||||
|
||||
Common examples of such Expansions are:
|
||||
|
||||
- [Player Expansion][playerexpansion]
|
||||
- [Server Expansion][serverexpansion]
|
||||
- [Math Expansion][mathexpansion]
|
||||
|
||||
These kinds of expansions don't require any additional plugins to function.
|
||||
When creating such an expansion is it recommended to use [`onRequest(OfflinePlayer, String)`](#onrequestofflineplayer-string).
|
||||
|
||||
#### Full Example
|
||||
Please see the [Common parts](#common-parts) section for info on the other methods.
|
||||
|
||||
```java
|
||||
package at.helpch.placeholderapi.example.expansions;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "someauthor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
if(params.equalsIgnoreCase("name")) {
|
||||
return player == null ? null : player.getName(); // "name" requires the player to be valid
|
||||
}
|
||||
|
||||
if(params.equalsIgnoreCase("placeholder1")) {
|
||||
return "Placeholder Text 1";
|
||||
}
|
||||
|
||||
if(params.equalsIgnoreCase("placeholder2")) {
|
||||
return "Placeholder Text 2";
|
||||
}
|
||||
|
||||
return null; // Placeholder is unknown by the Expansion
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
## With a Plugin (External Jar)
|
||||
If your expansion relies on a plugin to provide its placeholder values, you will need to override a few more methods to make sure everything will work correctly.
|
||||
|
||||
Your expansion will need to override the `getRequiredPlugin()` method to return the name of the plugin your expansion depends on.
|
||||
PlaceholderAPI automatically checks if this method will either return null, or if the name defined results in a non-null plugin.
|
||||
|
||||
It is worth noting that it is a bit more difficult to make a separate jar file that depends on a plugin, as it will require the plugin to have some sort of accessible API in order to get the required values.
|
||||
One way to bypass this is to override the `canRegister()` method with the following code:
|
||||
|
||||
```java
|
||||
private SomePlugin plugin = null; // This would be the plugin your expansion depends on
|
||||
|
||||
@Override
|
||||
public boolean canregister() {
|
||||
// This sets plugin to the SomePlugin instance you get through the PluginManager
|
||||
return (plugin = (SomePlugin) Bukkit.getPluginManager().getPlugin(getRequiredPlugin())) != null;
|
||||
}
|
||||
```
|
||||
Using this code-snippet, you can get a direct instance of the plugin and access things such as config values.
|
||||
With that said, it is recommended instead to use an API if one is available, as this kind of plugin access is a relatively poor approach.
|
||||
|
||||
#### Full Example
|
||||
Please see the [Common parts](#common-parts) section for info on the other methods.
|
||||
|
||||
```java
|
||||
package at.helpch.placeholderapi.example.expansions;
|
||||
|
||||
import at.helpch.placeholderapi.example.SomePlugin;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
|
||||
private SomePlugin plugin; // This instance is assigned in canRegister()
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "someauthor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequiredPlugin() {
|
||||
return "SomePlugin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRegister() {
|
||||
return (plugin = (SomePlugin) Bukkit.getPluginManager().getPlugin(getRequiredPlugin())) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
if(params.equalsIgnoreCase("placeholder1")){
|
||||
return plugin.getConfig().getString("placeholders.placeholder1", "default1");
|
||||
}
|
||||
|
||||
if(params.equalsIgnoreCase("placeholder2")){
|
||||
return plugin.getConfig().getString("placeholders.placeholder2", "default2");
|
||||
}
|
||||
|
||||
return null; // Placeholder is unknown by the expansion
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
## With a Plugin (Internal Class)
|
||||
The way expansions are handled when they are part of the plugin itself is fairly similar to when you [make an expansion without a plugin dependency](#without-a-plugin).
|
||||
|
||||
In fact, you don't even have to override the `getRequiredPlugin()` and `canRegister()` methods as it is always guaranteed that the plugin is available.
|
||||
Something worth noting, however, is that you need to override the `persist()` method and make it return true. This ensures that the expansion won't be unregistered by PlaceholderAPI whenever it is reloaded.
|
||||
|
||||
Finally, you can also use dependency injection as an easier way to access a plugin's methods.
|
||||
Here is a small code example of how dependency injection may look:
|
||||
|
||||
```java
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
private final SomePlugin plugin; // The instance is created in the constructor and won't be modified, so it can be final
|
||||
|
||||
public SomeExpansion(SomePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Full Example
|
||||
Please see the [Common parts](#common-parts) section for info on the other methods.
|
||||
|
||||
|
||||
```java
|
||||
package at.helpch.placeholderapi.example.expansions;
|
||||
|
||||
import at.helpch.placeholderapi.example.SomePlugin;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
|
||||
private final SomePlugin plugin;
|
||||
|
||||
public SomeExpansion(SomePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "someauthor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true; // This is required or else PlaceholderAPI will unregister the Expansion on reload
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
if(params.equalsIgnoreCase("placeholder1")){
|
||||
return plugin.getConfig().getString("placeholders.placeholder1", "default1");
|
||||
}
|
||||
|
||||
if(params.equalsIgnoreCase("placeholder2")) {
|
||||
return plugin.getConfig().getString("placeholders.placeholder2", "default2");
|
||||
}
|
||||
|
||||
return null; // Placeholder is unknown by the Expansion
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Register the Expansion
|
||||
To register the expansion, you will need to call the `register()` method yourself.
|
||||
This should be done in your plugin's `onEnable()` method after you make sure that PlaceholderAPI is installed and enabled.
|
||||
|
||||
```java
|
||||
package at.helpch.placeholderapi.example
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class SomePlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Small check to make sure that PlaceholderAPI is installed
|
||||
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new SomeExpansion(this).register();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
## Relational Placeholders
|
||||
Relational Placeholders are a bit more specific compared to the previous examples.
|
||||
While they do use the same [common parts](#common-parts) that the other examples do, they have a different method to return placeholders.
|
||||
|
||||
In order to use the relational placeholders feature, you will need to implement the [`Relational`][relational] interface, which in return adds the `onPlaceholderRequest(Player, Player, String)` method to use.
|
||||
|
||||
#### Full Example
|
||||
Please see the [Common parts](#common-parts) section for info on the other methods.
|
||||
|
||||
In this example, we use the [Internal class setup](#with-a-plugin-internal-jar) and `SomePlugin` has an `areFriends(Player, Player)` method that returns true or false based on if the given players are friends.
|
||||
|
||||
```java
|
||||
package at.helpch.placeholderapi.example.expansions;
|
||||
|
||||
import at.helpch.placeholderapi.example.SomePlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Player;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Relational;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion implements Relational {
|
||||
|
||||
private final SomePlugin plugin;
|
||||
|
||||
public SomeExpansion(SomePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "someauthor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true; // This is required or else PlaceholderAPI will unregister the Expansion on reload
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player one, Player two, String identifier) {
|
||||
if(one == null || two == null)
|
||||
return null; // We require both Players to be online
|
||||
|
||||
if(params.equalsIgnoreCase("friend")) {
|
||||
if(plugin.areFriends(one, two)) {
|
||||
return ChatColor.GREEN + one.getName() + " and " + two.getName() + " are friends!";
|
||||
} else {
|
||||
return ChatColor.GREEN + one.getName() + " and " + two.getName() + " are not friends!";
|
||||
}
|
||||
}
|
||||
|
||||
return null; // Placeholder is unknown by the Expansion
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Notes about Relational Placeholders
|
||||
Relational placeholders will always start with `%rel_` to properly identify them.
|
||||
So in the above example, the full placeholder will look like `%rel_example_friend%`.
|
||||
5567
wiki/Placeholders.md
Normal file
5567
wiki/Placeholders.md
Normal file
File diff suppressed because it is too large
Load Diff
1037
wiki/Plugins-using-PlaceholderAPI.md
Normal file
1037
wiki/Plugins-using-PlaceholderAPI.md
Normal file
File diff suppressed because it is too large
Load Diff
181
wiki/README.md
Normal file
181
wiki/README.md
Normal file
@@ -0,0 +1,181 @@
|
||||
[wiki]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki
|
||||
|
||||
[placeholders]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/Placeholders
|
||||
[using_papi]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/Plugins-using-PlaceholderAPI
|
||||
|
||||
[discord]: https://discord.gg/HelpChat
|
||||
[discussion]: https://github.com/PlaceholderAPI/PlaceholderAPI/discussions
|
||||
|
||||
[andre]: https://github.com/Andre601
|
||||
[andrew]: https://github.com/Andrew-Chen-Wang
|
||||
[action]: https://github.com/Andrew-Chen-Wang/github-wiki-action
|
||||
|
||||
<!-- Images -->
|
||||
[branch-selector]: https://user-images.githubusercontent.com/11576465/132779328-8571458a-d63d-4c25-b920-96aa16ae0058.png
|
||||
[upstream_up-to-date]: https://user-images.githubusercontent.com/11576465/132779917-96f19239-077d-44ed-98e7-6a76f305b33a.png
|
||||
[upstream_needs_update]: https://user-images.githubusercontent.com/11576465/132779798-1fe3dc72-a6c2-41eb-a8bc-95793671f384.png
|
||||
[create_branch]: https://user-images.githubusercontent.com/11576465/132780127-45599156-1400-40c9-b865-351574786873.png
|
||||
|
||||
# Wiki
|
||||
Welcome to the Wiki folder!
|
||||
|
||||
This folder contains all the files of the [PlaceholderAPI Wiki][wiki].
|
||||
It allows you to contribute towards the wiki and us to have more control about what changes are commited to it.
|
||||
|
||||
## Contrbuting to the wiki
|
||||
If you want to contribute towards the wiki, will you need to follow the below instructions to not get your Pull request closed without a warning.
|
||||
|
||||
### Fork the Repository (Not wiki!)
|
||||
> Already having a fork? Skip to the [next Step](#select-target-branch)!
|
||||
|
||||
You need to make a fork of the PlaceholderAPI Repository to contribute towards the wiki.
|
||||
To do this, click the "Fork" button on the top-right corner of the site and select the account you want your fork to be created on. This will also show you any already existing forks of this Repository that you may have.
|
||||
|
||||
The forking process should only take a few seconds and you should be redirected to your fork afterwards.
|
||||
|
||||
### Select target branch
|
||||
All main changes to the wiki are made on the dedicated `docs/wiki` branch.
|
||||
Before you try to make any changes should you make sure that you have the `docs/wiki` branch selected. To do that, check the button next to the `X branches` text. If it says anything other than `docs/wiki` will you need to click it and select the right branch.
|
||||
|
||||
![branch-selector]
|
||||
|
||||
### Fetch Changes from Upstream
|
||||
This is only required when you already had a fork and didn't update it for some time.
|
||||
|
||||
While you're on the `docs/wiki` branch, click the `Fetch upstream` text located right below the green `Code` button.
|
||||
Depending on the status of your branch can the prompt show different outcomes:
|
||||
|
||||
- `This branch is not behind the upstream PlaceholderAPI:docs/wiki`
|
||||
Your fork's `docs/wiki` branch is up-to-date with the latest changes from Upstream (This Repository). You don't have to update anything.
|
||||
![upstream_up-to-date]
|
||||
- `Fetch and merge <number> upstream commits from PlaceholderAPI:docs/wiki`
|
||||
This is shown when your fork's branch is outdated and upstream (This Repository) has changes. Click the `Fetch and merge` button to fetch the latest commits and update your fork's `docs/wiki` branch.
|
||||
![upstream_needs_update]
|
||||
|
||||
### Commit changes
|
||||
To commit changes will you need to choose, if you want to directly commit to your fork's `docs/wiki` branch, or make a dedicated branch for it.
|
||||
|
||||
#### Make separate branch (Optional)
|
||||
If you want to have a dedicated branch for it, will you need to click the button saying `docs/wiki`, type in the small text field the name of the branch you want to use and click the text saying `Create branch: <branch> from 'docs/wiki'`
|
||||
|
||||
![create_branch]
|
||||
|
||||
After that should you now have a separate branch that is based of the `docs/wiki` branch and you can finally commit changes to it.
|
||||
|
||||
#### Formatting
|
||||
The wiki uses normal Markdown formatting with some special design-rules you need to keep in mind.
|
||||
These rules are as follows:
|
||||
|
||||
- Unordered lists need to start with a `-` and not `*`. This is to not get it confused with *italic text* which uses single `*` characters.
|
||||
- New lines in lists need to keep their indends. This means you need to add two spaces at the start to keep the text in the same line.
|
||||
Example:
|
||||
```markdown
|
||||
- Line 1
|
||||
Line 2
|
||||
```
|
||||
- Use the `[[Page]]` and `[[Text|Page]]` format to link to other wiki pages. While those aren't rendered in the wiki folder will they render in the final wiki pages.
|
||||
- External links should be set as Refernce Links, which means they are set as `[text]: link` at the top of the page and then used either through `[text]` or `[display text][text]` througout the page.
|
||||
|
||||
#### Adding new Expansion
|
||||
When you add a new expansion to the wiki's [Placeholder page][placeholders] will you need to follow the following format:
|
||||
````markdown
|
||||
- ### [:name](:link)
|
||||
> :command
|
||||
|
||||
:text
|
||||
|
||||
```
|
||||
:placeholders
|
||||
```
|
||||
````
|
||||
|
||||
There are a few extra rules you need to also keep in mind:
|
||||
|
||||
- `:name` would be the name of your Expansion, not the plugin (Unless it is integrated into your plugin).
|
||||
- Only embed a link, if your Expansion requires a plugin to function.
|
||||
- When linking to a Spigot page, make sure to sanitze the link.
|
||||
This means that f.e. https://www.spigotmc.org/resources/placeholderapi.6245/ becomes https://www.spigotmc.org/resources/6245/
|
||||
- `:command` should be replaced with either the PlaceholderAPI command to download your expansion from the eCloud (`/papi ecloud download :name`) or with `NO DOWNLOAD COMMAND` if no separate download is available.
|
||||
- `:text` is optional and should only be provided to link to additional documentation, your own placeholder list, or explain more complicated placeholders/features.
|
||||
- `:placeholders` will be the list of placeholders your expansion provides.
|
||||
Please avoid specific examples (i.e. `%placeholder_player_user123%`) and instead use `<>` and `[]` to mark required and optional options respecively (`%placeholder_player_<player>%`)
|
||||
|
||||
**Note:**
|
||||
When your Expansion's entry is after and/or before other entries will you need to add `----` before or after it to separate it from other entries.
|
||||
|
||||
##### Example:
|
||||
````markdown
|
||||
- ### SomeExpansion
|
||||
> NO DOWNLOAD COMMAND
|
||||
|
||||
```
|
||||
%someexpansion_placeholder%
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
- ### YourExpansion
|
||||
> NO DOWNLOAD COMMAND
|
||||
|
||||
```
|
||||
%yourexpansion_placeholder%
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
- ### AnotherExpansion
|
||||
> NO DOWNLOAD COMMAND
|
||||
|
||||
```
|
||||
%anotherexpansion_placeholder%
|
||||
```
|
||||
````
|
||||
|
||||
After you added your expansion to this page will you also need to add an entry to the list at the top of the page.
|
||||
You do so by adding `- **[:text](#:name)**` to the list, where `:text` is the text to display (Usually the name you set) and `:name` is the name you just set. If your expansion shares the exact same name as another entry on the page will you need to make sure that your expansion is listed **after** the other one AND that the list-entry has a `-1` appended to `#:name` (So f.e. `#expansion` becomes `#expansion-1`).
|
||||
|
||||
Finally can you now commit your changes and move forward to the [Plugins using PlaceholderAPI][using_papi] page in the wiki folder.
|
||||
|
||||
#### Adding new plugin
|
||||
This step is only required if you either add a new plugin to the list, or you added an Expansion that is included in your own plugin.
|
||||
|
||||
Similar to the [Placeholders page][placeholders] does this page follow a specific format which we will explain real quick.
|
||||
|
||||
```markdown
|
||||
- [:name](:link)
|
||||
- [?] Supports placeholders.
|
||||
- [?] Provides own placeholders. [:page]
|
||||
```
|
||||
|
||||
Here are the following rules:
|
||||
|
||||
- `:name` needs to be replaced with the Name of your plugin.
|
||||
- `:link` needs to be the link of the plugin's resource page.
|
||||
- If no resource page is available can a GitHub repository be linked (if available) or the link omited altogether)
|
||||
- When linking to a Spigot page, make sure to sanitze the link.
|
||||
This means that f.e. https://www.spigotmc.org/resources/placeholderapi.6245/ becomes https://www.spigotmc.org/resources/6245/
|
||||
- `[?]` needs to be replaced with either `[ ]` or `[x]` depending on whether the mentioned option is supported or not.
|
||||
- `:page` needs to replace with the right value, depending on the conditions.
|
||||
- If your plugin provides own Placeholders for other plugins to use can you set `**[[Link|Placeholders#:name]]**` where `:name` is the title you set in the placeholders page.
|
||||
- If your plugin does not provide own placeholders will you need to set `Link`.
|
||||
|
||||
### Make a Pull request
|
||||
After you made your changes is it time to make a Pull request.
|
||||
|
||||
When you go to the upstream repository, should GitHub already show you a notification that you have commits to PR. Click the `Compare & pull request` button to proceed.
|
||||
|
||||

|
||||
|
||||
By default will GitHub select the `master` branch as the target, which is not what we want. To fix this, click the button saying `base:master` and select the `docs/wiki` branch.
|
||||
|
||||

|
||||
|
||||
Finally, fill out the Pull request template and submit the Pull request.
|
||||
Congratulations! You've successfully made a Pull request for the wiki.
|
||||
|
||||
### Questions?
|
||||
If you have any questions, do not hesitate to ask in the [HelpChat Discord][discord] or [open a new discussion][discussion] in this repository. We will be happy to help you.
|
||||
|
||||
### Credits
|
||||
- The Wiki is maintained by [Andre601][andre].
|
||||
- We use the [GitHub Wiki Action][action] by [Andrew-Chen-Wang][andrew] to update the PlaceholderAPI wiki through GitHub Actions.
|
||||
23
wiki/_Footer.md
Normal file
23
wiki/_Footer.md
Normal file
@@ -0,0 +1,23 @@
|
||||
[papi]: https://placeholderapi.com
|
||||
|
||||
[discordImg]: https://img.shields.io/discord/164280494874165248.svg?logo=discord&label=Discord&colorB=7289DA
|
||||
[discord]: https://helpch.at/discord
|
||||
|
||||
[jenkinsImg]: https://img.shields.io/badge/Download%20from-Jenkins-brightgreen.svg
|
||||
[jenkins]: http://ci.extendedclip.com/job/PlaceholderAPI/
|
||||
|
||||
[licenseImg]: https://img.shields.io/github/license/PlaceholderAPI/PlaceholderAPI.svg
|
||||
[license]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/LICENSE
|
||||
|
||||
[issuesImg]: https://img.shields.io/github/issues-raw/PlaceholderAPI/PlaceholderAPI.svg?logo=github&logoColor=white
|
||||
[issues]: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
|
||||
|
||||
[versionImg]: https://img.shields.io/nexus/placeholderapi/me.clip/placeholderapi?server=https%3A%2F%2Frepo.extendedclip.com&label=API%20Version
|
||||
[plugin-page]: https://spigotmc.org/resources/6245
|
||||
|
||||
> © 2015 - 2021 [PlaceholderAPI Team][papi]
|
||||
> Thanks for using PlaceholderAPI.
|
||||
>
|
||||
> **[Plugin-page]** | **[[Placeholders]]** | **[[Plugins using PlaceholderAPI]]** | **[[Hook into PlaceholderAPI]]**
|
||||
>
|
||||
> ![versionImg] [![jenkinsImg]][jenkins] [![licenseImg]][license] [![issuesImg]][issues] [![discordImg]][discord]
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user