Compare commits
8 Commits
fc209ba5b8
...
dev/ts-voi
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a45be832b | |||
| 376d63e906 | |||
| 00aa10a44e | |||
| 33ca8abd2a | |||
| 1863d04c65 | |||
| 22708cf75d | |||
| 505c59fb68 | |||
|
|
29c456d4bd |
21
.github/workflows/release.yml
vendored
21
.github/workflows/release.yml
vendored
@@ -11,25 +11,28 @@ permissions:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 检出代码
|
- name: 检出代码
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: 设置 Java
|
- name: 设置 Java 21
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
cache: maven
|
cache: gradle
|
||||||
|
|
||||||
- name: 构建插件
|
- name: 授予执行权限
|
||||||
run: mvn clean package -B
|
run: chmod +x gradlew
|
||||||
|
|
||||||
|
- name: 构建全部版本
|
||||||
|
run: ./gradlew buildAllVersions
|
||||||
|
|
||||||
- name: 创建发行版
|
- name: 创建发行版
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: target/essentialsc-*.jar
|
files: build/libs/EssentialsC*.jar
|
||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
21
.gitignore
vendored
21
.gitignore
vendored
@@ -4,7 +4,7 @@
|
|||||||
# Log files
|
# Log files
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# Package Files
|
# Package files
|
||||||
*.jar
|
*.jar
|
||||||
*.war
|
*.war
|
||||||
*.nar
|
*.nar
|
||||||
@@ -13,20 +13,9 @@
|
|||||||
*.tar.gz
|
*.tar.gz
|
||||||
*.rar
|
*.rar
|
||||||
|
|
||||||
# Maven
|
|
||||||
target/
|
|
||||||
pom.xml.tag
|
|
||||||
pom.xml.releaseBackup
|
|
||||||
pom.xml.versionsBackup
|
|
||||||
pom.xml.next
|
|
||||||
release.properties
|
|
||||||
dependency-reduced-pom.xml
|
|
||||||
buildNumber.properties
|
|
||||||
.mvn/timing.properties
|
|
||||||
.mvn/wrapper/maven-wrapper.jar
|
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
.gradle/
|
.gradle/
|
||||||
|
.gradle-user-home/
|
||||||
build/
|
build/
|
||||||
!gradle-wrapper.jar
|
!gradle-wrapper.jar
|
||||||
!**/src/main/**/build/
|
!**/src/main/**/build/
|
||||||
@@ -61,14 +50,14 @@ bin/
|
|||||||
# VS Code
|
# VS Code
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
# macOS
|
# System files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# Test server (不要上传测试服务器文件)
|
# 测试服务器目录
|
||||||
test-server/
|
test-server/
|
||||||
|
|
||||||
# Reference files (不要上传参考资料)
|
# 参考资料目录
|
||||||
references/
|
references/
|
||||||
|
|
||||||
# Plugin build output
|
# Plugin build output
|
||||||
|
|||||||
259
README.md
259
README.md
@@ -1,192 +1,157 @@
|
|||||||
# EssentialsC
|
# EssentialsC
|
||||||
|
|
||||||
> 一个轻量级的 Paper 服务器插件,灵感来自 CMI,但更加精简、易用且现代化。
|
轻量、现代、面向 Paper 服务端的基础功能插件,灵感来自 CMI,但更聚焦于常用能力与模块化构建。
|
||||||
|
|
||||||
[](https://github.com/Coldsmiles/EssentialsC/releases)
|
[](https://github.com/Coldsmiles/EssentialsC/releases)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://papermc.io/)
|
[](https://papermc.io/)
|
||||||
[](https://www.oracle.com/java/)
|
[](https://adoptium.net/)
|
||||||
|
|
||||||
## ✨ 核心特性
|
## 项目定位
|
||||||
|
|
||||||
### 🎯 随身功能方块
|
- 最低支持版本为 `Paper 1.21.11`
|
||||||
随时随地打开各种功能性方块,无需放置实体方块:
|
- 已适配 `Paper 26.1.2`
|
||||||
- **工作台** (`/workbench`, `/wb`)
|
- 构建环境固定为 `Java 21`
|
||||||
- **铁砧** (`/anvil`)
|
- 配置与文本分离:行为配置放在 `config.yml`,提示文本放在 `lang/`
|
||||||
- **制图台** (`/cartographytable`, `/ct`)
|
- 支持模块裁剪,便于按需构建不同版本
|
||||||
- **砂轮** (`/grindstone`, `/gs`)
|
|
||||||
- **织布机** (`/loom`)
|
|
||||||
- **锻造台** (`/smithingtable`, `/st`)
|
|
||||||
- **切石机** (`/stonecutter`, `/sc`)
|
|
||||||
|
|
||||||
### 📦 智能容器管理
|
## 主要功能
|
||||||
- **末影箱** (`/enderchest`, `/ec`) - 参考 EssentialsX 实现,100% 数据安全
|
|
||||||
- **潜影盒快捷打开** - 潜行+右键直接打开(类似 CMI)
|
|
||||||
- ✅ 支持自定义标题(可配置)
|
|
||||||
- ✅ 防刷物品机制(快照验证 + 数量检查)
|
|
||||||
- ✅ 防止套娃(不能放入另一个潜影盒)
|
|
||||||
- ✅ 异常恢复(物品丢失自动掉落)
|
|
||||||
|
|
||||||
### 🔧 实用工具
|
### 便捷方块
|
||||||
- **帽子** (`/hat`) - 将手中物品戴在头上
|
|
||||||
- **自杀** (`/suicide`, `/die`) - 快速自杀
|
|
||||||
- **飞行** (`/fly`) - 切换飞行模式
|
|
||||||
- **修复** (`/repair`, `/rep`) - 修复手中或所有物品
|
|
||||||
- **饱食** (`/feed`) - 补满饱食度
|
|
||||||
|
|
||||||
### 💚 生存辅助
|
- `/workbench` `(/wb)`
|
||||||
- **治疗** (`/heal`) - 恢复生命值和饱食度
|
- `/anvil`
|
||||||
- **隐身** (`/vanish`, `/v`) - 管理员隐身模式
|
- `/cartographytable` `(/ct, /cartography)`
|
||||||
|
- `/grindstone` `(/gs)`
|
||||||
|
- `/loom`
|
||||||
|
- `/smithingtable` `(/st, /smithing)`
|
||||||
|
- `/stonecutter` `(/sc)`
|
||||||
|
- `/enderchest` `(/ec)`
|
||||||
|
- `/essc blocks` 打开便捷菜单
|
||||||
|
|
||||||
### 📊 管理功能
|
### 玩家功能
|
||||||
- **玩家查询** (`/seen`, `/info`) - 查看玩家上线时间和信息
|
|
||||||
- **功能方块菜单** (`/essc blocks`) - GUI 方块集合面板
|
|
||||||
- **配置重载** (`/essc reload`) - 重新加载配置文件
|
|
||||||
|
|
||||||
---
|
- `/fly`
|
||||||
|
- `/nightvision` `(/nv)`
|
||||||
|
- `/glow`
|
||||||
|
- `/heal`
|
||||||
|
- `/feed`
|
||||||
|
- `/repair` `(/rep)`
|
||||||
|
- `/hat`
|
||||||
|
- `/suicide` `(/die)`
|
||||||
|
- `/vanish` `(/v)`
|
||||||
|
- `/seen` `(/info)`
|
||||||
|
- `/tpsbar`
|
||||||
|
- `/essc admin` 管理模式切换
|
||||||
|
|
||||||
## 🌍 多语言支持
|
### 其它功能
|
||||||
|
|
||||||
- ✅ 完整的中文和英文配置
|
- Shift + 右键快捷打开潜影盒
|
||||||
- ✅ 方块标题自动跟随客户端语言
|
- 潜影盒交互保护,尽量避免刷物品、吞物品和嵌套放入问题
|
||||||
- ✅ 可自定义所有消息文本
|
- 管理模式独立背包、装备栏与状态切换
|
||||||
|
- Enderman 掉落方块控制
|
||||||
|
- JEI 配方同步修复
|
||||||
|
|
||||||
## ⚡ 权限系统
|
## 构建变体
|
||||||
|
|
||||||
- ✅ 精细的权限管理
|
项目目前提供三个常用构建版本:
|
||||||
- ✅ 帮助菜单智能显示(只显示有权限的命令)
|
|
||||||
- ✅ 默认仅 OP 可用,可通过权限插件授权
|
|
||||||
- ✅ CMI 风格的命令别名支持
|
|
||||||
|
|
||||||
## 📦 快速开始
|
| 版本 | 产物名 | 说明 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 标准版 | `EssentialsC-<version>.jar` | 默认版本,不包含 `mob-drops` 模块 |
|
||||||
|
| 完整版 | `EssentialsC-all-<version>.jar` | 包含全部模块 |
|
||||||
|
| 精简版 | `EssentialsC-lite-<version>.jar` | 仅排除 `blocks` 模块,保留 `mob-drops` |
|
||||||
|
|
||||||
### 系统要求
|
如果需要进一步裁剪模块,也可以使用自定义构建参数生成 `custom` 版本。
|
||||||
- **服务器**: Paper 1.21+
|
|
||||||
- **Java**: 21+
|
|
||||||
|
|
||||||
### 安装步骤
|
## 安装说明
|
||||||
1. 下载最新版本的 [`essentialsc-*.jar`](https://github.com/Coldsmiles/EssentialsC/releases)
|
|
||||||
2. 将文件放入服务器的 `plugins` 文件夹
|
|
||||||
3. 重启服务器
|
|
||||||
4. 编辑 `plugins/EssentialsC/config.yml` 配置语言
|
|
||||||
5. (可选)使用权限插件为玩家授予相应权限
|
|
||||||
|
|
||||||
## 🎮 命令列表
|
1. 从 [Releases](https://github.com/Coldsmiles/EssentialsC/releases) 下载所需版本。
|
||||||
|
2. 将插件放入服务端的 `plugins/` 目录。
|
||||||
|
3. 启动一次服务端以生成配置文件。
|
||||||
|
4. 按需修改 `plugins/EssentialsC/config.yml` 与 `plugins/EssentialsC/lang/` 下的语言文件。
|
||||||
|
5. 如有需要,使用权限插件为玩家授权。
|
||||||
|
|
||||||
### 基础命令
|
## 配置说明
|
||||||
| 命令 | 说明 |
|
|
||||||
|------|------|
|
|
||||||
| `/essc help` | 显示帮助菜单(根据权限动态显示) |
|
|
||||||
| `/essc reload` | 重载配置(管理员) |
|
|
||||||
| `/essc blocks` | 打开功能方块菜单 |
|
|
||||||
|
|
||||||
### 功能方块命令
|
当前配置结构以“行为配置”和“文本配置”分离为原则:
|
||||||
| 命令 | 别名 | 说明 |
|
|
||||||
|------|------|------|
|
|
||||||
| `/workbench` | `/wb` | 打开工作台 |
|
|
||||||
| `/anvil` | - | 打开铁砧 |
|
|
||||||
| `/cartographytable` | `/ct` | 打开制图台 |
|
|
||||||
| `/grindstone` | `/gs` | 打开砂轮 |
|
|
||||||
| `/loom` | - | 打开织布机 |
|
|
||||||
| `/smithingtable` | `/st` | 打开锻造台 |
|
|
||||||
| `/stonecutter` | `/sc` | 打开切石机 |
|
|
||||||
| `/enderchest` | `/ec` | 打开末影箱 |
|
|
||||||
|
|
||||||
### 其他命令
|
- `config.yml`
|
||||||
| 命令 | 别名 | 说明 |
|
- 语言选择
|
||||||
|------|------|------|
|
- 管理模式行为
|
||||||
| `/hat` | - | 将手中物品戴在头上 |
|
- JEI 同步开关
|
||||||
| `/suicide` | `/die` | 自杀 |
|
- 掉落控制
|
||||||
| `/fly` | - | 切换飞行模式 |
|
- TPSBar 模式
|
||||||
| `/heal` | - | 恢复生命值和饱食度 |
|
- 便捷菜单布局
|
||||||
| `/vanish` | `/v` | 切换隐身模式(管理员) |
|
- `lang/zh_CN.yml`、`lang/en_US.yml`
|
||||||
| `/seen` | `/info` | 查看玩家信息(管理员) |
|
- 命令反馈
|
||||||
| `/feed` | - | 补满饱食度 |
|
- 帮助信息
|
||||||
| `/repair` | `/rep` | 修复手中或所有物品 |
|
- 菜单文本
|
||||||
|
- 管理模式文本
|
||||||
|
- TPSBar 文本
|
||||||
|
|
||||||
> 💡 **提示**: 使用 `/repair all` 可以修复背包中的所有物品
|
配置文件包含 `config-version`,后续如有结构升级,可基于版本号进行迁移与重建。
|
||||||
|
|
||||||
## ⚙️ 配置说明
|
## 权限示例
|
||||||
|
|
||||||
### config.yml
|
常用权限节点:
|
||||||
```yaml
|
|
||||||
# 语言设置 (en_US, zh_CN)
|
|
||||||
language: "zh_CN"
|
|
||||||
|
|
||||||
# 通用设置
|
```text
|
||||||
settings:
|
essentialsc.command.blocks
|
||||||
enable-feedback: true # 启用命令反馈消息
|
essentialsc.command.workbench
|
||||||
|
essentialsc.command.enderchest
|
||||||
# 潜影盒设置
|
essentialsc.command.fly
|
||||||
shulkerbox:
|
essentialsc.command.nightvision
|
||||||
default-title: "&e潜影盒" # 默认标题(支持颜色代码)
|
essentialsc.command.glow
|
||||||
|
essentialsc.command.heal
|
||||||
|
essentialsc.command.feed
|
||||||
|
essentialsc.command.repair
|
||||||
|
essentialsc.command.vanish
|
||||||
|
essentialsc.command.seen
|
||||||
|
essentialsc.command.admin
|
||||||
|
essentialsc.command.tpsbar
|
||||||
|
essentialsc.shulkerbox.open
|
||||||
|
essentialsc.mobdrops.enderman
|
||||||
|
essentialsc.*
|
||||||
```
|
```
|
||||||
|
|
||||||
### 自定义语言
|
具体默认值与完整节点以 `paper-plugin.yml` 为准。
|
||||||
编辑 `plugins/EssentialsC/lang/` 目录下的语言文件来自定义所有消息文本。
|
|
||||||
|
|
||||||
## 🔐 权限节点
|
## 从源码构建
|
||||||
|
|
||||||
所有命令默认需要 OP 权限。使用权限插件授予权限:
|
|
||||||
|
|
||||||
### 基础权限
|
|
||||||
```
|
|
||||||
essentialsc.command.workbench # 工作台
|
|
||||||
essentialsc.command.anvil # 铁砧
|
|
||||||
essentialsc.command.cartographytable # 制图台
|
|
||||||
essentialsc.command.grindstone # 砂轮
|
|
||||||
essentialsc.command.loom # 织布机
|
|
||||||
essentialsc.command.smithingtable # 锻造台
|
|
||||||
essentialsc.command.stonecutter # 切石机
|
|
||||||
essentialsc.command.enderchest # 末影箱
|
|
||||||
essentialsc.command.hat # 帽子
|
|
||||||
essentialsc.command.suicide # 自杀
|
|
||||||
essentialsc.command.fly # 飞行
|
|
||||||
essentialsc.command.heal # 治疗
|
|
||||||
essentialsc.command.vanish # 隐身
|
|
||||||
essentialsc.command.seen # 玩家查询
|
|
||||||
essentialsc.command.feed # 饱食度
|
|
||||||
essentialsc.command.repair # 修复
|
|
||||||
essentialsc.shulkerbox.open # 潜行+右键潜影盒
|
|
||||||
```
|
|
||||||
|
|
||||||
### 管理权限
|
|
||||||
```
|
|
||||||
essentialsc.command.blocks # 功能方块菜单
|
|
||||||
essentialsc.command.reload # 重载配置
|
|
||||||
essentialsc.command.help # 帮助(默认开放)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 通配符
|
|
||||||
```
|
|
||||||
essentialsc.* # 所有权限
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🔨 从源码构建
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/Coldsmiles/EssentialsC.git
|
git clone https://github.com/Coldsmiles/EssentialsC.git
|
||||||
cd EssentialsC
|
cd EssentialsC
|
||||||
mvn clean package
|
./gradlew buildAllVersions
|
||||||
```
|
```
|
||||||
|
|
||||||
编译后的文件位于 `target/essentialsc-*.jar`
|
Windows 可使用:
|
||||||
|
|
||||||
## 🤝 贡献
|
```powershell
|
||||||
|
.\gradlew.bat buildAllVersions
|
||||||
|
```
|
||||||
|
|
||||||
欢迎提交 Issue 和 Pull Request!
|
构建产物输出到 `build/libs/`。
|
||||||
|
|
||||||
## 📄 许可证
|
常用任务:
|
||||||
|
|
||||||
本项目采用 MIT 许可证 - 详见 [LICENSE](LICENSE) 文件
|
```bash
|
||||||
|
./gradlew shadowJarStandard
|
||||||
|
./gradlew shadowJarAll
|
||||||
|
./gradlew shadowJarLite
|
||||||
|
```
|
||||||
|
|
||||||
## 👨💻 作者
|
## 开发说明
|
||||||
|
|
||||||
**Coldsmiles_7**
|
- 使用 `paperweight-userdev` 进行 Paper 开发
|
||||||
|
- 运行时通过反射加载可选模块,避免裁剪版本因类缺失而启动失败
|
||||||
|
- 发布流程基于 GitHub Actions 和 Gradle Wrapper
|
||||||
|
|
||||||
- GitHub: [@Coldsmiles](https://github.com/Coldsmiles)
|
## 许可证
|
||||||
- 网站: www.infstar.cn
|
|
||||||
|
|
||||||
## ⭐ 支持
|
本项目基于 [MIT License](LICENSE) 开源。
|
||||||
|
|
||||||
如果觉得这个插件对你有帮助,请考虑在 GitHub 上给它一个 Star!
|
## 仓库
|
||||||
|
|
||||||
|
- GitHub: <https://github.com/Coldsmiles/EssentialsC>
|
||||||
|
- Gitea: <https://git.infstar.cn/InfStarMC/EssentialsC>
|
||||||
|
|||||||
212
build.gradle
Normal file
212
build.gradle
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
|
import org.gradle.language.jvm.tasks.ProcessResources
|
||||||
|
|
||||||
|
import java.util.Collections
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'io.papermc.paperweight.userdev' version '2.0.0-beta.21'
|
||||||
|
id 'com.gradleup.shadow' version '8.3.6'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'cn.infstar'
|
||||||
|
version = '1.3.1'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
name = 'papermc'
|
||||||
|
url = uri('https://repo.papermc.io/repository/maven-public/')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
paperweight.paperDevBundle('1.21.11-R0.1-SNAPSHOT')
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||||
|
}
|
||||||
|
|
||||||
|
def moduleExcludes = [
|
||||||
|
'blocks': [
|
||||||
|
'**/commands/WorkbenchCommand.java',
|
||||||
|
'**/commands/AnvilCommand.java',
|
||||||
|
'**/commands/CartographyTableCommand.java',
|
||||||
|
'**/commands/GrindstoneCommand.java',
|
||||||
|
'**/commands/LoomCommand.java',
|
||||||
|
'**/commands/SmithingTableCommand.java',
|
||||||
|
'**/commands/StonecutterCommand.java',
|
||||||
|
'**/commands/EnderChestCommand.java',
|
||||||
|
'**/commands/BlocksMenuCommand.java',
|
||||||
|
'**/listeners/ShulkerBoxListener.java'
|
||||||
|
],
|
||||||
|
'player': [
|
||||||
|
'**/commands/FlyCommand.java',
|
||||||
|
'**/commands/NightVisionCommand.java',
|
||||||
|
'**/commands/GlowCommand.java',
|
||||||
|
'**/commands/HealCommand.java',
|
||||||
|
'**/commands/FeedCommand.java',
|
||||||
|
'**/commands/VanishCommand.java',
|
||||||
|
'**/commands/SeenCommand.java',
|
||||||
|
'**/commands/HatCommand.java',
|
||||||
|
'**/commands/SuicideCommand.java',
|
||||||
|
'**/commands/RepairCommand.java',
|
||||||
|
'**/commands/AdminCommand.java',
|
||||||
|
'**/commands/TpsBarCommand.java',
|
||||||
|
'**/tpsbar/TpsBarManager.java'
|
||||||
|
],
|
||||||
|
'jei-fix': [
|
||||||
|
'**/listeners/JeiRecipeSyncListener.java'
|
||||||
|
],
|
||||||
|
'mob-drops': [
|
||||||
|
'**/listeners/MobDropListener.java',
|
||||||
|
'**/listeners/MobDropMenuListener.java',
|
||||||
|
'**/commands/MobDropCommand.java'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
def variantDefinitions = [
|
||||||
|
standard: [
|
||||||
|
archiveFileName: "EssentialsC-${project.version}.jar",
|
||||||
|
excludedModules: ['mob-drops']
|
||||||
|
],
|
||||||
|
all: [
|
||||||
|
archiveFileName: "EssentialsC-all-${project.version}.jar",
|
||||||
|
excludedModules: []
|
||||||
|
],
|
||||||
|
lite: [
|
||||||
|
archiveFileName: "EssentialsC-lite-${project.version}.jar",
|
||||||
|
excludedModules: ['blocks']
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
if (project.hasProperty('excludeModules')) {
|
||||||
|
def customExcludedModules = project.property('excludeModules')
|
||||||
|
.split(',')
|
||||||
|
.collect { it.trim() }
|
||||||
|
.findAll { !it.isEmpty() }
|
||||||
|
|
||||||
|
variantDefinitions.custom = [
|
||||||
|
archiveFileName: "EssentialsC-custom-${project.version}.jar",
|
||||||
|
excludedModules: customExcludedModules
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
def resolveExcludePatterns = { Collection<String> modules ->
|
||||||
|
modules.collectMany { module -> moduleExcludes.get(module, Collections.emptyList()) }.unique()
|
||||||
|
}
|
||||||
|
|
||||||
|
variantDefinitions.each { variantName, variantConfig ->
|
||||||
|
def unknownModules = variantConfig.excludedModules.findAll { !moduleExcludes.containsKey(it) }
|
||||||
|
if (!unknownModules.isEmpty()) {
|
||||||
|
throw new GradleException("Unknown modules for variant '${variantName}': ${unknownModules.join(', ')}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def variantSourceSets = [:]
|
||||||
|
|
||||||
|
variantDefinitions.each { variantName, variantConfig ->
|
||||||
|
def sourceSet = sourceSets.create(variantName)
|
||||||
|
sourceSet.java.srcDirs = sourceSets.main.java.srcDirs
|
||||||
|
sourceSet.resources.srcDirs = sourceSets.main.resources.srcDirs
|
||||||
|
resolveExcludePatterns(variantConfig.excludedModules).each { pattern ->
|
||||||
|
sourceSet.java.exclude(pattern)
|
||||||
|
}
|
||||||
|
sourceSet.compileClasspath += sourceSets.main.compileClasspath
|
||||||
|
sourceSet.runtimeClasspath += sourceSet.output + sourceSet.compileClasspath
|
||||||
|
variantSourceSets[variantName] = sourceSet
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(ProcessResources).configureEach {
|
||||||
|
filteringCharset = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
variantDefinitions.keySet().each { variantName ->
|
||||||
|
def sourceSet = variantSourceSets[variantName]
|
||||||
|
def processTaskName = sourceSet.processResourcesTaskName
|
||||||
|
tasks.named(processTaskName, ProcessResources).configure {
|
||||||
|
inputs.property('version', project.version)
|
||||||
|
filesMatching('paper-plugin.yml') {
|
||||||
|
expand('version': project.version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('jar').configure {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('shadowJar').configure {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
def variantJarTasks = variantDefinitions.collect { variantName, variantConfig ->
|
||||||
|
def taskName = "shadowJar${variantName.capitalize()}"
|
||||||
|
def sourceSet = variantSourceSets[variantName]
|
||||||
|
|
||||||
|
tasks.register(taskName, ShadowJar) {
|
||||||
|
group = 'build'
|
||||||
|
description = "Builds the ${variantName} plugin jar."
|
||||||
|
archiveFileName.set(variantConfig.archiveFileName as String)
|
||||||
|
from(sourceSet.output)
|
||||||
|
configurations = [project.configurations.runtimeClasspath]
|
||||||
|
dependsOn(tasks.named(sourceSet.classesTaskName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('assemble').configure {
|
||||||
|
dependsOn(variantJarTasks)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('buildAllVersions') {
|
||||||
|
group = 'build'
|
||||||
|
description = 'Builds standard, all, and lite plugin jars.'
|
||||||
|
dependsOn(variantJarTasks)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('deployToPaper12111', Copy) {
|
||||||
|
group = 'deployment'
|
||||||
|
description = 'Deploys the all variant to the local Paper 1.21.11 test server.'
|
||||||
|
def artifact = tasks.named('shadowJarAll').flatMap { it.archiveFile }
|
||||||
|
dependsOn(tasks.named('shadowJarAll'))
|
||||||
|
from(artifact)
|
||||||
|
into(layout.projectDirectory.dir('test-server/paper-1.21.11/plugins'))
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('deployToPaper26') {
|
||||||
|
group = 'deployment'
|
||||||
|
description = 'Deploys the all variant to the local Paper 26.1.2 test server.'
|
||||||
|
dependsOn(tasks.named('shadowJarAll'))
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
def pluginsDir = file("${projectDir}/test-server/paper-26.1.2/plugins")
|
||||||
|
if (!pluginsDir.exists()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fileTree(pluginsDir).matching {
|
||||||
|
include 'EssentialsC*.jar'
|
||||||
|
}.each { pluginJar ->
|
||||||
|
pluginJar.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
def artifact = tasks.named('shadowJarAll').flatMap { it.archiveFile }
|
||||||
|
copy {
|
||||||
|
from(artifact)
|
||||||
|
into("${projectDir}/test-server/paper-26.1.2/plugins")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('buildAndDeployToPaper26') {
|
||||||
|
group = 'deployment'
|
||||||
|
description = 'Builds and deploys the all variant to the local Paper 26.1.2 test server.'
|
||||||
|
dependsOn(tasks.named('clean'), tasks.named('deployToPaper26'))
|
||||||
|
}
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://mirrors.aliyun.com/gradle/distributions/v9.1.0/gradle-9.1.0-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
248
gradlew
vendored
Normal file
248
gradlew
vendored
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
93
gradlew.bat
vendored
Normal file
93
gradlew.bat
vendored
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
75
pom.xml
75
pom.xml
@@ -1,75 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>cn.infstar</groupId>
|
|
||||||
<artifactId>essentialsc</artifactId>
|
|
||||||
<version>1.2.0</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<name>essentialsc</name>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<java.version>21</java.version>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<test.server.path>${project.basedir}/test-server/plugins</test.server.path>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<defaultGoal>clean package</defaultGoal>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${java.version}</source>
|
|
||||||
<target>${java.version}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.5.3</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<!-- 阿里云 Maven 镜像 -->
|
|
||||||
<repository>
|
|
||||||
<id>aliyunmaven</id>
|
|
||||||
<url>https://maven.aliyun.com/repository/public</url>
|
|
||||||
</repository>
|
|
||||||
<!-- PaperMC 仓库 -->
|
|
||||||
<repository>
|
|
||||||
<id>papermc-repo</id>
|
|
||||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.papermc.paper</groupId>
|
|
||||||
<artifactId>paper-api</artifactId>
|
|
||||||
<version>1.21.11-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
||||||
18
settings.gradle
Normal file
18
settings.gradle
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
// 阿里云 Gradle 插件镜像,优先使用以提升国内拉取稳定性
|
||||||
|
maven {
|
||||||
|
name = 'aliyun-gradle-plugin'
|
||||||
|
url = uri('https://maven.aliyun.com/repository/gradle-plugin')
|
||||||
|
}
|
||||||
|
// Gradle 官方插件仓库
|
||||||
|
gradlePluginPortal()
|
||||||
|
// PaperMC 官方仓库,用于解析 paperweight 插件
|
||||||
|
maven {
|
||||||
|
name = 'papermc'
|
||||||
|
url = uri('https://repo.papermc.io/repository/maven-public/')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name = 'EssentialsC'
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
package cn.infstar.essentialsC;
|
package cn.infstar.essentialsC;
|
||||||
|
|
||||||
import cn.infstar.essentialsC.commands.*;
|
import cn.infstar.essentialsC.admin.AdminModeManager;
|
||||||
import cn.infstar.essentialsC.listeners.ShulkerBoxListener;
|
import cn.infstar.essentialsC.commands.BaseCommand;
|
||||||
|
import cn.infstar.essentialsC.commands.CommandRegistry;
|
||||||
|
import cn.infstar.essentialsC.commands.HelpCommand;
|
||||||
|
import cn.infstar.essentialsC.tpsbar.TpsBarService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -12,117 +16,154 @@ import java.lang.reflect.Field;
|
|||||||
public final class EssentialsC extends JavaPlugin {
|
public final class EssentialsC extends JavaPlugin {
|
||||||
|
|
||||||
private static LangManager langManager;
|
private static LangManager langManager;
|
||||||
|
private AdminModeManager adminModeManager;
|
||||||
|
private TpsBarService tpsBarManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// 初始化语言管理器
|
|
||||||
langManager = new LangManager(this);
|
langManager = new LangManager(this);
|
||||||
|
adminModeManager = new AdminModeManager(this);
|
||||||
// 注册监听器
|
getServer().getPluginManager().registerEvents(adminModeManager, this);
|
||||||
|
tpsBarManager = createOptionalService("cn.infstar.essentialsC.tpsbar.TpsBarManager", TpsBarService.class);
|
||||||
|
if (tpsBarManager instanceof Listener listener) {
|
||||||
|
getServer().getPluginManager().registerEvents(listener, this);
|
||||||
|
}
|
||||||
|
registerPluginChannels();
|
||||||
registerListeners();
|
registerListeners();
|
||||||
|
|
||||||
// 注册命令
|
|
||||||
registerCommands();
|
registerCommands();
|
||||||
|
|
||||||
getLogger().info("EssentialsC 插件已启用!");
|
getLogger().info("EssentialsC enabled. Version: " + getDescription().getVersion());
|
||||||
getLogger().info("当前语言: " + langManager.getCurrentLanguage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getLogger().info("EssentialsC 插件已禁用!");
|
if (tpsBarManager != null) {
|
||||||
|
tpsBarManager.shutdown();
|
||||||
|
}
|
||||||
|
if (adminModeManager != null) {
|
||||||
|
adminModeManager.shutdown();
|
||||||
|
}
|
||||||
|
getLogger().info("EssentialsC disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取语言管理器实例
|
|
||||||
*/
|
|
||||||
public static LangManager getLangManager() {
|
public static LangManager getLangManager() {
|
||||||
return langManager;
|
return langManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public AdminModeManager getAdminModeManager() {
|
||||||
* 注册所有监听器
|
return adminModeManager;
|
||||||
*/
|
|
||||||
private void registerListeners() {
|
|
||||||
// 注册潜影盒右键打开监听器
|
|
||||||
new ShulkerBoxListener(this);
|
|
||||||
getLogger().info("成功注册监听器!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TpsBarService getTpsBarManager() {
|
||||||
|
return tpsBarManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerPluginChannels() {
|
||||||
|
org.bukkit.plugin.messaging.Messenger messenger = getServer().getMessenger();
|
||||||
|
messenger.registerOutgoingPluginChannel(this, "fabric:recipe_sync");
|
||||||
|
messenger.registerOutgoingPluginChannel(this, "neoforge:recipe_content");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerListeners() {
|
||||||
|
if (registerListener("cn.infstar.essentialsC.listeners.ShulkerBoxListener")) {
|
||||||
|
getLogger().info("- Shulker box module");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (registerListener("cn.infstar.essentialsC.listeners.JeiRecipeSyncListener")) {
|
||||||
|
getLogger().info("- JEI recipe sync");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (registerListener("cn.infstar.essentialsC.listeners.MobDropListener")) {
|
||||||
|
createOptionalInstance("cn.infstar.essentialsC.listeners.MobDropMenuListener");
|
||||||
|
getLogger().info("- Mob drop control");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean registerListener(String className) {
|
||||||
|
try {
|
||||||
|
Class<?> listenerClass = Class.forName(className);
|
||||||
|
Object listenerInstance = listenerClass.getConstructor(EssentialsC.class).newInstance(this);
|
||||||
|
getServer().getPluginManager().registerEvents((org.bukkit.event.Listener) listenerInstance, this);
|
||||||
|
return true;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createOptionalInstance(String className) {
|
||||||
|
try {
|
||||||
|
Class<?> targetClass = Class.forName(className);
|
||||||
|
targetClass.getConstructor(EssentialsC.class).newInstance(this);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> T createOptionalService(String className, Class<T> serviceType) {
|
||||||
|
try {
|
||||||
|
Class<?> targetClass = Class.forName(className);
|
||||||
|
Object instance = targetClass.getConstructor(EssentialsC.class).newInstance(this);
|
||||||
|
return serviceType.cast(instance);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
try {
|
try {
|
||||||
// 获取 CommandMap
|
|
||||||
Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||||
bukkitCommandMap.setAccessible(true);
|
bukkitCommandMap.setAccessible(true);
|
||||||
org.bukkit.command.CommandMap commandMap = (org.bukkit.command.CommandMap) bukkitCommandMap.get(Bukkit.getServer());
|
org.bukkit.command.CommandMap commandMap = (org.bukkit.command.CommandMap) bukkitCommandMap.get(Bukkit.getServer());
|
||||||
|
|
||||||
// 注册所有命令(使用 CMI 风格:独立命令 + 别名)
|
for (CommandRegistry.CommandSpec spec : CommandRegistry.getCommandSpecs()) {
|
||||||
registerCommandWithAliases(commandMap, "workbench", new WorkbenchCommand(), "wb");
|
if (!spec.standalone()) {
|
||||||
registerCommandWithAliases(commandMap, "anvil", new AnvilCommand());
|
continue;
|
||||||
registerCommandWithAliases(commandMap, "cartographytable", new CartographyTableCommand(), "ct", "cartography");
|
}
|
||||||
registerCommandWithAliases(commandMap, "grindstone", new GrindstoneCommand(), "gs");
|
BaseCommand executor = CommandRegistry.getCommand(spec.name());
|
||||||
registerCommandWithAliases(commandMap, "loom", new LoomCommand());
|
if (executor == null) {
|
||||||
registerCommandWithAliases(commandMap, "smithingtable", new SmithingTableCommand(), "st", "smithing");
|
continue;
|
||||||
registerCommandWithAliases(commandMap, "stonecutter", new StonecutterCommand(), "sc");
|
}
|
||||||
registerCommandWithAliases(commandMap, "enderchest", new EnderChestCommand(), "ec");
|
registerCommandWithAliases(commandMap, spec.name(), executor, spec.aliases().toArray(String[]::new));
|
||||||
registerCommandWithAliases(commandMap, "hat", new HatCommand());
|
}
|
||||||
registerCommandWithAliases(commandMap, "suicide", new SuicideCommand(), "die");
|
|
||||||
registerCommandWithAliases(commandMap, "fly", new FlyCommand());
|
|
||||||
registerCommandWithAliases(commandMap, "heal", new HealCommand());
|
|
||||||
registerCommandWithAliases(commandMap, "vanish", new VanishCommand(), "v");
|
|
||||||
registerCommandWithAliases(commandMap, "seen", new SeenCommand(), "info");
|
|
||||||
registerCommandWithAliases(commandMap, "feed", new FeedCommand());
|
|
||||||
registerCommandWithAliases(commandMap, "repair", new RepairCommand(), "rep");
|
|
||||||
registerCommandWithAliases(commandMap, "essentialsc", new HelpCommand(), "essc");
|
registerCommandWithAliases(commandMap, "essentialsc", new HelpCommand(), "essc");
|
||||||
|
|
||||||
getLogger().info("成功注册所有命令!");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getLogger().severe("无法注册命令: " + e.getMessage());
|
getLogger().severe("Failed to register commands: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void registerCommandWithAliases(org.bukkit.command.CommandMap commandMap, String name, BaseCommand executor, String... aliases) {
|
||||||
* 注册命令并支持别名
|
|
||||||
* @param commandMap Bukkit CommandMap
|
|
||||||
* @param name 主命令名
|
|
||||||
* @param executor 命令执行器
|
|
||||||
* @param aliases 别名列表(可选)
|
|
||||||
*/
|
|
||||||
private void registerCommandWithAliases(org.bukkit.command.CommandMap commandMap, String name, cn.infstar.essentialsC.commands.BaseCommand executor, String... aliases) {
|
|
||||||
Command command = new Command(name) {
|
Command command = new Command(name) {
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||||
return executor.onCommand(sender, this, commandLabel, args);
|
return executor.onCommand(sender, this, commandLabel, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||||
if (executor instanceof org.bukkit.command.TabCompleter) {
|
if (executor instanceof org.bukkit.command.TabCompleter completer) {
|
||||||
return ((org.bukkit.command.TabCompleter) executor).onTabComplete(sender, this, alias, args);
|
return completer.onTabComplete(sender, this, alias, args);
|
||||||
}
|
}
|
||||||
return super.tabComplete(sender, alias, args);
|
return super.tabComplete(sender, alias, args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
command.setPermission(executor.getPermission());
|
command.setPermission(executor.getPermission());
|
||||||
// 注册到默认命名空间,使玩家可以直接使用 /workbench 而不是 /essentialsc:workbench
|
|
||||||
commandMap.register("", command);
|
commandMap.register("", command);
|
||||||
|
|
||||||
// 注册别名
|
|
||||||
for (String alias : aliases) {
|
for (String alias : aliases) {
|
||||||
Command aliasCmd = new Command(alias) {
|
Command aliasCmd = new Command(alias) {
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||||
return executor.onCommand(sender, this, commandLabel, args);
|
return executor.onCommand(sender, this, commandLabel, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
public java.util.List<String> tabComplete(CommandSender sender, String label, String[] args) throws IllegalArgumentException {
|
||||||
if (executor instanceof org.bukkit.command.TabCompleter) {
|
if (executor instanceof org.bukkit.command.TabCompleter completer) {
|
||||||
return ((org.bukkit.command.TabCompleter) executor).onTabComplete(sender, this, alias, args);
|
return completer.onTabComplete(sender, this, label, args);
|
||||||
}
|
}
|
||||||
return super.tabComplete(sender, alias, args);
|
return super.tabComplete(sender, label, args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
aliasCmd.setPermission(executor.getPermission());
|
aliasCmd.setPermission(executor.getPermission());
|
||||||
|
|||||||
@@ -1,152 +1,172 @@
|
|||||||
package cn.infstar.essentialsC;
|
package cn.infstar.essentialsC;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class LangManager {
|
public class LangManager {
|
||||||
|
|
||||||
|
private static final int CURRENT_CONFIG_VERSION = 2;
|
||||||
|
|
||||||
private final JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
private FileConfiguration langFile;
|
private FileConfiguration langFile;
|
||||||
private String currentLanguage;
|
private String currentLanguage;
|
||||||
|
|
||||||
public LangManager(JavaPlugin plugin) {
|
public LangManager(JavaPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
loadConfig();
|
loadConfig();
|
||||||
loadLanguage();
|
loadLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig() {
|
|
||||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
|
||||||
plugin.saveResource("config.yml", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
config = YamlConfiguration.loadConfiguration(configFile);
|
|
||||||
|
|
||||||
// 设置默认值
|
|
||||||
config.addDefault("language", "zh_CN");
|
|
||||||
config.addDefault("settings.enable-feedback", true);
|
|
||||||
config.addDefault("settings.message-prefix", "&6[EssentialsC] &r");
|
|
||||||
config.options().copyDefaults(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
config.save(configFile);
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.getLogger().severe("无法保存配置文件: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadLanguage() {
|
|
||||||
currentLanguage = config.getString("language", "zh_CN");
|
|
||||||
|
|
||||||
File langFolder = new File(plugin.getDataFolder(), "lang");
|
|
||||||
if (!langFolder.exists()) {
|
|
||||||
langFolder.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
File langFileObj = new File(langFolder, currentLanguage + ".yml");
|
|
||||||
|
|
||||||
// 如果语言文件不存在,从资源中复制
|
|
||||||
if (!langFileObj.exists()) {
|
|
||||||
InputStream inputStream = plugin.getResource("lang/" + currentLanguage + ".yml");
|
|
||||||
if (inputStream != null) {
|
|
||||||
plugin.saveResource("lang/" + currentLanguage + ".yml", false);
|
|
||||||
} else {
|
|
||||||
plugin.getLogger().warning("未找到语言文件: " + currentLanguage + ".yml,使用默认语言 en_US");
|
|
||||||
currentLanguage = "en_US";
|
|
||||||
plugin.saveResource("lang/en_US.yml", false);
|
|
||||||
langFileObj = new File(langFolder, "en_US.yml");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
langFile = YamlConfiguration.loadConfiguration(langFileObj);
|
|
||||||
|
|
||||||
// 尝试加载默认语言作为后备
|
|
||||||
if (!currentLanguage.equals("en_US")) {
|
|
||||||
InputStream defaultLangStream = plugin.getResource("lang/en_US.yml");
|
|
||||||
if (defaultLangStream != null) {
|
|
||||||
YamlConfiguration defaultLang = YamlConfiguration.loadConfiguration(
|
|
||||||
new InputStreamReader(defaultLangStream, StandardCharsets.UTF_8)
|
|
||||||
);
|
|
||||||
langFile.setDefaults(defaultLang);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取插件前缀
|
|
||||||
*/
|
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
return translateColorCodes(langFile.getString("prefix", "&6[EssentialsC] &r"));
|
return translateColorCodes(langFile.getString("prefix", "&6[EssentialsC] &r"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取翻译文本
|
|
||||||
*/
|
|
||||||
public String getString(String path) {
|
public String getString(String path) {
|
||||||
String value = langFile.getString(path);
|
String value = langFile.getString(path);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return "&cMissing translation: " + path;
|
return translateColorCodes("&cMissing translation: " + path);
|
||||||
}
|
}
|
||||||
return translateColorCodes(value);
|
return translateColorCodes(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取翻译文本并替换占位符
|
|
||||||
*/
|
|
||||||
public String getString(String path, Map<String, String> placeholders) {
|
public String getString(String path, Map<String, String> placeholders) {
|
||||||
String value = getString(path);
|
return applyPlaceholders(getString(path), placeholders);
|
||||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
|
||||||
value = value.replace("{" + entry.getKey() + "}", entry.getValue());
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getPrefixedString(String path) {
|
||||||
* 获取字符串列表(用于 Lore 等多行文本)
|
return getPrefix() + getString(path);
|
||||||
*/
|
}
|
||||||
public java.util.List<String> getStringList(String path) {
|
|
||||||
java.util.List<String> values = langFile.getStringList(path);
|
public String getPrefixedString(String path, Map<String, String> placeholders) {
|
||||||
|
return getPrefix() + getString(path, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getStringList(String path) {
|
||||||
|
List<String> values = langFile.getStringList(path);
|
||||||
if (values.isEmpty()) {
|
if (values.isEmpty()) {
|
||||||
// 如果找不到,返回包含错误信息的列表
|
values = List.of("&cMissing translation: " + path);
|
||||||
return java.util.Arrays.asList("&cMissing translation: " + path);
|
|
||||||
}
|
}
|
||||||
// 翻译颜色代码
|
|
||||||
java.util.List<String> translated = new java.util.ArrayList<>();
|
List<String> translated = new ArrayList<>();
|
||||||
for (String value : values) {
|
for (String value : values) {
|
||||||
translated.add(translateColorCodes(value));
|
translated.add(translateColorCodes(value));
|
||||||
}
|
}
|
||||||
return translated;
|
return translated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 重新加载配置和语言
|
|
||||||
*/
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
loadLanguage();
|
loadLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前语言
|
|
||||||
*/
|
|
||||||
public String getCurrentLanguage() {
|
public String getCurrentLanguage() {
|
||||||
return currentLanguage;
|
return currentLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void loadConfig() {
|
||||||
* 翻译颜色代码
|
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||||
*/
|
if (!configFile.exists()) {
|
||||||
|
plugin.saveResource("config.yml", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
migrateConfigIfNeeded(configFile);
|
||||||
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
config.addDefault("config-version", CURRENT_CONFIG_VERSION);
|
||||||
|
config.addDefault("language", "zh_CN");
|
||||||
|
config.options().copyDefaults(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
config.save(configFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().severe("Failed to save config.yml: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void migrateConfigIfNeeded(File configFile) {
|
||||||
|
FileConfiguration existingConfig = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
int existingVersion = existingConfig.getInt("config-version", 0);
|
||||||
|
if (existingVersion <= 0 || existingVersion >= CURRENT_CONFIG_VERSION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String language = existingConfig.getString("language", "zh_CN");
|
||||||
|
File backupFile = new File(plugin.getDataFolder(),
|
||||||
|
"config.v" + existingVersion + ".bak-" + System.currentTimeMillis() + ".yml");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.copy(configFile.toPath(), backupFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
plugin.saveResource("config.yml", true);
|
||||||
|
|
||||||
|
FileConfiguration newConfig = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
newConfig.set("language", language);
|
||||||
|
newConfig.save(configFile);
|
||||||
|
|
||||||
|
plugin.getLogger().info("Migrated config.yml from version " + existingVersion
|
||||||
|
+ " to " + CURRENT_CONFIG_VERSION + ". Backup saved to " + backupFile.getName());
|
||||||
|
} catch (IOException e) {
|
||||||
|
plugin.getLogger().severe("Failed to migrate config.yml: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadLanguage() {
|
||||||
|
currentLanguage = config.getString("language", "zh_CN");
|
||||||
|
|
||||||
|
File langFolder = new File(plugin.getDataFolder(), "lang");
|
||||||
|
if (!langFolder.exists() && !langFolder.mkdirs()) {
|
||||||
|
plugin.getLogger().warning("Failed to create language folder: " + langFolder.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
File langFileObj = new File(langFolder, currentLanguage + ".yml");
|
||||||
|
if (!langFileObj.exists()) {
|
||||||
|
if (plugin.getResource("lang/" + currentLanguage + ".yml") != null) {
|
||||||
|
plugin.saveResource("lang/" + currentLanguage + ".yml", false);
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().warning("Language file not found: " + currentLanguage + ".yml, falling back to en_US");
|
||||||
|
currentLanguage = "en_US";
|
||||||
|
plugin.saveResource("lang/en_US.yml", false);
|
||||||
|
langFileObj = new File(langFolder, "en_US.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
langFile = YamlConfiguration.loadConfiguration(langFileObj);
|
||||||
|
loadDefaultLanguageFallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDefaultLanguageFallback() {
|
||||||
|
InputStream defaultLangStream = plugin.getResource("lang/en_US.yml");
|
||||||
|
if (defaultLangStream == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
YamlConfiguration defaultLang = YamlConfiguration.loadConfiguration(
|
||||||
|
new InputStreamReader(defaultLangStream, StandardCharsets.UTF_8)
|
||||||
|
);
|
||||||
|
langFile.setDefaults(defaultLang);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String applyPlaceholders(String value, Map<String, String> placeholders) {
|
||||||
|
String result = value;
|
||||||
|
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||||
|
result = result.replace("{" + entry.getKey() + "}", entry.getValue());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private String translateColorCodes(String text) {
|
private String translateColorCodes(String text) {
|
||||||
return text.replace("&", "§");
|
return text == null ? "" : ChatColor.translateAlternateColorCodes('&', text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
341
src/main/java/cn/infstar/essentialsC/admin/AdminModeManager.java
Normal file
341
src/main/java/cn/infstar/essentialsC/admin/AdminModeManager.java
Normal file
@@ -0,0 +1,341 @@
|
|||||||
|
package cn.infstar.essentialsC.admin;
|
||||||
|
|
||||||
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public final class AdminModeManager implements Listener {
|
||||||
|
|
||||||
|
private static final float VANILLA_FLY_SPEED = 0.1F;
|
||||||
|
|
||||||
|
private final EssentialsC plugin;
|
||||||
|
private final File dataFile;
|
||||||
|
private final YamlConfiguration data;
|
||||||
|
private final Set<UUID> activePlayers = new HashSet<>();
|
||||||
|
|
||||||
|
private BukkitTask actionBarTask;
|
||||||
|
|
||||||
|
public AdminModeManager(EssentialsC plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
addConfigDefaults();
|
||||||
|
this.dataFile = new File(plugin.getDataFolder(), "admin-mode.yml");
|
||||||
|
this.data = YamlConfiguration.loadConfiguration(dataFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdminMode(Player player) {
|
||||||
|
return activePlayers.contains(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggle(Player player) {
|
||||||
|
if (isAdminMode(player)) {
|
||||||
|
disable(player, true);
|
||||||
|
} else {
|
||||||
|
enable(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
for (UUID uuid : new ArrayList<>(activePlayers)) {
|
||||||
|
Player player = plugin.getServer().getPlayer(uuid);
|
||||||
|
if (player != null) {
|
||||||
|
disable(player, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionBarTask != null) {
|
||||||
|
actionBarTask.cancel();
|
||||||
|
actionBarTask = null;
|
||||||
|
}
|
||||||
|
saveData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
String playerPath = getPlayerPath(player);
|
||||||
|
if (!data.getBoolean(playerPath + ".active", false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveProfile(player, playerPath + ".admin");
|
||||||
|
restoreNormalProfile(player);
|
||||||
|
data.set(playerPath + ".active", false);
|
||||||
|
saveData();
|
||||||
|
sendLangMessage(player, "admin-mode.messages.crash-restored");
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (isAdminMode(player)) {
|
||||||
|
disable(player, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enable(Player player) {
|
||||||
|
String playerPath = getPlayerPath(player);
|
||||||
|
player.closeInventory();
|
||||||
|
saveProfile(player, playerPath + ".normal");
|
||||||
|
|
||||||
|
if (!loadProfile(player, playerPath + ".admin")) {
|
||||||
|
clearInventory(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
activePlayers.add(player.getUniqueId());
|
||||||
|
data.set(playerPath + ".active", true);
|
||||||
|
|
||||||
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
|
player.setAllowFlight(true);
|
||||||
|
player.setFlying(true);
|
||||||
|
player.setFlySpeed(getAdminFlySpeed());
|
||||||
|
saveData();
|
||||||
|
|
||||||
|
sendLangMessage(player, "admin-mode.messages.enabled");
|
||||||
|
sendActionBar(player);
|
||||||
|
startActionBarTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disable(Player player, boolean notify) {
|
||||||
|
String playerPath = getPlayerPath(player);
|
||||||
|
player.closeInventory();
|
||||||
|
saveProfile(player, playerPath + ".admin");
|
||||||
|
restoreNormalProfile(player);
|
||||||
|
|
||||||
|
activePlayers.remove(player.getUniqueId());
|
||||||
|
data.set(playerPath + ".active", false);
|
||||||
|
saveData();
|
||||||
|
|
||||||
|
if (notify) {
|
||||||
|
sendLangMessage(player, "admin-mode.messages.disabled");
|
||||||
|
}
|
||||||
|
stopActionBarTaskIfIdle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restoreNormalProfile(Player player) {
|
||||||
|
String playerPath = getPlayerPath(player);
|
||||||
|
if (!loadProfile(player, playerPath + ".normal")) {
|
||||||
|
clearInventory(player);
|
||||||
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
player.setAllowFlight(false);
|
||||||
|
player.setFlying(false);
|
||||||
|
player.setFlySpeed(VANILLA_FLY_SPEED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveProfile(Player player, String path) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
data.set(path + ".storage", Arrays.asList(inventory.getStorageContents()));
|
||||||
|
data.set(path + ".armor", Arrays.asList(inventory.getArmorContents()));
|
||||||
|
data.set(path + ".extra", Arrays.asList(inventory.getExtraContents()));
|
||||||
|
data.set(path + ".cursor", player.getItemOnCursor());
|
||||||
|
data.set(path + ".held-slot", inventory.getHeldItemSlot());
|
||||||
|
data.set(path + ".game-mode", player.getGameMode().name());
|
||||||
|
data.set(path + ".allow-flight", player.getAllowFlight());
|
||||||
|
data.set(path + ".flying", player.isFlying());
|
||||||
|
data.set(path + ".fly-speed", player.getFlySpeed());
|
||||||
|
data.set(path + ".health", player.getHealth());
|
||||||
|
data.set(path + ".food-level", player.getFoodLevel());
|
||||||
|
data.set(path + ".saturation", player.getSaturation());
|
||||||
|
data.set(path + ".exhaustion", player.getExhaustion());
|
||||||
|
data.set(path + ".exp", player.getExp());
|
||||||
|
data.set(path + ".level", player.getLevel());
|
||||||
|
data.set(path + ".total-experience", player.getTotalExperience());
|
||||||
|
data.set(path + ".fire-ticks", player.getFireTicks());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean loadProfile(Player player, String path) {
|
||||||
|
if (!data.contains(path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
clearInventory(player);
|
||||||
|
inventory.setStorageContents(readItemArray(path + ".storage", inventory.getStorageContents().length));
|
||||||
|
inventory.setArmorContents(readItemArray(path + ".armor", inventory.getArmorContents().length));
|
||||||
|
inventory.setExtraContents(readItemArray(path + ".extra", inventory.getExtraContents().length));
|
||||||
|
inventory.setHeldItemSlot(clampHeldSlot(data.getInt(path + ".held-slot", inventory.getHeldItemSlot())));
|
||||||
|
player.setItemOnCursor(readItem(path + ".cursor"));
|
||||||
|
|
||||||
|
player.setGameMode(readGameMode(path + ".game-mode", player.getGameMode()));
|
||||||
|
player.setAllowFlight(data.getBoolean(path + ".allow-flight", player.getAllowFlight()));
|
||||||
|
player.setFlying(data.getBoolean(path + ".flying", false) && player.getAllowFlight());
|
||||||
|
player.setFlySpeed(clampFlySpeed(data.getDouble(path + ".fly-speed", VANILLA_FLY_SPEED)));
|
||||||
|
player.setHealth(readHealth(player, path + ".health"));
|
||||||
|
player.setFoodLevel(clampFoodLevel(data.getInt(path + ".food-level", player.getFoodLevel())));
|
||||||
|
player.setSaturation(clampSaturation(data.getDouble(path + ".saturation", player.getSaturation())));
|
||||||
|
player.setExhaustion(clampExhaustion(data.getDouble(path + ".exhaustion", player.getExhaustion())));
|
||||||
|
player.setExp(clampExp(data.getDouble(path + ".exp", player.getExp())));
|
||||||
|
player.setLevel(Math.max(0, data.getInt(path + ".level", player.getLevel())));
|
||||||
|
player.setTotalExperience(Math.max(0, data.getInt(path + ".total-experience", player.getTotalExperience())));
|
||||||
|
player.setFireTicks(Math.max(0, data.getInt(path + ".fire-ticks", player.getFireTicks())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack[] readItemArray(String path, int size) {
|
||||||
|
ItemStack[] items = new ItemStack[size];
|
||||||
|
List<?> list = data.getList(path);
|
||||||
|
if (list == null) {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int index = 0; index < Math.min(size, list.size()); index++) {
|
||||||
|
Object value = list.get(index);
|
||||||
|
if (value instanceof ItemStack itemStack) {
|
||||||
|
items[index] = itemStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GameMode readGameMode(String path, GameMode fallback) {
|
||||||
|
try {
|
||||||
|
return GameMode.valueOf(data.getString(path, fallback.name()));
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private double readHealth(Player player, String path) {
|
||||||
|
double maxHealth = player.getAttribute(Attribute.MAX_HEALTH) != null
|
||||||
|
? player.getAttribute(Attribute.MAX_HEALTH).getValue()
|
||||||
|
: player.getHealth();
|
||||||
|
double health = data.getDouble(path, player.getHealth());
|
||||||
|
if (!Double.isFinite(health)) {
|
||||||
|
return Math.min(Math.max(1.0D, player.getHealth()), maxHealth);
|
||||||
|
}
|
||||||
|
return Math.min(Math.max(1.0D, health), maxHealth);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack readItem(String path) {
|
||||||
|
Object value = data.get(path);
|
||||||
|
if (value instanceof ItemStack itemStack) {
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
return new ItemStack(Material.AIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearInventory(Player player) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
inventory.clear();
|
||||||
|
inventory.setArmorContents(new ItemStack[inventory.getArmorContents().length]);
|
||||||
|
inventory.setExtraContents(new ItemStack[inventory.getExtraContents().length]);
|
||||||
|
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startActionBarTask() {
|
||||||
|
if (actionBarTask != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int interval = Math.max(10, plugin.getConfig().getInt("admin-mode.actionbar.interval-ticks", 40));
|
||||||
|
actionBarTask = plugin.getServer().getScheduler().runTaskTimer(plugin, () -> {
|
||||||
|
for (UUID uuid : new ArrayList<>(activePlayers)) {
|
||||||
|
Player player = plugin.getServer().getPlayer(uuid);
|
||||||
|
if (player != null && player.isOnline()) {
|
||||||
|
sendActionBar(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stopActionBarTaskIfIdle();
|
||||||
|
}, 0L, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopActionBarTaskIfIdle() {
|
||||||
|
if (!activePlayers.isEmpty() || actionBarTask == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
actionBarTask.cancel();
|
||||||
|
actionBarTask = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendActionBar(Player player) {
|
||||||
|
String text = EssentialsC.getLangManager().getString("admin-mode.actionbar");
|
||||||
|
Component component = LegacyComponentSerializer.legacyAmpersand().deserialize(text);
|
||||||
|
player.sendActionBar(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getAdminFlySpeed() {
|
||||||
|
double speed = plugin.getConfig().getDouble("admin-mode.fly-speed", 0.2D);
|
||||||
|
return clampFlySpeed(speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float clampFlySpeed(double speed) {
|
||||||
|
if (!Double.isFinite(speed)) {
|
||||||
|
return VANILLA_FLY_SPEED;
|
||||||
|
}
|
||||||
|
return (float) Math.max(-1.0D, Math.min(1.0D, speed));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int clampHeldSlot(int slot) {
|
||||||
|
return Math.max(0, Math.min(8, slot));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int clampFoodLevel(int foodLevel) {
|
||||||
|
return Math.max(0, Math.min(20, foodLevel));
|
||||||
|
}
|
||||||
|
|
||||||
|
private float clampSaturation(double saturation) {
|
||||||
|
if (!Double.isFinite(saturation)) {
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
return (float) Math.max(0.0D, Math.min(20.0D, saturation));
|
||||||
|
}
|
||||||
|
|
||||||
|
private float clampExhaustion(double exhaustion) {
|
||||||
|
if (!Double.isFinite(exhaustion)) {
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
return (float) Math.max(0.0D, exhaustion);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float clampExp(double exp) {
|
||||||
|
if (!Double.isFinite(exp)) {
|
||||||
|
return 0.0F;
|
||||||
|
}
|
||||||
|
return (float) Math.max(0.0D, Math.min(1.0D, exp));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPlayerPath(Player player) {
|
||||||
|
return "players." + player.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendLangMessage(Player player, String path) {
|
||||||
|
player.sendMessage(EssentialsC.getLangManager().getPrefixedString(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveData() {
|
||||||
|
try {
|
||||||
|
data.save(dataFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
plugin.getLogger().warning("Failed to save admin-mode.yml: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addConfigDefaults() {
|
||||||
|
plugin.getConfig().addDefault("admin-mode.fly-speed", 0.2D);
|
||||||
|
plugin.getConfig().addDefault("admin-mode.actionbar.interval-ticks", 40);
|
||||||
|
plugin.getConfig().options().copyDefaults(true);
|
||||||
|
plugin.saveConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class AdminCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public AdminCommand() {
|
||||||
|
super("essentialsc.command.admin");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute(Player player, String[] args) {
|
||||||
|
plugin.getAdminModeManager().toggle(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class AnvilCommand extends BaseCommand {
|
public class AnvilCommand extends BaseCommand {
|
||||||
|
|
||||||
public AnvilCommand() {
|
public AnvilCommand() {
|
||||||
super("essentialsc.command.anvil");
|
super("essentialsc.command.anvil");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
// 使用 Paper API 打开铁砧(标题跟随客户端语言)
|
|
||||||
player.openAnvil(null, true);
|
player.openAnvil(null, true);
|
||||||
|
playBlockShortcutSound(player, Material.ANVIL, Sound.BLOCK_ANVIL_USE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,51 +2,84 @@ package cn.infstar.essentialsC.commands;
|
|||||||
|
|
||||||
import cn.infstar.essentialsC.EssentialsC;
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
import cn.infstar.essentialsC.LangManager;
|
import cn.infstar.essentialsC.LangManager;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.SoundGroup;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class BaseCommand implements CommandExecutor {
|
public abstract class BaseCommand implements CommandExecutor {
|
||||||
|
|
||||||
protected String permission;
|
protected String permission;
|
||||||
protected static cn.infstar.essentialsC.EssentialsC plugin;
|
protected static EssentialsC plugin;
|
||||||
|
|
||||||
public BaseCommand(String permission) {
|
public BaseCommand(String permission) {
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
plugin = cn.infstar.essentialsC.EssentialsC.getPlugin(cn.infstar.essentialsC.EssentialsC.class);
|
plugin = EssentialsC.getPlugin(EssentialsC.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取语言管理器
|
|
||||||
*/
|
|
||||||
protected LangManager getLang() {
|
protected LangManager getLang() {
|
||||||
return EssentialsC.getLangManager();
|
return EssentialsC.getLangManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void playBlockShortcutSound(Player player, Material material, Sound fallbackSound) {
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
Sound sound = resolvePlaceSound(material);
|
||||||
if (!(sender instanceof Player player)) {
|
if (sound == null) {
|
||||||
sender.sendMessage(getLang().getString("messages.player-only"));
|
sound = fallbackSound;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!player.hasPermission(permission)) {
|
if (sound != null) {
|
||||||
String message = getLang().getString("messages.no-permission",
|
player.playSound(player.getLocation(), sound, 1.0F, 1.0F);
|
||||||
java.util.Map.of("permission", permission));
|
|
||||||
player.sendMessage(message);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return execute(player, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void playShortcutSound(Player player, Sound sound) {
|
||||||
|
if (sound != null) {
|
||||||
|
player.playSound(player.getLocation(), sound, 1.0F, 1.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (sender instanceof Player player) {
|
||||||
|
if (!player.hasPermission(permission)) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.no-permission",
|
||||||
|
Map.of("permission", permission)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return execute(player, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
return executeConsole(sender, args);
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract boolean execute(Player player, String[] args);
|
protected abstract boolean execute(Player player, String[] args);
|
||||||
|
|
||||||
|
protected boolean executeConsole(CommandSender sender, String[] args) {
|
||||||
|
sender.sendMessage(getLang().getPrefixedString("messages.player-only"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Sound resolvePlaceSound(Material material) {
|
||||||
|
if (material == null || !material.isBlock()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
SoundGroup soundGroup = material.createBlockData().getSoundGroup();
|
||||||
|
return soundGroup.getPlaceSound();
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,128 +1,317 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class BlocksMenuCommand extends BaseCommand implements Listener {
|
public class BlocksMenuCommand extends BaseCommand implements Listener {
|
||||||
|
|
||||||
private static final int MENU_SIZE = 36;
|
private static final int MENU_SIZE = 36;
|
||||||
|
private static final int[] DIVIDER_SLOTS = {4, 13, 22, 31};
|
||||||
|
private static boolean listenerRegistered = false;
|
||||||
|
|
||||||
private final NamespacedKey blockKey;
|
private final NamespacedKey blockKey;
|
||||||
|
|
||||||
|
private static final class BlocksMenuHolder implements InventoryHolder {
|
||||||
|
private final Inventory inventory;
|
||||||
|
|
||||||
|
private BlocksMenuHolder(String title) {
|
||||||
|
this.inventory = Bukkit.createInventory(this, MENU_SIZE, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BlocksMenuCommand() {
|
public BlocksMenuCommand() {
|
||||||
super("essentialsc.command.blocks");
|
super("essentialsc.command.blocks");
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
addConfigDefaults();
|
||||||
blockKey = new NamespacedKey(plugin, "block_key");
|
if (!listenerRegistered) {
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
listenerRegistered = true;
|
||||||
|
}
|
||||||
|
this.blockKey = new NamespacedKey(plugin, "block_key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(@NotNull Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
openMenu(player);
|
openMenu(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openMenu(Player player) {
|
private void openMenu(Player player) {
|
||||||
String title = plugin.getConfig().getString("blocks-menu.title", "&6&lEssentialsC &8- &e&l功能方块菜单");
|
Inventory menu = new BlocksMenuHolder(getLang().getString("blocks-menu.title")).getInventory();
|
||||||
Inventory menu = Bukkit.createInventory(null, MENU_SIZE, translateColor(title));
|
|
||||||
|
var sectionsConfig = plugin.getConfig().getConfigurationSection("blocks-menu.sections");
|
||||||
// 从配置中读取所有物品
|
if (sectionsConfig != null) {
|
||||||
var itemsConfig = plugin.getConfig().getConfigurationSection("blocks-menu.items");
|
int visibleSections = renderSections(menu, player, sectionsConfig);
|
||||||
if (itemsConfig == null) return;
|
if (visibleSections > 1) {
|
||||||
|
renderDivider(menu);
|
||||||
for (String key : itemsConfig.getKeys(false)) {
|
|
||||||
var section = itemsConfig.getConfigurationSection(key);
|
|
||||||
if (section == null) continue;
|
|
||||||
|
|
||||||
// 检查权限
|
|
||||||
String permission = section.getString("permission");
|
|
||||||
if (permission != null && !player.hasPermission(permission)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
if (menu.isEmpty()) {
|
||||||
int slot = section.getInt("slot");
|
player.sendMessage(getLang().getPrefixedString("messages.blocks-menu-empty"));
|
||||||
Material material = Material.matchMaterial(section.getString("material", "STONE"));
|
return;
|
||||||
if (material == null) material = Material.STONE;
|
}
|
||||||
|
player.openInventory(menu);
|
||||||
String name = translateColor(section.getString("name", "&fItem"));
|
return;
|
||||||
java.util.List<String> lore = section.getStringList("lore").stream()
|
|
||||||
.map(this::translateColor)
|
|
||||||
.collect(java.util.stream.Collectors.toList());
|
|
||||||
|
|
||||||
addItem(menu, slot, material, name, lore, key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var itemsConfig = plugin.getConfig().getConfigurationSection("blocks-menu.items");
|
||||||
|
if (itemsConfig == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderItems(menu, player, itemsConfig);
|
||||||
|
if (menu.isEmpty()) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.blocks-menu-empty"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
player.openInventory(menu);
|
player.openInventory(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addItem(Inventory inv, int slot, Material material, String name, java.util.List<String> lore, String key) {
|
private int renderSections(Inventory menu, Player player, org.bukkit.configuration.ConfigurationSection sectionsConfig) {
|
||||||
ItemStack item = new ItemStack(material);
|
int visibleSections = 0;
|
||||||
|
for (String sectionKey : sectionsConfig.getKeys(false)) {
|
||||||
|
var section = sectionsConfig.getConfigurationSection(sectionKey);
|
||||||
|
if (section == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemsConfig = section.getConfigurationSection("items");
|
||||||
|
if (itemsConfig == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MenuItem> visibleItems = collectVisibleItems(player, itemsConfig);
|
||||||
|
if (visibleItems.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
visibleSections++;
|
||||||
|
for (MenuItem item : visibleItems) {
|
||||||
|
addItem(menu, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return visibleSections;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderItems(Inventory menu, Player player, org.bukkit.configuration.ConfigurationSection itemsConfig) {
|
||||||
|
for (MenuItem item : collectVisibleItems(player, itemsConfig)) {
|
||||||
|
addItem(menu, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MenuItem> collectVisibleItems(Player player, org.bukkit.configuration.ConfigurationSection itemsConfig) {
|
||||||
|
List<MenuItem> items = new ArrayList<>();
|
||||||
|
for (String key : itemsConfig.getKeys(false)) {
|
||||||
|
var section = itemsConfig.getConfigurationSection(key);
|
||||||
|
if (section == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String permission = section.getString("permission");
|
||||||
|
if (permission != null && !permission.isBlank() && !player.hasPermission(permission)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String commandKey = section.getString("command", key);
|
||||||
|
if (!CommandRegistry.isAvailable(commandKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem item = createMenuItem(section, commandKey);
|
||||||
|
if (item != null) {
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MenuItem createMenuItem(org.bukkit.configuration.ConfigurationSection section, String commandKey) {
|
||||||
|
int slot = section.getInt("slot", -1);
|
||||||
|
if (slot < 0 || slot >= MENU_SIZE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material material = Material.matchMaterial(section.getString("material", "STONE"));
|
||||||
|
if (material == null) {
|
||||||
|
material = Material.STONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = getLang().getString("blocks-menu.items." + commandKey + ".name");
|
||||||
|
List<String> lore = getLang().getStringList("blocks-menu.items." + commandKey + ".lore");
|
||||||
|
return new MenuItem(slot, material, name, lore, commandKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addItem(Inventory inventory, MenuItem menuItem) {
|
||||||
|
ItemStack item = new ItemStack(menuItem.material());
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
meta.setDisplayName(name);
|
meta.setDisplayName(menuItem.name());
|
||||||
meta.setLore(lore);
|
meta.setLore(menuItem.lore().isEmpty() ? null : menuItem.lore());
|
||||||
meta.getPersistentDataContainer().set(this.blockKey, PersistentDataType.STRING, key);
|
if (menuItem.commandKey() != null && !menuItem.commandKey().isBlank()) {
|
||||||
|
meta.getPersistentDataContainer().set(blockKey, PersistentDataType.STRING, menuItem.commandKey());
|
||||||
|
}
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
inv.setItem(slot, item);
|
inventory.setItem(menuItem.slot(), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void renderDivider(Inventory inventory) {
|
||||||
|
ItemStack divider = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
|
||||||
|
ItemMeta meta = divider.getItemMeta();
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName(" ");
|
||||||
|
divider.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int slot : DIVIDER_SLOTS) {
|
||||||
|
if (inventory.getItem(slot) == null) {
|
||||||
|
inventory.setItem(slot, divider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMenuClick(InventoryClickEvent event) {
|
public void onMenuClick(InventoryClickEvent event) {
|
||||||
// 动态获取配置的标题
|
if (!(event.getView().getTopInventory().getHolder(false) instanceof BlocksMenuHolder)) {
|
||||||
String configTitle = plugin.getConfig().getString("blocks-menu.title", "&6&lEssentialsC &8- &e&l功能方块菜单");
|
return;
|
||||||
String actualTitle = translateColor(configTitle);
|
}
|
||||||
|
|
||||||
if (!event.getView().getTitle().equals(actualTitle)) return;
|
|
||||||
if (!(event.getWhoClicked() instanceof Player player)) return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getClickedInventory() != event.getView().getTopInventory()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack clicked = event.getCurrentItem();
|
ItemStack clicked = event.getCurrentItem();
|
||||||
if (clicked == null || !clicked.hasItemMeta()) return;
|
if (clicked == null || !clicked.hasItemMeta()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ItemMeta meta = clicked.getItemMeta();
|
ItemMeta meta = clicked.getItemMeta();
|
||||||
String key = meta.getPersistentDataContainer().get(this.blockKey, PersistentDataType.STRING);
|
String key = meta.getPersistentDataContainer().get(blockKey, PersistentDataType.STRING);
|
||||||
|
if (key == null || key.isBlank()) {
|
||||||
// 点击后执行对应命令并播放音效(如果有)
|
return;
|
||||||
if (key != null && HelpCommand.COMMAND_CACHE.containsKey(key)) {
|
}
|
||||||
playBlockOpenSound(player, key);
|
|
||||||
HelpCommand.COMMAND_CACHE.get(key).execute(player, new String[]{});
|
BaseCommand blockCommand = CommandRegistry.getCommand(key);
|
||||||
|
if (blockCommand == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String permission = blockCommand.getPermission();
|
||||||
|
if (permission != null && !permission.isBlank() && !player.hasPermission(permission)) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.no-permission",
|
||||||
|
Map.of("permission", permission)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockCommand.execute(player, new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMenuDrag(InventoryDragEvent event) {
|
||||||
|
if (!(event.getView().getTopInventory().getHolder(false) instanceof BlocksMenuHolder)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int topSize = event.getView().getTopInventory().getSize();
|
||||||
|
for (int rawSlot : event.getRawSlots()) {
|
||||||
|
if (rawSlot >= 0 && rawSlot < topSize) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 播放对应方块的打开音效(优先使用交互音效)
|
|
||||||
*/
|
|
||||||
private void playBlockOpenSound(Player player, String key) {
|
|
||||||
org.bukkit.Sound sound = switch (key) {
|
|
||||||
case "workbench" -> org.bukkit.Sound.BLOCK_WOOD_HIT;
|
|
||||||
case "anvil" -> org.bukkit.Sound.BLOCK_ANVIL_USE;
|
|
||||||
case "cartographytable" -> org.bukkit.Sound.UI_CARTOGRAPHY_TABLE_TAKE_RESULT;
|
|
||||||
case "grindstone" -> org.bukkit.Sound.BLOCK_GRINDSTONE_USE;
|
|
||||||
case "loom" -> org.bukkit.Sound.UI_LOOM_TAKE_RESULT;
|
|
||||||
case "smithingtable" -> org.bukkit.Sound.BLOCK_SMITHING_TABLE_USE;
|
|
||||||
case "stonecutter" -> org.bukkit.Sound.BLOCK_STONE_HIT;
|
|
||||||
case "enderchest" -> org.bukkit.Sound.BLOCK_ENDER_CHEST_OPEN;
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (sound != null) {
|
|
||||||
player.playSound(player.getLocation(), sound, 1.0f, 1.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 转换颜色代码 & -> §
|
|
||||||
*/
|
|
||||||
private String translateColor(String text) {
|
private String translateColor(String text) {
|
||||||
return text.replace("&", "§");
|
return text == null ? "" : ChatColor.translateAlternateColorCodes('&', text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addConfigDefaults() {
|
||||||
|
plugin.getConfig().addDefault("blocks-menu.layout-version", 2);
|
||||||
|
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.blocks.items.workbench", 10, "CRAFTING_TABLE",
|
||||||
|
"essentialsc.command.workbench", "workbench");
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.blocks.items.enderchest", 11, "ENDER_CHEST",
|
||||||
|
"essentialsc.command.enderchest", "enderchest");
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.blocks.items.anvil", 12, "ANVIL",
|
||||||
|
"essentialsc.command.anvil", "anvil");
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.blocks.items.grindstone", 19, "GRINDSTONE",
|
||||||
|
"essentialsc.command.grindstone", "grindstone");
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.blocks.items.smithingtable", 20, "SMITHING_TABLE",
|
||||||
|
"essentialsc.command.smithingtable", "smithingtable");
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.blocks.items.stonecutter", 21, "STONECUTTER",
|
||||||
|
"essentialsc.command.stonecutter", "stonecutter");
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.blocks.items.loom", 28, "LOOM",
|
||||||
|
"essentialsc.command.loom", "loom");
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.blocks.items.cartographytable", 29, "CARTOGRAPHY_TABLE",
|
||||||
|
"essentialsc.command.cartographytable", "cartographytable");
|
||||||
|
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.shortcuts.items.nightvision", 14, "TINTED_GLASS",
|
||||||
|
"essentialsc.command.nightvision", "nightvision");
|
||||||
|
addMenuItemDefaults("blocks-menu.sections.shortcuts.items.glow", 15, "GLOWSTONE",
|
||||||
|
"essentialsc.command.glow", "glow");
|
||||||
|
|
||||||
|
plugin.getConfig().options().copyDefaults(true);
|
||||||
|
migrateLayoutIfNeeded();
|
||||||
|
plugin.saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void migrateLayoutIfNeeded() {
|
||||||
|
boolean hasStoredLayoutVersion = plugin.getConfig().contains("blocks-menu.layout-version", true);
|
||||||
|
if (hasStoredLayoutVersion && plugin.getConfig().getInt("blocks-menu.layout-version", 0) >= 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
applySlot("blocks", "workbench", 10);
|
||||||
|
applySlot("blocks", "enderchest", 11);
|
||||||
|
applySlot("blocks", "anvil", 12);
|
||||||
|
applySlot("blocks", "grindstone", 19);
|
||||||
|
applySlot("blocks", "smithingtable", 20);
|
||||||
|
applySlot("blocks", "stonecutter", 21);
|
||||||
|
applySlot("blocks", "loom", 28);
|
||||||
|
applySlot("blocks", "cartographytable", 29);
|
||||||
|
applySlot("shortcuts", "nightvision", 14);
|
||||||
|
applySlot("shortcuts", "glow", 15);
|
||||||
|
|
||||||
|
plugin.getConfig().set("blocks-menu.sections.blocks.title-item", null);
|
||||||
|
plugin.getConfig().set("blocks-menu.sections.shortcuts.title-item", null);
|
||||||
|
plugin.getConfig().set("blocks-menu.layout-version", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applySlot(String section, String key, int slot) {
|
||||||
|
plugin.getConfig().set("blocks-menu.sections." + section + ".items." + key + ".slot", slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMenuItemDefaults(String path, int slot, String material, String permission, String command) {
|
||||||
|
plugin.getConfig().addDefault(path + ".slot", slot);
|
||||||
|
plugin.getConfig().addDefault(path + ".material", material);
|
||||||
|
plugin.getConfig().addDefault(path + ".permission", permission);
|
||||||
|
plugin.getConfig().addDefault(path + ".command", command);
|
||||||
|
}
|
||||||
|
|
||||||
|
private record MenuItem(int slot, Material material, String name, List<String> lore, String commandKey) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class CartographyTableCommand extends BaseCommand {
|
public class CartographyTableCommand extends BaseCommand {
|
||||||
|
|
||||||
public CartographyTableCommand() {
|
public CartographyTableCommand() {
|
||||||
super("essentialsc.command.cartographytable");
|
super("essentialsc.command.cartographytable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
// 使用 Paper API 打开制图台(标题跟随客户端语言)
|
|
||||||
player.openCartographyTable(null, true);
|
player.openCartographyTable(null, true);
|
||||||
|
playBlockShortcutSound(player, Material.CARTOGRAPHY_TABLE, Sound.ENTITY_VILLAGER_WORK_CARTOGRAPHER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
|
import cn.infstar.essentialsC.tpsbar.TpsBarService;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public final class CommandRegistry {
|
||||||
|
|
||||||
|
private static final Map<String, CommandSpec> COMMANDS = new LinkedHashMap<>();
|
||||||
|
private static final Map<String, String> ALIAS_TO_COMMAND = new HashMap<>();
|
||||||
|
private static final Map<String, BaseCommand> COMMAND_CACHE = new HashMap<>();
|
||||||
|
private static final Set<String> UNAVAILABLE_COMMANDS = new java.util.HashSet<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
register("workbench", "essentialsc.command.workbench", "cn.infstar.essentialsC.commands.WorkbenchCommand", "wb");
|
||||||
|
register("anvil", "essentialsc.command.anvil", "cn.infstar.essentialsC.commands.AnvilCommand");
|
||||||
|
register("cartographytable", "essentialsc.command.cartographytable", "cn.infstar.essentialsC.commands.CartographyTableCommand", "ct", "cartography");
|
||||||
|
register("grindstone", "essentialsc.command.grindstone", "cn.infstar.essentialsC.commands.GrindstoneCommand", "gs");
|
||||||
|
register("loom", "essentialsc.command.loom", "cn.infstar.essentialsC.commands.LoomCommand");
|
||||||
|
register("smithingtable", "essentialsc.command.smithingtable", "cn.infstar.essentialsC.commands.SmithingTableCommand", "st", "smithing");
|
||||||
|
register("stonecutter", "essentialsc.command.stonecutter", "cn.infstar.essentialsC.commands.StonecutterCommand", "sc");
|
||||||
|
register("enderchest", "essentialsc.command.enderchest", "cn.infstar.essentialsC.commands.EnderChestCommand", "ec");
|
||||||
|
register("blocks", "essentialsc.command.blocks", "cn.infstar.essentialsC.commands.BlocksMenuCommand");
|
||||||
|
register("hat", "essentialsc.command.hat", "cn.infstar.essentialsC.commands.HatCommand");
|
||||||
|
register("suicide", "essentialsc.command.suicide", "cn.infstar.essentialsC.commands.SuicideCommand", "die");
|
||||||
|
register("fly", "essentialsc.command.fly", "cn.infstar.essentialsC.commands.FlyCommand");
|
||||||
|
register("nightvision", "essentialsc.command.nightvision", "cn.infstar.essentialsC.commands.NightVisionCommand", "nv");
|
||||||
|
register("glow", "essentialsc.command.glow", "cn.infstar.essentialsC.commands.GlowCommand");
|
||||||
|
register("heal", "essentialsc.command.heal", "cn.infstar.essentialsC.commands.HealCommand");
|
||||||
|
register("vanish", "essentialsc.command.vanish", "cn.infstar.essentialsC.commands.VanishCommand", "v");
|
||||||
|
register("seen", "essentialsc.command.seen", "cn.infstar.essentialsC.commands.SeenCommand", "info");
|
||||||
|
register("feed", "essentialsc.command.feed", "cn.infstar.essentialsC.commands.FeedCommand");
|
||||||
|
register("repair", "essentialsc.command.repair", "cn.infstar.essentialsC.commands.RepairCommand", "rep");
|
||||||
|
register("tpsbar", "essentialsc.command.tpsbar", "cn.infstar.essentialsC.commands.TpsBarCommand");
|
||||||
|
register("mobdrops", "essentialsc.mobdrops.enderman", "cn.infstar.essentialsC.commands.MobDropCommand");
|
||||||
|
registerSubCommand("admin", "essentialsc.command.admin", "cn.infstar.essentialsC.commands.AdminCommand");
|
||||||
|
}
|
||||||
|
|
||||||
|
private CommandRegistry() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void register(String name, String permission, String className, String... aliases) {
|
||||||
|
register(name, permission, className, true, aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerSubCommand(String name, String permission, String className, String... aliases) {
|
||||||
|
register(name, permission, className, false, aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void register(String name, String permission, String className, boolean standalone, String... aliases) {
|
||||||
|
List<String> aliasList = List.of(aliases);
|
||||||
|
CommandSpec spec = new CommandSpec(name, permission, className, aliasList, standalone);
|
||||||
|
COMMANDS.put(name, spec);
|
||||||
|
ALIAS_TO_COMMAND.put(name, name);
|
||||||
|
for (String alias : aliasList) {
|
||||||
|
ALIAS_TO_COMMAND.put(alias, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<CommandSpec> getCommandSpecs() {
|
||||||
|
return Collections.unmodifiableCollection(COMMANDS.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String resolveCommandName(String input) {
|
||||||
|
if (input == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ALIAS_TO_COMMAND.get(input.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isAvailable(String name) {
|
||||||
|
return getCommand(name) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPermission(String name) {
|
||||||
|
CommandSpec spec = COMMANDS.get(name);
|
||||||
|
return spec == null ? null : spec.permission();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BaseCommand getCommand(String name) {
|
||||||
|
String resolvedName = resolveCommandName(name);
|
||||||
|
if (resolvedName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseCommand cached = COMMAND_CACHE.get(resolvedName);
|
||||||
|
if (cached != null) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
if (UNAVAILABLE_COMMANDS.contains(resolvedName)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isRuntimeDisabled(resolvedName)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandSpec spec = COMMANDS.get(resolvedName);
|
||||||
|
if (spec == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class<?> rawClass = Class.forName(spec.className());
|
||||||
|
if (!BaseCommand.class.isAssignableFrom(rawClass)) {
|
||||||
|
UNAVAILABLE_COMMANDS.add(resolvedName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Constructor<? extends BaseCommand> constructor = rawClass.asSubclass(BaseCommand.class).getDeclaredConstructor();
|
||||||
|
BaseCommand command = constructor.newInstance();
|
||||||
|
COMMAND_CACHE.put(resolvedName, command);
|
||||||
|
return command;
|
||||||
|
} catch (ReflectiveOperationException | LinkageError ignored) {
|
||||||
|
UNAVAILABLE_COMMANDS.add(resolvedName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isRuntimeDisabled(String resolvedName) {
|
||||||
|
if (!"tpsbar".equals(resolvedName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
EssentialsC plugin = EssentialsC.getPlugin(EssentialsC.class);
|
||||||
|
TpsBarService tpsBarService = plugin.getTpsBarManager();
|
||||||
|
return tpsBarService == null || !tpsBarService.isPluginCommandEnabled();
|
||||||
|
} catch (IllegalStateException ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record CommandSpec(String name, String permission, String className, List<String> aliases, boolean standalone) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,19 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
|
||||||
* 末影箱命令 - 参考 EssentialsX 实现
|
|
||||||
* 直接打开玩家的末影箱,确保数据安全
|
|
||||||
*/
|
|
||||||
public class EnderChestCommand extends BaseCommand {
|
public class EnderChestCommand extends BaseCommand {
|
||||||
|
|
||||||
public EnderChestCommand() {
|
public EnderChestCommand() {
|
||||||
super("essentialsc.command.enderchest");
|
super("essentialsc.command.enderchest");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
// 直接打开玩家的末影箱(EssentialsX 方式)
|
|
||||||
// 优点:100% 安全,不会吞物品或刷物品
|
|
||||||
// 缺点:标题显示为 "Ender Chest"(由客户端语言决定)
|
|
||||||
player.openInventory(player.getEnderChest());
|
player.openInventory(player.getEnderChest());
|
||||||
|
playBlockShortcutSound(player, Material.ENDER_CHEST, Sound.BLOCK_ENDER_CHEST_OPEN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,42 +2,40 @@ package cn.infstar.essentialsC.commands;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class FeedCommand extends BaseCommand {
|
public class FeedCommand extends BaseCommand {
|
||||||
|
|
||||||
public FeedCommand() {
|
public FeedCommand() {
|
||||||
super("essentialsc.command.feed");
|
super("essentialsc.command.feed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(@NotNull Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
// 喂饱自己
|
|
||||||
feedPlayer(player);
|
feedPlayer(player);
|
||||||
player.sendMessage(getLang().getString("messages.feed-self"));
|
player.sendMessage(getLang().getPrefixedString("messages.feed-self"));
|
||||||
} else {
|
return true;
|
||||||
// 检查是否有喂饱他人的权限
|
|
||||||
if (!player.hasPermission("essentialsc.command.feed.others")) {
|
|
||||||
player.sendMessage(getLang().getString("messages.no-permission-others"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player target = Bukkit.getPlayer(args[0]);
|
|
||||||
if (target == null) {
|
|
||||||
player.sendMessage(getLang().getString("messages.player-not-found", Map.of("player", args[0])));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
feedPlayer(target);
|
|
||||||
player.sendMessage(getLang().getString("messages.feed-other", Map.of("player", target.getName())));
|
|
||||||
target.sendMessage(getLang().getString("messages.feed-by-other", Map.of("admin", player.getName())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!player.hasPermission("essentialsc.command.feed.others")) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.no-permission-others"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player target = Bukkit.getPlayer(args[0]);
|
||||||
|
if (target == null) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.player-not-found", Map.of("player", args[0])));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
feedPlayer(target);
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.feed-other", Map.of("player", target.getName())));
|
||||||
|
target.sendMessage(getLang().getPrefixedString("messages.feed-by-other", Map.of("admin", player.getName())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void feedPlayer(Player player) {
|
private void feedPlayer(Player player) {
|
||||||
player.setFoodLevel(20);
|
player.setFoodLevel(20);
|
||||||
player.setSaturation(20f);
|
player.setSaturation(20f);
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ public class FlyCommand extends BaseCommand {
|
|||||||
if (currentFlyState) {
|
if (currentFlyState) {
|
||||||
player.setAllowFlight(false);
|
player.setAllowFlight(false);
|
||||||
player.setFlying(false);
|
player.setFlying(false);
|
||||||
player.sendMessage(getLang().getString("messages.fly-disabled"));
|
player.sendMessage(getLang().getPrefixedString("messages.fly-disabled"));
|
||||||
} else {
|
} else {
|
||||||
player.setAllowFlight(true);
|
player.setAllowFlight(true);
|
||||||
player.setFlying(true);
|
player.setFlying(true);
|
||||||
player.sendMessage(getLang().getString("messages.fly-enabled"));
|
player.sendMessage(getLang().getPrefixedString("messages.fly-enabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
public class GlowCommand extends BaseCommand {
|
||||||
|
|
||||||
|
private final NamespacedKey enabledKey;
|
||||||
|
|
||||||
|
public GlowCommand() {
|
||||||
|
super("essentialsc.command.glow");
|
||||||
|
this.enabledKey = new NamespacedKey(plugin, "glow_enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute(Player player, String[] args) {
|
||||||
|
boolean currentState = isPluginGlowEnabled(player);
|
||||||
|
Boolean targetState = resolveTargetState(currentState, args);
|
||||||
|
if (targetState == null) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.glow-usage"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetState) {
|
||||||
|
player.setGlowing(true);
|
||||||
|
player.getPersistentDataContainer().set(enabledKey, PersistentDataType.BYTE, (byte) 1);
|
||||||
|
playShortcutSound(player, Sound.BLOCK_AMETHYST_BLOCK_CHIME);
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.glow-enabled"));
|
||||||
|
} else {
|
||||||
|
if (currentState) {
|
||||||
|
player.setGlowing(false);
|
||||||
|
player.getPersistentDataContainer().remove(enabledKey);
|
||||||
|
}
|
||||||
|
playShortcutSound(player, Sound.BLOCK_AMETHYST_CLUSTER_FALL);
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.glow-disabled"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean resolveTargetState(boolean currentState, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
return !currentState;
|
||||||
|
}
|
||||||
|
|
||||||
|
return switch (args[0].toLowerCase()) {
|
||||||
|
case "on", "true", "enable", "enabled" -> true;
|
||||||
|
case "off", "false", "disable", "disabled" -> false;
|
||||||
|
case "toggle" -> !currentState;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPluginGlowEnabled(Player player) {
|
||||||
|
Byte value = player.getPersistentDataContainer().get(enabledKey, PersistentDataType.BYTE);
|
||||||
|
return value != null && value == (byte) 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class GrindstoneCommand extends BaseCommand {
|
public class GrindstoneCommand extends BaseCommand {
|
||||||
|
|
||||||
public GrindstoneCommand() {
|
public GrindstoneCommand() {
|
||||||
super("essentialsc.command.grindstone");
|
super("essentialsc.command.grindstone");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
// 使用 Paper API 打开砂轮(标题跟随客户端语言)
|
|
||||||
player.openGrindstone(null, true);
|
player.openGrindstone(null, true);
|
||||||
|
playBlockShortcutSound(player, Material.GRINDSTONE, Sound.BLOCK_GRINDSTONE_USE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,37 +6,27 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class HatCommand extends BaseCommand {
|
public class HatCommand extends BaseCommand {
|
||||||
|
|
||||||
public HatCommand() {
|
public HatCommand() {
|
||||||
super("essentialsc.command.hat");
|
super("essentialsc.command.hat");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
ItemStack handItem = player.getInventory().getItemInMainHand();
|
ItemStack handItem = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (handItem == null || handItem.isEmpty()) {
|
if (handItem == null || handItem.isEmpty()) {
|
||||||
player.sendMessage(getLang().getString("messages.hat-no-item"));
|
player.sendMessage(getLang().getPrefixedString("messages.hat-no-item"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack helmet = player.getInventory().getHelmet();
|
ItemStack helmet = player.getInventory().getHelmet();
|
||||||
|
player.getInventory().setHelmet(handItem);
|
||||||
// 如果头盔栏有物品,先放回背包
|
player.getInventory().setItemInMainHand(helmet == null || helmet.isEmpty() ? null : helmet);
|
||||||
if (helmet != null && !helmet.isEmpty()) {
|
|
||||||
player.getInventory().setHelmet(handItem);
|
|
||||||
player.getInventory().setItemInMainHand(helmet);
|
|
||||||
} else {
|
|
||||||
player.getInventory().setHelmet(handItem);
|
|
||||||
player.getInventory().setItemInMainHand(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
|
||||||
String itemName = handItem.getType().toString();
|
player.sendMessage(getLang().getPrefixedString("messages.hat-success",
|
||||||
String message = getLang().getString("messages.hat-success",
|
Map.of("item", handItem.getType().toString())));
|
||||||
Map.of("item", itemName));
|
|
||||||
player.sendMessage(message);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,42 +2,40 @@ package cn.infstar.essentialsC.commands;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class HealCommand extends BaseCommand {
|
public class HealCommand extends BaseCommand {
|
||||||
|
|
||||||
public HealCommand() {
|
public HealCommand() {
|
||||||
super("essentialsc.command.heal");
|
super("essentialsc.command.heal");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(@NotNull Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
// 治疗自己
|
|
||||||
healPlayer(player);
|
healPlayer(player);
|
||||||
player.sendMessage(getLang().getString("messages.heal-self"));
|
player.sendMessage(getLang().getPrefixedString("messages.heal-self"));
|
||||||
} else {
|
return true;
|
||||||
// 检查是否有治疗他人的权限
|
|
||||||
if (!player.hasPermission("essentialsc.command.heal.others")) {
|
|
||||||
player.sendMessage(getLang().getString("messages.no-permission-others"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player target = Bukkit.getPlayer(args[0]);
|
|
||||||
if (target == null) {
|
|
||||||
player.sendMessage(getLang().getString("messages.player-not-found", Map.of("player", args[0])));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
healPlayer(target);
|
|
||||||
player.sendMessage(getLang().getString("messages.heal-other", Map.of("player", target.getName())));
|
|
||||||
target.sendMessage(getLang().getString("messages.heal-by-other", Map.of("admin", player.getName())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!player.hasPermission("essentialsc.command.heal.others")) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.no-permission-others"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player target = Bukkit.getPlayer(args[0]);
|
||||||
|
if (target == null) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.player-not-found", Map.of("player", args[0])));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
healPlayer(target);
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.heal-other", Map.of("player", target.getName())));
|
||||||
|
target.sendMessage(getLang().getPrefixedString("messages.heal-by-other", Map.of("admin", player.getName())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void healPlayer(Player player) {
|
private void healPlayer(Player player) {
|
||||||
player.setHealth(player.getMaxHealth());
|
player.setHealth(player.getMaxHealth());
|
||||||
player.setFoodLevel(20);
|
player.setFoodLevel(20);
|
||||||
|
|||||||
@@ -2,217 +2,228 @@ package cn.infstar.essentialsC.commands;
|
|||||||
|
|
||||||
import cn.infstar.essentialsC.EssentialsC;
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
import cn.infstar.essentialsC.LangManager;
|
import cn.infstar.essentialsC.LangManager;
|
||||||
|
import cn.infstar.essentialsC.tpsbar.TpsBarService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class HelpCommand extends BaseCommand implements TabCompleter {
|
public class HelpCommand extends BaseCommand implements TabCompleter {
|
||||||
|
|
||||||
// 缓存命令实例,避免重复创建
|
|
||||||
static final java.util.Map<String, BaseCommand> COMMAND_CACHE = new java.util.HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
COMMAND_CACHE.put("workbench", new WorkbenchCommand());
|
|
||||||
COMMAND_CACHE.put("anvil", new AnvilCommand());
|
|
||||||
COMMAND_CACHE.put("cartographytable", new CartographyTableCommand());
|
|
||||||
COMMAND_CACHE.put("grindstone", new GrindstoneCommand());
|
|
||||||
COMMAND_CACHE.put("loom", new LoomCommand());
|
|
||||||
COMMAND_CACHE.put("smithingtable", new SmithingTableCommand());
|
|
||||||
COMMAND_CACHE.put("stonecutter", new StonecutterCommand());
|
|
||||||
COMMAND_CACHE.put("enderchest", new EnderChestCommand());
|
|
||||||
COMMAND_CACHE.put("hat", new HatCommand());
|
|
||||||
COMMAND_CACHE.put("suicide", new SuicideCommand());
|
|
||||||
COMMAND_CACHE.put("fly", new FlyCommand());
|
|
||||||
COMMAND_CACHE.put("heal", new HealCommand());
|
|
||||||
COMMAND_CACHE.put("vanish", new VanishCommand());
|
|
||||||
COMMAND_CACHE.put("seen", new SeenCommand());
|
|
||||||
COMMAND_CACHE.put("feed", new FeedCommand());
|
|
||||||
COMMAND_CACHE.put("repair", new RepairCommand());
|
|
||||||
COMMAND_CACHE.put("blocks", new BlocksMenuCommand());
|
|
||||||
}
|
|
||||||
|
|
||||||
public HelpCommand() {
|
public HelpCommand() {
|
||||||
super("essentialsc.command.help");
|
super("essentialsc.command.help");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(@NotNull Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
|
return handleCommand(player, player, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean executeConsole(CommandSender sender, String[] args) {
|
||||||
|
if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
|
||||||
|
if (!sender.hasPermission("essentialsc.command.reload")) {
|
||||||
|
sendNoPermission(sender, "essentialsc.command.reload");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plugin.reloadConfig();
|
||||||
|
EssentialsC.getLangManager().reload();
|
||||||
|
TpsBarService tpsBarService = plugin.getTpsBarManager();
|
||||||
|
if (tpsBarService != null) {
|
||||||
|
tpsBarService.reloadSettings();
|
||||||
|
}
|
||||||
|
sender.sendMessage(getLang().getPrefixedString("messages.config-reloaded"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage(getLang().getPrefixedString("messages.player-only"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean handleCommand(CommandSender sender, Player player, String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
String subCommand = args[0].toLowerCase();
|
String subCommand = args[0].toLowerCase();
|
||||||
|
|
||||||
// 管理相关
|
|
||||||
if (subCommand.equals("reload")) {
|
if (subCommand.equals("reload")) {
|
||||||
if (!player.hasPermission("essentialsc.command.reload")) {
|
if (!sender.hasPermission("essentialsc.command.reload")) {
|
||||||
player.sendMessage(getLang().getString("messages.no-permission"));
|
sendNoPermission(sender, "essentialsc.command.reload");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
EssentialsC.getLangManager().reload();
|
EssentialsC.getLangManager().reload();
|
||||||
player.sendMessage("§a配置已重载!");
|
TpsBarService tpsBarService = plugin.getTpsBarManager();
|
||||||
|
if (tpsBarService != null) {
|
||||||
|
tpsBarService.reloadSettings();
|
||||||
|
}
|
||||||
|
sender.sendMessage(getLang().getPrefixedString("messages.config-reloaded"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// 功能方块和其他命令 - 使用别名映射
|
|
||||||
String actualCommand = getActualCommand(subCommand);
|
String actualCommand = getActualCommand(subCommand);
|
||||||
if (actualCommand != null && COMMAND_CACHE.containsKey(actualCommand)) {
|
BaseCommand targetCommand = CommandRegistry.getCommand(actualCommand);
|
||||||
String permission = getPermissionForCommand(actualCommand);
|
if (actualCommand != null && targetCommand != null) {
|
||||||
if (!player.hasPermission(permission)) {
|
String permission = CommandRegistry.getPermission(actualCommand);
|
||||||
player.sendMessage(getLang().getString("messages.no-permission"));
|
if (permission != null && !player.hasPermission(permission)) {
|
||||||
|
sendNoPermission(player, permission);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// seen 需要特殊处理参数
|
String[] forwardedArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||||
if (actualCommand.equals("seen")) {
|
if (actualCommand.equals("seen") && forwardedArgs.length == 0) {
|
||||||
if (args.length < 2) {
|
player.sendMessage(getLang().getPrefixedString("messages.seen-usage-console"));
|
||||||
player.sendMessage("§c用法: /essc seen <玩家名>");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
COMMAND_CACHE.get("seen").execute(player, new String[]{args[1]});
|
|
||||||
} else {
|
|
||||||
COMMAND_CACHE.get(actualCommand).execute(player, new String[]{});
|
|
||||||
}
|
}
|
||||||
return true;
|
targetCommand.execute(player, forwardedArgs);
|
||||||
} else if (subCommand.equals("version") || subCommand.equals("v")) {
|
|
||||||
player.sendMessage("§6EssentialsC §fv" + plugin.getDescription().getVersion());
|
|
||||||
player.sendMessage("§7运行在 Paper " + Bukkit.getVersion());
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
// 未知子命令
|
|
||||||
player.sendMessage("§c未知子命令: " + subCommand);
|
|
||||||
player.sendMessage("§7使用 §f/essc help §7查看所有可用命令");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subCommand.equals("version") || subCommand.equals("v")) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.version",
|
||||||
|
Map.of("version", plugin.getDescription().getVersion())));
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.paper-version",
|
||||||
|
Map.of("version", Bukkit.getVersion())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.unknown-subcommand",
|
||||||
|
Map.of("command", subCommand)));
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.help-usage"));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示帮助
|
|
||||||
LangManager lang = getLang();
|
LangManager lang = getLang();
|
||||||
String version = plugin.getDescription().getVersion();
|
String version = plugin.getDescription().getVersion();
|
||||||
|
|
||||||
player.sendMessage(lang.getString("help.title"));
|
sendPrefixed(player, lang.getString("help.title"));
|
||||||
player.sendMessage(lang.getString("help.version",
|
sendPrefixed(player, lang.getString("help.version", Map.of("version", version)));
|
||||||
java.util.Map.of("version", version)));
|
|
||||||
player.sendMessage("");
|
player.sendMessage("");
|
||||||
|
|
||||||
// 功能方块命令(检查权限后显示)
|
|
||||||
boolean hasBlockCommands = false;
|
boolean hasBlockCommands = false;
|
||||||
StringBuilder blockCommands = new StringBuilder();
|
StringBuilder blockCommands = new StringBuilder();
|
||||||
|
|
||||||
if (player.hasPermission("essentialsc.command.workbench")) {
|
if (CommandRegistry.isAvailable("workbench") && player.hasPermission("essentialsc.command.workbench")) {
|
||||||
blockCommands.append(lang.getString("help.commands.workbench")).append("\n");
|
blockCommands.append(lang.getString("help.commands.workbench")).append("\n");
|
||||||
hasBlockCommands = true;
|
hasBlockCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.anvil")) {
|
if (CommandRegistry.isAvailable("anvil") && player.hasPermission("essentialsc.command.anvil")) {
|
||||||
blockCommands.append(lang.getString("help.commands.anvil")).append("\n");
|
blockCommands.append(lang.getString("help.commands.anvil")).append("\n");
|
||||||
hasBlockCommands = true;
|
hasBlockCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.cartographytable")) {
|
if (CommandRegistry.isAvailable("cartographytable") && player.hasPermission("essentialsc.command.cartographytable")) {
|
||||||
blockCommands.append(lang.getString("help.commands.cartographytable")).append("\n");
|
blockCommands.append(lang.getString("help.commands.cartographytable")).append("\n");
|
||||||
hasBlockCommands = true;
|
hasBlockCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.grindstone")) {
|
if (CommandRegistry.isAvailable("grindstone") && player.hasPermission("essentialsc.command.grindstone")) {
|
||||||
blockCommands.append(lang.getString("help.commands.grindstone")).append("\n");
|
blockCommands.append(lang.getString("help.commands.grindstone")).append("\n");
|
||||||
hasBlockCommands = true;
|
hasBlockCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.loom")) {
|
if (CommandRegistry.isAvailable("loom") && player.hasPermission("essentialsc.command.loom")) {
|
||||||
blockCommands.append(lang.getString("help.commands.loom")).append("\n");
|
blockCommands.append(lang.getString("help.commands.loom")).append("\n");
|
||||||
hasBlockCommands = true;
|
hasBlockCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.smithingtable")) {
|
if (CommandRegistry.isAvailable("smithingtable") && player.hasPermission("essentialsc.command.smithingtable")) {
|
||||||
blockCommands.append(lang.getString("help.commands.smithingtable")).append("\n");
|
blockCommands.append(lang.getString("help.commands.smithingtable")).append("\n");
|
||||||
hasBlockCommands = true;
|
hasBlockCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.stonecutter")) {
|
if (CommandRegistry.isAvailable("stonecutter") && player.hasPermission("essentialsc.command.stonecutter")) {
|
||||||
blockCommands.append(lang.getString("help.commands.stonecutter")).append("\n");
|
blockCommands.append(lang.getString("help.commands.stonecutter")).append("\n");
|
||||||
hasBlockCommands = true;
|
hasBlockCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.enderchest")) {
|
if (CommandRegistry.isAvailable("enderchest") && player.hasPermission("essentialsc.command.enderchest")) {
|
||||||
blockCommands.append(lang.getString("help.commands.enderchest")).append("\n");
|
blockCommands.append(lang.getString("help.commands.enderchest")).append("\n");
|
||||||
hasBlockCommands = true;
|
hasBlockCommands = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasBlockCommands) {
|
if (hasBlockCommands) {
|
||||||
player.sendMessage(lang.getString("help.section-blocks"));
|
sendPrefixed(player, lang.getString("help.section-blocks"));
|
||||||
player.sendMessage(blockCommands.toString().trim());
|
sendPrefixedLines(player, blockCommands.toString().trim());
|
||||||
player.sendMessage("");
|
player.sendMessage("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 其他命令(检查权限后显示)
|
|
||||||
boolean hasOtherCommands = false;
|
boolean hasOtherCommands = false;
|
||||||
StringBuilder otherCommands = new StringBuilder();
|
StringBuilder otherCommands = new StringBuilder();
|
||||||
|
|
||||||
if (player.hasPermission("essentialsc.command.hat")) {
|
if (CommandRegistry.isAvailable("hat") && player.hasPermission("essentialsc.command.hat")) {
|
||||||
otherCommands.append(lang.getString("help.commands.hat")).append("\n");
|
otherCommands.append(lang.getString("help.commands.hat")).append("\n");
|
||||||
hasOtherCommands = true;
|
hasOtherCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.suicide")) {
|
if (CommandRegistry.isAvailable("suicide") && player.hasPermission("essentialsc.command.suicide")) {
|
||||||
otherCommands.append(lang.getString("help.commands.suicide")).append("\n");
|
otherCommands.append(lang.getString("help.commands.suicide")).append("\n");
|
||||||
hasOtherCommands = true;
|
hasOtherCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.fly")) {
|
if (CommandRegistry.isAvailable("fly") && player.hasPermission("essentialsc.command.fly")) {
|
||||||
otherCommands.append(lang.getString("help.commands.fly")).append("\n");
|
otherCommands.append(lang.getString("help.commands.fly")).append("\n");
|
||||||
hasOtherCommands = true;
|
hasOtherCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.heal")) {
|
if (CommandRegistry.isAvailable("nightvision") && player.hasPermission("essentialsc.command.nightvision")) {
|
||||||
|
otherCommands.append(lang.getString("help.commands.nightvision")).append("\n");
|
||||||
|
hasOtherCommands = true;
|
||||||
|
}
|
||||||
|
if (CommandRegistry.isAvailable("glow") && player.hasPermission("essentialsc.command.glow")) {
|
||||||
|
otherCommands.append(lang.getString("help.commands.glow")).append("\n");
|
||||||
|
hasOtherCommands = true;
|
||||||
|
}
|
||||||
|
if (CommandRegistry.isAvailable("heal") && player.hasPermission("essentialsc.command.heal")) {
|
||||||
otherCommands.append(lang.getString("help.commands.heal")).append("\n");
|
otherCommands.append(lang.getString("help.commands.heal")).append("\n");
|
||||||
hasOtherCommands = true;
|
hasOtherCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.vanish")) {
|
if (CommandRegistry.isAvailable("vanish") && player.hasPermission("essentialsc.command.vanish")) {
|
||||||
otherCommands.append(lang.getString("help.commands.vanish")).append("\n");
|
otherCommands.append(lang.getString("help.commands.vanish")).append("\n");
|
||||||
hasOtherCommands = true;
|
hasOtherCommands = true;
|
||||||
}
|
}
|
||||||
if (player.hasPermission("essentialsc.command.seen")) {
|
if (CommandRegistry.isAvailable("seen") && player.hasPermission("essentialsc.command.seen")) {
|
||||||
otherCommands.append(lang.getString("help.commands.seen")).append("\n");
|
otherCommands.append(lang.getString("help.commands.seen")).append("\n");
|
||||||
hasOtherCommands = true;
|
hasOtherCommands = true;
|
||||||
}
|
}
|
||||||
|
if (CommandRegistry.isAvailable("admin") && player.hasPermission("essentialsc.command.admin")) {
|
||||||
|
otherCommands.append(lang.getString("help.commands.admin")).append("\n");
|
||||||
|
hasOtherCommands = true;
|
||||||
|
}
|
||||||
|
if (CommandRegistry.isAvailable("tpsbar") && player.hasPermission("essentialsc.command.tpsbar")) {
|
||||||
|
otherCommands.append(lang.getString("help.commands.tpsbar")).append("\n");
|
||||||
|
hasOtherCommands = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (hasOtherCommands) {
|
if (hasOtherCommands) {
|
||||||
player.sendMessage(lang.getString("help.section-other"));
|
sendPrefixed(player, lang.getString("help.section-other"));
|
||||||
player.sendMessage(otherCommands.toString().trim());
|
sendPrefixedLines(player, otherCommands.toString().trim());
|
||||||
player.sendMessage("");
|
player.sendMessage("");
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage(lang.getString("help.footer"));
|
sendPrefixed(player, lang.getString("help.footer"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void sendNoPermission(CommandSender sender, String permission) {
|
||||||
* 将别名映射到实际命令名
|
sender.sendMessage(getLang().getPrefixedString("messages.no-permission",
|
||||||
*/
|
Map.of("permission", permission)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPrefixed(CommandSender sender, String message) {
|
||||||
|
sender.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPrefixedLines(CommandSender sender, String message) {
|
||||||
|
for (String line : message.split("\\R")) {
|
||||||
|
sendPrefixed(sender, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getActualCommand(String alias) {
|
private String getActualCommand(String alias) {
|
||||||
return switch (alias) {
|
return CommandRegistry.resolveCommandName(alias);
|
||||||
case "wb" -> "workbench";
|
|
||||||
case "cartography", "ct" -> "cartographytable";
|
|
||||||
case "gs" -> "grindstone";
|
|
||||||
case "smithing", "st" -> "smithingtable";
|
|
||||||
case "sc" -> "stonecutter";
|
|
||||||
case "ec" -> "enderchest";
|
|
||||||
case "die" -> "suicide";
|
|
||||||
case "info" -> "seen";
|
|
||||||
case "rep" -> "repair";
|
|
||||||
default -> alias;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取命令对应的权限节点
|
|
||||||
*/
|
|
||||||
private String getPermissionForCommand(String command) {
|
|
||||||
return "essentialsc.command." + command;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
List<String> completions = new ArrayList<>();
|
List<String> completions = new ArrayList<>();
|
||||||
String partial = args[0].toLowerCase();
|
String partial = args[0].toLowerCase();
|
||||||
|
|
||||||
// 所有可能的子命令及其权限(包括别名)
|
|
||||||
String[][] subCommands = {
|
String[][] subCommands = {
|
||||||
{"reload", "essentialsc.command.reload"},
|
{"reload", "essentialsc.command.reload"},
|
||||||
{"blocks", "essentialsc.command.blocks"},
|
{"blocks", "essentialsc.command.blocks"},
|
||||||
@@ -236,6 +247,9 @@ public class HelpCommand extends BaseCommand implements TabCompleter {
|
|||||||
{"suicide", "essentialsc.command.suicide"},
|
{"suicide", "essentialsc.command.suicide"},
|
||||||
{"die", "essentialsc.command.suicide"},
|
{"die", "essentialsc.command.suicide"},
|
||||||
{"fly", "essentialsc.command.fly"},
|
{"fly", "essentialsc.command.fly"},
|
||||||
|
{"nightvision", "essentialsc.command.nightvision"},
|
||||||
|
{"nv", "essentialsc.command.nightvision"},
|
||||||
|
{"glow", "essentialsc.command.glow"},
|
||||||
{"heal", "essentialsc.command.heal"},
|
{"heal", "essentialsc.command.heal"},
|
||||||
{"vanish", "essentialsc.command.vanish"},
|
{"vanish", "essentialsc.command.vanish"},
|
||||||
{"v", "essentialsc.command.vanish"},
|
{"v", "essentialsc.command.vanish"},
|
||||||
@@ -244,20 +258,29 @@ public class HelpCommand extends BaseCommand implements TabCompleter {
|
|||||||
{"feed", "essentialsc.command.feed"},
|
{"feed", "essentialsc.command.feed"},
|
||||||
{"repair", "essentialsc.command.repair"},
|
{"repair", "essentialsc.command.repair"},
|
||||||
{"rep", "essentialsc.command.repair"},
|
{"rep", "essentialsc.command.repair"},
|
||||||
|
{"tpsbar", "essentialsc.command.tpsbar"},
|
||||||
|
{"mobdrops", "essentialsc.mobdrops.enderman"},
|
||||||
|
{"admin", "essentialsc.command.admin"},
|
||||||
{"version", null},
|
{"version", null},
|
||||||
{"help", null}
|
{"help", null}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (String[] subCmd : subCommands) {
|
for (String[] subCmd : subCommands) {
|
||||||
if (subCmd[0].startsWith(partial)) {
|
if (!subCmd[0].startsWith(partial)) {
|
||||||
if (subCmd[1] == null || sender.hasPermission(subCmd[1])) {
|
continue;
|
||||||
completions.add(subCmd[0]);
|
}
|
||||||
}
|
|
||||||
|
String actualCommand = getActualCommand(subCmd[0]);
|
||||||
|
boolean available = actualCommand == null || CommandRegistry.isAvailable(actualCommand);
|
||||||
|
if (available && (subCmd[1] == null || sender.hasPermission(subCmd[1]))) {
|
||||||
|
completions.add(subCmd[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return completions;
|
return completions;
|
||||||
} else if (args.length == 2) {
|
}
|
||||||
|
|
||||||
|
if (args.length == 2) {
|
||||||
String subCmd = args[0].toLowerCase();
|
String subCmd = args[0].toLowerCase();
|
||||||
if ((subCmd.equals("seen") || subCmd.equals("info")) && sender.hasPermission("essentialsc.command.seen")) {
|
if ((subCmd.equals("seen") || subCmd.equals("info")) && sender.hasPermission("essentialsc.command.seen")) {
|
||||||
List<String> players = new ArrayList<>();
|
List<String> players = new ArrayList<>();
|
||||||
@@ -269,8 +292,38 @@ public class HelpCommand extends BaseCommand implements TabCompleter {
|
|||||||
}
|
}
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((subCmd.equals("nightvision") || subCmd.equals("nv")) && sender.hasPermission("essentialsc.command.nightvision")) {
|
||||||
|
return completeToggleArgs(args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subCmd.equals("glow") && sender.hasPermission("essentialsc.command.glow")) {
|
||||||
|
return completeToggleArgs(args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subCmd.equals("tpsbar") && sender.hasPermission("essentialsc.command.tpsbar.others")) {
|
||||||
|
List<String> players = new ArrayList<>();
|
||||||
|
String partial = args[1].toLowerCase();
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (p.getName().toLowerCase().startsWith(partial)) {
|
||||||
|
players.add(p.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return players;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> completeToggleArgs(String partialInput) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
String partial = partialInput.toLowerCase();
|
||||||
|
for (String option : List.of("on", "off", "toggle")) {
|
||||||
|
if (option.startsWith(partial)) {
|
||||||
|
completions.add(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class LoomCommand extends BaseCommand {
|
public class LoomCommand extends BaseCommand {
|
||||||
|
|
||||||
public LoomCommand() {
|
public LoomCommand() {
|
||||||
super("essentialsc.command.loom");
|
super("essentialsc.command.loom");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
// 使用 Paper API 打开织布机(标题跟随客户端语言)
|
|
||||||
player.openLoom(null, true);
|
player.openLoom(null, true);
|
||||||
|
playBlockShortcutSound(player, Material.LOOM, Sound.UI_LOOM_SELECT_PATTERN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MobDropCommand extends BaseCommand {
|
||||||
|
|
||||||
|
private static final int MENU_SIZE = 27;
|
||||||
|
private static final int ENDERMAN_SLOT = 13;
|
||||||
|
|
||||||
|
public static final class MobDropMenuHolder implements InventoryHolder {
|
||||||
|
private final Inventory inventory;
|
||||||
|
|
||||||
|
public MobDropMenuHolder(String title) {
|
||||||
|
this.inventory = Bukkit.createInventory(this, MENU_SIZE, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MobDropCommand() {
|
||||||
|
super("essentialsc.mobdrops.enderman");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute(Player player, String[] args) {
|
||||||
|
openMobDropMenu(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openMobDropMenu(EssentialsC plugin, Player player) {
|
||||||
|
var lang = EssentialsC.getLangManager();
|
||||||
|
boolean endermanEnabled = plugin.getConfig().getBoolean("mob-drops.enderman.enabled", true);
|
||||||
|
String status = lang.getString(endermanEnabled
|
||||||
|
? "mobdrops-menu.status.enabled"
|
||||||
|
: "mobdrops-menu.status.disabled");
|
||||||
|
|
||||||
|
Inventory menu = new MobDropMenuHolder(lang.getString("mobdrops-menu.title")).getInventory();
|
||||||
|
|
||||||
|
ItemStack endermanItem = new ItemStack(Material.ENDER_PEARL);
|
||||||
|
ItemMeta endermanMeta = endermanItem.getItemMeta();
|
||||||
|
if (endermanMeta != null) {
|
||||||
|
endermanMeta.setDisplayName(lang.getString("mobdrops-menu.enderman.name"));
|
||||||
|
endermanMeta.setLore(List.of(
|
||||||
|
lang.getString("mobdrops-menu.enderman.status", Map.of("status", status)),
|
||||||
|
"",
|
||||||
|
lang.getString("mobdrops-menu.enderman.toggle")
|
||||||
|
));
|
||||||
|
endermanItem.setItemMeta(endermanMeta);
|
||||||
|
}
|
||||||
|
menu.setItem(ENDERMAN_SLOT, endermanItem);
|
||||||
|
|
||||||
|
ItemStack glass = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
|
||||||
|
ItemMeta glassMeta = glass.getItemMeta();
|
||||||
|
if (glassMeta != null) {
|
||||||
|
glassMeta.setDisplayName(" ");
|
||||||
|
glass.setItemMeta(glassMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int slot = 0; slot < MENU_SIZE; slot++) {
|
||||||
|
if (menu.getItem(slot) == null) {
|
||||||
|
menu.setItem(slot, glass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.openInventory(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getEndermanSlot() {
|
||||||
|
return ENDERMAN_SLOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openMobDropMenu(Player player) {
|
||||||
|
openMobDropMenu(plugin, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
public class NightVisionCommand extends BaseCommand {
|
||||||
|
|
||||||
|
private final NamespacedKey enabledKey;
|
||||||
|
|
||||||
|
public NightVisionCommand() {
|
||||||
|
super("essentialsc.command.nightvision");
|
||||||
|
this.enabledKey = new NamespacedKey(plugin, "nightvision_enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute(Player player, String[] args) {
|
||||||
|
boolean currentState = isPluginNightVisionEnabled(player);
|
||||||
|
Boolean targetState = resolveTargetState(currentState, args);
|
||||||
|
if (targetState == null) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.nightvision-usage"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetState) {
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, false, false, false));
|
||||||
|
player.getPersistentDataContainer().set(enabledKey, PersistentDataType.BYTE, (byte) 1);
|
||||||
|
playShortcutSound(player, Sound.BLOCK_BEACON_POWER_SELECT);
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.nightvision-enabled"));
|
||||||
|
} else {
|
||||||
|
if (currentState) {
|
||||||
|
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
|
||||||
|
player.getPersistentDataContainer().remove(enabledKey);
|
||||||
|
}
|
||||||
|
playShortcutSound(player, Sound.BLOCK_BEACON_DEACTIVATE);
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.nightvision-disabled"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean resolveTargetState(boolean currentState, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
return !currentState;
|
||||||
|
}
|
||||||
|
|
||||||
|
return switch (args[0].toLowerCase()) {
|
||||||
|
case "on", "true", "enable", "enabled" -> true;
|
||||||
|
case "off", "false", "disable", "disabled" -> false;
|
||||||
|
case "toggle" -> !currentState;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPluginNightVisionEnabled(Player player) {
|
||||||
|
Byte value = player.getPersistentDataContainer().get(enabledKey, PersistentDataType.BYTE);
|
||||||
|
return value != null && value == (byte) 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,80 +3,71 @@ package cn.infstar.essentialsC.commands;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.Damageable;
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class RepairCommand extends BaseCommand {
|
public class RepairCommand extends BaseCommand {
|
||||||
|
|
||||||
public RepairCommand() {
|
public RepairCommand() {
|
||||||
super("essentialsc.command.repair");
|
super("essentialsc.command.repair");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(@NotNull Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
if (args.length > 0 && args[0].equalsIgnoreCase("all")) {
|
if (args.length > 0 && args[0].equalsIgnoreCase("all")) {
|
||||||
// 检查是否有修复全部的权限
|
|
||||||
if (!player.hasPermission("essentialsc.command.repair.all")) {
|
if (!player.hasPermission("essentialsc.command.repair.all")) {
|
||||||
player.sendMessage(getLang().getString("messages.no-permission-repair-all"));
|
player.sendMessage(getLang().getPrefixedString("messages.no-permission-repair-all"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int repairedCount = repairAll(player);
|
int repairedCount = repairAll(player);
|
||||||
if (repairedCount > 0) {
|
if (repairedCount > 0) {
|
||||||
player.sendMessage(getLang().getString("messages.repair-all-success", java.util.Map.of("count", String.valueOf(repairedCount))));
|
player.sendMessage(getLang().getPrefixedString("messages.repair-all-success",
|
||||||
|
Map.of("count", String.valueOf(repairedCount))));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(getLang().getString("messages.repair-no-items"));
|
player.sendMessage(getLang().getPrefixedString("messages.repair-no-items"));
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
if (item == null || item.getType().isAir()) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.repair-no-item-in-hand"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repairItem(item)) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.repair-hand-success"));
|
||||||
} else {
|
} else {
|
||||||
// 修复手中物品
|
player.sendMessage(getLang().getPrefixedString("messages.repair-not-damaged"));
|
||||||
ItemStack item = player.getInventory().getItemInMainHand();
|
|
||||||
if (item == null || item.getType().isAir()) {
|
|
||||||
player.sendMessage(getLang().getString("messages.repair-no-item-in-hand"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (repairItem(item)) {
|
|
||||||
player.sendMessage(getLang().getString("messages.repair-hand-success"));
|
|
||||||
} else {
|
|
||||||
player.sendMessage(getLang().getString("messages.repair-not-damaged"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean repairItem(ItemStack item) {
|
private boolean repairItem(ItemStack item) {
|
||||||
if (item.getItemMeta() instanceof Damageable damageable) {
|
if (item.getItemMeta() instanceof Damageable damageable && damageable.hasDamage()) {
|
||||||
if (damageable.hasDamage()) {
|
Damageable newMeta = (Damageable) damageable.clone();
|
||||||
Damageable newMeta = (Damageable) damageable.clone();
|
newMeta.setDamage(0);
|
||||||
newMeta.setDamage(0);
|
item.setItemMeta((org.bukkit.inventory.meta.ItemMeta) newMeta);
|
||||||
item.setItemMeta((org.bukkit.inventory.meta.ItemMeta) newMeta);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int repairAll(Player player) {
|
private int repairAll(Player player) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
ItemStack[] contents = player.getInventory().getContents();
|
for (ItemStack item : player.getInventory().getContents()) {
|
||||||
|
if (item != null && !item.getType().isAir() && repairItem(item)) {
|
||||||
for (ItemStack item : contents) {
|
count++;
|
||||||
if (item != null && !item.getType().isAir()) {
|
|
||||||
if (repairItem(item)) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 也修复盔甲栏
|
for (ItemStack item : player.getInventory().getArmorContents()) {
|
||||||
ItemStack[] armor = player.getInventory().getArmorContents();
|
if (item != null && !item.getType().isAir() && repairItem(item)) {
|
||||||
for (ItemStack item : armor) {
|
count++;
|
||||||
if (item != null && !item.getType().isAir()) {
|
|
||||||
if (repairItem(item)) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,57 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class SeenCommand extends BaseCommand {
|
public class SeenCommand extends BaseCommand {
|
||||||
|
|
||||||
public SeenCommand() {
|
public SeenCommand() {
|
||||||
super("essentialsc.command.seen");
|
super("essentialsc.command.seen");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(@NotNull Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
player.sendMessage(getLang().getString("messages.seen-usage"));
|
player.sendMessage(getLang().getPrefixedString("messages.seen-usage"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
|
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
|
||||||
if (!target.hasPlayedBefore() && !target.isOnline()) {
|
if (!target.hasPlayedBefore() && !target.isOnline()) {
|
||||||
player.sendMessage(getLang().getString("messages.player-not-found", Map.of("player", args[0])));
|
player.sendMessage(getLang().getPrefixedString("messages.player-not-found", Map.of("player", args[0])));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
StringBuilder info = new StringBuilder();
|
StringBuilder info = new StringBuilder();
|
||||||
info.append("§6========== §e玩家信息 §6==========\n");
|
info.append(getLang().getPrefix()).append(ChatColor.GOLD).append("Player info: ")
|
||||||
info.append("§7玩家名称: §f").append(target.getName()).append("\n");
|
.append(ChatColor.WHITE).append(target.getName()).append("\n");
|
||||||
|
|
||||||
if (target.isOnline()) {
|
if (target.isOnline()) {
|
||||||
info.append("§7状态: §a在线\n");
|
info.append(ChatColor.GRAY).append("Status: ").append(ChatColor.GREEN).append("Online").append("\n");
|
||||||
Player onlinePlayer = target.getPlayer();
|
Player onlinePlayer = target.getPlayer();
|
||||||
if (onlinePlayer != null) {
|
if (onlinePlayer != null) {
|
||||||
info.append("§7所在世界: §f").append(onlinePlayer.getWorld().getName()).append("\n");
|
info.append(ChatColor.GRAY).append("World: ").append(ChatColor.WHITE)
|
||||||
|
.append(onlinePlayer.getWorld().getName()).append("\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info.append("§7状态: §c离线\n");
|
info.append(ChatColor.GRAY).append("Status: ").append(ChatColor.RED).append("Offline").append("\n");
|
||||||
long lastSeen = target.getLastSeen();
|
long lastSeen = target.getLastSeen();
|
||||||
if (lastSeen > 0) {
|
if (lastSeen > 0) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
info.append(ChatColor.GRAY).append("Last seen: ").append(ChatColor.WHITE)
|
||||||
info.append("§7最后上线: §f").append(sdf.format(new Date(lastSeen))).append("\n");
|
.append(format.format(new Date(lastSeen))).append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info.append("§7首次加入: §f").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(target.getFirstPlayed()))).append("\n");
|
info.append(ChatColor.GRAY).append("First joined: ").append(ChatColor.WHITE)
|
||||||
info.append("§6=============================");
|
.append(format.format(new Date(target.getFirstPlayed())));
|
||||||
|
|
||||||
player.sendMessage(info.toString());
|
player.sendMessage(info.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class SmithingTableCommand extends BaseCommand {
|
public class SmithingTableCommand extends BaseCommand {
|
||||||
|
|
||||||
public SmithingTableCommand() {
|
public SmithingTableCommand() {
|
||||||
super("essentialsc.command.smithingtable");
|
super("essentialsc.command.smithingtable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
// 使用 Paper API 打开锻造台(标题跟随客户端语言)
|
|
||||||
player.openSmithingTable(null, true);
|
player.openSmithingTable(null, true);
|
||||||
|
playBlockShortcutSound(player, Material.SMITHING_TABLE, Sound.BLOCK_SMITHING_TABLE_USE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class StonecutterCommand extends BaseCommand {
|
public class StonecutterCommand extends BaseCommand {
|
||||||
|
|
||||||
public StonecutterCommand() {
|
public StonecutterCommand() {
|
||||||
super("essentialsc.command.stonecutter");
|
super("essentialsc.command.stonecutter");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
// 使用 Paper API 打开切石机(标题跟随客户端语言)
|
|
||||||
player.openStonecutter(null, true);
|
player.openStonecutter(null, true);
|
||||||
|
playBlockShortcutSound(player, Material.STONECUTTER, Sound.UI_STONECUTTER_SELECT_RECIPE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,15 @@ package cn.infstar.essentialsC.commands;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SuicideCommand extends BaseCommand {
|
public class SuicideCommand extends BaseCommand {
|
||||||
|
|
||||||
public SuicideCommand() {
|
public SuicideCommand() {
|
||||||
super("essentialsc.command.suicide");
|
super("essentialsc.command.suicide");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
String message = getLang().getString("messages.suicide-message",
|
|
||||||
Map.of("player", player.getName()));
|
|
||||||
player.setHealth(0);
|
player.setHealth(0);
|
||||||
// 消息会在玩家死亡后显示,所以这里不发送
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import cn.infstar.essentialsC.tpsbar.TpsBarService;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TpsBarCommand extends BaseCommand implements TabCompleter {
|
||||||
|
|
||||||
|
public TpsBarCommand() {
|
||||||
|
super("essentialsc.command.tpsbar");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute(Player player, String[] args) {
|
||||||
|
TpsBarService tpsBarService = plugin.getTpsBarManager();
|
||||||
|
if (tpsBarService == null) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.player-only"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
boolean enabled = tpsBarService.toggle(player);
|
||||||
|
tpsBarService.sendToggleMessage(player, player, enabled);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length != 1) {
|
||||||
|
player.sendMessage(tpsBarService.getUsageMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.hasPermission("essentialsc.command.tpsbar.others")) {
|
||||||
|
player.sendMessage(getLang().getPrefixedString("messages.no-permission",
|
||||||
|
Map.of("permission", "essentialsc.command.tpsbar.others")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<Player> targets = tpsBarService.resolveTargets(player, args[0]);
|
||||||
|
if (targets.isEmpty()) {
|
||||||
|
Player exactPlayer = Bukkit.getPlayerExact(args[0]);
|
||||||
|
if (exactPlayer == null) {
|
||||||
|
player.sendMessage(tpsBarService.getPlayerNotFoundMessage(args[0]));
|
||||||
|
} else {
|
||||||
|
player.sendMessage(tpsBarService.getNoTargetsMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player target : targets) {
|
||||||
|
boolean enabled = tpsBarService.toggle(target);
|
||||||
|
tpsBarService.sendToggleMessage(player, target, enabled);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean executeConsole(CommandSender sender, String[] args) {
|
||||||
|
sender.sendMessage(getLang().getPrefixedString("messages.player-only"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length != 1 || !(sender instanceof Player player)) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.hasPermission("essentialsc.command.tpsbar.others")) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
String partial = args[0].toLowerCase();
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (onlinePlayer.getName().toLowerCase().startsWith(partial)) {
|
||||||
|
completions.add(onlinePlayer.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,38 +1,35 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class VanishCommand extends BaseCommand {
|
public class VanishCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Set<UUID> vanishedPlayers = new HashSet<>();
|
private static final Set<UUID> vanishedPlayers = new HashSet<>();
|
||||||
|
|
||||||
public VanishCommand() {
|
public VanishCommand() {
|
||||||
super("essentialsc.command.vanish");
|
super("essentialsc.command.vanish");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(@NotNull Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
if (vanishedPlayers.contains(uuid)) {
|
if (vanishedPlayers.contains(uuid)) {
|
||||||
// 取消隐身
|
|
||||||
vanishedPlayers.remove(uuid);
|
vanishedPlayers.remove(uuid);
|
||||||
showPlayerToAll(player);
|
showPlayerToAll(player);
|
||||||
player.sendMessage(getLang().getString("messages.vanish-disabled"));
|
player.sendMessage(getLang().getPrefixedString("messages.vanish-disabled"));
|
||||||
} else {
|
} else {
|
||||||
// 开启隐身
|
|
||||||
vanishedPlayers.add(uuid);
|
vanishedPlayers.add(uuid);
|
||||||
hidePlayerFromAll(player);
|
hidePlayerFromAll(player);
|
||||||
player.sendMessage(getLang().getString("messages.vanish-enabled"));
|
player.sendMessage(getLang().getPrefixedString("messages.vanish-enabled"));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hidePlayerFromAll(Player player) {
|
private void hidePlayerFromAll(Player player) {
|
||||||
for (Player online : player.getServer().getOnlinePlayers()) {
|
for (Player online : player.getServer().getOnlinePlayers()) {
|
||||||
if (online != player) {
|
if (online != player) {
|
||||||
@@ -40,7 +37,7 @@ public class VanishCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPlayerToAll(Player player) {
|
private void showPlayerToAll(Player player) {
|
||||||
for (Player online : player.getServer().getOnlinePlayers()) {
|
for (Player online : player.getServer().getOnlinePlayers()) {
|
||||||
if (online != player) {
|
if (online != player) {
|
||||||
@@ -48,7 +45,7 @@ public class VanishCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVanished(Player player) {
|
public static boolean isVanished(Player player) {
|
||||||
return vanishedPlayers.contains(player.getUniqueId());
|
return vanishedPlayers.contains(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package cn.infstar.essentialsC.commands;
|
package cn.infstar.essentialsC.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class WorkbenchCommand extends BaseCommand {
|
public class WorkbenchCommand extends BaseCommand {
|
||||||
|
|
||||||
public WorkbenchCommand() {
|
public WorkbenchCommand() {
|
||||||
super("essentialsc.command.workbench");
|
super("essentialsc.command.workbench");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, String[] args) {
|
protected boolean execute(Player player, String[] args) {
|
||||||
// 打开工作台(标题由客户端语言决定)
|
|
||||||
player.openWorkbench(null, true);
|
player.openWorkbench(null, true);
|
||||||
|
playBlockShortcutSound(player, Material.CRAFTING_TABLE, Sound.BLOCK_CRAFTER_CRAFT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,336 @@
|
|||||||
|
package cn.infstar.essentialsC.listeners;
|
||||||
|
|
||||||
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
||||||
|
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeMap;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为 Fabric / NeoForge 客户端补发配方同步数据,修复 1.21.2+ 的 JEI 配方显示问题。
|
||||||
|
*/
|
||||||
|
public class JeiRecipeSyncListener implements Listener {
|
||||||
|
|
||||||
|
private final EssentialsC plugin;
|
||||||
|
private final boolean enabled;
|
||||||
|
private final boolean debug;
|
||||||
|
private final boolean sendPlayerMessage;
|
||||||
|
|
||||||
|
public JeiRecipeSyncListener(EssentialsC plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
this.enabled = config.getBoolean("jei-sync.enabled", true);
|
||||||
|
this.debug = config.getBoolean("jei-sync.debug", false);
|
||||||
|
this.sendPlayerMessage = config.getBoolean("jei-sync.send-player-message", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
if (!enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
String clientBrand = player.getClientBrandName();
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("========================================");
|
||||||
|
plugin.getLogger().info("玩家 " + player.getName() + " 加入");
|
||||||
|
plugin.getLogger().info("客户端品牌: '" + (clientBrand != null ? clientBrand : "null") + "'");
|
||||||
|
plugin.getLogger().info("JEI 同步功能: " + (enabled ? "启用" : "禁用"));
|
||||||
|
plugin.getLogger().info("========================================");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientBrand == null || clientBrand.isEmpty()) {
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("跳过 " + player.getName() + ":客户端品牌为空");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String brandLower = clientBrand.toLowerCase();
|
||||||
|
if (brandLower.contains("fabric")) {
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("检测到 Fabric 客户端,开始发送配方同步...");
|
||||||
|
}
|
||||||
|
sendPlayerMessage(player, "Fabric");
|
||||||
|
sendFabricRecipeSync(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (brandLower.contains("neoforge") || brandLower.contains("forge")) {
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("检测到 NeoForge/Forge 客户端,开始发送配方同步...");
|
||||||
|
}
|
||||||
|
sendPlayerMessage(player, "NeoForge");
|
||||||
|
sendNeoForgeRecipeSync(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("跳过 " + player.getName() + ":不支持的客户端类型 '" + clientBrand + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPlayerMessage(Player player, String clientType) {
|
||||||
|
if (!sendPlayerMessage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String messageKey;
|
||||||
|
if (clientType.equalsIgnoreCase("fabric")) {
|
||||||
|
messageKey = "messages.jei-sync-fabric";
|
||||||
|
} else if (clientType.equalsIgnoreCase("neoforge")) {
|
||||||
|
messageKey = "messages.jei-sync-neoforge";
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String fullMessage = EssentialsC.getLangManager().getPrefixedString(messageKey);
|
||||||
|
net.kyori.adventure.text.Component component =
|
||||||
|
net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacyAmpersand().deserialize(fullMessage);
|
||||||
|
player.sendMessage(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "deprecation"})
|
||||||
|
private void sendFabricRecipeSync(Player player) {
|
||||||
|
try {
|
||||||
|
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||||
|
MinecraftServer server = serverPlayer.level().getServer();
|
||||||
|
if (server == null) {
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().warning("服务端实例为 null");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RecipeMap recipeMap = server.getRecipeManager().recipes;
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("开始构建 Fabric 配方数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
var list = new ArrayList<FabricRecipeEntry>();
|
||||||
|
var seen = new HashSet<RecipeSerializer<?>>();
|
||||||
|
|
||||||
|
for (RecipeSerializer<?> serializer : BuiltInRegistries.RECIPE_SERIALIZER) {
|
||||||
|
if (!seen.add(serializer)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<RecipeHolder<?>> recipes = new ArrayList<>();
|
||||||
|
for (RecipeHolder<?> holder : recipeMap.values()) {
|
||||||
|
if (holder.value().getSerializer() == serializer) {
|
||||||
|
recipes.add(holder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!recipes.isEmpty()) {
|
||||||
|
RecipeSerializer<?> entrySerializer = recipes.get(0).value().getSerializer();
|
||||||
|
list.add(new FabricRecipeEntry(entrySerializer, recipes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = new FabricRecipeSyncPayload(list);
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("Fabric 配方条目数: " + list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
RegistryFriendlyByteBuf buffer = new RegistryFriendlyByteBuf(Unpooled.buffer(), server.registryAccess());
|
||||||
|
getFabricCodec().encode(buffer, payload);
|
||||||
|
|
||||||
|
byte[] bytes = new byte[buffer.writerIndex()];
|
||||||
|
buffer.getBytes(0, bytes);
|
||||||
|
|
||||||
|
Identifier id = Identifier.fromNamespaceAndPath("fabric", "recipe_sync");
|
||||||
|
DiscardedPayload discardedPayload = new DiscardedPayload(id, bytes);
|
||||||
|
serverPlayer.connection.send(new ClientboundCustomPayloadPacket(discardedPayload));
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("已发送 Fabric 配方同步 [" + id + "], 大小: " + bytes.length + " bytes");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("发送 Fabric 配方同步失败: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "deprecation"})
|
||||||
|
private net.minecraft.network.codec.StreamCodec<RegistryFriendlyByteBuf, FabricRecipeSyncPayload> getFabricCodec() {
|
||||||
|
return FabricRecipeEntry.CODEC.apply(net.minecraft.network.codec.ByteBufCodecs.list())
|
||||||
|
.map(FabricRecipeSyncPayload::new, FabricRecipeSyncPayload::entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "deprecation"})
|
||||||
|
private void sendNeoForgeRecipeSync(Player player) {
|
||||||
|
try {
|
||||||
|
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||||
|
MinecraftServer server = serverPlayer.level().getServer();
|
||||||
|
if (server == null) {
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().warning("服务端实例为 null");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RecipeMap recipeMap = server.getRecipeManager().recipes;
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("开始构建 NeoForge 配方数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
java.util.List<net.minecraft.world.item.crafting.RecipeType<?>> allRecipeTypes =
|
||||||
|
BuiltInRegistries.RECIPE_TYPE.stream().toList();
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("NeoForge 配方类型数: " + allRecipeTypes.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = createNeoForgePayload(allRecipeTypes, recipeMap);
|
||||||
|
RegistryFriendlyByteBuf buffer = new RegistryFriendlyByteBuf(Unpooled.buffer(), server.registryAccess());
|
||||||
|
getNeoForgeStreamCodec().encode(buffer, payload);
|
||||||
|
|
||||||
|
byte[] bytes = new byte[buffer.writerIndex()];
|
||||||
|
buffer.getBytes(0, bytes);
|
||||||
|
|
||||||
|
Identifier id = Identifier.fromNamespaceAndPath("neoforge", "recipe_content");
|
||||||
|
DiscardedPayload discardedPayload = new DiscardedPayload(id, bytes);
|
||||||
|
serverPlayer.connection.send(new ClientboundCustomPayloadPacket(discardedPayload));
|
||||||
|
serverPlayer.connection.send(new net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket(
|
||||||
|
net.minecraft.tags.TagNetworkSerialization.serializeTagsToNetwork(server.registries())
|
||||||
|
));
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
plugin.getLogger().info("已发送 NeoForge 配方同步 [" + id + "], 大小: " + bytes.length + " bytes");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("发送 NeoForge 配方同步失败: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private NeoForgeRecipeSyncPayload createNeoForgePayload(
|
||||||
|
java.util.List<net.minecraft.world.item.crafting.RecipeType<?>> recipeTypes,
|
||||||
|
RecipeMap recipeMap
|
||||||
|
) {
|
||||||
|
var recipeTypeSet = new java.util.HashSet<>(recipeTypes);
|
||||||
|
if (recipeTypeSet.isEmpty()) {
|
||||||
|
return new NeoForgeRecipeSyncPayload(recipeTypeSet, java.util.List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
var recipeSubset = recipeMap.values().stream()
|
||||||
|
.filter(h -> recipeTypeSet.contains(h.value().getType()))
|
||||||
|
.toList();
|
||||||
|
return new NeoForgeRecipeSyncPayload(recipeTypeSet, recipeSubset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "deprecation"})
|
||||||
|
private net.minecraft.network.codec.StreamCodec<RegistryFriendlyByteBuf, NeoForgeRecipeSyncPayload> getNeoForgeStreamCodec() {
|
||||||
|
return net.minecraft.network.codec.StreamCodec.composite(
|
||||||
|
net.minecraft.network.codec.ByteBufCodecs.registry(net.minecraft.core.registries.Registries.RECIPE_TYPE)
|
||||||
|
.apply(net.minecraft.network.codec.ByteBufCodecs.collection(java.util.HashSet::new)),
|
||||||
|
NeoForgeRecipeSyncPayload::recipeTypes,
|
||||||
|
RecipeHolder.STREAM_CODEC.apply(net.minecraft.network.codec.ByteBufCodecs.list()),
|
||||||
|
NeoForgeRecipeSyncPayload::recipes,
|
||||||
|
NeoForgeRecipeSyncPayload::new
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private static class FabricRecipeEntry {
|
||||||
|
// 这里保留 Object,是为了避免直接绑定易变的 NMS 泛型签名。
|
||||||
|
final Object serializer;
|
||||||
|
final List<RecipeHolder<?>> recipes;
|
||||||
|
|
||||||
|
FabricRecipeEntry(Object serializer, List<RecipeHolder<?>> recipes) {
|
||||||
|
this.serializer = serializer;
|
||||||
|
this.recipes = recipes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final net.minecraft.network.codec.StreamCodec<RegistryFriendlyByteBuf, FabricRecipeEntry> CODEC =
|
||||||
|
net.minecraft.network.codec.StreamCodec.ofMember(
|
||||||
|
FabricRecipeEntry::write,
|
||||||
|
FabricRecipeEntry::read
|
||||||
|
);
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static FabricRecipeEntry read(RegistryFriendlyByteBuf buf) {
|
||||||
|
Identifier recipeSerializerId = buf.readIdentifier();
|
||||||
|
RecipeSerializer<?> recipeSerializer = BuiltInRegistries.RECIPE_SERIALIZER.getValue(recipeSerializerId);
|
||||||
|
|
||||||
|
if (recipeSerializer == null) {
|
||||||
|
throw new RuntimeException("Tried syncing unsupported packet serializer '" + recipeSerializerId + "'!");
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = buf.readVarInt();
|
||||||
|
var list = new ArrayList<RecipeHolder<?>>();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
net.minecraft.resources.ResourceKey<net.minecraft.world.item.crafting.Recipe<?>> id =
|
||||||
|
buf.readResourceKey(net.minecraft.core.registries.Registries.RECIPE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
var streamCodecMethod = recipeSerializer.getClass().getMethod("streamCodec");
|
||||||
|
var streamCodec = streamCodecMethod.invoke(recipeSerializer);
|
||||||
|
net.minecraft.world.item.crafting.Recipe<?> recipe =
|
||||||
|
((net.minecraft.network.codec.StreamCodec<RegistryFriendlyByteBuf, net.minecraft.world.item.crafting.Recipe<?>>) streamCodec)
|
||||||
|
.decode(buf);
|
||||||
|
list.add(new RecipeHolder<>(id, recipe));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to decode recipe: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FabricRecipeEntry(recipeSerializer, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void write(RegistryFriendlyByteBuf buf) {
|
||||||
|
try {
|
||||||
|
var getKeyMethod = BuiltInRegistries.RECIPE_SERIALIZER.getClass().getMethod("getKey", Object.class);
|
||||||
|
Identifier identifier = (Identifier) getKeyMethod.invoke(BuiltInRegistries.RECIPE_SERIALIZER, this.serializer);
|
||||||
|
buf.writeIdentifier(identifier);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to get serializer key: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.writeVarInt(this.recipes.size());
|
||||||
|
|
||||||
|
try {
|
||||||
|
var streamCodecMethod = this.serializer.getClass().getMethod("streamCodec");
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
var codec = (net.minecraft.network.codec.StreamCodec<RegistryFriendlyByteBuf, net.minecraft.world.item.crafting.Recipe<?>>)
|
||||||
|
streamCodecMethod.invoke(this.serializer);
|
||||||
|
|
||||||
|
for (RecipeHolder<?> recipe : this.recipes) {
|
||||||
|
buf.writeResourceKey(recipe.id());
|
||||||
|
codec.encode(buf, recipe.value());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to encode recipe: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record FabricRecipeSyncPayload(List<FabricRecipeEntry> entries) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record NeoForgeRecipeSyncPayload(
|
||||||
|
java.util.Set<net.minecraft.world.item.crafting.RecipeType<?>> recipeTypes,
|
||||||
|
java.util.List<RecipeHolder<?>> recipes
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package cn.infstar.essentialsC.listeners;
|
||||||
|
|
||||||
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
|
|
||||||
|
public class MobDropListener implements Listener {
|
||||||
|
|
||||||
|
private final EssentialsC plugin;
|
||||||
|
private boolean endermanDropEnabled;
|
||||||
|
|
||||||
|
public MobDropListener(EssentialsC plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
config.addDefault("mob-drops.enderman.enabled", true);
|
||||||
|
config.options().copyDefaults(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
config.save(plugin.getDataFolder().toPath().resolve("config.yml").toFile());
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("无法保存配置文件: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.endermanDropEnabled = config.getBoolean("mob-drops.enderman.enabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
|
if (event.getEntityType() != EntityType.ENDERMAN) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!plugin.getConfig().getBoolean("mob-drops.enderman.enabled", true)) {
|
||||||
|
event.getDrops().clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload() {
|
||||||
|
loadConfig();
|
||||||
|
plugin.getLogger().info("生物掉落配置已重载(末影人: " + (endermanDropEnabled ? "开启" : "关闭") + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package cn.infstar.essentialsC.listeners;
|
||||||
|
|
||||||
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
|
import cn.infstar.essentialsC.commands.MobDropCommand;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MobDropMenuListener implements Listener {
|
||||||
|
|
||||||
|
private final EssentialsC plugin;
|
||||||
|
|
||||||
|
public MobDropMenuListener(EssentialsC plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
if (!(event.getView().getTopInventory().getHolder(false) instanceof MobDropCommand.MobDropMenuHolder)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack clickedItem = event.getCurrentItem();
|
||||||
|
if (clickedItem == null || clickedItem.getType().isAir()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getRawSlot() == MobDropCommand.getEndermanSlot()) {
|
||||||
|
toggleEndermanDrops(player);
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, () -> MobDropCommand.openMobDropMenu(plugin, player), 2L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleEndermanDrops(Player player) {
|
||||||
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
boolean newValue = !config.getBoolean("mob-drops.enderman.enabled", true);
|
||||||
|
config.set("mob-drops.enderman.enabled", newValue);
|
||||||
|
|
||||||
|
try {
|
||||||
|
config.save(plugin.getDataFolder().toPath().resolve("config.yml").toFile());
|
||||||
|
} catch (Exception e) {
|
||||||
|
player.sendMessage(EssentialsC.getLangManager().getPrefixedString("messages.mobdrop-save-failed",
|
||||||
|
Map.of("error", e.getMessage())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String status = EssentialsC.getLangManager().getString(newValue
|
||||||
|
? "mobdrops-menu.status.enabled"
|
||||||
|
: "mobdrops-menu.status.disabled");
|
||||||
|
player.sendMessage(EssentialsC.getLangManager().getPrefixedString("messages.mobdrop-toggled",
|
||||||
|
Map.of("status", status)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,17 +3,32 @@ package cn.infstar.essentialsC.listeners;
|
|||||||
import cn.infstar.essentialsC.EssentialsC;
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.block.ShulkerBox;
|
import org.bukkit.block.ShulkerBox;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.InventoryView;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -21,12 +36,9 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ShulkerBoxListener implements Listener {
|
public class ShulkerBoxListener implements Listener {
|
||||||
|
|
||||||
private final EssentialsC plugin;
|
private static final int SHULKER_SIZE = 27;
|
||||||
// 存储玩家打开的潜影盒:玩家UUID -> (原始物品快照, 当前物品引用)
|
|
||||||
private final Map<UUID, ShulkerBoxData> openShulkerBoxes = new HashMap<>();
|
|
||||||
|
|
||||||
// 预定义所有潜影盒材质(性能优化)
|
|
||||||
private static final Set<Material> SHULKER_BOX_MATERIALS = Set.of(
|
private static final Set<Material> SHULKER_BOX_MATERIALS = Set.of(
|
||||||
Material.SHULKER_BOX,
|
Material.SHULKER_BOX,
|
||||||
Material.WHITE_SHULKER_BOX,
|
Material.WHITE_SHULKER_BOX,
|
||||||
@@ -46,189 +58,306 @@ public class ShulkerBoxListener implements Listener {
|
|||||||
Material.RED_SHULKER_BOX,
|
Material.RED_SHULKER_BOX,
|
||||||
Material.BLACK_SHULKER_BOX
|
Material.BLACK_SHULKER_BOX
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
private final EssentialsC plugin;
|
||||||
* 潜影盒数据记录
|
private final Map<UUID, OpenShulkerSession> openShulkerBoxes = new HashMap<>();
|
||||||
*/
|
|
||||||
private static class ShulkerBoxData {
|
private static final class ShulkerBoxHolder implements InventoryHolder {
|
||||||
ItemStack originalSnapshot; // 打开时的物品快照(用于验证)
|
private final Inventory inventory;
|
||||||
ItemStack currentItem; // 当前物品引用(用于更新)
|
|
||||||
int totalItems; // 打开时的物品总数(用于防刷)
|
private ShulkerBoxHolder(Component title) {
|
||||||
|
this.inventory = Bukkit.createInventory(this, SHULKER_SIZE, title);
|
||||||
ShulkerBoxData(ItemStack snapshot, ItemStack current, int items) {
|
}
|
||||||
this.originalSnapshot = snapshot;
|
|
||||||
this.currentItem = current;
|
@Override
|
||||||
this.totalItems = items;
|
public Inventory getInventory() {
|
||||||
|
return this.inventory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class OpenShulkerSession {
|
||||||
|
private final ItemStack sourceItem;
|
||||||
|
private final EquipmentSlot sourceHand;
|
||||||
|
private final int preferredSlot;
|
||||||
|
|
||||||
|
private OpenShulkerSession(ItemStack sourceItem, EquipmentSlot sourceHand, int preferredSlot) {
|
||||||
|
this.sourceItem = sourceItem;
|
||||||
|
this.sourceHand = sourceHand;
|
||||||
|
this.preferredSlot = preferredSlot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ShulkerBoxListener(EssentialsC plugin) {
|
public ShulkerBoxListener(EssentialsC plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
// 只处理右键点击空气或方块的事件
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
if (!player.isSneaking() || !player.hasPermission("essentialsc.shulkerbox.open")) {
|
||||||
// 检查权限
|
|
||||||
if (!player.hasPermission("essentialsc.shulkerbox.open")) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack item = event.getItem();
|
if (openShulkerBoxes.containsKey(player.getUniqueId())) {
|
||||||
if (item == null || !isShulkerBox(item)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只有潜行+右键才打开潜影盒
|
EquipmentSlot hand = event.getHand() == EquipmentSlot.OFF_HAND ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND;
|
||||||
if (!player.isSneaking()) {
|
ItemStack sourceItem = getItemFromHand(player, hand);
|
||||||
|
if (!isShulkerBox(sourceItem)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (sourceItem.getAmount() != 1) {
|
||||||
// 取消默认行为(防止放置潜影盒)
|
player.sendMessage(EssentialsC.getLangManager().getPrefixedString("messages.shulkerbox-unstack-first"));
|
||||||
event.setCancelled(true);
|
return;
|
||||||
|
}
|
||||||
// 打开潜影盒
|
|
||||||
openShulkerBox(player, item);
|
if (!(sourceItem.getItemMeta() instanceof BlockStateMeta blockStateMeta)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(blockStateMeta.getBlockState() instanceof ShulkerBox shulkerBox)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setUseItemInHand(org.bukkit.event.Event.Result.DENY);
|
||||||
|
event.setUseInteractedBlock(org.bukkit.event.Event.Result.DENY);
|
||||||
|
|
||||||
|
ItemStack sourceSnapshot = sourceItem.clone();
|
||||||
|
plugin.getServer().getScheduler().runTask(plugin, () -> {
|
||||||
|
if (!player.isOnline() || openShulkerBoxes.containsKey(player.getUniqueId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack currentItem = getItemFromHand(player, hand);
|
||||||
|
if (!isSameShulkerItem(currentItem, sourceSnapshot)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
openShulkerBox(player, hand, sourceSnapshot, shulkerBox);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InventoryView view = event.getView();
|
||||||
|
Inventory topInventory = view.getTopInventory();
|
||||||
|
if (!(topInventory.getHolder(false) instanceof ShulkerBoxHolder)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int topSize = topInventory.getSize();
|
||||||
|
boolean clickTopInventory = event.getRawSlot() >= 0 && event.getRawSlot() < topSize;
|
||||||
|
|
||||||
|
if (clickTopInventory && isShulkerBox(event.getCursor())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
sendNestedMessage(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clickTopInventory && event.getClick() == ClickType.NUMBER_KEY) {
|
||||||
|
ItemStack hotbarItem = player.getInventory().getItem(event.getHotbarButton());
|
||||||
|
if (isShulkerBox(hotbarItem)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
sendNestedMessage(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clickTopInventory && event.getClick() == ClickType.SWAP_OFFHAND) {
|
||||||
|
ItemStack offHandItem = player.getInventory().getItemInOffHand();
|
||||||
|
if (isShulkerBox(offHandItem)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
sendNestedMessage(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.isShiftClick() && isShulkerBox(event.getCurrentItem())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
sendNestedMessage(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onInventoryDrag(InventoryDragEvent event) {
|
||||||
|
InventoryView view = event.getView();
|
||||||
|
Inventory topInventory = view.getTopInventory();
|
||||||
|
if (!(topInventory.getHolder(false) instanceof ShulkerBoxHolder)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isShulkerBox(event.getOldCursor())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int topSize = topInventory.getSize();
|
||||||
|
for (int rawSlot : event.getRawSlots()) {
|
||||||
|
if (rawSlot >= 0 && rawSlot < topSize) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
if (event.getWhoClicked() instanceof Player player) {
|
||||||
|
sendNestedMessage(player);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClose(InventoryCloseEvent event) {
|
public void onInventoryClose(InventoryCloseEvent event) {
|
||||||
if (!(event.getPlayer() instanceof Player player)) {
|
if (!(event.getPlayer() instanceof Player player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID playerId = player.getUniqueId();
|
|
||||||
ShulkerBoxData data = openShulkerBoxes.remove(playerId);
|
|
||||||
|
|
||||||
if (data == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Inventory closedInventory = event.getInventory();
|
|
||||||
ItemStack currentItem = data.currentItem;
|
|
||||||
|
|
||||||
// 验证物品是否还存在
|
|
||||||
if (currentItem == null || currentItem.getType().isAir()) {
|
|
||||||
// 物品已不存在,丢弃 inventory 中的所有物品
|
|
||||||
for (ItemStack item : closedInventory.getContents()) {
|
|
||||||
if (item != null && !item.getType().isAir()) {
|
|
||||||
player.getWorld().dropItemNaturally(player.getLocation(), item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新潜影盒物品中的内容
|
|
||||||
if (currentItem.getItemMeta() instanceof BlockStateMeta blockStateMeta) {
|
|
||||||
if (blockStateMeta.getBlockState() instanceof ShulkerBox shulkerBox) {
|
|
||||||
// 将 inventory 的内容复制回潜影盒
|
|
||||||
ItemStack[] contents = closedInventory.getContents();
|
|
||||||
for (int i = 0; i < 27 && i < contents.length; i++) {
|
|
||||||
shulkerBox.getInventory().setItem(i, contents[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新物品元数据
|
|
||||||
blockStateMeta.setBlockState(shulkerBox);
|
|
||||||
currentItem.setItemMeta(blockStateMeta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
|
||||||
if (!(event.getWhoClicked() instanceof Player player)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否是玩家打开的潜影盒(使用 get 避免两次查找)
|
|
||||||
if (openShulkerBoxes.get(player.getUniqueId()) == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取点击的物品
|
|
||||||
ItemStack clickedItem = event.getCurrentItem();
|
|
||||||
if (clickedItem == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否是潜影盒,如果是则阻止放置
|
|
||||||
if (isShulkerBox(clickedItem)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
player.sendMessage("§c不能在潜影盒中放入另一个潜影盒!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
if (commitOpenShulker(player, event.getInventory())) {
|
||||||
/**
|
player.playSound(player.getLocation(), Sound.BLOCK_SHULKER_BOX_CLOSE, 0.8F, 1.0F);
|
||||||
* 检查物品是否为潜影盒(O(1) 时间复杂度)
|
}
|
||||||
*/
|
|
||||||
private boolean isShulkerBox(ItemStack item) {
|
|
||||||
return SHULKER_BOX_MATERIALS.contains(item.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@EventHandler
|
||||||
* 打开潜影盒
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
*/
|
Player player = event.getPlayer();
|
||||||
private void openShulkerBox(Player player, ItemStack shulkerBox) {
|
commitOpenShulker(player, player.getOpenInventory().getTopInventory());
|
||||||
// 获取潜影盒的 BlockStateMeta
|
}
|
||||||
if (!(shulkerBox.getItemMeta() instanceof BlockStateMeta blockStateMeta)) {
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerKick(PlayerKickEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
commitOpenShulker(player, player.getOpenInventory().getTopInventory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginDisable(PluginDisableEvent event) {
|
||||||
|
if (event.getPlugin() != plugin) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取潜影盒的方块状态
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (!(blockStateMeta.getBlockState() instanceof ShulkerBox shulkerBoxBlock)) {
|
commitOpenShulker(player, player.getOpenInventory().getTopInventory());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean commitOpenShulker(Player player, Inventory inventory) {
|
||||||
|
if (!(inventory.getHolder(false) instanceof ShulkerBoxHolder)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenShulkerSession session = openShulkerBoxes.remove(player.getUniqueId());
|
||||||
|
if (session == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack updatedShulker = session.sourceItem.clone();
|
||||||
|
writeInventoryBack(updatedShulker, inventory.getContents());
|
||||||
|
restoreItemToPlayer(player, session, updatedShulker);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openShulkerBox(Player player, EquipmentSlot hand, ItemStack sourceItem, ShulkerBox shulkerBox) {
|
||||||
|
removeItemFromHand(player, hand);
|
||||||
|
|
||||||
|
ShulkerBoxHolder holder = new ShulkerBoxHolder(resolveTitle(sourceItem));
|
||||||
|
holder.getInventory().setContents(cloneContents(shulkerBox.getInventory().getContents()));
|
||||||
|
|
||||||
|
int preferredSlot = hand == EquipmentSlot.HAND ? player.getInventory().getHeldItemSlot() : -1;
|
||||||
|
openShulkerBoxes.put(player.getUniqueId(), new OpenShulkerSession(sourceItem, hand, preferredSlot));
|
||||||
|
player.openInventory(holder.getInventory());
|
||||||
|
player.playSound(player.getLocation(), Sound.BLOCK_SHULKER_BOX_OPEN, 0.8F, 1.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeInventoryBack(ItemStack shulkerItem, ItemStack[] contents) {
|
||||||
|
if (!(shulkerItem.getItemMeta() instanceof BlockStateMeta blockStateMeta)) {
|
||||||
|
plugin.getLogger().warning("Failed to save shulker box contents: missing BlockStateMeta.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建物品快照(用于后续验证)
|
if (!(blockStateMeta.getBlockState() instanceof ShulkerBox shulkerBox)) {
|
||||||
ItemStack snapshot = shulkerBox.clone();
|
plugin.getLogger().warning("Failed to save shulker box contents: block state is not a ShulkerBox.");
|
||||||
|
return;
|
||||||
// 计算当前物品总数(用于防刷检查)
|
}
|
||||||
int totalItems = 0;
|
|
||||||
for (ItemStack item : shulkerBoxBlock.getInventory().getContents()) {
|
shulkerBox.getInventory().setContents(cloneContents(contents));
|
||||||
if (item != null && !item.getType().isAir()) {
|
blockStateMeta.setBlockState(shulkerBox);
|
||||||
totalItems += item.getAmount();
|
shulkerItem.setItemMeta(blockStateMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restoreItemToPlayer(Player player, OpenShulkerSession session, ItemStack shulkerItem) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
|
||||||
|
if (session.sourceHand == EquipmentSlot.OFF_HAND) {
|
||||||
|
if (isEmpty(inventory.getItemInOffHand())) {
|
||||||
|
inventory.setItemInOffHand(shulkerItem);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (session.preferredSlot >= 0 && isEmpty(inventory.getItem(session.preferredSlot))) {
|
||||||
|
inventory.setItem(session.preferredSlot, shulkerItem);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取潜影盒的自定义名称,如果没有则使用配置中的默认标题
|
Map<Integer, ItemStack> leftovers = inventory.addItem(shulkerItem);
|
||||||
String title;
|
for (ItemStack leftover : leftovers.values()) {
|
||||||
if (shulkerBox.hasItemMeta() && shulkerBox.getItemMeta().hasDisplayName()) {
|
player.getWorld().dropItemNaturally(player.getLocation(), leftover);
|
||||||
// 使用潜影盒的自定义名称
|
}
|
||||||
title = shulkerBox.getItemMeta().getDisplayName();
|
}
|
||||||
|
|
||||||
|
private ItemStack[] cloneContents(ItemStack[] contents) {
|
||||||
|
ItemStack[] copied = new ItemStack[SHULKER_SIZE];
|
||||||
|
for (int i = 0; i < SHULKER_SIZE && i < contents.length; i++) {
|
||||||
|
copied[i] = contents[i] == null ? null : contents[i].clone();
|
||||||
|
}
|
||||||
|
return copied;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack getItemFromHand(Player player, EquipmentSlot hand) {
|
||||||
|
return hand == EquipmentSlot.OFF_HAND
|
||||||
|
? player.getInventory().getItemInOffHand()
|
||||||
|
: player.getInventory().getItemInMainHand();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeItemFromHand(Player player, EquipmentSlot hand) {
|
||||||
|
if (hand == EquipmentSlot.OFF_HAND) {
|
||||||
|
player.getInventory().setItemInOffHand(null);
|
||||||
} else {
|
} else {
|
||||||
// 使用配置文件中的默认标题
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), null);
|
||||||
String defaultTitle = plugin.getConfig().getString("shulkerbox.default-title", "");
|
}
|
||||||
if (defaultTitle != null && !defaultTitle.isEmpty()) {
|
}
|
||||||
// 转换颜色代码 & -> §
|
|
||||||
title = defaultTitle.replace('&', '§');
|
private Component resolveTitle(ItemStack shulkerBox) {
|
||||||
} else {
|
ItemMeta itemMeta = shulkerBox.getItemMeta();
|
||||||
// 如果配置为空,使用 "Shulker Box"(客户端会自动翻译)
|
if (itemMeta != null && itemMeta.hasDisplayName()) {
|
||||||
title = "Shulker Box";
|
Component displayName = itemMeta.displayName();
|
||||||
|
if (displayName != null) {
|
||||||
|
return displayName;
|
||||||
}
|
}
|
||||||
|
return LegacyComponentSerializer.legacySection().deserialize(itemMeta.getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建一个新的 inventory(基于潜影盒的内容)
|
return Component.translatable(shulkerBox.getType().getItemTranslationKey());
|
||||||
Inventory inventory = Bukkit.createInventory(null, 27, title);
|
}
|
||||||
|
|
||||||
// 复制潜影盒的内容到新 inventory
|
private void sendNestedMessage(Player player) {
|
||||||
ItemStack[] contents = shulkerBoxBlock.getInventory().getContents();
|
player.sendMessage(EssentialsC.getLangManager().getPrefixedString("messages.shulkerbox-nested"));
|
||||||
for (int i = 0; i < 27 && i < contents.length; i++) {
|
}
|
||||||
inventory.setItem(i, contents[i]);
|
|
||||||
|
private boolean isShulkerBox(ItemStack item) {
|
||||||
|
return item != null && !item.getType().isAir() && SHULKER_BOX_MATERIALS.contains(item.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEmpty(ItemStack item) {
|
||||||
|
return item == null || item.getType().isAir();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSameShulkerItem(ItemStack currentItem, ItemStack sourceSnapshot) {
|
||||||
|
if (!isShulkerBox(currentItem) || sourceSnapshot == null) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return currentItem.getAmount() == sourceSnapshot.getAmount() && currentItem.isSimilar(sourceSnapshot);
|
||||||
// 记录玩家打开的潜影盒(包含快照和当前引用)
|
|
||||||
openShulkerBoxes.put(player.getUniqueId(), new ShulkerBoxData(snapshot, shulkerBox, totalItems));
|
|
||||||
|
|
||||||
// 打开 inventory
|
|
||||||
player.openInventory(inventory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
390
src/main/java/cn/infstar/essentialsC/tpsbar/TpsBarManager.java
Normal file
390
src/main/java/cn/infstar/essentialsC/tpsbar/TpsBarManager.java
Normal file
@@ -0,0 +1,390 @@
|
|||||||
|
package cn.infstar.essentialsC.tpsbar;
|
||||||
|
|
||||||
|
import cn.infstar.essentialsC.EssentialsC;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.boss.BarColor;
|
||||||
|
import org.bukkit.boss.BarStyle;
|
||||||
|
import org.bukkit.boss.BossBar;
|
||||||
|
import org.bukkit.command.CommandMap;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public final class TpsBarManager implements Listener, TpsBarService {
|
||||||
|
|
||||||
|
private static final double MAX_TPS = 20.0D;
|
||||||
|
private static final int UPDATE_INTERVAL_TICKS = 20;
|
||||||
|
private static final BarStyle BAR_STYLE = BarStyle.SEGMENTED_20;
|
||||||
|
private static final double TPS_WARN_THRESHOLD = 18.0D;
|
||||||
|
private static final double TPS_CRITICAL_THRESHOLD = 15.0D;
|
||||||
|
private static final double MSPT_WARN_THRESHOLD = 40.0D;
|
||||||
|
private static final double MSPT_CRITICAL_THRESHOLD = 50.0D;
|
||||||
|
private static final double PING_WARN_THRESHOLD = 100.0D;
|
||||||
|
private static final double PING_CRITICAL_THRESHOLD = 200.0D;
|
||||||
|
|
||||||
|
private final EssentialsC plugin;
|
||||||
|
private final Set<UUID> enabledPlayers = new LinkedHashSet<>();
|
||||||
|
private final Map<UUID, BossBar> activeBars = new java.util.HashMap<>();
|
||||||
|
|
||||||
|
private BukkitTask updateTask;
|
||||||
|
private Mode mode;
|
||||||
|
private boolean pluginCommandEnabled;
|
||||||
|
private boolean nativeCommandAvailable;
|
||||||
|
private String titleFormat;
|
||||||
|
private String enabledSelfMessage;
|
||||||
|
private String disabledSelfMessage;
|
||||||
|
private String enabledOtherMessage;
|
||||||
|
private String disabledOtherMessage;
|
||||||
|
private String usageMessage;
|
||||||
|
private String playerNotFoundMessage;
|
||||||
|
private String noTargetsMessage;
|
||||||
|
private String nativeDetectedMessage;
|
||||||
|
private String pluginEnabledMessage;
|
||||||
|
private String pluginForcedButNativeExistsMessage;
|
||||||
|
private String modeChangedReloadMessage;
|
||||||
|
|
||||||
|
public TpsBarManager(EssentialsC plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
addConfigDefaults();
|
||||||
|
reloadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPluginCommandEnabled() {
|
||||||
|
return pluginCommandEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNativeCommandAvailable() {
|
||||||
|
return nativeCommandAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadSettings() {
|
||||||
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
var lang = EssentialsC.getLangManager();
|
||||||
|
Mode previousMode = this.mode;
|
||||||
|
|
||||||
|
this.mode = Mode.fromString(config.getString("tpsbar.mode", "auto"));
|
||||||
|
this.titleFormat = lang.getString("tpsbar.title-format");
|
||||||
|
this.enabledSelfMessage = lang.getString("tpsbar.messages.enabled-self");
|
||||||
|
this.disabledSelfMessage = lang.getString("tpsbar.messages.disabled-self");
|
||||||
|
this.enabledOtherMessage = lang.getString("tpsbar.messages.enabled-other");
|
||||||
|
this.disabledOtherMessage = lang.getString("tpsbar.messages.disabled-other");
|
||||||
|
this.usageMessage = lang.getString("tpsbar.messages.usage");
|
||||||
|
this.playerNotFoundMessage = lang.getString("tpsbar.messages.player-not-found");
|
||||||
|
this.noTargetsMessage = lang.getString("tpsbar.messages.no-targets");
|
||||||
|
this.nativeDetectedMessage = lang.getString("tpsbar.messages.native-detected");
|
||||||
|
this.pluginEnabledMessage = lang.getString("tpsbar.messages.plugin-enabled");
|
||||||
|
this.pluginForcedButNativeExistsMessage = lang.getString("tpsbar.messages.plugin-forced-but-native-exists");
|
||||||
|
this.modeChangedReloadMessage = lang.getString("tpsbar.messages.mode-changed-reload");
|
||||||
|
|
||||||
|
this.nativeCommandAvailable = detectNativeTpsBar();
|
||||||
|
this.pluginCommandEnabled = switch (mode) {
|
||||||
|
case OFF -> false;
|
||||||
|
case AUTO -> !nativeCommandAvailable;
|
||||||
|
case ON -> !nativeCommandAvailable;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (previousMode != null && previousMode != mode) {
|
||||||
|
plugin.getLogger().info(stripColor(modeChangedReloadMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nativeCommandAvailable) {
|
||||||
|
if (mode == Mode.AUTO) {
|
||||||
|
plugin.getLogger().info(stripColor(nativeDetectedMessage));
|
||||||
|
} else if (mode == Mode.ON) {
|
||||||
|
plugin.getLogger().warning(stripColor(pluginForcedButNativeExistsMessage));
|
||||||
|
}
|
||||||
|
} else if (pluginCommandEnabled) {
|
||||||
|
plugin.getLogger().info(stripColor(pluginEnabledMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pluginCommandEnabled) {
|
||||||
|
clearActiveBars();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
restartTaskIfNeeded();
|
||||||
|
refreshBars();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
clearActiveBars();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean toggle(Player target) {
|
||||||
|
if (enabledPlayers.contains(target.getUniqueId())) {
|
||||||
|
disable(target);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
enable(target);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendToggleMessage(Player actor, Player target, boolean enabled) {
|
||||||
|
if (actor.getUniqueId().equals(target.getUniqueId())) {
|
||||||
|
actor.sendMessage(prefixed(enabled ? enabledSelfMessage : disabledSelfMessage));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
actor.sendMessage(prefixed(applyPlaceholders(
|
||||||
|
enabled ? enabledOtherMessage : disabledOtherMessage,
|
||||||
|
Map.of("player", target.getName())
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsageMessage() {
|
||||||
|
return prefixed(usageMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPlayerNotFoundMessage(String input) {
|
||||||
|
return prefixed(applyPlaceholders(playerNotFoundMessage, Map.of("player", input)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNoTargetsMessage() {
|
||||||
|
return prefixed(noTargetsMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Player> resolveTargets(Player sender, String input) {
|
||||||
|
Set<Player> targets = new LinkedHashSet<>();
|
||||||
|
try {
|
||||||
|
for (Entity entity : Bukkit.selectEntities(sender, input)) {
|
||||||
|
if (entity instanceof Player target) {
|
||||||
|
targets.add(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targets.isEmpty()) {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player target = Bukkit.getPlayerExact(input);
|
||||||
|
if (target != null) {
|
||||||
|
targets.add(target);
|
||||||
|
}
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
disable(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearActiveBars() {
|
||||||
|
if (updateTask != null) {
|
||||||
|
updateTask.cancel();
|
||||||
|
updateTask = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BossBar bossBar : activeBars.values()) {
|
||||||
|
bossBar.removeAll();
|
||||||
|
}
|
||||||
|
activeBars.clear();
|
||||||
|
enabledPlayers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enable(Player player) {
|
||||||
|
enabledPlayers.add(player.getUniqueId());
|
||||||
|
|
||||||
|
BossBar bossBar = activeBars.computeIfAbsent(player.getUniqueId(), uuid ->
|
||||||
|
Bukkit.createBossBar("", BarColor.GREEN, BAR_STYLE)
|
||||||
|
);
|
||||||
|
bossBar.setVisible(true);
|
||||||
|
bossBar.addPlayer(player);
|
||||||
|
|
||||||
|
updateBar(player, bossBar);
|
||||||
|
startTaskIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disable(Player player) {
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
enabledPlayers.remove(uuid);
|
||||||
|
|
||||||
|
BossBar bossBar = activeBars.remove(uuid);
|
||||||
|
if (bossBar != null) {
|
||||||
|
bossBar.removeAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
stopTaskIfIdle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startTaskIfNeeded() {
|
||||||
|
if (updateTask != null || enabledPlayers.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTask = Bukkit.getScheduler().runTaskTimer(plugin, this::refreshBars, 0L, UPDATE_INTERVAL_TICKS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restartTaskIfNeeded() {
|
||||||
|
if (updateTask != null) {
|
||||||
|
updateTask.cancel();
|
||||||
|
updateTask = null;
|
||||||
|
}
|
||||||
|
startTaskIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopTaskIfIdle() {
|
||||||
|
if (!enabledPlayers.isEmpty() || updateTask == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTask.cancel();
|
||||||
|
updateTask = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshBars() {
|
||||||
|
List<UUID> stalePlayers = new ArrayList<>();
|
||||||
|
for (UUID uuid : enabledPlayers) {
|
||||||
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player == null || !player.isOnline()) {
|
||||||
|
stalePlayers.add(uuid);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BossBar bossBar = activeBars.computeIfAbsent(uuid, ignored ->
|
||||||
|
Bukkit.createBossBar("", BarColor.GREEN, BAR_STYLE)
|
||||||
|
);
|
||||||
|
if (!bossBar.getPlayers().contains(player)) {
|
||||||
|
bossBar.addPlayer(player);
|
||||||
|
}
|
||||||
|
updateBar(player, bossBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (UUID uuid : stalePlayers) {
|
||||||
|
enabledPlayers.remove(uuid);
|
||||||
|
BossBar bossBar = activeBars.remove(uuid);
|
||||||
|
if (bossBar != null) {
|
||||||
|
bossBar.removeAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stopTaskIfIdle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBar(Player player, BossBar bossBar) {
|
||||||
|
double tps = clampTps(plugin.getServer().getTPS()[0]);
|
||||||
|
double mspt = clampMspt(plugin.getServer().getAverageTickTime());
|
||||||
|
int ping = Math.max(0, player.getPing());
|
||||||
|
|
||||||
|
bossBar.setTitle(buildTitle(tps, mspt, ping));
|
||||||
|
bossBar.setColor(resolveBarColor(tps, mspt, ping));
|
||||||
|
bossBar.setStyle(BAR_STYLE);
|
||||||
|
bossBar.setProgress(clamp(tps / MAX_TPS, 0.0D, 1.0D));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildTitle(double tps, double mspt, int ping) {
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', applyPlaceholders(titleFormat, Map.of(
|
||||||
|
"tps_1m", formatDouble(tps),
|
||||||
|
"mspt", formatDouble(mspt),
|
||||||
|
"ping", Integer.toString(ping)
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private BarColor resolveBarColor(double tps, double mspt, int ping) {
|
||||||
|
if (tps <= TPS_CRITICAL_THRESHOLD || mspt >= MSPT_CRITICAL_THRESHOLD || ping >= PING_CRITICAL_THRESHOLD) {
|
||||||
|
return BarColor.RED;
|
||||||
|
}
|
||||||
|
if (tps <= TPS_WARN_THRESHOLD || mspt >= MSPT_WARN_THRESHOLD || ping >= PING_WARN_THRESHOLD) {
|
||||||
|
return BarColor.YELLOW;
|
||||||
|
}
|
||||||
|
return BarColor.GREEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean detectNativeTpsBar() {
|
||||||
|
try {
|
||||||
|
CommandMap commandMap = Bukkit.getCommandMap();
|
||||||
|
org.bukkit.command.Command command = commandMap.getCommand("tpsbar");
|
||||||
|
return command != null;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addConfigDefaults() {
|
||||||
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
config.addDefault("tpsbar.mode", "auto");
|
||||||
|
config.options().copyDefaults(true);
|
||||||
|
plugin.saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String prefixed(String message) {
|
||||||
|
return EssentialsC.getLangManager().getPrefix() + ChatColor.translateAlternateColorCodes('&', message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String applyPlaceholders(String text, Map<String, String> placeholders) {
|
||||||
|
String result = text == null ? "" : text;
|
||||||
|
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||||
|
result = result.replace("{" + entry.getKey() + "}", entry.getValue());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String stripColor(String message) {
|
||||||
|
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', message));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatDouble(double value) {
|
||||||
|
return String.format(Locale.US, "%.2f", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double clampTps(double value) {
|
||||||
|
if (!Double.isFinite(value)) {
|
||||||
|
return 0.0D;
|
||||||
|
}
|
||||||
|
return clamp(value, 0.0D, MAX_TPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double clampMspt(double value) {
|
||||||
|
if (!Double.isFinite(value)) {
|
||||||
|
return 0.0D;
|
||||||
|
}
|
||||||
|
return Math.max(0.0D, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double clamp(double value, double min, double max) {
|
||||||
|
return Math.max(min, Math.min(max, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum Mode {
|
||||||
|
OFF,
|
||||||
|
AUTO,
|
||||||
|
ON;
|
||||||
|
|
||||||
|
private static Mode fromString(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return AUTO;
|
||||||
|
}
|
||||||
|
return switch (value.toLowerCase(Locale.ROOT)) {
|
||||||
|
case "off", "false", "disabled" -> OFF;
|
||||||
|
case "on", "enabled", "plugin" -> ON;
|
||||||
|
default -> AUTO;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package cn.infstar.essentialsC.tpsbar;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface TpsBarService {
|
||||||
|
|
||||||
|
boolean isPluginCommandEnabled();
|
||||||
|
|
||||||
|
boolean isNativeCommandAvailable();
|
||||||
|
|
||||||
|
void reloadSettings();
|
||||||
|
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
boolean toggle(Player target);
|
||||||
|
|
||||||
|
void sendToggleMessage(Player actor, Player target, boolean enabled);
|
||||||
|
|
||||||
|
String getUsageMessage();
|
||||||
|
|
||||||
|
String getPlayerNotFoundMessage(String input);
|
||||||
|
|
||||||
|
String getNoTargetsMessage();
|
||||||
|
|
||||||
|
Collection<Player> resolveTargets(Player sender, String input);
|
||||||
|
}
|
||||||
@@ -1,87 +1,96 @@
|
|||||||
# EssentialsC 配置文件
|
# EssentialsC 主配置文件
|
||||||
# 你可以编辑此文件来自定义插件行为
|
|
||||||
|
|
||||||
# 语言设置
|
# 配置文件版本号
|
||||||
# 可用语言: en_US, zh_CN (你可以添加更多)
|
config-version: 2
|
||||||
|
|
||||||
|
# 语言文件名称,对应插件数据目录下 lang/<语言名>.yml
|
||||||
language: "zh_CN"
|
language: "zh_CN"
|
||||||
|
|
||||||
# 通用设置
|
admin-mode:
|
||||||
settings:
|
# 原版默认飞行速度为 0.1,这里 0.2 表示两倍飞行速度
|
||||||
# 启用或禁用命令反馈消息
|
fly-speed: 0.2
|
||||||
enable-feedback: true
|
actionbar:
|
||||||
|
# 管理模式状态提示的刷新间隔,单位为 tick
|
||||||
|
interval-ticks: 40
|
||||||
|
|
||||||
|
jei-sync:
|
||||||
|
# 是否启用 JEI 配方同步修复
|
||||||
|
enabled: true
|
||||||
|
# 是否输出调试日志
|
||||||
|
debug: false
|
||||||
|
# 是否在玩家加入时发送同步提示
|
||||||
|
send-player-message: true
|
||||||
|
|
||||||
|
mob-drops:
|
||||||
|
enderman:
|
||||||
|
# 是否允许末影人掉落方块
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
tpsbar:
|
||||||
|
# 可选值:off / auto / on
|
||||||
|
# auto: 若服务端没有原生 /tpsbar,则启用插件实现
|
||||||
|
# on: 始终启用插件实现;若服务端已有原生命令,则自动跳过以避免冲突
|
||||||
|
mode: auto
|
||||||
|
|
||||||
# 功能方块菜单配置
|
|
||||||
blocks-menu:
|
blocks-menu:
|
||||||
title: "&6&lEssentialsC &8- &e&l功能方块菜单"
|
# 菜单布局版本,用于后续自动迁移槽位布局
|
||||||
items:
|
layout-version: 2
|
||||||
workbench:
|
sections:
|
||||||
slot: 10
|
blocks:
|
||||||
material: CRAFTING_TABLE
|
items:
|
||||||
name: "&e工作台"
|
workbench:
|
||||||
lore:
|
# 物品所在槽位
|
||||||
- "&7/workbench"
|
slot: 10
|
||||||
- "&7打开工作台"
|
# 菜单图标材质
|
||||||
permission: essentialsc.command.workbench
|
material: CRAFTING_TABLE
|
||||||
anvil:
|
# 所需权限
|
||||||
slot: 11
|
permission: essentialsc.command.workbench
|
||||||
material: ANVIL
|
# 点击后执行的命令键
|
||||||
name: "&e铁砧"
|
command: workbench
|
||||||
lore:
|
enderchest:
|
||||||
- "&7/anvil"
|
slot: 11
|
||||||
- "&7打开铁砧"
|
material: ENDER_CHEST
|
||||||
permission: essentialsc.command.anvil
|
permission: essentialsc.command.enderchest
|
||||||
cartographytable:
|
command: enderchest
|
||||||
slot: 19
|
anvil:
|
||||||
material: CARTOGRAPHY_TABLE
|
slot: 12
|
||||||
name: "&e制图台"
|
material: ANVIL
|
||||||
lore:
|
permission: essentialsc.command.anvil
|
||||||
- "&7/cartographytable"
|
command: anvil
|
||||||
- "&7打开制图台"
|
grindstone:
|
||||||
permission: essentialsc.command.cartographytable
|
slot: 19
|
||||||
grindstone:
|
material: GRINDSTONE
|
||||||
slot: 20
|
permission: essentialsc.command.grindstone
|
||||||
material: GRINDSTONE
|
command: grindstone
|
||||||
name: "&e砂轮"
|
smithingtable:
|
||||||
lore:
|
slot: 20
|
||||||
- "&7/grindstone"
|
material: SMITHING_TABLE
|
||||||
- "&7打开砂轮"
|
permission: essentialsc.command.smithingtable
|
||||||
permission: essentialsc.command.grindstone
|
command: smithingtable
|
||||||
loom:
|
stonecutter:
|
||||||
slot: 21
|
slot: 21
|
||||||
material: LOOM
|
material: STONECUTTER
|
||||||
name: "&e织布机"
|
permission: essentialsc.command.stonecutter
|
||||||
lore:
|
command: stonecutter
|
||||||
- "&7/loom"
|
loom:
|
||||||
- "&7打开织布机"
|
slot: 28
|
||||||
permission: essentialsc.command.loom
|
material: LOOM
|
||||||
smithingtable:
|
permission: essentialsc.command.loom
|
||||||
slot: 22
|
command: loom
|
||||||
material: SMITHING_TABLE
|
cartographytable:
|
||||||
name: "&e锻造台"
|
slot: 29
|
||||||
lore:
|
material: CARTOGRAPHY_TABLE
|
||||||
- "&7/smithingtable"
|
permission: essentialsc.command.cartographytable
|
||||||
- "&7打开锻造台"
|
command: cartographytable
|
||||||
permission: essentialsc.command.smithingtable
|
shortcuts:
|
||||||
stonecutter:
|
items:
|
||||||
slot: 23
|
nightvision:
|
||||||
material: STONECUTTER
|
slot: 14
|
||||||
name: "&e切石机"
|
material: TINTED_GLASS
|
||||||
lore:
|
permission: essentialsc.command.nightvision
|
||||||
- "&7/stonecutter"
|
command: nightvision
|
||||||
- "&7打开切石机"
|
glow:
|
||||||
permission: essentialsc.command.stonecutter
|
slot: 15
|
||||||
enderchest:
|
material: GLOWSTONE
|
||||||
slot: 31
|
permission: essentialsc.command.glow
|
||||||
material: ENDER_CHEST
|
command: glow
|
||||||
name: "&e末影箱"
|
|
||||||
lore:
|
|
||||||
- "&7/enderchest"
|
|
||||||
- "&7打开末影箱"
|
|
||||||
permission: essentialsc.command.enderchest
|
|
||||||
|
|
||||||
# 潜影盒设置
|
|
||||||
shulkerbox:
|
|
||||||
# 潜影盒默认标题(当潜影盒没有自定义名称时使用)
|
|
||||||
# 支持颜色代码(使用 & 符号)
|
|
||||||
# 留空则使用 "Shulker Box"(客户端语言)
|
|
||||||
default-title: "&e潜影盒"
|
|
||||||
|
|||||||
@@ -1,22 +1,36 @@
|
|||||||
# English Language File (en_US)
|
# English language file
|
||||||
# You can customize all messages here
|
|
||||||
|
|
||||||
# Plugin prefix
|
|
||||||
prefix: "&6[EssentialsC] &r"
|
prefix: "&6[EssentialsC] &r"
|
||||||
|
|
||||||
# Command messages
|
|
||||||
messages:
|
messages:
|
||||||
no-permission: "&cYou don't have permission to use this command!\n&7Required permission: {permission}"
|
no-permission: "&cYou don't have permission to use this command!\n&7Required permission: {permission}"
|
||||||
player-only: "&cThis command can only be executed by players!"
|
player-only: "&cThis command can only be executed by players!"
|
||||||
|
config-reloaded: "&aConfiguration reloaded."
|
||||||
|
version: "&fEssentialsC v{version}"
|
||||||
|
paper-version: "&7Running on Paper {version}"
|
||||||
|
unknown-subcommand: "&cUnknown subcommand: {command}"
|
||||||
|
help-usage: "&7Use &f/essc help &7to view available commands."
|
||||||
|
blocks-menu-empty: "&cYou do not currently have any available shortcut menu entries."
|
||||||
|
|
||||||
hat-success: "&aYou are now wearing {item} on your head!"
|
hat-success: "&aYou are now wearing {item} on your head!"
|
||||||
hat-failed: "&cFailed to wear item on head!"
|
hat-failed: "&cFailed to wear the item on your head!"
|
||||||
hat-no-item: "&cYou need to hold an item in your hand!"
|
hat-no-item: "&cYou need to hold an item in your hand!"
|
||||||
suicide-message: "&e{player} has committed suicide!"
|
suicide-message: "&e{player} has committed suicide!"
|
||||||
fly-enabled: "&aFlight mode enabled!"
|
fly-enabled: "&aFlight mode enabled!"
|
||||||
fly-disabled: "&cFlight mode disabled!"
|
fly-disabled: "&cFlight mode disabled!"
|
||||||
|
nightvision-enabled: "&aNight vision enabled!"
|
||||||
|
nightvision-disabled: "&cNight vision disabled!"
|
||||||
|
nightvision-usage: "&cUsage: /nightvision [on|off|toggle]"
|
||||||
|
glow-enabled: "&aGlowing enabled!"
|
||||||
|
glow-disabled: "&cGlowing disabled!"
|
||||||
|
glow-usage: "&cUsage: /glow [on|off|toggle]"
|
||||||
vanish-enabled: "&aYou are now vanished!"
|
vanish-enabled: "&aYou are now vanished!"
|
||||||
vanish-disabled: "&cYou are no longer vanished!"
|
vanish-disabled: "&cYou are no longer vanished!"
|
||||||
seen-usage: "&cUsage: /seen <player>"
|
seen-usage: "&cUsage: /seen <player>"
|
||||||
|
seen-usage-console: "&cUsage: /seen <player>"
|
||||||
|
player-not-found: "&cPlayer not found: {player}"
|
||||||
|
no-permission-others: "&cYou don't have permission to affect other players!"
|
||||||
|
|
||||||
anvil-opened: "&aAnvil opened!"
|
anvil-opened: "&aAnvil opened!"
|
||||||
enchantingtable-opened: "&aEnchanting table opened!"
|
enchantingtable-opened: "&aEnchanting table opened!"
|
||||||
heal-self: "&aYour health and hunger have been restored!"
|
heal-self: "&aYour health and hunger have been restored!"
|
||||||
@@ -31,19 +45,23 @@ messages:
|
|||||||
repair-no-item-in-hand: "&cYou don't have an item in your hand!"
|
repair-no-item-in-hand: "&cYou don't have an item in your hand!"
|
||||||
repair-no-items: "&cNo repairable items in inventory!"
|
repair-no-items: "&cNo repairable items in inventory!"
|
||||||
no-permission-repair-all: "&cYou don't have permission to repair all items!"
|
no-permission-repair-all: "&cYou don't have permission to repair all items!"
|
||||||
player-not-found: "&cPlayer not found: {player}"
|
|
||||||
no-permission-others: "&cYou don't have permission to heal others!"
|
mobdrop-save-failed: "&cFailed to save config: {error}"
|
||||||
|
mobdrop-toggled: "&aEnderman drops are now {status}&a."
|
||||||
# Help command
|
shulkerbox-nested: "&cYou cannot put a shulker box inside another shulker box."
|
||||||
|
shulkerbox-unstack-first: "&cPlease unstack the shulker box before using quick open."
|
||||||
|
jei-sync-fabric: "&6JEI-FIX&8(&bFabric&8): &eSynchronizing recipes..."
|
||||||
|
jei-sync-neoforge: "&6JEI-FIX&8(&bNeoForge&8): &eSynchronizing recipes..."
|
||||||
|
|
||||||
help:
|
help:
|
||||||
title: "&6========== &eEssentialsC Help &6=========="
|
title: "&6========== &eEssentialsC Help &6=========="
|
||||||
version: "&7Plugin Version: &f{version}"
|
version: "&7Plugin Version: &f{version}"
|
||||||
section-blocks: "&6Functional Block Commands:"
|
section-blocks: "&6Functional Block Commands:"
|
||||||
section-other: "&6Other Commands:"
|
section-other: "&6Other Commands:"
|
||||||
footer: "&7Permissions required for each command"
|
footer: "&7Each command requires the corresponding permission."
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
workbench: " &f/workbench &7- Open a workbench"
|
workbench: " &f/workbench &7- Open a crafting table"
|
||||||
anvil: " &f/anvil &7- Open an anvil"
|
anvil: " &f/anvil &7- Open an anvil"
|
||||||
enchantingtable: " &f/enchantingtable &7- Open an enchanting table"
|
enchantingtable: " &f/enchantingtable &7- Open an enchanting table"
|
||||||
cartographytable: " &f/cartographytable &7- Open a cartography table"
|
cartographytable: " &f/cartographytable &7- Open a cartography table"
|
||||||
@@ -52,11 +70,102 @@ help:
|
|||||||
smithingtable: " &f/smithingtable &7- Open a smithing table"
|
smithingtable: " &f/smithingtable &7- Open a smithing table"
|
||||||
stonecutter: " &f/stonecutter &7- Open a stonecutter"
|
stonecutter: " &f/stonecutter &7- Open a stonecutter"
|
||||||
enderchest: " &f/enderchest &7- Open your ender chest"
|
enderchest: " &f/enderchest &7- Open your ender chest"
|
||||||
hat: " &f/hat &7- Wear held item as a hat"
|
blocks: " &f/blocks &7- Open the shortcut menu"
|
||||||
|
hat: " &f/hat &7- Wear the held item as a hat"
|
||||||
suicide: " &f/suicide &7- Commit suicide"
|
suicide: " &f/suicide &7- Commit suicide"
|
||||||
fly: " &f/fly &7- Toggle flight mode"
|
fly: " &f/fly &7- Toggle flight mode"
|
||||||
|
nightvision: " &f/nightvision &7- Toggle night vision"
|
||||||
|
glow: " &f/glow &7- Toggle glowing"
|
||||||
heal: " &f/heal &7- Restore health and hunger"
|
heal: " &f/heal &7- Restore health and hunger"
|
||||||
vanish: " &f/vanish &7- Toggle vanish mode"
|
vanish: " &f/vanish &7- Toggle vanish mode"
|
||||||
seen: " &f/seen &7- View player information"
|
seen: " &f/seen &7- View player information"
|
||||||
feed: " &f/feed &7- Restore hunger"
|
feed: " &f/feed &7- Restore hunger"
|
||||||
repair: " &f/repair &7- Repair hand or all items"
|
repair: " &f/repair &7- Repair held or all items"
|
||||||
|
admin: " &f/essc admin &7- Toggle admin mode"
|
||||||
|
tpsbar: " &f/tpsbar [player] &7- Toggle TPS boss bar"
|
||||||
|
|
||||||
|
blocks-menu:
|
||||||
|
title: "&6&lEssentialsC &8- &e&lShortcut Menu"
|
||||||
|
items:
|
||||||
|
workbench:
|
||||||
|
name: "&eWorkbench"
|
||||||
|
lore:
|
||||||
|
- "&7/workbench"
|
||||||
|
- "&7Open a crafting table"
|
||||||
|
enderchest:
|
||||||
|
name: "&eEnder Chest"
|
||||||
|
lore:
|
||||||
|
- "&7/enderchest"
|
||||||
|
- "&7Open your ender chest"
|
||||||
|
anvil:
|
||||||
|
name: "&eAnvil"
|
||||||
|
lore:
|
||||||
|
- "&7/anvil"
|
||||||
|
- "&7Open an anvil"
|
||||||
|
grindstone:
|
||||||
|
name: "&eGrindstone"
|
||||||
|
lore:
|
||||||
|
- "&7/grindstone"
|
||||||
|
- "&7Open a grindstone"
|
||||||
|
smithingtable:
|
||||||
|
name: "&eSmithing Table"
|
||||||
|
lore:
|
||||||
|
- "&7/smithingtable"
|
||||||
|
- "&7Open a smithing table"
|
||||||
|
stonecutter:
|
||||||
|
name: "&eStonecutter"
|
||||||
|
lore:
|
||||||
|
- "&7/stonecutter"
|
||||||
|
- "&7Open a stonecutter"
|
||||||
|
loom:
|
||||||
|
name: "&eLoom"
|
||||||
|
lore:
|
||||||
|
- "&7/loom"
|
||||||
|
- "&7Open a loom"
|
||||||
|
cartographytable:
|
||||||
|
name: "&eCartography Table"
|
||||||
|
lore:
|
||||||
|
- "&7/cartographytable"
|
||||||
|
- "&7Open a cartography table"
|
||||||
|
nightvision:
|
||||||
|
name: "&bNight Vision"
|
||||||
|
lore:
|
||||||
|
- "&7/nightvision"
|
||||||
|
- "&7Toggle night vision"
|
||||||
|
glow:
|
||||||
|
name: "&eGlow"
|
||||||
|
lore:
|
||||||
|
- "&7/glow"
|
||||||
|
- "&7Toggle your glowing effect"
|
||||||
|
|
||||||
|
admin-mode:
|
||||||
|
actionbar: "&c&lAdmin Mode"
|
||||||
|
messages:
|
||||||
|
enabled: "&aAdmin mode enabled, normal inventory has been saved."
|
||||||
|
disabled: "&cAdmin mode disabled, normal inventory has been restored."
|
||||||
|
crash-restored: "&eThe previous admin mode session has been restored safely."
|
||||||
|
|
||||||
|
tpsbar:
|
||||||
|
title-format: "&eTPS&7: {tps_1m} &8| &eMSPT&7: {mspt} &8| &ePing&7: {ping}"
|
||||||
|
messages:
|
||||||
|
enabled-self: "&aTPSBar enabled."
|
||||||
|
disabled-self: "&cTPSBar disabled."
|
||||||
|
enabled-other: "&aEnabled TPSBar for {player}."
|
||||||
|
disabled-other: "&cDisabled TPSBar for {player}."
|
||||||
|
usage: "&cUsage: /tpsbar [player]"
|
||||||
|
player-not-found: "&cPlayer not found: {player}"
|
||||||
|
no-targets: "&cNo matching players were found to toggle."
|
||||||
|
native-detected: "&7Detected a native /tpsbar command on this server, skipped plugin implementation."
|
||||||
|
plugin-enabled: "&7No native /tpsbar command was detected, plugin implementation enabled."
|
||||||
|
plugin-forced-but-native-exists: "&eThe configuration requests the plugin TPSBar, but a native /tpsbar already exists, so the plugin implementation was skipped to avoid conflicts."
|
||||||
|
mode-changed-reload: "&eTPSBar mode has been updated, but command registration changes require a server restart to fully take effect."
|
||||||
|
|
||||||
|
mobdrops-menu:
|
||||||
|
title: "&6&lMob Drop Control"
|
||||||
|
status:
|
||||||
|
enabled: "&aEnabled"
|
||||||
|
disabled: "&cDisabled"
|
||||||
|
enderman:
|
||||||
|
name: "&dEnderman Drops"
|
||||||
|
status: "&7Current status: {status}"
|
||||||
|
toggle: "&eClick to toggle"
|
||||||
|
|||||||
@@ -1,47 +1,65 @@
|
|||||||
# Chinese Language File (zh_CN)
|
# 简体中文语言文件
|
||||||
# 中文语言文件
|
|
||||||
|
|
||||||
# 插件前缀
|
prefix: "&7[&6EssentialsC&7]&f:&r"
|
||||||
prefix: "&6[EssentialsC] &r"
|
|
||||||
|
|
||||||
# 命令消息
|
|
||||||
messages:
|
messages:
|
||||||
no-permission: "&c你没有权限执行此命令!\n&7需要权限: {permission}"
|
no-permission: "&c你没有权限执行此命令!\n&7需要权限:{permission}"
|
||||||
player-only: "&c该命令只能由玩家执行!"
|
player-only: "&c此命令只能由玩家执行!"
|
||||||
hat-success: "&a你现在将 {item} 戴在头上!"
|
config-reloaded: "&a配置已重载。"
|
||||||
hat-failed: "&c无法将物品戴在头上!"
|
version: "&fEssentialsC v{version}"
|
||||||
hat-no-item: "&c你需要在手中持有物品!"
|
paper-version: "&7当前运行于 Paper {version}"
|
||||||
|
unknown-subcommand: "&c未知子命令:{command}"
|
||||||
|
help-usage: "&7使用 &f/essc help &7查看可用命令。"
|
||||||
|
blocks-menu-empty: "&c你当前没有可用的便捷菜单项目。"
|
||||||
|
|
||||||
|
hat-success: "&a你已将 {item} 戴在头上!"
|
||||||
|
hat-failed: "&c无法将该物品戴在头上!"
|
||||||
|
hat-no-item: "&c你需要手持一个物品!"
|
||||||
suicide-message: "&e{player} 自杀了!"
|
suicide-message: "&e{player} 自杀了!"
|
||||||
fly-enabled: "&a飞行模式已启用!"
|
fly-enabled: "&a飞行模式已开启!"
|
||||||
fly-disabled: "&c飞行模式已禁用!"
|
fly-disabled: "&c飞行模式已关闭!"
|
||||||
|
nightvision-enabled: "&a夜视已开启!"
|
||||||
|
nightvision-disabled: "&c夜视已关闭!"
|
||||||
|
nightvision-usage: "&c用法:/nightvision [on|off|toggle]"
|
||||||
|
glow-enabled: "&a发光已开启!"
|
||||||
|
glow-disabled: "&c发光已关闭!"
|
||||||
|
glow-usage: "&c用法:/glow [on|off|toggle]"
|
||||||
vanish-enabled: "&a你已进入隐身模式!"
|
vanish-enabled: "&a你已进入隐身模式!"
|
||||||
vanish-disabled: "&c你已退出隐身模式!"
|
vanish-disabled: "&c你已退出隐身模式!"
|
||||||
seen-usage: "&c用法: /seen <玩家名>"
|
seen-usage: "&c用法:/seen <玩家>"
|
||||||
|
seen-usage-console: "&c用法:/seen <玩家>"
|
||||||
|
player-not-found: "&c未找到玩家:{player}"
|
||||||
|
no-permission-others: "&c你没有权限影响其他玩家!"
|
||||||
|
|
||||||
anvil-opened: "&a已打开铁砧!"
|
anvil-opened: "&a已打开铁砧!"
|
||||||
enchantingtable-opened: "&a已打开附魔台!"
|
enchantingtable-opened: "&a已打开附魔台!"
|
||||||
heal-self: "&a你的生命值和饱食度已补满!"
|
heal-self: "&a你的生命值和饥饿值已恢复!"
|
||||||
heal-other: "&a你已治疗了玩家 {player}!"
|
heal-other: "&a你已治疗玩家 {player}!"
|
||||||
heal-by-other: "&a你被管理员 {admin} 治疗了!"
|
heal-by-other: "&a管理员 {admin} 治疗了你!"
|
||||||
feed-self: "&a你的饱食度已补满!"
|
feed-self: "&a你的饥饿值已恢复!"
|
||||||
feed-other: "&a你已喂饱玩家 {player}!"
|
feed-other: "&a你已喂饱玩家 {player}!"
|
||||||
feed-by-other: "&a你被管理员 {admin} 喂饱了!"
|
feed-by-other: "&a管理员 {admin} 喂饱了你!"
|
||||||
repair-hand-success: "&a手中物品已修复!"
|
repair-hand-success: "&a手中物品已修复!"
|
||||||
repair-all-success: "&a已修复 {count} 件物品!"
|
repair-all-success: "&a已修复 {count} 个物品!"
|
||||||
repair-not-damaged: "&c该物品没有损坏!"
|
repair-not-damaged: "&c该物品没有损坏!"
|
||||||
repair-no-item-in-hand: "&c你手中没有物品!"
|
repair-no-item-in-hand: "&c你手中没有物品!"
|
||||||
repair-no-items: "&c背包中没有可修复的物品!"
|
repair-no-items: "&c背包中没有可修复的物品!"
|
||||||
no-permission-repair-all: "&c你没有权限修复所有物品!"
|
no-permission-repair-all: "&c你没有权限修复全部物品!"
|
||||||
player-not-found: "&c未找到玩家: {player}"
|
|
||||||
no-permission-others: "&c你没有权限治疗其他玩家!"
|
mobdrop-save-failed: "&c保存配置失败:{error}"
|
||||||
|
mobdrop-toggled: "&a末影人掉落已切换为 {status}&a。"
|
||||||
|
shulkerbox-nested: "&c不能将潜影盒放入另一个潜影盒。"
|
||||||
|
shulkerbox-unstack-first: "&c请先将潜影盒拆分为单个后再快捷打开。"
|
||||||
|
jei-sync-fabric: "&6JEI-FIX&8(&bFabric&8): &e正在同步配方..."
|
||||||
|
jei-sync-neoforge: "&6JEI-FIX&8(&bNeoForge&8): &e正在同步配方..."
|
||||||
|
|
||||||
# 帮助命令
|
|
||||||
help:
|
help:
|
||||||
title: "&6========== &eEssentialsC 帮助 &6=========="
|
title: "&6========== &eEssentialsC 帮助 &6=========="
|
||||||
version: "&7插件版本: &f{version}"
|
version: "&7插件版本:&f{version}"
|
||||||
section-blocks: "&6功能方块命令:"
|
section-blocks: "&6功能方块命令:"
|
||||||
section-other: "&6其他功能命令:"
|
section-other: "&6其他命令:"
|
||||||
footer: "&7需要权限才能使用各个命令"
|
footer: "&7每个命令都需要对应权限。"
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
workbench: " &f/workbench &7- 打开工作台"
|
workbench: " &f/workbench &7- 打开工作台"
|
||||||
anvil: " &f/anvil &7- 打开铁砧"
|
anvil: " &f/anvil &7- 打开铁砧"
|
||||||
@@ -52,12 +70,102 @@ help:
|
|||||||
smithingtable: " &f/smithingtable &7- 打开锻造台"
|
smithingtable: " &f/smithingtable &7- 打开锻造台"
|
||||||
stonecutter: " &f/stonecutter &7- 打开切石机"
|
stonecutter: " &f/stonecutter &7- 打开切石机"
|
||||||
enderchest: " &f/enderchest &7- 打开末影箱"
|
enderchest: " &f/enderchest &7- 打开末影箱"
|
||||||
hat: " &f/hat &7- 将手中物品戴在头上"
|
blocks: " &f/blocks &7- 打开便捷菜单"
|
||||||
|
hat: " &f/hat &7- 将手持物品戴在头上"
|
||||||
suicide: " &f/suicide &7- 自杀"
|
suicide: " &f/suicide &7- 自杀"
|
||||||
fly: " &f/fly &7- 切换飞行模式"
|
fly: " &f/fly &7- 切换飞行模式"
|
||||||
heal: " &f/heal &7- 恢复生命值和饱食度"
|
nightvision: " &f/nightvision &7- 切换夜视"
|
||||||
|
glow: " &f/glow &7- 切换发光"
|
||||||
|
heal: " &f/heal &7- 恢复生命值和饥饿值"
|
||||||
vanish: " &f/vanish &7- 切换隐身模式"
|
vanish: " &f/vanish &7- 切换隐身模式"
|
||||||
seen: " &f/seen &7- 查看玩家信息"
|
seen: " &f/seen &7- 查看玩家信息"
|
||||||
feed: " &f/feed &7- 补满饱食度"
|
feed: " &f/feed &7- 恢复饥饿值"
|
||||||
repair: " &f/repair &7- 修复手中或所有物品"
|
repair: " &f/repair &7- 修复手中或全部物品"
|
||||||
blocks: " &f/blocks &7- 打开功能方块菜单"
|
admin: " &f/essc admin &7- 切换管理模式"
|
||||||
|
tpsbar: " &f/tpsbar [玩家] &7- 切换 TPS 状态栏"
|
||||||
|
|
||||||
|
blocks-menu:
|
||||||
|
title: "&6&lEssentialsC &8- &e&l便捷菜单"
|
||||||
|
items:
|
||||||
|
workbench:
|
||||||
|
name: "&e工作台"
|
||||||
|
lore:
|
||||||
|
- "&7/workbench"
|
||||||
|
- "&7打开工作台"
|
||||||
|
enderchest:
|
||||||
|
name: "&e末影箱"
|
||||||
|
lore:
|
||||||
|
- "&7/enderchest"
|
||||||
|
- "&7打开末影箱"
|
||||||
|
anvil:
|
||||||
|
name: "&e铁砧"
|
||||||
|
lore:
|
||||||
|
- "&7/anvil"
|
||||||
|
- "&7打开铁砧"
|
||||||
|
grindstone:
|
||||||
|
name: "&e砂轮"
|
||||||
|
lore:
|
||||||
|
- "&7/grindstone"
|
||||||
|
- "&7打开砂轮"
|
||||||
|
smithingtable:
|
||||||
|
name: "&e锻造台"
|
||||||
|
lore:
|
||||||
|
- "&7/smithingtable"
|
||||||
|
- "&7打开锻造台"
|
||||||
|
stonecutter:
|
||||||
|
name: "&e切石机"
|
||||||
|
lore:
|
||||||
|
- "&7/stonecutter"
|
||||||
|
- "&7打开切石机"
|
||||||
|
loom:
|
||||||
|
name: "&e织布机"
|
||||||
|
lore:
|
||||||
|
- "&7/loom"
|
||||||
|
- "&7打开织布机"
|
||||||
|
cartographytable:
|
||||||
|
name: "&e制图台"
|
||||||
|
lore:
|
||||||
|
- "&7/cartographytable"
|
||||||
|
- "&7打开制图台"
|
||||||
|
nightvision:
|
||||||
|
name: "&b夜视开关"
|
||||||
|
lore:
|
||||||
|
- "&7/nightvision"
|
||||||
|
- "&7切换夜视效果"
|
||||||
|
glow:
|
||||||
|
name: "&e发光开关"
|
||||||
|
lore:
|
||||||
|
- "&7/glow"
|
||||||
|
- "&7切换自身发光效果"
|
||||||
|
|
||||||
|
admin-mode:
|
||||||
|
actionbar: "&c&l管理模式"
|
||||||
|
messages:
|
||||||
|
enabled: "&a管理模式已开启,普通背包已保存。"
|
||||||
|
disabled: "&c管理模式已关闭,普通背包已恢复。"
|
||||||
|
crash-restored: "&e上一次管理模式会话已安全恢复。"
|
||||||
|
|
||||||
|
tpsbar:
|
||||||
|
title-format: "&eTPS&7: {tps_1m} &8| &eMSPT&7: {mspt} &8| &ePing&7: {ping}"
|
||||||
|
messages:
|
||||||
|
enabled-self: "&a已开启 TPSBar。"
|
||||||
|
disabled-self: "&c已关闭 TPSBar。"
|
||||||
|
enabled-other: "&a已为 {player} 开启 TPSBar。"
|
||||||
|
disabled-other: "&c已为 {player} 关闭 TPSBar。"
|
||||||
|
usage: "&c用法:/tpsbar [玩家]"
|
||||||
|
player-not-found: "&c未找到玩家:{player}"
|
||||||
|
no-targets: "&c没有匹配到可切换的玩家。"
|
||||||
|
native-detected: "&7检测到服务端已内置 /tpsbar,已跳过插件实现。"
|
||||||
|
plugin-enabled: "&7未检测到服务端内置 /tpsbar,已启用插件实现。"
|
||||||
|
plugin-forced-but-native-exists: "&e配置要求启用插件版 TPSBar,但服务端已存在原生 /tpsbar,已跳过插件实现以避免冲突。"
|
||||||
|
mode-changed-reload: "&eTPSBar 模式已更新,但命令注册状态需要重启服务器后才会完全生效。"
|
||||||
|
|
||||||
|
mobdrops-menu:
|
||||||
|
title: "&6&l生物掉落控制"
|
||||||
|
status:
|
||||||
|
enabled: "&a开启"
|
||||||
|
disabled: "&c关闭"
|
||||||
|
enderman:
|
||||||
|
name: "&d末影人掉落"
|
||||||
|
status: "&7当前状态:{status}"
|
||||||
|
toggle: "&e点击切换"
|
||||||
|
|||||||
@@ -1,99 +1,129 @@
|
|||||||
name: EssentialsC
|
name: EssentialsC
|
||||||
description: 精简版基础插件
|
description: 适用于 Paper 服务端的轻量基础功能插件。
|
||||||
version: '${version}'
|
version: ${version}
|
||||||
|
|
||||||
main: cn.infstar.essentialsC.EssentialsC
|
main: cn.infstar.essentialsC.EssentialsC
|
||||||
api-version: '1.21'
|
api-version: '1.21'
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
|
folia-supported: false
|
||||||
|
|
||||||
authors: [ Coldsmiles_7 ]
|
authors: [ Coldsmiles_7 ]
|
||||||
website: www.infstar.cn
|
website: www.infstar.cn
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
essentialsc.command.workbench:
|
essentialsc.command.workbench:
|
||||||
description: Allows use of /workbench command
|
description: 允许使用 /workbench
|
||||||
default: op
|
default: op
|
||||||
essentialsc.command.anvil:
|
essentialsc.command.anvil:
|
||||||
description: Allows use of /anvil command
|
description: 允许使用 /anvil
|
||||||
default: op
|
|
||||||
essentialsc.command.enchantingtable:
|
|
||||||
description: Allows use of /enchantingtable command
|
|
||||||
default: op
|
default: op
|
||||||
essentialsc.command.cartographytable:
|
essentialsc.command.cartographytable:
|
||||||
description: Allows use of /cartographytable command
|
description: 允许使用 /cartographytable
|
||||||
default: op
|
default: op
|
||||||
essentialsc.command.grindstone:
|
essentialsc.command.grindstone:
|
||||||
description: Allows use of /grindstone command
|
description: 允许使用 /grindstone
|
||||||
default: op
|
default: op
|
||||||
essentialsc.command.loom:
|
essentialsc.command.loom:
|
||||||
description: Allows use of /loom command
|
description: 允许使用 /loom
|
||||||
default: op
|
default: op
|
||||||
essentialsc.command.smithingtable:
|
essentialsc.command.smithingtable:
|
||||||
description: Allows use of /smithingtable command
|
description: 允许使用 /smithingtable
|
||||||
default: op
|
default: op
|
||||||
essentialsc.command.stonecutter:
|
essentialsc.command.stonecutter:
|
||||||
description: Allows use of /stonecutter command
|
description: 允许使用 /stonecutter
|
||||||
default: op
|
default: op
|
||||||
essentialsc.command.enderchest:
|
essentialsc.command.enderchest:
|
||||||
description: Allows use of /enderchest command
|
description: 允许使用 /enderchest
|
||||||
default: op
|
|
||||||
essentialsc.command.hat:
|
|
||||||
description: Allows use of /hat command
|
|
||||||
default: op
|
|
||||||
essentialsc.command.suicide:
|
|
||||||
description: Allows use of /suicide command
|
|
||||||
default: op
|
|
||||||
essentialsc.command.fly:
|
|
||||||
description: Allows use of /fly command
|
|
||||||
default: op
|
|
||||||
essentialsc.command.heal:
|
|
||||||
description: Allows use of /heal command
|
|
||||||
default: op
|
|
||||||
essentialsc.command.vanish:
|
|
||||||
description: Allows use of /vanish command
|
|
||||||
default: op
|
|
||||||
essentialsc.command.seen:
|
|
||||||
description: Allows use of /seen command
|
|
||||||
default: op
|
|
||||||
essentialsc.command.feed:
|
|
||||||
description: Allows use of /feed command
|
|
||||||
default: op
|
|
||||||
essentialsc.command.repair:
|
|
||||||
description: Allows use of /repair command
|
|
||||||
default: op
|
default: op
|
||||||
essentialsc.command.blocks:
|
essentialsc.command.blocks:
|
||||||
description: Allows use of /essc blocks command
|
description: 允许使用 /essc blocks
|
||||||
default: true
|
default: true
|
||||||
|
essentialsc.command.hat:
|
||||||
|
description: 允许使用 /hat
|
||||||
|
default: op
|
||||||
|
essentialsc.command.suicide:
|
||||||
|
description: 允许使用 /suicide
|
||||||
|
default: op
|
||||||
|
essentialsc.command.fly:
|
||||||
|
description: 允许使用 /fly
|
||||||
|
default: op
|
||||||
|
essentialsc.command.nightvision:
|
||||||
|
description: 允许使用 /nightvision
|
||||||
|
default: op
|
||||||
|
essentialsc.command.glow:
|
||||||
|
description: 允许使用 /glow
|
||||||
|
default: op
|
||||||
|
essentialsc.command.heal:
|
||||||
|
description: 允许使用 /heal
|
||||||
|
default: op
|
||||||
|
essentialsc.command.heal.others:
|
||||||
|
description: 允许治疗其他玩家
|
||||||
|
default: op
|
||||||
|
essentialsc.command.vanish:
|
||||||
|
description: 允许使用 /vanish
|
||||||
|
default: op
|
||||||
|
essentialsc.command.seen:
|
||||||
|
description: 允许使用 /seen
|
||||||
|
default: op
|
||||||
|
essentialsc.command.feed:
|
||||||
|
description: 允许使用 /feed
|
||||||
|
default: op
|
||||||
|
essentialsc.command.feed.others:
|
||||||
|
description: 允许为其他玩家补充饥饿值
|
||||||
|
default: op
|
||||||
|
essentialsc.command.repair:
|
||||||
|
description: 允许使用 /repair
|
||||||
|
default: op
|
||||||
|
essentialsc.command.repair.all:
|
||||||
|
description: 允许使用 /repair all
|
||||||
|
default: op
|
||||||
|
essentialsc.command.admin:
|
||||||
|
description: 允许使用 /essc admin
|
||||||
|
default: op
|
||||||
essentialsc.command.help:
|
essentialsc.command.help:
|
||||||
description: Allows use of /essentialsc help command
|
description: 允许使用 /essc help
|
||||||
default: true
|
default: true
|
||||||
essentialsc.command.reload:
|
essentialsc.command.reload:
|
||||||
description: Allows use of /essc reload command
|
description: 允许使用 /essc reload
|
||||||
|
default: op
|
||||||
|
essentialsc.command.tpsbar:
|
||||||
|
description: 允许使用 /tpsbar
|
||||||
default: op
|
default: op
|
||||||
essentialsc.shulkerbox.open:
|
essentialsc.shulkerbox.open:
|
||||||
description: Allows right-click to open shulker boxes without placing them
|
description: 允许通过 Shift+右键快捷打开潜影盒
|
||||||
|
default: op
|
||||||
|
essentialsc.mobdrops.enderman:
|
||||||
|
description: 允许控制末影人掉落方块
|
||||||
default: op
|
default: op
|
||||||
essentialsc.*:
|
essentialsc.*:
|
||||||
description: All EssentialsC permissions
|
description: 授予 EssentialsC 的全部权限
|
||||||
default: false
|
default: false
|
||||||
children:
|
children:
|
||||||
essentialsc.command.workbench: true
|
essentialsc.command.workbench: true
|
||||||
essentialsc.command.anvil: true
|
essentialsc.command.anvil: true
|
||||||
essentialsc.command.enchantingtable: true
|
|
||||||
essentialsc.command.cartographytable: true
|
essentialsc.command.cartographytable: true
|
||||||
essentialsc.command.grindstone: true
|
essentialsc.command.grindstone: true
|
||||||
essentialsc.command.loom: true
|
essentialsc.command.loom: true
|
||||||
essentialsc.command.smithingtable: true
|
essentialsc.command.smithingtable: true
|
||||||
essentialsc.command.stonecutter: true
|
essentialsc.command.stonecutter: true
|
||||||
essentialsc.command.enderchest: true
|
essentialsc.command.enderchest: true
|
||||||
|
essentialsc.command.blocks: true
|
||||||
essentialsc.command.hat: true
|
essentialsc.command.hat: true
|
||||||
essentialsc.command.suicide: true
|
essentialsc.command.suicide: true
|
||||||
essentialsc.command.fly: true
|
essentialsc.command.fly: true
|
||||||
|
essentialsc.command.nightvision: true
|
||||||
|
essentialsc.command.glow: true
|
||||||
essentialsc.command.heal: true
|
essentialsc.command.heal: true
|
||||||
|
essentialsc.command.heal.others: true
|
||||||
essentialsc.command.vanish: true
|
essentialsc.command.vanish: true
|
||||||
essentialsc.command.seen: true
|
essentialsc.command.seen: true
|
||||||
essentialsc.command.reload: true
|
|
||||||
essentialsc.command.feed: true
|
essentialsc.command.feed: true
|
||||||
|
essentialsc.command.feed.others: true
|
||||||
essentialsc.command.repair: true
|
essentialsc.command.repair: true
|
||||||
|
essentialsc.command.repair.all: true
|
||||||
|
essentialsc.command.admin: true
|
||||||
essentialsc.command.help: true
|
essentialsc.command.help: true
|
||||||
|
essentialsc.command.reload: true
|
||||||
|
essentialsc.command.tpsbar: true
|
||||||
essentialsc.shulkerbox.open: true
|
essentialsc.shulkerbox.open: true
|
||||||
|
essentialsc.mobdrops.enderman: true
|
||||||
|
|||||||
Reference in New Issue
Block a user