Compare commits

...

74 Commits

Author SHA1 Message Date
PiggyPiglet
968df21ef0 we're really getting somewhere!@1
who the fuck decided to use 2 space instead of 4
2025-11-17 14:11:21 +08:00
PiggyPiglet
2a8bb3695c Start merging chars replacer logic into adventure replacer
very rough no judge
2025-10-25 13:04:24 +08:00
PiggyPiglet
683dc6e8e3 Uhh 2025-10-25 12:33:33 +08:00
Funnycube
f14b081f0b Add modrinth 2025-08-15 17:06:52 +10:00
PiggyPiglet
b51fbf4e13 Fix jenkins build
disableAutoTargetJvm in gradle
2025-07-03 13:40:53 +08:00
PiggyPiglet
e48b6fe702 Update NMSVersion enum 2025-07-01 20:44:21 +08:00
PiggyPiglet
984f944daf Merge pull request #1127 from PlaceholderAPI/folia
Merge UniversalScheduler (Folia Support) #980
2025-07-01 20:24:13 +08:00
PiggyPiglet
0575c8cf41 Merge UniversalScheduler 2025-07-01 09:39:48 +08:00
PiggyPiglet
c181d18f5e Revert "Merge pull request #1092 from CoderKuo/master"
This reverts commit 2e0d9eb846, reversing
changes made to 33d1009d6a.
2025-06-16 11:08:43 +08:00
PiggyPiglet
2e0d9eb846 Merge pull request #1092 from CoderKuo/master
Optimize text replacement algorithm performance
2025-04-21 15:23:40 +08:00
PiggyPiglet
33d1009d6a Merge pull request #1095 from Kqliber/fix/1094
fix for all expansions stop loading after an exception is thrown (#1094)
2025-03-30 20:46:34 +08:00
PiggyPiglet
b16d62fb75 fix maven repo publishing (maybe?) 2025-03-30 20:41:51 +08:00
Funnycube
e019d6370c Merge pull request #1098 from Funny-cube/master
Revert api links
2025-01-16 13:31:08 +11:00
Funnycube
581b73dbc7 revert home link 2025-01-16 13:28:43 +11:00
Funnycube
25f7eafe32 revert api link 2025-01-16 13:27:45 +11:00
Kqliber
ef22d564f3 remove imports 2025-01-08 18:23:49 +00:00
Kqliber
787a053d98 fix for all expansions stop loading after an exception is thrown (#1094) 2025-01-08 18:21:43 +00:00
大阔
f31dd2bea9 Add fast path check for closure.head and closure.tail 2025-01-03 03:18:40 +08:00
大阔
5c8086150a Optimize text replacement algorithm performance 2025-01-03 02:23:17 +08:00
PiggyPiglet
b838d1c52a Update ecloud api link 2024-11-27 19:58:05 +08:00
Andre_601
0a712e6530 Fix API version badge + update flex 2024-11-13 14:40:41 +01:00
Gabriel Dumitru
272e2e7904 Merge pull request #1000 from mfnalex/master
Added missing NotNull annotations to setBracketPlaceholders methods
2024-07-10 22:35:49 +03:00
PiggyPiglet
98082398fc Target java release 8 for compilation 2024-07-04 17:46:04 +08:00
PiggyPiglet
c66806ecf8 Merge pull request #1067 from PlaceholderAPI/feat/1.21
feat: initial work on 1.21
2024-07-04 17:26:16 +08:00
Andre_601
c97f5aa5a6 Bump download stats 2024-06-18 22:45:15 +02:00
Glare
c1487898a9 chore(deps): update gradle + shadow fork 2024-06-14 10:07:06 -05:00
Glare
907ced6d7d feat: initial work on 1.21 2024-06-13 18:08:58 -05:00
PiggyPiglet
ac771207c3 bump to dev version 2024-05-21 18:51:05 +08:00
PiggyPiglet
8b031576aa bump version for release 2024-05-21 18:31:02 +08:00
PiggyPiglet
2d1a0ee157 Merge pull request #1060 from PlaceholderAPI/fix/parse-command-improvements
Parse command improvements
2024-05-21 18:08:19 +08:00
PiggyPiglet
b9e2bf9429 Merge pull request #1061 from PlaceholderAPI/feature/update-adventure-platform-bukkit
Update Adventure-platform-bukkit to 4.3.2
2024-05-21 18:05:13 +08:00
PiggyPiglet
a35923a117 cast instead of #getplayer 2024-05-21 17:59:57 +08:00
PiggyPiglet
d5e96bd6a6 exclude module-info fix #894 2024-05-20 22:44:44 +08:00
Andre601
2523b6c094 Update Adventure-platform-bukkit to 4.3.2 2024-05-10 14:41:51 +02:00
Andre601
7b230fc679 Fix output for parse command + "me" support in parserel 2024-05-06 16:42:24 +02:00
Andre_601
68f467ab29 Add 1.20.2 - 1.20.5 to NMSVersion.java (#1057) 2024-04-30 10:35:18 -05:00
PiggyPiglet
068b5a31b2 Fix #1034 & Deprecate VersionSpecific & update copyright (#1035)
Co-authored-by: Andre_601 <github@andre601.ch>
2024-04-30 10:34:43 -05:00
Gabriel Dumitru
882b7c5965 Merge pull request #1046 from PlaceholderAPI/feature/add-plugin-authors
Add Plugin Authors to /papi dump
2024-03-07 22:59:42 +02:00
Gabriel Dumitru
7a0be5edf8 Merge pull request #1040 from DevCyntrix/fix-class-cast-exception
Use the OfflinePlayer$getPlayer method instead of casting to Player class
2024-03-07 22:59:24 +02:00
Andre601
e94328935d Add Plugin Authors to /papi dump 2024-02-25 14:42:48 +01:00
Andre_601
604fed36a4 Man, this file is outdated... 2024-02-25 00:14:41 +01:00
Ricardo Borutta
403622d205 Use the OfflinePlayer$getPlayer method instead of casting to Player class
You should use this to avoid a class cast exception if some other plugins uses an own Implementation of the offline player.
2024-01-29 10:21:24 +01:00
Funnycube
1cd4d93f7f Merge pull request #1038 from Funny-cube/master
Update config.yml with papi domain for wiki and ecloud
2024-01-27 21:57:48 +11:00
Funnycube
a83ef75bf9 Update config.yml 2024-01-27 20:45:10 +11:00
Andre_601
b96e535aaa Update wiki link in PR template 2024-01-27 00:58:11 +01:00
Andre_601
2e67272aea Fix logo and update link in README 2024-01-26 23:05:04 +01:00
Andre_601
2c7767e77d fix github admonition blocks 2024-01-22 20:12:39 +01:00
Andre_601
c4a046ff24 Merge pull request #1006 from PlaceholderAPI/feature/add-new-download-pages
Add Hangar and BuiltByBit pages to readme
2023-11-26 16:58:08 +01:00
PiggyPiglet
57fa68c896 change version to .6-dev 2023-10-28 21:50:05 +08:00
PiggyPiglet
b64f024eb2 fix config version variable and set release version 2023-10-28 21:49:39 +08:00
PiggyPiglet
c7a4900aa3 remove ability to download unverified expansions 2023-10-28 21:42:18 +08:00
Andre_601
491abd6238 BuilT not BuilD 2023-09-25 15:11:49 +02:00
Andre_601
d3646a9874 Change Built By Bit to BuiltByBit Page 2023-09-25 15:07:13 +02:00
Andre_601
af0b475330 Add Hangar and BuiltByBit pages to readme 2023-09-25 14:58:30 +02:00
Funnycube
d35a499e31 Update plugin.yml
remove unused toggle permissions
2023-09-24 13:49:40 +10:00
Funnycube
c0f824450e Update build.gradle.kts
start 2.11.5-DEV
2023-09-24 12:59:01 +10:00
Funnycube
5b1a8ef4ba 2.11.4 release 2023-09-24 12:40:46 +10:00
PiggyPiglet
5623a00f9b Merge pull request #978 from JulianVennen/block-unverified-expansions
Add environment variable to override cloud_allowunverified_expansions
2023-09-21 17:38:54 +08:00
PiggyPiglet
4926907b47 Merge pull request #969 from PlaceholderAPI/feature/support-1.20
1.20 support
2023-09-04 17:26:11 +08:00
mfnalex
32f3d14682 added missing @NotNull to the returned List's type parameter and the parameter List's type parameter (is that proper English?) 2023-08-29 00:57:42 +02:00
mfnalex
152105017d added missing @NotNull to return value and String parameter of setBracketPlaceholders(Player, String) 2023-08-29 00:56:12 +02:00
mfnalex
be956f52b0 added missing @NotNull to return value and List parameter of setBracketPlaceholders(Player, List) 2023-08-29 00:55:28 +02:00
Andre_601
195158b18b Use new format for note block [skip ci] 2023-08-01 03:27:15 +02:00
Gabriel Dumitru
36fa9ac96d feat: distinguish expansions (external or internal) (fixes #945) (#953) 2023-07-24 11:48:29 +03:00
Julian
42cfe1dc80 simplify env values to true/false 2023-06-23 17:06:11 +02:00
Julian
92a7d54664 Add environment variable to override cloud_allowunverified_expansions
This adds the environment variable PAPI_ALLOW_UNVERIFIED_EXPANSIONS.
It allows overriding the option set in the config.yml.
2023-06-23 14:04:00 +02:00
Gabriel Dumitru
f91b4e3752 feat: fetch all expansions (#952) 2023-06-21 21:26:52 +03:00
PiggyPiglet
a497e05e55 Merge pull request #947 from JulianVennen/block-extensions-env
Add environment variable to block individual ecloud expansions.
2023-06-21 20:25:16 +08:00
Andre601
74d8fec6bd Bump Spigot version 2023-06-10 18:13:10 +02:00
Andre601
28287c7fbd 1.20 NMS version support 2023-06-10 17:59:55 +02:00
Gabriel Dumitru
744cf6d8c0 Merge pull request #946 from JulianVennen/block-load-path-traversal
Prevent loading of extensions outside of the expansions folder using the register command
2023-04-04 17:28:00 +03:00
Julian
ecd4c002c8 Add environment variable to block individual ecloud expansions.
This commit adds the environment variable "PAPI_BLOCKED_EXPANSIONS"
which can contain a case insensitive, comma separated list of blocked
expansions.
Expansions on this list can no longer be downloaded using commands.
2023-03-30 13:41:01 +02:00
Julian
b4e60b7db5 Prevent loading of extensions outside of the expansions folder using the register command 2023-03-30 12:47:23 +02:00
darbyjack
e862abe0b4 Start 2.11.4 DEV cycle 2023-03-17 20:07:24 -05:00
82 changed files with 5066 additions and 3344 deletions

View File

@@ -1,7 +1,7 @@
[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/docs/wiki/wiki
[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
[style]: https://github.com/PlaceholderAPI/PlaceholderAPI/tree/master/config/style
@@ -40,7 +40,8 @@ In those cases should you report the issue to the issue tracker of the expansion
## 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.
**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.**
> [!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.
### Code contributions
> **Source and Target Branch:** [`master`][master]
@@ -56,12 +57,10 @@ Javadocs changes should usually be combined with [code contributions](#code-cont
\*This branch may change in the future.
### Wiki contributions
> **Source and Target Branch:** [`docs/wiki`][docs-wiki]
> **Source and Target Branch:** [`wiki`][docs-wiki]
The Wiki of PlaceholderAPI has a unique quirk by having a dedicated [`wiki` folder][wiki] hosting the pages found on the actual wiki itself.
If you find outdated information, want to add missing expansions/plugins or just like to correct some wrong spelling should you both base of and target your contributions on the `docs/wiki` branch.
**Please only PR changes for the `wiki` folder on the `docs/wiki` branch! Pull requests not following this guidelines will be closed unnanounced.**
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.
## Code of Conduct
We have a [Code of Conduct] to maintain a welcoming atmosphere in this project.

View File

@@ -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://github.com/PlaceholderAPI/PlaceholderAPI/wiki
[Wiki]: https://wiki.placeholderapi.com

View File

@@ -1,8 +1,8 @@
comment:
footer: "\
----\n\n
> **Note**\n
> *This is an automated response created by a **GitHub Action***\n
> [!NOTE]\n
> *This is an automated response created by a **GitHub Action***<br>
> *Mentioning the bot won't have any effect!*
"

View File

@@ -7,6 +7,9 @@
[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
@@ -14,11 +17,11 @@
[ci]: http://ci.extendedclip.com/job/PlaceholderAPI/
[ciImg]: http://ci.extendedclip.com/buildStatus/icon?job=PlaceholderAPI
[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/wiki/img/papi-logo.png
[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
[contributing]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/.github/CONTRIBUTING.md
[placeholderexpansion]: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/PlaceholderExpansion
[placeholderexpansion]: https://wiki.placeholderapi.com/developers/creating-a-placeholderexpansion/
<!-- The stuff above isn't visible in the readme -->
[![logo]][spigot]
@@ -30,7 +33,7 @@
Support for specific plugins are provided either by the plugin itself or through expansions. The expansions may be downloaded in-game through the PAPI Expansion Cloud. There are currently over 240+ expansions that support a wide variety of plugins, such as Essentials, Factions, LuckPerms, and Vault.
PlaceholderAPI has been downloaded over 1,000,000 times and has been used concurrently on over 40,000 servers, which makes it a must-have for a server of any type or scale.
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.
## 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.
@@ -47,4 +50,7 @@ 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]

View File

@@ -4,11 +4,11 @@ plugins {
`java-library`
`maven-publish`
id("com.github.hierynomus.license") version "0.16.1"
id("com.github.johnrengelman.shadow") version "8.1.0"
id("io.github.goooler.shadow") version "8.1.7"
}
group = "me.clip"
version = "2.11.3"
version = "2.11.7-DEV-${System.getProperty("BUILD_NUMBER")}"
description = "An awesome placeholder provider!"
@@ -20,13 +20,16 @@ repositories {
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.3.0")
implementation("net.kyori:adventure-platform-bukkit:4.4.1")
compileOnly("org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT")
//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")
@@ -43,6 +46,8 @@ java {
withJavadocJar()
withSourcesJar()
disableAutoTargetJvm()
}
license {
@@ -54,7 +59,7 @@ license {
encoding = "UTF-8"
ext {
set("year", 2021)
set("year", 2024)
}
}
@@ -71,6 +76,7 @@ tasks {
withType<JavaCompile> {
options.encoding = "UTF-8"
options.release = 8
}
withType<Javadoc> {
@@ -87,7 +93,14 @@ tasks {
archiveClassifier.set("")
relocate("org.bstats", "me.clip.placeholderapi.metrics")
relocate("net.kyori", "me.clip.placeholderapi.libs.kyori")
// 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 {
@@ -105,9 +118,9 @@ tasks {
repositories {
maven {
if ("-DEV" in version.toString()) {
url = uri("https://repo.extendedclip.com/content/repositories/dev/")
url = uri("https://repo.extendedclip.com/snapshots")
} else {
url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")
url = uri("https://repo.extendedclip.com/releases")
}
credentials {

View File

@@ -1,4 +1,4 @@
Copyright (c) 2018-2021 Peter Blood
Copyright (c) 2018-2024 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:

Binary file not shown.

View File

@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

28
gradlew vendored
View File

@@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright <EFBFBD> 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions <EFBFBD>$var<EFBFBD>, <EFBFBD>${var}<EFBFBD>, <EFBFBD>${var:-default}<EFBFBD>, <EFBFBD>${var+SET}<EFBFBD>,
# <EFBFBD>${var#prefix}<EFBFBD>, <EFBFBD>${var%suffix}<EFBFBD>, and <EFBFBD>$( cmd )<EFBFBD>;
# * compound commands having a testable exit status, especially <EFBFBD>case<EFBFBD>;
# * various built-in commands including <EFBFBD>command<EFBFBD>, <EFBFBD>set<EFBFBD>, and <EFBFBD>ulimit<EFBFBD>.
# * 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:
#
@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# 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/.
@@ -80,10 +80,10 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# 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"'
@@ -143,12 +143,16 @@ fi
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
@@ -205,6 +209,12 @@ set -- \
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.

15
gradlew.bat vendored
View File

@@ -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,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 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!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
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%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

View File

@@ -0,0 +1,121 @@
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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,15 +21,19 @@
package me.clip.placeholderapi;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
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;
@@ -50,209 +54,229 @@ 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 {
final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
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);
}
boolean isSpigot;
try {
Class.forName("org.spigotmc.SpigotConfig");
isSpigot = true;
} catch (final ExceptionInInitializerError | ClassNotFoundException ignored) {
isSpigot = false;
boolean isSpigot;
try {
Class.forName("org.spigotmc.SpigotConfig");
isSpigot = true;
} catch (final ExceptionInInitializerError | ClassNotFoundException ignored) {
isSpigot = false;
}
VERSION = new Version(version, isSpigot);
}
VERSION = new Version(version, isSpigot);
}
@NotNull
private final PlaceholderAPIConfig config = new PlaceholderAPIConfig(this);
@NotNull
private final PlaceholderAPIConfig config = new PlaceholderAPIConfig(this);
@NotNull
private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
@NotNull
private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
@NotNull
private final TaskScheduler scheduler = UniversalScheduler.getScheduler(this);
@NotNull
private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
@NotNull
private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
private BukkitAudiences adventure;
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;
}
/**
* 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) {
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");
}
}
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();
/**
* 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;
}
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 true
*
* @return string value of true
*/
@NotNull
public static String booleanTrue() {
return getInstance().getPlaceholderAPIConfig().booleanTrue();
}
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 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();
}
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);
/**
* 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);
}
}
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -20,16 +20,19 @@
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) player, params);
return onPlaceholderRequest(player.getPlayer(), params);
}
return onPlaceholderRequest(null, params);

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -22,10 +22,12 @@ 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;
@@ -34,75 +36,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);
}
@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(Locale.ROOT).startsWith(parameter.toLowerCase(Locale.ROOT)))
.forEach(suggestions::add);
setPermission("placeholderapi." + label);
}
}
@NotNull
public final String getLabel() {
return 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()));
}
@NotNull
@Unmodifiable
public final Set<String> getAlias() {
return ImmutableSet.copyOf(alias);
}
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> getLabels() {
return ImmutableSet.<String>builder().add(label).addAll(alias).build();
}
@NotNull
public final String getLabel() {
return label;
}
@Nullable
public final String getPermission() {
return permission;
}
@NotNull
@Unmodifiable
public final Set<String> getAlias() {
return ImmutableSet.copyOf(alias);
}
public void setPermission(@NotNull final String permission) {
this.permission = permission;
}
@NotNull
@Unmodifiable
public final Set<String> getLabels() {
return ImmutableSet.<String>builder().add(label).addAll(alias).build();
}
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
@Nullable
public final String getPermission() {
return permission;
}
}
public void setPermission(@NotNull final String permission) {
this.permission = permission;
}
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 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) {
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -22,6 +22,7 @@ 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;
@@ -30,6 +31,7 @@ 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;
@@ -51,93 +53,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));
for (final PlaceholderCommand command : COMMANDS) {
command.getLabels().forEach(label -> commands.put(label, command));
}
this.commands = commands.build();
}
this.commands = commands.build();
}
@Override
public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Command command,
@NotNull final String alias, @NotNull final String[] args) {
if (args.length == 0) {
final PlaceholderCommand fallback = commands.get("version");
if (fallback != null) {
fallback.evaluate(plugin, sender, "", Collections.emptyList());
}
@Override
public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Command command,
@NotNull final String alias, @NotNull final String[] args) {
if (args.length == 0) {
final PlaceholderCommand fallback = commands.get("version");
if (fallback != null) {
fallback.evaluate(plugin, sender, "", Collections.emptyList());
}
return true;
}
return true;
final String search = args[0].toLowerCase(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;
}
final String search = args[0].toLowerCase(Locale.ROOT);
final PlaceholderCommand target = commands.get(search);
@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 (target == null) {
Msg.msg(sender, "&cUnknown command &7" + search);
return true;
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;
}
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(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;
}
}

View File

@@ -0,0 +1,51 @@
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));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -37,110 +37,110 @@ 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 CommandECloudStatus(),
new CommandECloudUpdate(),
new CommandECloudRefresh(),
new CommandECloudDownload(),
new CommandECloudExpansionInfo(),
new CommandECloudExpansionList(),
new CommandECloudExpansionPlaceholders());
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));
static {
COMMANDS
.forEach(command -> command.setPermission("placeholderapi.ecloud." + command.getLabel()));
}
this.commands = commands.build();
}
@NotNull
@Unmodifiable
private final Map<String, PlaceholderCommand> commands;
@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.");
public CommandECloud() {
super("ecloud");
return;
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();
}
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;
@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()));
}
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;
@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);
}
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()));
}
@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);
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
package me.clip.placeholderapi.commands.impl.cloud;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -30,17 +31,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!");
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -20,9 +20,11 @@
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;
@@ -33,87 +35,106 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudDownload extends PlaceholderCommand {
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;
public CommandECloudDownload() {
super("download");
}
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;
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.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) {
@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,
"&cFailed to download expansion: &f" + exception.getMessage());
"&cYou must supply the name of an expansion.");
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!");
if (isBlockedExpansion(params.get(0))) {
Msg.msg(sender,
"&cThis expansion can't be downloaded.");
return;
}
plugin.getCloudExpansionManager().clean();
plugin.getCloudExpansionManager()
.fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
});
}
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 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 (!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();
});
}
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;
}
@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 Optional<CloudExpansion> expansion = plugin.getCloudExpansionManager()
.findCloudExpansionByName(params.get(0));
if (!expansion.isPresent()) {
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;
}
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
}
final Optional<CloudExpansion> expansion = plugin.getCloudExpansionManager()
.findCloudExpansionByName(params.get(0));
if (!expansion.isPresent()) {
return;
}
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -23,6 +23,7 @@ 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;
@@ -33,97 +34,97 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudExpansionInfo extends PlaceholderCommand {
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;
public CommandECloudExpansionInfo() {
super("info");
}
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 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 StringBuilder builder = new StringBuilder();
@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;
}
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() <= 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;
}
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;
}
final Optional<CloudExpansion> expansion = plugin.getCloudExpansionManager()
.findCloudExpansionByName(params.get(0));
if (!expansion.isPresent()) {
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');
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
}
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));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -25,12 +25,14 @@ 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;
@@ -54,299 +56,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");
}
@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();
}
}
@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();
public CommandECloudExpansionList() {
super("list");
}
return expansions.subList(head, tail);
}
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;
}
if (page == -1) {
builder.append('\n');
return;
}
builder.append(" &bPage&7: &a")
.append(page)
.append("&r");
}
private static Component getMessage(@NotNull final List<CloudExpansion> expansions,
final int page, final int limit, @NotNull final String target) {
final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat();
final TextComponent.Builder message = text();
for (int index = 0; index < expansions.size(); index++) {
final CloudExpansion expansion = expansions.get(index);
final TextComponent.Builder line = text();
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;
@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();
}
}
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());
@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);
final TextComponent.Builder left = text("", page > 1 ? GRAY : DARK_GRAY).toBuilder();
if (expansions.size() < head) {
return Collections.emptyList();
}
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 expansions.subList(head, tail);
}
return message.build();
}
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;
}
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<>();
if (page == -1) {
builder.append('\n');
return;
}
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()));
builder.append(" &bPage&7: &a")
.append(page)
.append("&r");
}
final List<String> table = Format.tablify(Format.Align.LEFT, rows)
.orElse(Collections.emptyList());
if (table.isEmpty()) {
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();
final TextComponent.Builder message = text();
for (int index = 0; index < expansions.size(); index++) {
final CloudExpansion expansion = expansions.get(index);
final TextComponent.Builder line = text();
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();
}
table.add(1, "&8" + Strings.repeat("-", table.get(0).length() - (rows.get(0).size() * 2)));
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<>();
message.append(String.join("\n", table));
}
final AtomicInteger counter = new AtomicInteger(startIndex);
functions.put("&f", expansion -> "&8" + counter.getAndIncrement() + ".");
@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;
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));
}
final boolean installed = params.get(0).equalsIgnoreCase("installed");
final List<CloudExpansion> expansions = Lists
.newArrayList(getExpansions(params.get(0), plugin));
@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;
}
if (expansions.isEmpty()) {
Msg.msg(sender,
"&cNo expansions available to list.");
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);
}
expansions
.sort(plugin.getPlaceholderAPIConfig().getExpansionSort().orElse(ExpansionSort.LATEST));
@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 (!(sender instanceof Player) && params.size() < 2) {
final StringBuilder builder = new StringBuilder();
if (params.size() <= 1) {
suggestByParameter(
Sets.union(OPTIONS, plugin.getCloudExpansionManager().getCloudExpansionAuthors())
.stream(), suggestions, params.isEmpty() ? null : params.get(0));
return;
}
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;
suggestByParameter(IntStream.rangeClosed(1,
(int) Math.ceil((double) getExpansions(params.get(0), plugin).size() / PAGE_SIZE))
.mapToObj(Objects::toString), suggestions, params.get(1));
}
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));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,9 +21,11 @@
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;
@@ -34,61 +36,61 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudExpansionPlaceholders extends PlaceholderCommand {
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;
public CommandECloudExpansionPlaceholders() {
super("placeholders");
}
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 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 List<String> placeholders = expansion.getPlaceholders();
if (placeholders == null || placeholders.isEmpty()) {
Msg.msg(sender,
"&cThe expansion specified does not have placeholders listed.");
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<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));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
package me.clip.placeholderapi.commands.impl.cloud;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -30,20 +31,18 @@ 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().clean();
plugin.getCloudExpansionManager()
.fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
plugin.getCloudExpansionManager().load();
Msg.msg(sender,
"&aThe eCloud manager has been refreshed!");
}
Msg.msg(sender,
"&aThe eCloud manager has been refreshed!");
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
package me.clip.placeholderapi.commands.impl.cloud;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.manager.CloudExpansionManager;
@@ -31,34 +32,34 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudStatus extends PlaceholderCommand {
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.");
public CommandECloudStatus() {
super("status");
}
Msg.msg(sender, builder.toString());
}
@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());
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
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;
@@ -28,6 +29,7 @@ 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;
@@ -44,98 +46,98 @@ import org.jetbrains.annotations.Unmodifiable;
*/
public final class CommandECloudUpdate extends PlaceholderCommand {
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;
public CommandECloudUpdate() {
super("update");
}
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);
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());
}
// remove the ones that are the latest version
expansions.removeIf(expansion -> !expansion.shouldUpdate());
@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;
}
if (expansions.isEmpty()) {
Msg.msg(sender,
"&cNo updates available for " + (!multiple ? "this expansion."
: "your active expansions."));
return;
}
final boolean multiple = params.get(0).equalsIgnoreCase("all");
final List<CloudExpansion> expansions = new ArrayList<>();
Msg.msg(sender,
"&aUpdating expansions: " + expansions.stream().map(CloudExpansion::getName)
.collect(Collectors.joining("&7, &6", "&8[&6", "&8]&r")));
// 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;
}
Futures.onMainThread(plugin, downloadAndDiscover(expansions, plugin), (classes, exception) -> {
if (exception != null) {
Msg.msg(sender,
"&cFailed to update expansions: &e" + exception.getMessage());
return;
}
"&aUpdating expansions: " + expansions.stream().map(CloudExpansion::getName)
.collect(Collectors.joining("&7, &6", "&8[&6", "&8]&r")));
Msg.msg(sender,
"&aSuccessfully downloaded updates, registering new versions.");
Futures.onMainThread(plugin, downloadAndDiscover(expansions, plugin), (classes, exception) -> {
if (exception != null) {
Msg.msg(sender,
"&cFailed to update expansions: &e" + exception.getMessage());
return;
}
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,
"&aSuccessfully downloaded updates, registering new versions.");
Msg.msg(sender,
"&7Registered expansions:", message);
final String message = classes.stream()
.filter(Objects::nonNull)
.map(plugin.getLocalExpansionManager()::register)
.filter(Optional::isPresent)
.map(Optional::get)
.map(expansion -> " &a" + expansion.getName() + " &f" + expansion.getVersion())
.collect(Collectors.joining("\n"));
});
}
Msg.msg(sender,
"&7Registered expansions:", message);
@Override
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<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());
@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;
}
if (!installed.isEmpty() && (params.isEmpty() || "all"
.startsWith(params.get(0).toLowerCase(Locale.ROOT)))) {
suggestions.add("all");
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));
}
suggestByParameter(
installed.stream().map(CloudExpansion::getName).map(name -> name.replace(" ", "_")),
suggestions, params.isEmpty() ? null : params.get(0));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -54,158 +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();
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");
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();
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');
}
}
} catch (final IOException ex) {
throw new CompletionException(ex);
}
});
}
@NotNull
private String makeDump(@NotNull final PlaceholderAPIPlugin plugin) {
final StringBuilder builder = new StringBuilder();
builder.append('\n');
builder.append("Generated: ")
.append(DATE_FORMAT.format(Instant.now()))
.append("\n\n");
builder.append("Server Info: ")
.append(plugin.getServer().getBukkitVersion())
.append('/')
.append(plugin.getServer().getVersion())
.append("\n");
builder.append("PlaceholderAPI: ")
.append(plugin.getDescription().getVersion())
.append("\n\n");
builder.append("Java Version: ")
.append(System.getProperty("java.version"))
.append("\n\n");
builder.append("Expansions Registered:")
.append('\n');
builder.append("Plugin Info:")
.append('\n');
final List<PlaceholderExpansion> expansions = plugin.getLocalExpansionManager()
.getExpansions()
.stream()
.sorted(
Comparator.comparing(PlaceholderExpansion::getIdentifier)
.thenComparing(PlaceholderExpansion::getAuthor)
)
.collect(Collectors.toList());
List<Plugin> plugins = Arrays.stream(plugin.getServer().getPluginManager().getPlugins())
.sorted(Comparator.comparing(Plugin::getName))
.collect(Collectors.toList());
int size = expansions.stream().map(e -> e.getIdentifier().length())
.max(Integer::compareTo)
.orElse(0);
size = plugins.stream().map(pl -> pl.getName().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");
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();
}
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');
}
}
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());
size = plugins.stream().map(pl -> pl.getName().length())
.max(Integer::compareTo)
.orElse(0);
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();
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -25,6 +25,7 @@ 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;
@@ -37,74 +38,74 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandExpansionRegister extends PlaceholderCommand {
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;
public CommandExpansionRegister() {
super("register");
}
final LocalExpansionManager manager = plugin.getLocalExpansionManager();
@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 File file = new File(manager.getExpansionsFolder(), params.get(0));
if (!file.exists()) {
Msg.msg(sender,
"&cThe file &f" + file.getName() + "&c doesn't exist!");
return;
final LocalExpansionManager manager = plugin.getLocalExpansionManager();
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());
});
}
Futures.onMainThread(plugin, manager.findExpansionInFile(file), (clazz, exception) -> {
if (exception != null) {
Msg.msg(sender,
"&cFailed to find expansion in file: &f" + file);
@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;
}
plugin.getLogger()
.log(Level.WARNING, "failed to find expansion in file: " + file, exception);
return;
}
final String[] fileNames = plugin.getLocalExpansionManager().getExpansionsFolder()
.list((dir, name) -> name.endsWith(".jar"));
if (fileNames == null || fileNames.length == 0) {
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());
});
}
@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(Arrays.stream(fileNames), suggestions,
params.isEmpty() ? null : params.get(0));
}
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));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -22,6 +22,7 @@ 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;
@@ -33,45 +34,45 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandExpansionUnregister extends PlaceholderCommand {
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;
public CommandExpansionUnregister() {
super("unregister");
}
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 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 String message = !expansion.get().unregister() ?
"&cFailed to unregister expansion: &f" :
"&aSuccessfully unregistered expansion: &f";
@Override
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
if (params.size() > 1) {
return;
}
Msg.msg(sender, message + expansion.get().getName());
}
@Override
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
if (params.size() > 1) {
return;
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions,
params.isEmpty() ? null : params.get(0));
}
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions,
params.isEmpty() ? null : params.get(0));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
package me.clip.placeholderapi.commands.impl.local;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -31,42 +32,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|--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");
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
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;
@@ -32,82 +33,82 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandInfo extends PlaceholderCommand {
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;
public CommandInfo() {
super("info");
}
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 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 StringBuilder builder = new StringBuilder();
@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;
}
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');
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions,
params.isEmpty() ? null : params.get(0));
}
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));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,9 +21,11 @@
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;
@@ -34,28 +36,28 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandList extends PlaceholderCommand {
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;
public CommandList() {
super("list");
}
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")));
}
@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")));
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -25,6 +25,7 @@ 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;
@@ -40,191 +41,217 @@ import org.jetbrains.annotations.Unmodifiable;
public final class CommandParse extends PlaceholderCommand {
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(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;
}
}
@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;
}
}
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;
public CommandParse() {
super("parse", "bcparse", "parserel", "cmdparse");
}
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;
@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;
}
}
final String message = PlaceholderAPI
.setPlaceholders(player, String.join(" ", params.subList(1, params.size())));
if (command) {
Bukkit.dispatchCommand(sender, message);
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) {
switch (alias.toLowerCase(Locale.ROOT)) {
case "parserel":
completeParseRelation(params, suggestions);
break;
case "parse":
case "bcparse":
case "cmdparse":
completeParseSingular(sender, params, suggestions);
break;
}
}
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 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);
}
}
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 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 targetTwo = resolvePlayer(params.get(1));
if (targetTwo == null || !targetTwo.isOnline()) {
Msg.msg(sender, "&cFailed to find player: &f" + params.get(1));
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 String message = PlaceholderAPI
.setRelationalPlaceholders(((Player) targetOne), ((Player) targetTwo),
String.join(" ", params.subList(2, params.size())));
sender.sendMessage(message);
}
private void completeParseRelation(@NotNull @Unmodifiable final List<String> params,
@NotNull final List<String> suggestions) {
if (params.size() > 2) {
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 Stream<String> names = Bukkit.getOnlinePlayers().stream().map(Player::getName);
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(params.size() - 1));
}
final String name = params.get(params.size() - 1);
if (!name.startsWith("%") || name.endsWith("%")) {
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 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;
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
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;
@@ -29,15 +30,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);
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
package me.clip.placeholderapi.commands.impl.local;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
@@ -31,22 +32,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");
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -38,10 +38,6 @@ 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");

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -29,61 +29,61 @@ 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.
*/
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;
}
/**
* 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;
}
@NotNull
public static HandlerList getHandlerList() {
return HANDLERS;
}
/**
* 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;
}
/**
* 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 void setCancelled(boolean cancelled) {
this.cancelled = 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;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -28,7 +28,7 @@ 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
@@ -36,35 +36,35 @@ import org.jetbrains.annotations.NotNull;
*/
public final class ExpansionUnregisterEvent extends Event {
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
@NotNull
private final PlaceholderExpansion expansion;
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
public ExpansionUnregisterEvent(@NotNull final PlaceholderExpansion expansion) {
this.expansion = expansion;
}
@NotNull
private final PlaceholderExpansion expansion;
@NotNull
public static HandlerList getHandlerList() {
return HANDLERS;
}
/**
* The {@link PlaceholderExpansion PlaceholderExpansion} that was unregistered.
*
* @return The {@link PlaceholderExpansion PlaceholderExpansion} instance.
*/
@NotNull
public PlaceholderExpansion getExpansion() {
return expansion;
}
public ExpansionUnregisterEvent(@NotNull final PlaceholderExpansion expansion) {
this.expansion = expansion;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
@NotNull
public static HandlerList getHandlerList() {
return HANDLERS;
}
/**
* The {@link PlaceholderExpansion PlaceholderExpansion} that was unregistered.
*
* @return The {@link PlaceholderExpansion PlaceholderExpansion} instance.
*/
@NotNull
public PlaceholderExpansion getExpansion() {
return expansion;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -23,6 +23,7 @@ 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;
@@ -32,14 +33,14 @@ 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.
*/
public class ExpansionsLoadedEvent extends Event {
private final List<PlaceholderExpansion> expansions;
public ExpansionsLoadedEvent(List<PlaceholderExpansion> expansions) {
this.expansions = Collections.unmodifiableList(expansions);
}
@@ -47,16 +48,16 @@ public class ExpansionsLoadedEvent extends Event {
/**
* 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(){
public final List<PlaceholderExpansion> getExpansions() {
return expansions;
}
@NotNull
private static final HandlerList HANDLERS = new HandlerList();

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -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;
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -46,7 +46,15 @@ public enum NMSVersion {
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_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");
private final String version;

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -40,6 +40,14 @@ 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 _
@@ -159,6 +167,27 @@ 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 ===
/**
@@ -166,7 +195,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 epxpansion has.
* @return ConfigurationSection that this expansion has.
*/
@Nullable
public final ConfigurationSection getConfigSection() {
@@ -394,8 +423,8 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
*/
@Override
public final String toString() {
return String.format("PlaceholderExpansion[name: '%s', author: '%s', version: '%s']", getName(),
getAuthor(), getVersion());
return String.format("PlaceholderExpansion[name: '%s', author: '%s', version: '%s', type: '%s']", getName(),
getAuthor(), getVersion(), getExpansionType());
}
// === Deprecated API ===
@@ -432,4 +461,19 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
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
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -20,26 +20,27 @@
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);
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -27,7 +27,10 @@ package me.clip.placeholderapi.expansion;
* with that version.
*
* @author Ryan McCarthy
*
* @deprecated Will be removed in a future release.
*/
@Deprecated
public interface VersionSpecific {
/**

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -23,180 +23,181 @@ 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 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 CloudExpansion() {
}
public void setUrl(String url) {
this.url = url;
public String getTimeSinceLastUpdate() {
int time = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getLastUpdate());
return TimeUtil.getTime(time);
}
public String getVersion() {
return version;
public String getName() {
return name;
}
public void setVersion(String version) {
this.version = version;
public void setName(String name) {
this.name = name;
}
public String getReleaseNotes() {
return release_notes;
public String getAuthor() {
return author;
}
public void setReleaseNotes(String release_notes) {
this.release_notes = 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;
}
}
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -25,6 +25,7 @@ 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;
@@ -50,6 +51,7 @@ 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;
@@ -59,223 +61,218 @@ 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;
}
@NotNull
private static String toIndexName(@NotNull final String name) {
return name.toLowerCase(Locale.ROOT).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();
public CloudExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) {
this.plugin = plugin;
}
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 String name) {
return name.toLowerCase(Locale.ROOT).replace(' ', '_');
}
return cache.values()
.stream()
.filter(expansion -> author.equalsIgnoreCase(expansion.getAuthor()))
.collect(INDEXED_NAME_COLLECTOR);
}
@NotNull
private static String toIndexName(@NotNull final CloudExpansion expansion) {
return toIndexName(expansion.getName());
}
@NotNull
@Unmodifiable
public Set<String> getCloudExpansionAuthors() {
return cache.values().stream().map(CloudExpansion::getAuthor).collect(Collectors.toSet());
}
public void load() {
clean();
fetch();
}
public int getCloudExpansionAuthorCount() {
return getCloudExpansionAuthors().size();
}
public void kill() {
clean();
}
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> getCloudExpansions() {
return ImmutableMap.copyOf(cache);
}
@NotNull
public Optional<CloudExpansion> findCloudExpansionByName(@NotNull final String name) {
return Optional.ofNullable(cache.get(toIndexName(name)));
}
@NotNull
@Unmodifiable
public Map<String, CloudExpansion> getCloudExpansionsInstalled() {
if (cache.isEmpty()) {
return Collections.emptyMap();
}
public void clean() {
cache.clear();
return cache.values()
.stream()
.filter(CloudExpansion::hasExpansion)
.collect(INDEXED_NAME_COLLECTOR);
}
await.values().forEach(future -> future.cancel(true));
await.clear();
}
@NotNull
@Unmodifiable
public Map<String, CloudExpansion> getCloudExpansionsByAuthor(@NotNull final String author) {
if (cache.isEmpty()) {
return Collections.emptyMap();
}
public void fetch(final boolean allowUnverified) {
plugin.getLogger().info("Fetching available expansion information...");
return cache.values()
.stream()
.filter(expansion -> author.equalsIgnoreCase(expansion.getAuthor()))
.collect(INDEXED_NAME_COLLECTOR);
}
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));
@NotNull
@Unmodifiable
public Set<String> getCloudExpansionAuthors() {
return cache.values().stream().map(CloudExpansion::getAuthor).collect(Collectors.toSet());
}
List<String> toRemove = new ArrayList<>();
public int getCloudExpansionAuthorCount() {
return getCloudExpansionAuthors().size();
}
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());
}
}
public int getCloudUpdateCount() {
return ((int) plugin.getLocalExpansionManager()
.getExpansions()
.stream()
.filter(expansion -> findCloudExpansionByName(expansion.getName())
.map(CloudExpansion::shouldUpdate).orElse(false))
.count());
}
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);
}
@NotNull
public Optional<CloudExpansion> findCloudExpansionByName(@NotNull final String name) {
return Optional.ofNullable(cache.get(toIndexName(name)));
}
// loop thru what's left on the main thread
plugin
.getServer()
.getScheduler()
.runTask(
plugin,
() -> {
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<>();
try {
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
String name = entry.getKey();
CloudExpansion expansion = entry.getValue();
//noinspection UnstableApiUsage
String json = Resources.toString(new URL(API_URL), StandardCharsets.UTF_8);
values.putAll(GSON.fromJson(json, TYPE));
expansion.setName(name);
List<String> toRemove = new ArrayList<>();
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 (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
CloudExpansion expansion = entry.getValue();
if (expansion.getLatestVersion() == null
|| expansion.getVersion(expansion.getLatestVersion()) == null) {
toRemove.add(entry.getKey());
}
}
cache.put(toIndexName(expansion), expansion);
}
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);
// ugly swallowing of every throwable, but we have to be defensive
plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e);
}
});
});
}
public boolean isDownloading(@NotNull final CloudExpansion expansion) {
return await.containsKey(toIndexName(expansion));
}
// 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();
@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;
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);
}
});
});
}
final File file = new File(plugin.getLocalExpansionManager().getExpansionsFolder(),
"Expansion-" + toIndexName(expansion) + ".jar");
public boolean isDownloading(@NotNull final CloudExpansion expansion) {
return await.containsKey(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);
@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;
}
download.whenCompleteAsync((value, exception) -> {
await.remove(toIndexName(expansion));
final File file = new File(plugin.getLocalExpansionManager().getExpansionsFolder(),
"Expansion-" + toIndexName(expansion) + ".jar");
if (exception != null) {
Msg.severe("Failed to download %s:%s", exception, expansion.getName(), expansion.getVersion());
}
}, ASYNC_EXECUTOR);
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);
await.put(toIndexName(expansion), download);
download.whenCompleteAsync((value, exception) -> {
await.remove(toIndexName(expansion));
return 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;
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -22,6 +22,7 @@ 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;
@@ -34,10 +35,11 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
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;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.events.ExpansionRegisterEvent;
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
@@ -68,417 +70,429 @@ import org.jetbrains.annotations.Unmodifiable;
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!");
}
}
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(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;
if (!this.folder.exists() && !folder.mkdirs()) {
Msg.warn("Failed to create expansions folder!");
}
}
return Optional.ofNullable(bestMatch);
} finally {
expansionsLock.unlock();
}
}
@NotNull
public Optional<PlaceholderExpansion> findExpansionByIdentifier(
@NotNull final String identifier) {
return Optional.ofNullable(getExpansion(identifier));
}
public void load(@NotNull final CommandSender sender) {
registerAll(sender);
}
public void kill() {
unregisterAll();
}
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();
@NotNull
public File getExpansionsFolder() {
return folder;
}
@NotNull
@Unmodifiable
public Collection<String> getIdentifiers() {
expansionsLock.lock();
try {
return ImmutableSet.copyOf(expansions.keySet());
} finally {
expansionsLock.unlock();
}
}
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);
}
return Optional.empty();
}
@ApiStatus.Internal
public boolean register(@NotNull final PlaceholderExpansion expansion) {
final String identifier = expansion.getIdentifier().toLowerCase(Locale.ROOT);
if (!expansion.canRegister()) {
return false;
}
if (expansions.containsKey(identifier)) {
Msg.warn("Failed to load expansion %s. Identifier is already in use.",
expansion.getIdentifier());
return false;
@NotNull
@Unmodifiable
public Collection<PlaceholderExpansion> getExpansions() {
expansionsLock.lock();
try {
return ImmutableSet.copyOf(expansions.values());
} finally {
expansionsLock.unlock();
}
}
if (expansion instanceof Configurable) {
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
String pre = "expansions." + identifier + ".";
FileConfiguration cfg = plugin.getConfig();
boolean save = false;
@Nullable
public PlaceholderExpansion getExpansion(@NotNull final String identifier) {
expansionsLock.lock();
try {
return expansions.get(identifier.toLowerCase(Locale.ROOT));
} finally {
expansionsLock.unlock();
}
}
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);
@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;
}
}
} else {
if (!cfg.contains(pre + entries.getKey())) {
save = true;
cfg.set(pre + entries.getKey(), entries.getValue());
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();
}
}
}
}
if (save) {
plugin.saveConfig();
plugin.reloadConfig();
}
}
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 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;
}
}
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();
}
}
final PlaceholderExpansion removed = getExpansion(identifier);
if (removed != null && !removed.unregister()) {
return false;
}
expansion.setExpansionType(PlaceholderExpansion.Type.EXTERNAL);
final ExpansionRegisterEvent event = new ExpansionRegisterEvent(expansion);
Bukkit.getPluginManager().callEvent(event);
if (!expansion.register()) {
Msg.warn("Cannot load expansion %s due to an unknown issue.", expansion.getIdentifier());
return Optional.empty();
}
if (event.isCancelled()) {
return false;
}
return Optional.of(expansion);
} catch (LinkageError | NullPointerException ex) {
final String reason;
expansionsLock.lock();
try {
expansions.put(identifier, expansion);
} finally {
expansionsLock.unlock();
}
if (ex instanceof LinkageError) {
reason = " (Is a dependency missing?)";
} else {
reason = " - One of its properties is null which is not allowed!";
}
if (expansion instanceof Listener) {
Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin);
}
Msg.info("Successfully registered expansion: %s [%s]", expansion.getIdentifier(),
expansion.getVersion());
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().toLowerCase(Locale.ROOT)) == 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) {
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;
}
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.");
}
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();
}
}
@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());
}
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;
Msg.severe("Failed to load expansion class %s%s", ex, clazz.getSimpleName(), reason);
}
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 Optional.empty();
}
/**
* 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);
if (!expansion.canRegister()) {
return false;
}
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) {
throw new CompletionException(e.getMessage() + " (expansion file: " + file.getAbsolutePath() + ")", e);
}
});
}
// 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;
@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;
}
}
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());
}
}
}
}
@EventHandler
public void onQuit(@NotNull final PlayerQuitEvent event) {
for (final PlaceholderExpansion expansion : getExpansions()) {
if (!(expansion instanceof Cleanable)) {
continue;
}
if (save) {
plugin.saveConfig();
plugin.reloadConfig();
}
}
((Cleanable) expansion).cleanup(event.getPlayer());
}
}
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;
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPluginDisable(@NotNull final PluginDisableEvent event) {
final String name = event.getPlugin().getName();
if (name.equals(plugin.getName())) {
return;
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;
}
for (final PlaceholderExpansion expansion : getExpansions()) {
if (!name.equalsIgnoreCase(expansion.getRequiredPlugin())) {
continue;
}
@ApiStatus.Internal
public boolean unregister(@NotNull final PlaceholderExpansion expansion) {
if (expansions.remove(expansion.getIdentifier().toLowerCase(Locale.ROOT)) == null) {
return false;
}
expansion.unregister();
Msg.info("Unregistered placeholder expansion %s", expansion.getIdentifier());
Msg.info("Reason: required plugin %s was disabled.", name);
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) {
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;
}
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.");
}
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();
}
}
@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());
}
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;
}
for (final PlaceholderExpansion expansion : getExpansions()) {
if (!name.equalsIgnoreCase(expansion.getRequiredPlugin())) {
continue;
}
expansion.unregister();
Msg.info("Unregistered placeholder expansion %s", expansion.getIdentifier());
Msg.info("Reason: required plugin %s was disabled.", name);
}
}
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -22,6 +22,7 @@ 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;
@@ -30,108 +31,110 @@ import org.jetbrains.annotations.Nullable;
public final class CharsReplacer implements Replacer {
@NotNull
private final Closure closure;
@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 != 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);
public CharsReplacer(@NotNull final Closure closure) {
this.closure = closure;
}
return builder.toString();
}
@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();
}
}

View File

@@ -0,0 +1,146 @@
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;
}
}

View File

@@ -0,0 +1,48 @@
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;
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,6 +21,7 @@
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;
@@ -28,22 +29,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;
}
}
}
}

View File

@@ -0,0 +1,178 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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));
}
}

View File

@@ -0,0 +1,71 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,129 @@
/*
* 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);
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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();
}
}

View File

@@ -0,0 +1,220 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,41 @@
/*
* 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();
}
}

View File

@@ -0,0 +1,346 @@
/*
* 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);
}

View File

@@ -0,0 +1,53 @@
/*
* 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();
}

View File

@@ -0,0 +1,12 @@
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;
}
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -26,6 +26,7 @@ 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;
@@ -35,15 +36,17 @@ import org.bukkit.event.player.PlayerJoinEvent;
public class UpdateChecker implements Listener {
private final int RESOURCE_ID = 6245;
private static 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 i) {
plugin = i;
pluginVersion = i.getDescription().getVersion();
public UpdateChecker(PlaceholderAPIPlugin plugin) {
this.plugin = plugin;
scheduler = plugin.getScheduler();
pluginVersion = plugin.getDescription().getVersion();
}
public boolean hasUpdateAvailable() {
@@ -55,7 +58,7 @@ public class UpdateChecker implements Listener {
}
public void fetch() {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
scheduler.runTaskAsynchronously(() -> {
try {
HttpsURLConnection con = (HttpsURLConnection) new URL(
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
@@ -76,7 +79,7 @@ public class UpdateChecker implements Listener {
return;
}
Bukkit.getScheduler().runTask(plugin, () -> {
scheduler.runTask(() -> {
plugin.getLogger()
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
plugin.getLogger()

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -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;
@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;
}
matches.add(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
}
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<>();
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) {
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);
}
if (classes.isEmpty()) {
loader.close();
return null;
}
return classes.get(0);
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -29,6 +29,7 @@ import static java.util.stream.IntStream.range;
import java.util.List;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;
/**
@@ -36,35 +37,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
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -27,51 +27,53 @@ 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 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));
}
});
}
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));
}
});
}
@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());
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -23,6 +23,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;
@@ -30,50 +31,50 @@ import org.bukkit.command.CommandSender;
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 info(String msg, Object... args) {
log(Level.INFO, msg, args);
}
public static void warn(String msg, Object... args) {
log(Level.WARNING, msg, args);
}
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;
public static void log(Level level, String msg, Object... args) {
PlaceholderAPIPlugin.getInstance().getLogger().log(level, String.format(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 info(String msg, Object... args) {
log(Level.INFO, msg, args);
}
Bukkit.broadcastMessage(
Arrays.stream(messages).map(Msg::color).collect(Collectors.joining("\n")));
}
public static void warn(String msg, Object... args) {
log(Level.WARNING, msg, args);
}
public static String color(@NotNull final String text) {
return ChatColor.translateAlternateColorCodes('&', text);
}
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);
}
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -21,8 +21,8 @@
package me.clip.placeholderapi.util;
public enum TimeFormat {
DAYS,
HOURS,
MINUTES,
SECONDS
DAYS,
HOURS,
MINUTES,
SECONDS
}

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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
@@ -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 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 int seconds, final TimeFormat type) {
return getRemaining((long) seconds, type);
}
if (hours > 0) {
joiner.add(hours + "h");
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 (minutes > 0) {
joiner.add(minutes + "m");
/**
* 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 (seconds > 0) {
joiner.add(seconds + "s");
public static String getTime(final int seconds) {
return getTime((long) seconds);
}
return joiner.toString();
}
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();
}
}

View File

@@ -1,17 +1,16 @@
# 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://api.extendedclip.com/all/
# Wiki: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki
# Expansions: https://placeholderapi.com/ecloud
# Wiki: https://wiki.placeholderapi.com/
# 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'

View File

@@ -1,5 +1,6 @@
name: PlaceholderAPI
main: "me.clip.placeholderapi.PlaceholderAPIPlugin"
folia-supported: true
version: ${version}
author: HelpChat
@@ -11,6 +12,8 @@ commands:
placeholderapi:
description: "PlaceholderAPI Command"
aliases: ["papi"]
test:
description: "yes"
permissions:
placeholderapi.*:
@@ -37,7 +40,6 @@ 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
@@ -82,9 +84,6 @@ 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"
@@ -99,4 +98,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"

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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

View File

@@ -2,7 +2,7 @@
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2021 PlaceholderAPI Team
* 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