Compare commits

...

49 Commits

Author SHA1 Message Date
PiggyPiglet
e3e32f5688 Merge branch 'hytale' into hytale-curseforge 2026-02-02 21:41:15 +08:00
PiggyPiglet
abb85e6d16 1.0.5-dev 2026-02-02 21:41:05 +08:00
PiggyPiglet
dae0b96002 Merge branch 'hytale' into hytale-curseforge 2026-02-02 21:39:16 +08:00
PiggyPiglet
44ac2589a3 Fix permission system - also 1.0.4 release
it was horribly broken :(
2026-02-02 21:39:05 +08:00
PiggyPiglet
36995a0916 Merge branch 'hytale' into hytale-curseforge 2026-02-02 21:02:38 +08:00
PiggyPiglet
5ab5d06fc6 1.0.4-dev 2026-02-02 20:57:48 +08:00
PiggyPiglet
798ca2ea10 Merge branch 'hytale' into hytale-curseforge 2026-02-02 20:57:12 +08:00
PiggyPiglet
8814126d47 1.0.3 release 2026-02-02 20:56:56 +08:00
PiggyPiglet
07c6e292b3 Merge branch 'hytale' into hytale-curseforge 2026-02-02 20:34:18 +08:00
PiggyPiglet
21902c5fa3 Load expansions after server boot to prevent dep issues 2026-02-02 20:34:10 +08:00
PiggyPiglet
59d916966c Merge branch 'hytale' into hytale-curseforge 2026-02-02 20:07:32 +08:00
PiggyPiglet
3e75070375 Add eCloud blocked information msg to ecloud command 2026-02-02 20:07:22 +08:00
PiggyPiglet
d4c64fc17e Merge branch 'hytale' into hytale-curseforge 2026-02-02 15:35:40 +08:00
PiggyPiglet
59ec9bee5a use gradle version in manifest 2026-02-02 15:35:22 +08:00
Funnycube
395c743b41 comment out dormant code 2026-02-02 17:58:02 +11:00
PiggyPiglet
4b015a9076 Merge branch 'hytale' into hytale-curseforge 2026-01-30 22:18:13 +08:00
PiggyPiglet
95896416e6 1.0.3 dev 2026-01-30 22:18:05 +08:00
PiggyPiglet
7952702abd Merge branch 'hytale' into hytale-curseforge 2026-01-30 22:17:24 +08:00
PiggyPiglet
ebc62c6fd2 Add convenience booleanValue method to PlaceholderAPI class 2026-01-30 22:17:11 +08:00
PiggyPiglet
c11904d9c9 Merge branch 'hytale' into hytale-curseforge 2026-01-30 20:58:59 +08:00
PiggyPiglet
a065d620cb 1.0.2-dev 2026-01-30 20:58:26 +08:00
PiggyPiglet
b869b98338 Merge branch 'hytale' into hytale-curseforge 2026-01-30 20:55:13 +08:00
PiggyPiglet
873c9bf727 1.0.1 release 2026-01-30 20:54:55 +08:00
PiggyPiglet
a01e6abab8 Merge branch 'hytale' into hytale-curseforge 2026-01-30 20:53:33 +08:00
PiggyPiglet
3bf99821ef Implement config save, comment out old config api 2026-01-30 20:53:24 +08:00
PiggyPiglet
e8716e57ff Merge branch 'hytale' into hytale-curseforge 2026-01-30 20:03:06 +08:00
PiggyPiglet
6d8f223591 actually fix windows loading issue maybe 2026-01-30 20:02:19 +08:00
PiggyPiglet
8f9c52940c Merge branch 'hytale' into hytale-curseforge 2026-01-30 18:22:18 +08:00
PiggyPiglet
3b34193caa move expansion load to start to hopefully fix cube's non-load issue 2026-01-30 18:22:08 +08:00
PiggyPiglet
7edc94bc35 Update download/update messages to be clearer 2026-01-30 18:21:23 +08:00
PiggyPiglet
b06bc23465 Merge branch 'hytale' into hytale-curseforge 2026-01-30 18:15:33 +08:00
PiggyPiglet
757f6ee9ae Make dump command link more accessible 2026-01-30 18:15:17 +08:00
PiggyPiglet
ffd115296c eCloud disabled PAPI for CurseForge 2026-01-30 18:11:12 +08:00
PiggyPiglet
c308769e6d remove unused code 2026-01-30 17:41:13 +08:00
PiggyPiglet
98b7ef68ec fix /papi command showing error, add /placeholderapi alias 2026-01-26 21:31:43 +08:00
PiggyPiglet
62f6eb4e54 fix console commands, run parse command in world thread 2026-01-26 21:23:29 +08:00
Funnycube
5f4839390c updated color handling 2026-01-26 19:43:38 +11:00
PiggyPiglet
fb57b70546 run parse command sync 2026-01-24 22:00:03 +08:00
PiggyPiglet
ee392322c6 add build num to ver 2026-01-24 21:07:36 +08:00
PiggyPiglet
6f61c0eb31 fix parse command player cast 2026-01-24 21:06:04 +08:00
PiggyPiglet
db79cf6340 dev now 2026-01-24 19:38:48 +08:00
PiggyPiglet
fa50fd14a5 I missed an error :( 2026-01-24 19:36:23 +08:00
PiggyPiglet
085b09e019 fix javadoc errors 2026-01-24 19:34:21 +08:00
PiggyPiglet
6e3e64d3f8 add hytale classifier 2026-01-24 19:32:03 +08:00
PiggyPiglet
400857f18b Add gradle publishing config, remove remaining player usage 2026-01-24 19:29:13 +08:00
PiggyPiglet
7111fef559 Use PlayerRef instead of Player, finalise expansion/replace api 2026-01-24 19:05:58 +08:00
PiggyPiglet
722279308a Let there be light 2026-01-20 21:23:37 +08:00
PiggyPiglet
2d9f4fca77 start converting from bukkit to hytale 2026-01-19 20:39:13 +08:00
PiggyPiglet
cb5b9a8bb9 A fresh start 2026-01-19 18:57:25 +08:00
97 changed files with 3378 additions and 5983 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,8 @@
.idea/ .idea/
.gradle/ .gradle/
.vscode/
server/ server/
build/ build/
out/ out/
*.iml *.iml
libs/

View File

@@ -3,54 +3,33 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins { plugins {
`java-library` `java-library`
`maven-publish` `maven-publish`
// id("com.github.hierynomus.license") version "0.16.1" id("com.gradleup.shadow") version "9.3.1"
id("io.github.goooler.shadow") version "8.1.7"
} }
group = "me.clip" group = "at.helpch"
version = "2.12.0-DEV-${System.getProperty("BUILD_NUMBER")}" version = "1.0.5-DEV-${System.getProperty("BUILD_NUMBER")}"
description = "An awesome placeholder provider!" description = "An awesome placeholder provider!"
val paper by sourceSets.creating {
java.srcDir("src/paper/java")
// paper can see main code
compileClasspath += sourceSets.main.get().output
runtimeClasspath += output + compileClasspath
}
repositories { repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots/")
mavenCentral() mavenCentral()
mavenLocal() mavenLocal()
maven("https://repo.codemc.org/repository/maven-public/") maven {
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") url = uri("https://repo.codemc.io/repository/hytale/")
maven("https://repo.papermc.io/repository/maven-public/") }
} }
dependencies { dependencies {
implementation("org.bstats:bstats-bukkit:3.1.0") implementation("org.yaml:snakeyaml:2.5")
implementation("net.kyori:adventure-platform-bukkit:4.4.1")
add(paper.compileOnlyConfigurationName, "net.kyori:adventure-platform-bukkit:4.4.1") compileOnly("com.hypixel.hytale:Server:2026.01.17-4b0f30090")
add(paper.compileOnlyConfigurationName, "dev.folia:folia-api:1.21.11-R0.1-SNAPSHOT")
compileOnly("dev.folia:folia-api:1.21.11-R0.1-SNAPSHOT")
compileOnlyApi("org.jetbrains:annotations:23.0.0") compileOnlyApi("org.jetbrains:annotations:23.0.0")
testImplementation("org.openjdk.jmh:jmh-core:1.32")
testImplementation("org.openjdk.jmh:jmh-generator-annprocess:1.32")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
} }
java { java {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_21
withJavadocJar() withJavadocJar()
withSourcesJar() withSourcesJar()
@@ -65,105 +44,19 @@ tasks {
eachFile { expand("version" to project.version) } eachFile { expand("version" to project.version) }
} }
build {
dependsOn(named("shadowJar"))
}
register<JavaCompile>("compilePaper") {
source = paper.java
classpath = paper.compileClasspath
destinationDirectory.set(layout.buildDirectory.dir("classes/java/paper"))
options.encoding = "UTF-8"
options.release = 8
}
val plainJar by registering(Jar::class) {
dependsOn("compilePaper")
archiveClassifier.set("plain")
from(sourceSets.main.get().output)
from(paper.output)
}
val combinedSourcesJar by registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
from(paper.allSource)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
val combinedJavadoc by registering(Javadoc::class) {
isFailOnError = false
source = sourceSets.main.get().allJava + paper.allJava
classpath = sourceSets.main.get().compileClasspath + paper.compileClasspath
with(options as StandardJavadocDocletOptions) {
addStringOption("Xdoclint:none", "-quiet")
addStringOption("encoding", "UTF-8")
addStringOption("charSet", "UTF-8")
}
}
val combinedJavadocJar by registering(Jar::class) {
archiveClassifier.set("javadoc")
dependsOn(combinedJavadoc)
from(combinedJavadoc.get().destinationDir)
}
withType<JavaCompile> {
options.encoding = "UTF-8"
options.release = 8
}
withType<ShadowJar> { withType<ShadowJar> {
configurations = listOf(project.configurations.runtimeClasspath.get()) archiveClassifier.set("hytale")
from(sourceSets.main.get().output) relocate("org.yaml.snakeyaml", "at.helpch.placeholderapi.libs.yaml")
archiveClassifier.set("")
relocate("org.bstats", "me.clip.placeholderapi.metrics")
relocate("net.kyori", "me.clip.placeholderapi.libs.kyori")
exclude("META-INF/versions/**") exclude("META-INF/versions/**")
dependsOn("compilePaper")
doLast {
val paperDir = layout.buildDirectory.dir("classes/java/paper").get().asFile
val jarFile = archiveFile.get().asFile
ant.invokeMethod("zip", mapOf(
"destfile" to jarFile,
"update" to "true",
"basedir" to paperDir
))
}
}
test {
useJUnitPlatform()
} }
publishing { publishing {
publications { publications {
create<MavenPublication>("maven") { create<MavenPublication>("maven") {
artifactId = "placeholderapi" artifactId = "placeholderapi-hytale"
from(javaComponent)
artifact(plainJar) {
builtBy(plainJar)
classifier = ""
}
artifact(combinedSourcesJar) {
builtBy(combinedSourcesJar)
}
artifact(combinedJavadocJar) {
builtBy(combinedJavadocJar)
}
} }
} }
@@ -185,9 +78,3 @@ tasks {
publish.get().setDependsOn(listOf(build.get())) publish.get().setDependsOn(listOf(build.get()))
} }
configurations {
testImplementation {
extendsFrom(compileOnly.get())
}
}

View File

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

View File

@@ -0,0 +1,330 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import at.helpch.placeholderapi.expansion.Relational;
import at.helpch.placeholderapi.replacer.CharsReplacer;
import at.helpch.placeholderapi.replacer.MessageReplacer;
import at.helpch.placeholderapi.replacer.Replacer;
import at.helpch.placeholderapi.replacer.Replacer.Closure;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import org.jetbrains.annotations.NotNull;
public final class PlaceholderAPI {
private static final Replacer REPLACER_PERCENT = new CharsReplacer(Closure.PERCENT);
private static final Replacer REPLACER_BRACKET = new CharsReplacer(Closure.BRACKET);
static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
static final Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]");
static final Pattern RELATIONAL_PLACEHOLDER_PATTERN = Pattern
.compile("[%](rel_)([^%]+)[%]");
private PlaceholderAPI() {
}
// === Current API ===
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param text Text to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static String setPlaceholders(final PlayerRef player,
@NotNull final String text) {
return REPLACER_PERCENT.apply(text, player,
PlaceholderAPIPlugin.instance().localExpansionManager()::getExpansion);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param original Message to set the placeholder values in
* @return Message containing all translated placeholders
*/
@NotNull
public static Message setPlaceholders(final PlayerRef player,
@NotNull final Message original) {
return MessageReplacer.replace(original, str -> setPlaceholders(player, str));
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param text List of Strings to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static List<String> setPlaceholders(final PlayerRef player,
@NotNull final List<String> text) {
return text.stream().map(line -> setPlaceholders(player, line)).collect(Collectors.toList());
}
// /**
// * Translates all placeholders into their corresponding values.
// * <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
// *
// * @param player Player to parse the placeholders against
// * @param original List of Messages to set the placeholder values in
// * @return List of Message containing all translated placeholders
// */
// @NotNull
// public static List<Message> setPlaceholders(final Player player,
// @NotNull final List<Message> original) {
// return original.stream().map(msg -> setPlaceholders(player, msg)).collect(Collectors.toList());
// }
// /**
// * Translates all placeholders into their corresponding values.
// * <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
// *
// * @param player Player to parse the placeholders against
// * @param text Text to set the placeholder values in
// * @return String containing all translated placeholders
// */
// @NotNull
// public static String setPlaceholders(final Player player, @NotNull String text) {
// return setPlaceholders(((OfflinePlayer) player), text);
// }
// /**
// * Translates all placeholders into their corresponding values.
// * <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
// *
// * @param player Player to parse the placeholders against
// * @param text List of Strings to set the placeholder values in
// * @return String containing all translated placeholders
// */
// @NotNull
// public static List<String> setPlaceholders(final Player player, @NotNull List<@NotNull String> text) {
// return setPlaceholders(((OfflinePlayer) player), text);
// }
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param text Text to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static String setBracketPlaceholders(final PlayerRef player,
@NotNull final String text) {
return REPLACER_BRACKET.apply(text, player,
PlaceholderAPIPlugin.instance().localExpansionManager()::getExpansion);
}
@NotNull
public static Message setBracketPlaceholders(final PlayerRef player,
@NotNull final Message original) {
return MessageReplacer.replace(original, str -> setBracketPlaceholders(player, str));
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param text List of Strings to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static List<@NotNull String> setBracketPlaceholders(final PlayerRef player,
@NotNull final List<@NotNull String> text) {
return text.stream().map(line -> setBracketPlaceholders(player, line))
.collect(Collectors.toList());
}
// /**
// * Translates all placeholders into their corresponding values.
// * <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
// *
// * @param player Player to parse the placeholders against
// * @param text Text to set the placeholder values in
// * @return String containing all translated placeholders
// */
// @NotNull
// public static String setBracketPlaceholders(Player player, @NotNull String text) {
// return setBracketPlaceholders((OfflinePlayer) player, text);
// }
//
// /**
// * Translates all placeholders into their corresponding values.
// * <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
// *
// * @param player Player to parse the placeholders against
// * @param text List of Strings to set the placeholder values in
// * @return String containing all translated placeholders
// */
// @NotNull
// public static List<String> setBracketPlaceholders(Player player, @NotNull List<String> text) {
// return setBracketPlaceholders((OfflinePlayer) player, text);
// }
/**
* set relational placeholders in the text specified placeholders are matched with the pattern
* {@literal %<rel_(identifier)_(params)>%} when set with this method
*
* @param one First player to compare
* @param two Second player to compare
* @param text Text to parse the placeholders in
* @return The text containing the parsed relational placeholders
*/
public static String setRelationalPlaceholders(PlayerRef one, PlayerRef two, String text) {
final Matcher matcher = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
while (matcher.find()) {
final String format = matcher.group(2);
final int index = format.indexOf("_");
if (index <= 0 || index >= format.length()) {
continue;
}
String identifier = format.substring(0, index).toLowerCase(Locale.ROOT);
String params = format.substring(index + 1);
final PlaceholderExpansion expansion = PlaceholderAPIPlugin.instance()
.localExpansionManager().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;
}
/**
* Translate placeholders in the provided List based on the relation of the two provided players.
* <br>The pattern of a valid placeholder is {@literal %rel_<identifier>_<param>%}.
*
* @param one Player to compare
* @param two Player to compare
* @param text text to parse the placeholder values to
* @return The text containing the parsed relational placeholders
*/
public static List<String> setRelationalPlaceholders(PlayerRef one, PlayerRef two, List<String> text) {
return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
.collect(Collectors.toList());
}
/**
* Check if a specific placeholder identifier is currently registered
*
* @param identifier The identifier to check
* @return true if identifier is already registered
*/
public static boolean isRegistered(@NotNull final String identifier) {
return PlaceholderAPIPlugin.instance().localExpansionManager()
.findExpansionByIdentifier(identifier).isPresent();
}
/**
* Get all registered placeholder identifiers
*
* @return A Set of type String containing the identifiers of all registered expansions.
*/
@NotNull
public static Set<String> getRegisteredIdentifiers() {
return Set
.copyOf(PlaceholderAPIPlugin.instance().localExpansionManager().getIdentifiers());
}
/**
* Get the normal placeholder pattern.
*
* @return Regex Pattern of {@literal [%]([^%]+)[%]}
*/
public static Pattern getPlaceholderPattern() {
return PLACEHOLDER_PATTERN;
}
/**
* Get the bracket placeholder pattern.
*
* @return Regex Pattern of {@literal [{]([^{}]+)[}]}
*/
public static Pattern getBracketPlaceholderPattern() {
return BRACKET_PLACEHOLDER_PATTERN;
}
/**
* Get the relational placeholder pattern.
*
* @return Regex Pattern of {@literal [%](rel_)([^%]+)[%]}
*/
public static Pattern getRelationalPlaceholderPattern() {
return RELATIONAL_PLACEHOLDER_PATTERN;
}
/**
* Check if a String contains any PlaceholderAPI placeholders ({@literal
* %<identifier>_<params>%}).
*
* @param text String to check
* @return true if String contains any matches to the normal placeholder pattern, false otherwise
*/
public static boolean containsPlaceholders(String text) {
return text != null && PLACEHOLDER_PATTERN.matcher(text).find();
}
/**
* Check if a String contains any PlaceholderAPI bracket placeholders ({@literal
* {<identifier>_<params>}}).
*
* @param text String to check
* @return true if String contains any matches to the bracket placeholder pattern, false otherwise
*/
public static boolean containsBracketPlaceholders(String text) {
return text != null && BRACKET_PLACEHOLDER_PATTERN.matcher(text).find();
}
public static String booleanValue(final boolean value) {
return value ? PlaceholderAPIPlugin.instance().configManager().config().booleanValue().trueValue() : PlaceholderAPIPlugin.instance().configManager().config().booleanValue().falseValue();
}
}

View File

@@ -0,0 +1,88 @@
package at.helpch.placeholderapi;
import at.helpch.placeholderapi.commands.PlaceholderCommandRouter;
import at.helpch.placeholderapi.configuration.ConfigManager;
import at.helpch.placeholderapi.expansion.manager.CloudExpansionManager;
import at.helpch.placeholderapi.expansion.manager.LocalExpansionManager;
import com.hypixel.hytale.event.EventPriority;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import com.hypixel.hytale.server.core.console.ConsoleSender;
import com.hypixel.hytale.server.core.event.events.BootEvent;
import com.hypixel.hytale.server.core.event.events.PrepareUniverseEvent;
import com.hypixel.hytale.server.core.event.events.player.PlayerDisconnectEvent;
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import org.jetbrains.annotations.NotNull;
public class PlaceholderAPIPlugin extends JavaPlugin {
private final ConfigManager configManager = new ConfigManager(this);
private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
private static PlaceholderAPIPlugin instance;
public static PlaceholderAPIPlugin instance() {
return instance;
}
public PlaceholderAPIPlugin(@NotNull final JavaPluginInit init) {
super(init);
instance = this;
}
@Override
protected void setup() {
configManager.setup();
getEventRegistry().register(PlayerDisconnectEvent.class, localExpansionManager::onQuit);
getEventRegistry().register(EventPriority.LAST, BootEvent.class, this::onServerLoad);
if (configManager.config().cloudEnabled()) {
cloudExpansionManager.load();
}
}
@Override
protected void start() {
getCommandRegistry().registerCommand(new PlaceholderCommandRouter(this));
// localExpansionManager().load(ConsoleSender.INSTANCE);
super.start();
}
@Override
protected void shutdown() {
super.shutdown();
}
public void reloadPlugin(@NotNull final CommandSender sender) {
localExpansionManager.kill();
// configManager.save();
configManager.setup();
localExpansionManager.load(sender);
if (configManager.config().cloudEnabled()) {
cloudExpansionManager.load();
} else {
cloudExpansionManager.kill();
}
}
public LocalExpansionManager localExpansionManager() {
return localExpansionManager;
}
public ConfigManager configManager() {
return configManager;
}
public CloudExpansionManager cloudExpansionManager() {
return cloudExpansionManager;
}
private void onServerLoad(BootEvent event) {
localExpansionManager.load(ConsoleSender.INSTANCE);
}
}

View File

@@ -18,21 +18,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.replacer; package at.helpch.placeholderapi;
import me.clip.placeholderapi.Values; import com.hypixel.hytale.server.core.entity.entities.Player;
import org.openjdk.jmh.annotations.Benchmark; import com.hypixel.hytale.server.core.universe.PlayerRef;
import org.jetbrains.annotations.NotNull;
public class ReplacerBenchmarks { import org.jetbrains.annotations.Nullable;
@Benchmark
public void measureCharsReplacerSmallText() {
Values.CHARS_REPLACER.apply(Values.SMALL_TEXT, null, Values.PLACEHOLDERS::get);
}
@Benchmark
public void measureCharsReplacerLargeText() {
Values.CHARS_REPLACER.apply(Values.LARGE_TEXT, null, Values.PLACEHOLDERS::get);
}
public interface PlaceholderHook {
@Nullable
String onPlaceholderRequest(final PlayerRef player, @NotNull final String params);
} }

View File

@@ -18,18 +18,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.commands; package at.helpch.placeholderapi.commands;
import com.google.common.collect.ImmutableSet; import java.util.*;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.command.CommandSender; import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
@@ -41,22 +36,20 @@ public abstract class PlaceholderCommand {
@NotNull @NotNull
private final Set<String> alias; private final Set<String> alias;
@Nullable private Set<String> permissions = new HashSet<>();
private String permission;
protected PlaceholderCommand(@NotNull final String label, @NotNull final String... alias) { protected PlaceholderCommand(@NotNull final String label, @NotNull final String... alias) {
this.label = label; this.label = label;
this.alias = Sets.newHashSet(alias); this.alias = Set.of(alias);
setPermission("placeholderapi." + label); setPermissions("placeholderapi.*");
} }
@NotNull @NotNull
public static Stream<PlaceholderCommand> filterByPermission(@NotNull final CommandSender sender, public static Stream<PlaceholderCommand> filterByPermission(@NotNull final CommandSender sender,
@NotNull final Stream<PlaceholderCommand> commands) { @NotNull final Stream<PlaceholderCommand> commands) {
return commands.filter( return commands.filter(target -> target.getPermissions().stream().anyMatch(sender::hasPermission));
target -> target.getPermission() == null || sender.hasPermission(target.getPermission()));
} }
public static void suggestByParameter(@NotNull final Stream<String> possible, public static void suggestByParameter(@NotNull final Stream<String> possible,
@@ -77,22 +70,25 @@ public abstract class PlaceholderCommand {
@NotNull @NotNull
@Unmodifiable @Unmodifiable
public final Set<String> getAlias() { public final Set<String> getAlias() {
return ImmutableSet.copyOf(alias); return Set.copyOf(alias);
} }
@NotNull @NotNull
@Unmodifiable @Unmodifiable
public final Set<String> getLabels() { public final Set<String> getLabels() {
return ImmutableSet.<String>builder().add(label).addAll(alias).build(); final Set<String> set = new HashSet<>();
set.add(label);
set.addAll(alias);
return set;
} }
@Nullable @NotNull
public final String getPermission() { public final Set<String> getPermissions() {
return permission; return permissions;
} }
public void setPermission(@NotNull final String permission) { public void setPermissions(@NotNull final String @NotNull ... permissions) {
this.permission = permission; this.permissions.addAll(Arrays.asList(permissions));
} }
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@@ -106,5 +102,4 @@ public abstract class PlaceholderCommand {
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) { @NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
} }
} }

View File

@@ -0,0 +1,122 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands;
import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.impl.cloud.CommandECloud;
import at.helpch.placeholderapi.commands.impl.local.*;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.*;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
public final class PlaceholderCommandRouter extends AbstractCommand {
@Unmodifiable
private static final List<PlaceholderCommand> COMMANDS = List.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;
@Override
public String getName() {
return "papi";
}
public PlaceholderCommandRouter(@NotNull final PlaceholderAPIPlugin plugin) {
super("papi", "papi");
addAliases("placeholderapi");
setAllowsExtraArguments(true);
this.plugin = plugin;
final Map<String, PlaceholderCommand> commands = new HashMap<>();
for (final PlaceholderCommand command : COMMANDS) {
command.getLabels().forEach(label -> commands.put(label, command));
}
this.commands = commands;
}
@Override
protected boolean canGeneratePermission() {
return false;
}
@Override
protected @Nullable CompletableFuture<Void> execute(@NotNull final CommandContext context) {
final String[] args = context.getInputString().replace("papi", "").replace("placeholderapi", "").trim().split(" ");
final CommandSender sender = context.sender();
if (args.length == 0 || args[0].isBlank()) {
final PlaceholderCommand fallback = commands.get("version");
if (fallback != null) {
fallback.evaluate(plugin, sender, "", Collections.emptyList());
}
return CompletableFuture.completedFuture(null);
}
final String search = args[0].toLowerCase(Locale.ROOT);
final PlaceholderCommand target = commands.get(search);
if (target == null) {
sender.sendMessage(Message.raw("Unknown command ").color(Color.RED).insert(Message.raw(search).color(Color.GRAY)));
return CompletableFuture.completedFuture(null);
}
final Set<String> permissions = target.getPermissions();
if (permissions.stream().noneMatch(sender::hasPermission)) {
sender.sendMessage(Message.raw("You do not have permission to do this!").color(Color.RED));
return CompletableFuture.completedFuture(null);
}
target
.evaluate(plugin, sender, search, Arrays.asList(Arrays.copyOfRange(args, 1, args.length)));
return CompletableFuture.completedFuture(null);
}
}

View File

@@ -0,0 +1,184 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.cloud;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
public final class CommandECloud extends PlaceholderCommand {
@Unmodifiable
private static final List<PlaceholderCommand> COMMANDS = List
.of(new CommandECloudClear(),
new CommandECloudStatus(),
new CommandECloudUpdate(),
new CommandECloudRefresh(),
new CommandECloudDownload(),
new CommandECloudExpansionInfo(),
new CommandECloudExpansionList(),
new CommandECloudExpansionPlaceholders());
static {
COMMANDS
.forEach(command -> command.setPermissions("placeholderapi.ecloud." + command.getLabel()));
}
@NotNull
@Unmodifiable
private final Map<String, PlaceholderCommand> commands;
public CommandECloud() {
super("ecloud");
final Map<String, PlaceholderCommand> commands = new HashMap<>();
for (final PlaceholderCommand command : COMMANDS) {
command.getLabels().forEach(label -> commands.put(label, command));
}
this.commands = commands;
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud");
COMMANDS.stream().map(PlaceholderCommand::getPermissions).flatMap(Set::stream).forEach(this::setPermissions);
}
@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()) {
Message message = Message.empty()
.insert(Message.raw("PlaceholderAPI ").color(Color.CYAN).bold(true))
.insert(Message.raw("- ").color(Color.DARK_GRAY))
.insert(Message.raw("eCloud Help Menu ").color(Color.GRAY))
.insert(Message.raw("-\n").color(Color.DARK_GRAY));
final List<String[]> commands = List.of(
new String[]{"ecloud status", "View status of the eCloud"},
new String[]{"ecloud list <all/{author}/installed> {page}", "List all/author specific available expansions"},
new String[]{"ecloud info <expansion name> {version}", "View information about a specific expansion available on the eCloud"},
new String[]{"ecloud placeholders <expansion name>", "View placeholders for an expansion"},
new String[]{"ecloud download <expansion name> {version}", "Download an expansion from the eCloud"},
new String[]{"ecloud update <expansion name/all>", "Update a specific/all installed expansions"},
new String[]{"ecloud refresh", "Fetch the most up to date list of expansions available."},
new String[]{"ecloud clear", "Clear the expansion cloud cache."}
);
for (String[] command : commands) {
message = message.insert(Message.raw("\n/papi ").color(Color.CYAN))
.insert(Message.raw(command[0]).color(Color.WHITE))
.insert(Message.raw("\n " + command[1]).color(Color.GRAY));
}
sender.sendMessage(message);
// 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) {
sender.sendMessage(Message.raw("Unknown command ").color(Color.RED).insert(Message.raw("ecloud " + search).color(Color.GRAY)));
// Msg.msg(sender, "&cUnknown command &7ecloud " + search);
return;
}
final Set<String> permissions = target.getPermissions();
if (permissions.stream().noneMatch(sender::hasPermission)) {
sender.sendMessage(Message.raw("You do not have permission to do this!").color(Color.RED));
// Msg.msg(sender, "&cYou do not have permission to do this!");
return;
}
if (!plugin.configManager().config().cloudEnabled()) {
sender.sendMessage(Message.raw("The eCloud Manager is not enabled! To enable it, set 'cloud_enabled' to true and reload the plugin."));
// Msg.msg(sender, "&cThe eCloud Manager is not enabled! To enable it, set 'cloud_enabled' to true and reload the plugin.");
return;
}
if (!target.getLabel().equalsIgnoreCase("refresh") && plugin.cloudExpansionManager().isEmpty()) {
sender.sendMessage(Message.raw("There is no available data from the eCloud. Please try running ").color(Color.RED)
.insert(Message.raw("/papi ecloud refresh").color(Color.WHITE))
.insert(Message.raw(" If this does not resolve the issue, the eCloud may be blocked by your firewall, server host or service provider.\n\n").color(Color.RED))
.insert(Message.raw("More information: ").color(Color.RED))
.insert(Message.raw("https://placeholderapi.com/ecloud-blocked").color(Color.WHITE).bold(true).italic(true).link("https://placeholderapi.com/ecloud-blocked")));
// Msg.msg(sender, "&cThere is no available data from the eCloud. Please try running &f/papi ecloud refresh&c. If this does not resolve the issue, the eCloud may be blocked by your firewall, server host, or service provider.\n\nMore information: &fhttps://placeholderapi.com/ecloud-blocked");
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

@@ -18,14 +18,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.commands.impl.cloud; package at.helpch.placeholderapi.commands.impl.cloud;
import java.awt.*;
import java.util.List; import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand; import at.helpch.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg; import com.hypixel.hytale.server.core.Message;
import org.bukkit.command.CommandSender; import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
@@ -33,15 +34,17 @@ public final class CommandECloudClear extends PlaceholderCommand {
public CommandECloudClear() { public CommandECloudClear() {
super("clear"); super("clear");
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud.clear");
} }
@Override @Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias, @NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) { @NotNull @Unmodifiable final List<String> params) {
plugin.getCloudExpansionManager().clean(); plugin.cloudExpansionManager().clean();
Msg.msg(sender, sender.sendMessage(Message.raw("The eCloud cache has been cleared!").color(Color.GREEN));
"&aThe eCloud cache has been cleared!"); // Msg.msg(sender,
// "&aThe eCloud cache has been cleared!");
} }
} }

View File

@@ -0,0 +1,68 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.cloud;
import java.awt.*;
import java.util.Arrays;
import java.util.List;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudDownload extends PlaceholderCommand {
public CommandECloudDownload() {
super("download");
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud.download");
}
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));
}
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
final Message message = Message.raw("""
Expansion downloads have been disabled to meet CurseForge's policy requirements.
This limitation is imposed by the platform, not PlaceholderAPI.
""").color(Color.RED)
.insert(Message.raw("Please download expansions manually from ").color(Color.RED).insert(Message.raw("ecloud.placeholderapi.com").link("https://ecloud.placeholderapi.com").bold(true).italic(true).color(Color.WHITE)))
.insert(Message.raw(" or install the full version of PlaceholderAPI from ").color(Color.RED))
.insert(Message.raw("placeholderapi.com/downloads").link("https://placeholderapi.com/downloads").bold(true).italic(true).color(Color.WHITE));
sender.sendMessage(message);
}
}

View File

@@ -0,0 +1,134 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.cloud;
import java.awt.*;
import java.util.List;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudExpansionInfo extends PlaceholderCommand {
public CommandECloudExpansionInfo() {
super("info");
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud.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()) {
sender.sendMessage(Message.raw("You must specify the name of the expansion.").color(Color.RED));
// Msg.msg(sender,
// "&cYou must specify the name of the expansion.");
return;
}
final CloudExpansion expansion = plugin.cloudExpansionManager()
.findCloudExpansionByName(params.get(0)).orElse(null);
if (expansion == null) {
sender.sendMessage(Message.raw("There is no expansion with the name: ").color(Color.RED).insert(Message.raw(params.get(0)).color(Color.WHITE)));
// Msg.msg(sender,
// "&cThere is no expansion with the name: &f" + params.get(0));
return;
}
Message message = Message.raw("Expansion: ").color(Color.CYAN)
.insert(Message.raw(expansion.getName()).color(expansion.shouldUpdate() ? Color.YELLOW : Color.GREEN))
.insert(Message.raw("\nAuthor: ").color(Color.CYAN))
.insert(Message.raw(expansion.getAuthor()).color(Color.WHITE))
.insert(Message.raw("\n"));
if (params.size() < 2) {
message = message
.insert(Message.raw("Latest Version: ").color(Color.CYAN))
.insert(Message.raw(expansion.getLatestVersion()).color(Color.WHITE))
.insert(Message.raw("\nReleased: ").color(Color.CYAN))
.insert(Message.raw(expansion.getTimeSinceLastUpdate() + " ago").color(Color.WHITE))
.insert(Message.raw("\nVerified: ").color(Color.CYAN))
.insert(Message.raw(expansion.getVersion().isVerified() ? "YES" : "NO")
.color(expansion.getVersion().isVerified() ? Color.GREEN : Color.RED)
.bold(true))
.insert(Message.raw("\nRelease Notes: ").color(Color.CYAN))
.insert(Message.raw(expansion.getVersion().getReleaseNotes()).color(Color.WHITE))
.insert(Message.raw("\n"));
} else {
final CloudExpansion.Version version = expansion.getVersion(params.get(1));
if (version == null) {
sender.sendMessage(Message.raw("Could not find specified version: ").color(Color.RED)
.insert(Message.raw(params.get(1)).color(Color.WHITE))
.insert(Message.raw("\nVersions: ").color(Color.GREEN))
.insert(Message.raw(expansion.getAvailableVersions().toString()).color(Color.WHITE)));
// Msg.msg(sender,
// "&cCould not find specified version: &f" + params.get(1),
// "&aVersions: &f" + expansion.getAvailableVersions());
return;
}
message = message
.insert(Message.raw("Version: ").color(Color.CYAN))
.insert(Message.raw(version.getVersion()).color(Color.WHITE))
.insert(Message.raw("\nVerified: ").color(Color.CYAN))
.insert(Message.raw(version.isVerified() ? "YES" : "NO")
.color(version.isVerified() ? Color.GREEN : Color.RED)
.bold(true))
.insert(Message.raw("\nRelease Notes: ").color(Color.CYAN))
.insert(Message.raw(version.getReleaseNotes()).color(Color.WHITE))
.insert(Message.raw("\nDownload URL: ").color(Color.CYAN))
.insert(Message.raw(version.getUrl()).color(Color.WHITE))
.insert(Message.raw("\n"));
}
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) {
// 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

@@ -0,0 +1,392 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.cloud;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.function.Function;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import com.hypixel.hytale.server.core.entity.entities.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudExpansionList extends PlaceholderCommand {
private static final int PAGE_SIZE = 10;
@NotNull
private static final Function<CloudExpansion, String> EXPANSION_LATEST_VERSION =
CloudExpansion::getLatestVersion;
@NotNull
private static final Function<CloudExpansion, String> EXPANSION_CURRENT_VERSION =
expansion -> PlaceholderAPIPlugin.instance().localExpansionManager()
.findExpansionByName(expansion.getName()).map(PlaceholderExpansion::getVersion)
.orElse("Unknown");
@Unmodifiable
private static final Set<String> OPTIONS = Set.of("all", "installed");
public CommandECloudExpansionList() {
super("list");
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud.list");
}
@NotNull
private static Collection<CloudExpansion> getExpansions(@NotNull final String target,
@NotNull final PlaceholderAPIPlugin plugin) {
switch (target.toLowerCase(Locale.ROOT)) {
case "all":
return plugin.cloudExpansionManager().getCloudExpansions().values();
case "installed":
return plugin.cloudExpansionManager().getCloudExpansionsInstalled().values();
default:
return plugin.cloudExpansionManager().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();
}
return expansions.subList(head, tail);
}
public static Message buildExpansionTitle(@NotNull final String target, final int page) {
Message title;
switch (target.toLowerCase(Locale.ROOT)) {
case "all":
title = Message.raw("All Expansions").color(Color.CYAN);
break;
case "installed":
title = Message.raw("Installed Expansions").color(Color.CYAN);
break;
default:
title = Message.raw("Expansions by ").color(Color.CYAN)
.insert(Message.raw(target).color(Color.WHITE));
break;
}
if (page == -1) {
return title.insert(Message.raw("\n"));
}
return title
.insert(Message.raw(" Page").color(Color.CYAN))
.insert(Message.raw(": ").color(Color.GRAY))
.insert(Message.raw(String.valueOf(page)).color(Color.GREEN));
}
private static Message getMessage(@NotNull final List<CloudExpansion> expansions,
final int page, final int limit, @NotNull final String target) {
Message message = Message.empty();
for (int index = 0; index < expansions.size(); index++) {
final CloudExpansion expansion = expansions.get(index);
Message line = Message.empty();
final int expansionNumber = index + ((page - 1) * PAGE_SIZE) + 1;
line = line.insert(Message.raw(expansionNumber + ". ").color(Color.DARK_GRAY));
final Color expansionColour;
if (expansion.shouldUpdate()) {
expansionColour = Color.YELLOW;
} else {
if (expansion.hasExpansion()) {
expansionColour = Color.GREEN;
} else {
expansionColour = Color.GRAY;
}
}
line = line.insert(Message.raw(expansion.getName()).color(expansionColour));
// line = line.click(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.getVersion().isVerified() ? "✔" : "❌", expansion.getVersion().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.insert(Message.raw("\n"));
}
message = message.insert(line);
}
if (limit > 1) {
message = message.insert("\n");
// Message left = Message.raw("◀", 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 = message.insert(Message.raw(" - " + page + " - ").color(Color.GREEN));
}
return message;
}
private static Message buildExpansionTable(@NotNull final List<CloudExpansion> expansions,
final int startIndex,
@NotNull final String versionTitle,
@NotNull final Function<CloudExpansion, String> versionFunction) {
final List<List<String>> rows = new ArrayList<>();
rows.add(List.of("#", "Name", "Author", "Verified", versionTitle));
int counter = startIndex;
for (final CloudExpansion expansion : expansions) {
rows.add(List.of(
counter++ + ".",
expansion.getName(),
expansion.getAuthor(),
expansion.getVersion().isVerified() ? "Y" : "N",
versionFunction.apply(expansion)
));
}
final int columnCount = rows.getFirst().size();
final int[] widths = new int[columnCount];
for (final List<String> row : rows) {
for (int i = 0; i < columnCount; i++) {
widths[i] = Math.max(widths[i], row.get(i).length());
}
}
final List<Color> headerColors = List.of(
Color.WHITE,
new Color(85, 85, 255),
new Color(85, 85, 255),
new Color(85, 85, 255),
new Color(85, 85, 255)
);
Message message = Message.empty();
message = message.insert(buildTableRow(rows.getFirst(), headerColors, widths));
message = message.insert(Message.raw("\n"));
final int separatorLength = Arrays.stream(widths).sum() + (columnCount * 2);
message = message.insert(Message.raw("-".repeat(separatorLength)).color(Color.DARK_GRAY));
if (rows.size() > 1) {
message = message.insert(Message.raw("\n"));
}
for (int rowIndex = 1; rowIndex < rows.size(); rowIndex++) {
final List<String> row = rows.get(rowIndex);
final CloudExpansion expansion = expansions.get(rowIndex - 1);
final Color nameColor = expansion.shouldUpdate()
? Color.YELLOW
: (expansion.hasExpansion() ? Color.GREEN : Color.GRAY);
final List<Color> rowColors = List.of(
Color.DARK_GRAY,
nameColor,
Color.WHITE,
expansion.getVersion().isVerified() ? Color.GREEN : Color.RED,
Color.WHITE
);
message = message.insert(buildTableRow(row, rowColors, widths));
if (rowIndex < rows.size() - 1) {
message = message.insert(Message.raw("\n"));
}
}
return message;
}
private static Message buildTableRow(@NotNull final List<String> columns,
@NotNull final List<Color> colors,
@NotNull final int[] widths) {
Message row = Message.empty();
for (int i = 0; i < columns.size(); i++) {
final String padded = padRight(columns.get(i), widths[i] + 2);
row = row.insert(Message.raw(padded).color(colors.get(i)));
}
return row;
}
@NotNull
private static String padRight(@NotNull final String text, final int length) {
if (text.length() >= length) {
return text;
}
return text + " ".repeat(length - text.length());
}
@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()) {
sender.sendMessage(Message.raw("You must specify an option. [all, {author}, installed]").color(Color.RED));
// Msg.msg(sender,
// "&cYou must specify an option. [all, {author}, installed]");
return;
}
final boolean installed = params.get(0).equalsIgnoreCase("installed");
final List<CloudExpansion> expansions = new ArrayList<>(getExpansions(params.get(0), plugin));
if (expansions.isEmpty()) {
sender.sendMessage(Message.raw("No expansions available to list.").color(Color.RED));
// Msg.msg(sender,
// "&cNo expansions available to list.");
return;
}
expansions
.sort(plugin.configManager().config().cloudSorting());
if (!(sender instanceof Player) && params.size() < 2) {
final Message message = buildExpansionTitle(params.get(0), -1)
.insert(buildExpansionTable(
expansions,
1,
installed ? "Version" : "Latest Version",
installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION));
sender.sendMessage(message);
// Msg.msg(sender, builder.toString());
return;
}
final int page;
if (params.size() < 2) {
page = 1;
} else {
//noinspection UnstableApiUsage
Integer parsed/* = Ints.tryParse(params.get(1))*/;
try {
parsed = Integer.parseInt(params.get(1));
} catch (Exception e) {
parsed = null;
}
if (parsed == null) {
sender.sendMessage(Message.raw("Page number must be an integer.").color(Color.RED));
// 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) {
sender.sendMessage(Message.raw("Page number must be in the range [1.." + limit + "]").color(Color.RED)); //todo: not exact
// Msg.msg(sender,
// "&cPage number must be in the range &8[&a1&7..&a" + limit + "&8]");
return;
}
page = parsed;
}
final List<CloudExpansion> values = getPage(expansions, page - 1);
final Message title = buildExpansionTitle(params.get(0), page);
if (!(sender instanceof Player)) {
final Message message = title.insert(buildExpansionTable(
values,
((page - 1) * PAGE_SIZE) + 1,
installed ? "Version" : "Latest Version",
installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION));
sender.sendMessage(message);
// Msg.msg(sender, builder.toString());
return;
}
sender.sendMessage(title);
// Msg.msg(sender, builder.toString());
final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
final Message message = getMessage(values, page, limit, params.get(0));
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

@@ -0,0 +1,124 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.cloud;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudExpansionPlaceholders extends PlaceholderCommand {
public CommandECloudExpansionPlaceholders() {
super("placeholders");
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud.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()) {
sender.sendMessage(Message.raw("You must specify the name of the expansion.").color(Color.RED));
// Msg.msg(sender,
// "&cYou must specify the name of the expansion.");
return;
}
final CloudExpansion expansion = plugin.cloudExpansionManager()
.findCloudExpansionByName(params.get(0)).orElse(null);
if (expansion == null) {
sender.sendMessage(Message.raw("There is no expansion with the name: ").color(Color.RED).insert(Message.raw(params.getFirst()).color(Color.WHITE)));
// 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()) {
sender.sendMessage(Message.raw("The expansion specified does not have placeholders listed.").color(Color.RED));
// 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);
final List<List<String>> partitions = new ArrayList<>(IntStream.range(0, placeholders.size()).boxed().collect(Collectors.groupingBy(i -> i/10, Collectors.mapping(placeholders::get, Collectors.toList()))).values());
Message message = Message.raw(" ").color(Color.ORANGE)
.insert(Message.raw(String.valueOf(placeholders.size())).color(Color.ORANGE))
.insert(Message.raw(" placeholders: ").color(Color.GRAY));
for (int i = 0; i < partitions.size(); i++) {
if (i == 0) {
message = message.insert(Message.raw("\n"));
}
final List<String> partition = partitions.get(i);
for (int j = 0; j < partition.size(); j++) {
message = message.insert(Message.raw(partition.get(j)).color(Color.GREEN));
if (j < partition.size() - 1) {
message = message.insert(Message.raw(", ").color(Color.GRAY));
}
}
if (i < partitions.size() - 1) {
message = message.insert(Message.raw("\n"));
}
}
sender.sendMessage(message);
// 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

@@ -18,14 +18,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.commands.impl.cloud; package at.helpch.placeholderapi.commands.impl.cloud;
import java.awt.*;
import java.util.List; import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand; import at.helpch.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg; import com.hypixel.hytale.server.core.Message;
import org.bukkit.command.CommandSender; import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
@@ -33,16 +34,18 @@ public final class CommandECloudRefresh extends PlaceholderCommand {
public CommandECloudRefresh() { public CommandECloudRefresh() {
super("refresh"); super("refresh");
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud.refresh");
} }
@Override @Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias, @NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) { @NotNull @Unmodifiable final List<String> params) {
plugin.getCloudExpansionManager().load(); plugin.cloudExpansionManager().load();
Msg.msg(sender, sender.sendMessage(Message.raw("The eCloud manager has been refreshed!").color(Color.GREEN));
"&aThe eCloud manager has been refreshed!"); // Msg.msg(sender,
// "&aThe eCloud manager has been refreshed!");
} }
} }

View File

@@ -0,0 +1,72 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.cloud;
import java.awt.*;
import java.util.List;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.manager.CloudExpansionManager;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudStatus extends PlaceholderCommand {
public CommandECloudStatus() {
super("status");
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud.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.cloudExpansionManager();
final int updateCount = manager.getCloudUpdateCount();
final int authorCount = manager.getCloudExpansionAuthorCount();
final int expansionCount = manager.getCloudExpansions().size();
Message message = Message.raw("There are ").color(Color.CYAN)
.insert(Message.raw(String.valueOf(expansionCount)).color(Color.GREEN))
.insert(Message.raw(" expansions available on the eCloud.\n").color(Color.CYAN))
.insert(Message.raw("A total of ").color(Color.GRAY))
.insert(Message.raw(String.valueOf(authorCount)).color(Color.WHITE))
.insert(Message.raw(" authors have contributed Hytale expansions to the eCloud.\n").color(Color.GRAY));
if (updateCount > 0) {
message = message
.insert(Message.raw("You have ").color(Color.YELLOW))
.insert(Message.raw(String.valueOf(updateCount)).color(Color.WHITE))
.insert(Message.raw(updateCount > 1 ? " expansions" : " expansion").color(Color.YELLOW))
.insert(Message.raw(" installed that ").color(Color.YELLOW))
.insert(Message.raw(updateCount > 1 ? "have an" : "has an").color(Color.YELLOW))
.insert(Message.raw(" update available.").color(Color.YELLOW));
}
sender.sendMessage(message);
// Msg.msg(sender, builder.toString());
}
}

View File

@@ -0,0 +1,67 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.cloud;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import at.helpch.placeholderapi.util.Futures;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
/**
* please don't flame me for this code, I will fix this shit later.
*/
public final class CommandECloudUpdate extends PlaceholderCommand {
public CommandECloudUpdate() {
super("update");
setPermissions("placeholderapi.ecloud.*", "placeholderapi.ecloud.update");
}
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
final Message message = Message.raw("""
Expansion downloads have been disabled to meet CurseForge's policy requirements.
This limitation is imposed by the platform, not PlaceholderAPI.
""").color(Color.RED)
.insert(Message.raw("Please download expansions manually from ").color(Color.RED).insert(Message.raw("ecloud.placeholderapi.com").link("https://ecloud.placeholderapi.com").bold(true).italic(true).color(Color.WHITE)))
.insert(Message.raw(" or install the full version of PlaceholderAPI from ").color(Color.RED))
.insert(Message.raw("placeholderapi.com/downloads").link("https://placeholderapi.com/downloads").bold(true).italic(true).color(Color.WHITE));
sender.sendMessage(message);
}
}

View File

@@ -18,24 +18,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.commands.impl.local; package at.helpch.placeholderapi.commands.impl.local;
import com.google.common.io.CharStreams; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.commands.PlaceholderCommand; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import com.hypixel.hytale.common.plugin.AuthorInfo;
import me.clip.placeholderapi.util.Msg; import com.hypixel.hytale.common.util.java.ManifestUtil;
import org.bukkit.command.CommandSender; import com.hypixel.hytale.server.core.HytaleServer;
import org.bukkit.plugin.Plugin; import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import com.hypixel.hytale.server.core.plugin.PluginBase;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
import java.io.IOException; import java.awt.*;
import java.io.InputStream; import java.io.*;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -43,13 +43,11 @@ import java.time.Instant;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle; import java.time.format.FormatStyle;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionException;
import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public final class CommandDump extends PlaceholderCommand { public final class CommandDump extends PlaceholderCommand {
@@ -69,6 +67,7 @@ public final class CommandDump extends PlaceholderCommand {
public CommandDump() { public CommandDump() {
super("dump"); super("dump");
setPermissions("placeholderapi.admin", "placeholderapi.dump");
} }
@Override @Override
@@ -77,15 +76,17 @@ public final class CommandDump extends PlaceholderCommand {
@NotNull @Unmodifiable final List<String> params) { @NotNull @Unmodifiable final List<String> params) {
postDump(makeDump(plugin)).whenComplete((key, exception) -> { postDump(makeDump(plugin)).whenComplete((key, exception) -> {
if (exception != null) { if (exception != null) {
plugin.getLogger().log(Level.WARNING, "failed to post dump details", exception); plugin.getLogger().atWarning().log("failed to post dump details ", exception);
Msg.msg(sender, sender.sendMessage(Message.raw("Failed to post dump details, check console.").color(Color.RED));
"&cFailed to post dump details, check console."); // Msg.msg(sender,
// "&cFailed to post dump details, check console.");
return; return;
} }
Msg.msg(sender, sender.sendMessage(Message.raw("Successfully posted dump: ").color(Color.GREEN).insert(Message.raw(URL + key).color(Color.WHITE).bold(true).italic(true).link(URL + key)));
"&aSuccessfully posted dump: " + URL + key); // Msg.msg(sender,
// "&aSuccessfully posted dump: " + URL + key);
}); });
} }
@@ -106,7 +107,7 @@ public final class CommandDump extends PlaceholderCommand {
} }
try (final InputStream stream = connection.getInputStream()) { try (final InputStream stream = connection.getInputStream()) {
final String json = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8)); final String json = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining(System.lineSeparator()));
return gson.fromJson(json, JsonObject.class).get("key").getAsString(); return gson.fromJson(json, JsonObject.class).get("key").getAsString();
} }
} catch (final IOException ex) { } catch (final IOException ex) {
@@ -124,20 +125,20 @@ public final class CommandDump extends PlaceholderCommand {
.append("\n\n"); .append("\n\n");
builder.append("PlaceholderAPI: ") builder.append("PlaceholderAPI: ")
.append(plugin.getDescription().getVersion()) .append(plugin.getManifest().getVersion())
.append("\n\n"); .append("\n\n");
builder.append("Expansions Registered:") builder.append("Expansions Registered:")
.append('\n'); .append('\n');
final List<PlaceholderExpansion> expansions = plugin.getLocalExpansionManager() final List<PlaceholderExpansion> expansions = plugin.localExpansionManager()
.getExpansions() .getExpansions()
.stream() .stream()
.sorted( .sorted(
Comparator.comparing(PlaceholderExpansion::getIdentifier) Comparator.comparing(PlaceholderExpansion::getIdentifier)
.thenComparing(PlaceholderExpansion::getAuthor) .thenComparing(PlaceholderExpansion::getAuthor)
) )
.collect(Collectors.toList()); .toList();
int size = expansions.stream().map(e -> e.getIdentifier().length()) int size = expansions.stream().map(e -> e.getIdentifier().length())
.max(Integer::compareTo) .max(Integer::compareTo)
@@ -159,7 +160,7 @@ public final class CommandDump extends PlaceholderCommand {
builder.append("Expansions Directory:") builder.append("Expansions Directory:")
.append('\n'); .append('\n');
final String[] jars = plugin.getLocalExpansionManager() final String[] jars = plugin.localExpansionManager()
.getExpansionsFolder() .getExpansionsFolder()
.list((dir, name) -> name.toLowerCase(Locale.ROOT).endsWith(".jar")); .list((dir, name) -> name.toLowerCase(Locale.ROOT).endsWith(".jar"));
@@ -177,9 +178,7 @@ public final class CommandDump extends PlaceholderCommand {
builder.append('\n'); builder.append('\n');
builder.append("Server Info: ") builder.append("Server Info: ")
.append(plugin.getServer().getBukkitVersion()) .append(ManifestUtil.getImplementationVersion()) // hytale version
.append('/')
.append(plugin.getServer().getVersion())
.append("\n"); .append("\n");
builder.append("Java Version: ") builder.append("Java Version: ")
@@ -189,21 +188,23 @@ public final class CommandDump extends PlaceholderCommand {
builder.append("Plugin Info:") builder.append("Plugin Info:")
.append('\n'); .append('\n');
List<Plugin> plugins = Arrays.stream(plugin.getServer().getPluginManager().getPlugins()) List<PluginBase> plugins = HytaleServer.get().getPluginManager().getPlugins().stream()
.sorted(Comparator.comparing(Plugin::getName)) .sorted(Comparator.comparing(PluginBase::getName))
.collect(Collectors.toList()); .toList();
size = plugins.stream().map(pl -> pl.getName().length()) size = plugins.stream().map(pl -> pl.getName().length())
.max(Integer::compareTo) .max(Integer::compareTo)
.orElse(0); .orElse(0);
for (final Plugin other : plugins) { for (final PluginBase other : plugins) {
builder.append(" ") builder.append(" ")
.append(String.format("%-" + size + "s", other.getName())) .append(String.format("%-" + size + "s", other.getName()))
.append(" [Authors: [") .append(" [Authors: [")
.append(String.join(", ", other.getDescription().getAuthors())) .append(other.getManifest().getAuthors().stream()
.map(AuthorInfo::getName)
.collect(Collectors.joining(", ")))
.append("], Version: ") .append("], Version: ")
.append(other.getDescription().getVersion()) .append(other.getManifest().getVersion())
.append("]") .append("]")
.append("\n"); .append("\n");
} }

View File

@@ -0,0 +1,117 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.local;
import java.awt.*;
import java.io.File;
import java.util.List;
import java.util.Optional;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import at.helpch.placeholderapi.expansion.manager.LocalExpansionManager;
import at.helpch.placeholderapi.util.Futures;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandExpansionRegister extends PlaceholderCommand {
public CommandExpansionRegister() {
super("register");
setPermissions("placeholderapi.admin", "placeholderapi.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.isEmpty()) {
sender.sendMessage(Message.raw("You must specify the name of an expansion file.").color(Color.RED));
// Msg.msg(sender,
// "&cYou must specify the name of an expansion file.");
return;
}
final LocalExpansionManager manager = plugin.localExpansionManager();
final File file = new File(manager.getExpansionsFolder(), params.getFirst());
if (!file.exists() || !file.getParentFile().equals(manager.getExpansionsFolder())) {
sender.sendMessage(Message.raw("The file ").color(Color.RED).insert(Message.raw(file.getName()).color(Color.WHITE)).insert(Message.raw(" doesn't exist!").color(Color.RED)));
// Msg.msg(sender,
// "&cThe file &f" + file.getName() + "&c doesn't exist!");
return;
}
Futures.onMainThread(plugin, manager.findExpansionInFile(file), (clazz, exception) -> {
if (exception != null) {
sender.sendMessage(Message.raw("Failed to find expansion in file: ").color(Color.RED).insert(Message.raw(file.toString()).color(Color.WHITE)));
// Msg.msg(sender,
// "&cFailed to find expansion in file: &f" + file);
plugin.getLogger()
.atWarning().log("failed to find expansion in file: " + file, exception);
return;
}
if (clazz == null) {
sender.sendMessage(Message.raw("No expansion class found in file: ").color(Color.RED).insert(Message.raw(file.toString()).color(Color.WHITE)));
// Msg.msg(sender,
// "&cNo expansion class found in file: &f" + file);
return;
}
final Optional<PlaceholderExpansion> expansion = manager.register(clazz);
if (!expansion.isPresent()) {
sender.sendMessage(Message.raw("Failed to register expansion from ").color(Color.RED).insert(Message.raw(params.getFirst()).color(Color.WHITE)));
// Msg.msg(sender,
// "&cFailed to register expansion from &f" + params.get(0));
return;
}
sender.sendMessage(Message.raw("Sucessfully registered expansion: ").color(Color.GREEN).insert(Message.raw(expansion.get().getName()).color(Color.WHITE)));
// Msg.msg(sender,
// "&aSuccessfully registered expansion: &f" + expansion.get().getName());
});
}
// @Override
// public void complete(@NotNull final PlaceholderAPIPlugin plugin,
// @NotNull final CommandSender sender, @NotNull final String alias,
// @NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
// if (params.size() > 1) {
// return;
// }
//
// final String[] fileNames = plugin.getLocalExpansionManager().getExpansionsFolder()
// .list((dir, name) -> name.endsWith(".jar"));
// if (fileNames == null || fileNames.length == 0) {
// return;
// }
//
// suggestByParameter(Arrays.stream(fileNames), suggestions,
// params.isEmpty() ? null : params.get(0));
// }
}

View File

@@ -0,0 +1,86 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.local;
import java.awt.*;
import java.util.List;
import java.util.Optional;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandExpansionUnregister extends PlaceholderCommand {
public CommandExpansionUnregister() {
super("unregister");
setPermissions("placeholderapi.admin", "placeholderapi.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()) {
sender.sendMessage(Message.raw("You must specify the name of the expansion.").color(Color.RED));
// Msg.msg(sender,
// "&cYou must specify the name of the expansion.");
return;
}
final Optional<PlaceholderExpansion> expansion = plugin.localExpansionManager()
.findExpansionByName(params.get(0));
if (!expansion.isPresent()) {
sender.sendMessage(Message.raw("There is no expansion loaded with the identifier: ").color(Color.RED).insert(Message.raw(params.getFirst()).color(Color.WHITE)));
// 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";
final Message message = !expansion.get().unregister() ?
Message.raw("Failed to unregister expansion: ").color(Color.RED) :
Message.raw("Successfully unregistered expansion: ").color(Color.GREEN);
sender.sendMessage(message.insert(Message.raw(expansion.get().getName()).color(Color.WHITE)));
// sender.sendMessage(Message.raw(message + exp));
// 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));
// }
}

View File

@@ -0,0 +1,112 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.local;
import java.awt.*;
import java.util.List;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import com.hypixel.hytale.common.plugin.PluginManifest;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandHelp extends PlaceholderCommand {
public CommandHelp() {
super("help");
setPermissions("placeholderapi.admin", "placeholderapi.help");
}
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
final PluginManifest description = plugin.getManifest();
// final PluginDescriptionFile description = plugin.getDescription();
final Message message = Message.raw("PlaceholderAPI ").color(Color.CYAN).bold(true)
.insert(Message.raw("- ").color(Color.DARK_GRAY).bold(false))
.insert(Message.raw("Help Menu ").color(Color.WHITE).bold(false))
.insert(Message.raw("- ").color(Color.DARK_GRAY).bold(false))
.insert(Message.raw("(").color(Color.GRAY).bold(false))
.insert(Message.raw(description.getVersion().toString()).color(Color.WHITE).bold(false))
.insert(Message.raw(")").color(Color.GRAY).bold(false))
.insert(Message.raw("\n"))
.insert(genCommandMsg("bcparse", "<me|--null|player name> <message>", "Parse a message with placeholders and broadcast it"))
.insert(genCommandMsg("cmdparse", "<me|player> <command with placeholders>", "Parse a message with relational placeholders"))
.insert(genCommandMsg("dump", null, "Dump all relevant information needed to help debug issues into a paste link."))
.insert(genCommandMsg("info", "<placeholder name>", "View information for a specific expansion"))
.insert(genCommandMsg("list", null, "List active expansions"))
.insert(genCommandMsg("parse", "<me|--null|player name> <message>", "Parse a message with placeholders"))
.insert(genCommandMsg("parserel", "<player one> <player two> <message>", "Parse a message with relational placeholders"))
.insert(genCommandMsg("register", "<file name>", "Register an expansion by the name of the file"))
.insert(genCommandMsg("reload", null, "Reload the config of PAPI"))
.insert(genCommandMsg("unregister", "<expansion name>", "Unregister an expansion by name"))
.insert(genCommandMsg("version", null, "View plugin info/version"));
sender.sendMessage(message);
// 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");
}
private Message genCommandMsg(@NotNull final String command, @Nullable final String arguments,
@NotNull final String description) {
Message message = Message.raw("\n/papi ").color(Color.CYAN)
.insert(Message.raw(command).color(Color.WHITE));
if (arguments != null) {
message = message.insert(" " + arguments).color(Color.CYAN);
}
return message
.insert(Message.raw("\n " + description).color(Color.gray).bold(false));
}
}

View File

@@ -0,0 +1,130 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.local;
import java.awt.*;
import java.util.List;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandInfo extends PlaceholderCommand {
public CommandInfo() {
super("info");
setPermissions("placeholderapi.admin", "placeholderapi.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()) {
sender.sendMessage(Message.raw("You must specify the name of the expansion.").color(Color.RED));
// Msg.msg(sender,
// "&cYou must specify the name of the expansion.");
return;
}
final PlaceholderExpansion expansion = plugin.localExpansionManager()
.findExpansionByIdentifier(params.get(0)).orElse(null);
if (expansion == null) {
sender.sendMessage(Message.raw("There is no expansion loaded with the identifier: ").color(Color.RED).insert(Message.raw(params.getFirst()).color(Color.WHITE)));
// Msg.msg(sender,
// "&cThere is no expansion loaded with the identifier: &f" + params.get(0));
return;
}
Message message = Message.empty()
.insert(Message.raw("Placeholder expansion info for:").color(Color.GRAY))
.insert(Message.raw(expansion.getName() + "\n").color(Color.WHITE))
.insert(Message.raw("Status: ").color(Color.GRAY))
.insert(Message.raw(expansion.isRegistered() ? "Registered" : "Not Registered").color(expansion.isRegistered() ? Color.GREEN : Color.RED))
.insert("\n");
final String author = expansion.getAuthor();
if (author != null) {
message = message.insert(Message.raw("Author: ").color(Color.GRAY))
.insert(Message.raw(author + "\n").color(Color.WHITE));
// builder.append("&7Author: &r")
// .append(author)
// .append('\n');
}
final String version = expansion.getVersion();
if (version != null) {
message = message.insert(Message.raw("Version: ").color(Color.GRAY))
.insert(Message.raw(version + "\n").color(Color.WHITE));
// builder.append("&7Version: &r")
// .append(version)
// .append('\n');
}
final String requiredPlugin = expansion.getRequiredPlugin();
if (requiredPlugin != null) {
message = message.insert(Message.raw("Requires plugin: ").color(Color.GRAY))
.insert(Message.raw(requiredPlugin + '\n').color(Color.WHITE));
// builder.append("&7Requires plugin: &r")
// .append(requiredPlugin)
// .append('\n');
}
final List<String> placeholders = expansion.getPlaceholders();
if (placeholders != null && !placeholders.isEmpty()) {
message = message.insert(Message.raw("-- ").color(Color.DARK_GRAY))
.insert(Message.raw("Placeholders ").color(Color.GRAY))
.insert(Message.raw("--\n").color(Color.DARK_GRAY));
// builder.append("&8&m-- &7Placeholders &8&m--&r")
// .append('\n');
for (final String placeholder : placeholders) {
message = message.insert(Message.raw(placeholder + "\n").color(Color.WHITE));
// builder.append(placeholder)
// .append('\n');
}
}
sender.sendMessage(message);
// 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

@@ -0,0 +1,89 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.local;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import at.helpch.placeholderapi.PlaceholderAPI;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandList extends PlaceholderCommand {
public CommandList() {
super("list");
setPermissions("placeholderapi.admin", "placeholderapi.list");
}
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
final List<String> identifiers = new ArrayList<>(PlaceholderAPI.getRegisteredIdentifiers());
if (identifiers.isEmpty()) {
sender.sendMessage(Message.raw("There are no placeholder hooks active!").color(Color.RED));
// Msg.msg(sender, "&cThere are no placeholder hooks active!");
return;
}
final List<List<String>> partitions = new ArrayList<>(IntStream.range(0, identifiers.size()).boxed().collect(Collectors.groupingBy(i -> i/10, Collectors.mapping(identifiers::get, Collectors.toList()))).values());
// final List<List<String>> partitions = Lists
// .partition(identifiers.stream().sorted().collect(Collectors.toList()), 10);
Message message = Message.raw("A total of ").color(Color.GRAY)
.insert(Message.raw(identifiers.size() + " ").color(Color.WHITE))
.insert(Message.raw("placeholder hook(s) are active: ").color(Color.GRAY));
for (int i = 0; i < partitions.size(); ++i) {
final List<String> partition = partitions.get(i);
for (int j = 0; j < partition.size(); ++j) {
message = message.insert(Message.raw(partition.get(j)).color(Color.GREEN));
if (j != partition.size() - 1) {
message = message.insert(Message.raw(", ").color(Color.GRAY));
}
}
if (i != partitions.size() - 1) {
message = message.insert(Message.raw("\n"));
}
}
sender.sendMessage(message);
// 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

@@ -0,0 +1,279 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.local;
import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.stream.Stream;
import at.helpch.placeholderapi.PlaceholderAPI;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.NameMatching;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.server.core.universe.Universe;
import com.hypixel.hytale.server.core.universe.world.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandParse extends PlaceholderCommand {
public CommandParse() {
super("parse", "bcparse", "parserel", "cmdparse");
setPermissions("placeholderapi.admin", "placeholderapi.parse");
}
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
final Runnable logic = () -> {
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 World world;
if (sender instanceof Player) {
world = ((Player) sender).getWorld();
} else if (sender instanceof PlayerRef) {
UUID uuid = ((PlayerRef) sender).getWorldUuid();
world = uuid == null ? Universe.get().getDefaultWorld() : Universe.get().getWorld(uuid);
} else {
world = Universe.get().getDefaultWorld();
}
if (world != null) {
world.execute(logic);
} else {
logic.run();
}
}
private void evaluateParseSingular(@NotNull final CommandSender sender,
@NotNull @Unmodifiable final List<String> params, final boolean broadcast,
final boolean command) {
if (params.size() < 2) {
sender.sendMessage(Message.raw("You must provide a target and a message: ").color(Color.RED)
.insert(Message.raw("/papi ").color(Color.CYAN))
.insert(Message.raw(command ? "cmdparse" : (broadcast ? "bcparse" : "parse")).color(Color.CYAN))
.insert(Message.raw(" {target}").color(Color.GRAY))
.insert(Message.raw(" {message}").color(Color.GREEN)));
return;
}
PlayerRef player;
if ("me".equalsIgnoreCase(params.getFirst())) {
if (!(sender instanceof Player) && !(sender instanceof PlayerRef)) {
sender.sendMessage(Message.raw("You must be a player to use ").color(Color.RED).insert(Message.raw("me").color(Color.GRAY)).insert(Message.raw(" as a target!").color(Color.RED)));
return;
}
if (sender instanceof Player) {
player = ((Player) sender).getPlayerRef();
} else {
player = (PlayerRef) sender;
}
} else if ("--null".equalsIgnoreCase(params.get(0))) {
player = null;
} else {
final PlayerRef target = resolvePlayer(params.get(0));
if (target == null) {
sender.sendMessage(Message.raw("Failed to find player: ").color(Color.RED).insert(Message.raw(params.get(0)).color(Color.WHITE)));
return;
}
player = target;
}
final String message = PlaceholderAPI
.setPlaceholders(player, String.join(" ", params.subList(1, params.size())));
if (command) {
sender.sendMessage(Message.raw("To be implemented")); // todo: implement
return;
}
if (broadcast) {
Universe.get().sendMessage(Message.raw(message));
} else {
sender.sendMessage(Message.raw(message));
}
}
private void evaluateParseRelation(@NotNull final CommandSender sender,
@NotNull @Unmodifiable final List<String> params) {
if (params.size() < 3) {
sender.sendMessage(Message.raw("You must supply two targets, and a message: ").color(Color.RED)
.insert(Message.raw("/papi parserel ").color(Color.CYAN))
.insert(Message.raw("{target one} {target two} ").color(Color.GRAY))
.insert(Message.raw("{message}").color(Color.GREEN)));
return;
}
PlayerRef playerOne;
if ("me".equalsIgnoreCase(params.get(0))) {
if (!(sender instanceof Player) && !(sender instanceof PlayerRef)) {
sender.sendMessage(Message.raw("You must be a player to use ").color(Color.RED)
.insert(Message.raw("me").color(Color.GRAY))
.insert(Message.raw(" as a target!").color(Color.RED)));
return;
}
if (sender instanceof Player) {
playerOne = ((Player) sender).getPlayerRef();
} else {
playerOne = (PlayerRef) sender;
}
} else {
playerOne = resolvePlayer(params.get(0));
}
if (playerOne == null) {
sender.sendMessage(Message.raw("Failed to find player: ").color(Color.RED).insert(Message.raw(params.get(0)).color(Color.WHITE)));
return;
}
PlayerRef playerTwo;
if ("me".equalsIgnoreCase(params.get(1))) {
if (!(sender instanceof Player) && !(sender instanceof PlayerRef)) {
sender.sendMessage(Message.raw("You must be a player to use ").color(Color.RED).insert(Message.raw("me").color(Color.GRAY)).insert(Message.raw(" as a target!").color(Color.RED)));
return;
}
if (sender instanceof Player) {
playerTwo = ((Player) sender).getPlayerRef();
} else {
playerTwo = (PlayerRef) sender;
}
} else {
playerTwo = resolvePlayer(params.get(1));
}
if (playerTwo == null) {
sender.sendMessage(Message.raw("Failed to find player: ").color(Color.RED).insert(Message.raw(params.get(1)).color(Color.WHITE)));
return;
}
final String message = PlaceholderAPI
.setRelationalPlaceholders(playerOne, playerTwo,
String.join(" ", params.subList(2, params.size())));
sender.sendMessage(Message.raw(message));
}
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 = Universe.get().getPlayers().stream().map(PlayerRef::getUsername);
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.instance()
.localExpansionManager().findExpansionByIdentifier(name.substring(1, index))
.orElse(null);
if (expansion == null) {
return;
}
final Set<String> possible = new HashSet<>(expansion.getPlaceholders());
PlaceholderAPIPlugin.instance()
.cloudExpansionManager()
.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 PlayerRef resolvePlayer(@NotNull final String name) {
// Player target = Universe.get().getPlayerByUsername(name, NameMatching.EXACT);
// final Optional<Player> target = world.getPlayers().stream().filter(player -> player.getDisplayName().equals(name)).findAny();
//
// if (target.isEmpty()) {
// // Not the best option, but Spigot doesn't offer a good replacement (as usual)
//// target = Bukkit.getOfflinePlayer(name);
////
//// return target.hasPlayedBefore() ? target : null;
// return null;
// }
//
// return target.get();
return Universe.get().getPlayerByUsername(name, NameMatching.EXACT);
}
}

View File

@@ -18,14 +18,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.commands.impl.local; package at.helpch.placeholderapi.commands.impl.local;
import java.util.List; import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand; import at.helpch.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.ExpansionSafetyCheck; import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
@@ -33,15 +32,14 @@ public final class CommandReload extends PlaceholderCommand {
public CommandReload() { public CommandReload() {
super("reload"); super("reload");
setPermissions("placeholderapi.admin", "placeholderapi.reload");
} }
@Override @Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias, @NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) { @NotNull @Unmodifiable final List<String> params) {
if (!new ExpansionSafetyCheck(plugin).runChecks()) { plugin.reloadPlugin(sender);
plugin.reloadConf(sender);
}
} }
} }

View File

@@ -0,0 +1,71 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.commands.impl.local;
import java.awt.*;
import java.util.List;
import java.util.stream.Collectors;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand;
import com.hypixel.hytale.common.plugin.AuthorInfo;
import com.hypixel.hytale.common.plugin.PluginManifest;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandVersion extends PlaceholderCommand {
public CommandVersion() {
super("version");
setPermissions("placeholderapi.admin", "placeholderapi.version");
}
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
final PluginManifest description = plugin.getManifest();
sender.sendMessage(Message.empty()
.insert(Message.raw("PlaceholderAPI ").color(Color.CYAN).bold(true))
.insert(Message.raw("(").color(Color.GRAY))
.insert(Message.raw(description.getVersion().toString()).color(Color.WHITE))
.insert(Message.raw(")").color(Color.GRAY))
.insert(Message.raw("\nAuthor: ").color(Color.GRAY))
.insert(Message.raw(description.getAuthors().stream().map(AuthorInfo::getName).collect(Collectors.joining(", "))).color(Color.WHITE))
.insert(Message.raw("\nPAPI Commands: ").color(Color.GRAY))
.insert(Message.raw("/papi ").color(Color.CYAN))
.insert(Message.raw("help").color(Color.WHITE))
.insert(Message.raw("\neCloud Commands: ").color(Color.GRAY))
.insert(Message.raw("/papi ").color(Color.CYAN))
.insert(Message.raw("ecloud").color(Color.WHITE)));
// Msg.msg(sender,
// "&b&lPlaceholderAPI &7(&f" + description.getVersion() + "&7)",
// "&7Author: &f" + description.getAuthors().stream().map(AuthorInfo::getName).collect(Collectors.joining(", ")),
// "&7PAPI Commands: &b/papi &fhelp",
// "&7eCloud Commands&8: &b/papi &fecloud");
}
}

View File

@@ -0,0 +1,6 @@
package at.helpch.placeholderapi.configuration;
import org.jetbrains.annotations.NotNull;
public record BooleanValue(@NotNull String trueValue, @NotNull String falseValue) {
}

View File

@@ -0,0 +1,128 @@
package at.helpch.placeholderapi.configuration;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
public final class ConfigManager {
private static final Yaml YAML;
private static final Gson GSON = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
// .registerTypeAdapter()
private static final Pattern LINE_DELIMITER = Pattern.compile("\n");
static {
final DumperOptions options = new DumperOptions();
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
YAML = new Yaml(options);
}
private final JavaPlugin main;
private final HytaleLogger logger;
private PlaceholderAPIConfig config;
public ConfigManager(@NotNull final JavaPlugin main) {
this.main = main;
this.logger = main.getLogger();
}
public void setup() {
final String content;
try {
final Path file = createFile("/config.yml", main.getDataDirectory().toString() + "/config.yml");
if (file != null) {
content = Files.readString(file);
} else {
return;
}
} catch (Exception e) {
e.printStackTrace();
return;
}
final Map<String, Object> data = YAML.load(content);
config = GSON.fromJson(GSON.toJsonTree(data), PlaceholderAPIConfig.class);
}
public PlaceholderAPIConfig config() {
return config;
}
public void save() {
try {
final Map<String, Object> map = GSON.fromJson(GSON.toJsonTree(config), new TypeToken<Map<String, Object>>(){}.getType());
final String yaml = YAML.dump(map);
final Path path = Paths.get(main.getDataDirectory().toString() + "/config.yml");
Files.write(path, Arrays.asList(LINE_DELIMITER.split(yaml)), StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING);
} catch (Exception e) {
logger.atSevere().log("Something went wrong when saving config.yml: ", e);
}
}
@NotNull
public <T> T convertExpansion(@NotNull final Map<String, Object> expansionConfig, @NotNull final Class<T> type) {
return GSON.fromJson(GSON.toJsonTree(expansionConfig), type);
}
@Nullable
private Path createFile(@NotNull final String internalPath, @NotNull final String externalPath) {
final Path file = Paths.get(externalPath);
if (Files.exists(file)) {
return file;
}
final Optional<Path> parent = Optional.ofNullable(file.getParent());
try {
if (parent.isPresent()) {
Files.createDirectories(parent.get());
}
Files.createFile(file);
} catch (IOException e) {
logger.atSevere().log("Something went wrong when trying to create ", file);
return null;
}
if (exportResource(internalPath, externalPath)) {
return file;
}
return null;
}
private boolean exportResource(@NotNull final String internalPath, @NotNull final String externalPath) {
try {
Files.copy(PlaceholderAPIPlugin.class.getResourceAsStream(internalPath), Paths.get(externalPath),
StandardCopyOption.REPLACE_EXISTING);
return true;
} catch (Exception e) {
logger.atSevere().log("Something went wrong when moving internal: ", internalPath, " to ", externalPath);
}
return false;
}
}

View File

@@ -18,11 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.configuration; package at.helpch.placeholderapi.configuration;
import java.util.Comparator; import java.util.Comparator;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion; import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public enum ExpansionSort implements Comparator<CloudExpansion> { public enum ExpansionSort implements Comparator<CloudExpansion> {

View File

@@ -0,0 +1,107 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.helpch.placeholderapi.configuration;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
public final class PlaceholderAPIConfig {
private boolean cloudEnabled;
private boolean debugMode;
private ExpansionSort cloudSorting;
private BooleanValue booleanValue;
private String dateFormat;
private Map<String, Object> expansions;
public PlaceholderAPIConfig(boolean cloudEnabled, boolean debugMode, @NotNull ExpansionSort cloudSorting,
@NotNull BooleanValue booleanValue, @NotNull String dateFormat) {
this.cloudEnabled = cloudEnabled;
this.debugMode = debugMode;
this.cloudSorting = cloudSorting;
this.booleanValue = booleanValue;
this.dateFormat = dateFormat;
this.expansions = new HashMap<>();
}
public PlaceholderAPIConfig(boolean cloudEnabled, boolean debugMode, @NotNull ExpansionSort cloudSorting,
@NotNull BooleanValue booleanValue, @NotNull String dateFormat, Map<String, Object> expansions) {
this.cloudEnabled = cloudEnabled;
this.debugMode = debugMode;
this.cloudSorting = cloudSorting;
this.booleanValue = booleanValue;
this.dateFormat = dateFormat;
this.expansions = expansions;
}
public boolean cloudEnabled() {
return cloudEnabled;
}
public void cloudEnabled(final boolean value) {
cloudEnabled = value;
}
public boolean debugMode() {
return debugMode;
}
public void debugMode(final boolean value) {
debugMode = value;
}
@NotNull
public ExpansionSort cloudSorting() {
return cloudSorting;
}
public void cloudSorting(@NotNull final ExpansionSort value) {
cloudSorting = value;
}
@NotNull
public BooleanValue booleanValue() {
return booleanValue;
}
public void booleanValue(@NotNull final BooleanValue value) {
booleanValue = value;
}
@NotNull
public String dateFormat() {
return dateFormat;
}
public void dateFormat(@NotNull final String value) {
dateFormat = value;
}
@NotNull
public Map<String, Object> expansions() {
return expansions;
}
public void expansions(@NotNull final Map<String, Object> value) {
expansions = value;
}
}

View File

@@ -18,12 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.events; package at.helpch.placeholderapi.events;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.event.Cancellable; import com.hypixel.hytale.event.ICancellable;
import org.bukkit.event.Event; import com.hypixel.hytale.event.IEvent;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
@@ -31,12 +30,9 @@ import org.jetbrains.annotations.NotNull;
* been registered in PlaceholderAPI. * been registered in PlaceholderAPI.
* *
* <p>To know when <b>all</b> Expansions have been registered, use the * <p>To know when <b>all</b> Expansions have been registered, use the
* {@link me.clip.placeholderapi.events.ExpansionsLoadedEvent ExpansionsLoadedEvent} instead. * {@link at.helpch.placeholderapi.events.ExpansionsLoadedEvent ExpansionsLoadedEvent} instead.
*/ */
public final class ExpansionRegisterEvent extends Event implements Cancellable { public final class ExpansionRegisterEvent implements IEvent<Void>, ICancellable {
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
@NotNull @NotNull
private final PlaceholderExpansion expansion; private final PlaceholderExpansion expansion;
private boolean cancelled; private boolean cancelled;
@@ -45,11 +41,6 @@ public final class ExpansionRegisterEvent extends Event implements Cancellable {
this.expansion = expansion; this.expansion = expansion;
} }
@NotNull
public static HandlerList getHandlerList() {
return HANDLERS;
}
/** /**
* The {@link PlaceholderExpansion PlaceholderExpansion} that was registered in PlaceholderAPI. * The {@link PlaceholderExpansion PlaceholderExpansion} that was registered in PlaceholderAPI.
* <br>The PlaceholderExpansion will be available for use when the event * <br>The PlaceholderExpansion will be available for use when the event
@@ -80,10 +71,4 @@ public final class ExpansionRegisterEvent extends Event implements Cancellable {
this.cancelled = cancelled; this.cancelled = cancelled;
} }
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
} }

View File

@@ -18,11 +18,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.events; package at.helpch.placeholderapi.events;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.event.Event; import com.hypixel.hytale.event.IEvent;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
@@ -34,11 +33,7 @@ import org.jetbrains.annotations.NotNull;
* <br>This includes removing any Listeners, stopping active tasks and clearing the cache of * <br>This includes removing any Listeners, stopping active tasks and clearing the cache of
* the PlaceholderExpansion. * the PlaceholderExpansion.
*/ */
public final class ExpansionUnregisterEvent extends Event { public final class ExpansionUnregisterEvent implements IEvent<ExpansionUnregisterEvent> {
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
@NotNull @NotNull
private final PlaceholderExpansion expansion; private final PlaceholderExpansion expansion;
@@ -46,11 +41,6 @@ public final class ExpansionUnregisterEvent extends Event {
this.expansion = expansion; this.expansion = expansion;
} }
@NotNull
public static HandlerList getHandlerList() {
return HANDLERS;
}
/** /**
* The {@link PlaceholderExpansion PlaceholderExpansion} that was unregistered. * The {@link PlaceholderExpansion PlaceholderExpansion} that was unregistered.
* *
@@ -61,10 +51,4 @@ public final class ExpansionUnregisterEvent extends Event {
return expansion; return expansion;
} }
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
} }

View File

@@ -18,15 +18,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.events; package at.helpch.placeholderapi.events;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.event.Event; import com.hypixel.hytale.event.IEvent;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
@@ -37,7 +36,7 @@ import org.jetbrains.annotations.NotNull;
* <p>All PlaceholderExpansions, except for those loaded by plugins, are loaded * <p>All PlaceholderExpansions, except for those loaded by plugins, are loaded
* after Spigot triggered its ServerLoadEvent (1.13+), or after PlaceholderAPI has been enabled. * after Spigot triggered its ServerLoadEvent (1.13+), or after PlaceholderAPI has been enabled.
*/ */
public class ExpansionsLoadedEvent extends Event { public class ExpansionsLoadedEvent implements IEvent<ExpansionsLoadedEvent> {
private final List<PlaceholderExpansion> expansions; private final List<PlaceholderExpansion> expansions;
@@ -57,18 +56,4 @@ public class ExpansionsLoadedEvent extends Event {
public final List<PlaceholderExpansion> getExpansions() { public final List<PlaceholderExpansion> getExpansions() {
return expansions; return expansions;
} }
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
@NotNull
public static HandlerList getHandlerList() {
return HANDLERS;
}
} }

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.exceptions; package at.helpch.placeholderapi.exceptions;
public final class NoDefaultCommandException extends RuntimeException { public final class NoDefaultCommandException extends RuntimeException {

View File

@@ -18,11 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion; package at.helpch.placeholderapi.expansion;
/** /**
* Classes implementing this interface will have a {@link #clear() clear void} that is called * Classes implementing this interface will have a {@link #clear() clear void} that is called
* by PlaceholderAPI whenever the {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion} * by PlaceholderAPI whenever the {@link at.helpch.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion}
* is unregistered. * is unregistered.
* *
* <p>This allows you to execute things such as clearing internal caches, saving data to files, etc. * <p>This allows you to execute things such as clearing internal caches, saving data to files, etc.

View File

@@ -18,12 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion; package at.helpch.placeholderapi.expansion;
import org.bukkit.entity.Player; import com.hypixel.hytale.server.core.universe.PlayerRef;
/** /**
* Classes implementing this interface will have a {@link #cleanup(Player) cleanup void} that is * Classes implementing this interface will have a {@link #cleanup(PlayerRef) cleanup void} that is
* called by PlaceholderAPI whenever a Player leaves the server. * called by PlaceholderAPI whenever a Player leaves the server.
* *
* <p>This can be useful for cases where you keep data of the player in a cache or similar * <p>This can be useful for cases where you keep data of the player in a cache or similar
@@ -38,5 +38,5 @@ public interface Cleanable {
* *
* @param p (@link Player} who left the server * @param p (@link Player} who left the server
*/ */
void cleanup(Player p); void cleanup(PlayerRef p);
} }

View File

@@ -18,18 +18,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion; package at.helpch.placeholderapi.expansion;
import org.jetbrains.annotations.NotNull;
import java.util.Map; import java.util.Map;
/** /**
* Implementing this interface allows {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansions} * Implementing this interface allows {@link at.helpch.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansions}
* to set a list of default configuration values through the {@link #getDefaults() getDefaults method} * allows you to map an object to a section of yaml in the main config.yml.
* that should be added to the config.yml of PlaceholderAPI.
* *
* <p>The entries will be added under {@code expansions} as their own section. * <p>The entries will be added under {@code expansions} as their own section.
* <h2>Example:</h2> * <h2>Example:</h2>
* returning a Map with key {@code foo} and value {@code bar} will result in the following config entry:
* *
* <pre><code> * <pre><code>
* expansions: * expansions:
@@ -41,17 +41,23 @@ import java.util.Map;
* *
* @author Ryan McCarthy * @author Ryan McCarthy
*/ */
public interface Configurable { public interface Configurable<T> {
/** @NotNull
* The map returned by this method will be used to set config options in PlaceholderAPI's config.yml. Class<T> provideConfigType();
*
* <p>The key and value pairs are set under a section named after your @NotNull
* {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion} in the T provideDefault();
* {@code expansions} section of the config.
* // /**
* @return Map of config path / values which need to be added / removed from the PlaceholderAPI // * The map returned by this method will be used to set config options in PlaceholderAPI's config.yml.
* config.yml file // *
*/ // * <p>The key and value pairs are set under a section named after your
Map<String, Object> getDefaults(); // * {@link at.helpch.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion} in the
// * {@code expansions} section of the config.
// *
// * @return Map of config path / values which need to be added / removed from the PlaceholderAPI
// * config.yml file
// */
// Map<String, Object> getDefaults();
} }

View File

@@ -18,16 +18,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion; package at.helpch.placeholderapi.expansion;
import java.util.Collections; import java.util.*;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.PlaceholderHook; import at.helpch.placeholderapi.PlaceholderHook;
import org.bukkit.Bukkit; import com.hypixel.hytale.component.Ref;
import org.bukkit.configuration.ConfigurationSection; import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.HytaleServer;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.plugin.PluginBase;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -39,11 +44,12 @@ import org.jetbrains.annotations.Nullable;
* class extending this one is located under the {@code PlaceholderAPI/expansions} * class extending this one is located under the {@code PlaceholderAPI/expansions}
* directory or when the {@link #register()} method is called by said class. * directory or when the {@link #register()} method is called by said class.
*/ */
public abstract class PlaceholderExpansion extends PlaceholderHook { public abstract class PlaceholderExpansion implements PlaceholderHook {
private static final Pattern PATH_DELIMITER = Pattern.compile(".");
/** /**
* The type is {@link Type#INTERNAL} by default. * 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}. * For external expansions, the type is updated on {@link at.helpch.placeholderapi.expansion.manager.LocalExpansionManager#register(Class) register}.
* *
* @since 2.11.4 * @since 2.11.4
*/ */
@@ -124,7 +130,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
* @return true if the identifier for this expansion is already registered * @return true if the identifier for this expansion is already registered
*/ */
public final boolean isRegistered() { public final boolean isRegistered() {
return getPlaceholderAPI().getLocalExpansionManager().findExpansionByIdentifier(getIdentifier()) return getPlaceholderAPI().localExpansionManager().findExpansionByIdentifier(getIdentifier())
.map(it -> it.equals(this)).orElse(false); .map(it -> it.equals(this)).orElse(false);
} }
@@ -137,7 +143,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
*/ */
public boolean canRegister() { public boolean canRegister() {
return getRequiredPlugin() == null return getRequiredPlugin() == null
|| Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null; || HytaleServer.get().getPluginManager().getPlugins().stream().map(PluginBase::getName).anyMatch(getRequiredPlugin()::equals);
} }
/** /**
@@ -146,7 +152,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
* @return true if this expansion is now registered with PlaceholderAPI * @return true if this expansion is now registered with PlaceholderAPI
*/ */
public boolean register() { public boolean register() {
return getPlaceholderAPI().getLocalExpansionManager().register(this); return getPlaceholderAPI().localExpansionManager().register(this);
} }
/** /**
@@ -155,7 +161,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
* @return true if this expansion is now unregistered with PlaceholderAPI * @return true if this expansion is now unregistered with PlaceholderAPI
*/ */
public final boolean unregister() { public final boolean unregister() {
return getPlaceholderAPI().getLocalExpansionManager().unregister(this); return getPlaceholderAPI().localExpansionManager().unregister(this);
} }
@@ -166,7 +172,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
*/ */
@NotNull @NotNull
public final PlaceholderAPIPlugin getPlaceholderAPI() { public final PlaceholderAPIPlugin getPlaceholderAPI() {
return PlaceholderAPIPlugin.getInstance(); return PlaceholderAPIPlugin.instance();
} }
/** /**
@@ -193,138 +199,187 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
// === Configuration === // === Configuration ===
/** // /**
* Gets the ConfigurationSection of the expansion located in the config.yml of PlaceholderAPI or // * Gets the ConfigurationSection of the expansion located in the config.yml of PlaceholderAPI or
* null when not specified. // * null when not specified.
* <br>You may use the {@link Configurable} interface to define default values set // * <br>You may use the {@link Configurable} interface to define default values set
* // *
* @return ConfigurationSection that this expansion has. // * @return ConfigurationSection that this expansion has.
*/ // */
// @NotNull
// public final Map<String, Object> getExpansionConfig() {
// return (Map<String, Object>) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), new HashMap<>());
// }
@Nullable @Nullable
public final ConfigurationSection getConfigSection() { public final <T> T getExpansionConfig(@NotNull final Class<? extends Configurable<T>> configurableType) {
return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier()); return (T) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), null);
} }
/** // /**
* Gets the ConfigurationSection relative to the {@link #getConfigSection() default one} set // * Gets the ConfigurationSection relative to the {@link #getConfigSection() default one} set
* by the expansion or null when the default ConfigurationSection is null // * by the expansion or null when the default ConfigurationSection is null
* // *
* @param path The path to get the ConfigurationSection from. This is relative to the default section // * @param path The path to get the ConfigurationSection from. This is relative to the default section
* @return ConfigurationSection relative to the default section // * @return ConfigurationSection relative to the default section
*/ // */
@Nullable // @Nullable
public final ConfigurationSection getConfigSection(@NotNull final String path) { // public final ConfigurationSection getConfigSection(@NotNull final String path) {
final ConfigurationSection section = getConfigSection(); // final ConfigurationSection section = getConfigSection();
return section == null ? null : section.getConfigurationSection(path); // return section == null ? null : section.getConfigurationSection(path);
} // }
/** // /**
* Gets the Object relative to the {@link #getConfigSection() default ConfigurationSection} set // * Gets the Object relative to the config section set
* by the expansion or the provided Default Object, when the default ConfigurationSection is null // * by the expansion or the provided Default Object, when the default ConfigurationSection is null
* // *
* @param path The path to get the Object from. This is relative to the default section // * @param path The path to get the Object from. This is relative to the default section
* @param def The default Object to return when the ConfigurationSection returns null // * @param def The default Object to return when the ConfigurationSection returns null
* @return Object from the provided path or the default one provided // * @return Object from the provided path or the default one provided
*/ // */
@Nullable // @Nullable
@Contract("_, !null -> !null") // @Contract("_, !null -> !null")
public final Object get(@NotNull final String path, final Object def) { // public final Object get(@NotNull final String path, final Object def) {
final ConfigurationSection section = getConfigSection(); // return get(new ArrayDeque<>(Arrays.asList(PATH_DELIMITER.split(path))), def, getExpansionConfig());
return section == null ? def : section.get(path, def); // }
} //
// private Object get(@NotNull final Queue<String> path, final Object def, @NotNull final Map<String, Object> map) {
/** // if (path.size() == 1) {
* Gets the int relative to the {@link #getConfigSection() default ConfigurationSection} set // return map.getOrDefault(path.poll(), def);
* by the expansion or the provided Default int, when the default ConfigurationSection is null // }
* //
* @param path The path to get the int from. This is relative to the default section // Object obj = map.get(path.poll());
* @param def The default int to return when the ConfigurationSection returns null //
* @return int from the provided path or the default one provided // if (!(obj instanceof Map<?, ?>)) {
*/ // return def;
public final int getInt(@NotNull final String path, final int def) { // }
final ConfigurationSection section = getConfigSection(); //
return section == null ? def : section.getInt(path, def); // return get(path, def, (Map<String, Object>) obj);
} // }
//
/** // /**
* Gets the long relative to the {@link #getConfigSection() default ConfigurationSection} set // * Gets the int relative to the config section set
* by the expansion or the provided Default long, when the default ConfigurationSection is null // * by the expansion or the provided Default int, when the default ConfigurationSection is null
* // *
* @param path The path to get the long from. This is relative to the default section // * @param path The path to get the int from. This is relative to the default section
* @param def The default long to return when the ConfigurationSection returns null // * @param def The default int to return when the ConfigurationSection returns null
* @return long from the provided path or the default one provided // * @return int from the provided path or the default one provided
*/ // */
public final long getLong(@NotNull final String path, final long def) { // public final int getInt(@NotNull final String path, final int def) {
final ConfigurationSection section = getConfigSection(); // final Object obj = get(path, def);
return section == null ? def : section.getLong(path, def); //
} // if (!(obj instanceof Integer)) {
// return def;
/** // }
* Gets the double relative to the {@link #getConfigSection() default ConfigurationSection} set //
* by the expansion or the provided Default double, when the default ConfigurationSection is null // return (Integer) obj;
* // }
* @param path The path to get the double from. This is relative to the default section //
* @param def The default double to return when the ConfigurationSection returns null // /**
* @return double from the provided path or the default one provided // * Gets the long relative to the config section set
*/ // * by the expansion or the provided Default long, when the default ConfigurationSection is null
public final double getDouble(@NotNull final String path, final double def) { // *
final ConfigurationSection section = getConfigSection(); // * @param path The path to get the long from. This is relative to the default section
return section == null ? def : section.getDouble(path, def); // * @param def The default long to return when the ConfigurationSection returns null
} // * @return long from the provided path or the default one provided
// */
/** // public final long getLong(@NotNull final String path, final long def) {
* Gets the String relative to the {@link #getConfigSection() default ConfigurationSection} set // final Object obj = get(path, def);
* by the expansion or the provided Default String, when the default ConfigurationSection is null //
* // if (!(obj instanceof Long) ) {
* @param path The path to get the String from. This is relative to the default section // return def;
* @param def The default String to return when the ConfigurationSection returns null. Can be null // }
* @return String from the provided path or the default one provided //
*/ // return (Long) obj;
@Nullable // }
@Contract("_, !null -> !null") //
public final String getString(@NotNull final String path, @Nullable final String def) { // /**
final ConfigurationSection section = getConfigSection(); // * Gets the double relative to the config section set
return section == null ? def : section.getString(path, def); // * by the expansion or the provided Default double, when the default ConfigurationSection is null
} // *
// * @param path The path to get the double from. This is relative to the default section
/** // * @param def The default double to return when the ConfigurationSection returns null
* Gets a String List relative to the {@link #getConfigSection() default ConfigurationSection} set // * @return double from the provided path or the default one provided
* by the expansion or an empty List, when the default ConfigurationSection is null // */
* // public final double getDouble(@NotNull final String path, final double def) {
* @param path The path to get the String list from. This is relative to the default section // final Object obj = get(path, def);
* @return String list from the provided path or an empty list //
*/ // if (!(obj instanceof Double) ) {
@NotNull // return def;
public final List<String> getStringList(@NotNull final String path) { // }
final ConfigurationSection section = getConfigSection(); //
return section == null ? Collections.emptyList() : section.getStringList(path); // return (Double) obj;
} // }
//
/** // /**
* Gets the boolean relative to the {@link #getConfigSection() default ConfigurationSection} set // * Gets the String relative to the config section set
* by the expansion or the default boolean, when the default ConfigurationSection is null // * by the expansion or the provided Default String, when the default ConfigurationSection is null
* // *
* @param path The path to get the boolean from. This is relative to the default section // * @param path The path to get the String from. This is relative to the default section
* @param def The default boolean to return when the ConfigurationSection is null // * @param def The default String to return when the ConfigurationSection returns null. Can be null
* @return boolean from the provided path or the default one provided // * @return String from the provided path or the default one provided
*/ // */
public final boolean getBoolean(@NotNull final String path, final boolean def) { // @Nullable
final ConfigurationSection section = getConfigSection(); // @Contract("_, !null -> !null")
return section == null ? def : section.getBoolean(path, def); // public final String getString(@NotNull final String path, @Nullable final String def) {
} // final Object obj = get(path, def);
//
/** // if (!(obj instanceof String)) {
* Whether the {@link #getConfigSection() default ConfigurationSection} contains the provided path // return def;
* or not. This will return {@code false} when either the default section is null, or doesn't // }
* contain the provided path //
* // return (String) obj;
* @param path The path to check // }
* @return true when the default ConfigurationSection is not null and contains the path, false otherwise //
*/ // /**
public final boolean configurationContains(@NotNull final String path) { // * Gets a String List relative to the config section set
final ConfigurationSection section = getConfigSection(); // * by the expansion or an empty List, when the default ConfigurationSection is null
return section != null && section.contains(path); // *
} // * @param path The path to get the String list from. This is relative to the default section
// * @return String list from the provided path or an empty list
// */
// @NotNull
// public final List<String> getStringList(@NotNull final String path) {
// final Object obj = get(path, new ArrayList<>());
//
// if (!(obj instanceof List<?>)) {
// return new ArrayList<>();
// }
//
// return (List<String>) obj;
// }
//
// /**
// * Gets the boolean relative to the config section set
// * by the expansion or the default boolean, when the default ConfigurationSection is null
// *
// * @param path The path to get the boolean from. This is relative to the default section
// * @param def The default boolean to return when the ConfigurationSection is null
// * @return boolean from the provided path or the default one provided
// */
// public final boolean getBoolean(@NotNull final String path, final boolean def) {
// final Object obj = get(path, def);
//
// if (!(obj instanceof Boolean)) {
// return def;
// }
//
// return (Boolean) obj;
// }
//
// /**
// * Whether the config section contains the provided path
// * or not. This will return {@code false} when either the default section is null, or doesn't
// * contain the provided path
// *
// * @param path The path to check
// * @return true when the default ConfigurationSection is not null and contains the path, false otherwise
// */
// public final boolean configurationContains(@NotNull final String path) {
// final Object obj = get(path, null);
//
// return obj == null;
// }
/** /**
* Logs the provided message with the provided Level in the console. * Logs the provided message with the provided Level in the console.
@@ -334,7 +389,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
* @param msg The message to log * @param msg The message to log
*/ */
public void log(Level level, String msg) { public void log(Level level, String msg) {
getPlaceholderAPI().getLogger().log(level, "[" + getName() + "] " + msg); getPlaceholderAPI().getLogger().at(level).log("[" + getName() + "] " + msg);
} }
/** /**
@@ -346,7 +401,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
* @param throwable The Throwable to log * @param throwable The Throwable to log
*/ */
public void log(Level level, String msg, Throwable throwable) { public void log(Level level, String msg, Throwable throwable) {
getPlaceholderAPI().getLogger().log(level, "[" + getName() + "] " + msg, throwable); getPlaceholderAPI().getLogger().at(level).log("[" + getName() + "] " + msg, throwable);
} }
/** /**
@@ -476,4 +531,16 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
} }
@Nullable
public static Player player(@NotNull final PlayerRef target) {
final Ref<EntityStore> ref = target.getReference();
if (ref == null || !ref.isValid()) {
return null;
}
final Store<EntityStore> store = ref.getStore();
return store.isInThread() ? store.getComponent(ref, Player.getComponentType()) : null;
}
} }

View File

@@ -18,12 +18,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion; package at.helpch.placeholderapi.expansion;
import org.bukkit.entity.Player; import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.PlayerRef;
/** /**
* Implementing this interface allows your {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion} * Implementing this interface allows your {@link at.helpch.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion}
* to be used as a relational placeholder expansion. * to be used as a relational placeholder expansion.
* *
* <p>Relational placeholders take two Players as input and are always prefixed with {@code rel_}, * <p>Relational placeholders take two Players as input and are always prefixed with {@code rel_},
@@ -39,5 +40,5 @@ public interface Relational {
* @param identifier The text right after the expansion's name (%expansion_<b>identifier</b>%) * @param identifier The text right after the expansion's name (%expansion_<b>identifier</b>%)
* @return Parsed String from the expansion. * @return Parsed String from the expansion.
*/ */
String onPlaceholderRequest(Player one, Player two, String identifier); String onPlaceholderRequest(PlayerRef one, PlayerRef two, String identifier);
} }

View File

@@ -18,11 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion; package at.helpch.placeholderapi.expansion;
/** /**
* Implementing this interface adds the {@link #start() start} and {@link #stop() stop} void * Implementing this interface adds the {@link #start() start} and {@link #stop() stop} void
* methods to your {@link me.clip.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion}. * methods to your {@link at.helpch.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion}.
* *
* <p>This can be used to execute methods and tasks whenever the PlaceholderExpansion has been * <p>This can be used to execute methods and tasks whenever the PlaceholderExpansion has been
* successfully (un)registered. * successfully (un)registered.

View File

@@ -18,13 +18,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion.cloud; package at.helpch.placeholderapi.expansion.cloud;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.clip.placeholderapi.util.TimeUtil; import at.helpch.placeholderapi.util.TimeUtil;
public class CloudExpansion { public class CloudExpansion {

View File

@@ -18,19 +18,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion.manager; package at.helpch.placeholderapi.expansion.manager;
import com.google.common.collect.ImmutableMap; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import com.google.common.io.Resources;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.io.File; import java.io.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -42,27 +41,23 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.*;
import java.util.concurrent.CompletionException; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function; import java.util.function.Function;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collector; import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion; import com.hypixel.hytale.logger.HytaleLogger;
import me.clip.placeholderapi.util.Msg;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
public final class CloudExpansionManager { public final class CloudExpansionManager {
@NotNull @NotNull
private static final String API_URL = "https://ecloud.placeholderapi.com/api/v3/"; private static final String API_URL = "https://ecloud.placeholderapi.com/api/v3/?platform=hytale";
@NotNull @NotNull
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
@@ -76,6 +71,7 @@ public final class CloudExpansionManager {
@NotNull @NotNull
private final PlaceholderAPIPlugin plugin; private final PlaceholderAPIPlugin plugin;
private final HytaleLogger logger;
@NotNull @NotNull
private final Map<String, CloudExpansion> cache = new HashMap<>(); private final Map<String, CloudExpansion> cache = new HashMap<>();
@@ -83,11 +79,11 @@ public final class CloudExpansionManager {
private final Map<String, CompletableFuture<File>> await = new ConcurrentHashMap<>(); private final Map<String, CompletableFuture<File>> await = new ConcurrentHashMap<>();
private final ExecutorService ASYNC_EXECUTOR = private final ExecutorService ASYNC_EXECUTOR =
Executors.newCachedThreadPool( Executors.newCachedThreadPool(new LoggingThreadFactory("placeholderapi-io-#%1$d"));
new ThreadFactoryBuilder().setNameFormat("placeholderapi-io-#%1$d").build());
public CloudExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) { public CloudExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.logger = plugin.getLogger();
} }
@NotNull @NotNull
@@ -112,7 +108,11 @@ public final class CloudExpansionManager {
@NotNull @NotNull
@Unmodifiable @Unmodifiable
public Map<String, CloudExpansion> getCloudExpansions() { public Map<String, CloudExpansion> getCloudExpansions() {
return ImmutableMap.copyOf(cache); return Map.copyOf(cache);
}
public boolean isEmpty() {
return cache.isEmpty();
} }
@NotNull @NotNull
@@ -152,7 +152,7 @@ public final class CloudExpansionManager {
} }
public int getCloudUpdateCount() { public int getCloudUpdateCount() {
return ((int) plugin.getLocalExpansionManager() return ((int) plugin.localExpansionManager()
.getExpansions() .getExpansions()
.stream() .stream()
.filter(expansion -> findCloudExpansionByName(expansion.getName()) .filter(expansion -> findCloudExpansionByName(expansion.getName())
@@ -173,15 +173,24 @@ public final class CloudExpansionManager {
} }
public void fetch() { public void fetch() {
plugin.getLogger().info("Fetching available expansion information..."); logger.at(Level.INFO).log("Fetching available expansion information...");
ASYNC_EXECUTOR.submit( ASYNC_EXECUTOR.submit(
() -> { () -> {
// a defence tactic! use ConcurrentHashMap instead of normal HashMap // a defence tactic! use ConcurrentHashMap instead of normal HashMap
Map<String, CloudExpansion> values = new ConcurrentHashMap<>(); Map<String, CloudExpansion> values = new ConcurrentHashMap<>();
try { try {
final URI uri = new URI(API_URL);
final URLConnection connection = uri.toURL().openConnection();
final String json;
try (final InputStream input = connection.getInputStream()) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
json = reader.lines().collect(Collectors.joining(System.lineSeparator()));
}
//noinspection UnstableApiUsage //noinspection UnstableApiUsage
String json = Resources.toString(new URL(API_URL), StandardCharsets.UTF_8); // String json = Resources.toString(new URL(API_URL), StandardCharsets.UTF_8);
values.putAll(GSON.fromJson(json, TYPE)); values.putAll(GSON.fromJson(json, TYPE));
List<String> toRemove = new ArrayList<>(); List<String> toRemove = new ArrayList<>();
@@ -197,15 +206,17 @@ public final class CloudExpansionManager {
for (String name : toRemove) { for (String name : toRemove) {
values.remove(name); values.remove(name);
} }
} catch (UnknownHostException e) {
logger.atWarning().log("There is no data available from the eCloud. Please try running /papi refresh. If this does not resolve the issue, the eCloud may be blocked by your firewall, server host, or service provider.\n\nMore information: https://placeholderapi.com/ecloud-blocked", e);
} catch (Throwable e) { } catch (Throwable e) {
// ugly swallowing of every throwable, but we have to be defensive // ugly swallowing of every throwable, but we have to be defensive
plugin.getLogger().log(Level.WARNING, "Failed to download expansion information", e); logger.atWarning().log("Failed to download expansion information", e);
} }
// loop through what's left on the main thread // loop through what's left on the main thread
plugin plugin
.getScheduler() .getTaskRegistry()
.runTask( .registerTask(CompletableFuture.runAsync(
() -> { () -> {
try { try {
for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) { for (Map.Entry<String, CloudExpansion> entry : values.entrySet()) {
@@ -215,7 +226,7 @@ public final class CloudExpansionManager {
expansion.setName(name); expansion.setName(name);
Optional<PlaceholderExpansion> localOpt = Optional<PlaceholderExpansion> localOpt =
plugin.getLocalExpansionManager().findExpansionByName(name); plugin.localExpansionManager().findExpansionByName(name);
if (localOpt.isPresent()) { if (localOpt.isPresent()) {
PlaceholderExpansion local = localOpt.get(); PlaceholderExpansion local = localOpt.get();
if (local.isRegistered()) { if (local.isRegistered()) {
@@ -229,18 +240,18 @@ public final class CloudExpansionManager {
} }
} catch (Throwable e) { } catch (Throwable e) {
// ugly swallowing of every throwable, but we have to be defensive // ugly swallowing of every throwable, but we have to be defensive
plugin logger.atWarning().log("Failed to download expansion information", e);
.getLogger()
.log(Level.WARNING, "Failed to download expansion information", e);
} }
}); }));
}); });
} }
/*
public boolean isDownloading(@NotNull final CloudExpansion expansion) { public boolean isDownloading(@NotNull final CloudExpansion expansion) {
return await.containsKey(toIndexName(expansion)); return await.containsKey(toIndexName(expansion));
} }
@NotNull @NotNull
public CompletableFuture<File> downloadExpansion(@NotNull final CloudExpansion expansion, public CompletableFuture<File> downloadExpansion(@NotNull final CloudExpansion expansion,
@NotNull final CloudExpansion.Version version) { @NotNull final CloudExpansion.Version version) {
@@ -249,7 +260,7 @@ public final class CloudExpansionManager {
return previous; return previous;
} }
final File file = new File(plugin.getLocalExpansionManager().getExpansionsFolder(), final File file = new File(plugin.localExpansionManager().getExpansionsFolder(),
"Expansion-" + toIndexName(expansion) + ".jar"); "Expansion-" + toIndexName(expansion) + ".jar");
final CompletableFuture<File> download = CompletableFuture.supplyAsync(() -> { final CompletableFuture<File> download = CompletableFuture.supplyAsync(() -> {
@@ -266,13 +277,29 @@ public final class CloudExpansionManager {
await.remove(toIndexName(expansion)); await.remove(toIndexName(expansion));
if (exception != null) { if (exception != null) {
Msg.severe("Failed to download %s:%s", exception, expansion.getName(), expansion.getVersion()); logger.atSevere().log("Failed to download %s:%s %s", expansion.getName(), expansion.getVersion(), exception);
} }
}, ASYNC_EXECUTOR); }, ASYNC_EXECUTOR);
await.put(toIndexName(expansion), download); await.put(toIndexName(expansion), download);
return download; return download;
} */
private static final class LoggingThreadFactory implements ThreadFactory {
private final ThreadFactory backing = Executors.defaultThreadFactory();
private final String format;
private final AtomicLong count = new AtomicLong(0);
private LoggingThreadFactory(@NotNull final String format) {
this.format = format;
} }
@Override
public Thread newThread(@NotNull final Runnable r) {
final Thread thread = backing.newThread(r);
thread.setName(String.format(format, count.getAndIncrement()));
return thread;
}
}
} }

View File

@@ -18,57 +18,48 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion.manager; package at.helpch.placeholderapi.expansion.manager;
import com.google.common.collect.ImmutableSet; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import com.google.common.collect.Sets;
import java.awt.*;
import java.io.File; import java.io.File;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.configuration.ConfigManager;
import me.clip.placeholderapi.events.ExpansionRegisterEvent; import at.helpch.placeholderapi.configuration.PlaceholderAPIConfig;
import me.clip.placeholderapi.events.ExpansionUnregisterEvent; import at.helpch.placeholderapi.events.ExpansionRegisterEvent;
import me.clip.placeholderapi.events.ExpansionsLoadedEvent; import at.helpch.placeholderapi.events.ExpansionUnregisterEvent;
import me.clip.placeholderapi.expansion.Cacheable; import at.helpch.placeholderapi.events.ExpansionsLoadedEvent;
import me.clip.placeholderapi.expansion.Cleanable; import at.helpch.placeholderapi.expansion.Cacheable;
import me.clip.placeholderapi.expansion.Configurable; import at.helpch.placeholderapi.expansion.Cleanable;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.Configurable;
import me.clip.placeholderapi.expansion.Taskable; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.VersionSpecific; import at.helpch.placeholderapi.expansion.Taskable;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion; import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import me.clip.placeholderapi.util.FileUtil; import at.helpch.placeholderapi.util.FileUtil;
import me.clip.placeholderapi.util.Futures; import at.helpch.placeholderapi.util.Futures;
import me.clip.placeholderapi.util.Msg; import com.hypixel.hytale.common.plugin.PluginIdentifier;
import org.bukkit.Bukkit; import com.hypixel.hytale.event.IEventDispatcher;
import org.bukkit.command.CommandSender; import com.hypixel.hytale.logger.HytaleLogger;
import org.bukkit.configuration.file.FileConfiguration; import com.hypixel.hytale.server.core.HytaleServer;
import org.bukkit.event.EventHandler; import com.hypixel.hytale.server.core.Message;
import org.bukkit.event.EventPriority; import com.hypixel.hytale.server.core.command.system.CommandSender;
import org.bukkit.event.HandlerList; import com.hypixel.hytale.server.core.event.events.player.PlayerDisconnectEvent;
import org.bukkit.event.Listener; import com.hypixel.hytale.server.core.plugin.PluginBase;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
public final class LocalExpansionManager implements Listener { public final class LocalExpansionManager /*implements Listener*/ {
@NotNull @NotNull
private static final String EXPANSIONS_FOLDER_NAME = "expansions"; private static final String EXPANSIONS_FOLDER_NAME = "expansions";
@@ -83,6 +74,8 @@ public final class LocalExpansionManager implements Listener {
private final File folder; private final File folder;
@NotNull @NotNull
private final PlaceholderAPIPlugin plugin; private final PlaceholderAPIPlugin plugin;
private final HytaleLogger logger;
private final ConfigManager configManager;
@NotNull @NotNull
private final Map<String, PlaceholderExpansion> expansions = new ConcurrentHashMap<>(); private final Map<String, PlaceholderExpansion> expansions = new ConcurrentHashMap<>();
@@ -91,10 +84,12 @@ public final class LocalExpansionManager implements Listener {
public LocalExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) { public LocalExpansionManager(@NotNull final PlaceholderAPIPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.folder = new File(plugin.getDataFolder(), EXPANSIONS_FOLDER_NAME); this.folder = new File(plugin.getDataDirectory().toString(), EXPANSIONS_FOLDER_NAME);
this.logger = plugin.getLogger();
this.configManager = plugin.configManager();
if (!this.folder.exists() && !folder.mkdirs()) { if (!this.folder.exists() && !folder.mkdirs()) {
Msg.warn("Failed to create expansions folder!"); logger.atWarning().log("Failed to create expansions folder!");
} }
} }
@@ -117,7 +112,7 @@ public final class LocalExpansionManager implements Listener {
public Collection<String> getIdentifiers() { public Collection<String> getIdentifiers() {
expansionsLock.lock(); expansionsLock.lock();
try { try {
return ImmutableSet.copyOf(expansions.keySet()); return Set.copyOf(expansions.keySet());
} finally { } finally {
expansionsLock.unlock(); expansionsLock.unlock();
} }
@@ -128,7 +123,7 @@ public final class LocalExpansionManager implements Listener {
public Collection<PlaceholderExpansion> getExpansions() { public Collection<PlaceholderExpansion> getExpansions() {
expansionsLock.lock(); expansionsLock.lock();
try { try {
return ImmutableSet.copyOf(expansions.values()); return Set.copyOf(expansions.values());
} finally { } finally {
expansionsLock.unlock(); expansionsLock.unlock();
} }
@@ -183,8 +178,8 @@ public final class LocalExpansionManager implements Listener {
Objects.requireNonNull(expansion.getVersion(), "The expansion version is null!"); Objects.requireNonNull(expansion.getVersion(), "The expansion version is null!");
if (expansion.getRequiredPlugin() != null && !expansion.getRequiredPlugin().isEmpty()) { if (expansion.getRequiredPlugin() != null && !expansion.getRequiredPlugin().isEmpty()) {
if (!Bukkit.getPluginManager().isPluginEnabled(expansion.getRequiredPlugin())) { if (HytaleServer.get().getPluginManager().getPlugin(PluginIdentifier.fromString(expansion.getRequiredPlugin())) == null) {
Msg.warn("Cannot load expansion %s due to a missing plugin: %s", expansion.getIdentifier(), logger.atWarning().log("Cannot load expansion %s due to a missing plugin: %s", expansion.getIdentifier(),
expansion.getRequiredPlugin()); expansion.getRequiredPlugin());
return Optional.empty(); return Optional.empty();
} }
@@ -193,7 +188,7 @@ public final class LocalExpansionManager implements Listener {
expansion.setExpansionType(PlaceholderExpansion.Type.EXTERNAL); expansion.setExpansionType(PlaceholderExpansion.Type.EXTERNAL);
if (!expansion.register()) { if (!expansion.register()) {
Msg.warn("Cannot load expansion %s due to an unknown issue.", expansion.getIdentifier()); logger.atWarning().log("Cannot load expansion %s due to an unknown issue.", expansion.getIdentifier());
return Optional.empty(); return Optional.empty();
} }
@@ -207,7 +202,7 @@ public final class LocalExpansionManager implements Listener {
reason = " - One of its properties is null which is not allowed!"; reason = " - One of its properties is null which is not allowed!";
} }
Msg.severe("Failed to load expansion class %s%s", ex, clazz.getSimpleName(), reason); logger.atSevere().log("Failed to load expansion class %s%s", ex, clazz.getSimpleName(), reason);
} }
return Optional.empty(); return Optional.empty();
@@ -229,50 +224,64 @@ public final class LocalExpansionManager implements Listener {
// Avoid loading two external expansions with the same identifier // Avoid loading two external expansions with the same identifier
if (expansion.getExpansionType() == PlaceholderExpansion.Type.EXTERNAL && expansions.containsKey(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()); logger.atWarning().log("Failed to load external expansion %s. Identifier is already in use.", expansion.getIdentifier());
return false; return false;
} }
if (expansion instanceof Configurable) { if (expansion instanceof Configurable<?> configurable) {
Map<String, Object> defaults = ((Configurable) expansion).getDefaults(); final PlaceholderAPIConfig config = configManager.config();
String pre = "expansions." + identifier + ".";
FileConfiguration cfg = plugin.getConfig();
boolean save = false;
if (defaults != null) { if (config.expansions() == null) {
for (Map.Entry<String, Object> entries : defaults.entrySet()) { config.expansions(new HashMap<>());
if (entries.getKey() == null || entries.getKey().isEmpty()) {
continue;
} }
if (entries.getValue() == null) { if (!config.expansions().containsKey(expansion.getIdentifier())) {
if (cfg.contains(pre + entries.getKey())) { config.expansions().put(expansion.getIdentifier(), configurable.provideDefault());
save = true; configManager.save();
cfg.set(pre + entries.getKey(), null);
}
} else { } else {
if (!cfg.contains(pre + entries.getKey())) { final Object expansionConfig = configManager.convertExpansion((Map<String, Object>) config.expansions().get(expansion.getIdentifier()), configurable.provideConfigType());
save = true; config.expansions().put(expansion.getIdentifier(), expansionConfig);
cfg.set(pre + entries.getKey(), entries.getValue());
}
}
} }
// Map<String, Object> defaults = ((Configurable<?>) expansion).getDefaults();
// String pre = "expansions." + identifier + ".";
// boolean save = false;
//
// final PlaceholderAPIConfig config = this.config.config();
//
// if (defaults != null) {
// for (Map.Entry<String, Object> entries : defaults.entrySet()) {
// if (entries.getKey() == null || entries.getKey().isEmpty()) {
// continue;
// }
//
// if (entries.getValue() == null) {
// if (cfg.contains(pre + entries.getKey())) {
// save = true;
// cfg.set(pre + entries.getKey(), null);
// }
// } else {
// if (!cfg.contains(pre + entries.getKey())) {
// save = true;
// cfg.set(pre + entries.getKey(), entries.getValue());
// }
// }
// }
// }
//
// if (save) {
// plugin.saveConfig();
// plugin.reloadConfig();
// }
} }
if (save) { // if (expansion instanceof VersionSpecific) {
plugin.saveConfig(); // VersionSpecific nms = (VersionSpecific) expansion;
plugin.reloadConfig(); // if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
} // Msg.warn("Your server version is incompatible with expansion %s %s",
} // expansion.getIdentifier(), expansion.getVersion());
// return false;
if (expansion instanceof VersionSpecific) { // }
VersionSpecific nms = (VersionSpecific) expansion; // }
if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
Msg.warn("Your server version is incompatible with expansion %s %s",
expansion.getIdentifier(), expansion.getVersion());
return false;
}
}
final PlaceholderExpansion removed = getExpansion(identifier); final PlaceholderExpansion removed = getExpansion(identifier);
if (removed != null && !removed.unregister()) { if (removed != null && !removed.unregister()) {
@@ -280,7 +289,12 @@ public final class LocalExpansionManager implements Listener {
} }
final ExpansionRegisterEvent event = new ExpansionRegisterEvent(expansion); final ExpansionRegisterEvent event = new ExpansionRegisterEvent(expansion);
Bukkit.getPluginManager().callEvent(event); final IEventDispatcher<ExpansionRegisterEvent, ExpansionRegisterEvent> eventDispatcher = HytaleServer.get().getEventBus().dispatchFor(ExpansionRegisterEvent.class);
if (eventDispatcher.hasListener()) {
eventDispatcher.dispatch(event);
}
// Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return false; return false;
@@ -293,11 +307,11 @@ public final class LocalExpansionManager implements Listener {
expansionsLock.unlock(); expansionsLock.unlock();
} }
if (expansion instanceof Listener) { // if (expansion instanceof Listener) {
Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin); // Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin);
} // }
Msg.info( logger.at(Level.INFO).log(
"Successfully registered %s expansion: %s [%s]", "Successfully registered %s expansion: %s [%s]",
expansion.getExpansionType().name().toLowerCase(), expansion.getExpansionType().name().toLowerCase(),
expansion.getIdentifier(), expansion.getIdentifier(),
@@ -309,8 +323,8 @@ public final class LocalExpansionManager implements Listener {
} }
// Check eCloud for updates only if the expansion is external // Check eCloud for updates only if the expansion is external
if (plugin.getPlaceholderAPIConfig().isCloudEnabled() && expansion.getExpansionType() == PlaceholderExpansion.Type.EXTERNAL) { if (configManager.config().cloudEnabled() && expansion.getExpansionType() == PlaceholderExpansion.Type.EXTERNAL) {
final Optional<CloudExpansion> cloudExpansionOptional = plugin.getCloudExpansionManager().findCloudExpansionByName(identifier); final Optional<CloudExpansion> cloudExpansionOptional = plugin.cloudExpansionManager().findCloudExpansionByName(identifier);
if (cloudExpansionOptional.isPresent()) { if (cloudExpansionOptional.isPresent()) {
CloudExpansion cloudExpansion = cloudExpansionOptional.get(); CloudExpansion cloudExpansion = cloudExpansionOptional.get();
cloudExpansion.setHasExpansion(true); cloudExpansion.setHasExpansion(true);
@@ -327,12 +341,15 @@ public final class LocalExpansionManager implements Listener {
return false; return false;
} }
Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(expansion)); final IEventDispatcher<ExpansionUnregisterEvent, ExpansionUnregisterEvent> eventDispatcher = HytaleServer.get().getEventBus().dispatchFor(ExpansionUnregisterEvent.class);
if (eventDispatcher.hasListener()) {
if (expansion instanceof Listener) { eventDispatcher.dispatch(new ExpansionUnregisterEvent(expansion));
HandlerList.unregisterAll((Listener) expansion);
} }
// if (expansion instanceof Listener) {
// HandlerList.unregisterAll((Listener) expansion);
// }
if (expansion instanceof Taskable) { if (expansion instanceof Taskable) {
((Taskable) expansion).stop(); ((Taskable) expansion).stop();
} }
@@ -341,8 +358,8 @@ public final class LocalExpansionManager implements Listener {
((Cacheable) expansion).clear(); ((Cacheable) expansion).clear();
} }
if (plugin.getPlaceholderAPIConfig().isCloudEnabled()) { if (configManager.config().cloudEnabled()) {
plugin.getCloudExpansionManager().findCloudExpansionByName(expansion.getName()) plugin.cloudExpansionManager().findCloudExpansionByName(expansion.getName())
.ifPresent(cloud -> { .ifPresent(cloud -> {
cloud.setHasExpansion(false); cloud.setHasExpansion(false);
cloud.setShouldUpdate(false); cloud.setShouldUpdate(false);
@@ -353,11 +370,11 @@ public final class LocalExpansionManager implements Listener {
} }
private void registerAll(@NotNull final CommandSender sender) { private void registerAll(@NotNull final CommandSender sender) {
Msg.info("Placeholder expansion registration initializing..."); logger.at(Level.INFO).log("Placeholder expansion registration initializing...");
Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> { Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> {
if (exception != null) { if (exception != null) {
Msg.severe("Failed to load class files of expansion.", exception); logger.atSevere().log("Failed to load class files of expansion.", exception);
return; return;
} }
@@ -369,33 +386,30 @@ public final class LocalExpansionManager implements Listener {
.collect(Collectors.toList()); .collect(Collectors.toList());
final long needsUpdate = registered.stream() final long needsUpdate = registered.stream()
.map(expansion -> plugin.getCloudExpansionManager().findCloudExpansionByName(expansion.getName()).orElse(null)) .map(expansion -> plugin.cloudExpansionManager().findCloudExpansionByName(expansion.getName()).orElse(null))
.filter(Objects::nonNull) .filter(Objects::nonNull)
.filter(CloudExpansion::shouldUpdate) .filter(CloudExpansion::shouldUpdate)
.count(); .count();
Message message = Message.raw(registered.size() + "").color(registered.isEmpty() ? Color.YELLOW : Color.GREEN)
StringBuilder message = new StringBuilder(registered.size() == 0 ? "&6" : "&a") .insert(" placeholder hook(s) registered!");
.append(registered.size())
.append(' ')
.append("placeholder hook(s) registered!");
if (needsUpdate > 0) { if (needsUpdate > 0) {
message.append(' ') message = message.insert(" ")
.append("&6") .insert(Message.raw(needsUpdate + " placeholder hook(s) have an update available.").color(Color.YELLOW));
.append(needsUpdate)
.append(' ')
.append("placeholder hook(s) have an update available.");
} }
// logger.at(Level.INFO).log(message.toString());
sender.sendMessage(message);
Msg.msg(sender, message.toString()); final IEventDispatcher<ExpansionsLoadedEvent, ExpansionsLoadedEvent> eventDispatcher = HytaleServer.get().getEventBus().dispatchFor(ExpansionsLoadedEvent.class);
if (eventDispatcher.hasListener()) {
Bukkit.getPluginManager().callEvent(new ExpansionsLoadedEvent(registered)); eventDispatcher.dispatch(new ExpansionsLoadedEvent(registered));
}
}); });
} }
private void unregisterAll() { private void unregisterAll() {
for (final PlaceholderExpansion expansion : Sets.newHashSet(expansions.values())) { for (final PlaceholderExpansion expansion : new HashSet<>(expansions.values())) {
if (expansion.persist()) { if (expansion.persist()) {
continue; continue;
} }
@@ -424,7 +438,7 @@ public final class LocalExpansionManager implements Listener {
final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class); final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class);
if (expansionClass == null) { if (expansionClass == null) {
Msg.severe("Failed to load expansion %s, as it does not have a class which" logger.atSevere().log("Failed to load expansion %s, as it does not have a class which"
+ " extends PlaceholderExpansion", file.getName()); + " extends PlaceholderExpansion", file.getName());
return null; return null;
} }
@@ -433,17 +447,17 @@ public final class LocalExpansionManager implements Listener {
.map(method -> new MethodSignature(method.getName(), method.getParameterTypes())) .map(method -> new MethodSignature(method.getName(), method.getParameterTypes()))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
if (!expansionMethods.containsAll(ABSTRACT_EXPANSION_METHODS)) { if (!expansionMethods.containsAll(ABSTRACT_EXPANSION_METHODS)) {
Msg.severe("Failed to load expansion %s, as it does not have the required" logger.atSevere().log("Failed to load expansion %s, as it does not have the required"
+ " methods declared for a PlaceholderExpansion.", file.getName()); + " methods declared for a PlaceholderExpansion.", file.getName());
return null; return null;
} }
return expansionClass; return expansionClass;
} catch (VerifyError | NoClassDefFoundError e) { } catch (VerifyError | NoClassDefFoundError e) {
Msg.severe("Failed to load expansion %s (is a dependency missing?)", e, file.getName()); logger.atSevere().log("Failed to load expansion %s (is a dependency missing?)", e, file.getName());
return null; return null;
} catch (Exception e) { } catch (Exception e) {
plugin.getLogger().log(Level.SEVERE, "Failed to load expansion file: " + file.getAbsolutePath(), e); logger.atSevere().log("Failed to load expansion file: " + file.getAbsolutePath(), e);
return null; return null;
} }
}); });
@@ -460,39 +474,38 @@ public final class LocalExpansionManager implements Listener {
throw ((LinkageError) ex.getCause()); throw ((LinkageError) ex.getCause());
} }
Msg.warn("There was an issue with loading an expansion."); logger.atWarning().log("There was an issue with loading an expansion.");
return null; return null;
} }
} }
public void onQuit(@NotNull final PlayerDisconnectEvent event) {
@EventHandler
public void onQuit(@NotNull final PlayerQuitEvent event) {
for (final PlaceholderExpansion expansion : getExpansions()) { for (final PlaceholderExpansion expansion : getExpansions()) {
if (!(expansion instanceof Cleanable)) { if (!(expansion instanceof Cleanable)) {
continue; continue;
} }
((Cleanable) expansion).cleanup(event.getPlayer()); ((Cleanable) expansion).cleanup(event.getPlayerRef());
} }
} }
@EventHandler(priority = EventPriority.HIGH) // @EventHandler(priority = EventPriority.HIGH)
public void onPluginDisable(@NotNull final PluginDisableEvent event) { //todo: hytale has no plugin disable event as of yet :(
final String name = event.getPlugin().getName(); // public void onPluginDisable() {
if (name.equals(plugin.getName())) { // final String name = event.getPlugin().getName();
return; // if (name.equals(plugin.getName())) {
} // return;
// }
for (final PlaceholderExpansion expansion : getExpansions()) { //
if (!name.equalsIgnoreCase(expansion.getRequiredPlugin())) { // for (final PlaceholderExpansion expansion : getExpansions()) {
continue; // if (!name.equalsIgnoreCase(expansion.getRequiredPlugin())) {
} // continue;
// }
expansion.unregister(); //
Msg.info("Unregistered placeholder expansion %s", expansion.getIdentifier()); // expansion.unregister();
Msg.info("Reason: required plugin %s was disabled.", name); // Msg.info("Unregistered placeholder expansion %s", expansion.getIdentifier());
} // Msg.info("Reason: required plugin %s was disabled.", name);
} // }
// }
} }

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.expansion.manager; package at.helpch.placeholderapi.expansion.manager;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;

View File

@@ -18,14 +18,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.replacer; package at.helpch.placeholderapi.replacer;
import java.util.Locale; import java.util.Locale;
import java.util.function.Function; import java.util.function.Function;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.ChatColor; import com.hypixel.hytale.server.core.entity.entities.Player;
import org.bukkit.OfflinePlayer; import com.hypixel.hytale.server.core.universe.PlayerRef;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -41,7 +41,7 @@ public final class CharsReplacer implements Replacer {
@NotNull @NotNull
@Override @Override
public String apply(@NotNull final String text, @Nullable final OfflinePlayer player, public String apply(@NotNull final String text, @Nullable final PlayerRef player,
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup) { @NotNull final Function<String, @Nullable PlaceholderExpansion> lookup) {
final char[] chars = text.toCharArray(); final char[] chars = text.toCharArray();
final StringBuilder builder = new StringBuilder(text.length()); final StringBuilder builder = new StringBuilder(text.length());
@@ -117,7 +117,7 @@ public final class CharsReplacer implements Replacer {
continue; continue;
} }
final String replacement = placeholder.onRequest(player, parametersString); final String replacement = placeholder.onPlaceholderRequest(player, parametersString);
if (replacement == null) { if (replacement == null) {
builder.append(closure.head).append(identifierString); builder.append(closure.head).append(identifierString);

View File

@@ -0,0 +1,50 @@
package at.helpch.placeholderapi.replacer;
import at.helpch.placeholderapi.PlaceholderAPI;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.entity.entities.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
public final class MessageReplacer {
@NotNull
public static Message replace(@NotNull final Message original, @NotNull final Function<String, String> setPlaceholders) {
if (original.getFormattedMessage().rawText == null) {
return original;
}
String replaced = setPlaceholders.apply(original.getFormattedMessage().rawText);
String link = original.getFormattedMessage().link == null ? null : setPlaceholders.apply(original.getFormattedMessage().link);
List<Message> newChildren = original.getChildren().stream()
.filter(Objects::nonNull)
.map(child -> replace(child, setPlaceholders))
.toList();
Message message = Message.raw(replaced);
if (original.getColor() != null) {
message = message.color(original.getColor());
}
if (link != null) {
message = message.link(link);
}
int bold = original.getFormattedMessage().bold.getValue();
if (bold != 0) {
message = message.bold(bold != 1);
}
int italic = original.getFormattedMessage().italic.getValue();
if (italic != 0) {
message = message.italic(italic != 1);
}
return message.insertAll(newChildren);
}
}

View File

@@ -18,19 +18,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.replacer; package at.helpch.placeholderapi.replacer;
import java.util.function.Function; import java.util.function.Function;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer; import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public interface Replacer { public interface Replacer {
@NotNull @NotNull
String apply(@NotNull final String text, @Nullable final OfflinePlayer player, String apply(@NotNull final String text, @Nullable final PlayerRef player,
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup); @NotNull final Function<String, @Nullable PlaceholderExpansion> lookup);

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.util; package at.helpch.placeholderapi.util;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.util; package at.helpch.placeholderapi.util;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.util; package at.helpch.placeholderapi.util;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -28,9 +28,9 @@ import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.Bukkit; import com.hypixel.hytale.server.core.HytaleServer;
import org.bukkit.plugin.Plugin; import com.hypixel.hytale.server.core.universe.Universe;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public final class Futures { public final class Futures {
@@ -42,11 +42,7 @@ public final class Futures {
@NotNull final CompletableFuture<T> future, @NotNull final CompletableFuture<T> future,
@NotNull final BiConsumer<T, Throwable> consumer) { @NotNull final BiConsumer<T, Throwable> consumer) {
future.whenComplete((value, exception) -> { future.whenComplete((value, exception) -> {
if (Bukkit.isPrimaryThread()) { HytaleServer.SCHEDULED_EXECUTOR.execute(() -> consumer.accept(value, exception));
consumer.accept(value, exception);
} else {
plugin.getScheduler().runTask(() -> consumer.accept(value, exception));
}
}); });
} }

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.util; package at.helpch.placeholderapi.util;
public enum TimeFormat { public enum TimeFormat {
DAYS, DAYS,

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package me.clip.placeholderapi.util; package at.helpch.placeholderapi.util;
import java.time.Duration; import java.time.Duration;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;

View File

@@ -1,606 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi;
import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.Relational;
import me.clip.placeholderapi.expansion.manager.LocalExpansionManager;
import me.clip.placeholderapi.replacer.CharsReplacer;
import me.clip.placeholderapi.replacer.Replacer;
import me.clip.placeholderapi.replacer.Replacer.Closure;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public final class PlaceholderAPI {
private static final Replacer REPLACER_PERCENT = new CharsReplacer(Closure.PERCENT);
private static final Replacer REPLACER_BRACKET = new CharsReplacer(Closure.BRACKET);
static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
static final Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]");
static final Pattern RELATIONAL_PLACEHOLDER_PATTERN = Pattern
.compile("[%](rel_)([^%]+)[%]");
private PlaceholderAPI() {
}
// === Current API ===
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param text Text to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static String setPlaceholders(final OfflinePlayer player,
@NotNull final String text) {
return REPLACER_PERCENT.apply(text, player,
PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param text List of Strings to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static List<String> setPlaceholders(final OfflinePlayer player,
@NotNull final List<String> text) {
return text.stream().map(line -> setPlaceholders(player, line)).collect(Collectors.toList());
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param text Text to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static String setPlaceholders(final Player player, @NotNull String text) {
return setPlaceholders(((OfflinePlayer) player), text);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param text List of Strings to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static List<String> setPlaceholders(final Player player, @NotNull List<@NotNull String> text) {
return setPlaceholders(((OfflinePlayer) player), text);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param text Text to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static String setBracketPlaceholders(final OfflinePlayer player,
@NotNull final String text) {
return REPLACER_BRACKET.apply(text, player,
PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param text List of Strings to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static List<@NotNull String> setBracketPlaceholders(final OfflinePlayer player,
@NotNull final List<@NotNull String> text) {
return text.stream().map(line -> setBracketPlaceholders(player, line))
.collect(Collectors.toList());
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param text Text to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static String setBracketPlaceholders(Player player, @NotNull String text) {
return setBracketPlaceholders((OfflinePlayer) player, text);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param text List of Strings to set the placeholder values in
* @return String containing all translated placeholders
*/
@NotNull
public static List<String> setBracketPlaceholders(Player player, @NotNull List<String> text) {
return setBracketPlaceholders((OfflinePlayer) player, text);
}
/**
* set relational placeholders in the text specified placeholders are matched with the pattern
* {@literal %<rel_(identifier)_(params)>%} when set with this method
*
* @param one First player to compare
* @param two Second player to compare
* @param text Text to parse the placeholders in
* @return The text containing the parsed relational placeholders
*/
public static String setRelationalPlaceholders(Player one, Player two, String text) {
final Matcher matcher = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
while (matcher.find()) {
final String format = matcher.group(2);
final int index = format.indexOf("_");
if (index <= 0 || index >= format.length()) {
continue;
}
String identifier = format.substring(0, index).toLowerCase(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;
}
/**
* Translate placeholders in the provided List based on the relation of the two provided players.
* <br>The pattern of a valid placeholder is {@literal %rel_<identifier>_<param>%}.
*
* @param one Player to compare
* @param two Player to compare
* @param text text to parse the placeholder values to
* @return The text containing the parsed relational placeholders
*/
public static List<String> setRelationalPlaceholders(Player one, Player two, List<String> text) {
return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
.collect(Collectors.toList());
}
/**
* Check if a specific placeholder identifier is currently registered
*
* @param identifier The identifier to check
* @return true if identifier is already registered
*/
public static boolean isRegistered(@NotNull final String identifier) {
return PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()
.findExpansionByIdentifier(identifier).isPresent();
}
/**
* Get all registered placeholder identifiers
*
* @return A Set of type String containing the identifiers of all registered expansions.
*/
@NotNull
public static Set<String> getRegisteredIdentifiers() {
return ImmutableSet
.copyOf(PlaceholderAPIPlugin.getInstance().getLocalExpansionManager().getIdentifiers());
}
/**
* Get the normal placeholder pattern.
*
* @return Regex Pattern of {@literal [%]([^%]+)[%]}
*/
public static Pattern getPlaceholderPattern() {
return PLACEHOLDER_PATTERN;
}
/**
* Get the bracket placeholder pattern.
*
* @return Regex Pattern of {@literal [{]([^{}]+)[}]}
*/
public static Pattern getBracketPlaceholderPattern() {
return BRACKET_PLACEHOLDER_PATTERN;
}
/**
* Get the relational placeholder pattern.
*
* @return Regex Pattern of {@literal [%](rel_)([^%]+)[%]}
*/
public static Pattern getRelationalPlaceholderPattern() {
return RELATIONAL_PLACEHOLDER_PATTERN;
}
/**
* Check if a String contains any PlaceholderAPI placeholders ({@literal
* %<identifier>_<params>%}).
*
* @param text String to check
* @return true if String contains any matches to the normal placeholder pattern, false otherwise
*/
public static boolean containsPlaceholders(String text) {
return text != null && PLACEHOLDER_PATTERN.matcher(text).find();
}
/**
* Check if a String contains any PlaceholderAPI bracket placeholders ({@literal
* {<identifier>_<params>}}).
*
* @param text String to check
* @return true if String contains any matches to the bracket placeholder pattern, false otherwise
*/
public static boolean containsBracketPlaceholders(String text) {
return text != null && BRACKET_PLACEHOLDER_PATTERN.matcher(text).find();
}
// === Deprecated API ===
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static boolean registerExpansion(PlaceholderExpansion expansion) {
return expansion.register();
}
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static boolean unregisterExpansion(PlaceholderExpansion expansion) {
return expansion.unregister();
}
/**
* Get map of registered placeholders
*
* @return Map of registered placeholders
* @deprecated Use {@link LocalExpansionManager#getExpansions()} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static Map<String, PlaceholderHook> getPlaceholders() {
return PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()
.getExpansions().stream()
.collect(Collectors.toMap(PlaceholderExpansion::getIdentifier, ex -> ex));
}
/**
* @param plugin The Plugin to register with this {@link PlaceholderHook}
* @param placeholderHook The {@link PlaceholderHook} to register
* @return always false
* @deprecated Please use {@link PlaceholderExpansion} to
* register placeholders instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static boolean registerPlaceholderHook(Plugin plugin, PlaceholderHook placeholderHook) {
Msg.warn("Nag author(s) %s of plugin %s about their usage of the deprecated PlaceholderHook"
+ " class! This class will be removed in v2.13.0!", plugin.getDescription().getAuthors(),
plugin.getName());
return false;
}
/**
* @param identifier The identifier to use for the {@link PlaceholderHook}
* @param placeholderHook The {@link PlaceholderHook} to register
* @return always false
* @deprecated Please use {@link PlaceholderExpansion} to
* register placeholders instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static boolean registerPlaceholderHook(String identifier,
PlaceholderHook placeholderHook) {
Msg.warn("%s is attempting to register placeholders via deprecated PlaceholderHook class."
+ " This class is no longer supported and will be removed in v2.13.0!", identifier);
return false;
}
/**
* @param plugin The plugin to unregister
* @return always false
* @deprecated Please use {@link PlaceholderExpansion} to
* unregister placeholders instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static boolean unregisterPlaceholderHook(Plugin plugin) {
Msg.warn("Nag author(s) %s of plugin %s about their usage of the PlaceholderAPI class."
+ " This way of unregistering placeholders is no longer supported and will be removed"
+ " in v2.13.0!", plugin.getDescription().getAuthors(), plugin.getName());
return false;
}
/**
* @param identifier The identifier to unregister
* @return always false
* @deprecated Please use {@link PlaceholderExpansion} to
* unregister placeholders instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static boolean unregisterPlaceholderHook(String identifier) {
Msg.warn("%s is attempting to unregister placeholders via PlaceholderAPI class."
+ " This way of unregistering placeholders is no longer supported and will be removed"
+ " in v2.13.0!", identifier);
return false;
}
/**
* @return Set of registered identifiers
* @deprecated Will be removed in a future release.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static Set<String> getRegisteredPlaceholderPlugins() {
return getRegisteredIdentifiers();
}
/**
* @return always null
* @deprecated Will be removed in a future release.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static Set<String> getExternalPlaceholderPlugins() {
return null;
}
/**
* @param player The offline player to parse the placeholders against
* @param text The text to parse
* @param pattern The Pattern to use
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Please use {@link #setPlaceholders(OfflinePlayer, String)} instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static String setPlaceholders(OfflinePlayer player,
String text, Pattern pattern, boolean colorize) {
return setPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The List of text to parse
* @param pattern The Pattern to use
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Please use {@link #setPlaceholders(OfflinePlayer, List)} instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static List<String> setPlaceholders(OfflinePlayer player,
List<String> text, Pattern pattern, boolean colorize) {
return setPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The List of text to parse
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static List<String> setPlaceholders(OfflinePlayer player, List<String> text,
boolean colorize) {
return setPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The List of text to parse
* @param pattern The Pattern to use
* @return String with the parsed placeholders
* @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static List<String> setPlaceholders(OfflinePlayer player, List<String> text,
Pattern pattern) {
return setPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The text to parse
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Will be removed in a future release.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static String setPlaceholders(Player player, String text, boolean colorize) {
return setPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The List of text to parse
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Will be removed in a future release.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static List<String> setPlaceholders(Player player, List<String> text, boolean colorize) {
return setPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The text to parse
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static String setPlaceholders(OfflinePlayer player, String text, boolean colorize) {
return setPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The text to parse
* @param pattern The Pattern to use
* @return String with the parsed placeholders
* @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static String setPlaceholders(OfflinePlayer player, String text, Pattern pattern) {
return setPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The List of text to parse
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Use {@link #setPlaceholders(OfflinePlayer, List)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static List<String> setBracketPlaceholders(OfflinePlayer player, List<String> text,
boolean colorize) {
return setBracketPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The text to parse
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static String setBracketPlaceholders(OfflinePlayer player, String text, boolean colorize) {
return setBracketPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The text to parse
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Will be removed in a future release.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static String setBracketPlaceholders(Player player, String text, boolean colorize) {
return setBracketPlaceholders(player, text);
}
/**
* @param player The offline player to parse the placeholders against
* @param text The List of text to parse
* @param colorize If PlaceholderAPI should also parse color codes
* @return String with the parsed placeholders
* @deprecated Will be removed in a future release.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static List<String> setBracketPlaceholders(Player player, List<String> text,
boolean colorize) {
return setBracketPlaceholders(player, text);
}
/**
* set relational placeholders in the text specified placeholders are matched with the pattern
* {@literal %<rel_(identifier)_(params)>%} when set with this method
*
* @param one Player to compare
* @param two Player to compare
* @param text Text to parse the placeholders in
* @param colorize If color codes ({@literal &[0-1a-fk-o]}) should be translated
* @return The text containing the parsed relational placeholders
* @deprecated Use {@link #setPlaceholders(OfflinePlayer, String)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static String setRelationalPlaceholders(Player one, Player two, String text,
boolean colorize) {
return setRelationalPlaceholders(one, two, text);
}
/**
* Translate placeholders in the provided list based on the relation of the two provided players.
* <br>The pattern of a valid placeholder is {@literal %rel_<identifier>_<params>%}.
*
* @param one First player to compare
* @param two Second player to compare
* @param text Text to parse the placeholders in
* @param colorize If color codes ({@literal &[0-1a-fk-o]}) should be translated
* @return The text containing the parsed relational placeholders
* @deprecated Use {@link #setRelationalPlaceholders(Player, Player, List)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.13.0")
public static List<String> setRelationalPlaceholders(Player one, Player two, List<String> text,
boolean colorize) {
return setRelationalPlaceholders(one, two, text);
}
}

View File

@@ -1,297 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import me.clip.placeholderapi.commands.PlaceholderCommandRouter;
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.ExpansionSafetyCheck;
import me.clip.placeholderapi.util.Msg;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.AdvancedPie;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
/**
* Yes I have a shit load of work to do...
*
* @author Ryan McCarthy
*/
public final class PlaceholderAPIPlugin extends JavaPlugin {
@NotNull
private static final Version VERSION;
private static PlaceholderAPIPlugin instance;
static {
String version = Bukkit.getServer().getBukkitVersion().split("-")[0];
String suffix;
if (version.chars()
.filter(c -> c == '.')
.count() == 1) {
suffix = "R1";
version = 'v' + version.replace('.', '_') + '_' + suffix;
} else {
int minor = Integer.parseInt(version.split("\\.")[2].charAt(0) + "");
version = 'v' + version.replace('.', '_').replace("_" + minor, "") + '_' + "R" + (minor - 1);
}
boolean isSpigot;
try {
Class.forName("org.spigotmc.SpigotConfig");
isSpigot = true;
} catch (final ExceptionInInitializerError | ClassNotFoundException ignored) {
isSpigot = false;
}
VERSION = new Version(version, isSpigot);
}
@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);
private BukkitAudiences adventure;
private boolean safetyCheck = false;
/**
* 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");
}
}
@Deprecated
public static Version getServerVersion() {
return VERSION;
}
@Override
public void onLoad() {
saveDefaultConfig();
safetyCheck = new ExpansionSafetyCheck(this).runChecks();
if (safetyCheck) {
return;
}
instance = this;
}
@Override
public void onEnable() {
if (safetyCheck) {
return;
}
setupCommand();
setupMetrics();
setupExpansions();
adventure = BukkitAudiences.create(this);
if (config.isCloudEnabled()) {
getCloudExpansionManager().load();
}
if (config.checkUpdates()) {
new UpdateChecker(this).fetch();
}
}
@Override
public void onDisable() {
if (safetyCheck) {
return;
}
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

@@ -1,42 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class PlaceholderHook {
@Nullable
public String onRequest(final OfflinePlayer player, @NotNull final String params) {
if (player != null && player.isOnline()) {
return onPlaceholderRequest(player.getPlayer(), params);
}
return onPlaceholderRequest(null, params);
}
@Nullable
public String onPlaceholderRequest(final Player player, @NotNull final String params) {
return null;
}
}

View File

@@ -1,145 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.impl.cloud.CommandECloud;
import me.clip.placeholderapi.commands.impl.local.CommandDump;
import me.clip.placeholderapi.commands.impl.local.CommandExpansionRegister;
import me.clip.placeholderapi.commands.impl.local.CommandExpansionUnregister;
import me.clip.placeholderapi.commands.impl.local.CommandHelp;
import me.clip.placeholderapi.commands.impl.local.CommandInfo;
import me.clip.placeholderapi.commands.impl.local.CommandList;
import me.clip.placeholderapi.commands.impl.local.CommandParse;
import me.clip.placeholderapi.commands.impl.local.CommandReload;
import me.clip.placeholderapi.commands.impl.local.CommandVersion;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
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());
@NotNull
private final PlaceholderAPIPlugin plugin;
@NotNull
@Unmodifiable
private final Map<String, PlaceholderCommand> commands;
public PlaceholderCommandRouter(@NotNull final PlaceholderAPIPlugin plugin) {
this.plugin = plugin;
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();
}
@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;
}
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;
}
@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

@@ -1,146 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands.impl.cloud;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Stream;
public final class CommandECloud extends PlaceholderCommand {
@Unmodifiable
private static final List<PlaceholderCommand> COMMANDS = ImmutableList
.of(new CommandECloudClear(),
new CommandECloudStatus(),
new CommandECloudUpdate(),
new CommandECloudRefresh(),
new CommandECloudDownload(),
new CommandECloudExpansionInfo(),
new CommandECloudExpansionList(),
new CommandECloudExpansionPlaceholders());
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));
}
this.commands = commands.build();
}
@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()));
}
@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

@@ -1,140 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.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;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandECloudDownload extends PlaceholderCommand {
public CommandECloudDownload() {
super("download");
}
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));
}
@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;
}
if (isBlockedExpansion(params.get(0))) {
Msg.msg(sender,
"&cThis expansion can't be downloaded.");
return;
}
final CloudExpansion expansion = plugin.getCloudExpansionManager()
.findCloudExpansionByName(params.get(0)).orElse(null);
if (expansion == null) {
Msg.msg(sender,
"&cFailed to find an expansion named: &f" + params.get(0));
return;
}
final CloudExpansion.Version version;
if (params.size() < 2) {
version = expansion.getVersion(expansion.getLatestVersion());
if (version == null) {
Msg.msg(sender,
"&cCould not find latest version for expansion.");
return;
}
} else {
version = expansion.getVersion(params.get(1));
if (version == null) {
Msg.msg(sender,
"&cCould not find specified version: &f" + params.get(1),
"&7Available versions: &f" + expansion.getAvailableVersions());
return;
}
}
if (!version.isVerified()) {
Msg.msg(sender, "&cThe expansion '&f" + params.get(0) + "&c' is not verified and can only be downloaded manually from &fhttps://ecloud.placeholderapi.com");
return;
}
plugin.getCloudExpansionManager().downloadExpansion(expansion, version)
.whenComplete((file, exception) -> {
if (exception != null) {
Msg.msg(sender,
"&cFailed to download expansion: &f" + exception.getMessage());
return;
}
Msg.msg(sender,
"&aSuccessfully downloaded expansion &f" + expansion.getName() + " [" + version
.getVersion() + "] &ato file: &f" + file.getName(),
"&aMake sure to type &f/papi reload &ato enable your new expansion!");
plugin.getCloudExpansionManager().load();
});
}
@Override
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
if (params.size() > 2) {
return;
}
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

@@ -1,133 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.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;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
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;
}
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');
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("&bVerified: ")
.append(expansion.getVersion().isVerified() ? "&a&l✔" : "&c&l❌")
.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("&bVerified: ")
.append(version.isVerified() ? "&a&l✔" : "&c&l❌")
.append('\n')
.append("&bRelease Notes: &f")
.append(version.getReleaseNotes())
.append('\n')
.append("&bDownload URL: &f")
.append(version.getUrl())
.append('\n');
}
Msg.msg(sender, builder.toString());
}
@Override
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
if (params.size() > 2) {
return;
}
if (params.size() <= 1) {
final Stream<String> names = plugin.getCloudExpansionManager().getCloudExpansions().values()
.stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
return;
}
final Optional<CloudExpansion> expansion = plugin.getCloudExpansionManager()
.findCloudExpansionByName(params.get(0));
if (!expansion.isPresent()) {
return;
}
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
}
}

View File

@@ -1,354 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands.impl.cloud;
import com.google.common.base.Strings;
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;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
import me.clip.placeholderapi.util.Format;
import me.clip.placeholderapi.util.Msg;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import static net.kyori.adventure.text.Component.*;
import static net.kyori.adventure.text.format.NamedTextColor.*;
public final class CommandECloudExpansionList extends PlaceholderCommand {
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.getVersion().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");
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();
}
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;
}
}
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.getVersion().isVerified() ? "" : "", expansion.getVersion().isVerified() ? GREEN : RED, TextDecoration.BOLD))
.append(newline())
.append(text("Released: ", AQUA)).append(text(format.format(expansion.getLastUpdate()), WHITE))
.toBuilder();
Optional.ofNullable(expansion.getDescription())
.filter(description -> !description.isEmpty())
.ifPresent(description -> hoverText.append(newline()).append(newline())
.append(text(description.replace("\r", "").trim(), WHITE))
);
line.hoverEvent(HoverEvent.showText(hoverText.build()));
if (index != expansions.size() - 1) {
line.append(newline());
}
message.append(line.build());
}
if (limit > 1) {
message.append(newline());
final TextComponent.Builder left = text("", page > 1 ? GRAY : DARK_GRAY).toBuilder();
if (page > 1) {
left.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page - 1)));
}
final TextComponent.Builder right = text("", page < limit ? GRAY : DARK_GRAY).toBuilder();
if (page < limit) {
right.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page + 1)));
}
message.append(left, text(" " + page + " ", GREEN), right);
}
return message.build();
}
private static void addExpansionTable(@NotNull final List<CloudExpansion> expansions,
@NotNull final StringBuilder message, final int startIndex,
@NotNull final String versionTitle,
@NotNull final Function<CloudExpansion, Object> versionFunction) {
final Map<String, Function<CloudExpansion, Object>> functions = new LinkedHashMap<>();
final AtomicInteger counter = new AtomicInteger(startIndex);
functions.put("&f", expansion -> "&8" + counter.getAndIncrement() + ".");
functions.put("&9Name", EXPANSION_NAME);
functions.put("&9Author", EXPANSION_AUTHOR);
functions.put("&9Verified", EXPANSION_VERIFIED);
functions.put(versionTitle, versionFunction);
final List<List<String>> rows = new ArrayList<>();
rows.add(0, new ArrayList<>(functions.keySet()));
for (final CloudExpansion expansion : expansions) {
rows.add(functions.values().stream().map(function -> function.apply(expansion))
.map(Objects::toString).collect(Collectors.toList()));
}
final List<String> table = Format.tablify(Format.Align.LEFT, rows)
.orElse(Collections.emptyList());
if (table.isEmpty()) {
return;
}
table.add(1, "&8" + Strings.repeat("-", table.get(0).length() - (rows.get(0).size() * 2)));
message.append(String.join("\n", table));
}
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params) {
if (params.isEmpty()) {
Msg.msg(sender,
"&cYou must specify an option. [all, {author}, installed]");
return;
}
final boolean installed = params.get(0).equalsIgnoreCase("installed");
final List<CloudExpansion> expansions = Lists
.newArrayList(getExpansions(params.get(0), plugin));
if (expansions.isEmpty()) {
Msg.msg(sender,
"&cNo expansions available to list.");
return;
}
expansions
.sort(plugin.getPlaceholderAPIConfig().getExpansionSort().orElse(ExpansionSort.LATEST));
if (!(sender instanceof Player) && params.size() < 2) {
final StringBuilder builder = new StringBuilder();
addExpansionTitle(builder, params.get(0), -1);
addExpansionTable(expansions,
builder,
1,
installed ? "&9Version" : "&9Latest Version",
installed ? EXPANSION_CURRENT_VERSION : EXPANSION_LATEST_VERSION);
Msg.msg(sender, builder.toString());
return;
}
final int page;
if (params.size() < 2) {
page = 1;
} 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

@@ -1,96 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.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;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
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;
}
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")));
}
@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

@@ -1,65 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.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;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
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.");
}
Msg.msg(sender, builder.toString());
}
}

View File

@@ -1,143 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands.impl.cloud;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
import me.clip.placeholderapi.util.Futures;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
/**
* please don't flame me for this code, I will fix this shit later.
*/
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;
}
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);
}
// remove the ones that are the latest version
expansions.removeIf(expansion -> !expansion.shouldUpdate());
if (expansions.isEmpty()) {
Msg.msg(sender,
"&cNo updates available for " + (!multiple ? "this expansion."
: "your active expansions."));
return;
}
Msg.msg(sender,
"&aUpdating expansions: " + expansions.stream().map(CloudExpansion::getName)
.collect(Collectors.joining("&7, &6", "&8[&6", "&8]&r")));
Futures.onMainThread(plugin, downloadAndDiscover(expansions, plugin), (classes, exception) -> {
if (exception != null) {
Msg.msg(sender,
"&cFailed to update expansions: &e" + exception.getMessage());
return;
}
Msg.msg(sender,
"&aSuccessfully downloaded updates, registering new versions.");
final String message = classes.stream()
.filter(Objects::nonNull)
.map(plugin.getLocalExpansionManager()::register)
.filter(Optional::isPresent)
.map(Optional::get)
.map(expansion -> " &a" + expansion.getName() + " &f" + expansion.getVersion())
.collect(Collectors.joining("\n"));
Msg.msg(sender,
"&7Registered expansions:", message);
});
}
@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());
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));
}
}

View File

@@ -1,111 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands.impl.local;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.manager.LocalExpansionManager;
import me.clip.placeholderapi.util.Futures;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
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;
}
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());
});
}
@Override
public void complete(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
if (params.size() > 1) {
return;
}
final String[] fileNames = plugin.getLocalExpansionManager().getExpansionsFolder()
.list((dir, name) -> name.endsWith(".jar"));
if (fileNames == null || fileNames.length == 0) {
return;
}
suggestByParameter(Arrays.stream(fileNames), suggestions,
params.isEmpty() ? null : params.get(0));
}
}

View File

@@ -1,78 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.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;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
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;
}
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());
}
@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

@@ -1,73 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands.impl.local;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginDescriptionFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandHelp extends PlaceholderCommand {
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();
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

@@ -1,114 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands.impl.local;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
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;
}
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());
}
@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

@@ -1,63 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.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;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
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;
}
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

@@ -1,257 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands.impl.local;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Stream;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
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 provide a target and message: &b/papi "
+ (command ? "cmdparse" : (broadcast ? "bcparse" : "parse"))
+ " &7{target} &a{message}");
return;
}
OfflinePlayer player;
if ("me".equalsIgnoreCase(params.get(0))) {
if (!(sender instanceof Player)) {
Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
return;
}
player = ((Player) sender);
} else if ("--null".equalsIgnoreCase(params.get(0))) {
player = null;
} else {
final OfflinePlayer target = resolvePlayer(params.get(0));
if (target == null) {
Msg.msg(sender, "&cFailed to find player: &7" + params.get(0));
return;
}
player = target;
}
final String message = PlaceholderAPI
.setPlaceholders(player, String.join(" ", params.subList(1, params.size())));
if (command) {
Bukkit.dispatchCommand(sender, message);
return;
}
if (broadcast) {
Bukkit.broadcastMessage(message);
} else {
sender.sendMessage(message);
}
}
private void evaluateParseRelation(@NotNull final CommandSender sender,
@NotNull @Unmodifiable final List<String> params) {
if (params.size() < 3) {
Msg.msg(sender,
"&cYou must supply two targets, and a message: &b/papi parserel &7{target one} "
+ "{target two} &a{message}");
return;
}
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);
}
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));
}
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

@@ -1,53 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.commands.impl.local;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginDescriptionFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
public final class CommandVersion extends PlaceholderCommand {
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();
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

@@ -1,94 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.configuration;
import java.util.Optional;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.jetbrains.annotations.NotNull;
public final class PlaceholderAPIConfig {
@NotNull
private final PlaceholderAPIPlugin plugin;
public PlaceholderAPIConfig(@NotNull final PlaceholderAPIPlugin plugin) {
this.plugin = plugin;
}
public boolean checkUpdates() {
return plugin.getConfig().getBoolean("check_updates");
}
public boolean isCloudEnabled() {
return plugin.getConfig().getBoolean("cloud_enabled");
}
public void setCloudEnabled(boolean state) {
plugin.getConfig().set("cloud_enabled", state);
plugin.saveConfig();
}
public boolean isDebugMode() {
return plugin.getConfig().getBoolean("debug", false);
}
public Optional<ExpansionSort> getExpansionSort() {
final String option = plugin.getConfig()
.getString("cloud_sorting", ExpansionSort.LATEST.name());
try {
//noinspection ConstantConditions (bad spigot annotation)
return Optional.of(ExpansionSort.valueOf(option.toUpperCase()));
} catch (final IllegalArgumentException ignored) {
return Optional.empty();
}
}
@NotNull
public String dateFormat() {
//noinspection ConstantConditions (bad spigot annotation)
return plugin.getConfig().getString("date_format", "MM/dd/yy HH:mm:ss");
}
@NotNull
public String booleanTrue() {
//noinspection ConstantConditions (bad spigot annotation)
return plugin.getConfig().getString("boolean.true", "true");
}
@NotNull
public String booleanFalse() {
//noinspection ConstantConditions (bad spigot annotation)
return plugin.getConfig().getString("boolean.false", "false");
}
public boolean detectMaliciousExpansions() {
return plugin.getConfig().getBoolean("detect_malicious_expansions", true);
}
}

View File

@@ -1,70 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.events;
import me.clip.placeholderapi.PlaceholderHook;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* @deprecated This event is no longer used.
*/
@Deprecated
public final class PlaceholderHookUnloadEvent extends Event {
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
@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;
}
@NotNull
public static HandlerList getHandlerList() {
return HANDLERS;
}
@NotNull
public String getHookName() {
return plugin;
}
@NotNull
public PlaceholderHook getHook() {
return placeholderHook;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
}

View File

@@ -1,81 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.expansion;
public enum NMSVersion {
UNKNOWN("unknown"),
SPIGOT_1_7_R1("v1_7_R1"),
SPIGOT_1_7_R2("v1_7_R2"),
SPIGOT_1_7_R3("v1_7_R3"),
SPIGOT_1_7_R4("v1_7_R4"),
SPIGOT_1_8_R1("v1_8_R1"),
SPIGOT_1_8_R2("v1_8_R2"),
SPIGOT_1_8_R3("v1_8_R3"),
SPIGOT_1_9_R1("v1_9_R1"),
SPIGOT_1_9_R2("v1_9_R2"),
SPIGOT_1_10_R1("v1_10_R1"),
SPIGOT_1_11_R1("v1_11_R1"),
SPIGOT_1_12_R1("v1_12_R1"),
SPIGOT_1_13_R1("v1_13_R1"),
SPIGOT_1_13_R2("v1_13_R2"),
SPIGOT_1_14_R1("v1_14_R1"),
SPIGOT_1_15_R1("v1_15_R1"),
SPIGOT_1_16_R1("v1_16_R1"),
SPIGOT_1_16_R2("v1_16_R2"),
SPIGOT_1_16_R3("v1_16_R3"),
SPIGOT_1_17_R1("v1_17_R1"),
SPIGOT_1_18_R1("v1_18_R1"),
SPIGOT_1_19_R1("v1_19_R1"),
SPIGOT_1_19_R2("v1_19_R2"),
SPIGOT_1_19_R3("v1_19_R3"),
SPIGOT_1_20_R1("v1_20_R1"),
SPIGOT_1_20_R2("v1_20_R2"),
SPIGOT_1_20_R3("v1_20_R3"),
SPIGOT_1_20_R4("v1_20_R4"),
SPIGOT_1_21_R1("v1_21_R1"),
SPIGOT_1_21_R2("V1_21_R2"),
SPIGOT_1_21_R3("V1_21_R3"),
SPIGOT_1_21_R4("V1_21_R4"),
SPIGOT_1_21_R5("V1_21_R5"),
SPIGOT_1_21_R6("V1_21_R6");
private final String version;
NMSVersion(String version) {
this.version = version;
}
public static NMSVersion getVersion(String version) {
for (NMSVersion v : values()) {
if (v.getVersion().equalsIgnoreCase(version)) {
return v;
}
}
return NMSVersion.UNKNOWN;
}
public String getVersion() {
return version;
}
}

View File

@@ -1,46 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.expansion;
@Deprecated
public final class Version {
private final boolean isSpigot;
private final String version;
public Version(String version, boolean isSpigot) {
this.version = version;
this.isSpigot = isSpigot;
}
public String getVersion() {
return version == null ? "unknown" : version;
}
public boolean isSpigot() {
return isSpigot;
}
public boolean compareTo(String version) {
return getVersion().equalsIgnoreCase(version);
}
}

View File

@@ -1,43 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.expansion;
/**
* Placeholder expansions which use NMS code should be version specific. Implementing this class
* allows you to perform checks based on the version the server is running. The isCompatibleWith
* method will be passed the server version and allow you to return if your expansion is compatible
* with that version.
*
* @author Ryan McCarthy
* @deprecated Will be removed in a future release.
*/
@Deprecated
public interface VersionSpecific {
/**
* This method is called before the expansion is attempted to be registered The server version
* will be passed to this method so you know what version the server is currently running.
*
* @param v The {@link Version} to check against
* @return true if your expansion is compatible with the version the server is running.
*/
boolean isCompatibleWith(Version v);
}

View File

@@ -1,48 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.listeners;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerLoadEvent;
import org.jetbrains.annotations.NotNull;
public final class ServerLoadEventListener implements Listener {
@NotNull
private final PlaceholderAPIPlugin plugin;
public ServerLoadEventListener(@NotNull final PlaceholderAPIPlugin plugin) {
this.plugin = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onServerLoad(@NotNull final ServerLoadEvent event) {
HandlerList.unregisterAll(this);
plugin.getLocalExpansionManager().load(Bukkit.getConsoleSender());
}
}

View File

@@ -1,180 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler;
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
import org.bukkit.plugin.Plugin;
/**
* Just modified BukkitRunnable
*/
public abstract class UniversalRunnable implements Runnable {
MyScheduledTask task;
public synchronized void cancel() throws IllegalStateException {
checkScheduled();
task.cancel();
}
/**
* Returns true if this task has been cancelled.
*
* @return true if the task has been cancelled
* @throws IllegalStateException if task was not scheduled yet
*/
public synchronized boolean isCancelled() throws IllegalStateException {
checkScheduled();
return task.isCancelled();
}
/**
* Schedules this in the Bukkit scheduler to run on next tick.
*
* @param plugin the reference to the plugin scheduling task
* @return {@link MyScheduledTask}
* @throws IllegalArgumentException if plugin is null
* @throws IllegalStateException if this was already scheduled
* @see TaskScheduler#runTask(Runnable)
*/
public synchronized MyScheduledTask runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
checkNotYetScheduled();
return setupTask(UniversalScheduler.getScheduler(plugin).runTask(this));
}
/**
* <b>Asynchronous tasks should never access any API in Bukkit. Great care
* should be taken to assure the thread-safety of asynchronous tasks.</b>
* <p>
* Schedules this in the Bukkit scheduler to run asynchronously.
*
* @param plugin the reference to the plugin scheduling task
* @return {@link MyScheduledTask}
* @throws IllegalArgumentException if plugin is null
* @throws IllegalStateException if this was already scheduled
* @see TaskScheduler#runTaskAsynchronously(Runnable)
*/
public synchronized MyScheduledTask runTaskAsynchronously(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
checkNotYetScheduled();
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskAsynchronously(this));
}
/**
* Schedules this to run after the specified number of server ticks.
*
* @param plugin the reference to the plugin scheduling task
* @param delay the ticks to wait before running the task
* @return {@link MyScheduledTask}
* @throws IllegalArgumentException if plugin is null
* @throws IllegalStateException if this was already scheduled
* @see TaskScheduler#runTaskLater(Runnable, long)
*/
public synchronized MyScheduledTask runTaskLater(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException {
checkNotYetScheduled();
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskLater(this, delay));
}
/**
* <b>Asynchronous tasks should never access any API in Bukkit. Great care
* should be taken to assure the thread-safety of asynchronous tasks.</b>
* <p>
* Schedules this to run asynchronously after the specified number of
* server ticks.
*
* @param plugin the reference to the plugin scheduling task
* @param delay the ticks to wait before running the task
* @return {@link MyScheduledTask}
* @throws IllegalArgumentException if plugin is null
* @throws IllegalStateException if this was already scheduled
* @see TaskScheduler#runTaskLaterAsynchronously(Runnable, long)
*/
public synchronized MyScheduledTask runTaskLaterAsynchronously(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException {
checkNotYetScheduled();
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskLaterAsynchronously(this, delay));
}
/**
* Schedules this to repeatedly run until cancelled, starting after the
* specified number of server ticks.
*
* @param plugin the reference to the plugin scheduling task
* @param delay the ticks to wait before running the task
* @param period the ticks to wait between runs
* @return {@link MyScheduledTask}
* @throws IllegalArgumentException if plugin is null
* @throws IllegalStateException if this was already scheduled
* @see TaskScheduler#runTaskTimer(Runnable, long, long)
*/
public synchronized MyScheduledTask runTaskTimer(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException {
checkNotYetScheduled();
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskTimer(this, delay, period));
}
/**
* <b>Asynchronous tasks should never access any API in Bukkit. Great care
* should be taken to assure the thread-safety of asynchronous tasks.</b>
* <p>
* Schedules this to repeatedly run asynchronously until cancelled,
* starting after the specified number of server ticks.
*
* @param plugin the reference to the plugin scheduling task
* @param delay the ticks to wait before running the task for the first
* time
* @param period the ticks to wait between runs
* @return {@link MyScheduledTask}
* @throws IllegalArgumentException if plugin is null
* @throws IllegalStateException if this was already scheduled
* @see TaskScheduler#runTaskTimerAsynchronously(Runnable, long, long)
*/
public synchronized MyScheduledTask runTaskTimerAsynchronously(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException {
checkNotYetScheduled();
return setupTask(UniversalScheduler.getScheduler(plugin).runTaskTimerAsynchronously(this, delay, period));
}
private void checkScheduled() {
if (task == null) {
throw new IllegalStateException("Not scheduled yet");
}
}
private void checkNotYetScheduled() {
if (task != null) {
throw new IllegalStateException("Already scheduled");
}
}
private MyScheduledTask setupTask(final MyScheduledTask task) {
this.task = task;
return task;
}
}

View File

@@ -1,42 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler;
import me.clip.placeholderapi.scheduler.bukkit.BukkitScheduler;
import me.clip.placeholderapi.scheduler.folia.FoliaScheduler;
import me.clip.placeholderapi.scheduler.paper.PaperScheduler;
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
import me.clip.placeholderapi.scheduler.utils.JavaUtil;
import org.bukkit.plugin.Plugin;
public class UniversalScheduler {
private static final boolean IS_FOLIA = JavaUtil.classExists("io.papermc.paper.threadedregions.RegionizedServer");
private static final boolean IS_CANVAS = JavaUtil.classExists("io.canvasmc.canvas.server.ThreadedServer");
private static final boolean IS_EXPANDED_SCHEDULING_AVAILABLE = JavaUtil.classExists("io.papermc.paper.threadedregions.scheduler.ScheduledTask");
public static TaskScheduler getScheduler(Plugin plugin) {
return IS_FOLIA || IS_CANVAS ? new FoliaScheduler(plugin) : (IS_EXPANDED_SCHEDULING_AVAILABLE ? new PaperScheduler(plugin) : new BukkitScheduler(plugin));
}
}

View File

@@ -1,71 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler.bukkit;
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
public class BukkitScheduledTask implements MyScheduledTask {
BukkitTask task;
boolean isRepeating;
public BukkitScheduledTask(final BukkitTask task) {
this.task = task;
this.isRepeating = false;
}
public BukkitScheduledTask(final BukkitTask task, boolean isRepeating) {
this.task = task;
this.isRepeating = isRepeating;
}
@Override
public void cancel() {
task.cancel();
}
@Override
public boolean isCancelled() {
return task.isCancelled();
}
@Override
public Plugin getOwningPlugin() {
return task.getOwner();
}
@Override
public boolean isCurrentlyRunning() {
return Bukkit.getServer().getScheduler().isCurrentlyRunning(this.task.getTaskId()); //There's no other way. Fuck bukkit
}
@Override
public boolean isRepeatingTask() {
return isRepeating;
}
}

View File

@@ -1,129 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler.bukkit;
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;
public class BukkitScheduler implements TaskScheduler {
final Plugin plugin;
public BukkitScheduler(Plugin plugin) {
this.plugin = plugin;
}
@Override
public boolean isGlobalThread() {
return Bukkit.getServer().isPrimaryThread();
}
@Override
public boolean isEntityThread(Entity entity) {
return Bukkit.getServer().isPrimaryThread();
}
@Override
public boolean isRegionThread(Location location) {
return Bukkit.getServer().isPrimaryThread();
}
@Override
public MyScheduledTask runTask(Runnable runnable) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTask(plugin, runnable));
}
@Override
public MyScheduledTask runTaskLater(Runnable runnable, long delay) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskLater(plugin, runnable, delay));
}
@Override
public MyScheduledTask runTaskTimer(Runnable runnable, long delay, long period) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
}
@Override
public MyScheduledTask runTaskAsynchronously(Runnable runnable) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable));
}
@Override
public MyScheduledTask runTaskLaterAsynchronously(Runnable runnable, long delay) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, runnable, delay));
}
@Override
public MyScheduledTask runTaskTimerAsynchronously(Runnable runnable, long delay, long period) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, delay, period));
}
//Useless? Or...
public MyScheduledTask runTask(Plugin plugin, Runnable runnable) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTask(plugin, runnable));
}
@Override
public MyScheduledTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskLater(plugin, runnable, delay));
}
@Override
public MyScheduledTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
}
@Override
public MyScheduledTask runTaskAsynchronously(Plugin plugin, Runnable runnable) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable));
}
@Override
public MyScheduledTask runTaskLaterAsynchronously(Plugin plugin, Runnable runnable, long delay) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, runnable, delay));
}
@Override
public MyScheduledTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, delay, period));
}
@Override
public void execute(Runnable runnable) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable);
}
@Override
public void cancelTasks() {
Bukkit.getScheduler().cancelTasks(plugin);
}
@Override
public void cancelTasks(Plugin plugin) {
Bukkit.getScheduler().cancelTasks(plugin);
}
}

View File

@@ -1,57 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler.folia;
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.plugin.Plugin;
public class FoliaScheduledTask implements MyScheduledTask {
private final ScheduledTask task;
public FoliaScheduledTask(final ScheduledTask task) {
this.task = task;
}
public void cancel() {
this.task.cancel();
}
public boolean isCancelled() {
return this.task.isCancelled();
}
public Plugin getOwningPlugin() {
return this.task.getOwningPlugin();
}
public boolean isCurrentlyRunning() {
final ScheduledTask.ExecutionState state = this.task.getExecutionState();
return state == ScheduledTask.ExecutionState.RUNNING || state == ScheduledTask.ExecutionState.CANCELLED_RUNNING;
}
public boolean isRepeatingTask() {
return this.task.isRepeatingTask();
}
}

View File

@@ -1,220 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler.folia;
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler;
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
import io.papermc.paper.threadedregions.scheduler.RegionScheduler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;
import java.util.concurrent.TimeUnit;
public class FoliaScheduler implements TaskScheduler {
final Plugin plugin;
public FoliaScheduler(Plugin plugin) {
this.plugin = plugin;
}
private final RegionScheduler regionScheduler = Bukkit.getServer().getRegionScheduler();
private final GlobalRegionScheduler globalRegionScheduler = Bukkit.getServer().getGlobalRegionScheduler();
private final AsyncScheduler asyncScheduler = Bukkit.getServer().getAsyncScheduler();
@Override
public boolean isGlobalThread() {
return Bukkit.getServer().isGlobalTickThread();
}
@Override
public boolean isTickThread() {
return Bukkit.getServer().isPrimaryThread(); // The Paper implementation checks whether this is a tick thread, this method exists to avoid confusion.
}
@Override
public boolean isEntityThread(Entity entity) {
return Bukkit.getServer().isOwnedByCurrentRegion(entity);
}
@Override
public boolean isRegionThread(Location location) {
return Bukkit.getServer().isOwnedByCurrentRegion(location);
}
@Override
public MyScheduledTask runTask(Runnable runnable) {
return new FoliaScheduledTask(globalRegionScheduler.run(plugin, task -> runnable.run()));
}
@Override
public MyScheduledTask runTaskLater(Runnable runnable, long delay) {
//Folia exception: Delay ticks may not be <= 0
if (delay <= 0) {
return runTask(runnable);
}
return new FoliaScheduledTask(globalRegionScheduler.runDelayed(plugin, task -> runnable.run(), delay));
}
@Override
public MyScheduledTask runTaskTimer(Runnable runnable, long delay, long period) {
//Folia exception: Delay ticks may not be <= 0
delay = getOneIfNotPositive(delay);
return new FoliaScheduledTask(globalRegionScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay, period));
}
@Override
public MyScheduledTask runTask(Plugin plugin, Runnable runnable) {
return new FoliaScheduledTask(globalRegionScheduler.run(plugin, task -> runnable.run()));
}
@Override
public MyScheduledTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
//Folia exception: Delay ticks may not be <= 0
if (delay <= 0) {
return runTask(plugin, runnable);
}
return new FoliaScheduledTask(globalRegionScheduler.runDelayed(plugin, task -> runnable.run(), delay));
}
@Override
public MyScheduledTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
//Folia exception: Delay ticks may not be <= 0
delay = getOneIfNotPositive(delay);
return new FoliaScheduledTask(globalRegionScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay, period));
}
@Override
public MyScheduledTask runTask(Location location, Runnable runnable) {
return new FoliaScheduledTask(regionScheduler.run(plugin, location, task -> runnable.run()));
}
@Override
public MyScheduledTask runTaskLater(Location location, Runnable runnable, long delay) {
//Folia exception: Delay ticks may not be <= 0
if (delay <= 0) {
return runTask(runnable);
}
return new FoliaScheduledTask(regionScheduler.runDelayed(plugin, location, task -> runnable.run(), delay));
}
@Override
public MyScheduledTask runTaskTimer(Location location, Runnable runnable, long delay, long period) {
//Folia exception: Delay ticks may not be <= 0
delay = getOneIfNotPositive(delay);
return new FoliaScheduledTask(regionScheduler.runAtFixedRate(plugin, location, task -> runnable.run(), delay, period));
}
@Override
public MyScheduledTask runTask(Entity entity, Runnable runnable) {
return new FoliaScheduledTask(entity.getScheduler().run(plugin, task -> runnable.run(), null));
}
@Override
public MyScheduledTask runTaskLater(Entity entity, Runnable runnable, long delay) {
//Folia exception: Delay ticks may not be <= 0
if (delay <= 0) {
return runTask(entity, runnable);
}
return new FoliaScheduledTask(entity.getScheduler().runDelayed(plugin, task -> runnable.run(), null, delay));
}
@Override
public MyScheduledTask runTaskTimer(Entity entity, Runnable runnable, long delay, long period) {
//Folia exception: Delay ticks may not be <= 0
delay = getOneIfNotPositive(delay);
return new FoliaScheduledTask(entity.getScheduler().runAtFixedRate(plugin, task -> runnable.run(), null, delay, period));
}
@Override
public MyScheduledTask runTaskAsynchronously(Runnable runnable) {
return new FoliaScheduledTask(asyncScheduler.runNow(plugin, task -> runnable.run()));
}
@Override
public MyScheduledTask runTaskLaterAsynchronously(Runnable runnable, long delay) {
//Folia exception: Delay ticks may not be <= 0
delay = getOneIfNotPositive(delay);
return new FoliaScheduledTask(asyncScheduler.runDelayed(plugin, task -> runnable.run(), delay * 50L, TimeUnit.MILLISECONDS));
}
@Override
public MyScheduledTask runTaskTimerAsynchronously(Runnable runnable, long delay, long period) {
return new FoliaScheduledTask(asyncScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay * 50, period * 50, TimeUnit.MILLISECONDS));
}
@Override
public MyScheduledTask runTaskAsynchronously(Plugin plugin, Runnable runnable) {
return new FoliaScheduledTask(asyncScheduler.runNow(plugin, task -> runnable.run()));
}
@Override
public MyScheduledTask runTaskLaterAsynchronously(Plugin plugin, Runnable runnable, long delay) {
//Folia exception: Delay ticks may not be <= 0
delay = getOneIfNotPositive(delay);
return new FoliaScheduledTask(asyncScheduler.runDelayed(plugin, task -> runnable.run(), delay * 50L, TimeUnit.MILLISECONDS));
}
@Override
public MyScheduledTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
//Folia exception: Delay ticks may not be <= 0
delay = getOneIfNotPositive(delay);
return new FoliaScheduledTask(asyncScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay * 50, period * 50, TimeUnit.MILLISECONDS));
}
@Override
public void execute(Runnable runnable) {
globalRegionScheduler.execute(plugin, runnable);
}
@Override
public void execute(Location location, Runnable runnable) {
regionScheduler.execute(plugin, location, runnable);
}
@Override
public void execute(Entity entity, Runnable runnable) {
entity.getScheduler().execute(plugin, runnable, null, 1L);
}
@Override
public void cancelTasks() {
globalRegionScheduler.cancelTasks(plugin);
asyncScheduler.cancelTasks(plugin);
}
@Override
public void cancelTasks(Plugin plugin) {
globalRegionScheduler.cancelTasks(plugin);
asyncScheduler.cancelTasks(plugin);
}
private long getOneIfNotPositive(long x) {
return x <= 0 ? 1L : x;
}
}

View File

@@ -1,41 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler.paper;
import me.clip.placeholderapi.scheduler.folia.FoliaScheduler;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
//Thanks to Towny
public class PaperScheduler extends FoliaScheduler {
public PaperScheduler(Plugin plugin) {
super(plugin);
}
@Override
public boolean isGlobalThread() {
// isGlobalThread does not exist on paper, match the bukkit task scheduler's behaviour.
return Bukkit.getServer().isPrimaryThread();
}
}

View File

@@ -1,346 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler.scheduling.schedulers;
import me.clip.placeholderapi.scheduler.scheduling.tasks.MyScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
public interface TaskScheduler {
/**
* <b>Folia</b>: Returns whether the current thread is ticking the global region <br>
* <b>Paper and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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(FoliaandPaper) 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

@@ -1,53 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2023 Sevastjan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.clip.placeholderapi.scheduler.scheduling.tasks;
import org.bukkit.plugin.Plugin;
public interface MyScheduledTask {
/**
* Cancels executing task
*/
void cancel();
/**
* @return true if task is cancelled, false otherwise
*/
boolean isCancelled();
/**
* @return The plugin under which the task was scheduled.
*/
Plugin getOwningPlugin();
/**
* @return true if task is currently executing, false otherwise
*/
boolean isCurrentlyRunning();
/**
* @return true if task is repeating, false otherwise
*/
boolean isRepeatingTask();
}

View File

@@ -1,12 +0,0 @@
package me.clip.placeholderapi.scheduler.utils;
public class JavaUtil {
public static boolean classExists(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}

View File

@@ -1,128 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.updatechecker;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class UpdateChecker implements Listener {
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 plugin) {
this.plugin = plugin;
scheduler = plugin.getScheduler();
pluginVersion = plugin.getDescription().getVersion();
}
public boolean hasUpdateAvailable() {
return updateAvailable;
}
public String getSpigotVersion() {
return spigotVersion;
}
public void fetch() {
scheduler.runTaskAsynchronously(() -> {
try {
HttpsURLConnection con = (HttpsURLConnection) new URL(
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
con.setRequestMethod("GET");
spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
} catch (Exception ex) {
plugin.getLogger().info("Failed to check for updates on spigot.");
return;
}
if (spigotVersion == null || spigotVersion.isEmpty()) {
return;
}
updateAvailable = spigotIsNewer();
if (!updateAvailable) {
return;
}
scheduler.runTask(() -> {
plugin.getLogger()
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
plugin.getLogger()
.info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/");
Bukkit.getPluginManager().registerEvents(this, plugin);
});
});
}
private boolean spigotIsNewer() {
if (spigotVersion == null || spigotVersion.isEmpty()) {
return false;
}
int[] plV = toReadable(pluginVersion);
int[] spV = toReadable(spigotVersion);
if (plV[0] < spV[0]) {
return true;
} else if ((plV[1] < spV[1])) {
return true;
} else {
return plV[2] < spV[2];
}
}
private int[] toReadable(String version) {
if (version.contains("-DEV")) {
version = version.split("-DEV")[0];
}
return Arrays.stream(version.split("\\.")).mapToInt(Integer::parseInt).toArray();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onJoin(PlayerJoinEvent e) {
if (e.getPlayer().hasPermission("placeholderapi.updatenotify")) {
Msg.msg(e.getPlayer(),
"&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getSpigotVersion()
+ "&e)"
, "&bis available at &ehttps://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID
+ "/");
}
}
}

View File

@@ -1,80 +0,0 @@
package me.clip.placeholderapi.util;
import com.google.common.hash.Hashing;
import com.google.common.io.Files;
import com.google.common.io.Resources;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;
public final class ExpansionSafetyCheck {
private static final String MESSAGE =
"\n###############################################\n" +
"###############################################\n" +
"PlaceholderAPI performs checks at startup and /papi reload for known malicious expansions. If you're seeing this message, there are the following malicious expansions in plugins/PlaceholderAPI/expansions.\n" +
"%s" +
"To prevent further infection PlaceholderAPI has stopped the server.\n" +
"If you're seeing this message after updating PAPI, your server may have been infected for some time, so best practice is a complete system wipe and reinstall of your server software and plugins to be safe.\n" +
"If you're seeing this after downloading an expansion however, PAPI hasn't loaded any of the malicious expansions above so you should be safe to simply delete the expansion in question.\n" +
"###############################################\n" +
"###############################################";
private final PlaceholderAPIPlugin main;
public ExpansionSafetyCheck(@NotNull final PlaceholderAPIPlugin main) {
this.main = main;
}
public boolean runChecks() {
if (!main.getPlaceholderAPIConfig().detectMaliciousExpansions()) {
return false;
}
final File expansionsFolder = new File(main.getDataFolder(), "expansions");
if (!expansionsFolder.exists()) {
return false;
}
final Set<String> knownMaliciousExpansions;
try {
final String hashes = Resources.toString(new URL("https://check.placeholderapi.com"), StandardCharsets.UTF_8);
knownMaliciousExpansions = Arrays.stream(hashes.split("\n")).collect(Collectors.toSet());
} catch (Exception e) {
main.getLogger().log(Level.SEVERE, "Failed to download anti malware hash check list from https://check.placeholderapi.com", e);
return false;
}
final Set<String> maliciousPaths = new HashSet<>();
for (File file : expansionsFolder.listFiles()) {
try {
final String hash = Hashing.sha256().hashBytes(Files.asByteSource(file).read()).toString();
if (knownMaliciousExpansions.contains(hash)) {
maliciousPaths.add(file.getAbsolutePath());
}
} catch (Exception e) {
main.getLogger().log(Level.SEVERE, "Error occurred while trying to read " + file.getAbsolutePath(), e);
}
}
if (maliciousPaths.isEmpty()) {
return false;
}
main.getLogger().severe(String.format(MESSAGE, maliciousPaths.stream().map(p -> "HASH OF " + p + " MATCHES KNOWN MALICIOUS EXPANSION DELETE IMMEDIATELY\n").collect(Collectors.joining())));
main.getServer().shutdown();
return true;
}
}

View File

@@ -1,80 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.util;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.stream.Collectors;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
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;
}
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

@@ -10,10 +10,9 @@
# Download placeholders: /papi ecloud # Download placeholders: /papi ecloud
check_updates: true check_updates: true
cloud_enabled: true cloud_enabled: true
cloud_sorting: "name" cloud_sorting: "NAME"
boolean: boolean_value:
'true': 'yes' true_value: 'yes'
'false': 'no' false_value: 'no'
date_format: MM/dd/yy HH:mm:ss date_format: MM/dd/yy HH:mm:ss
detect_malicious_expansions: true
debug: false debug: false

View File

@@ -0,0 +1,14 @@
{
"Group": "HelpChat",
"Name": "PlaceholderAPI",
"Version": "${version}",
"Description": "An awesome placeholder provider",
"Authors": [{"Name": "HelpChat"}],
"Website": "https://placeholderapi.com",
"ServerVersion": "*",
"Dependencies": {},
"OptionalDependencies": {},
"DisabledByDefault": false,
"Main": "at.helpch.placeholderapi.PlaceholderAPIPlugin",
"IncludesAssetPack": false
}

View File

@@ -1,99 +0,0 @@
name: PlaceholderAPI
main: "me.clip.placeholderapi.PlaceholderAPIPlugin"
folia-supported: true
version: ${version}
author: HelpChat
api-version: "1.13"
description: "An awesome placeholder provider!"
commands:
placeholderapi:
description: "PlaceholderAPI Command"
aliases: ["papi"]
permissions:
placeholderapi.*:
description: "Ability to use all PAPI commands"
children:
placeholderapi.admin: true
placeholderapi.ecloud.*: true
placeholderapi.admin:
description: "Ability to use all PAPI commands"
children:
placeholderapi.help: true
placeholderapi.info: true
placeholderapi.list: true
placeholderapi.parse: true
placeholderapi.reload: true
placeholderapi.version: true
placeholderapi.register: true
placeholderapi.unregister: true
placeholderapi.updatenotify: true
placeholderapi.ecloud.*:
description: "Ability to use all PAPI ecloud commands"
children:
placeholderapi.ecloud: true
placeholderapi.ecloud.info: true
placeholderapi.ecloud.list: true
placeholderapi.ecloud.clear: true
placeholderapi.ecloud.status: true
placeholderapi.ecloud.update: true
placeholderapi.ecloud.refresh: true
placeholderapi.ecloud.download: true
placeholderapi.ecloud.placeholders: true
placeholderapi.help:
default: "op"
description: "Allows you to view the list of PAPI commands"
placeholderapi.info:
default: "op"
description: "Allows you to view expansion information"
placeholderapi.list:
default: "op"
description: "Allows you to list active expansions"
placeholderapi.ecloud:
default: "op"
description: "Allows you to access PAPI eCloud"
placeholderapi.parse:
default: "op"
description: "Allows you to parse placeholders"
placeholderapi.reload:
default: "op"
description: "Allows you to reload PAPI and its configuration"
placeholderapi.version:
default: "op"
description: "Allows you to view the version of PAPI installed"
placeholderapi.register:
default: "op"
description: "Allows you to register expansions"
placeholderapi.unregister:
default: "op"
description: "Allows you to unregister expansions"
placeholderapi.updatenotify:
default: "op"
description: "Notifies you when there is a PAPI update"
placeholderapi.ecloud.info:
default: "op"
description: "Allows you to view cloud expansion information"
placeholderapi.ecloud.list:
default: "op"
description: "Allows you to list eCloud expansions"
placeholderapi.ecloud.clear:
default: "op"
description: "Allows you to clear the local eCloud expansion cache"
placeholderapi.ecloud.status:
default: "op"
description: "Allows you to view the status of eCloud expansions"
placeholderapi.ecloud.update:
default: "op"
description: "Allows you to update registered eCloud expansions"
placeholderapi.ecloud.refresh:
default: "op"
description: "Allows you to refresh the local eCloud expansion cache"
placeholderapi.ecloud.download:
default: "op"
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"

View File

@@ -1,180 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi;
import me.clip.placeholderapi.replacer.ExactReplacer;
import me.clip.placeholderapi.replacer.RelationalExactReplacer;
import me.clip.placeholderapi.replacer.Replacer;
import net.kyori.adventure.text.Component;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
import static me.clip.placeholderapi.PlaceholderAPI.RELATIONAL_PLACEHOLDER_PATTERN;
public final class PAPIComponents {
private static final Replacer PERCENT_EXACT_REPLACER = new ExactReplacer('%', '%');
private static final Replacer BRACKET_EXACT_REPLACER = new ExactReplacer('{', '}');
private static final RelationalExactReplacer RELATIONAL_EXACT_REPLACER = new RelationalExactReplacer();
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param component Component to set the placeholder values in
* @return Component containing all translated placeholders
*/
@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(PERCENT_EXACT_REPLACER.apply(result.group(), player, PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion))));
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param components List of Components to set the placeholder values in
* @return List of Components containing all translated placeholders
*/
@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());
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param component Component to set the placeholder values in
* @return Component containing all translated placeholders
*/
@NotNull
public static Component setPlaceholders(final Player player, @NotNull final Component component) {
return setPlaceholders((OfflinePlayer) player, component);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal %<identifier>_<params>%}.
*
* @param player Player to parse the placeholders against
* @param components List of Components to set the placeholder values in
* @return List of components containing all translated placeholders
*/
@NotNull
public static List<Component> setPlaceholders(final Player player, @NotNull final List<Component> components) {
return setPlaceholders((OfflinePlayer) player, components);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param component Component to set the placeholder values in
* @return Component containing all translated placeholders
*/
@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(BRACKET_EXACT_REPLACER.apply(result.group(), player, PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion))));
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param components List of Components to set the placeholder values in
* @return List of Components containing all translated placeholders
*/
@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());
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param component Component to set the placeholder values in
* @return Component containing all translated placeholders
*/
@NotNull
public static Component setBracketPlaceholders(final Player player, @NotNull final Component component) {
return setBracketPlaceholders((OfflinePlayer) player, component);
}
/**
* Translates all placeholders into their corresponding values.
* <br>The pattern of a valid placeholder is {@literal {<identifier>_<params>}}.
*
* @param player Player to parse the placeholders against
* @param components List of Components to set the placeholder values in
* @return List of Components containing all translated placeholders
*/
@NotNull
public static List<Component> setBracketPlaceholders(final Player player, @NotNull final List<Component> components) {
return setBracketPlaceholders((OfflinePlayer) player, components);
}
/**
* set relational placeholders in the text specified placeholders are matched with the pattern
* {@literal %<rel_(identifier)_(params)>%} when set with this method
*
* @param one First player to compare
* @param two Second player to compare
* @param component Component to parse the placeholders in
* @return The Component containing the parsed relational placeholders
*/
public static Component setRelationalPlaceholders(Player one, Player two, Component component) {
return component.replaceText(config -> config.match(RELATIONAL_PLACEHOLDER_PATTERN).replacement((result, builder) ->
builder.content(RELATIONAL_EXACT_REPLACER.apply(result.group(2), one, two, PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion))));
}
/**
* Translate placeholders in the provided List based on the relation of the two provided players.
* <br>The pattern of a valid placeholder is {@literal %rel_<identifier>_<param>%}.
*
* @param one Player to compare
* @param two Player to compare
* @param components List of Components to parse the placeholder values to
* @return The List of Components containing the parsed relational placeholders
*/
public static List<Component> setRelationalPlaceholders(Player one, Player two, List<Component> components) {
return components.stream().map(line -> setRelationalPlaceholders(one, two, line))
.collect(Collectors.toList());
}
// kyori doesn't seem to have a method that can do a contains with regex, we don't want to do a more expensive replace
// public static boolean containsPlaceholders(@Nullable final Component text) {
// return text != null && text.replaceText()
// }
}

View File

@@ -1,76 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.replacer;
import 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 final class ExactReplacer implements Replacer {
private static final Pattern DELIMITER = Pattern.compile("_");
private final char start;
private final char end;
public ExactReplacer(final char start, final char end) {
this.start = start;
this.end = end;
}
@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 start + text + end;
}
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 start + text + end;
}
return result;
}
}

View File

@@ -1,73 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.replacer;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.Relational;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Function;
import java.util.regex.Pattern;
public final class RelationalExactReplacer {
private static final Pattern DELIMITER = Pattern.compile("_");
@NotNull
public String apply(@NotNull String text, @Nullable final Player player1,
@Nullable final Player player2, @NotNull final Function<String,
@Nullable PlaceholderExpansion> lookup) {
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 "%rel_" + text + '%';
}
if (!(expansion instanceof Relational)) {
return "%rel_" + text + '%';
}
final String params;
if (text.endsWith("_")) {
params = "";
} else {
params = text.substring(text.indexOf('_') + 1);
}
final String result = ((Relational) expansion).onPlaceholderRequest(player1, player2, params);
if (result == null) {
return "%rel_" + text + '%';
}
return result;
}
}

View File

@@ -1,93 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi;
import com.google.common.collect.ImmutableMap;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.replacer.CharsReplacer;
import me.clip.placeholderapi.replacer.Replacer;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface Values {
String SMALL_TEXT = "My name is %player_name%";
String LARGE_TEXT = "My name is %player_name% and my location is (%player_x%, %player_y%, %player_z%), this placeholder is invalid %server_name%";
ImmutableMap<String, PlaceholderExpansion> PLACEHOLDERS = ImmutableMap.<String, PlaceholderExpansion>builder()
.put("player", new MockPlayerPlaceholderExpansion())
.build();
Replacer CHARS_REPLACER = new CharsReplacer(Replacer.Closure.PERCENT);
final class MockPlayerPlaceholderExpansion extends PlaceholderExpansion {
public static final String PLAYER_X = "10";
public static final String PLAYER_Y = "20";
public static final String PLAYER_Z = "30";
public static final String PLAYER_NAME = "Sxtanna";
@NotNull
@Override
public String getIdentifier() {
return "player";
}
@NotNull
@Override
public String getAuthor() {
return "Sxtanna";
}
@NotNull
@Override
public String getVersion() {
return "1.0";
}
@Override
public String onRequest(@Nullable final OfflinePlayer player, @NotNull final String params) {
final String[] parts = params.split("_");
if (parts.length == 0) {
return null;
}
switch (parts[0]) {
case "name":
return PLAYER_NAME;
case "x":
return PLAYER_X;
case "y":
return PLAYER_Y;
case "z":
return PLAYER_Z;
}
return null;
}
}
}

View File

@@ -1,63 +0,0 @@
/*
* This file is part of PlaceholderAPI
*
* PlaceholderAPI
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
*
* PlaceholderAPI free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlaceholderAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.clip.placeholderapi.replacer;
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_NAME;
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_X;
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_Y;
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_Z;
import static org.junit.jupiter.api.Assertions.assertEquals;
import me.clip.placeholderapi.Values;
import org.junit.jupiter.api.Test;
public final class ReplacerUnitTester {
@Test
void testCharsReplacerProducesExpectedSingleValue() {
assertEquals(PLAYER_NAME,
Values.CHARS_REPLACER.apply("%player_name%", null, Values.PLACEHOLDERS::get));
}
@Test
void testCharsReplacerProducesExpectedSentence() {
assertEquals(String.format(
"My name is %s and my location is (%s, %s, %s), this placeholder is invalid %%server_name%%",
PLAYER_NAME, PLAYER_X, PLAYER_Y, PLAYER_Z),
Values.CHARS_REPLACER.apply(Values.LARGE_TEXT, null, Values.PLACEHOLDERS::get));
}
@Test
void testResultsAreTheSameAsReplacement() {
final String resultChars = Values.CHARS_REPLACER
.apply("%player_name%", null, Values.PLACEHOLDERS::get);
assertEquals(PLAYER_NAME, resultChars);
}
@Test
void testCharsReplacerIgnoresMalformed() {
final String text = "10% and %hello world 15%";
assertEquals(text, Values.CHARS_REPLACER.apply(text, null, Values.PLACEHOLDERS::get));
}
}