feat(core-bukkit): 当安装 PlaceholderAPI 时自动替换 UI 变量

This commit is contained in:
2024-03-14 23:49:57 +08:00
parent d594dea3d7
commit 258bb9ac4f
4 changed files with 15 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ package cn.hamster3.mc.plugin.core.bukkit.page.handler;
import cn.hamster3.mc.plugin.core.bukkit.page.ButtonGroup;
import cn.hamster3.mc.plugin.core.bukkit.page.PageConfig;
import cn.hamster3.mc.plugin.core.bukkit.page.PageManager;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.HumanEntity;
@@ -118,6 +119,9 @@ public abstract class PageHandler implements InventoryHolder {
@NotNull
public String getTitle() {
String title = pageConfig.getTitle();
if (player instanceof Player && Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
title = PlaceholderAPI.setPlaceholders((Player) player, title);
}
for (Map.Entry<String, String> entry : getPageVariables().entrySet()) {
title = title.replace(entry.getKey(), entry.getValue());
}

View File

@@ -390,21 +390,25 @@ public final class CoreBukkitUtils {
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
command = PlaceholderAPI.setPlaceholders(player, command);
}
String[] split = command.split(":", 2);
switch (split[0]) {
String[] args = command.split(":", 2);
switch (args[0]) {
case "player": {
Bukkit.dispatchCommand(player, split[1]);
Bukkit.dispatchCommand(player, args[1]);
break;
}
case "console": {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), split[1]);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), args[1]);
break;
}
case "message": {
player.sendMessage(args[1]);
break;
}
case "op": {
boolean op = player.isOp();
player.setOp(true);
try {
Bukkit.dispatchCommand(player, split[1]);
Bukkit.dispatchCommand(player, args[1]);
} finally {
player.setOp(op);
}

View File

@@ -12,6 +12,7 @@ load: STARTUP
softdepend:
- Vault
- PlayerPoints
- PlaceholderAPI
loadbefore:
- HamsterAPI