Re-implement PlaceholderAPI as normal placeholder

This commit is contained in:
filoghost 2021-12-09 19:27:35 +01:00
parent 69f2ecbd23
commit 911170e50c
2 changed files with 52 additions and 0 deletions

View File

@ -114,6 +114,8 @@ public class DefaultPlaceholders {
placeholderRegistry.registerIndividualPlaceholder(plugin, "displayName", 20, (player, argument) -> {
return player.getDisplayName();
});
placeholderRegistry.registerIndividualPlaceholderFactory(plugin, "papi", new PlaceholderAPIPlaceholderFactory());
}
private static List<String> toStringList(ChatColor... colors) {

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.internal.placeholder;
import me.clip.placeholderapi.PlaceholderAPI;
import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholder;
import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderFactory;
import me.filoghost.holographicdisplays.plugin.bridge.placeholderapi.PlaceholderAPIHook;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PlaceholderAPIPlaceholderFactory implements IndividualPlaceholderFactory {
@Override
public @Nullable IndividualPlaceholder getPlaceholder(@Nullable String argument) {
if (argument == null) {
return null;
}
return new PlaceholderAPIPlaceholder("%" + argument + "%");
}
private static class PlaceholderAPIPlaceholder implements IndividualPlaceholder {
private final String content;
PlaceholderAPIPlaceholder(String content) {
this.content = content;
}
@Override
public int getRefreshIntervalTicks() {
return 1;
}
@Override
public @Nullable String getReplacement(@NotNull Player player, @Nullable String argument) {
if (!PlaceholderAPIHook.isEnabled()) {
return null;
}
return PlaceholderAPI.setPlaceholders(player, content);
}
}
}