mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-11-05 02:10:57 +01:00
Re-implement PlaceholderAPI as normal placeholder
This commit is contained in:
parent
69f2ecbd23
commit
911170e50c
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user