1
mirror of https://github.com/CarmJos/MineConfiguration.git synced 2026-06-13 15:58:42 +08:00

Compare commits

...

53 Commits

Author SHA1 Message Date
carm bf5c6a2fce feat(notify): 尝试实现整合的消息配置 #39 2023-12-25 03:40:33 +08:00
carm f86229037d feat(notify): 尝试实现整合的消息配置 #39 2023-12-25 02:38:43 +08:00
carm 38292052f5 feat(notify): 尝试实现整合的消息配置 #39 2023-12-25 02:33:37 +08:00
dependabot[bot] b737e4dda2 chore(deps): bump cc.carm.lib:easyconfiguration-core from 3.8.0 to 3.8.1 (#60)
Bumps [cc.carm.lib:easyconfiguration-core](https://github.com/CarmJos/EasyConfiguration) from 3.8.0 to 3.8.1.
- [Release notes](https://github.com/CarmJos/EasyConfiguration/releases)
- [Commits](https://github.com/CarmJos/EasyConfiguration/compare/3.8.0...3.8.1)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyconfiguration-core
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-23 23:05:28 +08:00
dependabot[bot] 058da094cd chore(deps): bump org.apache.maven.plugins:maven-compiler-plugin (#59)
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.11.0 to 3.12.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.11.0...maven-compiler-plugin-3.12.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-compiler-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-19 08:20:43 +08:00
dependabot[bot] 020adeb030 chore(deps): bump org.apache.maven.plugins:maven-surefire-plugin (#58)
Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.2...surefire-3.2.3)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-15 18:17:22 +08:00
dependabot[bot] 3183e1025d chore(deps): bump com.github.cryptomorin:XSeries from 9.7.0 to 9.8.0 (#57)
Bumps [com.github.cryptomorin:XSeries](https://github.com/CryptoMorin/XSeries) from 9.7.0 to 9.8.0.
- [Release notes](https://github.com/CryptoMorin/XSeries/releases)
- [Commits](https://github.com/CryptoMorin/XSeries/compare/v9.7.0...v9.8.0)

---
updated-dependencies:
- dependency-name: com.github.cryptomorin:XSeries
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-14 00:36:18 +08:00
dependabot[bot] 3c57b97fb1 chore(deps): bump org.apache.maven.plugins:maven-javadoc-plugin (#56)
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.2 to 3.6.3.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.2...maven-javadoc-plugin-3.6.3)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-05 08:13:21 +08:00
carm c77253508c feat(item): 令插入的行支持ConfiguredMessage的解析方法 2023-11-21 23:51:05 +08:00
carm 56ee1ec991 Merge remote-tracking branch 'origin/master' 2023-11-21 23:50:39 +08:00
carm 706db18ffe feat(item): 令插入的行支持ConfiguredMessage的解析方法 2023-11-21 23:50:29 +08:00
dependabot[bot] 46bfbe063e chore(deps): bump org.jetbrains:annotations from 24.0.1 to 24.1.0 (#55)
Bumps [org.jetbrains:annotations](https://github.com/JetBrains/java-annotations) from 24.0.1 to 24.1.0.
- [Release notes](https://github.com/JetBrains/java-annotations/releases)
- [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md)
- [Commits](https://github.com/JetBrains/java-annotations/compare/24.0.1...24.1.0)

---
updated-dependencies:
- dependency-name: org.jetbrains:annotations
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-16 17:56:10 +08:00
dependabot[bot] c3d993311e chore(deps): bump cc.carm.lib:easyplugin-color from 1.5.10 to 1.5.11 (#54)
Bumps [cc.carm.lib:easyplugin-color](https://github.com/CarmJos/EasyPlugin) from 1.5.10 to 1.5.11.
- [Release notes](https://github.com/CarmJos/EasyPlugin/releases)
- [Commits](https://github.com/CarmJos/EasyPlugin/compare/1.5.10...1.5.11)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyplugin-color
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-15 01:16:44 +08:00
dependabot[bot] 67d1fd67fc chore(deps): bump org.apache.maven.plugins:maven-javadoc-plugin (#51)
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.0 to 3.6.2.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.0...maven-javadoc-plugin-3.6.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-07 07:58:26 +08:00
dependabot[bot] 357b6054a4 chore(deps): bump org.apache.maven.plugins:maven-surefire-plugin (#52)
Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.1 to 3.2.2.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.1...surefire-3.2.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-07 07:58:18 +08:00
dependabot[bot] c150d607e9 chore(deps): bump cc.carm.lib:easyplugin-color from 1.5.8 to 1.5.10 (#53)
Bumps [cc.carm.lib:easyplugin-color](https://github.com/CarmJos/EasyPlugin) from 1.5.8 to 1.5.10.
- [Release notes](https://github.com/CarmJos/EasyPlugin/releases)
- [Commits](https://github.com/CarmJos/EasyPlugin/compare/1.5.8...1.5.10)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyplugin-color
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-07 07:58:08 +08:00
carm dbcaff5c93 fix(head): 修复头颅皮肤无法正确应用的问题 2023-11-05 02:56:56 +08:00
dependabot[bot] e0d5f9229b chore(deps): bump me.clip:placeholderapi from 2.11.4 to 2.11.5 (#50)
Bumps me.clip:placeholderapi from 2.11.4 to 2.11.5.

---
updated-dependencies:
- dependency-name: me.clip:placeholderapi
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-31 14:13:10 +08:00
dependabot[bot] caf92ef565 chore(deps): bump org.apache.maven.plugins:maven-surefire-plugin (#48)
Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.2 to 3.2.1.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.2...surefire-3.2.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-25 22:50:12 +08:00
dependabot[bot] 77547cdc80 chore(deps): bump com.github.cryptomorin:XSeries from 9.6.1.1 to 9.7.0 (#49)
Bumps [com.github.cryptomorin:XSeries](https://github.com/CryptoMorin/XSeries) from 9.6.1.1 to 9.7.0.
- [Release notes](https://github.com/CryptoMorin/XSeries/releases)
- [Commits](https://github.com/CryptoMorin/XSeries/compare/v9.6.1.1...v9.7.0)

---
updated-dependencies:
- dependency-name: com.github.cryptomorin:XSeries
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-25 22:50:04 +08:00
carm 5d55ddbce9 feat(item): 优化PreparedItem的结构,使其适用于更多项目。 2023-10-11 22:44:57 +08:00
carm c73032266d feat(item): 优化PreparedItem的结构,使其适用于更多项目。 2023-10-11 22:32:19 +08:00
dependabot[bot] a6b6d46be6 chore(deps): bump com.github.cryptomorin:XSeries from 9.6.0 to 9.6.1.1 (#46)
Bumps [com.github.cryptomorin:XSeries](https://github.com/CryptoMorin/XSeries) from 9.6.0 to 9.6.1.1.
- [Release notes](https://github.com/CryptoMorin/XSeries/releases)
- [Commits](https://github.com/CryptoMorin/XSeries/compare/v9.6.0...v9.6.1.1)

---
updated-dependencies:
- dependency-name: com.github.cryptomorin:XSeries
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-11 20:18:07 +08:00
carm 47d7b17082 ci(cache): NO MORE GITHUB CACHE SERVICE! 2023-10-10 15:23:41 +08:00
dependabot[bot] 0663f3d117 chore(deps): bump com.github.cryptomorin:XSeries from 9.5.0 to 9.6.0 (#45)
Bumps [com.github.cryptomorin:XSeries](https://github.com/CryptoMorin/XSeries) from 9.5.0 to 9.6.0.
- [Release notes](https://github.com/CryptoMorin/XSeries/releases)
- [Commits](https://github.com/CryptoMorin/XSeries/compare/v9.5.0...v9.6.0)

---
updated-dependencies:
- dependency-name: com.github.cryptomorin:XSeries
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-03 13:32:00 +08:00
dependabot[bot] 1947ba1899 chore(deps): bump org.apache.maven.plugins:maven-shade-plugin (#43)
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.0 to 3.5.1.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.0...maven-shade-plugin-3.5.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-shade-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-26 12:48:09 +08:00
dependabot[bot] 2e4de9880f chore(deps): bump me.clip:placeholderapi from 2.11.3 to 2.11.4 (#44)
Bumps me.clip:placeholderapi from 2.11.3 to 2.11.4.

---
updated-dependencies:
- dependency-name: me.clip:placeholderapi
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-26 12:47:59 +08:00
carm 398bc773d6 feat(item): 重构物品相关代码,支持更多功能 2023-09-21 22:23:35 +08:00
dependabot[bot] 1396c6bd6e chore(deps): bump org.apache.maven.plugins:maven-javadoc-plugin (#42)
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.5.0 to 3.6.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.5.0...maven-javadoc-plugin-3.6.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-21 00:12:31 +08:00
carm 2959c00795 feat(item): 重构物品相关代码,支持更多功能 2023-09-21 00:08:42 +08:00
carm 09537975e4 feat(item): 重构物品相关代码,支持更多功能 2023-09-20 23:46:59 +08:00
carm 02625b5c0c feat(item): 重构物品相关代码,支持更多功能 2023-09-20 23:39:34 +08:00
carm bb9e24dd96 fix(item): 修复上下空行错误 2023-09-08 23:47:53 +08:00
carm 5bdc5908ef feat(item): 支持为插入的LORE设置偏移量,以便在上方、下方空行,分割功能。 2023-09-08 22:15:28 +08:00
dependabot[bot] dde304625e chore(deps): bump cc.carm.lib:easyplugin-color from 1.5.7 to 1.5.8 (#41)
Bumps [cc.carm.lib:easyplugin-color](https://github.com/CarmJos/EasyPlugin) from 1.5.7 to 1.5.8.
- [Release notes](https://github.com/CarmJos/EasyPlugin/releases)
- [Commits](https://github.com/CarmJos/EasyPlugin/compare/1.5.7...1.5.8)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyplugin-color
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-07 22:23:55 +08:00
carm 24ef0b6dcd feat(send): 提供物品预备方法,方便插入lore、修改附魔、flags等 2023-09-07 03:49:15 +08:00
carm a1d6cf1258 feat(send): 提供新消息发送方法,分离玩家参数和消息参数 2023-09-07 02:31:57 +08:00
carm 0f7fc39f87 feat(send): 提供新消息发送方法,分离玩家参数和消息参数 2023-09-06 06:40:52 +08:00
dependabot[bot] 92ecb55a95 chore(deps): bump cc.carm.lib:easyplugin-color from 1.5.6 to 1.5.7 (#40)
Bumps [cc.carm.lib:easyplugin-color](https://github.com/CarmJos/EasyPlugin) from 1.5.6 to 1.5.7.
- [Release notes](https://github.com/CarmJos/EasyPlugin/releases)
- [Commits](https://github.com/CarmJos/EasyPlugin/compare/1.5.6...1.5.7)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyplugin-color
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-06 01:10:37 +08:00
carm bfd1624e85 chore(update): 适配上游版本更新。 2023-08-29 12:43:49 +08:00
dependabot[bot] 01d3c245a9 chore(deps): bump net.md-5:bungeecord-chat from 1.16-R0.4 to 1.20-R0.1 (#37)
Bumps [net.md-5:bungeecord-chat](https://github.com/SpigotMC/BungeeCord) from 1.16-R0.4 to 1.20-R0.1.
- [Commits](https://github.com/SpigotMC/BungeeCord/commits)

---
updated-dependencies:
- dependency-name: net.md-5:bungeecord-chat
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-08 14:09:36 +08:00
dependabot[bot] 8721c6085f chore(deps): bump com.github.cryptomorin:XSeries from 9.4.0 to 9.5.0 (#36)
Bumps [com.github.cryptomorin:XSeries](https://github.com/CryptoMorin/XSeries) from 9.4.0 to 9.5.0.
- [Release notes](https://github.com/CryptoMorin/XSeries/releases)
- [Commits](https://github.com/CryptoMorin/XSeries/compare/v9.4.0...v9.5.0)

---
updated-dependencies:
- dependency-name: com.github.cryptomorin:XSeries
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-08 14:09:23 +08:00
dependabot[bot] eca4d47b8f chore(deps): bump easyconfiguration-core from 3.7.0 to 3.7.1 (#35)
Bumps [easyconfiguration-core](https://github.com/CarmJos/EasyConfiguration) from 3.7.0 to 3.7.1.
- [Release notes](https://github.com/CarmJos/EasyConfiguration/releases)
- [Commits](https://github.com/CarmJos/EasyConfiguration/compare/3.7.0...3.7.1)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyconfiguration-core
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-20 08:49:44 +08:00
dependabot[bot] 3750ac7d58 chore(deps): bump easyconfiguration-core from 3.6.0 to 3.7.0 (#34)
Bumps [easyconfiguration-core](https://github.com/CarmJos/EasyConfiguration) from 3.6.0 to 3.7.0.
- [Release notes](https://github.com/CarmJos/EasyConfiguration/releases)
- [Commits](https://github.com/CarmJos/EasyConfiguration/compare/3.6.0...3.7.0)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyconfiguration-core
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-11 17:02:40 +08:00
dependabot[bot] d3bdc4ad60 chore(deps): bump easyplugin-color from 1.5.4 to 1.5.6 (#33)
Bumps [easyplugin-color](https://github.com/CarmJos/EasyPlugin) from 1.5.4 to 1.5.6.
- [Release notes](https://github.com/CarmJos/EasyPlugin/releases)
- [Commits](https://github.com/CarmJos/EasyPlugin/compare/1.5.4...1.5.6)

---
updated-dependencies:
- dependency-name: cc.carm.lib:easyplugin-color
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-02 04:03:39 +08:00
dependabot[bot] 6bb6fb1b95 chore(deps): bump maven-shade-plugin from 3.4.1 to 3.5.0 (#32)
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.1 to 3.5.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.1...maven-shade-plugin-3.5.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-shade-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-17 21:22:09 +08:00
dependabot[bot] dd2499512c chore(deps): bump XSeries from 9.3.1 to 9.4.0 (#31)
Bumps [XSeries](https://github.com/CryptoMorin/XSeries) from 9.3.1 to 9.4.0.
- [Release notes](https://github.com/CryptoMorin/XSeries/releases)
- [Commits](https://github.com/CryptoMorin/XSeries/compare/v9.3.1...v9.4.0)

---
updated-dependencies:
- dependency-name: com.github.cryptomorin:XSeries
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-14 09:58:56 +08:00
dependabot[bot] 3aa0542f01 chore(deps): bump maven-surefire-plugin from 3.1.0 to 3.1.2 (#30)
Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.0 to 3.1.2.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.0...surefire-3.1.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-09 13:36:34 +08:00
dependabot[bot] 4d9d5f5d84 chore(deps): bump maven-release-plugin from 3.0.0 to 3.0.1 (#29)
Bumps [maven-release-plugin](https://github.com/apache/maven-release) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/apache/maven-release/releases)
- [Commits](https://github.com/apache/maven-release/compare/maven-release-3.0.0...maven-release-3.0.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-release-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-06 12:12:30 +08:00
carm 2b31ee1318 fix(item): 修复物品获取后修改被直接应用到缓存导致重复获取第一次物品的问题。 2023-06-01 02:32:45 +08:00
carm 9d6212e5ea feat(conf): 为入口类添加了实例方法,方便快捷创建基础配置和消息配置文件。 2023-05-27 00:22:30 +08:00
carm 8f3d574446 feat(conf): 搭配XSeries实现部分配置类的跨版本支持。 2023-05-27 00:12:37 +08:00
dependabot[bot] 437e1d6d61 chore(deps): bump maven-source-plugin from 3.2.1 to 3.3.0 (#28)
Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.2.1 to 3.3.0.
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.2.1...maven-source-plugin-3.3.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-source-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-23 21:33:19 +08:00
41 changed files with 1483 additions and 401 deletions
+2 -2
View File
@@ -22,7 +22,7 @@ jobs:
with: with:
java-version: '11' java-version: '11'
distribution: 'adopt' distribution: 'adopt'
cache: maven # cache: maven # Say 4uck u to github cache services.
server-id: github server-id: github
server-username: MAVEN_USERNAME server-username: MAVEN_USERNAME
server-password: MAVEN_TOKEN server-password: MAVEN_TOKEN
@@ -46,7 +46,7 @@ jobs:
with: with:
java-version: '11' java-version: '11'
distribution: 'adopt' distribution: 'adopt'
cache: maven # cache: maven # Say 4uck u to github cache services.
server-id: ossrh server-id: ossrh
server-username: MAVEN_USERNAME server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD server-password: MAVEN_PASSWORD
+2 -2
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>mineconfiguration-parent</artifactId> <artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<version>2.6.0</version> <version>2.9.1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<properties> <properties>
@@ -39,7 +39,7 @@
<dependency> <dependency>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId> <artifactId>bungeecord-chat</artifactId>
<version>1.16-R0.4</version> <version>1.20-R0.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@@ -0,0 +1,51 @@
package cc.carm.lib.mineconfiguration.common;
import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import org.jetbrains.annotations.NotNull;
public abstract class AbstractConfiguration<P extends ConfigurationProvider<?>> {
private final P configProvider;
private final P messageProvider;
protected AbstractConfiguration(@NotNull P configProvider, @NotNull P messageProvider) {
this.configProvider = configProvider;
this.messageProvider = messageProvider;
}
public void initializeConfig(@NotNull ConfigurationRoot configRoot) {
this.configProvider.initialize(configRoot);
}
public void initializeMessage(@NotNull ConfigurationRoot messageRoot) {
this.messageProvider.initialize(messageRoot);
}
public void initializeConfig(@NotNull Class<? extends ConfigurationRoot> configRoot) {
this.configProvider.initialize(configRoot);
}
public void initializeMessage(@NotNull Class<? extends ConfigurationRoot> messageRoot) {
this.messageProvider.initialize(messageRoot);
}
public P getConfigProvider() {
return configProvider;
}
public P getMessageProvider() {
return messageProvider;
}
public void reload() throws Exception {
getConfigProvider().reload();
getMessageProvider().reload();
}
public void save() throws Exception {
getConfigProvider().save();
getMessageProvider().save();
}
}
@@ -38,6 +38,16 @@ public interface BaseMessage<R, M> {
@ApiStatus.OverrideOnly @ApiStatus.OverrideOnly
void apply(@NotNull R receiver, @NotNull M message); void apply(@NotNull R receiver, @NotNull M message);
/**
* 填入变量值,返回一个准备好待发送的消息。
*
* @param values 变量值
* @return 准备好待发送的消息
*/
default @NotNull PreparedMessage<R, M> prepare(@NotNull Object... values) {
return new PreparedMessage<>(this, values);
}
/** /**
* 为某位接收者解析此消息。 * 为某位接收者解析此消息。
* *
@@ -7,6 +7,7 @@ import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@@ -47,11 +48,20 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
sendFunction.accept(receiver, message); sendFunction.accept(receiver, message);
} }
@Override protected <N> @Nullable N parseTo(@Nullable R sender, @NotNull Map<String, Object> placeholders,
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) { @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable N> parser) {
T value = get(); T value = get();
if (value == null || value.getMessage().isEmpty()) return null; if (value == null || value.getMessage().isEmpty()) return null;
else return value.parse(this.messageParser, sender, placeholders); else return value.parse(parser, sender, placeholders);
}
public @Nullable String parseString(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
return parseTo(sender, placeholders, (r, s) -> s);
}
@Override
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
return parseTo(sender, placeholders, this.messageParser);
} }
public void set(@Nullable String value) { public void set(@Nullable String value) {
@@ -62,4 +72,28 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
return textBuilder.apply(value); return textBuilder.apply(value);
} }
public abstract class PreparedMessage<P, N> {
protected final @NotNull Object[] values;
protected PreparedMessage(@NotNull Object[] values) {
this.values = values;
}
public Object[] getValues() {
return values;
}
public abstract void to(P receiver);
public void to(Collection<P> receivers) {
receivers.forEach(this::to);
}
public N get(P receiver) {
return null;
}
}
} }
@@ -4,6 +4,7 @@ import cc.carm.lib.configuration.core.function.ConfigDataFunction;
import cc.carm.lib.configuration.core.value.ValueManifest; import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredList; import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.mineconfiguration.common.data.AbstractText; import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -68,14 +69,22 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Object... values) {
return parseToLine(receiver, "\n", ParamsUtils.buildParams(this.params, values));
}
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Map<String, Object> placeholders) { public @Nullable M parseToLine(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
return parseToLine(receiver, "\n", placeholders);
}
public @Nullable M parseToLine(@Nullable R receiver, @NotNull String delimiter, @NotNull Map<String, Object> placeholders) {
List<T> list = get(); List<T> list = get();
if (list.isEmpty()) return null; if (list.isEmpty()) return null;
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList()); List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
if (String.join("", messages).isEmpty()) return null; if (String.join("", messages).isEmpty()) return null;
String combined = String.join("\n", messages); String combined = String.join(delimiter, messages);
T text = textBuilder.apply(combined); T text = textBuilder.apply(combined);
return text.parse(this.messageParser, receiver, placeholders); return text.parse(this.messageParser, receiver, placeholders);
@@ -0,0 +1,48 @@
package cc.carm.lib.mineconfiguration.common.value;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PreparedMessage<R, M> {
protected final @NotNull BaseMessage<R, M> message;
protected final @NotNull Object[] values;
protected PreparedMessage(@NotNull BaseMessage<R, M> message, @NotNull Object[] values) {
this.message = message;
this.values = values;
}
/**
* 为某位接收者解析此消息。
*
* @param receiver 接收者
* @return 解析变量后的消息内容
*/
public @Nullable M parse(@Nullable R receiver) {
return message.parse(receiver, values);
}
/**
* 向某位接收者发送消息
*
* @param receiver 消息的接收者
*/
public void to(@Nullable R receiver) {
message.send(receiver, values);
}
/**
* 向某位接收者发送消息
*
* @param receivers 消息的接收者们
*/
public void to(@NotNull Iterable<? extends R> receivers) {
receivers.forEach(this::to);
}
public void toAll() {
to(message.getAllReceivers());
}
}
+10 -11
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>mineconfiguration-parent</artifactId> <artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<version>2.6.0</version> <version>2.9.1</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -37,11 +37,18 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.8.0</version>
<scope>compile</scope>
</dependency>
<!--suppress VulnerableLibrariesLocal --> <!--suppress VulnerableLibrariesLocal -->
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version> <version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@@ -49,15 +56,7 @@
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId> <artifactId>placeholderapi</artifactId>
<version>2.11.3</version> <version>2.11.5</version>
<scope>provided</scope>
</dependency>
<!--ProtocolLib for general packet's function support-->
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.8.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@@ -7,9 +7,6 @@ import cc.carm.lib.mineconfiguration.bukkit.builder.CraftConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider; import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper; import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> { public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
@@ -17,7 +14,7 @@ public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
return new CraftConfigBuilder(); return new CraftConfigBuilder();
} }
public CraftConfigValue(@NotNull ValueManifest<T> manifest) { protected CraftConfigValue(@NotNull ValueManifest<T> manifest) {
super(manifest); super(manifest);
} }
@@ -1,12 +1,16 @@
package cc.carm.lib.mineconfiguration.bukkit; package cc.carm.lib.mineconfiguration.bukkit;
import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider; import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider;
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
public class MineConfiguration { public class MineConfiguration extends AbstractConfiguration<BukkitConfigProvider> {
public static BukkitConfigProvider from(File file, String source) { public static BukkitConfigProvider from(File file, String source) {
BukkitConfigProvider provider = new BukkitConfigProvider(file); BukkitConfigProvider provider = new BukkitConfigProvider(file);
@@ -39,4 +43,24 @@ public class MineConfiguration {
return from(new File(plugin.getDataFolder(), fileName), source); return from(new File(plugin.getDataFolder(), fileName), source);
} }
public MineConfiguration(@NotNull JavaPlugin plugin) {
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
}
public MineConfiguration(@NotNull JavaPlugin plugin,
@NotNull ConfigurationRoot configRoot,
@NotNull ConfigurationRoot messageRoot) {
this(plugin);
initializeConfig(configRoot);
initializeMessage(messageRoot);
}
public MineConfiguration(@NotNull JavaPlugin plugin,
@NotNull Class<? extends ConfigurationRoot> configRoot,
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
this(plugin);
initializeConfig(configRoot);
initializeMessage(messageRoot);
}
} }
@@ -6,11 +6,8 @@ import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageBuilder;
import cc.carm.lib.mineconfiguration.bukkit.builder.serializable.SerializableBuilder; import cc.carm.lib.mineconfiguration.bukkit.builder.serializable.SerializableBuilder;
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder; import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder; import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CraftConfigBuilder extends ConfigBuilder { public class CraftConfigBuilder extends ConfigBuilder {
@@ -34,12 +31,4 @@ public class CraftConfigBuilder extends ConfigBuilder {
return new SerializableBuilder<>(valueClass); return new SerializableBuilder<>(valueClass);
} }
public @NotNull ConfiguredItem ofItem() {
return createItem().build();
}
public @NotNull ConfiguredItem ofItem(@Nullable ItemConfig defaultItem) {
return createItem().defaults(defaultItem).build();
}
} }
@@ -2,19 +2,21 @@ package cc.carm.lib.mineconfiguration.bukkit.builder.item;
import cc.carm.lib.configuration.core.value.ValueManifest; import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder; import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig; import cc.carm.lib.mineconfiguration.bukkit.value.item.ConfiguredItem;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils; import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.UnaryOperator;
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConfigBuilder> { public class ItemConfigBuilder extends AbstractCraftBuilder<ItemStack, ItemConfigBuilder> {
protected Material type; protected Material type;
protected short data = 0; protected short data = 0;
@@ -84,7 +86,7 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags))); return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags)));
} }
public ItemConfigBuilder formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) { public ItemConfigBuilder formatParam(@NotNull UnaryOperator<String> paramFormatter) {
this.paramFormatter = paramFormatter; this.paramFormatter = paramFormatter;
return getThis(); return getThis();
} }
@@ -104,9 +106,20 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
return this; return this;
} }
protected @Nullable ItemConfig buildDefault() { protected @Nullable ItemStack buildDefault() {
if (this.type == null) return null; if (this.type == null) return null;
else return new ItemConfig(type, data, name, lore, enchants, flags);
ItemStack item = new ItemStack(type, 1, data);
ItemMeta meta = item.getItemMeta();
if (meta == null) return item;
Optional.ofNullable(this.name).ifPresent(meta::setDisplayName);
Optional.ofNullable(this.lore).ifPresent(meta::setLore);
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
flags.forEach(meta::addItemFlags);
item.setItemMeta(meta);
return item;
} }
@Override @Override
@@ -1,6 +1,5 @@
package cc.carm.lib.mineconfiguration.bukkit.builder.message; package cc.carm.lib.mineconfiguration.bukkit.builder.message;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig; import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser; import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder; import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
@@ -9,7 +8,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Optional;
import java.util.function.BiFunction; import java.util.function.BiFunction;
public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> { public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
@@ -0,0 +1,110 @@
package cc.carm.lib.mineconfiguration.bukkit.builder.notify;
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.NotifyConfig;
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.ConfiguredNotify;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.DefaultNotifyTypes;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.Sound;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.UnaryOperator;
public class NotifyConfigBuilder extends CommonConfigBuilder<List<NotifyConfig>, NotifyConfigBuilder> {
protected final @NotNull List<NotifyConfig> notifications = new ArrayList<>();
protected @NotNull String[] params = new String[0];
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
public NotifyConfigBuilder() {
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
}
public NotifyConfigBuilder defaultMessages(@NotNull String... messages) {
return defaultMessages(Arrays.asList(messages));
}
public NotifyConfigBuilder defaultMessages(@NotNull List<String> messages) {
for (String message : messages) {
notifications.add(NotifyConfig.of(DefaultNotifyTypes.MESSAGE, message));
}
return defaults(this.notifications);
}
public NotifyConfigBuilder defaultActionBar(@NotNull String message) {
notifications.add(NotifyConfig.of(DefaultNotifyTypes.ACTIONBAR, message));
return defaults(this.notifications);
}
public NotifyConfigBuilder defaultSound(@NotNull Sound sound, float volume, float pitch) {
return defaultSound(sound.name(), volume, pitch);
}
public NotifyConfigBuilder defaultSound(@NotNull Sound sound, float volume) {
return defaultSound(sound, volume, 1.0f);
}
public NotifyConfigBuilder defaultSound(@NotNull Sound sound) {
return defaultSound(sound, 1.0f);
}
public NotifyConfigBuilder defaultSound(@NotNull String soundName, float volume, float pitch) {
notifications.add(NotifyConfig.of(DefaultNotifyTypes.SOUND, new SoundConfig(soundName, volume, pitch)));
return defaults(this.notifications);
}
public NotifyConfigBuilder defaultSound(@NotNull String soundName, float volume) {
return defaultSound(soundName, volume, 1.0f);
}
public NotifyConfigBuilder defaultSound(@NotNull String soundName) {
return defaultSound(soundName, 1.0f);
}
public NotifyConfigBuilder defaultTitle(@Nullable String line1, @Nullable String line2,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut) {
notifications.add(NotifyConfig.of(DefaultNotifyTypes.TITLE, TitleConfig.of(line1, line2, fadeIn, stay, fadeOut)));
return defaults(this.notifications);
}
public NotifyConfigBuilder defaultTitle(@Nullable String line1, @Nullable String line2) {
return defaultTitle(line1, line2, 10, 60, 10);
}
public NotifyConfigBuilder params(String... params) {
this.params = params;
return this;
}
public NotifyConfigBuilder params(@NotNull List<String> params) {
return params(params.toArray(new String[0]));
}
public NotifyConfigBuilder formatParam(UnaryOperator<String> paramFormatter) {
this.paramFormatter = paramFormatter;
return this;
}
@Override
protected @NotNull NotifyConfigBuilder getThis() {
return this;
}
@Override
public @NotNull ConfiguredNotify build() {
return new ConfiguredNotify(buildManifest(), ParamsUtils.formatParams(this.paramFormatter, this.params));
}
}
@@ -2,43 +2,29 @@ package cc.carm.lib.mineconfiguration.bukkit.builder.title;
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder; import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig; import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
import cc.carm.lib.mineconfiguration.bukkit.utils.ProtocolLibHelper;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle; import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils; import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range; import org.jetbrains.annotations.Range;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.UnaryOperator;
public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleConfigBuilder> { public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleConfigBuilder> {
@SuppressWarnings("deprecation")
protected static @NotNull TitleSendConsumer DEFAULT_TITLE_CONSUMER = (player, fadeIn, stay, fadeOut, line1, line2) -> {
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
try {
ProtocolLibHelper.sendTitle(player, fadeIn, stay, fadeOut, line1, line2);
} catch (Exception ignored) {
}
} else {
player.sendTitle(line1, line2);
}
};
protected @NotNull String[] params = new String[0]; protected @NotNull String[] params = new String[0];
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn = 10; protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn = 10;
protected @Range(from = 0L, to = Integer.MAX_VALUE) int stay = 60; protected @Range(from = 0L, to = Integer.MAX_VALUE) int stay = 60;
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut = 10; protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut = 10;
protected @NotNull TitleSendConsumer sendConsumer; protected @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter; protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
public TitleConfigBuilder() { public TitleConfigBuilder() {
this.sendConsumer = TitleConfigBuilder.DEFAULT_TITLE_CONSUMER; this.sendConsumer = ConfiguredTitle.DEFAULT_TITLE_CONSUMER;
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER; this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
} }
@@ -47,7 +33,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
return defaults(TitleConfig.of(line1, line2)); return defaults(TitleConfig.of(line1, line2));
} }
public @NotNull TitleConfigBuilder whenSend(@NotNull TitleSendConsumer consumer) { public @NotNull TitleConfigBuilder whenSend(@NotNull ConfiguredTitle.TitleConsumer consumer) {
this.sendConsumer = consumer; this.sendConsumer = consumer;
return this; return this;
} }
@@ -76,7 +62,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
return this; return this;
} }
public TitleConfigBuilder formatParam(Function<String, String> paramFormatter) { public TitleConfigBuilder formatParam(UnaryOperator<String> paramFormatter) {
this.paramFormatter = paramFormatter; this.paramFormatter = paramFormatter;
return this; return this;
} }
@@ -1,178 +0,0 @@
package cc.carm.lib.mineconfiguration.bukkit.data;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.stream.Collectors;
public class ItemConfig {
protected @NotNull Material type;
protected short data;
protected @Nullable String name;
protected @NotNull List<String> lore;
protected @NotNull Map<Enchantment, Integer> enchants;
protected @NotNull Set<ItemFlag> flags;
public ItemConfig(@NotNull Material type, @Nullable String name) {
this(type, name, Collections.emptyList());
}
public ItemConfig(@NotNull Material type, @Nullable String name, @NotNull List<String> lore) {
this(type, (short) 0, name, lore);
}
public ItemConfig(@NotNull Material type, short damage,
@Nullable String name, @NotNull List<String> lore) {
this(type, damage, name, lore, Collections.emptyMap(), Collections.emptySet());
}
public ItemConfig(@NotNull Material type, short damage,
@Nullable String name, @NotNull List<String> lore,
@NotNull Map<Enchantment, Integer> enchants,
@NotNull Set<ItemFlag> flags) {
this.type = type;
this.data = damage;
this.name = name;
this.lore = lore;
this.enchants = enchants;
this.flags = flags;
}
public @NotNull Material getType() {
return type;
}
public short getData() {
return data;
}
public @Nullable String getName() {
return name;
}
public @Nullable String getName(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
return Optional.ofNullable(getName())
.map(name -> TextParser.parseText(player, name, placeholders))
.orElse(null);
}
public @NotNull List<String> getLore() {
return lore;
}
public @Nullable List<String> getLore(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
if (getLore().isEmpty()) return null;
else return TextParser.parseList(player, getLore(), placeholders);
}
public final @NotNull ItemStack getItemStack() {
return getItemStack(1);
}
public @NotNull ItemStack getItemStack(int amount) {
return getItemStack(null, amount, new HashMap<>());
}
public @NotNull ItemStack getItemStack(@Nullable Player player) {
return getItemStack(player, new HashMap<>());
}
public @NotNull ItemStack getItemStack(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
return getItemStack(player, 1, placeholders);
}
public @NotNull ItemStack getItemStack(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
ItemStack item = new ItemStack(type, amount, data);
ItemMeta meta = item.getItemMeta();
if (meta == null) return item;
Optional.ofNullable(getName(player, placeholders)).ifPresent(meta::setDisplayName);
Optional.ofNullable(getLore(player, placeholders)).ifPresent(meta::setLore);
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
flags.forEach(meta::addItemFlags);
item.setItemMeta(meta);
return item;
}
public @NotNull Map<String, Object> serialize() {
Map<String, Object> map = new LinkedHashMap<>();
map.put("type", type.name());
if (this.data != 0) map.put("data", data);
if (name != null) map.put("name", name);
if (!lore.isEmpty()) map.put("lore", lore);
Map<String, Integer> enchantments = new LinkedHashMap<>();
enchants.forEach((enchant, level) -> {
if (level > 0) enchantments.put(enchant.getName(), level);
});
if (!enchantments.isEmpty()) {
map.put("enchants", enchantments);
}
if (!flags.isEmpty()) {
map.put("flags", flags.stream().map(ItemFlag::name).collect(Collectors.toList()));
}
return map;
}
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationSection section) throws Exception {
return deserialize(CraftSectionWrapper.of(section));
}
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper<?> section) throws Exception {
String typeName = section.getString("type");
if (typeName == null) throw new NullPointerException("Item type name is null");
Material type = Material.matchMaterial(typeName);
if (type == null) throw new Exception("Invalid material name: " + typeName);
short data = section.getShort("data", (short) 0);
String name = section.getString("name");
List<String> lore = section.getStringList("lore");
Map<Enchantment, Integer> enchantments = readEnchantments(section.getConfigurationSection("enchants"));
Set<ItemFlag> flags = readFlags(section.getStringList("flags"));
return new ItemConfig(type, data, name, lore, enchantments, flags);
}
private static ItemFlag parseFlag(String flagName) {
return Arrays.stream(ItemFlag.values()).filter(flag -> flag.name().equalsIgnoreCase(flagName)).findFirst().orElse(null);
}
private static Set<ItemFlag> readFlags(List<String> flagConfig) {
Set<ItemFlag> flags = new LinkedHashSet<>();
for (String flagName : flagConfig) {
ItemFlag flag = parseFlag(flagName);
if (flag != null) flags.add(flag);
}
return flags;
}
private static Map<Enchantment, Integer> readEnchantments(ConfigurationWrapper<?> section) {
Map<Enchantment, Integer> enchantments = new LinkedHashMap<>();
if (section == null) return enchantments;
section.getKeys(false).forEach(key -> {
Enchantment enchantment = Enchantment.getByName(key);
int level = section.getInt(key, 0);
if (enchantment != null && level > 0) {
enchantments.put(enchantment, level);
}
});
return enchantments;
}
}
@@ -0,0 +1,53 @@
package cc.carm.lib.mineconfiguration.bukkit.data;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyCache;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Optional;
public class NotifyConfig {
public static @Nullable NotifyConfig deserialize(@NotNull String config) {
return Optional.ofNullable(NotifyCache.deserialize(config)).map(NotifyConfig::of).orElse(null);
}
public static @NotNull NotifyConfig of(@NotNull NotifyCache<?, ?> cache) {
return new NotifyConfig(cache);
}
public static @Nullable NotifyConfig of(@NotNull String key, @Nullable String param, @Nullable String content) {
return Optional.ofNullable(NotifyCache.of(key, param, content)).map(NotifyConfig::of).orElse(null);
}
public static <T extends NotifyType<M>, M> NotifyConfig of(@NotNull T type, @Nullable String param, @Nullable String content) {
return of(type, type.parseMeta(param, content));
}
public static <T extends NotifyType<M>, M> NotifyConfig of(@NotNull T type, @Nullable M meta) {
return of(NotifyCache.of(type, meta));
}
protected final @NotNull NotifyCache<?, ?> cache;
public NotifyConfig(@NotNull NotifyCache<?, ?> cache) {
this.cache = cache;
}
public @NotNull NotifyCache<?, ?> getCache() {
return cache;
}
public void execute(@NotNull Player player, @NotNull Map<String, Object> placeholders) {
getCache().execute(player, placeholders);
}
public String serialize() {
return getCache().serialize();
}
}
@@ -1,8 +1,8 @@
package cc.carm.lib.mineconfiguration.bukkit.data; package cc.carm.lib.mineconfiguration.bukkit.data;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper; import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser; import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -25,20 +25,82 @@ public class TitleConfig {
return new TitleConfig(line1, line2); return new TitleConfig(line1, line2);
} }
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2,
int fadeIn, int stay, int fadeOut) {
return of(
Optional.ofNullable(line1).map(TextConfig::of).orElse(null),
Optional.ofNullable(line2).map(TextConfig::of).orElse(null),
fadeIn, stay, fadeOut
);
}
public static @NotNull TitleConfig of(@Nullable TextConfig line1, @Nullable TextConfig line2,
int fadeIn, int stay, int fadeOut) {
return new TitleConfig(line1, line2, fadeIn, stay, fadeOut);
}
protected @Nullable TextConfig line1; protected @Nullable TextConfig line1;
protected @Nullable TextConfig line2; protected @Nullable TextConfig line2;
protected final int fadeIn;
protected final int stay;
protected final int fadeOut;
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2) { protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2) {
this(line1, line2, -1, -1, -1);
}
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2, int fadeIn, int stay, int fadeOut) {
this.line1 = line1; this.line1 = line1;
this.line2 = line2; this.line2 = line2;
this.fadeIn = fadeIn;
this.stay = stay;
this.fadeOut = fadeOut;
}
public int getFadeIn() {
return fadeIn;
}
public int getFadeOut() {
return fadeOut;
}
public int getStay() {
return stay;
}
public boolean isStandardTime() {
return this.fadeIn == 10 && this.stay == 60 && this.fadeOut == 10;
}
public @Nullable TextConfig getLine1() {
return line1;
}
public @Nullable TextConfig getLine2() {
return line2;
} }
public void send(@NotNull Player player, public void send(@NotNull Player player,
@Range(from = 0L, to = Long.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Long.MAX_VALUE) int stay,
@Range(from = 0L, to = Long.MAX_VALUE) int fadeOut,
@NotNull Map<String, Object> placeholders, @NotNull Map<String, Object> placeholders,
@Nullable TitleSendConsumer sendConsumer) { @Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
send(
player,
this.fadeIn < 0 ? 10 : this.fadeIn,
this.stay < 0 ? 60 : this.stay,
this.fadeOut < 0 ? 10 : this.fadeOut,
placeholders,
sendConsumer
);
}
public void send(@NotNull Player player,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
@NotNull Map<String, Object> placeholders,
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
if (this.line1 == null && this.line2 == null) return; if (this.line1 == null && this.line2 == null) return;
if (sendConsumer == null) return; if (sendConsumer == null) return;
sendConsumer.send( sendConsumer.send(
@@ -58,11 +120,23 @@ public class TitleConfig {
Map<String, Object> map = new LinkedHashMap<>(); Map<String, Object> map = new LinkedHashMap<>();
if (this.line1 != null) map.put("line1", this.line1.getMessage()); if (this.line1 != null) map.put("line1", this.line1.getMessage());
if (this.line2 != null) map.put("line2", this.line2.getMessage()); if (this.line2 != null) map.put("line2", this.line2.getMessage());
if (this.fadeIn > 0) map.put("fadeIn", this.fadeIn);
if (this.stay > 0) map.put("stay", this.stay);
if (this.fadeOut > 0) map.put("fadeOut", this.fadeOut);
return map; return map;
} }
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) { public static @Nullable TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
return of(section.getString("line1"), section.getString("line2")); String line1 = section.getString("line1");
String line2 = section.getString("line2");
if (line1 == null && line2 == null) return null;
return of(
line1, line2,
section.getInt("fadeIn", -1),
section.getInt("stay", -1),
section.getInt("fadeOut", -1)
);
} }
} }
@@ -1,26 +0,0 @@
package cc.carm.lib.mineconfiguration.bukkit.function;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
@FunctionalInterface
public interface TitleSendConsumer {
/**
* 向目标玩家发送标题文字
*
* @param player 目标玩家
* @param fadeIn 淡入时间 (ticks)
* @param stay 保留时间 (ticks)
* @param fadeOut 淡出时间 (ticks)
* @param line1 第一行文字
* @param line2 第二行文字
*/
void send(@NotNull Player player,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
@NotNull String line1, @NotNull String line2);
}
@@ -7,6 +7,9 @@ import java.util.List;
public class PlaceholderAPIHelper { public class PlaceholderAPIHelper {
private PlaceholderAPIHelper() {
}
public static String parseMessages(Player player, String message) { public static String parseMessages(Player player, String message) {
try { try {
return PlaceholderAPI.setPlaceholders(player, message); return PlaceholderAPI.setPlaceholders(player, message);
@@ -1,41 +0,0 @@
package cc.carm.lib.mineconfiguration.bukkit.utils;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ProtocolLibHelper {
@SuppressWarnings("deprecation")
public static void sendTitle(@NotNull Player player, long fadeIn, long stay, long fadeOut, String line1, String line2) throws Exception {
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
if (line1 != null) {
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
packet.getTitleActions().write(0, EnumWrappers.TitleAction.TITLE);
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line1));
pm.sendServerPacket(player, packet, false);
}
if (line2 != null) {
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
packet.getTitleActions().write(0, EnumWrappers.TitleAction.SUBTITLE);
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line2));
pm.sendServerPacket(player, packet, false);
}
PacketContainer timePacket = pm.createPacket(PacketType.Play.Server.TITLE);
timePacket.getTitleActions().write(0, EnumWrappers.TitleAction.TIMES);
timePacket.getIntegers()
.write(0, Math.toIntExact(fadeIn))
.write(1, Math.toIntExact(stay))
.write(2, Math.toIntExact(fadeOut));
pm.sendServerPacket(player, timePacket, false);
}
}
@@ -15,6 +15,9 @@ import java.util.stream.Collectors;
public class TextParser { public class TextParser {
private TextParser() {
}
@Contract("_,!null,_->!null") @Contract("_,!null,_->!null")
public static @Nullable String parseText(@Nullable CommandSender sender, @Nullable String message, @NotNull Map<String, Object> placeholders) { public static @Nullable String parseText(@Nullable CommandSender sender, @Nullable String message, @NotNull Map<String, Object> placeholders) {
if (message == null) return null; if (message == null) return null;
@@ -1,71 +0,0 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.configuration.core.function.ConfigValueParser;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
public static ItemConfigBuilder create() {
return CraftConfigValue.builder().createItem();
}
public static ConfiguredItem of() {
return CraftConfigValue.builder().ofItem();
}
public static ConfiguredItem of(@Nullable ItemConfig defaultItem) {
return CraftConfigValue.builder().ofItem(defaultItem);
}
protected final @NotNull String[] params;
public ConfiguredItem(@NotNull ValueManifest<ItemConfig> manifest, @NotNull String[] params) {
super(
manifest, ItemConfig.class,
getItemParser(), ItemConfig::serialize
);
this.params = params;
}
public static ConfigValueParser<ConfigurationWrapper<?>, ItemConfig> getItemParser() {
return (s, d) -> ItemConfig.deserialize(s);
}
public @NotNull String[] getParams() {
return params;
}
public @Nullable ItemStack getItem(@Nullable Player player) {
return getItem(player, 1);
}
public @Nullable ItemStack getItem(@Nullable Player player, int amount) {
return getItem(player, amount, new HashMap<>());
}
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Object... values) {
return getItem(player, amount, ParamsUtils.buildParams(params, values));
}
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull String[] params, @NotNull Object[] values) {
return getItem(player, amount, ParamsUtils.buildParams(params, values));
}
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
return getOptional().map(item -> item.getItemStack(player, amount, placeholders)).orElse(null);
}
}
@@ -4,15 +4,19 @@ import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue; import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder; import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig; import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage; import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
import com.cryptomorin.xseries.messages.ActionBar;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@@ -41,6 +45,14 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSe
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of); super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
} }
public void sendActionBar(Player player, String... values) {
sendActionBar(player, ParamsUtils.buildParams(this.params, values));
}
public void sendActionBar(Player player, Map<String, Object> placeholders) {
ActionBar.sendActionBar(player, parseString(player, placeholders));
}
@Override @Override
public @NotNull Collection<CommandSender> getAllReceivers() { public @NotNull Collection<CommandSender> getAllReceivers() {
List<CommandSender> senders = new ArrayList<>(); List<CommandSender> senders = new ArrayList<>();
@@ -7,8 +7,8 @@ import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue; import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder; import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig; import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils; import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import com.cryptomorin.xseries.messages.Titles;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -22,6 +22,8 @@ import java.util.function.Predicate;
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> { public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
public static final @NotNull ConfiguredTitle.TitleConsumer DEFAULT_TITLE_CONSUMER = Titles::sendTitle;
public static TitleConfigBuilder create() { public static TitleConfigBuilder create() {
return CraftConfigValue.builder().createTitle(); return CraftConfigValue.builder().createTitle();
} }
@@ -35,7 +37,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
return create().defaults(line1, line2).fadeIn(fadeIn).stay(stay).fadeOut(fadeOut).build(); return create().defaults(line1, line2).fadeIn(fadeIn).stay(stay).fadeOut(fadeOut).build();
} }
protected final @NotNull TitleSendConsumer sendConsumer; protected final @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
protected final @NotNull String[] params; protected final @NotNull String[] params;
protected final int fadeIn; protected final int fadeIn;
@@ -43,7 +45,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
protected final int fadeOut; protected final int fadeOut;
public ConfiguredTitle(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params, public ConfiguredTitle(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params,
@NotNull TitleSendConsumer sendConsumer, @NotNull ConfiguredTitle.TitleConsumer sendConsumer,
int fadeIn, int stay, int fadeOut) { int fadeIn, int stay, int fadeOut) {
super(manifest, TitleConfig.class, getTitleParser(), TitleConfig::serialize); super(manifest, TitleConfig.class, getTitleParser(), TitleConfig::serialize);
this.sendConsumer = sendConsumer; this.sendConsumer = sendConsumer;
@@ -68,7 +70,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
return fadeOut; return fadeOut;
} }
public @NotNull TitleSendConsumer getSendConsumer() { public @NotNull ConfiguredTitle.TitleConsumer getSendConsumer() {
return sendConsumer; return sendConsumer;
} }
@@ -116,4 +118,26 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() { public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
return (s, d) -> TitleConfig.deserialize(s); return (s, d) -> TitleConfig.deserialize(s);
} }
@FunctionalInterface
public interface TitleConsumer {
/**
* 向目标玩家发送标题文字
*
* @param player 目标玩家
* @param fadeIn 淡入时间 (ticks)
* @param stay 保留时间 (ticks)
* @param fadeOut 淡出时间 (ticks)
* @param line1 第一行文字
* @param line2 第二行文字
*/
void send(@NotNull Player player,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
@NotNull String line1, @NotNull String line2);
}
} }
@@ -0,0 +1,106 @@
package cc.carm.lib.mineconfiguration.bukkit.value.item;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
import com.cryptomorin.xseries.XItemStack;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Consumer;
public class ConfiguredItem extends ConfiguredSection<ItemStack> {
public static ItemConfigBuilder create() {
return new ItemConfigBuilder();
}
protected final @NotNull String[] params;
public ConfiguredItem(@NotNull ValueManifest<ItemStack> manifest, @NotNull String[] params) {
super(
manifest, ItemStack.class,
(data, v) -> XItemStack.deserialize((ConfigurationSection) data.getSource()),
XItemStack::serialize
);
this.params = params;
}
public @NotNull String[] getParams() {
return params;
}
@Override
public @NotNull Optional<@Nullable ItemStack> getOptional() {
return Optional.ofNullable(super.get());
}
@Override
public @Nullable ItemStack get() {
return getOptional().map(ItemStack::clone).orElse(null);
}
public @Nullable ItemStack get(Consumer<ItemStack> modifier) {
return getOptional().map(item -> {
modifier.accept(item);
return item;
}).orElse(null);
}
public @NotNull PreparedItem prepare(@NotNull Object... values) {
return PreparedItem.of(player -> get()).params(params).values(values);
}
public @Nullable ItemStack get(@Nullable Player player) {
return get(player, new HashMap<>());
}
public @Nullable ItemStack get(@Nullable Player player, @NotNull Object... values) {
return prepare(values).get(player);
}
public @Nullable ItemStack get(@Nullable Player player, @NotNull String[] params, @NotNull Object[] values) {
return prepare().params(params).values(values).get(player);
}
public @Nullable ItemStack get(@Nullable Player player,
@NotNull Map<String, Object> placeholders) {
return prepare().placeholders(placeholders).get(player);
}
public void modifyItem(Consumer<ItemStack> modifier) {
ItemStack item = get();
if (item == null) return;
modifier.accept(item);
set(item);
}
public void modifyMeta(Consumer<ItemMeta> modifier) {
modifyItem(item -> {
ItemMeta meta = item.getItemMeta();
modifier.accept(meta);
item.setItemMeta(meta);
});
}
public void setName(@Nullable String name) {
modifyMeta(meta -> meta.setDisplayName(name));
}
public void setLore(@Nullable List<String> lore) {
modifyMeta(meta -> meta.setLore(lore));
}
public void setLore(String... lore) {
if (lore.length == 0) setLore((List<String>) null);
else setLore(Arrays.asList(lore));
}
}
@@ -0,0 +1,273 @@
package cc.carm.lib.mineconfiguration.bukkit.value.item;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class ItemModifier<S extends ItemModifier<S, R>, R> {
public static final @NotNull Pattern LORE_INSERT_PATTERN = Pattern.compile("^(?:\\{(.*)})?#(.*)#(?:\\{(-?\\d+)(?:,(-?\\d+))?})?$");
protected final @NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider;
protected @NotNull Map<String, Object> placeholders = new HashMap<>();
protected @NotNull String[] params;
protected @NotNull Object[] values;
protected final @NotNull Map<String, LoreContent<?>> insertLore = new HashMap<>();
protected @NotNull BiConsumer<ItemStack, Player> itemConsumer;
protected @NotNull BiConsumer<ItemMeta, Player> metaConsumer;
protected ItemModifier(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
this.itemProvider = itemProvider;
this.params = new String[0];
this.values = new Object[0];
itemConsumer = (item, player) -> {
};
metaConsumer = (meta, player) -> {
};
}
protected abstract @NotNull S getThis();
public abstract @Nullable R get(Player player);
public void applyTo(@Nullable ItemStack item, @Nullable Player player) {
if (item == null) return;
ItemMeta meta = item.getItemMeta();
if (meta == null) return;
Map<String, Object> finalPlaceholders = buildPlaceholders();
String name = meta.getDisplayName();
if (!name.isEmpty()) {
meta.setDisplayName(TextParser.parseText(player, name, finalPlaceholders));
}
List<String> parsedLore = parseLore(player, meta.getLore(), insertLore, finalPlaceholders);
if (!parsedLore.isEmpty()) {
meta.setLore(parsedLore);
}
metaConsumer.accept(meta, player);
item.setItemMeta(meta);
itemConsumer.accept(item, player);
}
public S handleMeta(@NotNull BiConsumer<ItemMeta, Player> modifier) {
this.metaConsumer = this.metaConsumer.andThen(modifier);
return getThis();
}
public S handleItem(@NotNull BiConsumer<ItemStack, Player> modifier) {
this.itemConsumer = this.itemConsumer.andThen(modifier);
return getThis();
}
public S params(String[] params) {
this.params = params;
return getThis();
}
public S values(Object... values) {
this.values = values;
return getThis();
}
public S placeholders(@NotNull Map<String, Object> placeholders) {
this.placeholders = placeholders;
return getThis();
}
public S placeholders(@NotNull Consumer<Map<String, Object>> consumer) {
Map<String, Object> placeholders = new HashMap<>();
consumer.accept(placeholders);
return placeholders(placeholders);
}
public S insertLore(@NotNull String path, @NotNull LoreContent<?> content) {
insertLore.put(path, content);
return getThis();
}
public S insertLore(@NotNull String path, @NotNull List<String> content) {
return insertLore(path, content, false);
}
public S insertLore(@NotNull String path, @NotNull List<String> content, boolean original) {
return insertLore(path, LoreContent.of(content, original));
}
public S insertLore(@NotNull String path, @NotNull String... content) {
return insertLore(path, Arrays.asList(content));
}
public S insertLore(@NotNull String path, @NotNull ConfiguredList<String> content) {
return insertLore(path, content.copy());
}
public S insertLore(@NotNull String path,
@NotNull ConfiguredMessage<String> content, @NotNull Object... params) {
return insertLore(path, new LoreContent<ConfiguredMessage<String>>(content, false) {
@Override
public List<String> parse(CommandSender receiver) {
String str = getSource().parse(receiver, params);
if (str == null || str.isEmpty()) return Collections.emptyList();
return Collections.singletonList(str);
}
});
}
public S insertLore(@NotNull String path,
@NotNull ConfiguredMessageList<String> content, @NotNull Object... params) {
return insertLore(path, new LoreContent<ConfiguredMessageList<String>>(content, false) {
@Override
public List<String> parse(CommandSender receiver) {
List<String> list = getSource().parse(receiver, params);
if (list == null || list.isEmpty()) return Collections.emptyList();
return list;
}
});
}
public S amount(int amount) {
return handleItem((item, player) -> item.setAmount(amount));
}
public S addEnchantment(Enchantment e) {
return addEnchantment(e, 1);
}
public S addEnchantment(Enchantment e, int level) {
return addEnchantment(e, level, true);
}
public S addEnchantment(Enchantment e, int level, boolean ignoreLevelRestriction) {
return handleMeta((meta, player) -> meta.addEnchant(e, level, ignoreLevelRestriction));
}
public S addItemFlags(ItemFlag... flags) {
return handleMeta((meta, player) -> meta.addItemFlags(flags));
}
public S glow() {
return addItemFlags(ItemFlag.HIDE_ENCHANTS).addEnchantment(Enchantment.DURABILITY);
}
/**
* @param owner 玩家名
* @return this
* @deprecated Use {@link #setSkullOwner(OfflinePlayer)} instead.
*/
@Deprecated
public S setSkullOwner(String owner) {
return handleMeta((meta, player) -> {
if (!(meta instanceof SkullMeta)) return;
SkullMeta skullMeta = (SkullMeta) meta;
skullMeta.setOwner(owner);
});
}
public S setSkullOwner(UUID owner) {
return setSkullOwner(Bukkit.getOfflinePlayer(owner));
}
public S setSkullOwner(OfflinePlayer owner) {
return handleMeta((meta, player) -> {
if (!(meta instanceof SkullMeta)) return;
SkullMeta skullMeta = (SkullMeta) meta;
skullMeta.setOwningPlayer(owner);
});
}
protected Map<String, Object> buildPlaceholders() {
Map<String, Object> finalPlaceholders = new HashMap<>();
finalPlaceholders.putAll(ParamsUtils.buildParams(params, values));
finalPlaceholders.putAll(this.placeholders);
return finalPlaceholders;
}
public static List<String> parseLore(@Nullable Player player, @Nullable List<String> lore,
@NotNull Map<String, LoreContent<?>> insertedLore,
@NotNull Map<String, Object> placeholders) {
List<String> parsedLore = new ArrayList<>();
if (lore == null || lore.isEmpty()) return parsedLore;
for (String line : lore) {
Matcher matcher = LORE_INSERT_PATTERN.matcher(line);
if (!matcher.matches()) {
parsedLore.add(TextParser.parseText(player, line, placeholders));
continue;
}
String path = matcher.group(2);
LoreContent<?> content = insertedLore.get(path);
if (content == null) continue;
String prefix = Optional.ofNullable(matcher.group(1))
.map(s -> TextParser.parseText(player, s, placeholders))
.orElse("");
int offset1 = Optional.ofNullable(matcher.group(3))
.map(Integer::parseInt).orElse(0);
Integer offset2 = Optional.ofNullable(matcher.group(4))
.map(Integer::parseInt).orElse(null);
List<String> inserted = parseLoreLine(
player, content, placeholders, prefix,
offset2 == null ? 0 : offset1, offset2 == null ? offset1 : offset2
);
if (content.isOriginal()) {
parsedLore.addAll(inserted);
} else {
parsedLore.addAll(TextParser.parseList(player, inserted, placeholders));
}
}
return parsedLore;
}
public static List<String> parseLoreLine(@Nullable Player player, @NotNull LoreContent<?> content,
@NotNull Map<String, Object> placeholders,
@NotNull String parsedPrefix, int upOffset, int downOffset) {
List<String> lore = content.parse(player);
if (lore.isEmpty()) return Collections.emptyList();
upOffset = Math.max(0, upOffset);
downOffset = Math.max(0, downOffset);
List<String> finalLore = new ArrayList<>();
for (int i = 0; i < upOffset; i++) finalLore.add(" ");
if (content.isOriginal()) {
lore.stream().map(s -> parsedPrefix + s).forEach(finalLore::add);
} else {
lore.stream().map(s -> parsedPrefix + TextParser.parseText(player, s, placeholders)).forEach(finalLore::add);
}
for (int i = 0; i < downOffset; i++) finalLore.add(" ");
return finalLore;
}
}
@@ -0,0 +1,42 @@
package cc.carm.lib.mineconfiguration.bukkit.value.item;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public abstract class LoreContent<S> {
public static LoreContent<List<String>> of(@NotNull List<String> content) {
return of(content, false);
}
public static LoreContent<List<String>> of(@NotNull List<String> content, boolean original) {
return new LoreContent<List<String>>(content, original) {
@Override
public List<String> parse(CommandSender receiver) {
return getSource();
}
};
}
protected final @NotNull S source;
protected final boolean original;
public LoreContent(@NotNull S source, boolean original) {
this.source = source;
this.original = original;
}
public @NotNull S getSource() {
return source;
}
public abstract List<String> parse(CommandSender receiver);
public boolean isOriginal() {
return original;
}
}
@@ -0,0 +1,37 @@
package cc.carm.lib.mineconfiguration.bukkit.value.item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Function;
public class PreparedItem extends ItemModifier<PreparedItem, ItemStack> {
public static PreparedItem of(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
return new PreparedItem(itemProvider);
}
public static PreparedItem of(@Nullable ItemStack item) {
return of(player -> item);
}
public PreparedItem(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
super(itemProvider);
}
public @Nullable ItemStack get(Player player) {
@Nullable ItemStack item = itemProvider.apply(player);
if (item == null) return null;
applyTo(item, player);
return item;
}
@Override
public @NotNull PreparedItem getThis() {
return this;
}
}
@@ -0,0 +1,52 @@
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.mineconfiguration.bukkit.builder.notify.NotifyConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.NotifyConfig;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class ConfiguredNotify extends ConfiguredList<NotifyConfig> {
public static NotifyConfigBuilder create() {
return new NotifyConfigBuilder();
}
public static final Set<NotifyType<?>> TYPES = new HashSet<>(Arrays.asList(DefaultNotifyTypes.values()));
public static NotifyType<?> getType(@NotNull String key) {
return TYPES.stream().filter(type -> type.key.equalsIgnoreCase(key)).findFirst().orElse(null);
}
protected final @NotNull String[] params;
public ConfiguredNotify(@NotNull ValueManifest<List<NotifyConfig>> manifest, @NotNull String[] params) {
super(manifest, NotifyConfig.class, obj -> Objects.requireNonNull(NotifyConfig.deserialize(String.valueOf(obj))), NotifyConfig::serialize);
this.params = params;
}
public String[] getParams() {
return params;
}
public @NotNull PreparedNotify prepare(@NotNull Object... values) {
return new PreparedNotify(getNotNull(), ParamsUtils.buildParams(getParams(), values));
}
public void send(@NotNull Player player, @NotNull Object... values) {
prepare(values).to(player);
}
public void send(@NotNull Iterable<? extends Player> players, @NotNull Object... values) {
prepare(values).to(players);
}
public void sendAll(@NotNull String... values) {
prepare(values).toAll();
}
}
@@ -0,0 +1,30 @@
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.SoundNotify;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.StringNotify;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.TitleNotify;
import com.cryptomorin.xseries.messages.ActionBar;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Optional;
public interface DefaultNotifyTypes {
StringNotify MESSAGE = StringNotify.of("MESSAGE", Player::sendMessage, content -> Optional.ofNullable(content).orElse(" "));
StringNotify MSG = StringNotify.of("MSG", Player::sendMessage);
StringNotify ACTIONBAR = StringNotify.of("ACTIONBAR", ActionBar::sendActionBar);
TitleNotify TITLE = new TitleNotify("TITLE");
SoundNotify SOUND = new SoundNotify("SOUND");
static NotifyType<?>[] values() {
return new NotifyType<?>[]{MESSAGE, MSG, ACTIONBAR, TITLE, SOUND};
}
static NotifyType<?> valueOf(String name) {
return Arrays.stream(values()).filter(type -> type.key.equalsIgnoreCase(name)).findFirst().orElse(null);
}
}
@@ -0,0 +1,62 @@
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NotifyCache<T extends NotifyType<M>, M> {
// Notify config format: [TYPE(@PARAM)] CONTENTS...
public static final @NotNull Pattern CONFIG_FORMAT = Pattern.compile("\\[(?<type>[^@\\]]+)(@(?<param>[^]]+))?] (?<content>.*)");
public static @Nullable NotifyCache<?, ?> deserialize(@NotNull String config) {
// parse config with config_format
Matcher matcher = CONFIG_FORMAT.matcher(config.trim());
if (!matcher.matches()) return of("MESSAGE", null, config);
return of(matcher.group("type"), matcher.group("param"), matcher.group("content"));
}
public static @Nullable NotifyCache<?, ?> of(@NotNull String key, @Nullable String param, @Nullable String content) {
NotifyType<?> type = ConfiguredNotify.getType(key);
if (type == null) return null;
return NotifyCache.of(type, param, content);
}
public static <T extends NotifyType<M>, M> NotifyCache<T, M> of(@NotNull T type, @Nullable String param, @Nullable String content) {
return new NotifyCache<>(type, type.parseMeta(param, content));
}
public static <T extends NotifyType<M>, M> NotifyCache<T, M> of(@NotNull T type, @Nullable M meta) {
return new NotifyCache<>(type, meta);
}
protected final @NotNull T type;
protected final @Nullable M meta;
public NotifyCache(@NotNull T type, @Nullable M meta) {
this.type = type;
this.meta = meta;
}
public @NotNull T getType() {
return type;
}
public @Nullable M getMeta() {
return meta;
}
public void execute(@NotNull Player player, @NotNull Map<String, Object> placeholders) {
type.execute(player, meta, placeholders);
}
public String serialize() {
return type.serializeConfig(meta);
}
}
@@ -0,0 +1,61 @@
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
public abstract class NotifyType<M> {
protected final @NotNull String key;
protected final @NotNull Class<M> metaClass;
protected NotifyType(@NotNull String key, @NotNull Class<M> metaClass) {
this.key = key;
this.metaClass = metaClass;
}
public @NotNull String getKey() {
return key;
}
public @NotNull Class<M> getMetaClass() {
return metaClass;
}
/**
* Parse metadata from string.
* <br> e.g. "[TYPE-KEY@PARAM] CONTENTS..."
*
* @param param The param of the notify config.
* @param content The content of the notify config.
* @return The parsed metadata.
*/
public abstract @Nullable M parseMeta(@Nullable String param, @Nullable String content);
/**
* Serialize the metadata to singleton string to storage on configs.
*
* @param meta The parsed metadata.
* @return The serialized string.
*/
public abstract @NotNull String serializeConfig(@Nullable M meta);
/**
* Execute the notify content to specific player.
*
* @param player The player who receive the notification.
* @param meta The parsed metadata.
*/
public abstract void execute(@NotNull Player player, @Nullable M meta, @NotNull Map<String, Object> placeholders);
@Contract("_, _, null -> null; _, _, !null -> !null")
protected String setPlaceholders(@NotNull Player player, @Nullable String content,
@NotNull Map<String, Object> placeholders) {
return TextParser.parseText(player, content, placeholders);
}
}
@@ -0,0 +1,45 @@
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
import cc.carm.lib.mineconfiguration.bukkit.data.NotifyConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Map;
public class PreparedNotify {
protected final @NotNull List<NotifyConfig> notifications;
protected final @NotNull Map<String, Object> placeholders;
protected PreparedNotify(@NotNull List<NotifyConfig> notifications, @NotNull Map<String, Object> placeholders) {
this.notifications = notifications;
this.placeholders = placeholders;
}
/**
* 向某位接收者发送消息
*
* @param receiver 消息的接收者
*/
public void to(@NotNull Player receiver) {
notifications.forEach(config -> config.execute(receiver, placeholders));
}
/**
* 向某位接收者发送消息
*
* @param receivers 消息的接收者们
*/
public void to(@NotNull Iterable<? extends Player> receivers) {
receivers.forEach(this::to);
}
public void toAll() {
to(Bukkit.getOnlinePlayers());
}
}
@@ -0,0 +1,54 @@
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type;
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
public class SoundNotify extends NotifyType<SoundConfig> {
public SoundNotify(@NotNull String key) {
super(key, SoundConfig.class);
}
@Override
public @Nullable SoundConfig parseMeta(@Nullable String param, @Nullable String content) {
if (content == null) return null;
String[] args = param == null ? new String[0] : param.split(",");
try {
return new SoundConfig(content.trim(),
(args.length >= 1) ? Float.parseFloat(args[0]) : 1,
(args.length >= 2) ? Float.parseFloat(args[1]) : 1
);
} catch (Exception exception) {
exception.printStackTrace();
return null;
}
}
@Override
public @NotNull String serializeConfig(@Nullable SoundConfig meta) {
if (meta == null) return "[" + key + "] ";
if (meta.getVolume() == 1 && meta.getPitch() == 1) {
return "[" + key + "] " + meta.getTypeName();
} else {
return "[" + key + "@" + +meta.getVolume() + "," + meta.getPitch() + "] " + meta.getTypeName();
}
}
@Override
public void execute(@NotNull Player player, @Nullable SoundConfig meta, @NotNull Map<String, Object> placeholders) {
System.out.println("SoundNotify.execute");
if (meta != null) {
System.out.println("SoundNotify.play");
meta.playTo(player);
}
}
}
@@ -0,0 +1,52 @@
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.UnaryOperator;
public abstract class StringNotify extends NotifyType<String> {
public static StringNotify of(String key, BiConsumer<Player, String> consumer) {
return of(key, consumer, (content) -> "[" + key + "] " + (content == null ? " " : content));
}
public static StringNotify of(String key,
BiConsumer<Player, String> consumer,
UnaryOperator<String> serializer) {
return new StringNotify(key) {
@Override
public @NotNull String serializeConfig(@Nullable String meta) {
return serializer.apply(meta);
}
@Override
public void send(@NotNull Player player, @NotNull String parsedContent) {
consumer.accept(player, parsedContent);
}
};
}
protected StringNotify(String key) {
super(key, String.class);
}
public abstract void send(@NotNull Player player, @NotNull String parsedContent);
@Override
public @Nullable String parseMeta(@Nullable String param, @Nullable String content) {
return content;
}
@Override
public void execute(@NotNull Player player, @Nullable String content, @NotNull Map<String, Object> placeholders) {
if (content == null) return;
send(player, setPlaceholders(player, content, placeholders));
}
}
@@ -0,0 +1,67 @@
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type;
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
import cc.carm.lib.mineconfiguration.bukkit.value.notify.NotifyType;
import com.cryptomorin.xseries.messages.Titles;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TitleNotify extends NotifyType<TitleConfig> {
//Content format line1{N}line2
public static final Pattern CONTENT_FORMAT = Pattern.compile("(?<line1>.+?)(?:\\{n}(?<line2>.+))?");
//Param format fadeIn,stay,fadeOut
public static final Pattern PARAM_FORMAT = Pattern.compile("(?<fadeIn>\\d+),(?<stay>\\d+),(?<fadeOut>\\d+)");
public TitleNotify(String key) {
super(key, TitleConfig.class);
}
@Override
public @Nullable TitleConfig parseMeta(@Nullable String param, @Nullable String content) {
if (content == null) return null;
Matcher contentMatcher = CONTENT_FORMAT.matcher(content);
if (!contentMatcher.matches()) return null;
if (param == null) {
return TitleConfig.of(contentMatcher.group("line1"), contentMatcher.group("line2"));
}
Matcher paramMatcher = PARAM_FORMAT.matcher(param);
if (!paramMatcher.matches()) {
return TitleConfig.of(contentMatcher.group("line1"), contentMatcher.group("line2"));
}
return TitleConfig.of(
contentMatcher.group("line1"), contentMatcher.group("line2"),
Integer.parseInt(paramMatcher.group("fadeIn")),
Integer.parseInt(paramMatcher.group("stay")),
Integer.parseInt(paramMatcher.group("fadeOut"))
);
}
@Override
public @NotNull String serializeConfig(@Nullable TitleConfig meta) {
if (meta == null || (meta.getLine1() == null && meta.getLine2() == null)) return "[" + key + "] ";
String line1 = meta.getLine1() == null ? "" : meta.getLine1().getMessage();
String line2 = meta.getLine2() == null ? "" : meta.getLine2().getMessage();
if (meta.isStandardTime()) {
return "[" + key + "] " + line1 + "{n}" + line1;
} else
return "[" + key + "@" + meta.getFadeIn() + "," + meta.getStay() + "," + meta.getFadeOut() + "] " + line1 + "{n}" + line1;
}
@Override
public void execute(@NotNull Player player, @Nullable TitleConfig meta, @NotNull Map<String, Object> placeholders) {
if (meta != null) meta.send(player, placeholders, Titles::sendTitle);
}
}
@@ -0,0 +1,55 @@
import cc.carm.lib.mineconfiguration.bukkit.value.item.LoreContent;
import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem;
import org.junit.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
public class LoreInsertTest {
@Test
public void insert() {
List<String> original = Arrays.asList(
"测试lore的第一行",
"测试lore的第二行",
"#click-lore#{1,2}",
"测试lore的倒数第二行",
"{--> }#click-lore#{2}",
"测试lore的倒数第一行"
);
List<String> replace = Arrays.asList("> 插入的点击行1", "> 插入的点击行2");
Map<String, LoreContent<?>> inserted = new HashMap<>();
inserted.put("click-lore", LoreContent.of(replace));
PreparedItem.parseLore(null, original, inserted, new HashMap<>()).forEach(System.out::println);
}
@Test
public void parse() {
System.out.println(parse("{LOVE}#click-lore#{1,0}"));
System.out.println(parse("#click-lore#{1,2}"));
System.out.println(parse("#click-lore#{1}"));
System.out.println(parse("#click-lore#{我}"));
}
public static String parse(String line) {
Matcher matcher = PreparedItem.LORE_INSERT_PATTERN.matcher(line);
if (!matcher.matches()) {
return "Failed -> [" + line + "]";
} else {
String prefix = matcher.group(1);
String path = matcher.group(2);
String offset1 = matcher.group(3);
String offset2 = matcher.group(4);
return "Prefix -> [" + prefix + "] Path -> [" + path + "] Offset-> [" + offset1 + "/" + offset2 + "]";
}
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>mineconfiguration-parent</artifactId> <artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<version>2.6.0</version> <version>2.9.1</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -1,15 +1,18 @@
package cc.carm.lib.mineconfiguration.bungee; package cc.carm.lib.mineconfiguration.bungee;
import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider; import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.JsonConfiguration; import net.md_5.bungee.config.JsonConfiguration;
import net.md_5.bungee.config.YamlConfiguration; import net.md_5.bungee.config.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
public class MineConfiguration { public class MineConfiguration extends AbstractConfiguration<BungeeConfigProvider> {
protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) { protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) {
BungeeConfigProvider provider = new BungeeConfigProvider(file, loader); BungeeConfigProvider provider = new BungeeConfigProvider(file, loader);
@@ -94,4 +97,26 @@ public class MineConfiguration {
return fromJSON(new File(plugin.getDataFolder(), fileName), source); return fromJSON(new File(plugin.getDataFolder(), fileName), source);
} }
public MineConfiguration(@NotNull Plugin plugin) {
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
}
public MineConfiguration(@NotNull Plugin plugin,
@NotNull ConfigurationRoot configRoot,
@NotNull ConfigurationRoot messageRoot) {
this(plugin);
initializeConfig(configRoot);
initializeMessage(messageRoot);
}
public MineConfiguration(@NotNull Plugin plugin,
@NotNull Class<? extends ConfigurationRoot> configRoot,
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
this(plugin);
initializeConfig(configRoot);
initializeMessage(messageRoot);
}
} }
+10 -10
View File
@@ -10,14 +10,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<deps.easyconfifuration.version>3.6.0</deps.easyconfifuration.version> <deps.easyconfifuration.version>3.9.1</deps.easyconfifuration.version>
<deps.easyplugin.version>1.5.4</deps.easyplugin.version> <deps.easyplugin.version>1.5.11</deps.easyplugin.version>
<deps.yamlcommentwriter.version>1.0.1</deps.yamlcommentwriter.version> <deps.yamlcommentwriter.version>1.0.1</deps.yamlcommentwriter.version>
</properties> </properties>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<artifactId>mineconfiguration-parent</artifactId> <artifactId>mineconfiguration-parent</artifactId>
<version>2.6.0</version> <version>2.9.1</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>common</module> <module>common</module>
@@ -109,7 +109,7 @@
<dependency> <dependency>
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>
<version>24.0.1</version> <version>24.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@@ -122,7 +122,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version> <version>3.2.3</version>
<configuration> <configuration>
<useSystemClassLoader>false</useSystemClassLoader> <useSystemClassLoader>false</useSystemClassLoader>
</configuration> </configuration>
@@ -150,7 +150,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId> <artifactId>maven-release-plugin</artifactId>
<version>3.0.0</version> <version>3.0.1</version>
<configuration> <configuration>
<autoVersionSubmodules>true</autoVersionSubmodules> <autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile> <useReleaseProfile>false</useReleaseProfile>
@@ -161,7 +161,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version> <version>3.12.0</version>
<configuration> <configuration>
<source>${project.jdk.version}</source> <source>${project.jdk.version}</source>
<target>${project.jdk.version}</target> <target>${project.jdk.version}</target>
@@ -178,7 +178,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version> <version>3.3.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -196,7 +196,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version> <version>3.6.3</version>
<configuration> <configuration>
<classifier>javadoc</classifier> <classifier>javadoc</classifier>
<detectJavaApiLink>false</detectJavaApiLink> <detectJavaApiLink>false</detectJavaApiLink>
@@ -225,7 +225,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version> <version>3.5.1</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>