mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-09-06 05:17:05 +02:00
updated to phase out PlaceholderHook
This commit is contained in:
@@ -181,40 +181,20 @@ public final class PlaceholderAPIPlugin extends JavaPlugin
|
||||
private void setupMetrics()
|
||||
{
|
||||
final Metrics metrics = new Metrics(this);
|
||||
metrics.addCustomChart(
|
||||
new Metrics.SimplePie(
|
||||
"using_expansion_cloud",
|
||||
() -> getPlaceholderAPIConfig().isCloudEnabled() ? "yes" : "no"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", () -> getPlaceholderAPIConfig().isCloudEnabled() ? "yes" : "no"));
|
||||
|
||||
metrics.addCustomChart(
|
||||
new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
|
||||
|
||||
metrics.addCustomChart(
|
||||
new Metrics.AdvancedPie(
|
||||
"expansions_used",
|
||||
() -> {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();
|
||||
metrics.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
|
||||
final Map<String, Integer> values = new HashMap<>();
|
||||
|
||||
if (!hooks.isEmpty())
|
||||
{
|
||||
for (final PlaceholderExpansion expansion : getLocalExpansionManager().getExpansions())
|
||||
{
|
||||
values.put(expansion.getRequiredPlugin() == null ? expansion.getIdentifier() : expansion.getRequiredPlugin(), 1);
|
||||
}
|
||||
|
||||
for (PlaceholderHook hook : hooks.values())
|
||||
{
|
||||
if (hook instanceof PlaceholderExpansion)
|
||||
{
|
||||
PlaceholderExpansion expansion = (PlaceholderExpansion) hook;
|
||||
map.put(
|
||||
expansion.getRequiredPlugin() == null
|
||||
? expansion.getIdentifier()
|
||||
: expansion.getRequiredPlugin(),
|
||||
1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}));
|
||||
return values;
|
||||
}));
|
||||
}
|
||||
|
||||
private void setupExpansions()
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package me.clip.placeholderapi.replacer;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -20,8 +20,9 @@ public final class CharsReplacer implements Replacer
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public @NotNull String apply(@NotNull final String text, @Nullable final OfflinePlayer player, @NotNull final Function<String, @Nullable PlaceholderHook> lookup)
|
||||
public String apply(@NotNull final String text, @Nullable final OfflinePlayer player, @NotNull final Function<String, @Nullable PlaceholderExpansion> lookup)
|
||||
{
|
||||
final char[] chars = text.toCharArray();
|
||||
final StringBuilder builder = new StringBuilder(text.length());
|
||||
@@ -142,7 +143,7 @@ public final class CharsReplacer implements Replacer
|
||||
continue;
|
||||
}
|
||||
|
||||
final PlaceholderHook placeholder = lookup.apply(identifierString);
|
||||
final PlaceholderExpansion placeholder = lookup.apply(identifierString);
|
||||
if (placeholder == null)
|
||||
{
|
||||
builder.append(closure.head).append(identifierString);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package me.clip.placeholderapi.replacer;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -22,8 +22,9 @@ public final class RegexReplacer implements Replacer
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public @NotNull String apply(@NotNull final String text, @Nullable final OfflinePlayer player, @NotNull final Function<String, @Nullable PlaceholderHook> lookup)
|
||||
public String apply(@NotNull final String text, @Nullable final OfflinePlayer player, @NotNull final Function<String, @Nullable PlaceholderExpansion> lookup)
|
||||
{
|
||||
final Matcher matcher = pattern.matcher(text);
|
||||
if (!matcher.find())
|
||||
@@ -38,13 +39,13 @@ public final class RegexReplacer implements Replacer
|
||||
final String identifier = matcher.group("identifier");
|
||||
final String parameters = matcher.group("parameters");
|
||||
|
||||
final PlaceholderHook hook = lookup.apply(identifier);
|
||||
if (hook == null)
|
||||
final PlaceholderExpansion expansion = lookup.apply(identifier);
|
||||
if (expansion == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final String requested = hook.onRequest(player, parameters);
|
||||
final String requested = expansion.onRequest(player, parameters);
|
||||
matcher.appendReplacement(builder, requested != null ? requested : matcher.group(0));
|
||||
}
|
||||
while (matcher.find());
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package me.clip.placeholderapi.replacer;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -11,7 +11,7 @@ public interface Replacer
|
||||
{
|
||||
|
||||
@NotNull
|
||||
String apply(@NotNull final String text, @Nullable final OfflinePlayer player, @NotNull final Function<String, @Nullable PlaceholderHook> lookup);
|
||||
String apply(@NotNull final String text, @Nullable final OfflinePlayer player, @NotNull final Function<String, @Nullable PlaceholderExpansion> lookup);
|
||||
|
||||
|
||||
enum Closure
|
||||
|
Reference in New Issue
Block a user