Compare commits

..
Author SHA1 Message Date
PiggyPiglet 96701da560 move folder debug msg above listfiles 2026-07-06 06:59:17 +08:00
PiggyPiglet ccf520a1b0 debug msgs 2026-07-06 06:54:38 +08:00
Funnycube 7d21d2f1d7 2.12.4 dev 2026-07-03 21:49:43 +10:00
Funnycube 31a050af54 2.12.3 release 2026-07-03 21:21:05 +10:00
10 changed files with 59 additions and 195 deletions

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ plugins {
}
group = "me.clip"
version = "2.12.3-DEV-${System.getProperty("BUILD_NUMBER")}"
version = "2.12.4-DEV-${System.getProperty("BUILD_NUMBER")}"
description = "An awesome placeholder provider!"
@@ -65,8 +65,8 @@ public final class PlaceholderAPI {
@NotNull
public static String setPlaceholders(final OfflinePlayer player,
@NotNull final String text) {
final LocalExpansionManager manager = PlaceholderAPIPlugin.getInstance().getLocalExpansionManager();
return REPLACER_PERCENT.apply(text, player, manager::getExpansion, manager::resolvePlaceholderValue);
return REPLACER_PERCENT.apply(text, player,
PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion);
}
/**
@@ -124,8 +124,8 @@ public final class PlaceholderAPI {
@NotNull
public static String setBracketPlaceholders(final OfflinePlayer player,
@NotNull final String text) {
final LocalExpansionManager manager = PlaceholderAPIPlugin.getInstance().getLocalExpansionManager();
return REPLACER_BRACKET.apply(text, player, manager::getExpansion, manager::resolvePlaceholderValue);
return REPLACER_BRACKET.apply(text, player,
PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()::getExpansion);
}
/**
@@ -35,40 +35,8 @@ public abstract class PlaceholderHook {
return onPlaceholderRequest(null, params);
}
/**
* Override this method when a placeholder should return a non-string value for type handling.
* <br>The default delegates to {@link #onPlaceholderTypeHandledRequest(Player, String)} with an online
* {@link Player}, matching the behavior of {@link #onRequest(OfflinePlayer, String)}.
*
* @param player Player to parse the placeholder against
* @param params Placeholder parameters
* @return Object to resolve through type handlers, or null to leave the placeholder unchanged
*/
@Nullable
public Object onTypeHandledRequest(final OfflinePlayer player, @NotNull final String params) {
if (player != null && player.isOnline()) {
return onPlaceholderTypeHandledRequest(player.getPlayer(), params);
}
return onPlaceholderTypeHandledRequest(null, params);
}
@Nullable
public String onPlaceholderRequest(final Player player, @NotNull final String params) {
return null;
}
/**
* Override this method when a player placeholder should return a non-string value for type handling.
* <br>The default returns null so legacy string placeholders are only resolved through
* {@link #onRequest(OfflinePlayer, String)}.
*
* @param player Online player to parse the placeholder against
* @param params Placeholder parameters
* @return Object to resolve through type handlers, or null to leave the placeholder unchanged
*/
@Nullable
public Object onPlaceholderTypeHandledRequest(final Player player, @NotNull final String params) {
return null;
}
}
@@ -91,6 +91,8 @@ public final class CommandDump extends PlaceholderCommand {
@NotNull
private CompletableFuture<String> postDump(@NotNull final String dump) {
System.out.println("DUMP CREATE SUCCESS");
return CompletableFuture.supplyAsync(() -> {
try {
final HttpURLConnection connection = ((HttpURLConnection) new URL(URL + "documents")
@@ -110,6 +112,7 @@ public final class CommandDump extends PlaceholderCommand {
return gson.fromJson(json, JsonObject.class).get("key").getAsString();
}
} catch (final IOException ex) {
ex.printStackTrace();
throw new CompletionException(ex);
}
});
@@ -123,6 +126,8 @@ public final class CommandDump extends PlaceholderCommand {
.append(DATE_FORMAT.format(Instant.now()))
.append("\n\n");
System.out.println("DUMP1");
builder.append("PlaceholderAPI: ")
.append(plugin.getDescription().getVersion())
.append("\n\n");
@@ -130,6 +135,8 @@ public final class CommandDump extends PlaceholderCommand {
builder.append("Expansions Registered:")
.append('\n');
System.out.println("DUMP2");
final List<PlaceholderExpansion> expansions = plugin.getLocalExpansionManager()
.getExpansions()
.stream()
@@ -139,6 +146,8 @@ public final class CommandDump extends PlaceholderCommand {
)
.collect(Collectors.toList());
System.out.println("DUMP3");
int size = expansions.stream().map(e -> e.getIdentifier().length())
.max(Integer::compareTo)
.orElse(0);
@@ -163,6 +172,7 @@ public final class CommandDump extends PlaceholderCommand {
.getExpansionsFolder()
.list((dir, name) -> name.toLowerCase(Locale.ROOT).endsWith(".jar"));
System.out.println("DUMP4");
if (jars == null) {
builder.append(" ¨[Warning]: Could not load jar files from expansions folder.");
@@ -182,10 +192,14 @@ public final class CommandDump extends PlaceholderCommand {
.append(plugin.getServer().getVersion())
.append("\n");
System.out.println("DUMP5");
builder.append("Java Version: ")
.append(System.getProperty("java.version"))
.append("\n\n");
System.out.println("DUMP6");
builder.append("Plugin Info:")
.append('\n');
@@ -193,6 +207,8 @@ public final class CommandDump extends PlaceholderCommand {
.sorted(Comparator.comparing(Plugin::getName))
.collect(Collectors.toList());
System.out.println("DUMP7");
size = plugins.stream().map(pl -> pl.getName().length())
.max(Integer::compareTo)
.orElse(0);
@@ -208,6 +224,8 @@ public final class CommandDump extends PlaceholderCommand {
.append("\n");
}
System.out.println("DUMP8");
return builder.toString();
}
}
@@ -1,33 +0,0 @@
package me.clip.placeholderapi.expansion;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class PlaceholderContext<T> {
@Nullable private final Player player;
@NotNull private final T type;
@NotNull private final String args;
public PlaceholderContext(@Nullable final Player player, @NotNull final T type,
@NotNull final String args) {
this.player = player;
this.type = type;
this.args = args;
}
@Nullable
public Player player() {
return player;
}
@NotNull
public T type() {
return type;
}
@NotNull
public String args() {
return args;
}
}
@@ -20,7 +20,6 @@
package me.clip.placeholderapi.expansion;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
@@ -141,10 +140,6 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|| Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null;
}
public Collection<TypeHandler<?>> provideTypeHandlers() {
return Collections.emptyList();
}
/**
* Attempt to register this PlaceholderExpansion
*
@@ -1,15 +0,0 @@
package me.clip.placeholderapi.expansion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface TypeHandler<T> {
Class<T> typeClass();
default boolean includeDerivatives() {
return true;
}
@Nullable
String onRequest(@NotNull final PlaceholderContext<T> context);
}
@@ -44,16 +44,19 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.events.ExpansionRegisterEvent;
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
import me.clip.placeholderapi.events.ExpansionsLoadedEvent;
import me.clip.placeholderapi.expansion.*;
import me.clip.placeholderapi.expansion.Cacheable;
import me.clip.placeholderapi.expansion.Cleanable;
import me.clip.placeholderapi.expansion.Configurable;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.Taskable;
import me.clip.placeholderapi.expansion.VersionSpecific;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
import me.clip.placeholderapi.util.FileUtil;
import me.clip.placeholderapi.util.Futures;
import me.clip.placeholderapi.util.Msg;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
@@ -83,7 +86,6 @@ public final class LocalExpansionManager implements Listener {
@NotNull
private final Map<String, PlaceholderExpansion> expansions = new ConcurrentHashMap<>();
private final Map<Class<?>, TypeHandler> typeHandlers = new ConcurrentHashMap<>();
private final ReentrantLock expansionsLock = new ReentrantLock();
@@ -206,64 +208,6 @@ public final class LocalExpansionManager implements Listener {
return Optional.empty();
}
@Nullable
public String resolvePlaceholderValue(@NotNull final PlaceholderExpansion expansion, @Nullable final OfflinePlayer player,
@NotNull final String args) {
Object value = expansion.onRequest(player, args);
if (value != null) {
return (String) value;
}
value = expansion.onTypeHandledRequest(player, args);
if (value instanceof String) {
return (String) value;
}
if (value != null) {
return resolveTypeHandler(value, player, args);
}
return null;
}
@Nullable
public String resolveTypeHandler(@NotNull final Object value, @Nullable final OfflinePlayer player,
@NotNull final String args) {
TypeHandler handler = null;
for (final TypeHandler<?> typeHandler : typeHandlers.values()) {
if (typeHandler.typeClass() == value.getClass()) {
handler = typeHandler;
}
}
if (handler == null) {
for (final TypeHandler<?> typeHandler : typeHandlers.values()) {
if (typeHandler.includeDerivatives() && typeHandler.typeClass().isAssignableFrom(value.getClass())) {
handler = typeHandler;
}
}
}
if (handler == null) {
Msg.warn("Failed to resolve type handler for placeholder %s and type %s", args, value.getClass().getSimpleName());
return null;
}
return handler.onRequest(new PlaceholderContext<>(player(player), value, args));
}
@Nullable
private Player player(@Nullable final OfflinePlayer player) {
if (player == null || !player.isOnline()) {
return null;
}
return player.getPlayer();
}
/**
* Attempt to register a {@link PlaceholderExpansion}
*
@@ -284,16 +228,6 @@ public final class LocalExpansionManager implements Listener {
return false;
}
for (final TypeHandler<?> typeHandler : expansion.provideTypeHandlers()) {
if (typeHandler.typeClass().isAssignableFrom(String.class)) {
Msg.warn("Failed to load type handler %s from expansion %s as there is already a type handler for this type.",
expansion.getIdentifier(), typeHandler.typeClass().getSimpleName());
continue;
}
typeHandlers.putIfAbsent(typeHandler.typeClass(), typeHandler);
}
if (expansion instanceof Configurable) {
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
String pre = "expansions." + identifier + ".";
@@ -417,13 +351,19 @@ public final class LocalExpansionManager implements Listener {
Msg.info("Placeholder expansion registration initializing...");
Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> {
System.out.println("LOAD1");
if (exception != null) {
Msg.severe("Failed to load class files of expansion.", exception);
exception.printStackTrace();
return;
}
System.out.println("LOAD2 - size: " + classes.size());
final List<PlaceholderExpansion> registered = classes.stream()
.filter(Objects::nonNull)
.peek(clazz -> System.out.println("Attempting register of - " + clazz))
.map(this::register)
.filter(Optional::isPresent)
.map(Optional::get)
@@ -452,6 +392,8 @@ public final class LocalExpansionManager implements Listener {
Msg.msg(sender, message.toString());
Bukkit.getPluginManager().callEvent(new ExpansionsLoadedEvent(registered));
System.out.println("LOAD3");
});
}
@@ -467,7 +409,12 @@ public final class LocalExpansionManager implements Listener {
@NotNull
public CompletableFuture<@NotNull List<@Nullable Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() {
System.out.println(folder);
File[] files = folder.listFiles((dir, name) -> name.endsWith(".jar"));
System.out.println("FIND FILES - " + Arrays.toString(files));
if (files == null) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
@@ -480,6 +427,8 @@ public final class LocalExpansionManager implements Listener {
@NotNull
public CompletableFuture<@Nullable Class<? extends PlaceholderExpansion>> findExpansionInFile(
@NotNull final File file) {
System.out.println("FOUND FILE - " + file);
return CompletableFuture.supplyAsync(() -> {
try {
final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class);
@@ -47,17 +47,15 @@ public final class CharsReplacer implements Replacer {
* @param text The raw text containing potential placeholders to be replaced.
* @param player The {@link OfflinePlayer} to contextually parse the placeholders against.
* May be {@code null} if no player context is available.
* @param lookup A function that maps a lowercase identifier string to a registered
* {@link PlaceholderExpansion}.
* @param resolver Resolves a registered {@link PlaceholderExpansion} to its replacement value.
* @return A string with all valid placeholders replaced by their respective values.
* Returns the original text if no placeholders are found.
*/
@NotNull
@Override
public String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup,
@NotNull final PlaceholderResolver resolver) {
* @param lookup A function that maps a lowercase identifier string to a registered
* {@link PlaceholderExpansion}.
* @return A string with all valid placeholders replaced by their respective values.
* Returns the original text if no placeholders are found.
*/
@NotNull
@Override
public String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup) {
final char head = closure.head;
int startPlaceholder = text.indexOf(head);
@@ -124,10 +122,10 @@ public final class CharsReplacer implements Replacer {
final PlaceholderExpansion expansion = lookup.apply(identifier.toLowerCase(Locale.ROOT));
String replacement = null;
if (expansion != null) {
replacement = resolver.resolve(expansion, player, parameters);
}
if (expansion != null) {
replacement = expansion.onRequest(player, parameters);
}
if (replacement != null) {
builder.append(replacement);
@@ -150,4 +148,4 @@ public final class CharsReplacer implements Replacer {
return builder.toString();
}
}
}
@@ -29,26 +29,10 @@ import org.jetbrains.annotations.Nullable;
public interface Replacer {
@NotNull
default String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup) {
return apply(text, player, lookup, PlaceholderExpansion::onRequest);
}
@NotNull
String apply(@NotNull final String text, @Nullable final OfflinePlayer player,
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup,
@NotNull final PlaceholderResolver resolver);
@NotNull final Function<String, @Nullable PlaceholderExpansion> lookup);
@FunctionalInterface
interface PlaceholderResolver {
@Nullable
String resolve(@NotNull final PlaceholderExpansion expansion,
@Nullable final OfflinePlayer player,
@NotNull final String params);
}
enum Closure {
BRACKET('{', '}'),