GamerulePlaceholder
轻量级 Paper 插件,通过 PlaceholderAPI 占位符暴露 Minecraft 游戏规则值。支持按名称查询任意世界以及玩家当前所在的世界。
依赖项
Paper 1.21.x(已在 1.21.6 上测试)。
服务器上已安装 PlaceholderAPI。
运行 Paper 1.21.x 需要 Java 21。
安装
将插件 JAR 文件放入服务器的 plugins/ 文件夹中。
确保已安装并启用 PlaceholderAPI。
重启服务器;扩展包将在启动时自动注册。
按世界方案的占位符
%gamerule_<rule>_<world>%
返回世界 <world> 中游戏规则 <rule> 的值。
示例:%gamerule_keepInventory_world% → “true” 或 “false”。
当前世界方案的占位符
%gamerule_currentworld_<rule>%
从请求玩家的当前世界中获取游戏规则值。
需要玩家上下文(例如,计分板、聊天、为解析玩家占位符的 GUI)。
示例:%gamerule_currentworld_doDaylightCycle%
备注
<rule> 必须与服务版本中的游戏规则名称完全匹配(例如 keepInventory、doDaylightCycle、playersSleepingPercentage)。
如果世界或游戏规则不存在,占位符将返回空字符串。
布尔型/整型游戏规则的返回值是纯文本(例如,“true”、“100”)。
使用示例
记分板:显示玩家在末地是否保留物品栏:%gamerule_keepInventory_world%
玩家上下文:显示日夜循环是否在玩家当前维度运行:%gamerule_currentworld_doDaylightCycle%
性能
该插件仅通过 Paper API 读取数值,不执行任何 I/O、循环或异步任务。即使占位符频繁更新(例如在记分板中),其开销也可忽略不计。
从源码构建
前置条件:JDK 21 和 Maven。
在项目根目录下,运行:mvn clean package。
插件 JAR 文件将生成在 target/ 目录中,可将其复制到 plugins/ 目录。
Paper API 和 PlaceholderAPI 被声明为 provided 作用域;它们必须作为插件存在于服务器上。
故障排除
插件已加载但占位符为空:请验证世界名称和游戏规则的拼写是否正确;确保 gamerule_currentworld_ 存在玩家上下文。
Java 版本错误:对于 Paper 1.21.x,请使用 Java 21。
致谢
作者:CrooLyy
专为 Paper + PlaceholderAPI 构建。
GamerulePlaceholder
Lightweight Paper plugin that exposes Minecraft gamerule values through PlaceholderAPI placeholders. Supports querying any world by name and the player’s current world.
Requirements
Paper 1.21.x (tested on 1.21.6).
PlaceholderAPI installed on the server.
Java 21 to run Paper 1.21.x.
Installation
Place the plugin JAR into the server’s plugins/ folder.
Ensure PlaceholderAPI is installed and enabled.
Restart the server; the expansion registers automatically at startup.
Placeholders per world scheme
%gamerule_<rule>_<world>%
Returns the value of gamerule <rule> in world <world>.
Example: %gamerule_keepInventory_world% → “true” or “false”.
Placeholders scheme for current world
%gamerule_currentworld_<rule>%
Returns the gamerule value from the requesting player’s current world.
Requires player context (e.g., scoreboards, chat, GUIs that resolve placeholders for a player).
Example: %gamerule_currentworld_doDaylightCycle%
Notes
<rule> must match the exact gamerule name as in the server version (e.g., keepInventory, doDaylightCycle, playersSleepingPercentage).
If the world or gamerule doesn’t exist, the placeholder returns an empty string.
Boolean/Integer gamerules are returned as plain text (e.g., “true”, “100”).
Usage Examples
Scoreboard: Show whether players keep inventory in the overworld: %gamerule_keepInventory_world%
Player context: Show if day/night cycle runs in the player’s current dimension: %gamerule_currentworld_doDaylightCycle%
Performance
The plugin only reads values via the Paper API and performs no I/O, loops, or async tasks. Overhead is negligible even when placeholders update frequently (e.g., in scoreboards).
Building From Source
Prerequisites: JDK 21 and Maven.
In the project root, run: mvn clean package.
The plugin JAR will be produced in target/ and can be copied to plugins/.
Paper API and PlaceholderAPI are declared with provided scope; they must exist as plugins on the server.
Troubleshooting
Plugin loads but placeholders are empty: verify the world name and gamerule spelling; ensure a player context exists for gamerule_currentworld_.
Java version errors: use Java 21 for Paper 1.21.x.
Credits
Author: CrooLyyCheck
Built for Paper + PlaceholderAPI.
评论 0
登录后参与评分
还没有评论,来抢沙发吧