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

@@ -5,7 +5,7 @@ plugins {
} }
group = "cn.hamster3.mc.plugin" group = "cn.hamster3.mc.plugin"
version = "1.3.0" version = "1.3.1"
subprojects { subprojects {
apply { apply {

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.ButtonGroup;
import cn.hamster3.mc.plugin.core.bukkit.page.PageConfig; import cn.hamster3.mc.plugin.core.bukkit.page.PageConfig;
import cn.hamster3.mc.plugin.core.bukkit.page.PageManager; import cn.hamster3.mc.plugin.core.bukkit.page.PageManager;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
@@ -118,6 +119,9 @@ public abstract class PageHandler implements InventoryHolder {
@NotNull @NotNull
public String getTitle() { public String getTitle() {
String title = pageConfig.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()) { for (Map.Entry<String, String> entry : getPageVariables().entrySet()) {
title = title.replace(entry.getKey(), entry.getValue()); title = title.replace(entry.getKey(), entry.getValue());
} }

View File

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

View File

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