更新
This commit is contained in:
41
src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java
Normal file
41
src/main/java/com/ilummc/tlib/compat/PlaceholderHook.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.ilummc.tlib.compat;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
|
||||
public abstract class PlaceholderHook {
|
||||
|
||||
private static PlaceholderHook impl;
|
||||
|
||||
public static void init() {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null)
|
||||
impl = new PlaceholderImpl();
|
||||
else impl = new AbstractImpl();
|
||||
}
|
||||
|
||||
public static String replace(CommandSender sender, String text) {
|
||||
return sender instanceof Player ? impl.replace(((Player) sender), text) : text;
|
||||
}
|
||||
|
||||
abstract String replace(Player player, String text);
|
||||
|
||||
private static class PlaceholderImpl extends PlaceholderHook {
|
||||
|
||||
@Override
|
||||
String replace(Player player, String text) {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static class AbstractImpl extends PlaceholderHook {
|
||||
|
||||
@Override
|
||||
String replace(Player player, String text) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user