24 Commits
Author SHA1 Message Date
NotAlexNoyle 23cc5d1608 Exclude CODEOWNERS from language statistics 2026-10-28 08:31:42 -04:00
NotAlexNoyle 349fbd798e Add CODEOWNERS (one staff approval) 2026-10-28 08:31:42 -04:00
NotAlexNoyle d20a24c886 Remove ChatColor 2026-06-22 09:46:53 -04:00
NotAlexNoyle 8b9a51a694 Merge pull request #1
Merge from upstream while retaining Purpur 1.19.4 and Essentials-OG support.
2026-06-22 09:38:38 -04:00
NotAlexNoyle 86f0519e2f Remove functions that don't exist in Essentials-OG 2026-05-04 18:51:38 -04:00
PiggyPiglet 08f73fc53e Merge pull request #73 from Tanguygab/master
Gradle, Refactor, Home placeholders & Baltop Refresh
2026-04-10 20:31:27 +08:00
Tanguygab 7bd2cab800 Updated PAPI/HelpChat repo 2026-04-10 00:34:44 +02:00
Tanguygab 060417c382 Added configurable refresh for balancetop 2026-04-10 00:21:29 +02:00
Tanguygab 064ad7ea5d Removed debug msgs 2026-04-10 00:07:42 +02:00
Tanguygab dd931a4ad3 Full Refactor 2026-04-10 00:07:21 +02:00
Tanguygab e5e1c2fc05 Fixed home placeholders & switched to Gradle 2026-04-09 20:54:22 +02:00
Tanguygab 605c39de2c Allow home name in %essentials_home_<name|pos>_w|x|y|z% 2026-04-09 19:22:22 +02:00
NotAlexNoyle 3b0a581f17 Fix build with TrueOG Bootstrap 2026-03-30 13:14:17 -04:00
NotAlexNoyle ca78d6fc13 Depend on Essentials-OG 2026-03-30 08:32:06 -04:00
NotAlexNoyle 92cbb8486c Maven -> Gradle 2026-03-30 08:07:15 -04:00
darbyjack f5fb7e66bb Bump to 1.5.2 for release 2023-02-19 13:58:05 -06:00
Glare d1585a9468 Merge pull request #59 from PlaceholderAPI/misc-fixes 2023-02-19 13:57:31 -06:00
darbyjack d2ee91b64d Implemented geolocation placeholder 2023-02-19 13:55:20 -06:00
darbyjack 33c01b96c1 Implemented muted_time_remaining placeholder 2023-02-19 13:27:58 -06:00
darbyjack 315bbcf25e Home Improvements 2023-02-19 13:06:47 -06:00
Gabriel Dumitru 23af08e031 Merge pull request #56 from PlaceholderAPI/add-is_clearinventory_confirm 2022-10-06 19:51:00 +03:00
Gabriel Dumitru 08f9d343ee Merge pull request #55 from PlaceholderAPI/fix-53 2022-10-06 19:49:57 +03:00
Gabriel Dumitru a720e34d28 add %essentials_is_clearinventory_confirm% (close #54) 2022-10-02 00:10:38 +03:00
Gabriel Dumitru 0895001dcd fix #53 2022-10-02 00:05:05 +03:00
11 changed files with 719 additions and 434 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
.gitea/CODEOWNERS linguist-detectable=false
+3
View File
@@ -0,0 +1,3 @@
# Pull requests request review from the eligible staff team(s).
# One approval from either an Admin or Developer satisfies branch protection.
* @trueog/Admins @trueog/Developers
+2
View File
@@ -81,6 +81,7 @@ local.properties
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
.gradle/
# CMake
cmake-build-debug/
@@ -147,3 +148,4 @@ dist/
nbdist/
.nb-gradle/
nbactions.xml
/.gradle/
+70
View File
@@ -0,0 +1,70 @@
plugins {
id("java")
id("java-library")
id("com.gradleup.shadow") version "8.3.9"
eclipse
}
group = "com.extendedclip.papi.expansion.essentials"
version = "2.0.0"
java {
sourceCompatibility = JavaVersion.VERSION_17
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.GRAAL_VM)
}
}
repositories {
mavenCentral()
gradlePluginPortal()
maven { url = uri("https://repo.purpurmc.org/snapshots") }
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://repo.essentialsx.net/releases/") }
}
dependencies {
compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("com.github.PlaceholderAPI:PlaceholderAPI:2.11.2")
compileOnly("net.essentialsx:EssentialsX:2.21.0") {
exclude(group = "org.bstats", module = "bstats-bukkit")
}
}
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
tasks.withType<Jar>().configureEach {
archiveBaseName.set(rootProject.name)
manifest {
attributes(
"Implementation-Title" to rootProject.name,
"Implementation-Version" to project.version,
"Specification-Title" to rootProject.name,
"Specification-Version" to project.version,
)
}
}
tasks.jar {
archiveClassifier.set("part")
}
tasks.shadowJar {
archiveBaseName.set(rootProject.name)
archiveClassifier.set("")
archiveVersion.set(project.version.toString())
}
tasks.build {
dependsOn(tasks.shadowJar)
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(17)
options.compilerArgs.add("-parameters")
options.encoding = "UTF-8"
}
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored Executable
+251
View File
@@ -0,0 +1,251 @@
#!/bin/sh
#
# 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.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,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=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# 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"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
Vendored
+94
View File
@@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
-80
View File
@@ -1,80 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.extendedclip.papi.expansion.essentials</groupId>
<artifactId>essentials-expansion</artifactId>
<version>1.5.1</version>
<name>PAPI-Expansion-Essentials</name>
<description>PlaceholderAPI expansion for Essentials placeholders</description>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>ess-repo</id>
<url>https://repo.essentialsx.net/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.essentialsx</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.19.3</version>
<exclusions>
<exclusion>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<finalName>${name}</finalName>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<target>1.8</target>
<source>1.8</source>
<encoding>UTF-8</encoding>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
</plugins>
</build>
</project>
+1
View File
@@ -0,0 +1 @@
rootProject.name = "Essentials-PAPI"
@@ -25,61 +25,117 @@ import com.earth2me.essentials.Kit;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.DescParseTickFormat;
import com.google.common.primitives.Ints;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.essentialsx.api.v2.services.BalanceTop;
import org.bukkit.*;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class EssentialsExpansion extends PlaceholderExpansion {
private String k;
private String m;
private String b;
private String t;
private String q;
private final DecimalFormat format = new DecimalFormat("#,###");
private static final DecimalFormat COORDS_FORMAT = new DecimalFormat("#.###");
private static final LegacyComponentSerializer LEGACY_AMPERSAND = LegacyComponentSerializer.legacyAmpersand();
private static final LegacyComponentSerializer LEGACY_SECTION = LegacyComponentSerializer.legacySection();
private static final PlainTextComponentSerializer PLAIN_TEXT = PlainTextComponentSerializer.plainText();
private static final List<String> PLACEHOLDERS;
static {
PLACEHOLDERS = Stream.of(
Stream.of(
"is_clearinventory_confirm",
"is_teleport_enabled",
"is_muted",
"muted",
"afk",
"afk_reason",
"afk_player_count",
"msg_ignore",
"fly",
"nickname",
"nickname_stripped",
"muted_time_remaining",
"geolocation",
"godmode",
"unique",
"homes_set",
"homes_max",
"jailed",
"jailed_time_remaining",
"pm_recipient",
"safe_online",
"tp_cooldown",
"world_date",
"world_time",
"world_time_24"
),
Stream.of(
"last_use",
"is_available",
"time_until_available",
"has"
).map(placeholder -> "kit_" + placeholder + "_<kit>"),
Stream.of("has_kit_<kit>"),
Stream.of(
Stream.of(
"total",
"max",
"name_<index>",
"has_<name>"
),
Stream.of(
"world",
"x",
"y",
"z"
).map(placeholder -> placeholder + "_<name|index>")
).flatMap(placeholders -> placeholders).map(placeholder -> "home_" + placeholder)
).flatMap(placeholders -> placeholders)
.map(placeholder -> "%essentials_" + placeholder + "%")
.toList();
}
private Essentials essentials;
private BalanceTop baltop;
private final String VERSION = getClass().getPackage().getImplementationVersion();
@Override
public boolean canRegister() {
return Bukkit.getPluginManager().getPlugin("Essentials") != null && Bukkit.getPluginManager().getPlugin("Essentials").isEnabled();
return getEssentials() != null;
}
@Override
public boolean register() {
k = getString("formatting.thousands", "k");
m = getString("formatting.millions", "m");
b = getString("formatting.billions", "b");
t = getString("formatting.trillions", "t");
q = getString("formatting.quadrillions", "q");
essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
if (essentials != null && essentials.isEnabled()) {
baltop = essentials.getBalanceTop();
baltop.calculateBalanceTopMapAsync();
return super.register();
}
return false;
essentials = getEssentials();
return essentials != null && super.register();
}
@Override
@@ -94,377 +150,257 @@ public class EssentialsExpansion extends PlaceholderExpansion {
@Override
public @NotNull String getVersion() {
return VERSION;
String version = getClass().getPackage().getImplementationVersion();
return version == null ? "2.0.0" : version;
}
@Override
public String onRequest(OfflinePlayer player, @NotNull String identifier) {
final String papiTrue = PlaceholderAPIPlugin.booleanTrue();
final String papiFalse = PlaceholderAPIPlugin.booleanFalse();
public @NotNull List<String> getPlaceholders() {
return PLACEHOLDERS;
}
// Put this before the null check as most of it is not required
if (identifier.startsWith("baltop_")) {
Map<UUID, BalanceTop.Entry> baltopCache = baltop.getBalanceTopCache();
identifier = identifier.substring(7);
if (identifier.startsWith("balance_")) {
identifier = identifier.substring(8);
if (identifier.startsWith("fixed_")) {
identifier = identifier.substring(6);
Integer id = Ints.tryParse(identifier);
if (id == null) {
return "Invalid ID";
}
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
if (id >= entries.length) {
return "0";
}
return String.valueOf(entries[id].getBalance().longValue());
}
if (identifier.startsWith("formatted_")) {
identifier = identifier.substring(10);
Integer id = Ints.tryParse(identifier);
if (id == null) {
return "Invalid ID";
}
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
if (id >= entries.length) {
return "0";
}
return fixMoney(entries[id].getBalance().doubleValue());
}
if (identifier.startsWith("commas_")) {
identifier = identifier.substring(7);
Integer id = Ints.tryParse(identifier);
if (id == null) {
return "Invalid ID";
}
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
if (id >= entries.length) {
return "0";
}
return format.format(entries[id].getBalance().doubleValue());
}
Integer id = Ints.tryParse(identifier);
if (id == null) {
return "Invalid ID";
}
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
if (id >= entries.length) {
return "0";
}
return String.valueOf(entries[id].getBalance().doubleValue());
}
if (identifier.startsWith("player_")) {
identifier = identifier.substring(7);
boolean stripped = false;
if (identifier.startsWith("stripped_")) {
identifier = identifier.substring(9);
stripped = true;
}
Integer id = Ints.tryParse(identifier);
if (id == null) {
return "Invalid ID";
}
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
if (id >= entries.length) {
return "0";
}
if (stripped) {
User user = essentials.getUser(entries[id].getUuid());
if (user != null) {
return user.getName();
} else {
return null;
}
} else {
return entries[id].getDisplayName();
}
}
if (identifier.equals("rank")) {
// Another null check because it is above the normal one
if (player == null) return "";
if (!baltopCache.containsKey(player.getUniqueId())) {
return "";
}
return String.valueOf(new ArrayList<>(baltopCache.keySet()).indexOf(player.getUniqueId()) + 1);
}
@Override
public String onRequest(OfflinePlayer player, @NotNull String params) {
if (player == null) {
return "";
}
Object output = request(player, params);
if (output == null) {
return null;
}
if (player == null) return "";
if (identifier.equals("tp_cooldown")) {
final double cooldown = essentials.getSettings().getTeleportCooldown();
final long d1 = System.currentTimeMillis();
final long d2 = essentials.getUser(player.getUniqueId()).getLastTeleportTimestamp();
long diff = TimeUnit.MILLISECONDS.toSeconds(d1 - d2);
if(diff < cooldown) return String.valueOf((int) (cooldown - diff));
return "0";
if (output instanceof Boolean bool) {
return bool ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
}
return output.toString();
}
if (identifier.startsWith("kit_last_use_")) {
String kitName = identifier.split("kit_last_use_")[1].toLowerCase();
Kit kit;
private Essentials getEssentials() {
final PluginManager pluginManager = Bukkit.getPluginManager();
final Plugin plugin = pluginManager.getPlugin("Essentials-OG");
final Plugin fallback = plugin != null ? plugin : pluginManager.getPlugin("Essentials");
return fallback instanceof Essentials && fallback.isEnabled() ? (Essentials) fallback : null;
}
private Object request(OfflinePlayer player, String params) {
final User user = essentials.getUser(player.getUniqueId());
return switch (params) {
case "is_clearinventory_confirm" -> user.isPromptingClearConfirm();
case "is_teleport_enabled" -> user.isTeleportEnabled();
case "is_muted", "muted" -> user.isMuted();
case "afk" -> user.isAfk();
case "afk_reason" -> user.getAfkMessage() == null ? "" : translateLegacyAmpersand(user.getAfkMessage());
case "afk_player_count" -> String.valueOf(essentials.getUserMap().getAllUniqueUsers().stream()
.map(uuid -> essentials.getUser(uuid))
.filter(User::isAfk)
.count());
case "msg_ignore" -> user.isIgnoreMsg();
case "fly" -> user.getBase().getAllowFlight();
case "nickname" -> user.getNickname() != null ? user.getNickname() : player.getName();
case "nickname_stripped" -> stripLegacyFormatting(user.getNickname() != null ? user.getNickname() : player.getName());
case "muted_time_remaining" -> user.isMuted() ? DateUtil.formatDateDiff(user.getMuteTimeout()) : "";
case "geolocation" -> user.getGeoLocation() != null ? user.getGeoLocation() : "";
case "godmode" -> user.isGodModeEnabled();
case "unique" -> NumberFormat.getInstance().format(essentials.getUserMap().getUniqueUsers());
case "homes_set" -> user.getHomes().isEmpty() ? "0" : String.valueOf(user.getHomes().size());
case "homes_max" -> String.valueOf(essentials.getSettings().getHomeLimit(user));
case "jailed" -> user.isJailed();
case "jailed_time_remaining" -> user.isJailed() ? user.getFormattedJailTime() : "";
case "pm_recipient" -> user.getReplyRecipient() != null ? user.getReplyRecipient().getName() : "";
case "safe_online" -> String.valueOf(StreamSupport
.stream(essentials.getOnlineUsers().spliterator(), false)
.filter(onlineUser -> !onlineUser.isHidden())
.count());
case "tp_cooldown" -> {
final double cooldown = essentials.getSettings().getTeleportCooldown();
final long now = System.currentTimeMillis();
final long lastTeleport = user.getLastTeleportTimestamp();
final long diff = TimeUnit.MILLISECONDS.toSeconds(now - lastTeleport);
yield diff < cooldown ? String.valueOf((int) (cooldown - diff)) : "0";
}
case "world_date" -> DateFormat.getDateInstance(DateFormat.MEDIUM, essentials.getI18n().getCurrentLocale())
.format(DescParseTickFormat.ticksToDate(user.getWorld() == null ? 0 : user.getWorld().getFullTime()));
case "world_time" -> DescParseTickFormat.format12(user.getWorld() == null ? 0 : user.getWorld().getTime());
case "world_time_24" -> DescParseTickFormat.format24(user.getWorld() == null ? 0 : user.getWorld().getTime());
default -> requestPrefixed(player, user, params);
};
}
private Object requestPrefixed(OfflinePlayer player, User user, String params) {
String[] args = params.split("_");
String prefix = args[0];
String remaining = params.substring(prefix.length() + (params.contains("_") ? 1 : 0));
return switch (prefix) {
case "kit" -> requestKit(player, user, remaining);
case "has" -> remaining.startsWith("kit_") ? playerHasKit(player, remaining.substring("kit_".length())) : null;
case "home" -> requestHome(user, remaining);
default -> null;
};
}
private Object requestKit(OfflinePlayer player, User user, String params) {
if (params.startsWith("last_use_")) {
String kitName = params.substring("last_use_".length()).toLowerCase(Locale.ROOT);
try {
kit = new Kit(kitName, essentials);
Kit kit = new Kit(kitName, essentials);
long time = user.getKitTimestamp(kit.getName());
return time <= 0 ? "0" : PlaceholderAPIPlugin.getDateFormat().format(new Date(time));
} catch (Exception e) {
return "Invalid kit name";
}
long time = essentials.getUser(player.getUniqueId()).getKitTimestamp(kit.getName());
if (time == 1 || time <= 0) {
return "1";
}
return PlaceholderAPIPlugin.getDateFormat().format(new Date(time));
}
if (identifier.startsWith("kit_is_available_")) {
String kitName = identifier.split("kit_is_available_")[1].toLowerCase();
Kit kit;
User user = essentials.getUser(player.getUniqueId());
long time;
if (params.startsWith("is_available_")) {
String kitName = params.substring("is_available_".length()).toLowerCase(Locale.ROOT);
try {
kit = new Kit(kitName, essentials);
Kit kit = new Kit(kitName, essentials);
try {
return kit.getNextUse(user) == 0;
} catch (Exception e) {
return false;
}
} catch (Exception e) {
return "Invalid kit name";
}
try {
time = kit.getNextUse(user);
} catch (Exception e) {
return papiFalse;
}
return time == 0 ? papiTrue : papiFalse;
}
if (identifier.startsWith("kit_time_until_available_")) {
String kitName = identifier.split("kit_time_until_available_")[1].toLowerCase();
if (params.startsWith("time_until_available_")) {
String kitName = params.substring("time_until_available_".length()).toLowerCase(Locale.ROOT);
boolean raw = false;
User user = essentials.getUser(player.getUniqueId());
Kit kit;
long time;
if (kitName.startsWith("raw_")) {
raw = true;
kitName = kitName.substring(4);
if (kitName.isEmpty()) {
return "Invalid kit name";
}
kitName = kitName.substring("raw_".length());
}
try {
kit = new Kit(kitName, essentials);
} catch (Exception e) {
if (kitName.isEmpty()) {
return "Invalid kit name";
}
try {
time = kit.getNextUse(user);
} catch (Exception e) {
return "-1";
}
if (time <= System.currentTimeMillis()) {
return raw ? "0" : DateUtil.formatDateDiff(System.currentTimeMillis());
}
if (raw) {
return String.valueOf(Instant.now().until(Instant.ofEpochMilli(time), ChronoUnit.MILLIS));
} else {
return DateUtil.formatDateDiff(time);
}
}
if (identifier.startsWith("has_kit_")) {
Player oPlayer = player.getPlayer();
if (oPlayer == null) return papiFalse;
String kit = identifier.split("has_kit_")[1];
return oPlayer.hasPermission("essentials.kits." + kit) ? papiTrue : papiFalse;
}
if (identifier.startsWith("home_")) {
Integer homeNumber;
final User user = essentials.getUser(player.getUniqueId());
// Removes all the letters from the identifier to get the home slot.
// Checks if the number slot is an integer or not.
if ((homeNumber = Ints.tryParse(identifier.replaceAll("\\D+", ""))) == null) return null;
// Since it is easier for users to type from 1-x I subtract one from the original number to work from 0-x.
homeNumber -= 1;
// checks if the home is out of bounds and returns and empty string if it is.
if (homeNumber >= user.getHomes().size() || homeNumber < 0) return "";
// checks if the identifier matches the pattern home_%d
if (identifier.matches("(\\w+_)(\\d+)")) return user.getHomes().get(homeNumber);
//checks if the identifier matches the pattern home_%d_(x/y/z)
if (identifier.matches("(\\w+_)(\\d+)(_\\w)")) {
Kit kit = new Kit(kitName, essentials);
try {
final Location home = user.getHome(user.getHomes().get(homeNumber));
final StringBuilder stringBuilder = new StringBuilder();
switch (identifier.charAt(identifier.length() - 1)) {
case 'x':
stringBuilder.append(home.getX());
break;
case 'y':
stringBuilder.append((int) home.getY());
break;
case 'z':
stringBuilder.append(home.getZ());
break;
long time = kit.getNextUse(user);
if (time <= System.currentTimeMillis()) {
return raw ? "0" : DateUtil.formatDateDiff(System.currentTimeMillis());
}
return stringBuilder.toString();
return raw ? String.valueOf(Instant.now().until(Instant.ofEpochMilli(time), ChronoUnit.MILLIS)) : DateUtil.formatDateDiff(time);
} catch (Exception e) {
return null;
return "-1";
}
} catch (Exception e) {
return "Invalid kit name";
}
}
if (identifier.startsWith("worth")) {
ItemStack item;
if (identifier.contains(":")){
Material material = Material.getMaterial(identifier.replace("worth:", "").toUpperCase());
if (material == null) return "";
item = new ItemStack(material,1);
} else {
Player oPlayer = player.getPlayer();
if (oPlayer == null) return "";
if (oPlayer.getItemInHand().getType() == Material.AIR) return "";
item = oPlayer.getItemInHand();
}
BigDecimal worth = essentials.getWorth().getPrice(essentials, item);
if (worth == null) return "";
return String.valueOf(worth.doubleValue());
if (params.startsWith("has_")) {
return playerHasKit(player, params.substring("has_".length()));
}
final User user = essentials.getUser(player.getUniqueId());
switch (identifier) {
case "is_pay_confirm":
return user.isPromptingPayConfirm() ? papiTrue : papiFalse;
case "is_pay_enabled":
return user.isAcceptingPay() ? papiTrue : papiFalse;
case "is_teleport_enabled":
return user.isTeleportEnabled() ? papiTrue : papiFalse;
case "is_muted":
return user.isMuted() ? papiTrue : papiFalse;
case "vanished":
return user.isVanished() ? papiTrue : papiFalse;
case "afk":
return user.isAfk() ? papiTrue : papiFalse;
case "afk_reason":
if (user.getAfkMessage() == null) return "";
return ChatColor.translateAlternateColorCodes('&', user.getAfkMessage());
case "afk_player_count":
return String.valueOf(essentials.getUserMap().getAllUniqueUsers().stream()
.map(UUID -> essentials.getUser(UUID)).filter(User::isAfk)
.count());
case "msg_ignore":
return user.isIgnoreMsg() ? papiTrue : papiFalse;
case "fly":
return user.getBase().getAllowFlight() ? papiTrue : papiFalse;
case "nickname":
return user.getNickname() != null ? essentials.getUser(player.getUniqueId()).getNickname() : player.getName();
case "nickname_stripped":
return ChatColor.stripColor(user.getNickname() != null ? essentials.getUser(player.getUniqueId()).getNickname() : player.getName());
case "godmode":
return user.isGodModeEnabled() ? papiTrue : papiFalse;
case "unique":
return NumberFormat.getInstance().format(essentials.getUserMap().getUniqueUsers());
case "homes_set":
return user.getHomes().isEmpty() ? "0" : String.valueOf(user.getHomes().size());
case "homes_max":
return String.valueOf(essentials.getSettings().getHomeLimit(user));
case "jailed":
return user.isJailed() ? papiTrue : papiFalse;
case "jailed_time_remaining":
return user.getFormattedJailTime();
case "pm_recipient":
return user.getReplyRecipient() != null ? user.getReplyRecipient().getName() : "";
case "safe_online":
return String.valueOf(StreamSupport.stream(essentials.getOnlineUsers().spliterator(), false)
.filter(user1 -> !user1.isHidden())
.count());
case "world_date":
return DateFormat.getDateInstance(DateFormat.MEDIUM, essentials.getI18n().getCurrentLocale())
.format(DescParseTickFormat.ticksToDate(user.getWorld() == null ? 0 : user.getWorld().getFullTime()));
case "world_time":
return DescParseTickFormat.format12(user.getWorld() == null ? 0 : user.getWorld().getTime());
case "world_time_24":
return DescParseTickFormat.format24(user.getWorld() == null ? 0 : user.getWorld().getTime());
}
return null;
}
private String format(double d) {
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(0);
return format.format(d);
private Object requestHome(User user, String params) {
List<String> homes = user.getHomes();
if (isLegacyHome(params)) {
return requestLegacyHome(user, homes, params);
}
String[] args = params.split("_", 2);
String type = args[0];
String homeName = args.length == 2 ? args[1] : "";
Integer homeNumber = Ints.tryParse(homeName);
return switch (type) {
case "total" -> String.valueOf(homes.size());
case "max" -> String.valueOf(essentials.getSettings().getHomeLimit(user));
case "has" -> user.hasHome(homeName);
case "name" -> homeNumber == null || homeNumber < 0 || homeNumber >= homes.size() ? "" : homes.get(homeNumber);
case "w", "world", "x", "y", "z" -> requestHomeLocation(user, homes, homeName, homeNumber, type);
default -> null;
};
}
private String fixMoney(double d) {
if (d < 1000L) {
return format(d);
}
if (d < 1000000L) {
return format(d / 1000L) + k;
}
if (d < 1000000000L) {
return format(d / 1000000L) + m;
}
if (d < 1000000000000L) {
return format(d / 1000000000L) + b;
}
if (d < 1000000000000000L) {
return format(d / 1000000000000L) + t;
}
if (d < 1000000000000000000L) {
return format(d / 1000000000000000L) + q;
private Object requestHomeLocation(User user, List<String> homes, String homeName, Integer homeNumber, String type) {
if (homeNumber != null && (homeNumber < 0 || homeNumber >= homes.size())) {
return "Invalid home";
}
return String.valueOf(d);
Location home = user.getHome(homeNumber == null ? homeName : homes.get(homeNumber));
if (home == null) {
return "Invalid home";
}
Object output = switch (type) {
case "w", "world" -> home.getWorld() == null ? "null" : home.getWorld().getName();
case "x" -> home.getX();
case "y" -> home.getY();
case "z" -> home.getZ();
default -> null;
};
return output instanceof Double coords ? COORDS_FORMAT.format(coords) : output;
}
private Object requestLegacyHome(User user, List<String> homes, String params) {
String[] args = params.split("_", 2);
Integer homeNumber = Ints.tryParse(args[0]);
if (homeNumber == null) {
return null;
}
homeNumber -= 1;
if (homeNumber >= homes.size() || homeNumber < 0) {
return "";
}
if (args.length == 1) {
return homes.get(homeNumber);
}
try {
Location home = user.getHome(homes.get(homeNumber));
if (home == null) {
return null;
}
return switch (args[1]) {
case "w" -> home.getWorld() == null ? "null" : home.getWorld().getName();
case "x" -> COORDS_FORMAT.format(home.getX());
case "y" -> String.valueOf((int) home.getY());
case "z" -> COORDS_FORMAT.format(home.getZ());
default -> null;
};
} catch (Exception e) {
return null;
}
}
private boolean playerHasKit(OfflinePlayer player, String kit) {
Player onlinePlayer = player.getPlayer();
return onlinePlayer != null && onlinePlayer.hasPermission("essentials.kits." + kit);
}
private boolean isLegacyHome(String params) {
return params.matches("\\d+(_[wxyz])?");
}
private String translateLegacyAmpersand(String input) {
return LEGACY_SECTION.serialize(LEGACY_AMPERSAND.deserialize(input));
}
private String stripLegacyFormatting(String input) {
return PLAIN_TEXT.serialize(LEGACY_SECTION.deserialize(input));
}
}