Compare commits

...
719 Commits
Author SHA1 Message Date
tr7zw 5bdddc134a Release 2.16.1 2026-09-17 20:06:29 +02:00
tr7zw 733b871c09 Merge pull request #359 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.16.0
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.15.0 to 3.16.0
2026-09-17 20:04:44 +02:00
tr7zw bc48239fdd Start 2.16.1-SNAPSHOT 2026-09-16 18:52:12 +02:00
tr7zw f182204b2f Merge pull request #360 from NriotHrreion/fix/paper-26.3-as-bukkit-mirror
Add Minecraft 26.3 item stack compatibility
2026-09-16 18:51:06 +02:00
NriotHrreion a424ce1e85 Add Minecraft 26.3 item stack compatibility 2026-09-16 14:44:15 +08:00
dependabot[bot] c881566c14 Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.15.0 to 3.16.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.15.0...maven-compiler-plugin-3.16.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2026-09-02 23:12:40 +00:00
tr7zw 2d6aa142de Bump version 2.16.0 2026-07-27 18:21:45 +02:00
tr7zw cc1436cd09 Merge pull request #353 from SoSeDiK/blocks
Migrate NBTBlock & NBTChunk to NBT
2026-07-27 18:12:50 +02:00
tr7zw 4506dd37da Remove setClosed calls
They do nothing in this case
2026-07-27 18:09:51 +02:00
tr7zw bbc02e1299 Merge pull request #356 from EverNife/master
Fix 'GET_LIST' and 'OWN_TYPE' to their 'LEGACY' sufixed name on Forge at 1.7.10
2026-07-24 21:28:43 +02:00
Petrus Pradella ca9d5ad140 Fix 'GET_LIST' and 'OWN_TYPE' to thier 'LEGACY' sufixed name on Forge at Minecraft 1.7.10 2026-07-13 03:04:12 -03:00
tr7zw 25c82a5ad0 Merge pull request #354 from SoSeDiK/badges
Update readme badges
2026-07-08 20:06:33 +02:00
tr7zw 17d40445d2 Remove ko-fi 2026-07-08 20:06:04 +02:00
SoSeDiK 47ad3591df Migrate NBTBlock & NBTChunk to NBT 2026-06-26 22:35:25 +03:00
SoSeDiK b3652ecf7d Update readme badges 2026-06-26 12:55:36 +03:00
tr7zw 46a9116613 Start 2.15.8-SNAPSHOT, add 26.2 support 2026-06-16 20:02:53 +02:00
tr7zw 5776be4a35 Add support for 26.1.x, paper 26.1.x support, bump version 2026-04-06 16:07:15 +02:00
tr7zw 9fbee68966 Release 2.15.6 2026-03-28 17:05:22 +01:00
tr7zw b277f0b01d Update the DataVersion when upgrading Item NBT 2026-03-28 16:59:38 +01:00
tr7zw e4793a0d46 Merge pull request #348 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.6.2
Bump org.apache.maven.plugins:maven-shade-plugin from 3.6.1 to 3.6.2
2026-03-28 16:11:44 +01:00
tr7zw 7c34542b86 Add 26.1 2026-03-28 16:08:13 +01:00
dependabot[bot] 856bf5ed6d Bump org.apache.maven.plugins:maven-shade-plugin from 3.6.1 to 3.6.2
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.6.1 to 3.6.2.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.6.1...maven-shade-plugin-3.6.2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-05 23:17:37 +00:00
tr7zw 123da87a3a Merge pull request #341 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.7.1
Bump org.codehaus.mojo:license-maven-plugin from 2.7.0 to 2.7.1
2026-03-05 21:45:13 +01:00
tr7zw f3d7545c6b Merge pull request #344 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.15.0
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.14.1 to 3.15.0
2026-03-05 21:45:02 +01:00
tr7zw 3b29fe399e Merge pull request #347 from tr7zw/dependabot/maven/org.bstats-bstats-bukkit-3.2.1
Bump org.bstats:bstats-bukkit from 3.1.0 to 3.2.1
2026-03-05 21:44:50 +01:00
tr7zw c368318bb6 Start 2.15.6-SNAPSHOT 2026-03-05 21:44:05 +01:00
dependabot[bot] c1473dfa97 Bump org.bstats:bstats-bukkit from 3.1.0 to 3.2.1
Bumps [org.bstats:bstats-bukkit](https://github.com/Bastian/bStats-Metrics) from 3.1.0 to 3.2.1.
- [Release notes](https://github.com/Bastian/bStats-Metrics/releases)
- [Commits](https://github.com/Bastian/bStats-Metrics/compare/v3.1.0...v3.2.1)

---
updated-dependencies:
- dependency-name: org.bstats:bstats-bukkit
  dependency-version: 3.2.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-24 23:13:02 +00:00
dependabot[bot] a360ca50f4 Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.14.1 to 3.15.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.14.1...maven-compiler-plugin-3.15.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-03 04:12:03 +00:00
dependabot[bot] 8b1ca8447e Bump org.codehaus.mojo:license-maven-plugin from 2.7.0 to 2.7.1
Bumps [org.codehaus.mojo:license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.7.0 to 2.7.1.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/2.7.0...2.7.1)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-version: 2.7.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-05 23:02:18 +00:00
tr7zw b66353d0d0 Release 2.15.5 2025-12-09 20:19:44 +01:00
tr7zw 5bec1371d2 Add missing line so the api doesn't complain 2025-12-09 19:11:20 +01:00
tr7zw 8cbb6af964 Start 2.15.5-SNAPSHOT 2025-12-09 19:09:48 +01:00
tr7zw 309455ecfc Merge branch 'master' of https://github.com/tr7zw/Item-NBT-API 2025-12-09 18:44:38 +01:00
tr7zw 22c0b0385b Release 2.15.4 2025-12-09 18:44:30 +01:00
tr7zw bc6bd56ce9 Merge pull request #339 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.4.0
Bump org.apache.maven.plugins:maven-source-plugin from 3.3.1 to 3.4.0
2025-12-09 18:43:18 +01:00
tr7zw fcdf0929f9 Add 1.21.11 support 2025-12-09 18:37:52 +01:00
tr7zw e1c6ce2575 Start 2.15.4-SNAPSHOT 2025-12-09 18:36:41 +01:00
dependabot[bot] 2fcc1d82ab Bump org.apache.maven.plugins:maven-source-plugin from 3.3.1 to 3.4.0
Bumps [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.3.1 to 3.4.0.
- [Release notes](https://github.com/apache/maven-source-plugin/releases)
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.3.1...maven-source-plugin-3.4.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-02 02:01:29 +00:00
tr7zw eec2c0980e tag 2.15.3 2025-10-11 17:05:48 +02:00
tr7zw 3ddf3e53dc Add 1.21.10 support 2025-10-04 20:09:20 +02:00
tr7zw 70d5ab12eb Add 1.21.9 spigot support 2025-09-30 19:25:28 +02:00
tr7zw a63e9ba8f4 Add 1.21.9 Paper support, Fix Gameprofile reading/writing 2025-09-30 19:14:54 +02:00
tr7zw d8a59d6383 Merge pull request #335 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.6.1
Bump org.apache.maven.plugins:maven-shade-plugin from 3.6.0 to 3.6.1
2025-09-28 11:53:27 +02:00
tr7zw 943c7d23d6 Merge pull request #336 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.7.0
Bump org.codehaus.mojo:license-maven-plugin from 2.6.0 to 2.7.0
2025-09-28 11:53:18 +02:00
tr7zw 6c70ce2ccc Merge pull request #337 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.14.1
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.14.0 to 3.14.1
2025-09-28 11:53:09 +02:00
tr7zw c1b7854fbb Merge pull request #338 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.12.0
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.3 to 3.12.0
2025-09-28 11:52:59 +02:00
tr7zw f9f1c204b6 Start 2.15.3-SNAPSHOT 2025-09-28 11:52:38 +02:00
dependabot[bot] 789f1fea96 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.3 to 3.12.0
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.11.3 to 3.12.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.11.3...maven-javadoc-plugin-3.12.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-22 23:02:47 +00:00
dependabot[bot] 0e40144f09 Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.14.0 to 3.14.1.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.14.0...maven-compiler-plugin-3.14.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-22 23:02:10 +00:00
dependabot[bot] 1c6315e014 Bump org.codehaus.mojo:license-maven-plugin from 2.6.0 to 2.7.0
Bumps [org.codehaus.mojo:license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.6.0 to 2.7.0.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/2.6.0...2.7.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-version: 2.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-22 23:02:05 +00:00
dependabot[bot] 91f345adf2 Bump org.apache.maven.plugins:maven-shade-plugin from 3.6.0 to 3.6.1
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.6.0 to 3.6.1.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.6.0...v3.6.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-15 23:09:04 +00:00
tr7zw 71783a8dc9 Release 2.15.2 2025-08-26 21:59:51 +02:00
tr7zw 5d06ae9275 Fix version variables in DataFixerUtil 2025-08-26 21:51:54 +02:00
tr7zw 835fdf48cd Fix codec mapping issue in 1.21.5. Fix #332 2025-08-26 21:35:36 +02:00
tr7zw 31d77d25f9 Merge pull request #333 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.11.3
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.2 to 3.11.3
2025-08-20 21:55:57 +02:00
dependabot[bot] 6cb08ac919 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.2 to 3.11.3
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.11.2 to 3.11.3.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.11.2...maven-javadoc-plugin-3.11.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-19 10:47:34 +00:00
tr7zw 08a92ac06c 2.15.2-SNAPSHOT, add 1.21.8 2025-07-17 20:29:51 +02:00
tr7zw 6bcd00d114 Bump to 2.15.1 release 2025-07-01 19:42:39 +02:00
tr7zw bc93986392 Merge pull request #328 from patyhank/master
Mark 1.21.7 as supported
2025-07-01 15:01:39 +02:00
蒟蒻 aa646e35ae mark 1.21.7 as supported 2025-07-01 20:51:49 +08:00
tr7zw 1054d16996 Add Spigot 1.21.6 support 2025-06-24 22:18:48 +02:00
tr7zw 9351a86774 Merge pull request #325 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.6.0
Bump org.codehaus.mojo:license-maven-plugin from 2.5.0 to 2.6.0
2025-06-24 21:57:11 +02:00
tr7zw 56a43d246b Merge pull request #326 from patyhank/master
[1.21.6] support Entity and BlockEntity
2025-06-24 21:57:01 +02:00
蒟蒻 2b895fd4ef Entity and BlockEntity update to MC1_21_R5 2025-06-24 10:54:47 +08:00
dependabot[bot] 8f8bbfd034 Bump org.codehaus.mojo:license-maven-plugin from 2.5.0 to 2.6.0
Bumps [org.codehaus.mojo:license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/2.5.0...2.6.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-version: 2.6.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-24 01:45:14 +00:00
tr7zw df231c2324 Fix RegistryOps initialization for MC1_21_R5 and above
Wrapped the initialization of nbtRegistryOps in a version check to ensure it only runs for Minecraft versions MC1_21_R5 and above. This prevents potential errors on earlier versions where the method may not be available.
2025-06-21 13:55:03 +02:00
tr7zw b068284b6e Fix 1.21.6 items with components 2025-06-19 02:26:08 +02:00
tr7zw 9e9b85f46a WIP update to 1.21.6 Paper (here be dragons) 2025-06-18 22:43:03 +02:00
tr7zw 3baed4b1e7 Catch issues with the yml 2025-06-16 18:44:30 +02:00
tr7zw 432b40b3bc Add paper-plugin.yml support. Stat for plugin type 2025-06-06 22:22:56 +02:00
tr7zw fdf3638948 Add new bStats graphs 2025-06-06 21:39:10 +02:00
tr7zw b240e888cd Shade in the Metrics the correct way 2025-06-06 19:33:17 +02:00
tr7zw ccc096e2d4 Start 2.15.1-SNAPSHOT 2025-06-06 19:00:02 +02:00
tr7zw 35f541d3db Tag 2.15.0 2025-04-17 20:30:44 +02:00
tr7zw d4ee3b998c Fix wiki 2025-04-17 19:46:53 +02:00
tr7zw 2902dca5a5 Follow the javadoc of the list#remove method. Fix #293 2025-04-17 19:45:29 +02:00
tr7zw 1c1e3c8664 Remove "json" wording, add more warnings/info 2025-04-17 19:41:27 +02:00
tr7zw 7f8f021ced Merge pull request #321 from SoSeDiK/diff
Add a method to extract difference between two compounds
2025-04-17 19:24:21 +02:00
SoSeDiK 98ed1850f6 Add a method to extract difference between two compounds 2025-04-12 16:18:22 +03:00
tr7zw 764e01503d Merge pull request #320 from SoSeDiK/wiki
Update "Reading world data" wiki example
2025-03-31 19:04:27 +02:00
SoSeDiK 43d8e2a351 Update "Reading world data" wiki example 2025-03-31 19:09:42 +03:00
tr7zw 689cd4fa3b Remove unused code path 2025-03-31 18:03:11 +02:00
tr7zw c8f68f8b3b Merge pull request #319 from SoSeDiK/dataversion
Add DataVersion for itemstack conversions
2025-03-28 10:22:12 +01:00
tr7zw e52ba209e6 Fix mistake 2025-03-25 22:50:44 +01:00
tr7zw 418f5bea07 1.21.5 update, needs a lot of testing 2025-03-25 22:42:01 +01:00
SoSeDiK 1392e72a8a Only run items through the data fixer on MC1_20_R4+ 2025-03-22 00:37:57 +02:00
SoSeDiK dc39d1d8ef Add DataVersion for itemstack conversions 2025-03-21 23:13:50 +02:00
tr7zw a974142a55 Merge pull request #316 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.14.0
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.13.0 to 3.14.0
2025-02-23 10:39:14 +00:00
dependabot[bot] f014e71020 Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.13.0 to 3.14.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.13.0...maven-compiler-plugin-3.14.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>
2025-02-21 23:13:30 +00:00
tr7zw da6be72d29 Merge pull request #313 from SoSeDiK/wiki
Update wiki
2024-12-28 19:11:29 +00:00
SoSeDiK d9a93e9306 Add info about paper-plugin.yml 2024-12-28 15:57:04 +02:00
SoSeDiK ba374fe69c Update gradle shadow plugin info 2024-12-28 15:53:01 +02:00
SoSeDiK aa35ee8333 Fixup modifyMeta example 2024-12-28 15:51:28 +02:00
SoSeDiK 3bb0bdd74c Clarify persistent data storage availability 2024-12-28 15:50:49 +02:00
tr7zw f3af749b11 Merge pull request #309 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.5.0
Bump org.codehaus.mojo:license-maven-plugin from 2.4.0 to 2.5.0
2024-12-21 23:44:01 +00:00
tr7zw d81c2b4e8e Merge pull request #311 from FireML/patch-1
Add EvenMoreFish to Plugins.md
2024-12-21 23:43:51 +00:00
tr7zw 94192feb8f Merge pull request #312 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.11.2
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.1 to 3.11.2
2024-12-21 23:43:29 +00:00
tr7zw af3d9c8502 Start 2.14.2-SNAPSHOT 2024-12-22 00:42:03 +01:00
tr7zw ae98859524 Tag 2.14.1 2024-12-16 17:11:16 +01:00
tr7zw 70f0bb62f9 Add Util to get ItemStacks in Json Format for hover components 2024-12-14 21:58:53 +01:00
dependabot[bot] 505e172955 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.1 to 3.11.2
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.11.1 to 3.11.2.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.11.1...maven-javadoc-plugin-3.11.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>
2024-12-09 23:45:07 +00:00
FireML d2b2b6a506 Add EvenMoreFish to Plugins.md, and Update CommandAPI URL 2024-12-08 01:31:10 +00:00
tr7zw e2e8aad70a Merge pull request #310 from ArmyFury/patch-1
Update Plugins.md
2024-12-07 13:17:51 +00:00
ArmyFury 4874366e30 Update Plugins.md
added SummonFriendlyMobs to plugins list
2024-12-07 12:47:39 +05:30
tr7zw d2de90ee25 Add 1.21.4 support 2024-12-03 23:28:21 +01:00
dependabot[bot] a0f93e575e Bump org.codehaus.mojo:license-maven-plugin from 2.4.0 to 2.5.0
Bumps [org.codehaus.mojo:license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.4.0 to 2.5.0.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/2.4.0...2.5.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-29 23:30:47 +00:00
tr7zw b339c9e9c2 Merge pull request #306 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.11.1
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.10.1 to 3.11.1
2024-11-13 23:54:08 +01:00
tr7zw 3425a6672d Merge pull request #308 from SoSeDiK/wiki-changes
Update wiki
2024-11-13 23:53:54 +01:00
tr7zw 67616266da Start snapshots 2.14.1 2024-11-13 23:53:07 +01:00
SoSeDiK b08e4aa12f Update wiki to reflect some 2.14.0 changes
ItemMeta usage clarifications
2024-11-12 14:28:06 +02:00
dependabot[bot] 27411e90da Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.10.1 to 3.11.1
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.10.1 to 3.11.1.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.10.1...maven-javadoc-plugin-3.11.1)

---
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>
2024-11-04 23:48:38 +00:00
tr7zw 73776cfec4 Sneak quick fix into release 2024-11-02 15:18:16 +01:00
tr7zw bd674e31c0 Tag 2.14.0 2024-11-02 15:07:50 +01:00
tr7zw 3405ffe0a3 Fix javadoc deploy 2024-11-02 13:24:22 +01:00
tr7zw f1317bcb04 Fix BlockEntity test. Fix #304 2024-11-02 13:06:19 +01:00
tr7zw 4a32343b95 Add 1.21.3 2024-10-28 18:56:04 +01:00
tr7zw 3de6ed83eb Hide NBTFile/NBTContainer fully behind NBT. Update tests to new format. Add missing addCompound(ReadableNBT comp) to ReadWriteNBTCompoundList 2024-10-22 23:45:16 +02:00
tr7zw e5bdce73ea Merge pull request #300 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.10.1
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.10.0 to 3.10.1
2024-10-22 22:42:25 +02:00
tr7zw 410e88a35b Add getComponents methods 2024-10-22 22:39:35 +02:00
tr7zw e3142b4869 Add 1.21.2 support 2024-10-22 22:24:59 +02:00
tr7zw 243a5c2bcd Fix really stupid edge case of writeCompound 2024-10-22 22:08:04 +02:00
dependabot[bot] 045c710366 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.10.0 to 3.10.1
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.10.0 to 3.10.1.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.10.0...maven-javadoc-plugin-3.10.1)

---
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>
2024-10-01 23:20:24 +00:00
tr7zw 4cd118671f Merge pull request #297 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.10.0
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.8.0 to 3.10.0
2024-08-27 23:03:05 +02:00
dependabot[bot] d86c91f2e6 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.8.0 to 3.10.0
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.8.0 to 3.10.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.8.0...maven-javadoc-plugin-3.10.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>
2024-08-27 16:08:01 +00:00
tr7zw f8736c8188 Also update old items with "Count" tags 2024-08-27 18:07:27 +02:00
tr7zw b3aec54205 Start 2.13.3-SNAPSHOT 2024-08-27 18:06:56 +02:00
tr7zw 0f926998f6 Tag 2.13.2 2024-08-10 20:28:54 +02:00
tr7zw 3a44a5e989 Add 1.21.1 Paper support 2024-08-10 20:21:32 +02:00
tr7zw 30b931945c Merge pull request #288 from SoSeDiK/chunkload
Prevent chunk loading during tile entity tests
2024-08-10 20:20:58 +02:00
tr7zw 88d8629541 Merge pull request #290 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.8.0
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.7.0 to 3.8.0
2024-07-21 20:56:57 +02:00
dependabot[bot] 00ae0448f4 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.7.0 to 3.8.0
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.7.0 to 3.8.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.7.0...maven-javadoc-plugin-3.8.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>
2024-07-21 18:53:26 +00:00
tr7zw ce26e180e6 Merge branch 'master' of https://github.com/tr7zw/Item-NBT-API 2024-07-21 20:51:52 +02:00
tr7zw c939105e45 Start 2.13.2-SNAPSHOT 2024-07-21 20:51:48 +02:00
tr7zw 2079123a42 Merge pull request #287 from SoSeDiK/wiki
Small wiki changes
2024-07-21 20:48:08 +02:00
SoSeDiK 31b17fe9c9 Update wiki
- Fix broken (block-)entities link in sidebar
- Change "(block)-entities" to "entities and block entities" in titles to better reflect title in links
- Move repository above artifact in Maven/Gradle usage
- Add info about preloadApi
- Add title for ItemMeta usage
- Small text changes
2024-07-01 15:53:10 +03:00
SoSeDiK b565902006 Prevent chunk loading during tile entity tests 2024-07-01 15:20:52 +03:00
tr7zw 5280ba82a2 Tag 2.13.1 2024-06-20 22:37:58 +02:00
tr7zw 522f732ed1 Fix wiki and update the datafixer 2024-06-20 22:34:21 +02:00
tr7zw ac84a4d69a Fix another dead link 2024-06-20 22:20:04 +02:00
tr7zw d7e18c1cb6 Fix dead link 2024-06-20 22:18:41 +02:00
tr7zw ffa612634a Merge pull request #282 from SoSeDiK/wiki
Update wiki
2024-06-20 22:13:01 +02:00
tr7zw 739682122b Remove the usage of the word "tile" entity 2024-06-20 22:07:38 +02:00
tr7zw 2e20af40e5 Add NBT.preloadApi 2024-06-20 21:39:39 +02:00
SoSeDiK e6527515be Update Maven/Gradle usage 2024-06-17 01:05:07 +03:00
SoSeDiK e6f33a35ae Small clarifications/grammar 2024-06-17 01:05:07 +03:00
SoSeDiK 39801ada18 Update saving entity nbt example 2024-06-17 01:05:07 +03:00
SoSeDiK 75fab7622a Update examples 2024-06-17 01:05:07 +03:00
tr7zw 33eef1bcf1 Update FAQ.md 2024-06-17 01:05:07 +03:00
SoSeDiK 877a42fd06 Even more TODOs 2024-06-17 01:05:07 +03:00
SoSeDiK 0a7e560e2e Fill out some TODOs 2024-06-17 01:05:07 +03:00
SoSeDiK 174728a681 mvn spottless:apply 2024-06-17 01:05:07 +03:00
SoSeDiK 79ba1dd275 [WIP] Started updating wiki 2024-06-17 01:05:07 +03:00
tr7zw 25c59b0eae Fix build 2024-06-16 22:51:48 +02:00
tr7zw 0057d3f2e8 Remove nbtinjector/dataapi from the build 2024-06-16 00:35:20 +02:00
tr7zw 59c67a3f0b Remove unused code/private some methods/classes 2024-06-16 00:31:36 +02:00
tr7zw 3ec606ae21 Disable old method mappings 2024-06-15 23:39:40 +02:00
tr7zw ff0a94f279 Add nullable flag 2024-06-15 23:27:41 +02:00
tr7zw 53216d3b7d Overwrite resolveCompound to be ReadWriteNBT 2024-06-15 23:06:38 +02:00
tr7zw 7cf23201ce Hotfix Paper 1.21 2024-06-14 21:30:01 +02:00
tr7zw fe1d586f44 Start 2.13.1 snapshots 2024-06-14 12:33:35 +02:00
tr7zw 956ef15a1d Bump version 2024-06-13 21:15:01 +02:00
tr7zw ed867749f8 Delete data api/injector logic 2024-06-13 20:56:49 +02:00
tr7zw 88fbc0140e Remove nbt-injector and nbt-data-api 2024-06-13 20:48:36 +02:00
tr7zw 82e52267b8 More deprecation, use the NBT class 2024-06-13 20:27:23 +02:00
tr7zw c16548ff4e New "modifyComponents" api 2024-06-13 20:26:39 +02:00
tr7zw cf30cf996e Update to 1.21 2024-06-13 19:56:59 +02:00
tr7zw 633433d6d0 Merge pull request #278 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.6.0
Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.3 to 3.6.0
2024-06-08 21:02:14 +02:00
tr7zw 153c72818a Merge pull request #279 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.7.0
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.3 to 3.7.0
2024-06-08 21:02:06 +02:00
dependabot[bot] 4798880a53 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.3 to 3.7.0
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.7.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.7.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>
2024-05-31 23:20:47 +00:00
dependabot[bot] 1f149dbae4 Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.3 to 3.6.0
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.3 to 3.6.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.3...maven-shade-plugin-3.6.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>
2024-05-31 23:20:38 +00:00
tr7zw 8570c6f77e Improve error when trying to get NBT from non BlockEntity BlockStates. Fix #276 2024-05-19 01:07:24 +02:00
tr7zw 30f75e0714 Deprecate usage of NBTItem/NBTEntity/NBTTileEntity 2024-05-19 00:55:15 +02:00
tr7zw af7a6b0a1c Start 2.12.5-SNAPSHOT 2024-05-19 00:47:46 +02:00
tr7zw c0a9197113 Tag 2.12.4 2024-04-30 15:27:10 +02:00
tr7zw e14dd4f82a Add 1.20.6 2024-04-30 00:13:20 +02:00
tr7zw 198dbfabae Fix wiki page 2024-04-29 19:46:11 +02:00
tr7zw 8bd49db49b Fix incorrect MojangMapping, breaking on mojmapped servers like paper 1.20.5 2024-04-28 19:30:10 +02:00
tr7zw caf1d7cd98 Add utility method to get the current versions DataFixer id 2024-04-25 18:57:12 +02:00
tr7zw 027f2a2edd Add more version ids, test loading 1.12.2 items in 1.20.5 2024-04-25 18:39:40 +02:00
tr7zw b74b0b852e Pull down the 1.20.4 id 2024-04-25 18:04:39 +02:00
tr7zw 6ea6ab7e13 Bump the datafixer id to the actual 1.20.5 id 2024-04-25 18:03:59 +02:00
tr7zw 372225626c Use an older datafixerupper for compiling 2024-04-24 16:04:03 +02:00
tr7zw 2483f9b947 Add Datafixer. Auto update 1.20.4 items to 1.20.5 2024-04-24 15:59:20 +02:00
tr7zw fdc16aad69 Fix issues on older versions 2024-04-24 01:47:21 +02:00
tr7zw c723eef68b Merge pull request #277 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.5.3
Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.2 to 3.5.3
2024-04-24 01:41:02 +02:00
tr7zw 03299012ac Fix BlockEntities for 1.20.5 2024-04-24 01:40:33 +02:00
dependabot[bot] eabf0a9696 Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.2 to 3.5.3
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.2 to 3.5.3.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.2...maven-shade-plugin-3.5.3)

---
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>
2024-04-23 23:17:03 +00:00
tr7zw 9367942b54 Re-implement gameprofile methods for 1.20.5+ 2024-04-24 00:08:48 +02:00
tr7zw 167487e6ab Deprecate/disable more stuff not applying to 1.20.5 2024-04-23 23:47:49 +02:00
tr7zw 6395dd1964 Disable invalid tests for 1.20.5+ 2024-04-23 23:04:15 +02:00
tr7zw d3ef690f2e Fix version mapping 2024-04-23 22:56:44 +02:00
tr7zw 012f32dca9 Start update to 1.20.5 2024-04-23 22:55:50 +02:00
tr7zw 0b8d5b153c Merge pull request #273 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.3.1
Bump org.apache.maven.plugins:maven-source-plugin from 3.3.0 to 3.3.1
2024-04-06 18:54:51 +02:00
tr7zw 246e3fa38e Start 2.12.4-SNAPSHOT 2024-04-06 18:54:26 +02:00
dependabot[bot] 19777de6d4 Bump org.apache.maven.plugins:maven-source-plugin from 3.3.0 to 3.3.1
Bumps [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.3.0 to 3.3.1.
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.3.0...maven-source-plugin-3.3.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-04 23:45:13 +00:00
tr7zw 3afd9df2ae Tag 2.12.3 2024-03-24 17:27:30 +01:00
tr7zw 2cb16ed0c4 Merge pull request #270 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.13.0
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.12.1 to 3.13.0
2024-03-21 21:38:09 +01:00
dependabot[bot] ac64acf271 Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.12.1 to 3.13.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.12.1...maven-compiler-plugin-3.13.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>
2024-03-18 23:52:09 +00:00
tr7zw 85cc13a817 Update wiki code 2024-03-18 19:45:36 +01:00
tr7zw 75c8575b5b Merge pull request #267 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.5.2
Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.1 to 3.5.2
2024-02-22 19:56:42 +01:00
dependabot[bot] 67557d5f94 Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.1 to 3.5.2
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.1 to 3.5.2.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.1...maven-shade-plugin-3.5.2)

---
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>
2024-02-20 23:24:58 +00:00
tr7zw 330fb7711c Turns out Map.of is Java 9... 2024-02-13 00:22:48 +01:00
tr7zw e7f48c72bd Add marker that paper doesn't need to remap the nbtapi 2024-02-12 17:48:59 +01:00
tr7zw 3eefb1d315 Add support for un-remapped Paper 1.20+ 2024-02-12 16:55:16 +01:00
tr7zw a37a2c6729 Merge pull request #265 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.4.0
Bump org.codehaus.mojo:license-maven-plugin from 2.3.0 to 2.4.0
2024-01-24 00:43:02 +01:00
dependabot[bot] e42fad0761 Bump org.codehaus.mojo:license-maven-plugin from 2.3.0 to 2.4.0
Bumps [org.codehaus.mojo:license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.3.0 to 2.4.0.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/2.3.0...2.4.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-23 23:42:13 +00:00
tr7zw eee2dfa181 Merge pull request #264 from SmartGecko44/master
Update LICENSE copyright to 2024
2024-01-01 16:10:25 +01:00
Gecko! 4728449294 Update LICENSE copyright to 2024 2024-01-01 15:07:02 +01:00
tr7zw ccd78d1b00 Merge pull request #263 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.12.1
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.12.0 to 3.12.1
2023-12-27 22:17:53 +01:00
dependabot[bot] 83bea69710 Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.12.0 to 3.12.1.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.12.0...maven-compiler-plugin-3.12.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-25 23:36:12 +00:00
tr7zw 87fd1ee8ee Merge pull request #261 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.12.0
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.11.0 to 3.12.0
2023-12-19 19:50:31 +01:00
tr7zw af0528328f Start 2.12.3-SNAPSHOT 2023-12-19 19:50:04 +01:00
dependabot[bot] 86c802e2db Bump org.apache.maven.plugins:maven-compiler-plugin
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>
2023-12-18 23:26:00 +00:00
tr7zw 7bf91d0510 2.12.2 release 2023-12-10 14:27:42 +01:00
tr7zw aed5af12a2 Add 1.20.4 support 2023-12-08 21:41:03 +01:00
tr7zw dd6e9e8312 Merge pull request #258 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.6.3
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.2 to 3.6.3
2023-12-05 16:23:22 +01:00
dependabot[bot] 42871b6c06 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.2 to 3.6.3
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>
2023-12-04 23:53:19 +00:00
tr7zw 4ad7a172a0 Merge pull request #256 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.6.2
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.0 to 3.6.2
2023-11-11 17:26:34 +01:00
tr7zw 6f112c0130 Start 2.12.2-SNAPSHOT 2023-11-11 17:26:02 +01:00
dependabot[bot] 5a948f017a Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.0 to 3.6.2
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>
2023-11-06 23:25:24 +00:00
tr7zw f5a1b21761 Tag 2.12.1 2023-11-04 17:49:07 +01:00
tr7zw 4af722752e Use the correct mappings for 1.19.4. Fix #254 2023-11-03 21:21:47 +01:00
tr7zw af3b7a49d0 Fix Version Id of 1.20R2 2023-10-26 21:11:57 +02:00
tr7zw 189ff2f369 Merge pull request #253 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.3.0
Bump org.codehaus.mojo:license-maven-plugin from 2.2.0 to 2.3.0
2023-10-25 01:04:49 +02:00
dependabot[bot] ddf8ab3c9b Bump org.codehaus.mojo:license-maven-plugin from 2.2.0 to 2.3.0
Bumps [org.codehaus.mojo:license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.2.0 to 2.3.0.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/2.2.0...2.3.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-24 23:03:14 +00:00
tr7zw a8a81eee83 Merge pull request #250 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.5.1
Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.0 to 3.5.1
2023-10-22 17:44:19 +02:00
tr7zw fb384784f0 Start 2.12.1 snapshots 2023-10-22 17:43:27 +02:00
dependabot[bot] 256abbc500 Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.0 to 3.5.1
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>
2023-09-25 23:45:49 +00:00
tr7zw dc333ae25a Release 2.12.0 2023-09-21 23:20:21 +02:00
tr7zw d18adb459d Try to disable jitpack 2023-09-21 23:00:13 +02:00
tr7zw bc914b73bc oops, remove debug code 2023-09-21 20:50:01 +02:00
tr7zw 60172ea2a7 Correct copy paste fail 2023-09-21 20:24:39 +02:00
tr7zw 7b30c1533e Add 1.20.2 support 2023-09-21 20:16:11 +02:00
tr7zw a1c90658f3 Merge pull request #248 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.6.0
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.5.0 to 3.6.0
2023-09-19 22:26:41 +02:00
dependabot[bot] 0b0fdeaa60 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.5.0 to 3.6.0
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>
2023-09-15 23:09:02 +00:00
tr7zw d989797453 Add support for ProxyLists 2023-09-15 01:15:11 +02:00
tr7zw c70aefe670 Allow using "[123]" and "[-1]" to navigate lists/arrays for resolve methods
Also god, some of this code needs heavy refactoring
2023-09-14 23:56:45 +02:00
tr7zw 7d0fc09470 Fix formatting 2023-09-13 18:54:02 +02:00
tr7zw 427113e6f0 Add YourKit 2023-09-13 18:50:33 +02:00
tr7zw 20ae1cb178 Document inconsistency of hasNBTData() 2023-09-13 00:20:53 +02:00
tr7zw 83b011fafa Allow passing null into NBTContainer 2023-09-13 00:03:44 +02:00
tr7zw 3affeee151 Remove dead code, simplify remove handling for empty items 2023-09-13 00:01:09 +02:00
tr7zw 06da2114ad Fix getKeys with empty ItemsStacks 2023-09-12 23:52:31 +02:00
tr7zw a3efdc622b Return to snapshots to fix issues with items without nbt 2023-09-12 23:45:59 +02:00
tr7zw 9b60978af6 Tag 2.12.0-RC1 2023-09-08 20:06:14 +02:00
tr7zw 598db19d8d Merge pull request #244 from tr7zw/proxyPrototype
Add Proxy system (Preview)
2023-09-08 19:32:05 +02:00
tr7zw 7a914d00e7 Merge branch 'master' into proxyPrototype 2023-09-08 19:12:34 +02:00
tr7zw 7141c56319 Merge pull request #243 from SoSeDiK/fixes
Fix Folia detection and NBT#modify for tile entities
2023-09-04 13:00:42 +02:00
SoSeDiK 992d9717ec Fix NBT#modify fot tile entities 2023-09-04 13:40:13 +03:00
SoSeDiK c5c2652d42 Fix Folia detection 2023-09-04 13:39:51 +03:00
SoSeDiK fb8e2272b3 Some javadoc grammar corrections 2023-09-04 13:33:14 +03:00
tr7zw 120d087edc Add "has" support 2023-08-11 18:52:40 +02:00
tr7zw 12c98d7d94 Make the casing changable 2023-08-11 18:45:50 +02:00
tr7zw 51d06817bc Merge branch 'master' into proxyPrototype 2023-08-11 18:18:17 +02:00
tr7zw 3bb4d7b449 Remove all-contributors since no one ever pr'd to it. Enable spotless for markdown files 2023-08-11 01:07:02 +02:00
tr7zw f562994d18 Update to bStats 3.0.2. Fix #230 2023-08-11 01:02:43 +02:00
tr7zw f86d234c9c Update NBTItemMeta.java 2023-08-10 22:27:58 +02:00
tr7zw cb8e24428b Fix 2023-08-10 22:12:25 +02:00
tr7zw 30bd0bcbaf Add hasCustomModelData 2023-08-10 21:40:52 +02:00
tr7zw bb4d3bb9b0 Add test 2023-08-10 21:19:21 +02:00
tr7zw 523ce8cf60 Start adding an NBTItemMeta wrapper. Add NBT Handlers 2023-08-09 18:01:12 +02:00
tr7zw d3d7a3138c Thanks, merge conflict 2023-08-08 20:11:10 +02:00
tr7zw e71bf88d12 Make a readonly view during meta modification 2023-08-08 20:07:41 +02:00
tr7zw 1ba6fc8706 Fix formatting 2023-08-06 19:40:43 +02:00
tr7zw a341034de0 Add a generic get/set method for NBTHandlers 2023-08-06 19:36:43 +02:00
tr7zw b45b25c255 Add the NBT methods to use Proxies 2023-08-06 19:23:36 +02:00
tr7zw c7eaa51bdb Merge branch 'master' into proxyPrototype 2023-08-06 17:50:12 +02:00
tr7zw 6b1d4e28ed Update NBTModifyItemTest.java 2023-08-06 16:15:51 +02:00
tr7zw 4341cb33ea Merge branch 'master' into proxyPrototype 2023-08-06 16:03:27 +02:00
tr7zw bde0bf7c8d Fix build 2023-08-06 16:03:20 +02:00
tr7zw 55ab9a2918 Merge branch 'master' into proxyPrototype 2023-08-06 15:57:29 +02:00
tr7zw 7f4d134bd0 Add getters with Consumers, so no return is required 2023-08-06 15:55:50 +02:00
tr7zw 6e8b8f3565 Add NBT.readNbt, fix resolveOrDefault 2023-08-06 00:06:47 +02:00
tr7zw a009b521c0 Remove static 2023-08-05 23:48:12 +02:00
tr7zw 54d0db8189 Handler prototype 2023-08-05 23:06:00 +02:00
tr7zw 66ffcf2866 Merge branch 'master' into proxyPrototype 2023-08-05 22:08:15 +02:00
tr7zw d653bc67d8 Fix typo 2023-08-04 21:01:11 +02:00
tr7zw 533765ba74 Add more readonly Validation 2023-08-03 00:49:11 +02:00
tr7zw 0232f720cb Close NBTItems/Entity/BlockEntity after the NBT context, to prevent people leaking objects 2023-08-03 00:29:22 +02:00
tr7zw 205ca93977 Catch attempts trying to smuggle NBT to outside the scope 2023-08-02 23:36:54 +02:00
tr7zw fa62c9825d Fix 2023-08-02 22:42:18 +02:00
tr7zw 5051bc834d Add more sanity checks 2023-08-02 22:33:42 +02:00
tr7zw 10ea4b1767 Don't merge empty tags 2023-08-02 22:24:00 +02:00
tr7zw b801b46bce Set Items nbt tag to null when empty, Add ReadableItemNBT with hasNBTData, add tests 2023-08-02 19:33:09 +02:00
tr7zw fc94dac05b Fix nbt getting lost when modifying meta first, add test, quick return setCompound for finalizer 2023-07-28 17:25:52 +02:00
tr7zw 1ab5f70c88 Merge pull request #242 from U5B/usb-wiki-plugins
add honorable plugin list mentions
2023-07-26 15:35:43 +02:00
usb af6a11d649 add honorable plugin list mentions 2023-07-26 05:53:33 -07:00
tr7zw c90636970a Add and enforce nullable annotations on some interfaces 2023-07-26 00:18:11 +02:00
tr7zw f3b1cc27e7 Add new resolve methods 2023-07-25 23:13:40 +02:00
tr7zw 33eddbaece Further cache during readonly mode 2023-07-25 21:16:45 +02:00
tr7zw 20f9b2f1ce Cache the tag in readOnly mode 2023-07-24 02:59:02 +02:00
tr7zw e8c24c6bc5 Skip making a copy for nms itemstacks during modifications 2023-07-24 02:53:37 +02:00
tr7zw affad0d92c Optimize NBT.modify calls for items 2023-07-24 00:07:08 +02:00
tr7zw ba169438ba Fix NBTFile.saveTo, Boolean -> boolean 2023-07-17 19:53:11 +02:00
tr7zw c2e23af84f Allow sub proxies 2023-07-06 19:40:22 +02:00
tr7zw 9ff2e38d07 Merge pull request #238 from BlackBaroness/patch-1
Fix minor English mistakes in documentation
2023-07-06 00:28:23 +02:00
BlackBaroness 5b12aa70e7 Update Set-a-skull's-skin-using-NBT-API.md 2023-07-06 01:23:14 +03:00
BlackBaroness 5424282fe6 Update Set-a-skull's-skin-using-NBT-API.md 2023-07-06 01:19:52 +03:00
tr7zw 8b76359143 Merge pull request #237 from BlackBaroness/patch-1
Update "set skull skin" documentation
2023-07-06 00:19:19 +02:00
BlackBaroness 2c6d54b32c Update "set skull skin" documentation 2023-07-06 01:15:47 +03:00
tr7zw a341c6a81e Update sonar badges 2023-07-05 00:41:52 +02:00
tr7zw 23b9f9128f Only mention Gson if something went wrong 2023-07-05 00:19:01 +02:00
tr7zw 81c3b75dc9 Add Folia support. Fix #225 2023-07-05 00:16:09 +02:00
tr7zw d3b1d00e15 Missing ! 2023-07-05 00:06:38 +02:00
tr7zw 177d1fe5b7 Update javadoc 2023-07-04 23:34:33 +02:00
tr7zw f1682205d8 Remove functional-annotations, add version checks 2023-07-04 23:19:22 +02:00
tr7zw ced5b15023 Add long[] to the proxy builder 2023-07-04 23:08:27 +02:00
tr7zw f6a150d5be Merge branch 'master' into proxyPrototype 2023-07-04 23:06:00 +02:00
tr7zw 1bfdb93622 Merge pull request #236 from tr7zw/readOnlyOptimization
Read only optimization
2023-07-04 23:05:06 +02:00
tr7zw 09af2df542 Merge pull request #235 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.2.0
Bump license-maven-plugin from 2.1.0 to 2.2.0
2023-07-04 23:04:39 +02:00
tr7zw cd1bdc0436 Add Mojmaped jar support 2023-07-04 22:55:29 +02:00
tr7zw b2ea170f9e Add long array support. Fix #219 2023-07-04 22:02:07 +02:00
dependabot[bot] 769ba78aa1 Bump license-maven-plugin from 2.1.0 to 2.2.0
Bumps [license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.1.0 to 2.2.0.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/2.1.0...2.2.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-03 23:46:55 +00:00
tr7zw 0228b68a7c Change NBT.modify calls on (Block-)Entities to be atomic 2023-07-03 23:47:43 +02:00
tr7zw 2a80e8ff63 Add readonly modes for Entity/TileEntity 2023-07-02 20:48:53 +02:00
tr7zw 9bdd79ef7d Add a different error for people accidentally shading the plugin 2023-06-27 14:41:40 +02:00
tr7zw 55893bac8a Add nbtapi version to error messages 2023-06-27 14:27:08 +02:00
tr7zw bfe627658e Make a note that it's 2 different artifacts, add example 2023-06-21 14:10:53 +02:00
tr7zw a929bd2ddc Merge pull request #232 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.5.0
Bump maven-shade-plugin from 3.4.1 to 3.5.0
2023-06-17 01:58:14 +02:00
dependabot[bot] 3a966e0478 Bump maven-shade-plugin from 3.4.1 to 3.5.0
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>
2023-06-16 23:57:38 +00:00
tr7zw 62105ead48 Merge pull request #229 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.1.0
Bump license-maven-plugin from 2.0.1 to 2.1.0
2023-06-15 16:51:56 +02:00
tr7zw cfd04fffa6 Format 2023-06-12 18:21:35 +02:00
tr7zw c8231eb050 Testing readOnly mode for NBT.get(ItemStack) 2023-06-12 18:17:37 +02:00
tr7zw f7bceec594 Start 2.12.0-SNAPSHOT 2023-06-12 18:02:11 +02:00
tr7zw c377927ee6 Tag 2.11.3 2023-06-07 20:20:15 +02:00
tr7zw 0653f47bc1 Add 1.20 support 2023-06-07 20:14:05 +02:00
dependabot[bot] 84e096d8b4 Bump license-maven-plugin from 2.0.1 to 2.1.0
Bumps [license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.0.1 to 2.1.0.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/2.0.1...2.1.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-06 23:57:51 +00:00
tr7zw 8bc066872c Allow annotations to customize the interface methods 2023-05-29 21:32:12 +02:00
tr7zw 4491f6780a Spotless 2023-05-28 23:15:56 +02:00
tr7zw af19868289 Add support for default methods 2023-05-28 23:06:24 +02:00
tr7zw 5588fc60b4 Merge pull request #227 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.3.0
Bump maven-source-plugin from 3.2.1 to 3.3.0
2023-05-23 10:08:50 +02:00
dependabot[bot] 7c27630c10 Bump maven-source-plugin from 3.2.1 to 3.3.0
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>
2023-05-22 23:58:27 +00:00
tr7zw 4c538aad7b Innitial test, prototyping proxies 2023-05-20 21:33:36 +02:00
tr7zw 45dd70afad Merge pull request #224 from tom-devv/typo
Fix a small typo in nbt-injector
2023-05-10 21:50:05 +02:00
tom-devv 280ce7a50d Fix typo 2023-05-10 20:40:00 +01:00
tr7zw 175065dac4 Try to use the actual plugin name for issues.
Add a warning for using "de.tr7zw.nbtapi" as relocation target in other plugins.
Fix #206
2023-05-08 00:14:48 +02:00
tr7zw f4bfca8ba8 Disable the update check by default for shaded versions 2023-05-07 20:14:17 +02:00
tr7zw 37378b4ee1 Merge pull request #221 from tr7zw/dependabot/maven/org.codehaus.mojo-license-maven-plugin-2.0.1
Bump license-maven-plugin from 2.0.0 to 2.0.1
2023-05-06 16:16:23 +02:00
tr7zw 662c0bb92d Merge pull request #223 from SoSeDiK/tagcheck
Allow checking nbt type alongside the key
2023-05-06 16:15:57 +02:00
SoSeDiK c485f8c967 Allow checking nbt type alongside the key 2023-05-06 17:01:23 +03:00
tr7zw 5759b68d89 Merge pull request #222 from SoSeDiK/bool
Add support for boolean in getOrDefault/getOrNull
2023-05-06 15:50:28 +02:00
tr7zw c22cbaaaf0 Start next snapshot 2023-05-06 15:49:40 +02:00
SoSeDiK 4a0e1b5557 Add support for boolean in getOrDefault/getOrNull 2023-05-06 16:48:45 +03:00
dependabot[bot] 1c2e61875e Bump license-maven-plugin from 2.0.0 to 2.0.1
Bumps [license-maven-plugin](https://github.com/mojohaus/license-maven-plugin) from 2.0.0 to 2.0.1.
- [Release notes](https://github.com/mojohaus/license-maven-plugin/releases)
- [Commits](https://github.com/mojohaus/license-maven-plugin/compare/license-maven-plugin-2.0.0...2.0.1)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:license-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-05 23:57:37 +00:00
tr7zw 6f25881eda Add 1.19.4 as supported version. 2.11.2 2023-03-16 19:15:55 +01:00
tr7zw bd69504f54 Merge pull request #216 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.11.0
Bump maven-compiler-plugin from 3.10.1 to 3.11.0
2023-03-09 21:08:23 +01:00
dependabot[bot] 85d7224fdd Bump maven-compiler-plugin from 3.10.1 to 3.11.0
Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.10.1 to 3.11.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.10.1...maven-compiler-plugin-3.11.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>
2023-02-28 00:00:07 +00:00
tr7zw 8dc51a3d30 Merge pull request #214 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.5.0
Bump maven-javadoc-plugin from 3.4.1 to 3.5.0
2023-02-16 10:03:07 +01:00
dependabot[bot] 8a440889b0 Bump maven-javadoc-plugin from 3.4.1 to 3.5.0
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.4.1 to 3.5.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.4.1...maven-javadoc-plugin-3.5.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>
2023-02-15 23:57:59 +00:00
tr7zw 4a93fdc869 Fix issue with ReadWriteNBT returning ReadableNBT 2023-02-15 22:06:17 +01:00
tr7zw c905de852d Merge pull request #210 from tr7zw/revert-209-dependabot/maven/com.diffplug.spotless-spotless-maven-plugin-2.31.0
Revert "Bump spotless-maven-plugin from 2.30.0 to 2.31.0"
2023-01-31 12:16:37 +01:00
tr7zw fd7da1e3fb Revert "Bump spotless-maven-plugin from 2.30.0 to 2.31.0" 2023-01-31 12:03:09 +01:00
tr7zw 1123e27b10 Merge pull request #209 from tr7zw/dependabot/maven/com.diffplug.spotless-spotless-maven-plugin-2.31.0
Bump spotless-maven-plugin from 2.30.0 to 2.31.0
2023-01-31 11:42:42 +01:00
dependabot[bot] a97ed32097 Bump spotless-maven-plugin from 2.30.0 to 2.31.0
Bumps [spotless-maven-plugin](https://github.com/diffplug/spotless) from 2.30.0 to 2.31.0.
- [Release notes](https://github.com/diffplug/spotless/releases)
- [Changelog](https://github.com/diffplug/spotless/blob/main/CHANGES.md)
- [Commits](https://github.com/diffplug/spotless/compare/lib/2.30.0...lib/2.31.0)

---
updated-dependencies:
- dependency-name: com.diffplug.spotless:spotless-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-26 23:01:52 +00:00
tr7zw 05b4249bb4 Merge pull request #207 from tr7zw/dependabot/maven/com.diffplug.spotless-spotless-maven-plugin-2.30.0
Bump spotless-maven-plugin from 2.29.0 to 2.30.0
2023-01-25 20:33:17 +01:00
tr7zw e399590d1d Bump for 2.11.2-SNAPSHOT 2023-01-25 20:32:30 +01:00
tr7zw 310682ea25 Merge pull request #208 from FREE2WIN2/master
Fix Wiki repository url for maven and gradle.
2023-01-24 11:02:17 +01:00
FREE2WIN2 6b70966926 Wiki: Fix repository url of codemc repo 2023-01-20 23:03:47 +01:00
FREE2WIN2 79275c0c19 Wiki: Fix repository url of codemc repo 2023-01-20 23:03:03 +01:00
dependabot[bot] 2b21ef46bb Bump spotless-maven-plugin from 2.29.0 to 2.30.0
Bumps [spotless-maven-plugin](https://github.com/diffplug/spotless) from 2.29.0 to 2.30.0.
- [Release notes](https://github.com/diffplug/spotless/releases)
- [Changelog](https://github.com/diffplug/spotless/blob/main/CHANGES.md)
- [Commits](https://github.com/diffplug/spotless/compare/lib/2.29.0...lib/2.30.0)

---
updated-dependencies:
- dependency-name: com.diffplug.spotless:spotless-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-16 23:03:41 +00:00
tr7zw 79e1e62862 Merge pull request #205 from tr7zw/dependabot/maven/com.diffplug.spotless-spotless-maven-plugin-2.29.0
Bump spotless-maven-plugin from 2.28.0 to 2.29.0
2023-01-03 23:51:49 +01:00
dependabot[bot] 852ddf4a22 Bump spotless-maven-plugin from 2.28.0 to 2.29.0
Bumps [spotless-maven-plugin](https://github.com/diffplug/spotless) from 2.28.0 to 2.29.0.
- [Release notes](https://github.com/diffplug/spotless/releases)
- [Changelog](https://github.com/diffplug/spotless/blob/main/CHANGES.md)
- [Commits](https://github.com/diffplug/spotless/compare/lib/2.28.0...lib/2.29.0)

---
updated-dependencies:
- dependency-name: com.diffplug.spotless:spotless-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-02 23:03:22 +00:00
tr7zw f648aca74b Release 2.11.1 2022-12-14 17:08:29 +01:00
tr7zw 9e79a604d3 Merge branch 'pr/204' 2022-12-14 16:56:44 +01:00
tr7zw 13c3f861c3 Add test for the failing code 2022-12-14 16:56:14 +01:00
tr7zw 25aa64a895 Start 2.11.1-SNAPSHOT 2022-12-14 16:47:44 +01:00
Kevin_OVI cc61fc1e6e Fix StackOverflowError when merging ReadableNBT
Fix StackOverflowError by casting the ReadableNBT object to a NBTCompound
2022-12-14 16:09:17 +01:00
tr7zw 54d9ac614e Bump to 2.11.0 2022-12-11 19:49:39 +01:00
tr7zw 306812264f Merge pull request #203 from tr7zw/last-minute-interface-refactor
Last minute interface refactor
2022-12-11 00:04:53 +01:00
tr7zw af616831bf Spotless 2022-12-10 23:53:11 +01:00
tr7zw fb4757c0a3 Add missing ReadWriteItemNBT class. Update wiki 2022-12-10 23:50:22 +01:00
tr7zw ddd96453f0 Add mostly AI generated javadoc
Too timeconstrained to write new ``int size();`` javadoc
2022-12-08 19:58:43 +01:00
tr7zw dd17fb4d83 Janky javac logic with removeIf 2022-12-08 18:33:51 +01:00
tr7zw 465ae73fe6 Add removeIf to lists. Extend NBT methods. 2022-12-08 18:18:40 +01:00
tr7zw 63dbf69c02 Update ReadableNBTList.java 2022-12-08 17:07:06 +01:00
tr7zw fffa9118d1 Add missing subList method 2022-12-08 17:03:59 +01:00
tr7zw e4a8a39473 Create experimental new interfaces for the NBT class
Has some potentially breaking changes about Lists and especially CompoundLists(I don't think any plugin would use that? But can't say for sure). Might need to be fully reverted in case it causes to many issues.
2022-12-08 00:14:36 +01:00
tr7zw 38c42ed577 Add 1.19.3 support 2022-12-07 21:48:57 +01:00
tr7zw 3c20b5db32 Merge pull request #202 from SoSeDiK/npe
Fix NPE hiding the actual error when passing null object
2022-12-01 20:01:36 +01:00
SoSeDiK de62c840d3 Fix NPE hiding the actual error when passing null object 2022-12-01 11:43:31 +02:00
tr7zw f10ba986ba Merge pull request #201 from tr7zw/dependabot/maven/com.diffplug.spotless-spotless-maven-plugin-2.28.0
Bump spotless-maven-plugin from 2.27.2 to 2.28.0
2022-11-25 23:55:10 +01:00
dependabot[bot] b28bac5919 Bump spotless-maven-plugin from 2.27.2 to 2.28.0
Bumps [spotless-maven-plugin](https://github.com/diffplug/spotless) from 2.27.2 to 2.28.0.
- [Release notes](https://github.com/diffplug/spotless/releases)
- [Changelog](https://github.com/diffplug/spotless/blob/main/CHANGES.md)
- [Commits](https://github.com/diffplug/spotless/compare/maven/2.27.2...lib/2.28.0)

---
updated-dependencies:
- dependency-name: com.diffplug.spotless:spotless-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-24 23:02:22 +00:00
tr7zw c5c96e6d17 Update FUNDING.yml 2022-11-24 18:59:51 +00:00
tr7zw 22ded53d31 Merge pull request #200 from steveb05/gradle-wiki
Update gradle wiki with shading support
2022-11-24 19:58:18 +01:00
steve 39160df3ec Update gradle wiki with shading support 2022-11-23 14:38:03 +01:00
tr7zw 49fd713c63 Endings 2022-11-10 23:44:10 +01:00
tr7zw 58f2fda332 .gitattributes lf 2022-11-10 23:39:10 +01:00
tr7zw c06f8f8145 Update formatter.xml 2022-11-10 23:14:48 +01:00
tr7zw 45504d09f0 Enforce Java Conventions formatting 2022-11-10 23:06:40 +01:00
tr7zw 88fb62677d Merge pull request #199 from tr7zw/mergeapi
Use modified mavan javadoc plugin to include javadoc
2022-11-10 19:29:21 +01:00
tr7zw 07d0f4dbd2 Update pom.xml 2022-11-10 19:29:01 +01:00
tr7zw e4c7344095 Use modified mavan javadoc plugin to include javadoc 2022-11-10 19:22:22 +01:00
tr7zw 9aad17aa0d Merge pull request #198 from SoSeDiK/uuid
Catch IllegalArgumentException for getUUID
2022-11-10 17:28:22 +01:00
SoSeDiK 5a4fdc2752 Catch IllegalArgumentException for getUUID 2022-11-10 18:22:13 +02:00
tr7zw fc2c944bb7 Merge pull request #197 from SoSeDiK/pages
Deploy all javadocs at once
2022-11-10 17:15:56 +01:00
SoSeDiK a49025cc17 Deploy all javadocs at once 2022-11-10 18:07:15 +02:00
tr7zw c6f8f4163a Merge pull request #196 from SoSeDiK/actions
Update workflows
2022-11-10 16:12:05 +01:00
SoSeDiK 54c1c17d07 Do not run wiki & javadoc deploy workflows if on fork 2022-11-10 04:47:46 +02:00
SoSeDiK 31ddc33667 Fix wiki fail if no changes 2022-11-10 04:47:46 +02:00
SoSeDiK 4588724ca8 Update actions 2022-11-10 04:47:46 +02:00
tr7zw 793540f282 Merge pull request #195 from tr7zw/enumApi
Add Enum methods
2022-11-09 20:27:48 +01:00
tr7zw 9927bfb845 Fix getOrDefault for UUID 2022-11-09 20:16:08 +01:00
tr7zw d83b777862 Fix getOrDefault, don't pass on IllegalArgumentException for invalid enums 2022-11-09 19:35:54 +01:00
tr7zw 6f9ea15c9f Add Enum methods 2022-11-09 18:45:57 +01:00
tr7zw d30f984376 Add some javadoc to NBTBlock 2022-11-07 01:54:41 +01:00
tr7zw 3a987af139 Also check the size of itemstacks. 2022-11-07 01:34:07 +01:00
tr7zw 783d4548ab Merge pull request #194 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.4.1
Bump maven-shade-plugin from 3.4.0 to 3.4.1
2022-10-28 01:34:53 +02:00
dependabot[bot] f23a1ca325 Bump maven-shade-plugin from 3.4.0 to 3.4.1
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.0 to 3.4.1.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.0...maven-shade-plugin-3.4.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>
2022-10-27 23:25:27 +00:00
tr7zw 766d57a085 Merge pull request #193 from SoSeDiK/fix
Fix #convertNBTtoItemArray for empty (full of nulls/AIRs) arrays
2022-10-11 20:14:33 +02:00
SoSeDiK f74f6545a7 Fix #convertNBTtoItemArray for empty arrays 2022-10-11 21:11:39 +03:00
SoSeDiK b74c8f524f Properly ignore .idea folder 2022-10-11 21:02:11 +03:00
tr7zw bf65c7ce68 Update wiki.yml 2022-10-03 02:22:48 +02:00
tr7zw 42f4af52bc Try to move the wiki into the repo 2022-10-03 02:22:02 +02:00
tr7zw 8e8285b36d Add modifyMeta method 2022-09-27 22:21:36 +02:00
tr7zw ca76df589b Merge pull request #188 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.4.0
Bump maven-shade-plugin from 3.3.0 to 3.4.0
2022-09-15 14:21:54 +02:00
tr7zw 9e6ae13711 Merge pull request #189 from tr7zw/dependabot/maven/org.javassist-javassist-3.29.2-GA
Bump javassist from 3.29.1-GA to 3.29.2-GA
2022-09-15 14:21:43 +02:00
dependabot[bot] 02d3ab0b11 Bump javassist from 3.29.1-GA to 3.29.2-GA
Bumps [javassist](https://github.com/jboss-javassist/javassist) from 3.29.1-GA to 3.29.2-GA.
- [Release notes](https://github.com/jboss-javassist/javassist/releases)
- [Changelog](https://github.com/jboss-javassist/javassist/blob/master/Changes.md)
- [Commits](https://github.com/jboss-javassist/javassist/commits)

---
updated-dependencies:
- dependency-name: org.javassist:javassist
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-14 23:18:03 +00:00
dependabot[bot] abb7fdf622 Bump maven-shade-plugin from 3.3.0 to 3.4.0
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.3.0 to 3.4.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.3.0...maven-shade-plugin-3.4.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>
2022-09-14 23:17:54 +00:00
tr7zw 7263b5a12f Minor cleanup 2022-09-04 16:45:33 +02:00
tr7zw e500a443a1 Add getOrNull Method 2022-09-03 21:22:40 +02:00
tr7zw 332f9e4b42 ItemStack Array storage methods 2022-09-03 21:13:19 +02:00
tr7zw 42e37f0838 Prevent unintended nms access. Fix #183 2022-09-03 20:31:04 +02:00
tr7zw efd22f2bd1 Merge pull request #184 from tr7zw/dependabot/maven/org.javassist-javassist-3.29.1-GA
Bump javassist from 3.29.0-GA to 3.29.1-GA
2022-09-03 20:29:13 +02:00
tr7zw 4dace8749d Merge pull request #185 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.4.1
Bump maven-javadoc-plugin from 3.4.0 to 3.4.1
2022-09-03 20:28:30 +02:00
tr7zw 82dbb4b7d1 Merge pull request #186 from AndyNoob/master
Added a null check to NBTCompound#getItemStack
2022-09-03 20:28:14 +02:00
tr7zw bb85fd092d Further deprecate the Gson methods. #187 2022-09-03 20:15:20 +02:00
tr7zw c9d4ec6cc1 Let getUUID check all options and fail safe 2022-09-03 20:04:16 +02:00
AndyNoob ff72945ade Added a null check to NBTCompound#getItemStack 2022-08-19 13:30:03 -07:00
dependabot[bot] fc186cc076 Bump maven-javadoc-plugin from 3.4.0 to 3.4.1
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.4.0 to 3.4.1.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.4.0...maven-javadoc-plugin-3.4.1)

---
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>
2022-08-15 23:15:14 +00:00
dependabot[bot] e59008d475 Bump javassist from 3.29.0-GA to 3.29.1-GA
Bumps [javassist](https://github.com/jboss-javassist/javassist) from 3.29.0-GA to 3.29.1-GA.
- [Release notes](https://github.com/jboss-javassist/javassist/releases)
- [Changelog](https://github.com/jboss-javassist/javassist/blob/master/Changes.md)
- [Commits](https://github.com/jboss-javassist/javassist/commits)

---
updated-dependencies:
- dependency-name: org.javassist:javassist
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-11 23:14:19 +00:00
tr7zw 0a033f1fc9 GetUUID/SetUUID handle < 1.16 2022-07-28 01:12:33 +02:00
tr7zw 0954eaa294 Deprecate setObject/getObject 2022-07-28 00:29:44 +02:00
tr7zw 854524062e Draft new api for clearer nbt access with lambdas. 2022-07-28 00:23:38 +02:00
tr7zw 4e498e3247 Merge pull request #182 from supercoolspy/master
Gender pronoun fix
2022-07-27 23:35:32 +02:00
supercoolspy 5c213e3c2d Gender pronoun fix 2022-07-10 17:35:36 -07:00
tr7zw 54d3d4a83f Merge pull request #180 from SoSeDiK/nbt-tweaks
Some additions
2022-06-26 23:37:13 +02:00
tr7zw 7ae34cc78c Bump to 2.11.0-SNAPSHOT 2022-06-26 23:34:29 +02:00
SoSeDiK 620af1f49e Add getOrDefault 2022-06-26 23:46:05 +03:00
SoSeDiK 7a6e778a2a Add hasTag 2022-06-26 23:46:05 +03:00
SoSeDiK 2e74e8def8 Add NBTFile util methods 2022-06-26 23:45:06 +03:00
tr7zw 80facd8d8b Try deploying multiple javadocs 2022-06-15 19:23:59 +02:00
tr7zw 8e4e674443 Update javadoc.yml 2022-06-15 19:15:17 +02:00
tr7zw a0ca526af4 Update javadoc.yml 2022-06-15 19:13:27 +02:00
tr7zw 9d1448f96e Update javadoc.yml 2022-06-15 19:04:44 +02:00
tr7zw 06b6cdddd0 Split javadoc deploy 2022-06-15 19:01:37 +02:00
tr7zw 1fc21e8707 Start 2.10.1-SNAPSHOT. Attempt to auto deploy javadoc 2022-06-15 18:46:02 +02:00
tr7zw 9000d576ca Release 2.10.0 2022-06-11 19:32:38 +02:00
tr7zw c7ea044853 Add sync checks to Block-Entity. Fix #173 2022-06-07 19:38:27 +02:00
tr7zw 20f5787696 Add 1.19(.0) support. 2022-06-07 19:19:42 +02:00
tr7zw cd764ce984 Merge pull request #166 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.10.1
Bump maven-compiler-plugin from 3.10.0 to 3.10.1
2022-06-07 18:54:13 +02:00
tr7zw 57735d76ee Merge pull request #168 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.3.0
Bump maven-shade-plugin from 3.2.4 to 3.3.0
2022-06-07 18:54:00 +02:00
tr7zw 5d80816f1b Merge pull request #174 from tr7zw/dependabot/maven/org.javassist-javassist-3.29.0-GA
Bump javassist from 3.28.0-GA to 3.29.0-GA
2022-06-07 18:53:52 +02:00
tr7zw 51dedc0c33 Merge pull request #172 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.4.0
Bump maven-javadoc-plugin from 3.3.0 to 3.4.0
2022-06-07 18:53:24 +02:00
tr7zw 7e2a32dda9 Merge pull request #171 from EverNife/master
Make the NBT-API compatible with Forge 1.7.10
2022-06-07 18:51:36 +02:00
tr7zw 425ca3f930 Start 2.10.0-SNAPSHOT 2022-06-07 18:49:00 +02:00
Pétrus Pradella 36e5a5fd02 Add simple way to clear all keys from compound 2022-05-26 09:55:08 -03:00
dependabot[bot] c9b3a92e16 Bump javassist from 3.28.0-GA to 3.29.0-GA
Bumps [javassist](https://github.com/jboss-javassist/javassist) from 3.28.0-GA to 3.29.0-GA.
- [Release notes](https://github.com/jboss-javassist/javassist/releases)
- [Commits](https://github.com/jboss-javassist/javassist/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-13 23:14:36 +00:00
dependabot[bot] bc09a2e84c Bump maven-javadoc-plugin from 3.3.0 to 3.4.0
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.0 to 3.4.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.0...maven-javadoc-plugin-3.4.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>
2022-04-20 23:12:21 +00:00
Pétrus Pradella a260cd6345 Fix isForge comment 2022-04-18 07:28:31 -03:00
Pétrus Pradella b3107b0e9d Make the NBT-API compatible with Forge 1.7.10 2022-04-18 07:11:38 -03:00
dependabot[bot] f3d36fc92c Bump maven-shade-plugin from 3.2.4 to 3.3.0
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.4 to 3.3.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.4...maven-shade-plugin-3.3.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>
2022-03-29 23:23:37 +00:00
dependabot[bot] d0b0472894 Bump maven-compiler-plugin from 3.10.0 to 3.10.1
Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.10.0 to 3.10.1.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.10.0...maven-compiler-plugin-3.10.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-11 23:24:40 +00:00
tr7zw a8ddfa7a5a Bump version 2.9.2 2022-03-03 21:28:30 +01:00
tr7zw eae2ebb72a Make NBTPersistentDataContainer publicly usable 2022-03-03 19:56:08 +01:00
tr7zw 0ca0d3038e Log less during network issues. Fix #163 2022-03-03 19:41:50 +01:00
tr7zw dd0c421145 Update 1.18.2 2022-03-02 15:43:16 +01:00
tr7zw d0d3e19c70 Merge pull request #162 from spnda/1.18.2
Add: 1.18.2 enum
2022-03-02 15:22:25 +01:00
sean b0cf14c77e Add: 1.18.2 support 2022-03-02 14:15:37 +01:00
tr7zw ba4308e571 Merge pull request #160 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.10.0
Bump maven-compiler-plugin from 3.8.1 to 3.10.0
2022-02-15 09:47:59 +01:00
dependabot[bot] 325591e503 Bump maven-compiler-plugin from 3.8.1 to 3.10.0
Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.8.1 to 3.10.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.8.1...maven-compiler-plugin-3.10.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>
2022-02-14 23:16:30 +00:00
tr7zw fb6c856444 2.9.2-SNAPSHOT, Fix Error message having an error(duh), Add int[] List, Add UUID List 2022-02-08 15:29:36 +01:00
tr7zw 3d0a17fa25 Tag 2.9.1 2022-01-30 17:23:54 +01:00
tr7zw 5b409771e1 :hurtrealbad: 2022-01-30 00:31:31 +01:00
tr7zw bca1efce52 Grammar, add the version as prefix 2022-01-30 00:25:56 +01:00
tr7zw e3502a50ee Silent close the stream 2022-01-29 23:00:02 +01:00
tr7zw a495729725 Merge pull request #155 from honkling/master
Fix resource leak when reading NBT files
2022-01-29 22:51:17 +01:00
tr7zw 88661da61c Extend NbtApiException with selfcheck data, clearify Itemstack null/air check 2022-01-29 22:49:17 +01:00
tr7zw b4720f73e2 Remove System.out 2022-01-29 22:33:42 +01:00
tr7zw a97e2c6234 2.9.1-SNAPSHOT 2022-01-29 22:26:00 +01:00
honkling 8171762e42 Close stream if reading file fails 2022-01-29 08:43:46 -06:00
tr7zw 0602a2b8c3 Bump to 2.9.0. Reduce/change logging 2021-12-17 22:58:07 +01:00
tr7zw e0c060a982 Fix 1.8 2021-11-29 19:54:36 +01:00
tr7zw caa37d4cb0 Update NBTReflectionUtil.java 2021-11-29 19:26:51 +01:00
tr7zw de9f2a786f Fix BlockEntities 2021-11-29 19:04:26 +01:00
tr7zw 423f0a07e4 Fix NMS_WORLD_GET_TILEENTITY 2021-11-28 16:28:20 +01:00
tr7zw eda1d60ccc Forgot to press "replace" 2021-11-25 20:43:41 +01:00
tr7zw acb5a376e9 Update ReflectionMethod.java 2021-11-25 20:16:58 +01:00
tr7zw 165bb4ce68 Fallback logic 2021-11-25 20:13:34 +01:00
tr7zw 08bde0923f Update MojangToMapping.java 2021-11-25 20:05:29 +01:00
tr7zw a78b68d16f Bump version, 1.18 WIP 2021-11-25 20:02:24 +01:00
tr7zw 87204ac4a0 Update spigot.bb 2021-11-15 00:06:32 +01:00
tr7zw 71701d4a3a Replace apache commons-lang exceptions with internal ones. Fix #138
It was never inteded to use external exceptions like that one inside the project.
2021-09-03 23:40:56 +02:00
tr7zw 6b156c47e4 no 1.17 in unit-test 2021-06-28 22:03:38 +02:00
tr7zw f783db7fca Bump download links 2021-06-28 21:54:01 +02:00
tr7zw 394c093981 Fix #127 2021-06-28 21:44:18 +02:00
tr7zw 1f94a8452e 2.8.1-SNAPSHOT, fix equals check and add more unit tests for it 2021-06-28 21:40:25 +02:00
tr7zw 8e96e4cb7d 2.8.0 2021-06-11 15:39:27 +02:00
tr7zw b08f6c193f Fix annotations shade location in plugin jar 2021-06-11 15:21:29 +02:00
tr7zw 30d6b7cb01 Update License stuff 2021-06-11 15:19:15 +02:00
tr7zw d08b2fcb11 Sortpom 2021-06-11 14:21:52 +02:00
tr7zw fb4ef48d7a Merge pull request #126 from tr7zw/dependabot/maven/com.github.ekryd.sortpom-sortpom-maven-plugin-3.0.0
Bump sortpom-maven-plugin from 2.12.0 to 3.0.0
2021-06-11 14:14:34 +02:00
tr7zw 441fedf1e8 Merge pull request #124 from tr7zw/dependabot/maven/org.javassist-javassist-3.28.0-GA
Bump javassist from 3.27.0-GA to 3.28.0-GA
2021-06-11 14:14:22 +02:00
tr7zw fe7b04d6d6 Merge pull request #125 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.3.0
Bump maven-javadoc-plugin from 3.2.0 to 3.3.0
2021-06-11 14:14:10 +02:00
tr7zw 05826a5ed5 Merge pull request #114 from spnda/fix-available-annotation
Fix the spelling of AvailableSince interface
2021-06-11 14:03:27 +02:00
dependabot[bot] e8a508623b Bump sortpom-maven-plugin from 2.12.0 to 3.0.0
Bumps [sortpom-maven-plugin](https://github.com/Ekryd/sortpom) from 2.12.0 to 3.0.0.
- [Release notes](https://github.com/Ekryd/sortpom/releases)
- [Commits](https://github.com/Ekryd/sortpom/compare/sortpom-parent-2.12.0...sortpom-parent-3.0.0)

---
updated-dependencies:
- dependency-name: com.github.ekryd.sortpom:sortpom-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-11 12:02:43 +00:00
dependabot[bot] 7b65e54ac7 Bump maven-javadoc-plugin from 3.2.0 to 3.3.0
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.2.0 to 3.3.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.2.0...maven-javadoc-plugin-3.3.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>
2021-06-11 12:02:34 +00:00
dependabot[bot] 44ff2fa973 Bump javassist from 3.27.0-GA to 3.28.0-GA
Bumps [javassist](https://github.com/jboss-javassist/javassist) from 3.27.0-GA to 3.28.0-GA.
- [Release notes](https://github.com/jboss-javassist/javassist/releases)
- [Commits](https://github.com/jboss-javassist/javassist/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-11 12:02:31 +00:00
tr7zw 595357f4c6 Merge pull request #120 from tr7zw/dependabot/add-v2-config-file
Upgrade to GitHub-native Dependabot
2021-06-11 14:01:42 +02:00
tr7zw 03475a3f76 Add 1.17 support 2021-06-11 13:46:05 +02:00
tr7zw 8e05513122 Relocate javassist. 2.8.0-SNAPSHOT 2021-06-11 12:22:34 +02:00
tr7zw d43447c721 2.7.2 paper hotfix 2021-05-20 11:51:45 +02:00
dependabot-preview[bot] 50edbaeed3 Upgrade to GitHub-native Dependabot 2021-04-29 19:12:43 +00:00
pnda 01afd25131 Fix availability spelling 2021-01-27 15:46:59 +01:00
tr7zw 601cb2f56c Fix pom issue and release 2.7.1 2020-12-30 14:53:58 +01:00
tr7zw 442a6e935b 2.7.0 Release 2020-12-29 23:36:41 +01:00
tr7zw 2213ab879d Update pom.xml 2020-12-29 23:26:00 +01:00
tr7zw 00c2ce951b Reimplement equals method to hopefully be better than before, add getListType method 2020-12-29 23:12:21 +01:00
tr7zw 60d8101b9f Add NBTBlock for 1.16.4 2020-12-29 20:06:59 +01:00
tr7zw ef56b44629 Add NBTChunk and NBTPersistentDataContainer 2020-12-29 18:56:44 +01:00
tr7zw 5859276c11 Add getOrCreateCompound and clearify the javadoc of addCompound 2020-12-29 17:24:09 +01:00
tr7zw f588e6fec9 Start using maven vars for the version. Start NBT-Crafting 2020-12-29 17:06:13 +01:00
tr7zw 413b0f38f4 Update pom.xml 2020-12-29 16:53:04 +01:00
tr7zw a40eb5b4b4 Start work on 2.7.0-SNAPSHOT 2020-12-29 16:51:30 +01:00
tr7zw a4deb2a1ee Release 2.6.1 to fix the spigotmc/curseforge situation 2020-12-20 18:40:07 +01:00
tr7zw feaf59998f Putting the src versions of the spigot/curseforge page text into the repo 2020-12-08 21:40:13 +01:00
tr7zw cc1a88cdc8 Update README.md 2020-12-08 21:17:33 +01:00
tr7zw b58215d4bf Merge pull request #108 from LoneDev6/patch-2
Update .all-contributorsrc
2020-12-08 21:15:53 +01:00
tr7zw 689c354443 Bump to 2.6.1-SNAPSHOT 2020-12-08 21:15:23 +01:00
LoneDev ff3a7c3add Update .all-contributorsrc
Added "Code" icon to user LoneDev6
2020-11-30 12:53:42 +01:00
tr7zw 7d76d3c342 2.6.0 Release 2020-11-03 18:15:20 +01:00
tr7zw 2107d6f53d Fix >= != >, update readme 2020-11-03 18:02:52 +01:00
tr7zw f3e912723b Add 1.16.4 Fixes #106 , Fix issue with the version fallback for unknown future versions 2020-11-03 17:47:53 +01:00
tr7zw 47f29234e3 Fix loggers, allow replacement of the nbt-api logger for shaded plugins. Fixes #99 somewhat 2020-10-28 18:31:30 +01:00
tr7zw bd1ebac035 Bump to 2.6.0-SNAPSHOT 2020-10-28 18:12:20 +01:00
tr7zw ea9ccdc077 Add Stargazers graph 2020-10-12 10:53:18 +02:00
tr7zw f2d13e9b4e Bump Year 2020-09-28 21:11:31 +00:00
tr7zw 17c689699d Change to 2.5.0 Release 2020-08-14 10:04:52 +02:00
tr7zw c8110b0637 Merge pull request #100 from LoneDev6/master
Update MinecraftVersion.java to 1.16.2
2020-08-14 10:04:16 +02:00
tr7zw 2daec88667 Merge branch 'master' into master 2020-08-14 09:48:33 +02:00
tr7zw 01aec6c272 Bump versions to 2.5.0-SNAPSHOT, add 1.16.2 to unit test 2020-08-14 09:44:45 +02:00
LoneDev6 b74ba362c8 Update MinecraftVersion.java 2020-08-12 13:52:12 +02:00
tr7zw 65a86027ba Update ReflectionMethod.java 2020-08-03 18:15:34 +02:00
tr7zw 580c07fc3f Apply isntead of merge so removeing tags works 2020-07-11 19:43:05 +02:00
tr7zw c38ca2cb35 Add direct apply mode
Fixes #49
2020-07-11 18:44:22 +02:00
tr7zw 1ebd2a8ed1 Add Config file
Fixes #79
2020-07-11 18:13:51 +02:00
tr7zw 19300566c2 More 1.7.10 fixes, add 1.7.10 to unit test 2020-07-10 18:45:40 +02:00
tr7zw 6b6783e7c6 Block the NBTInjector from even trying to load in invalid versions, fixed 1.7.10 getType 2020-07-10 17:55:26 +02:00
tr7zw 7e5b5a1ff4 Fix loading in 1.7.10 2020-07-10 17:11:07 +02:00
tr7zw ff50036688 Merge branch 'master' of https://github.com/tr7zw/Item-NBT-API 2020-07-10 16:37:47 +02:00
tr7zw 7c0b63d0e3 Bump to 2.5.0-SNAPSHOT since the API will change compared to 2.4.1 2020-07-10 16:37:45 +02:00
tr7zw 8f4dad62bd Merge pull request #89 from tr7zw/dependabot/maven/com.github.ekryd.sortpom-sortpom-maven-plugin-2.12.0
Bump sortpom-maven-plugin from 2.11.0 to 2.12.0
2020-07-10 16:35:46 +02:00
tr7zw 6667682c6c Merge pull request #92 from brandonwamboldt/fix-91
Use the correct TILEENTITY_SET_NBT method on pre-1.1.6 versions
2020-07-10 16:35:25 +02:00
Brandon Wamboldt 0123652cc7 Use the correct TILEENTITY_SET_NBT method on pre-1.1.6 versions
Fixes #91
2020-07-10 09:41:36 -03:00
dependabot-preview[bot] 0d9c200e88 Bump sortpom-maven-plugin from 2.11.0 to 2.12.0
Bumps [sortpom-maven-plugin](https://github.com/Ekryd/sortpom) from 2.11.0 to 2.12.0.
- [Release notes](https://github.com/Ekryd/sortpom/releases)
- [Commits](https://github.com/Ekryd/sortpom/compare/sortpom-parent-2.11.0...sortpom-parent-2.12.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-03 05:29:48 +00:00
tr7zw ab3c52ada1 Merge pull request #88 from SoSeDiK/apply
Implement utility methods for merging NBT
2020-06-30 11:12:55 +02:00
tr7zw 443fb2d3c0 Fix potential issue with 1.7.10 2020-06-28 16:24:24 +02:00
SoSeDiK 0de8279b4b Implement utility methods for merging NBT 2020-06-27 06:48:04 +03:00
tr7zw 003e015d1d Merge pull request #87 from stijnb1234/master
ReflectionMethod cleanup
2020-06-25 17:01:12 +02:00
tr7zw b5dc20683f Bump to 2.4.2-SNAPSHOT for future development 2020-06-25 17:00:47 +02:00
Stijn Bannink bda2845a79 ReflectionMethod cleanup 2020-06-25 16:58:18 +02:00
tr7zw 817b104757 Merge pull request #85 from LoneDev6/master
1.16.1 support
2020-06-25 15:47:54 +02:00
tr7zw d4ab47d287 Release 2.4.1: 1.16.1 Update 2020-06-25 15:46:57 +02:00
tr7zw cd30dd1303 Fix 1.16 TileEntities 2020-06-25 15:36:44 +02:00
tr7zw ff6a0361b7 Merge branch 'master' into pr/85 2020-06-25 15:36:24 +02:00
tr7zw 97042b9fc1 Merge pull request #86 from Leonardo-DGS/patch-1
Fix mistake in MinecraftVersion.java
2020-06-25 15:33:24 +02:00
Leonardo Di Gianfelice Stornelli 6234e359eb Fix mistake in MinecraftVersion.java 2020-06-25 15:22:58 +02:00
LoneDev6 32070b8f19 Merge branch 'master' of https://github.com/LoneDev6/Item-NBT-API 2020-06-25 13:17:55 +02:00
LoneDev6 a371a33766 Fixed imports 2020-06-25 13:17:44 +02:00
tr7zw 8ad527057e Update pom.xml 2020-06-25 13:16:48 +02:00
LoneDev6 cf5fe7c083 Merge branch 'master' of https://github.com/LoneDev6/Item-NBT-API 2020-06-25 13:08:07 +02:00
LoneDev6 0255ef044f Get and set UUID (1.16.1+) 2020-06-25 13:08:04 +02:00
tr7zw faeea97934 Update pom.xml 2020-06-25 13:06:31 +02:00
tr7zw b4a59cdede Update pom.xml 2020-06-25 13:05:49 +02:00
tr7zw c47ca55e84 Update pom.xml 2020-06-25 13:05:28 +02:00
tr7zw 8cbf4b1cf6 Bump version 2020-06-25 13:05:15 +02:00
LoneDev6 67bf920ba7 1.16.1 support
- 1.16.1 support
- incremented api version
2020-06-25 12:36:26 +02:00
tr7zw af0a8f1d4c Merge pull request #82 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.2.4
Bump maven-shade-plugin from 3.2.3 to 3.2.4
2020-06-16 12:23:41 +02:00
dependabot-preview[bot] 7fa614b3d5 Bump maven-shade-plugin from 3.2.3 to 3.2.4
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.3 to 3.2.4.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.3...maven-shade-plugin-3.2.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-06-03 05:31:03 +00:00
tr7zw 55a3f8b1b1 Merge pull request #81 from drunderscore/fix/nbtcomp-docs
Correct documentation to specify JSON validity
2020-05-27 23:48:09 +02:00
James Puleo 2a432e68ab Correct documentation to specify JSON validity 2020-05-27 17:45:42 -04:00
tr7zw efbd6912ab Update README.md 2020-05-06 19:19:03 +02:00
tr7zw 70579b649d Fix typo
Fixes (part of) #78
2020-04-27 13:44:56 +02:00
tr7zw cdeabe7364 Fix Copypaste fail 2020-04-26 20:08:15 +02:00
tr7zw f4f32d9303 Reading from dead entities is valid 2020-04-21 14:04:32 +02:00
tr7zw 5cb25ad47d Merge pull request #77 from j0x0f/fix/nbt-list-iterator-remove
Fix "remove" method in NBTList iterators
2020-04-20 20:24:19 +02:00
j0x0f 1fb0945f1d IteratorTest: Also test previously failed case
Removing an element from the list would skip the element that was right after the removed one.
2020-04-20 21:34:09 +05:00
j0x0f d31e2849b3 IteratorTest
Add test to NBTList iterators: `iterator()` and `listIterator()`. Covers `hasNext`, `next` and `remove` methods.
2020-04-20 21:24:10 +05:00
tr7zw ca2bb4d0b3 Adding a ReadWriteLock to Compounds to minimize the chance of Concurrent exceptions 2020-04-20 17:38:58 +02:00
j0x0f 550ae33051 Fixed skipping an element right after removed one 2020-04-20 02:24:35 +05:00
tr7zw 1b7bf63982 Merge pull request #75 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.2.3
Bump maven-shade-plugin from 3.2.2 to 3.2.3
2020-04-18 18:55:50 +02:00
tr7zw d89edc6738 Merge pull request #76 from j0x0f/feature/nbt-list-removeIf
Implement "remove" method in NBTList iterator
2020-04-18 18:54:54 +02:00
tr7zw 71f4cb764e Bump to 2.4.0-SNAPSHOT 2020-04-18 18:53:30 +02:00
j0x0f bba58df6c3 Implement "remove" method in NBTList iterator 2020-04-18 21:43:00 +05:00
dependabot-preview[bot] a9bb1bc839 Bump maven-shade-plugin from 3.2.2 to 3.2.3
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.2...maven-shade-plugin-3.2.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-04-14 05:20:37 +00:00
tr7zw 75249b556e Bump to 2.3.2 (no spigot release), prevent shading to change the nms packet names 2020-04-11 16:32:30 +02:00
tr7zw 8aba56ff70 2.3.1 fixes
Added the api-version 1.13. Only >= 1.13 uses this so doesn't use legacy materials. Fixes #74
The versioncheck was doing a http request in the mainthread, which was fine for the plugin version since it happend during enable, but shaded versions might do that sometime later when players are online, causing a short lag.
2020-04-09 19:28:04 +02:00
tr7zw 27761ac95a Bump to 2.4.0-SNAPSHOT 2020-04-04 18:00:36 +02:00
tr7zw c6b3055a15 Add Peaches_MLG 2020-04-04 17:59:37 +02:00
tr7zw 05da1c6b1c Bump version for tag 2020-04-02 01:18:13 +02:00
tr7zw 8b861f6c7a Update NBTContainer.java 2020-04-01 17:01:30 +02:00
tr7zw 58c744dab7 Update NBTContainer.java 2020-04-01 16:50:54 +02:00
tr7zw 8c75990918 Add null (and other) checks for userInput 2020-04-01 04:34:25 +02:00
tr7zw e6fa7bca63 Adding the missing Lists
Float, Double and Long lists
2020-03-21 14:48:40 +01:00
tr7zw 6eff3d9cdc Merge pull request #72 from tr7zw/dependabot/maven/org.javassist-javassist-3.27.0-GA
Bump javassist from 3.26.0-GA to 3.27.0-GA
2020-03-21 13:40:13 +01:00
dependabot-preview[bot] 492372519a Bump javassist from 3.26.0-GA to 3.27.0-GA
Bumps [javassist](https://github.com/jboss-javassist/javassist) from 3.26.0-GA to 3.27.0-GA.
- [Release notes](https://github.com/jboss-javassist/javassist/releases)
- [Commits](https://github.com/jboss-javassist/javassist/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-20 05:16:29 +00:00
tr7zw 054a7f5173 Merge pull request #71 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.2.0
Bump maven-javadoc-plugin from 3.1.1 to 3.2.0
2020-03-17 00:24:21 +01:00
dependabot-preview[bot] a7b73fda9d Bump maven-javadoc-plugin from 3.1.1 to 3.2.0
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.1.1 to 3.2.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.1.1...maven-javadoc-plugin-3.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-16 05:26:07 +00:00
tr7zw fd9bbe093b Add Equals unittest 2020-03-12 22:12:09 +01:00
tr7zw 92108a218c Override NBTCompound equals and hashcode to use the toString result 2020-03-12 21:57:21 +01:00
tr7zw 340fd2ae63 Add Stream API 2020-03-12 21:50:32 +01:00
tr7zw 371d55cd1f Fix merge, Fix 1.13 Injector
Thanks to DefinitlyEvil, fixes #70
2020-03-12 20:49:33 +01:00
tr7zw fe8e50d788 Merge pull request #69 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.2.2
Bump maven-shade-plugin from 3.2.1 to 3.2.2
2020-02-13 10:22:30 +01:00
dependabot-preview[bot] 834d0bc6e3 Bump maven-shade-plugin from 3.2.1 to 3.2.2
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.1 to 3.2.2.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.1...maven-shade-plugin-3.2.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-13 05:13:45 +00:00
tr7zw 0a31d709e3 Merge pull request #66 from tr7zw/dependabot/maven/com.github.ekryd.sortpom-sortpom-maven-plugin-2.11.0
Bump sortpom-maven-plugin from 2.10.0 to 2.11.0
2020-02-05 16:39:36 +01:00
dependabot-preview[bot] 19254b5214 Bump sortpom-maven-plugin from 2.10.0 to 2.11.0
Bumps [sortpom-maven-plugin](https://github.com/Ekryd/sortpom) from 2.10.0 to 2.11.0.
- [Release notes](https://github.com/Ekryd/sortpom/releases)
- [Commits](https://github.com/Ekryd/sortpom/compare/sortpom-parent-2.10.0...sortpom-parent-2.11.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-04 05:14:11 +00:00
tr7zw 188942887e Add TauCubed 2020-01-26 18:24:35 +01:00
tr7zw ab1b6e5fa8 Add Gaby 2020-01-25 21:53:44 +01:00
tr7zw c684f9f288 Add all-contributors section 2020-01-25 18:42:56 +01:00
tr7zw 4a3fbf135b Update README.md 2020-01-18 15:28:02 +01:00
tr7zw 1e3e8dc5d9 Update README.md 2020-01-18 14:57:04 +01:00
tr7zw be0fc09cb3 Update README.md 2020-01-18 14:55:19 +01:00
tr7zw a9a248c7cf Small stuff and making method names clearer 2020-01-17 01:42:21 +01:00
tr7zw 26e3c5b913 Add NBTGameProfile for converting 2020-01-17 00:58:09 +01:00
tr7zw 2585ef0a50 Add the persistentDataContainer for Entities 2020-01-16 19:36:46 +01:00
tr7zw 0754250af9 Add functional-annotations
Starting to make avaliable 1.14+ PersistentDataAPI containers
2020-01-16 19:01:54 +01:00
tr7zw 922c32c91b Update FUNDING.yml 2020-01-15 11:09:32 +01:00
tr7zw c7e01f2660 Delete the selftest file first, incase it's corrupted 2020-01-06 22:36:37 +01:00
tr7zw cb67076324 Bump nbt-data-api to 2.3.0-SNAPSHOT 2020-01-06 19:56:29 +01:00
tr7zw b691c6972c Merge remote-tracking branch 'origin/NbtDataApi' 2020-01-06 19:54:53 +01:00
tr7zw cec0222114 bump to 2.3.0-SNAPSHOT 2020-01-06 19:54:47 +01:00
tr7zw 61fd8669f0 Prepare Tag 2.2.0 2019-12-31 15:23:28 +01:00
tr7zw aa54a91c40 clean pom 2019-12-31 15:18:21 +01:00
tr7zw 739b449254 Merge branch 'master' into NbtDataApi 2019-12-31 01:40:54 +01:00
tr7zw d97a050e1a Fix bug in nbtcompound to ItemStack method, added simple ItemStack getter/setter 2019-12-31 01:36:23 +01:00
tr7zw e3da9bf20e Lazy Plugin (Player) data getter 2019-12-31 00:24:12 +01:00
tr7zw 259b184829 include 2019-12-30 19:00:46 +01:00
tr7zw 58bbcbe888 Init nbt-data-api 2019-12-30 18:57:47 +01:00
tr7zw 8479479c84 Handle async bstats init
Fixes #59
2019-12-30 15:50:52 +01:00
tr7zw 6129125dd9 Add toString to lists 2019-12-30 12:00:39 +01:00
tr7zw 43baa7c2ef Detect future Versions, real version checking 2019-12-30 01:28:45 +01:00
tr7zw c6cbc3b309 Fix build 2019-12-30 00:14:02 +01:00
tr7zw 39fd158c56 Add update check 2019-12-29 20:13:11 +01:00
tr7zw 2202dc38e0 Lists fix previous, but not sure how correct it compared to how it should work 2019-12-29 19:14:17 +01:00
tr7zw 656b7caff2 Fix List's Iterator/ListIterator off-by-one Error
List Iterator's previous is probably still broken
2019-12-29 19:01:20 +01:00
tr7zw 0918f25716 Remove debug message 2019-12-26 01:49:58 +01:00
tr7zw 662ad04a5e Removed custom toString (now uses asNBTString), CompList AddCompound got a helper method for auto copy 2019-12-26 01:45:02 +01:00
tr7zw daf684931f More stacked list tests, fix java 11 javadoc 2019-12-26 01:16:32 +01:00
tr7zw 99b5775855 Merge pull request #58 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.2.1
Bump maven-source-plugin from 3.2.0 to 3.2.1
2019-12-23 13:04:57 +01:00
dependabot-preview[bot] 87a6fce52f Bump maven-source-plugin from 3.2.0 to 3.2.1
Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.2.0 to 3.2.1.
- [Release notes](https://github.com/apache/maven-source-plugin/releases)
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.2.0...maven-source-plugin-3.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-23 05:20:46 +00:00
tr7zw 0a46bce99c Fix javadoc 2019-12-23 01:42:35 +01:00
tr7zw a1a3c0be33 Make CompoundLists extend NBTCompounds, so now they feature all methods
This took way to long...........
2019-12-23 00:09:19 +01:00
tr7zw bbf5064a15 fuuuu 2019-12-21 21:49:31 +01:00
tr7zw 437c69b7f4 Wups setAccessible 2019-12-21 21:23:23 +01:00
tr7zw ede8ebba6b Trying to fix Reflections for Java 11+
This is related to #50
2019-12-21 18:23:15 +01:00
tr7zw 54d1ed019f Throw exception on NBT-Injector use without enableing it
Fixes #51
2019-12-21 16:14:33 +01:00
tr7zw 4491709645 Bump version to 2.2.0-SNAPSHOT 2019-12-21 16:07:11 +01:00
tr7zw 34abb0aefb Merge pull request #57 from SoSeDiK/injector
Injector: Updated fields' names for 1.15 support
2019-12-21 15:59:00 +01:00
SoSeDiK 2522edac6b Updated fields' names for 1.15 support 2019-12-20 23:03:04 +02:00
tr7zw f64ac8e3ac 1.15 update, 2.2.1 2019-12-13 19:27:04 +01:00
tr7zw 5d3188a813 Merge branch 'master' of https://github.com/tr7zw/Item-NBT-API 2019-12-13 18:27:32 +01:00
tr7zw fc85d7f4ec Add 1.15 to testing 2019-12-13 18:26:09 +01:00
tr7zw 6063f8a27d Merge pull request #54 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.2.0
Bump maven-source-plugin from 3.1.0 to 3.2.0
2019-11-04 10:33:33 +01:00
dependabot-preview[bot] f203a0c8bc Bump maven-source-plugin from 3.1.0 to 3.2.0
Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/apache/maven-source-plugin/releases)
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.1.0...maven-source-plugin-3.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-04 08:59:27 +00:00
tr7zw 0bec8d4025 Merge pull request #48 from tr7zw/e3ndr-readme-update
Update README.md
2019-10-17 20:17:09 +02:00
Ender 56abfad7a1 Update README.md 2019-10-17 12:37:15 -05:00
tr7zw e96ae3227e Merge pull request #47 from tr7zw/github-completebuild
Try full build + on pull_request
2019-10-09 15:10:47 +02:00
tr7zw b727e33227 Try full build + on pull_request 2019-10-09 14:50:06 +02:00
tr7zw be13f4bd5e Fix snapshot build 2019-10-09 11:03:02 +02:00
tr7zw 18d03036a9 Add missing Entity mappings for 1.14 2019-10-07 16:48:53 +02:00
tr7zw edeb9051e7 Fix dependency 2019-10-07 16:32:56 +02:00
tr7zw 5b17a25c23 Change to 2.1.1-SNAPSHOT 2019-10-07 16:30:44 +02:00
tr7zw 9f8208347b Merge pull request #45 from tr7zw/GithubActionsBuild
Update maven.yml
2019-10-01 10:05:52 +02:00
tr7zw 6e3ab1fb7e Update maven.yml 2019-10-01 10:02:04 +02:00
tr7zw 7587df8ef2 Forgot to increment version in MetricsLite. Sadly to late now 2019-09-24 01:44:38 +02:00
tr7zw e769113e51 2.1.0 update
Update to 2.1.0:
- Fixed 1.12/11 invisible mobs
- Fixed an NBTInjector exception that could happen in 1.13.2
- If reflections where unable to get their hook, a NPE was thrown because the logger wasn't yet initialized
- The NBTInjector won't enable by default, enable it during onLoad if you want to use it
- Prevent /reload when the NBTInjector is enabled to prevent currupt serverstates
2019-09-23 20:44:20 +02:00
tr7zw 9e8e1e0b7d Remove Snapshot for release 2019-08-03 20:32:33 +02:00
tr7zw b5d40e8152 Remove logging that can spam the console 2019-08-02 22:15:34 +02:00
tr7zw a058cdd828 Merge pull request #40 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.1.1
Bump maven-javadoc-plugin from 3.1.0 to 3.1.1
2019-07-25 16:19:23 +02:00
dependabot-preview[bot] 604d19b4cd Bump maven-javadoc-plugin from 3.1.0 to 3.1.1
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.1.0 to 3.1.1.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.1.0...maven-javadoc-plugin-3.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-08 05:16:48 +00:00
tr7zw d73e5829f3 Add 1.14.3 to the automatic testing 2019-06-27 13:45:34 +02:00
tr7zw da34e9ef0b Update README.md 2019-06-22 17:29:52 +02:00
tr7zw fa5eae6ea4 Added more Entity Types because Paper had problems 2019-06-21 13:34:34 +02:00
tr7zw 8beeb269bd Fix nested Compounds 2019-06-20 20:57:23 +02:00
tr7zw 277ebd40b3 Sortpom, use the codemc repo for spigot 2019-06-16 18:28:11 +02:00
tr7zw 5d31541e68 Fix 2019-06-16 18:03:23 +02:00
tr7zw 115ca3d918 Format all the things 2019-06-16 18:02:35 +02:00
tr7zw 5103d9f10b Document all the code 2019-06-16 17:54:16 +02:00
tr7zw 872d1d26aa Moved the Version dependent methods to a different class 2019-06-16 14:47:14 +02:00
tr7zw dc7a052f9e Small sonar fixes 2019-06-16 13:57:24 +02:00
tr7zw 9e0e73d316 Code Cleanup(Sonar), Readme changes 2019-06-15 22:57:26 +02:00
tr7zw 02970734ff 1.14 (hopefully) fully working
Only the following entities will not be compatible: Player, fishing bobber and lightning bolt.
2019-06-15 16:38:55 +02:00
tr7zw cc58be0129 1.14 now works... Except some entities
1.14 has major problems. The Following entity classes can't be autoresolved(at least with the current method): area_effect_cloud, cow, fishing_bobber, wandering_trader, player, llama, panda, donkey, ender_dragon, skeleton_horse, fox, mule, fireball, zombie_horse, wither, villager, trader_llama, mooshroom, horse, lightning_bolt
2019-06-13 23:59:11 +02:00
tr7zw 2276dae154 1.14 fixes, but Entities are broken
1.14 had a few small problems that got fixed. Now the NBTAPI and Custom nbt to Tiles work. Only Entities still need some more work.
2019-06-12 19:33:48 +02:00
tr7zw 4c0a796c38 1.13.2 now works
Mojang did some terrible stuff to get around with. At least it doesn't need a custom reverse map like 1.11/12
2019-06-12 18:31:53 +02:00
tr7zw 96d6164d99 1.12.2 is now working
Also just found out 1.12.0 uses the same nms id 1.12R1, but mappings don't match. The nbt-api doesn't work with 1.12.0
2019-06-10 23:31:12 +02:00
tr7zw 17670f9f3b 1.11.2 working 2019-06-10 20:08:09 +02:00
tr7zw 419ca7ab98 NBTInjector 1.10.2 working 2019-06-10 17:38:37 +02:00
tr7zw d7b1736056 Making sure bStats works and doesn't kill me when you have 2.0.0 and 1.x installed 2019-06-10 17:09:43 +02:00
tr7zw 41d1aec29d NBTInjector now working with 1.8.8, 1.9.2 and 1.9.4 2019-06-10 16:24:31 +02:00
tr7zw c471706ab6 Cleaned up some loose ends from NBTReflectionUtil
The NBTReflectionUtil still had some places where methods get looked up on the fly. This is slow, fills the gc and doesn't allow prechecking on server startup. Now they also use the ReflectionMethod class for caching and checking.
2019-06-10 14:59:45 +02:00
tr7zwandMiniDigger 341728bcd4 Finished Tests, fixed error handeling
All tests are now in their own classes.
Errors in the ReflectionUtil will now throw a NBTApiException, not print it to the console and return null.
Fixed Inconsistency on items with a null Compound on them(Thanks to MiniDigger)

Co-Authored-By: MiniDigger <admin@minidigger.me>
2019-06-10 14:33:04 +02:00
tr7zw 72415bc0e0 Merge pull request #37 from tr7zw/dependabot/maven/org.javassist-javassist-3.25.0-GA
Bump javassist from 3.20.0-GA to 3.25.0-GA
2019-06-10 02:13:46 +02:00
tr7zw 9c48acecf1 Renaming to NBTApi and NBTInjector
For all intents and purposes the libs are now called NBTApi and NBTInjector. In some places it will still be ItemNBTApi(github/bStats/maven).
The NBTApi now needs to be shaded to a different package in order to be used in plugins, else you will get a warning in the console.
2019-06-10 02:12:58 +02:00
tr7zw 5fd0fa53fd Reworking API selfcheck 2019-06-07 21:40:46 +02:00
tr7zw 774580949a Reduce copy/pasted code 2019-06-06 23:30:32 +02:00
tr7zw 2bb0e11539 NBTInjector comments, removed debug logging 2019-06-06 23:13:03 +02:00
tr7zw 1272601282 Testing with converting the Vanilla Entity into the extended one 2019-06-03 18:42:32 +02:00
dependabot-preview[bot] 4c965288ee Bump javassist from 3.20.0-GA to 3.25.0-GA
Bumps [javassist](https://github.com/jboss-javassist/javassist) from 3.20.0-GA to 3.25.0-GA.
- [Release notes](https://github.com/jboss-javassist/javassist/releases)
- [Commits](https://github.com/jboss-javassist/javassist/commits)
2019-06-03 07:26:34 +00:00
tr7zw 6ef5af2093 Concept to make Tiles working without reloading the chunk. Still need to check how Bukkit refferences react to the tile beeing replaced. 2019-06-02 19:57:30 +02:00
tr7zw 2af23d148b Integer Lists
Starting to port Inventivetalent's nbt-injector with a testlistener in the plugin
2019-06-01 19:47:40 +02:00
tr7zw f6ff4acafe Fix build 2019-05-30 01:49:59 +02:00
tr7zw 7aebc9653b Use codemc repo 2019-05-29 21:39:50 +02:00
tr7zw a59011d9aa Merge branch 'HEAD' of https://github.com/tr7zw/Item-NBT-API.git 2019-05-29 21:23:56 +02:00
tr7zw 256c113eb2 NBTList's now implement the java List interface.
All missing types still need to be implemented
2019-05-29 21:23:20 +02:00
tr7zw 0f8a24f608 Merge pull request #35 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.1.0
Bump maven-source-plugin from 3.0.1 to 3.1.0
2019-05-29 16:42:31 +02:00
tr7zw f7bbc044c3 Merge branch 'HEAD' of https://github.com/tr7zw/Item-NBT-API.git 2019-05-29 16:42:01 +02:00
tr7zw 40b4e1137f Move bStats into the api 2019-05-29 16:41:14 +02:00
tr7zw 17fedfabbc Create FUNDING.yml 2019-05-29 14:27:44 +02:00
dependabot[bot] a4456a855a Bump maven-source-plugin from 3.0.1 to 3.1.0
Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.0.1 to 3.1.0.
- [Release notes](https://github.com/apache/maven-source-plugin/releases)
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.0.1...maven-source-plugin-3.1.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2019-05-20 05:50:31 +00:00
159 changed files with 15558 additions and 1960 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
text eol=lf
+3
View File
@@ -0,0 +1,3 @@
# These are supported funding model platforms
ko_fi: tr7zw
+14
View File
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: com.github.ekryd.sortpom:sortpom-maven-plugin
versions:
- 2.13.3-SNAPSHOT
- 2.14.0
- 2.14.1
- 2.15.0
+36
View File
@@ -0,0 +1,36 @@
name: Javadoc CI
on:
push:
branches:
- master
permissions:
contents: write
jobs:
javadoc:
if: ${{ github.repository_owner == 'tr7zw' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 8
- name: Build with Maven
run: mvn package
- name: Copy artifacts
shell: bash
run: |
mkdir -p artifacts/v2-api && cp -r item-nbt-api/target/reports/apidocs/* artifacts/v2-api
mkdir -p artifacts/v2-plugin && cp -r item-nbt-plugin/target/apidocs/* artifacts/v2-plugin
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
clean: false
folder: artifacts
+18
View File
@@ -0,0 +1,18 @@
name: Java CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 8
- name: Build with Maven
run: mvn install --file pom.xml
+34
View File
@@ -0,0 +1,34 @@
name: Wiki CI
on:
push:
branches:
- master
permissions:
contents: write
jobs:
wiki:
if: ${{ github.repository_owner == 'tr7zw' }}
runs-on: ubuntu-latest
steps:
- name: Checkout base code
uses: actions/checkout@v3
with:
path: base-code
- name: Checkout wiki code
uses: actions/checkout@v3
with:
repository: ${{github.repository}}.wiki
path: wiki
- name: Push to wiki
run: |
cd wiki
rm *.md
cp ../base-code/wiki/* ./
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git diff-index --quiet HEAD || (git commit -m "Add changes" && git push)
+106 -104
View File
@@ -1,104 +1,106 @@
### Java files ###
*.class
# Package Files
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
# Ignore project files
*.iml
# Ignore IDEA directory
.idea/*
# File-based project format:
*.ipr
*.iws
### Plugin-specific files: ###
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
### Eclipse ###
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
# Eclipse Core
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# JDT-specific (Eclipse Java Development Tools)
.classpath
# PDT-specific
.buildpath
# sbteclipse plugin
.target
# TeXlipse plugin
.texlipse
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/
### Git ###
# Don't exclude the .gitignore itself
!.gitignore
### Java files ###
*.class
# Package Files
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
# Ignore project files
*.iml
# Ignore IDEA directory
.idea/
# File-based project format:
*.ipr
*.iws
### Plugin-specific files: ###
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
### Eclipse ###
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.factorypath
# Eclipse Core
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# JDT-specific (Eclipse Java Development Tools)
.classpath
# PDT-specific
.buildpath
# sbteclipse plugin
.target
# TeXlipse plugin
.texlipse
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/
### Git ###
# Don't exclude the .gitignore itself
!.gitignore
.vscode/settings.json
-6
View File
@@ -1,6 +0,0 @@
language: java
addons:
sonarcloud:
organization: "tr7zw-github"
script:
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar
+5 -6
View File
@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 tr7zw
Copyright (c) 2015 - 2024, tr7zw
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -9,14 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+33 -3
View File
@@ -1,6 +1,36 @@
# Item-NBT-API
Add custom NBT tags to Items without NMS!
http://www.spigotmc.org/resources/item-nbt-api.7939/
[![](https://travis-ci.org/tr7zw/Item-NBT-API.svg?branch=master)](https://travis-ci.org/tr7zw/Item-NBT-API)[![](https://jitpack.io/v/tr7zw/Item-NBT-API.svg)](https://jitpack.io/#tr7zw/Item-NBT-API)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=alert_status)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=ncloc)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)
[![Modrinth](https://img.shields.io/modrinth/dt/nbtapi?logo=modrinth&label=Modrinth%20downloads)](https://modrinth.com/plugin/nbtapi)
[![Discord](https://img.shields.io/discord/342814924310970398?color=%237289DA&label=Discord&logo=discord&logoColor=white)](https://discordapp.com/invite/yk4caxM)
Add custom NBT tags to Items/Tiles/Entities without NMS! Modify NBT and store it in Files, other NBT, or as String in yaml/json/SQL/Redis.
[Server Owner/Developer Wiki](https://github.com/tr7zw/Item-NBT-API/wiki)
### Build/Maven/Sonar Status
[![Build Status](https://ci.codemc.org/buildStatus/icon?job=Tr7zw%2FItem-NBT-API)](https://ci.codemc.org/job/Tr7zw/job/Item-NBT-API/)[![](https://sonarcloud.io/api/project_badges/measure?project=tr7zw_Item-NBT-API&metric=ncloc)](https://sonarcloud.io/summary/overall?id=tr7zw_Item-NBT-API)[![](https://sonarcloud.io/api/project_badges/measure?project=tr7zw_Item-NBT-API&metric=duplicated_lines_density)](https://sonarcloud.io/summary/overall?id=tr7zw_Item-NBT-API)[![](https://sonarcloud.io/api/project_badges/measure?project=tr7zw_Item-NBT-API&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=tr7zw_Item-NBT-API)
### SpigotMC Status
[![Version](https://badges.spiget.org/resources/version/Version-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![Rating](https://badges.spiget.org/resources/rating/Rating-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![Rating](https://badges.spiget.org/resources/downloads/SpigotDownloads-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![bStats Servers](https://img.shields.io/bstats/servers/1058.svg?color=green&label=OnlineServers&style=plastic)](https://bstats.org/plugin/bukkit/ItemNBTAPI)[![bStats Players](https://img.shields.io/bstats/players/1058.svg?color=green&label=OnlinePlayers&style=plastic)](https://bstats.org/plugin/bukkit/ItemNBTAPI)[![All Contributors](https://img.shields.io/badge/all_contributors-13-green.svg?style=plastic)](#contributors-%e2%9c%a8)
## Getting started
Import the API using [Maven](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Maven) or [Gradle](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Gradle), then check out the [basic usage](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API) or code examples like [working with Skulls](https://github.com/tr7zw/Item-NBT-API/wiki/Example-Usages#set-a-skulls-skin).
### bStats
[![bStats Stats](https://bstats.org/signatures/bukkit/ItemNBTAPI.svg)](https://bstats.org/plugin/bukkit/ItemNBTAPI)
### Github Stargazers
<img src="https://starchart.cc/tr7zw/Item-NBT-API.svg" alt="stargazers" width="800"/>
### Supported by YourKit
![](https://www.yourkit.com/images/yklogo.png)
YourKit supports open source projects with innovative and intelligent tools
for monitoring and profiling Java and .NET applications.
YourKit is the creator of <a href="https://www.yourkit.com/java/profiler/">YourKit Java Profiler</a>,
<a href="https://www.yourkit.com/.net/profiler/">YourKit .NET Profiler</a>,
and <a href="https://www.yourkit.com/youmonitor/">YourKit YouMonitor</a>.
+21
View File
@@ -0,0 +1,21 @@
# (Item-)NBT-API
Add custom NBT tags to Items/Tiles/Entities without NMS! Modify NBT and store it in Files, other NBT, or as String in yaml/json/SQL/Redis.
[Server Owner/Developer Wiki](https://github.com/tr7zw/Item-NBT-API/wiki)
### Build/Maven/Sonar Status
[![Build Status](https://github.com/tr7zw/Item-NBT-API/workflows/Java%20CI/badge.svg)](https://ci.codemc.org/job/Tr7zw/job/Item-NBT-API/)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=alert_status)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=ncloc)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)
Discord:[![Discord](https://img.shields.io/discord/342814924310970398?color=%237289DA&label=Discord&logo=discord&logoColor=white)](https://discordapp.com/invite/yk4caxM)
### SpigotMC Status
[![Version](https://badges.spiget.org/resources/version/Version-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![Rating](https://badges.spiget.org/resources/rating/Rating-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![Rating](https://badges.spiget.org/resources/downloads/SpigotDownloads-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![bStats Servers](https://img.shields.io/bstats/servers/1058.svg?color=green&label=OnlineServers&style=plastic)](https://bstats.org/plugin/bukkit/ItemNBTAPI)[![bStats Players](https://img.shields.io/bstats/players/1058.svg?color=green&label=OnlinePlayers&style=plastic)](https://bstats.org/plugin/bukkit/ItemNBTAPI)
## Getting started
Import the API using [Maven](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Maven) or [Gradle](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Gradle), then check out the [basic usage](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API) or code examples like [working with Skulls](https://github.com/tr7zw/Item-NBT-API/wiki/Example-Usages#set-a-skulls-skin).
### bStats
[![bStats Stats](https://bstats.org/signatures/bukkit/ItemNBTAPI.svg)](https://bstats.org/plugin/bukkit/ItemNBTAPI)
+390
View File
@@ -0,0 +1,390 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="21">
<profile kind="CodeFormatterProfile" name="Java Conventions Spaces" version="21">
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="8"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.align_with_spaces" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
<setting id="org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_record_components" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_logical_operator" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_shift_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_type_parameters" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_loops" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant" value="49"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.text_block_indentation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_module_statements" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_type_annotations" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines" value="2147483647"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_not_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_type_arguments" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package" value="49"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_tag_description" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_record_constructor" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_string_concatenation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_shift_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_shift_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_additive_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_relational_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_logical_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_method_body_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_additive_operator" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_relational_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_relational_operator" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_additive_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_record_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type" value="49"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable" value="49"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_additive_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field" value="49"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_conditional_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_shift_operator" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.keep_code_block_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_assignment_operator" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method" value="49"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assertion_message" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_logical_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_relational_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_logical_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_string_concatenation" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
</profile>
</profiles>
+5 -6
View File
@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 tr7zw
Copyright (c) 2015 - 2021, tr7zw
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -9,14 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+63 -14
View File
@@ -1,20 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>1.8.3-SNAPSHOT</version>
</parent>
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.16.1</version>
</parent>
<artifactId>item-nbt-api</artifactId>
<packaging>jar</packaging>
<artifactId>item-nbt-api</artifactId>
<packaging>jar</packaging>
<build>
<defaultGoal>clean install javadoc:javadoc</defaultGoal>
</build>
<dependencies>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>datafixerupper</artifactId>
<version>4.0.26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean install javadoc:javadoc</defaultGoal>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>de.tr7zw.changeme.nbtapi.utils.metrics</shadedPattern>
</relocation>
</relocations>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>LICENSE</resource>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<id>shade</id>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,933 @@
package de.tr7zw.changeme.nbtapi;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.Level;
import javax.annotation.Nullable;
import de.tr7zw.changeme.nbtapi.utils.CheckUtil;
import org.bukkit.Chunk;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import com.mojang.authlib.GameProfile;
import de.tr7zw.changeme.nbtapi.iface.NBTFileHandle;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import de.tr7zw.changeme.nbtapi.wrapper.NBTProxy;
import de.tr7zw.changeme.nbtapi.wrapper.ProxyBuilder;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBTList;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* General utility class for a clean and simple nbt access.
*
* @author tr7zw
*
*/
@SuppressWarnings("deprecation")
public class NBT {
private NBT() {
// No instances of NBT. Utility class
}
/**
* Utility method for shaded versions to preload and check the API during
* onEnable. This method does not throw an exception and instead logs them. Will
* return false if something fundamentally is wrong and the NBTAPI is in a non
* functioning state. The shading plugin then needs to handle this. Note:
* Calling this method during onLoad will cause an failure, so please wait till
* onEnable.
*
* @return true if everything went fine
*/
public static boolean preloadApi() {
try {
// boiled down version of the plugin selfcheck without tests
if (MinecraftVersion.getVersion() == MinecraftVersion.UNKNOWN) {
NbtApiException.confirmedBroken = true;
return false;
}
for (ClassWrapper c : ClassWrapper.values()) {
if (c.isEnabled() && c.getClazz() == null) {
NbtApiException.confirmedBroken = true;
return false;
}
}
for (ReflectionMethod method : ReflectionMethod.values()) {
if (method.isCompatible() && !method.isLoaded()) {
NbtApiException.confirmedBroken = true;
return false;
}
}
// not settings NbtApiException.confirmedBroken = false, as no actual tests were done.
// This just means the version was found, and all reflections seem to work.
return true;
} catch (Exception ex) {
NbtApiException.confirmedBroken = true;
MinecraftVersion.getLogger().log(Level.WARNING, "[NBTAPI] Error during the selfcheck!", ex);
return false;
}
}
/**
* Get a read only instance of the items NBT. This method is slightly slower
* than calling NBT.get due to having to create a copy of the ItemStack, but
* allows context free access to the data.
*
* @param item
* @return
*/
public static ReadableNBT readNbt(ItemStack item) {
return new NBTItem(item.clone(), false, true, false);
}
/**
* It takes an ItemStack, and a function that takes a ReadableNBT and returns a
* generic type T. It then returns the result of the function applied to a new
* NBTItem
*
* @param item The itemstack you want to get the NBT from
* @param getter A function that takes a ReadableNBT and returns a value of type
* T.
* @return The function is being returned.
*/
public static <T> T get(ItemStack item, Function<ReadableItemNBT, T> getter) {
NBTItem nbt = new NBTItem(item, false, true, false);
T ret = getter.apply(nbt);
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
nbt.setClosed();
return ret;
}
/**
* It takes an ItemStack, and a Consumer that takes a ReadableNBT. Applies the
* Consumer on the NBT of the item
*
* @param item The itemstack you want to get the NBT from
*/
public static void get(ItemStack item, Consumer<ReadableItemNBT> getter) {
NBTItem nbt = new NBTItem(item, false, true, false);
getter.accept(nbt);
nbt.setClosed();
}
/**
* It takes an entity and a function that takes a ReadableNBT and returns a
* generic type T, and returns the result of the function
*
* @param entity The entity to get the NBT from
* @param getter A function that takes a ReadableNBT and returns a value.
* @return The NBTEntity class is being returned.
*/
public static <T> T get(Entity entity, Function<ReadableNBT, T> getter) {
NBTEntity nbt = new NBTEntity(entity, true);
T ret = getter.apply(nbt);
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
nbt.setClosed();
return ret;
}
/**
* It takes an Entity, and a Consumer that takes a ReadableNBT. Applies the
* Consumer on the NBT of the Entity
*
* @param entity The entity to get the NBT from
*/
public static void get(Entity entity, Consumer<ReadableNBT> getter) {
NBTEntity nbt = new NBTEntity(entity, true);
getter.accept(nbt);
nbt.setClosed();
}
/**
* It takes a block state and a function that takes a readable NBT and returns a
* value of type T. It then returns the value of the function applied to a new
* NBTTileEntity created from the block state
*
* @param blockState The block state of the block you want to get the NBT from.
* @param getter A function that takes a ReadableNBT and returns a value of
* type T.
* @return The return type is the same as the type of the getter function.
*/
public static <T> T get(BlockState blockState, Function<ReadableNBT, T> getter) {
NBTTileEntity nbt = new NBTTileEntity(blockState, true);
T ret = getter.apply(nbt);
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
nbt.setClosed();
return ret;
}
/**
* It takes an BlockEntity, and a Consumer that takes a ReadableNBT. Applies the
* Consumer on the NBT of the BlockEntity
*
* @param blockState The block state of the block you want to get the NBT from.
*/
public static void get(BlockState blockState, Consumer<ReadableNBT> getter) {
NBTTileEntity nbt = new NBTTileEntity(blockState, true);
getter.accept(nbt);
nbt.setClosed();
}
/**
* It takes an entity and a function that takes a ReadableNBT and returns a
* generic type T, and returns the result of the function, applied to the
* entities persistent data container
*
* @param entity The entity to get the data from
* @param getter A function that takes a ReadableNBT and returns a value of type
* T.
* @return The return type is T, which is a generic type.
*/
public static <T> T getPersistentData(Entity entity, Function<ReadableNBT, T> getter) {
T ret = getter.apply(new NBTEntity(entity).getPersistentDataContainer());
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
return ret;
}
/**
* It takes a block entity and a function that takes a ReadableNBT and returns a
* generic type T, and returns the result of the function, applied to the block
* entities persistent data container
*
* @param blockState The block state of the block you want to get the data from.
* @param getter A function that takes a ReadableNBT and returns a value of
* type T.
* @return The value of the NBT tag.
*/
public static <T> T getPersistentData(BlockState blockState, Function<ReadableNBT, T> getter) {
T ret = getter.apply(new NBTTileEntity(blockState).getPersistentDataContainer());
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
return ret;
}
/**
* It takes an ItemStack, applies a function to its NBT, and returns the result
* of the function
*
* @param item The item you want to modify
* @param function The function that will be applied to the item.
* @return The return value of the function.
*/
public static <T> T modify(ItemStack item, Function<ReadWriteItemNBT, T> function) {
NBTItem nbti = new NBTItem(item, false, false, true);
T val = function.apply(nbti);
nbti.finalizeChanges();
if (val instanceof ReadableNBT || val instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
nbti.setClosed();
return val;
}
/**
* It takes an ItemStack and a Consumer&lt;ReadWriteNBT&gt;, and then applies
* the Consumer to the ItemStacks NBT
*
* @param item The item you want to modify
* @param consumer The consumer that will be used to modify the NBT.
*/
public static void modify(ItemStack item, Consumer<ReadWriteItemNBT> consumer) {
NBTItem nbti = new NBTItem(item, false, false, true);
consumer.accept(nbti);
nbti.finalizeChanges();
nbti.setClosed();
}
/**
* It takes an entity and a function that takes a ReadWriteNBT and returns a
* generic type T. It then returns the result of the function
*
* @param entity The entity to modify
* @param function The function that will be called.
* @return The return type is the same as the return type of the function.
*/
public static <T> T modify(Entity entity, Function<ReadWriteNBT, T> function) {
NBTEntity nbtEnt = new NBTEntity(entity);
NBTContainer cont = new NBTContainer(nbtEnt.getCompound());
T ret = function.apply(cont);
nbtEnt.setCompound(cont.getCompound());
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
nbtEnt.setClosed();
return ret;
}
/**
* It takes an ItemStack and a Consumer&lt;ReadWriteNBT&gt;, and then applies
* the Consumer to the ItemStacks Components as NBT. This is for 1.20.5+ only.
* This method is quite expensive, so don't overuse it.
*
* @param item The item you want to modify the components of
* @param consumer The consumer that will be used to modify the components.
*/
public static void modifyComponents(ItemStack item, Consumer<ReadWriteNBT> consumer) {
if (!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException("This method only works for 1.20.5+!");
}
ReadWriteNBT nbti = NBT.itemStackToNBT(item);
consumer.accept(nbti.getOrCreateCompound("components"));
ItemStack tmp = NBT.itemStackFromNBT(nbti);
item.setItemMeta(tmp.getItemMeta());
}
/**
* It takes an ItemStack and a Consumer&lt;ReadWriteNBT&gt;, and then applies
* the Consumer to the ItemStacks Components as NBT. This is for 1.20.5+ only.
* This method is quite expensive, so don't overuse it.
*
* @param item The item you want to modify the components of
* @param function The consumer that will be used to modify the components.
* @return The return type is the same as the return type of the function.
*/
public static <T> T modifyComponents(ItemStack item, Function<ReadWriteNBT, T> function) {
if (!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException("This method only works for 1.20.5+!");
}
ReadWriteNBT nbti = NBT.itemStackToNBT(item);
T ret = function.apply(nbti.getOrCreateCompound("components"));
ItemStack tmp = NBT.itemStackFromNBT(nbti);
item.setItemMeta(tmp.getItemMeta());
return ret;
}
/**
* It takes an ItemStack and a Consumer&lt;ReadWriteNBT&gt;, and then applies
* the Consumer to the ItemStacks Components as NBT. This is for 1.20.5+ only.
* This method is quite expensive, try to cache the results/use it smartly.
*
* @param item The item you want to read the components of
* @param consumer The consumer that will be used to read the components.
*/
public static void getComponents(ItemStack item, Consumer<ReadableNBT> consumer) {
if (!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException("This method only works for 1.20.5+!");
}
ReadWriteNBT nbti = NBT.itemStackToNBT(item);
consumer.accept(nbti.getOrCreateCompound("components"));
}
/**
* It takes an ItemStack and a Consumer&lt;ReadWriteNBT&gt;, and then applies
* the Consumer to the ItemStacks Components as NBT. This is for 1.20.5+ only.
* This method is quite expensive, try to cache the results/use it smartly.
*
* @param item The item you want to read the components of
* @param function The consumer that will be used to read the components.
* @return The return type is the same as the return type of the function.
*/
public static <T> T getComponents(ItemStack item, Function<ReadableNBT, T> function) {
if (!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException("This method only works for 1.20.5+!");
}
ReadWriteNBT nbti = NBT.itemStackToNBT(item);
return function.apply(nbti.getOrCreateCompound("components"));
}
/**
* It takes an entity and a function that takes a ReadWriteNBT and applies the
* function to the entity
*
* @param entity The entity to modify
* @param consumer The consumer that will be called with the NBTEntity.
*/
public static void modify(Entity entity, Consumer<ReadWriteNBT> consumer) {
NBTEntity nbtEnt = new NBTEntity(entity);
NBTContainer cont = new NBTContainer(nbtEnt.getCompound());
consumer.accept(cont);
nbtEnt.setCompound(cont.getCompound());
nbtEnt.setClosed();
}
/**
* It takes an entity and a function that takes a ReadWriteNBT from the entities
* persistent data and returns a generic type T. It then returns the result of
* the function
*
* @param entity The entity to modify the data of.
* @param function The function that will be called.
* @return The return type is the same as the return type of the function.
*/
public static <T> T modifyPersistentData(Entity entity, Function<ReadWriteNBT, T> function) {
T ret = function.apply(new NBTEntity(entity).getPersistentDataContainer());
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
return ret;
}
/**
* It allows you to modify the persistent data of an entity without any return
* value
*
* @param entity The entity to modify
* @param consumer The consumer that will be used to modify the persistent data.
*/
public static void modifyPersistentData(Entity entity, Consumer<ReadWriteNBT> consumer) {
consumer.accept(new NBTEntity(entity).getPersistentDataContainer());
}
/**
* It takes a block state and a function that takes a ReadWriteNBT and returns a
* generic type T. It then returns the result of the function
*
* @param blockState The blockstate you want to modify
* @param function The function that will be called.
* @return The return type is the same as the return type of the function.
*/
public static <T> T modify(BlockState blockState, Function<ReadWriteNBT, T> function) {
NBTTileEntity blockEnt = new NBTTileEntity(blockState);
NBTContainer cont = new NBTContainer(blockEnt.getCompound());
T ret = function.apply(cont);
blockEnt.setCompound(cont.getCompound());
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
blockEnt.setClosed();
return ret;
}
/**
* It takes a block state and a consumer, and then it creates a new
* NBTTileEntity object with the block state, and then it passes that
* NBTTileEntity object to the consumer
*
* @param blockState The blockstate you want to modify
* @param consumer A Consumer&lt;ReadWriteNBT&gt;. This is a function that
* takes a ReadWriteNBT and does something with it.
*/
public static void modify(BlockState blockState, Consumer<ReadWriteNBT> consumer) {
NBTTileEntity blockEnt = new NBTTileEntity(blockState);
NBTContainer cont = new NBTContainer(blockEnt.getCompound());
consumer.accept(cont);
blockEnt.setCompound(cont.getCompound());
blockEnt.setClosed();
}
/**
* It takes a block state and a function that takes a ReadWriteNBT of the block
* entities persistent data and returns a generic type T. It then returns the
* result of the function
*
* @param blockState The block state of the block you want to modify.
* @param function The function that will be called to modify the NBT data.
* @return The return type is the same as the return type of the function.
*/
public static <T> T modifyPersistentData(BlockState blockState, Function<ReadWriteNBT, T> function) {
T ret = function.apply(new NBTTileEntity(blockState).getPersistentDataContainer());
if (ret instanceof ReadableNBT || ret instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
return ret;
}
/**
* It takes a block state and a consumer, and then it calls the consumer with
* the persistent data container of the block entity
*
* @param blockState The block state of the block you want to modify.
* @param consumer A Consumer&lt;ReadWriteNBT&gt;. This is a function that
* takes a ReadWriteNBT and does something with it.
*/
public static void modifyPersistentData(BlockState blockState, Consumer<ReadWriteNBT> consumer) {
consumer.accept(new NBTTileEntity(blockState).getPersistentDataContainer());
}
/**
* It converts a GameProfile object to a ReadWriteNBT object
*
* @param profile The GameProfile to convert to NBT
* @return A ReadWriteNBT object.
*/
public static ReadWriteNBT gameProfileToNBT(GameProfile profile) {
return NBTGameProfile.toNBT(profile);
}
/**
* It takes a NBT compound and returns a GameProfile
*
* @param compound The NBT tag to read the GameProfile from.
* @return A GameProfile object.
*/
public static GameProfile gameProfileFromNBT(ReadableNBT compound) {
return NBTGameProfile.fromNBT((NBTCompound) compound);
}
/**
* It converts an ItemStack to a ReadWriteNBT object
*
* @param itemStack The item stack you want to convert to NBT.
* @return A ReadWriteNBT object.
*/
public static ReadWriteNBT itemStackToNBT(ItemStack itemStack) {
return NBTItem.convertItemtoNBT(itemStack);
}
/**
* It converts a ReadableNBT object into an ItemStack
*
* @param compound The NBT tag to convert to an ItemStack
* @return An ItemStack
*/
@Nullable
public static ItemStack itemStackFromNBT(ReadableNBT compound) {
return NBTItem.convertNBTtoItem((NBTCompound) compound);
}
/**
* It converts an array of ItemStacks into a ReadWriteNBT object
*
* @param itemStacks The ItemStack[] you want to convert to NBT
* @return An NBTItem object.
*/
public static ReadWriteNBT itemStackArrayToNBT(ItemStack[] itemStacks) {
return NBTItem.convertItemArraytoNBT(itemStacks);
}
/**
* It converts a ReadableNBT object into an array of ItemStacks
*
* @param compound The NBT tag to convert to an ItemStack array.
* @return An array of ItemStacks.
*/
@Nullable
public static ItemStack[] itemStackArrayFromNBT(ReadableNBT compound) {
return NBTItem.convertNBTtoItemArray((NBTCompound) compound);
}
/**
* Create a new NBTContainer object and return it.
*
* @return A new instance of the NBTContainer class.
*/
public static ReadWriteNBT createNBTObject() {
return new NBTContainer();
}
/**
* It takes a nbt json string, and returns a ReadWriteNBT object
*
* @param nbtString The NBT string to parse.
* @return A new ReadWriteNBT object.
*/
public static ReadWriteNBT parseNBT(String nbtString) {
return new NBTContainer(nbtString);
}
/**
* Reads in an NBT stream and returns a ReadWriteNBT object
*
* @param stream The NBT stream to read.
* @return A new ReadWriteNBT object.
*/
public static ReadWriteNBT readNBT(InputStream stream) {
return new NBTContainer(stream);
}
/**
* Helper method for other developers using NMS. Allows to wrap any
* net.minecraft.nbt.CompoundTag to a NBTAPI ReadWriteNBT object.
*
* @param nmsNbtTag Needs to be a valid net.minecraft.nbt.CompoundTag
* @return A new ReadWriteNBT object.
*/
public static ReadWriteNBT wrapNMSTag(Object nmsNbtTag) {
return new NBTContainer(nmsNbtTag);
}
/**
* Creates a NBTFileHandle that uses @param file to store its data. If this file
* exists, the data will be loaded, otherwise a new file gets created.
*
* @param file
* @throws IOException
*/
public static NBTFileHandle getFileHandle(File file) throws IOException {
return new NBTFile(file);
}
/**
* Reads NBT data from the provided file.
* <p>
* Returns an empty tag if the file does not exist.
*
* @param file file to read
* @return ReadWriteNBT of the files data
* @throws IOException exception
*/
public static ReadWriteNBT readFile(File file) throws IOException {
return NBTFile.readFrom(file);
}
/**
* Saves NBT data to the provided file.
* <p>
* Will fully override the file if it already exists.
*
* @param file file
* @param nbt NBT data
* @throws IOException exception
*/
public static void writeFile(File file, ReadWriteNBT nbt) throws IOException {
NBTFile.saveTo(file, (NBTCompound) nbt);
}
/**
* Create a read only proxy class for NBT, given an annotated interface.
*
* @param <T>
* @param item
* @param wrapper
* @return
*/
public static <T extends NBTProxy> T readNbt(ItemStack item, Class<T> wrapper) {
return new ProxyBuilder<>(new NBTItem(item, false, true, false), wrapper).readOnly().build();
}
/**
* Create a read only proxy class for NBT, given an annotated interface.
*
* @param <T>
* @param entity
* @param wrapper
* @return
*/
public static <T extends NBTProxy> T readNbt(Entity entity, Class<T> wrapper) {
return new ProxyBuilder<>(new NBTEntity(entity, true), wrapper).readOnly().build();
}
/**
* Create a read only proxy class for NBT, given an annotated interface.
*
* @param <T>
* @param blockState
* @param wrapper
* @return
*/
public static <T extends NBTProxy> T readNbt(BlockState blockState, Class<T> wrapper) {
return new ProxyBuilder<>(new NBTTileEntity(blockState, true), wrapper).readOnly().build();
}
/**
* It takes an ItemStack, applies a function to its NBT wrapped in a proxy, and
* returns the result of the function
*
* @param item The item you want to
* @param wrapper The target Proxy class
* @param function The function that will be applied to the item.
* @return The return value of the function.
*/
public static <T, X extends NBTProxy> T modify(ItemStack item, Class<X> wrapper, Function<X, T> function) {
NBTItem nbti = new NBTItem(item, false, false, true);
T val = function.apply(new ProxyBuilder<>(nbti, wrapper).build());
nbti.finalizeChanges();
if (val instanceof ReadableNBT || val instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
nbti.setClosed();
return val;
}
/**
* It takes an ItemStack, applies a function to its NBT wrapped in a proxy.
*
* @param item The item you want to modify
* @param wrapper The target Proxy class
* @param consumer The consumer that will be used to modify the NBT.
*/
public static <X extends NBTProxy> void modify(ItemStack item, Class<X> wrapper, Consumer<X> consumer) {
NBTItem nbti = new NBTItem(item, false, false, true);
consumer.accept(new ProxyBuilder<>(nbti, wrapper).build());
nbti.finalizeChanges();
nbti.setClosed();
}
/**
* It takes an entity and a function to modify the entity via the proxy
*
* @param entity The entity to modify
* @param wrapper The target Proxy class
* @param consumer The consumer that will be called with the proxy.
*/
public static <X extends NBTProxy> void modify(Entity entity, Class<X> wrapper, Consumer<X> consumer) {
NBTEntity nbtEnt = new NBTEntity(entity);
NBTContainer cont = new NBTContainer(nbtEnt.getCompound());
consumer.accept(new ProxyBuilder<>(cont, wrapper).build());
nbtEnt.setCompound(cont.getCompound());
cont.setClosed();
}
/**
* It takes an entity and a function to modify the entity via the proxy
*
* @param entity The entity to modify
* @param wrapper The target Proxy class
* @param function The Function that will be called with the proxy.
* @return The return value of the function.
*/
public static <T, X extends NBTProxy> T modify(Entity entity, Class<X> wrapper, Function<X, T> function) {
NBTEntity nbtEnt = new NBTEntity(entity);
NBTContainer cont = new NBTContainer(nbtEnt.getCompound());
T val = function.apply(new ProxyBuilder<>(cont, wrapper).build());
nbtEnt.setCompound(cont.getCompound());
cont.setClosed();
return val;
}
/**
* It takes an block entity and a function to modify the entity via the proxy
*
* @param blockState The blockstate you want to modify
* @param wrapper The target Proxy class
* @param consumer The Consumer that will be called.
*/
public static <X extends NBTProxy> void modify(BlockState blockState, Class<X> wrapper, Consumer<X> consumer) {
NBTTileEntity blockEnt = new NBTTileEntity(blockState);
NBTContainer cont = new NBTContainer(blockEnt.getCompound());
consumer.accept(new ProxyBuilder<>(cont, wrapper).build());
blockEnt.setCompound(cont);
cont.setClosed();
}
/**
* It takes an block entity and a function to modify the entity via the proxy
*
* @param blockState The blockstate you want to modify
* @param wrapper The target Proxy class
* @param function The function that will be called.
* @return The return value of the function.
*/
public static <T, X extends NBTProxy> T modify(BlockState blockState, Class<X> wrapper, Function<X, T> function) {
NBTTileEntity blockEnt = new NBTTileEntity(blockState);
NBTContainer cont = new NBTContainer(blockEnt.getCompound());
T val = function.apply(new ProxyBuilder<>(cont, wrapper).build());
blockEnt.setCompound(cont);
cont.setClosed();
return val;
}
/**
* Reads block‑specific data that was previously stored in the chunk's
* persistent data container.
* <p>
* The data is stored inside the {@code blocks} compound of the chunk's
* persistent data container, using a key formed as {@code X_Y_Z} where
* X, Y, Z are the block's coordinates.
* <p>
* <b>Minecraft version:</b> this method requires <b>1.16.4 or newer</b>.
*
* @param block the block whose stored data is to be read
* @param consumer the consumer that receives a {@link ReadableNBT} view of the data
*/
public static void readChunkPDC(Block block, Consumer<ReadableNBT> consumer) {
processBlockChunkPDC(block, false, nbt -> {
consumer.accept(nbt);
return null;
});
}
/**
* Reads block‑specific data from the chunk's persistent data container and
* applies a function to produce a result.
* <p>
* The data is stored inside the {@code blocks} compound of the chunk's
* persistent data container, using a key formed as {@code X_Y_Z} where
* X, Y, Z are the block's coordinates.
* <p>
* <b>Minecraft version:</b> this method requires <b>1.16.4 or newer</b>.
*
* @param block the block whose stored data is to be read
* @param function the function that processes the {@link ReadableNBT} and
* returns a value
* @param <T> the type of the returned value
* @return the result of the function applied to the data
*/
public static <T> T readAndGetChunkPDC(Block block, Function<ReadableNBT, T> function) {
return processBlockChunkPDC(block, false, function::apply);
}
/**
* Modifies block‑specific data stored in the chunk's persistent data container.
* <p>
* The data is stored inside the {@code blocks} compound of the chunk's
* persistent data container, using a key formed as {@code X_Y_Z} where
* X, Y, Z are the block's coordinates.
* <p>
* <b>Caution:</b> the data remains even if the block is broken, replaced, moved,
* or exploded, etc. You should manually remove the data when it is no longer needed.
* <p>
* <b>Minecraft version:</b> this method requires <b>1.16.4 or newer</b>.
*
* @param block the block whose data is to be modified
* @param consumer the consumer that receives the {@link ReadWriteNBT} and
* applies modifications
*/
public static void modifyChunkPDC(Block block, Consumer<ReadWriteNBT> consumer) {
processBlockChunkPDC(block, true, nbt -> {
consumer.accept(nbt);
return null;
});
}
/**
* Modifies block‑specific data in the chunk's persistent data container and
* returns a result computed from the modified data.
* <p>
* The data is stored inside the {@code blocks} compound of the chunk's
* persistent data container, using a key formed as {@code X_Y_Z} where
* X, Y, Z are the block's coordinates.
* <p>
* <b>Caution:</b> the data remains even if the block is broken, replaced, moved,
* or exploded, etc. You should manually remove the data when it is no longer needed.
* <p>
* <b>Minecraft version:</b> this method requires <b>1.16.4 or newer</b>.
*
* @param block the block whose data is to be modified
* @param function the function that receives the {@link ReadWriteNBT}, modifies
* it, and returns a value
* @param <T> the type of the returned value
* @return the result of the function after modification
*/
public static <T> T modifyAndGetChunkPDC(Block block, Function<ReadWriteNBT, T> function) {
return processBlockChunkPDC(block, true, function::apply);
}
private static <T> T processBlockChunkPDC(Block block, boolean createIfAbsent, Function<NBTCompound, T> action) {
CheckUtil.assertAvailable(MinecraftVersion.MC1_16_R3);
String blockKey = block.getX() + "_" + block.getY() + "_" + block.getZ();
NBTCompound chunkData = new NBTPersistentDataContainer(block.getChunk().getPersistentDataContainer(), !createIfAbsent);
NBTCompound blocksData = createIfAbsent
? chunkData.getOrCreateCompound("blocks")
: chunkData.getCompound("blocks");
NBTCompound blockData;
if (createIfAbsent) {
blockData = blocksData.getOrCreateCompound(blockKey);
} else {
blockData = blocksData == null ? null : blocksData.getCompound(blockKey);
if (blockData == null) {
blockData = new NBTContainer().setReadOnly(true);
}
}
T result = action.apply(blockData);
if (createIfAbsent) {
if (blockData.isEmpty()) {
blocksData.removeKey(blockKey);
}
if (blocksData.isEmpty()) {
chunkData.removeKey("blocks");
}
}
if (result instanceof ReadableNBT || result instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
return result;
}
/**
* Reads the chunk's persistent data container.
* <p>
* <b>Minecraft version:</b> this method requires <b>1.16.4 or newer</b>.
*
* @param chunk the chunk whose persistent data is to be read
* @param consumer the consumer that receives a {@link ReadableNBT} view of the data
*/
public static void readChunkPDC(Chunk chunk, Consumer<ReadableNBT> consumer) {
processChunkPDC(chunk, false, nbt -> {
consumer.accept(nbt);
return null;
});
}
/**
* Reads the chunk's persistent data container and applies a function to produce a result.
* <p>
* <b>Minecraft version:</b> this method requires <b>1.16.4 or newer</b>.
*
* @param chunk the chunk whose persistent data is to be read
* @param function the function that processes the {@link ReadableNBT} and
* returns a value
* @param <T> the type of the returned value
* @return the result of the function applied to the data
*/
public static <T> T readAndGetChunkPDC(Chunk chunk, Function<ReadableNBT, T> function) {
return processChunkPDC(chunk, false, function::apply);
}
/**
* Modifies the chunk's persistent data container.
* <p>
* <b>Minecraft version:</b> this method requires <b>1.16.4 or newer</b>.
*
* @param chunk the chunk whose persistent data is to be modified
* @param consumer the consumer that receives the {@link ReadWriteNBT} and
* applies modifications
*/
public static void modifyChunkPDC(Chunk chunk, Consumer<ReadWriteNBT> consumer) {
processChunkPDC(chunk, true, nbt -> {
consumer.accept(nbt);
return null;
});
}
/**
* Modifies the chunk's persistent data container and returns a result computed from the modified data.
* <p>
* <b>Minecraft version:</b> this method requires <b>1.16.4 or newer</b>.
*
* @param chunk the chunk whose persistent data is to be modified
* @param function the function that receives the {@link ReadWriteNBT}, modifies
* it, and returns a value
* @param <T> the type of the returned value
* @return the result of the function after modification
*/
public static <T> T modifyAndGetChunkPDC(Chunk chunk, Function<ReadWriteNBT, T> function) {
return processChunkPDC(chunk, true, function::apply);
}
private static <T> T processChunkPDC(Chunk chunk, boolean createIfAbsent, Function<NBTCompound, T> action) {
CheckUtil.assertAvailable(MinecraftVersion.MC1_16_R3);
NBTCompound chunkData = new NBTPersistentDataContainer(chunk.getPersistentDataContainer(), !createIfAbsent);
T result = action.apply(chunkData);
if (result instanceof ReadableNBT || result instanceof ReadableNBTList<?>) {
throw new NbtApiException("Tried returning part of the NBT to outside of the NBT scope!");
}
return result;
}
}
@@ -0,0 +1,46 @@
package de.tr7zw.changeme.nbtapi;
import org.bukkit.block.Block;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* Helper class to store NBT data to Block Locations. Use getData() to get the
* NBT instance. Important notes:
* <p>
* - Non BlockEntities can not have NBT data. This stores the data to the chunk
* instead!
* <p>
* - The data is really just on the location. If the block gets
* broken/changed/exploded/moved etc., the data is still on that location!
*
* @author tr7zw
* @deprecated use methods in {@link NBT} class to read/modify block's NBT
*/
@Deprecated
public class NBTBlock {
private final Block block;
private final NBTChunk nbtChunk;
public NBTBlock(Block block) {
this.block = block;
if (!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R3)) {
throw new NbtApiException("NBTBlock is only working for 1.16.4+!");
}
nbtChunk = new NBTChunk(block.getChunk());
}
/**
* Gets the block NBT data stored within the chunk's PDC.
*
* @return block NBT data
* @deprecated use methods in {@link NBT} class to read/modify block's NBT
*/
@Deprecated
public NBTCompound getData() {
return nbtChunk.getPersistentDataContainer().getOrCreateCompound("blocks")
.getOrCreateCompound(block.getX() + "_" + block.getY() + "_" + block.getZ());
}
}
@@ -0,0 +1,33 @@
package de.tr7zw.changeme.nbtapi;
import org.bukkit.Chunk;
import de.tr7zw.changeme.nbtapi.utils.CheckUtil;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* Helper class to store NBT data to {@link Chunk}'s PDC (persistent data container).
*
* @deprecated use methods in {@link NBT} class to read/modify chunk's nbt
*/
@Deprecated
public class NBTChunk {
private final Chunk chunk;
public NBTChunk(Chunk chunk) {
this.chunk = chunk;
}
/**
* Gets the NBTCompound used by spigots PersistentDataAPI. This method is only
* available for 1.16.4+!
*
* @return NBTCompound containing the data of the PersistentDataAPI
*/
public NBTCompound getPersistentDataContainer() {
CheckUtil.assertAvailable(MinecraftVersion.MC1_16_R3);
return new NBTPersistentDataContainer(chunk.getPersistentDataContainer());
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,123 @@
package de.tr7zw.changeme.nbtapi;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBTCompoundList;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* {@link NBTListCompound} implementation for NBTLists
*
* @author tr7zw
*
*/
public class NBTCompoundList extends NBTList<ReadWriteNBT> implements ReadWriteNBTCompoundList {
protected NBTCompoundList(NBTCompound owner, String name, NBTType type, Object list) {
super(owner, name, type, list);
}
/**
* Adds a new Compound to the end of the List and returns it.
*
* @return The added {@link NBTListCompound}
*/
public NBTListCompound addCompound() {
return (NBTListCompound) addCompound(null);
}
/**
* Adds a copy of the Compound to the end of the List and returns it. When null
* is given, a new Compound will be created
*
* @param comp
* @return
*/
public NBTCompound addCompound(NBTCompound comp) {
if (getParent().isReadOnly()) {
throw new NbtApiException("Tried setting data in read only mode!");
}
try {
Object compound = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
ReflectionMethod.LIST_ADD.run(listObject, size(), compound);
} else {
ReflectionMethod.LEGACY_LIST_ADD.run(listObject, compound);
}
getParent().saveCompound();
NBTListCompound listcomp = new NBTListCompound(this, compound);
if (comp != null) {
listcomp.mergeCompound(comp);
}
return listcomp;
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
@Override
public ReadWriteNBT addCompound(ReadableNBT comp) {
if (comp instanceof NBTCompound) {
return addCompound((NBTCompound) comp);
}
return null;
}
/**
* Adds a new Compound to the end of the List.
*
*
* @deprecated Please use addCompound!
* @param empty
* @return True, if compound was added
*/
@Override
@Deprecated
public boolean add(ReadWriteNBT empty) {
return addCompound(empty) != null;
}
@Override
public void add(int index, ReadWriteNBT element) {
if (element != null) {
throw new NbtApiException("You need to pass null! ListCompounds from other lists won't work.");
}
if (getParent().isReadOnly()) {
throw new NbtApiException("Tried setting data in read only mode!");
}
try {
Object compound = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
ReflectionMethod.LIST_ADD.run(listObject, index, compound);
} else {
ReflectionMethod.LEGACY_LIST_ADD.run(listObject, compound);
}
super.getParent().saveCompound();
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
@Override
public NBTListCompound get(int index) {
try {
Object compound = ReflectionMethod.LIST_GET_COMPOUND.run(listObject, index);
return new NBTListCompound(this, compound);
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
@Override
public NBTListCompound set(int index, ReadWriteNBT element) {
throw new NbtApiException("This method doesn't work in the ListCompound context.");
}
@Override
protected Object asTag(ReadWriteNBT object) {
return null;
}
}
@@ -0,0 +1,112 @@
package de.tr7zw.changeme.nbtapi;
import java.io.InputStream;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ObjectCreator;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* A Standalone {@link NBTCompound} implementation. All data is just kept inside
* this Object.
*
* @author tr7zw
*
*/
public class NBTContainer extends NBTCompound {
private Object nbt;
private boolean closed;
private boolean readOnly;
/**
* Creates an empty, standalone NBTCompound
*
* @deprecated use {@link NBT#createNBTObject()}
*/
@Deprecated
public NBTContainer() {
super(null, null);
nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
/**
* Takes in any NMS Compound to wrap it
*
* @param nbt
* @deprecated Use NBT.wrapNMSTag
*/
@Deprecated
public NBTContainer(Object nbt) {
super(null, null);
if (nbt == null) {
nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().isAssignableFrom(nbt.getClass())) {
throw new NbtApiException("The object '" + nbt.getClass() + "' is not a valid NBT-Object!");
}
this.nbt = nbt;
}
/**
* Reads in a NBT InputStream
*
* @param inputsteam
* @deprecated Use NBT.readNBT
*/
@Deprecated
public NBTContainer(InputStream inputsteam) {
super(null, null);
this.nbt = NBTReflectionUtil.readNBT(inputsteam);
}
/**
* Parses in a NBT String to a standalone {@link NBTCompound}. Can throw a
* {@link NbtApiException} in case something goes wrong.
*
* @param nbtString
* @deprecated Use NBT.parseNBT
*/
@Deprecated
public NBTContainer(String nbtString) {
super(null, null);
if (nbtString == null) {
throw new NullPointerException("The String can't be null!");
}
try {
nbt = ReflectionMethod.PARSE_NBT.run(null, nbtString);
} catch (Exception ex) {
throw new NbtApiException("Unable to parse Malformed Json!", ex);
}
}
@Override
public Object getCompound() {
return nbt;
}
@Override
public void setCompound(Object tag) {
nbt = tag;
}
@Override
protected void setClosed() {
this.closed = true;
}
@Override
protected boolean isClosed() {
return closed;
}
protected boolean isReadOnly() {
return readOnly;
}
protected NBTContainer setReadOnly(boolean readOnly) {
this.readOnly = true;
return this;
}
}
@@ -0,0 +1,45 @@
package de.tr7zw.changeme.nbtapi;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* Double implementation for NBTLists
*
* @author tr7zw
*
*/
public class NBTDoubleList extends NBTList<Double> {
protected NBTDoubleList(NBTCompound owner, String name, NBTType type, Object list) {
super(owner, name, type, list);
}
@Override
protected Object asTag(Double object) {
try {
Constructor<?> con = ClassWrapper.NMS_NBTTAGDOUBLE.getClazz().getDeclaredConstructor(double.class);
con.setAccessible(true);
return con.newInstance(object);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
}
}
@Override
public Double get(int index) {
try {
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
return Double.valueOf(obj.toString());
} catch (NumberFormatException nf) {
return 0d;
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
}
@@ -0,0 +1,105 @@
package de.tr7zw.changeme.nbtapi;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import de.tr7zw.changeme.nbtapi.utils.CheckUtil;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* NBT class to access vanilla tags from Entities. Entities don't support custom
* tags. Use the NBTInjector for custom tags. Changes will be instantly applied
* to the Entity, use the merge method to do many things at once.
*
* @author tr7zw
*
*/
public class NBTEntity extends NBTCompound {
private final Entity ent;
private final boolean readonly;
private final Object compound;
private boolean closed = false;
/**
* @param entity Any valid Bukkit Entity
* @param readonly Readonly makes a copy at init, only reading from that copy
*/
protected NBTEntity(Entity entity, boolean readonly) {
super(null, null);
if (entity == null) {
throw new NullPointerException("Entity can't be null!");
}
this.readonly = readonly;
ent = entity;
if (readonly) {
this.compound = getCompound();
} else {
this.compound = null;
}
}
/**
* Deprecated: Please use the NBT class
*
* @param entity Any valid Bukkit Entity
*/
@Deprecated
public NBTEntity(Entity entity) {
super(null, null);
if (entity == null) {
throw new NullPointerException("Entity can't be null!");
}
this.readonly = false;
this.compound = null;
ent = entity;
}
@Override
protected void setClosed() {
this.closed = true;
}
@Override
protected boolean isClosed() {
return closed;
}
@Override
protected boolean isReadOnly() {
return readonly;
}
@Override
public Object getCompound() {
// this runs before async check, since it's just a copy
if (readonly && compound != null) {
return compound;
}
if (!Bukkit.isPrimaryThread())
throw new NbtApiException("Entity NBT needs to be accessed sync!");
return NBTReflectionUtil.getEntityNBTTagCompound(NBTReflectionUtil.getNMSEntity(ent));
}
@Override
protected void setCompound(Object compound) {
if (readonly) {
throw new NbtApiException("Tried setting data in read only mode!");
}
if (!Bukkit.isPrimaryThread())
throw new NbtApiException("Entity NBT needs to be accessed sync!");
NBTReflectionUtil.setEntityNBTTag(compound, NBTReflectionUtil.getNMSEntity(ent));
}
/**
* Gets the NBTCompound used by spigots PersistentDataAPI. This method is only
* available for 1.14+!
*
* @return NBTCompound containing the data of the PersistentDataAPI
*/
public NBTCompound getPersistentDataContainer() {
CheckUtil.assertAvailable(MinecraftVersion.MC1_14_R1);
return new NBTPersistentDataContainer(ent.getPersistentDataContainer());
}
}
@@ -0,0 +1,114 @@
package de.tr7zw.changeme.nbtapi;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import de.tr7zw.changeme.nbtapi.iface.NBTFileHandle;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ObjectCreator;
/**
* {@link NBTCompound} implementation backed by a {@link File}
*
* @author tr7zw
*
*/
public class NBTFile extends NBTCompound implements NBTFileHandle {
private final File file;
private Object nbt;
/**
* Creates a NBTFile that uses @param file to store its data. If this file
* exists, the data will be loaded.
*
* @param file
* @throws IOException
* @deprecated Use NBT.getFileHandle(file)
*/
@Deprecated
public NBTFile(File file) throws IOException {
super(null, null);
if (file == null) {
throw new NullPointerException("File can't be null!");
}
this.file = file;
if (file.exists()) {
nbt = NBTReflectionUtil.readNBT(Files.newInputStream(file.toPath()));
} else {
nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
save();
}
}
/**
* Saves the data to the file
*
* @throws IOException
*/
@Override
public void save() throws IOException {
try {
getWriteLock().lock();
saveTo(file, this);
} finally {
getWriteLock().unlock();
}
}
/**
* @return The File used to store the data
*/
@Override
public File getFile() {
return file;
}
@Override
public Object getCompound() {
return nbt;
}
@Override
protected void setCompound(Object compound) {
nbt = compound;
}
/**
* Reads NBT data from the provided file.
* <p>
* Returns empty NBTContainer if file does not exist.
*
* @param file file to read
* @return NBTCompound holding file's nbt data
* @throws IOException exception
* @deprecated Use NBT.readFile(file)
*/
@Deprecated
public static NBTCompound readFrom(File file) throws IOException {
if (!file.exists())
return new NBTContainer();
return new NBTContainer(NBTReflectionUtil.readNBT(Files.newInputStream(file.toPath())));
}
/**
* Saves NBT data to the provided file.
* <p>
* Will fully override the file if it already exists.
*
* @param file file
* @param nbt NBT data
* @throws IOException exception
* @deprecated Use NBT.writeFile(file, nbt)
*/
@Deprecated
public static void saveTo(File file, NBTCompound nbt) throws IOException {
if (!file.exists()) {
file.getParentFile().mkdirs();
if (!file.createNewFile())
throw new IOException("Unable to create file at " + file.getAbsolutePath());
}
nbt.writeCompound(Files.newOutputStream(file.toPath()));
}
}
@@ -0,0 +1,45 @@
package de.tr7zw.changeme.nbtapi;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* Float implementation for NBTLists
*
* @author tr7zw
*
*/
public class NBTFloatList extends NBTList<Float> {
protected NBTFloatList(NBTCompound owner, String name, NBTType type, Object list) {
super(owner, name, type, list);
}
@Override
protected Object asTag(Float object) {
try {
Constructor<?> con = ClassWrapper.NMS_NBTTAGFLOAT.getClazz().getDeclaredConstructor(float.class);
con.setAccessible(true);
return con.newInstance(object);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
}
}
@Override
public Float get(int index) {
try {
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
return Float.valueOf(obj.toString());
} catch (NumberFormatException nf) {
return 0f;
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
}
@@ -0,0 +1,42 @@
package de.tr7zw.changeme.nbtapi;
import com.mojang.authlib.GameProfile;
import de.tr7zw.changeme.nbtapi.utils.GameprofileUtil;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ObjectCreator;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
public class NBTGameProfile {
/**
* Convert a GameProfile to NBT. The NBT then can be modified or be stored
*
* @param profile
* @return A NBTContainer with all the GameProfile data
*/
@Deprecated
public static NBTCompound toNBT(GameProfile profile) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
return (NBTCompound) GameprofileUtil.writeGameProfile(NBT.createNBTObject(), profile);
}
return new NBTContainer(ReflectionMethod.GAMEPROFILE_SERIALIZE.run(null,
ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance(), profile));
}
/**
* Reconstructs a GameProfile from a NBTCompound
*
* @param compound Has to contain GameProfile data
* @return The reconstructed GameProfile
*/
@Deprecated
public static GameProfile fromNBT(NBTCompound compound) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
return GameprofileUtil.readGameProfile(compound);
}
return (GameProfile) ReflectionMethod.GAMEPROFILE_DESERIALIZE.run(null,
NBTReflectionUtil.getToCompount(compound.getCompound(), compound));
}
}
@@ -0,0 +1,51 @@
package de.tr7zw.changeme.nbtapi;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* Integer implementation for NBTLists
*
* @author tr7zw
*
*/
public class NBTIntArrayList extends NBTList<int[]> {
private final NBTContainer tmpContainer;
protected NBTIntArrayList(NBTCompound owner, String name, NBTType type, Object list) {
super(owner, name, type, list);
this.tmpContainer = new NBTContainer();
}
@Override
protected Object asTag(int[] object) {
try {
Constructor<?> con = ClassWrapper.NMS_NBTTAGINTARRAY.getClazz().getDeclaredConstructor(int[].class);
con.setAccessible(true);
return con.newInstance(object);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
}
}
@Override
public int[] get(int index) {
try {
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
ReflectionMethod.COMPOUND_SET.run(tmpContainer.getCompound(), "tmp", obj);
int[] val = tmpContainer.getIntArray("tmp");
tmpContainer.removeKey("tmp");
return val;
} catch (NumberFormatException nf) {
return null;
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
}
@@ -0,0 +1,45 @@
package de.tr7zw.changeme.nbtapi;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* Integer implementation for NBTLists
*
* @author tr7zw
*
*/
public class NBTIntegerList extends NBTList<Integer> {
protected NBTIntegerList(NBTCompound owner, String name, NBTType type, Object list) {
super(owner, name, type, list);
}
@Override
protected Object asTag(Integer object) {
try {
Constructor<?> con = ClassWrapper.NMS_NBTTAGINT.getClazz().getDeclaredConstructor(int.class);
con.setAccessible(true);
return con.newInstance(object);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
}
}
@Override
public Integer get(int index) {
try {
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
return Integer.valueOf(obj.toString());
} catch (NumberFormatException nf) {
return 0;
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
}
@@ -0,0 +1,430 @@
package de.tr7zw.changeme.nbtapi;
import java.util.Set;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* NBT class to access vanilla/custom tags on ItemStacks. This class doesn't
* autosave to the Itemstack, use getItem to get the changed ItemStack
*
* @author tr7zw
*
*/
public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
private ItemStack bukkitItem;
private final boolean directApply;
private final boolean finalizer;
private ItemStack originalSrcStack = null;
private Object cachedCompound = null;
private boolean closed = false;
/**
* Constructor for NBTItems. The ItemStack will be cloned! Deprecated: Please
* use the NBT class to work with items. It's up to 400% faster and provides
* less ways to mess up code.
*
* @param item
*/
@Deprecated
public NBTItem(ItemStack item) {
this(item, false);
}
/**
* @param item
* @param directApply
* @param readOnly When turned on, no copy of the source item is created.
* Modifying the stack in that case is not valid! Also
* overwrites directApply
*/
protected NBTItem(ItemStack item, boolean directApply, boolean readOnly, boolean finalizer) {
super(null, null, readOnly);
if (item == null || item.getType() == Material.AIR || item.getAmount() <= 0) {
throw new NullPointerException("ItemStack can't be null/air/amount of 0! This is not a NBTAPI bug!");
}
this.finalizer = finalizer;
if (finalizer) {
this.bukkitItem = item;
this.originalSrcStack = item;
this.directApply = false;
} else if (readOnly) {
bukkitItem = item;
this.directApply = false;
} else {
this.directApply = directApply;
bukkitItem = item.clone();
if (directApply) {
this.originalSrcStack = item;
}
}
}
/**
* Constructor for NBTItems. The ItemStack will be cloned! If directApply is
* true, all changed will be mapped to the original item. Changes to the NBTItem
* will overwrite changes done to the original item in that case.
*
* @param item
* @param directApply
*/
@Deprecated
public NBTItem(ItemStack item, boolean directApply) {
super(null, null);
if (item == null || item.getType() == Material.AIR || item.getAmount() <= 0) {
throw new NullPointerException("ItemStack can't be null/air/amount of 0! This is not a NBTAPI bug!");
}
this.finalizer = false;
this.directApply = directApply;
bukkitItem = item.clone();
if (directApply) {
this.originalSrcStack = item;
}
}
@Override
public Object getCompound() {
if (closed) {
throw new NbtApiException("Tried using closed NBT data!");
}
if (isReadOnly() && (cachedCompound != null
|| ClassWrapper.CRAFT_ITEMSTACK.getClazz().isAssignableFrom(bukkitItem.getClass()))) {
if (cachedCompound == null) {
cachedCompound = NBTReflectionUtil
.getItemRootNBTTagCompound(NBTReflectionUtil.getCraftItemHandle(bukkitItem));
}
return cachedCompound;
}
if (finalizer) {
if (cachedCompound == null) {
updateCachedCompound();
}
return cachedCompound;
}
return NBTReflectionUtil.getItemRootNBTTagCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem));
}
private void updateCachedCompound() {
if (finalizer) {
cachedCompound = NBTReflectionUtil
.getItemRootNBTTagCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem));
}
}
protected void finalizeChanges() {
if (!finalizer || cachedCompound == null) {
return;
}
// There was data, but not anymore, delete the tag from the itemstack
if (NBTReflectionUtil.getKeys(this).isEmpty()) {
cachedCompound = null;
}
if (ClassWrapper.CRAFT_ITEMSTACK.getClazz().isAssignableFrom(originalSrcStack.getClass())) {
Object nmsStack = NBTReflectionUtil.getCraftItemHandle(originalSrcStack);
NBTReflectionUtil.setItemStackCompound(nmsStack, cachedCompound);
bukkitItem = originalSrcStack;
} else {
Object stack = ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem);
NBTReflectionUtil.setItemStackCompound(stack, cachedCompound);
bukkitItem = (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null, stack);
originalSrcStack.setItemMeta(bukkitItem.getItemMeta());
}
}
@Override
protected void setClosed() {
this.closed = true;
}
@Override
protected boolean isClosed() {
return closed;
}
@SuppressWarnings("unchecked")
@Override
protected void setCompound(Object compound) {
if (isReadOnly()) {
throw new NbtApiException("Tried setting data in read only mode!");
}
if (closed) {
throw new NbtApiException("Tried using closed NBT data!");
}
if (finalizer) {
cachedCompound = compound;
return;
}
if (compound != null && ((Set<String>) ReflectionMethod.COMPOUND_GET_KEYS.run(compound)).isEmpty()) {
compound = null;
}
if (ClassWrapper.CRAFT_ITEMSTACK.getClazz().isAssignableFrom(bukkitItem.getClass())) {
Object nmsStack = NBTReflectionUtil.getCraftItemHandle(bukkitItem);
NBTReflectionUtil.setItemStackCompound(nmsStack, compound);
} else {
Object stack = ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem);
NBTReflectionUtil.setItemStackCompound(stack, compound);
bukkitItem = (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null, stack);
}
}
/**
* Apply stored NBT tags to the provided ItemStack.
* <p>
* Note: This will completely override current item's {@link ItemMeta}. If you
* still want to keep the original item's NBT tags, see
* {@link #mergeNBT(ItemStack)} and {@link #mergeCustomNBT(ItemStack)}.
*
* @param item ItemStack that should get the new NBT data
*/
@Deprecated
public void applyNBT(ItemStack item) {
if (item == null || item.getType() == Material.AIR) {
throw new NullPointerException("ItemStack can't be null/Air! This is not a NBTAPI bug!");
}
NBTItem nbti = new NBTItem(new ItemStack(item.getType()));
nbti.mergeCompound(this);
item.setItemMeta(nbti.getItem().getItemMeta());
}
/**
* Merge all NBT tags to the provided ItemStack.
*
* @param item ItemStack that should get the new NBT data
*/
@Deprecated
public void mergeNBT(ItemStack item) {
NBTItem nbti = new NBTItem(item);
nbti.mergeCompound(this);
item.setItemMeta(nbti.getItem().getItemMeta());
}
/**
* Merge only custom (non-vanilla) NBT tags to the provided ItemStack.
*
* @param item ItemStack that should get the new NBT data
*/
@Deprecated
public void mergeCustomNBT(ItemStack item) {
if (item == null || item.getType() == Material.AIR) {
throw new NullPointerException("ItemStack can't be null/Air!");
}
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
NBT.modify(item, nbt -> {
nbt.mergeCompound(this);
});
return;
}
ItemMeta meta = item.getItemMeta();
NBTReflectionUtil.getUnhandledNBTTags(meta)
.putAll(NBTReflectionUtil.getUnhandledNBTTags(bukkitItem.getItemMeta()));
item.setItemMeta(meta);
}
/**
* True, if the item has any tags now known for this item type.
*
* @return true when custom tags are present
*/
@Deprecated
public boolean hasCustomNbtData() {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
return hasNBTData();
}
finalizeChanges();
ItemMeta meta = bukkitItem.getItemMeta();
return !NBTReflectionUtil.getUnhandledNBTTags(meta).isEmpty();
}
/**
* Remove all custom (non-vanilla) NBT tags from the NBTItem.
*/
@Deprecated
public void clearCustomNBT() {
finalizeChanges();
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
setCompound(null);
return;
}
ItemMeta meta = bukkitItem.getItemMeta();
NBTReflectionUtil.getUnhandledNBTTags(meta).clear();
bukkitItem.setItemMeta(meta);
updateCachedCompound();
}
/**
* @return The modified ItemStack
*/
public ItemStack getItem() {
return bukkitItem;
}
protected void setItem(ItemStack item) {
bukkitItem = item;
}
/**
* Returns true if the item has NBT data. This needs to be checked before
* calling methods like remove, otherwise the value might be wrong!
*
* @return Does the ItemStack have a NBTCompound.
*/
public boolean hasNBTData() {
return getCompound() != null;
}
/**
* Gives save access to the {@link ItemMeta} of the internal {@link ItemStack}.
* Supported operations while inside this scope: - any get/set method of
* {@link ItemMeta} - any getter on {@link NBTItem}
*
* All changes made to the {@link NBTItem} during this scope will be reverted at
* the end.
*
* @param handler
*/
public void modifyMeta(BiConsumer<ReadableNBT, ItemMeta> handler) {
finalizeChanges();
ItemMeta meta = bukkitItem.getItemMeta();
handler.accept(new NBTContainer(getResolvedObject()).setReadOnly(true), meta);
bukkitItem.setItemMeta(meta);
updateCachedCompound();
if (directApply) {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException(
"Direct apply mode meta changes don't work anymore in 1.20.5+. Please switch to the modern NBT.modify sytnax!");
}
applyNBT(originalSrcStack);
}
}
/**
* Gives save access to the {@link ItemMeta} of the internal {@link ItemStack}.
* Supported operations while inside this scope: - any get/set method of
* {@link ItemMeta} - any getter on {@link NBTItem}
*
* All changes made to the {@link NBTItem} during this scope will be reverted at
* the end.
*
* @param handler
*/
public <T extends ItemMeta> void modifyMeta(Class<T> type, BiConsumer<ReadableNBT, T> handler) {
finalizeChanges();
@SuppressWarnings("unchecked")
T meta = (T) bukkitItem.getItemMeta();
handler.accept(new NBTContainer(getResolvedObject()).setReadOnly(true), meta);
bukkitItem.setItemMeta(meta);
updateCachedCompound();
if (directApply) {
applyNBT(originalSrcStack);
}
}
/**
* Helper method that converts {@link ItemStack} to {@link NBTContainer} with
* all it's data like Material, Damage, Amount and Tags.
*
* @param item
* @return Standalone {@link NBTContainer} with the Item's data
*/
@Deprecated
public static NBTContainer convertItemtoNBT(ItemStack item) {
return NBTReflectionUtil.convertNMSItemtoNBTCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, item));
}
/**
* Helper method to do the inverse of "convertItemtoNBT". Creates an
* {@link ItemStack} using the {@link NBTCompound}
*
* @param comp
* @return ItemStack using the {@link NBTCompound}'s data
*/
@Nullable
@Deprecated
public static ItemStack convertNBTtoItem(NBTCompound comp) {
return (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null,
NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp));
}
/**
* Helper method that converts {@link ItemStack}[] to {@link NBTContainer} with
* all its data like Material, Damage, Amount and Tags. This is a custom
* implementation and won't work with vanilla code(Shulker content etc).
*
* @param items
* @return Standalone {@link NBTContainer} with the Item's data
*/
@Deprecated
public static NBTContainer convertItemArraytoNBT(ItemStack[] items) {
NBTContainer container = new NBTContainer();
container.setInteger("size", items.length);
NBTCompoundList list = container.getCompoundList("items");
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item == null || item.getType() == Material.AIR) {
continue;
}
NBTListCompound entry = list.addCompound();
entry.setInteger("Slot", i);
entry.mergeCompound(convertItemtoNBT(item));
}
return container;
}
/**
* Helper method to do the inverse of "convertItemArraytoNBT". Creates an
* {@link ItemStack}[] using the {@link NBTCompound}. This is a custom
* implementation and won't work with vanilla code (Shulker content, etc.).
*
* Will return null for invalid data. Empty slots in the array are filled with
* AIR Stacks!
*
* @param comp
* @return ItemStack[] using the {@link NBTCompound}'s data
*/
@Nullable
@Deprecated
public static ItemStack[] convertNBTtoItemArray(NBTCompound comp) {
if (!comp.hasTag("size")) {
return null;
}
ItemStack[] rebuild = new ItemStack[comp.getInteger("size")];
for (int i = 0; i < rebuild.length; i++) { // not using Arrays.fill, since then it's all the same instance
rebuild[i] = new ItemStack(Material.AIR);
}
if (!comp.hasTag("items")) {
return rebuild;
}
NBTCompoundList list = comp.getCompoundList("items");
for (ReadWriteNBT lcomp : list) {
if (lcomp instanceof NBTCompound) {
int slot = lcomp.getInteger("Slot");
rebuild[slot] = convertNBTtoItem((NBTCompound) lcomp);
}
}
return rebuild;
}
@Override
protected void saveCompound() {
if (directApply) {
applyNBT(originalSrcStack);
}
}
}
@@ -0,0 +1,474 @@
package de.tr7zw.changeme.nbtapi;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.function.Predicate;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBTList;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* Abstract List implementation for ListCompounds
*
* @author tr7zw
*
* @param <T>
*/
public abstract class NBTList<T> implements List<T>, ReadWriteNBTList<T> {
private String listName;
private NBTCompound parent;
private NBTType type;
protected Object listObject;
protected NBTList(NBTCompound owner, String name, NBTType type, Object list) {
parent = owner;
listName = name;
this.type = type;
this.listObject = list;
}
/**
* @return Name of this list-compound
*/
public String getName() {
return listName;
}
/**
* @return The Compound's parent Object
*/
public NBTCompound getParent() {
return parent;
}
private void validateClosed() {
if (parent.isClosed()) {
throw new NbtApiException("Tried using closed NBT data!");
}
}
private void validateWritable() {
if (getParent().isReadOnly()) {
throw new NbtApiException("Tried setting data in read only mode!");
}
}
protected void save() {
validateClosed();
parent.set(listName, listObject);
}
protected abstract Object asTag(T object);
@Override
public boolean add(T element) {
validateClosed();
validateWritable();
try {
parent.getWriteLock().lock();
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
ReflectionMethod.LIST_ADD.run(listObject, size(), asTag(element));
} else {
ReflectionMethod.LEGACY_LIST_ADD.run(listObject, asTag(element));
}
save();
return true;
} catch (Exception ex) {
throw new NbtApiException(ex);
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public void add(int index, T element) {
validateClosed();
validateWritable();
try {
parent.getWriteLock().lock();
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
ReflectionMethod.LIST_ADD.run(listObject, index, asTag(element));
} else {
ReflectionMethod.LEGACY_LIST_ADD.run(listObject, asTag(element));
}
save();
} catch (Exception ex) {
throw new NbtApiException(ex);
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public T set(int index, T element) {
validateClosed();
validateWritable();
try {
parent.getWriteLock().lock();
T prev = get(index);
ReflectionMethod.LIST_SET.run(listObject, index, asTag(element));
save();
return prev;
} catch (Exception ex) {
throw new NbtApiException(ex);
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public T remove(int i) {
validateClosed();
validateWritable();
try {
parent.getWriteLock().lock();
T old = get(i);
ReflectionMethod.LIST_REMOVE_KEY.run(listObject, i);
save();
return old;
} catch (Exception ex) {
throw new NbtApiException(ex);
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public int size() {
validateClosed();
try {
parent.getReadLock().lock();
return (int) ReflectionMethod.LIST_SIZE.run(listObject);
} catch (Exception ex) {
throw new NbtApiException(ex);
} finally {
parent.getReadLock().unlock();
}
}
/**
* @return The type that this list contains
*/
@Override
public NBTType getType() {
return type;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public void clear() {
while (!isEmpty()) {
remove(0);
}
}
@Override
public boolean contains(Object o) {
validateClosed();
try {
parent.getReadLock().lock();
for (int i = 0; i < size(); i++) {
if (o.equals(get(i)))
return true;
}
return false;
} finally {
parent.getReadLock().unlock();
}
}
@Override
public int indexOf(Object o) {
validateClosed();
try {
parent.getReadLock().lock();
for (int i = 0; i < size(); i++) {
if (o.equals(get(i)))
return i;
}
return -1;
} finally {
parent.getReadLock().unlock();
}
}
@Override
public boolean addAll(Collection<? extends T> c) {
validateClosed();
try {
parent.getWriteLock().lock();
int size = size();
for (T ele : c) {
add(ele);
}
return size != size();
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public boolean addAll(int index, Collection<? extends T> c) {
validateClosed();
try {
parent.getWriteLock().lock();
int size = size();
for (T ele : c) {
add(index++, ele);
}
return size != size();
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public boolean containsAll(Collection<?> c) {
validateClosed();
try {
parent.getReadLock().lock();
for (Object ele : c) {
if (!contains(ele))
return false;
}
return true;
} finally {
parent.getReadLock().unlock();
}
}
@Override
public int lastIndexOf(Object o) {
validateClosed();
try {
parent.getReadLock().lock();
int index = -1;
for (int i = 0; i < size(); i++) {
if (o.equals(get(i)))
index = i;
}
return index;
} finally {
parent.getReadLock().unlock();
}
}
@Override
public boolean removeAll(Collection<?> c) {
validateClosed();
try {
parent.getWriteLock().lock();
int size = size();
for (Object obj : c) {
remove(obj);
}
return size != size();
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public boolean retainAll(Collection<?> c) {
validateClosed();
try {
parent.getWriteLock().lock();
int size = size();
for (Object obj : c) {
for (int i = 0; i < size(); i++) {
if (!obj.equals(get(i))) {
remove(i--);
}
}
}
return size != size();
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public boolean remove(Object o) {
validateClosed();
try {
parent.getWriteLock().lock();
int size = size();
int id = indexOf(o);
if (id != -1) {
remove(id);
}
return size != size();
} finally {
parent.getWriteLock().unlock();
}
}
@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
private int index = -1;
@Override
public boolean hasNext() {
return size() > index + 1;
}
@Override
public T next() {
if (!hasNext())
throw new NoSuchElementException();
return get(++index);
}
@Override
public void remove() {
NBTList.this.remove(index);
index--;
}
};
}
@Override
public ListIterator<T> listIterator() {
return listIterator(0);
}
@Override
public ListIterator<T> listIterator(int startIndex) {
final NBTList<T> list = this;
return new ListIterator<T>() {
int index = startIndex - 1;
@Override
public void add(T e) {
list.add(index, e);
}
@Override
public boolean hasNext() {
return size() > index + 1;
}
@Override
public boolean hasPrevious() {
return index >= 0 && index <= size();
}
@Override
public T next() {
if (!hasNext())
throw new NoSuchElementException();
return get(++index);
}
@Override
public int nextIndex() {
return index + 1;
}
@Override
public T previous() {
if (!hasPrevious())
throw new NoSuchElementException("Id: " + (index - 1));
return get(index--);
}
@Override
public int previousIndex() {
return index - 1;
}
@Override
public void remove() {
list.remove(index);
index--;
}
@Override
public void set(T e) {
list.set(index, e);
}
};
}
@Override
public Object[] toArray() {
validateClosed();
try {
parent.getReadLock().lock();
Object[] ar = new Object[size()];
for (int i = 0; i < size(); i++)
ar[i] = get(i);
return ar;
} finally {
parent.getReadLock().unlock();
}
}
@SuppressWarnings("unchecked")
@Override
public <E> E[] toArray(E[] a) {
validateClosed();
try {
parent.getReadLock().lock();
E[] ar = Arrays.copyOf(a, size());
Arrays.fill(ar, null);
Class<?> arrayclass = a.getClass().getComponentType();
for (int i = 0; i < size(); i++) {
T obj = get(i);
if (arrayclass.isInstance(obj)) {
ar[i] = (E) get(i);
} else {
throw new ArrayStoreException("The array does not match the objects stored in the List.");
}
}
return ar;
} finally {
parent.getReadLock().unlock();
}
}
@Override
public List<T> subList(int fromIndex, int toIndex) {
validateClosed();
try {
parent.getReadLock().lock();
ArrayList<T> list = new ArrayList<>();
for (int i = fromIndex; i < toIndex; i++)
list.add(get(i));
return list;
} finally {
parent.getReadLock().unlock();
}
}
@Override
public boolean removeIf(Predicate<? super T> filter) {
return List.super.removeIf(filter);
}
@Override
public String toString() {
validateClosed();
try {
parent.getReadLock().lock();
return listObject.toString();
} finally {
parent.getReadLock().unlock();
}
}
}
@@ -0,0 +1,61 @@
package de.tr7zw.changeme.nbtapi;
/**
* Cut down version of the {@link NBTCompound} for inside
* {@link NBTCompoundList} This Compound implementation is missing the ability
* for further subCompounds and Lists. This class probably will change in the
* future
*
* @author tr7zw
*
*/
public class NBTListCompound extends NBTCompound {
private NBTList<?> owner;
private Object compound;
protected NBTListCompound(NBTList<?> parent, Object obj) {
super(null, null);
owner = parent;
compound = obj;
}
public NBTList<?> getListParent() {
return owner;
}
@Override
protected boolean isClosed() {
return owner.getParent().isClosed();
}
@Override
protected boolean isReadOnly() {
return owner.getParent().isReadOnly();
}
@Override
public Object getCompound() {
if (isClosed()) {
throw new NbtApiException("Tried using closed NBT data!");
}
return compound;
}
@Override
protected void setCompound(Object compound) {
if (isClosed()) {
throw new NbtApiException("Tried using closed NBT data!");
}
if (isReadOnly()) {
throw new NbtApiException("Tried setting data in read only mode!");
}
this.compound = compound;
}
@Override
protected void saveCompound() {
owner.save();
}
}
@@ -0,0 +1,45 @@
package de.tr7zw.changeme.nbtapi;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* Long implementation for NBTLists
*
* @author tr7zw
*
*/
public class NBTLongList extends NBTList<Long> {
protected NBTLongList(NBTCompound owner, String name, NBTType type, Object list) {
super(owner, name, type, list);
}
@Override
protected Object asTag(Long object) {
try {
Constructor<?> con = ClassWrapper.NMS_NBTTAGLONG.getClazz().getDeclaredConstructor(long.class);
con.setAccessible(true);
return con.newInstance(object);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
}
}
@Override
public Long get(int index) {
try {
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
return Long.valueOf(obj.toString().replace("L", ""));
} catch (NumberFormatException nf) {
return 0l;
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
}
@@ -0,0 +1,36 @@
package de.tr7zw.changeme.nbtapi;
import java.util.Map;
import org.bukkit.persistence.PersistentDataContainer;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
public class NBTPersistentDataContainer extends NBTCompound {
private final PersistentDataContainer container;
public NBTPersistentDataContainer(PersistentDataContainer container) {
this(container, false);
}
protected NBTPersistentDataContainer(PersistentDataContainer container, boolean readOnly) {
super(null, null, readOnly);
this.container = container;
}
@Override
public Object getCompound() {
return ReflectionMethod.CRAFT_PERSISTENT_DATA_CONTAINER_TO_TAG.run(container);
}
@Override
protected void setCompound(Object compound) {
@SuppressWarnings("unchecked")
Map<Object, Object> map = (Map<Object, Object>) ReflectionMethod.CRAFT_PERSISTENT_DATA_CONTAINER_GET_MAP
.run(container);
map.clear();
ReflectionMethod.CRAFT_PERSISTENT_DATA_CONTAINER_PUT_ALL.run(container, compound);
}
}
@@ -0,0 +1,841 @@
package de.tr7zw.changeme.nbtapi;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DynamicOps;
import de.tr7zw.changeme.nbtapi.utils.DataFixerUtil;
import de.tr7zw.changeme.nbtapi.utils.GsonWrapper;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.ReflectionUtil;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.CodecHelper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ObjectCreator;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* Utility class for translating NBTApi calls to reflections into NMS code All
* methods are allowed to throw {@link NbtApiException}
*
* @author tr7zw
*
*/
@SuppressWarnings("deprecation")
public class NBTReflectionUtil {
private static Field field_unhandledTags = null;
private static Field field_handle = null;
private static Object type_custom_data = null;
private static Object registry_access = null;
public static Codec<Object> itemstack_codec = null;
public static DynamicOps<Object> nbtOps = null;
public static DynamicOps<Object> nbtRegistryOps = null;
public static Object problemReporter = null;
static {
try {
field_unhandledTags = ClassWrapper.CRAFT_METAITEM.getClazz().getDeclaredField("unhandledTags");
field_unhandledTags.setAccessible(true);
} catch (NoSuchFieldException e) {
}
try {
field_handle = ClassWrapper.CRAFT_ITEMSTACK.getClazz().getDeclaredField("handle");
field_handle.setAccessible(true);
} catch (NoSuchFieldException e) {
}
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
try {
Field typeField = ReflectionUtil.getMappedField(ClassWrapper.NMS_DATACOMPONENTS.getClazz(), "net.minecraft.core.component.DataComponents#CUSTOM_DATA");
type_custom_data = typeField.get(null);
} catch (Exception e) {
MinecraftVersion.getLogger().log(Level.WARNING,
"Unable to find DataComponents#CUSTOM_DATA, NBTApi will not be able to read/write custom data on 1.20+",
e);
}
try {
Object nmsServer = ReflectionMethod.NMSSERVER_GETSERVER.run(Bukkit.getServer());
registry_access = ReflectionMethod.NMSSERVER_GETREGISTRYACCESS.run(nmsServer);
itemstack_codec = (Codec<Object>) ReflectionUtil.getMappedField(ClassWrapper.NMS_ITEMSTACK.getClazz(), "net.minecraft.world.item.ItemStack#CODEC").get(null);
nbtOps = (DynamicOps<Object>) ReflectionUtil.getMappedField(ClassWrapper.NMS_NBTOPS.getClazz(), "net.minecraft.nbt.NbtOps#INSTANCE").get(null);
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R5)) {
nbtRegistryOps = (DynamicOps<Object>) ReflectionMethod.GET_SERIALIZATION_CONTEXT.run(registry_access, nbtOps);
problemReporter = ReflectionUtil.getMappedField(ClassWrapper.NMS_PROBLEM_REPORTER.getClazz(), "net.minecraft.util.ProblemReporter#DISCARDING").get(null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Hidden constructor
*/
private NBTReflectionUtil() {
}
/**
* Gets the NMS Entity for a given Bukkit Entity
*
* @param entity Bukkit Entity
* @return NMS Entity
*/
public static Object getNMSEntity(Entity entity) {
try {
return ReflectionMethod.CRAFT_ENTITY_GET_HANDLE.run(ClassWrapper.CRAFT_ENTITY.getClazz().cast(entity));
} catch (Exception e) {
throw new NbtApiException("Exception while getting the NMS Entity from a Bukkit Entity!", e);
}
}
/**
* Reads in a InputStream as NMS Compound
*
* @param stream InputStream of any NBT file
* @return NMS Compound
*/
public static Object readNBT(InputStream stream) {
try {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R3)) {
return ReflectionMethod.NBTFILE_READV2.run(null, stream,
ReflectionMethod.NBTACCOUNTER_CREATE_UNLIMITED.run(null));
} else {
return ReflectionMethod.NBTFILE_READ.run(null, stream);
}
} catch (Exception e) {
try {
stream.close();
} catch (IOException ignore) {
}
throw new NbtApiException("Exception while reading a NBT File!", e);
}
}
/**
* Writes a NMS Compound to an OutputStream
*
* @param nbt NMS Compound
* @param stream Stream to write to
* @return ???
*/
public static Object writeNBT(Object nbt, OutputStream stream) {
try {
return ReflectionMethod.NBTFILE_WRITE.run(null, nbt, stream);
} catch (Exception e) {
throw new NbtApiException("Exception while writing NBT!", e);
}
}
/**
* Gets the nms handle ItemStack from a CraftItemStack. Passing Spigot
* ItemStacks will cause an error!
*
* @param item
* @return
*/
public static Object getCraftItemHandle(ItemStack item) {
try {
return field_handle.get(item);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new NbtApiException("Error getting handle from " + item.getClass(), e);
}
}
/**
* Writes a Compound to an OutputStream
*
* @param comp Compound
* @param stream Stream to write to
*/
public static void writeApiNBT(NBTCompound comp, OutputStream stream) {
try {
Object workingtag = comp.getResolvedObject();
if (workingtag == null) {
workingtag = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
}
ReflectionMethod.NBTFILE_WRITE.run(null, workingtag, stream);
} catch (Exception e) {
throw new NbtApiException("Exception while writing NBT!", e);
}
}
/**
* Simulates getOrCreateTag. If an Item doesn't yet have a Tag, it will return a
* new empty tag.
*
* @param nmsitem
* @return NMS Compound
*/
public static Object getItemRootNBTTagCompound(Object nmsitem) {
try {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
Object customData = ReflectionMethod.NMSDATACOMPONENTHOLDER_GET.run(nmsitem, type_custom_data);
if (customData == null) {
return null;
}
return ReflectionMethod.NMSCUSTOMDATA_GETCOPY.run(customData);
} else {
Object answer = ReflectionMethod.NMSITEM_GETTAG.run(nmsitem);
return answer;
}
} catch (Exception e) {
throw new NbtApiException("Exception while getting an Itemstack's NBTCompound!", e);
}
}
/**
* Set the Compound as the Items NBT or CustomData
*
* @param nmsItem
* @param compound
*/
public static void setItemStackCompound(Object nmsItem, Object compound) {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
if (compound == null) {
ReflectionMethod.NMSITEM_SET.run(nmsItem, new Object[] { type_custom_data, null });
} else {
ReflectionMethod.NMSITEM_SET.run(nmsItem, type_custom_data,
ObjectCreator.NMS_CUSTOMDATA.getInstance(compound));
}
} else {
ReflectionMethod.ITEMSTACK_SET_TAG.run(nmsItem, compound);
}
}
/**
* Converts {@link NBTCompound} to NMS ItemStacks
*
* @param nbtcompound Any valid {@link NBTCompound}
* @return NMS ItemStack
*/
public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) {
Object nmsComp = null;
try {
nmsComp = getToCompount(nbtcompound.getCompound(), nbtcompound);
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
if (nbtcompound.hasTag("DataVersion", NBTType.NBTTagInt)) {
int dataVersion = nbtcompound.getInteger("DataVersion");
int currentVersion = DataFixerUtil.getCurrentVersion();
if (dataVersion < currentVersion) {
nmsComp = DataFixerUtil.fixUpRawItemData(nmsComp, dataVersion, currentVersion);
}
} else if (nbtcompound.hasTag("tag") || nbtcompound.hasTag("Count")) {
nmsComp = DataFixerUtil.fixUpRawItemData(nmsComp, DataFixerUtil.VERSION1_20_4, DataFixerUtil.getCurrentVersion());
}
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R5)) {
return CodecHelper.convertNbtToItemStack(nmsComp);
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R4)) {
Optional<Object> opt = (Optional<Object>) ReflectionMethod.NMSITEM_LOAD_MODERN.run(null,
registry_access, nmsComp);
return opt.orElse(null);
} else {
return ReflectionMethod.NMSITEM_LOAD.run(null, registry_access, nmsComp);
}
} else if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_11_R1.getVersionId()) {
return ObjectCreator.NMS_COMPOUNDFROMITEM.getInstance(nmsComp);
} else {
return ReflectionMethod.NMSITEM_CREATESTACK.run(null, nmsComp);
}
} catch (Exception e) {
throw new NbtApiException("Exception while converting NBTCompound to NMS ItemStack! " + nmsComp, e);
}
}
/**
* Converts NMS ItemStacks to {@link NBTContainer}
*
* @param nmsitem NMS ItemStack
* @return {@link NBTContainer} with all the data
*/
public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) {
try {
NBTContainer container;
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R5)) {
container = new NBTContainer(CodecHelper.convertItemStackToNbt(nmsitem));
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
container = new NBTContainer(ReflectionMethod.NMSITEM_SAVE_MODERN.run(nmsitem, registry_access));
} else {
Object answer = ReflectionMethod.NMSITEM_SAVE.run(nmsitem,
ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance());
container = new NBTContainer(answer);
}
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_12_R1)) {
container.setInteger("DataVersion", DataFixerUtil.getCurrentVersion());
}
return container;
} catch (Exception e) {
throw new NbtApiException("Exception while converting NMS ItemStack to NBTCompound!", e);
}
}
/**
* Gets a live copy of non-vanilla NBT tags.
*
* @param meta ItemMeta from which tags should be retrieved
* @return Map containing unhandled (custom) NBT tags
*/
@SuppressWarnings("unchecked")
@Deprecated
public static Map<String, Object> getUnhandledNBTTags(ItemMeta meta) {
try {
return (Map<String, Object>) field_unhandledTags.get(meta);
} catch (Exception e) {
throw new NbtApiException("Exception while getting unhandled tags from ItemMeta!", e);
}
}
/**
* Gets the Vanilla NBT Compound from a given NMS Entity
*
* @param nmsEntity
* @return NMS NBT Compound
*/
public static Object getEntityNBTTagCompound(Object nmsEntity) {
try {
Object nbt = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
Object answer;
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R5)) {
Object output = ReflectionMethod.NMS_GET_TAG_VALUE_OUTPUT.run(null, problemReporter, registry_access);
ReflectionMethod.NMS_ENTITY_GET_NBT_1216.run(nmsEntity, output);
answer = ReflectionMethod.NMS_TAG_VALUE_OUTPUT_TO_TAG_COMPOUND.run(output);
} else {
answer = ReflectionMethod.NMS_ENTITY_GET_NBT.run(nmsEntity, nbt);
}
if (answer == null)
answer = nbt;
return answer;
} catch (Exception e) {
throw new NbtApiException("Exception while getting NBTCompound from NMS Entity!", e);
}
}
/**
* Loads all Vanilla tags from a NMS Compound into a NMS Entity
*
* @param nbtTag
* @param nmsEntity
* @return The NMS Entity
*/
public static Object setEntityNBTTag(Object nbtTag, Object nmsEntity) {
try {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R5)) {
Object valueInputTag = ReflectionMethod.NMS_GET_TAG_VALUE_INPUT.run(null, problemReporter, registry_access, nbtTag);
ReflectionMethod.NMS_ENTITY_SET_NBT_1216.run(nmsEntity, valueInputTag);
} else {
ReflectionMethod.NMS_ENTITY_SET_NBT.run(nmsEntity, nbtTag);
}
return nmsEntity;
} catch (Exception ex) {
throw new NbtApiException("Exception while setting the NBTCompound of an Entity", ex);
}
}
/**
* Gets the NMS Compound from a given TileEntity
*
* @param tile
* @return NMS Compound with the Vanilla data
*/
public static Object getTileEntityNBTTagCompound(BlockState tile) {
try {
Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld());
Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld);
Object o = null;
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY_1_7_10.run(nmsworld, tile.getX(), tile.getY(),
tile.getZ());
} else {
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
}
if (o == null) {
throw new NbtApiException("The passed BlockState(" + tile.getType()
+ ") doesn't point to a BlockEntity. Only BlockEntities like Chest/Signs/Furnance/etc have NBT.");
}
Object answer = null;
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R5)) {
Object output = ReflectionMethod.NMS_GET_TAG_VALUE_OUTPUT.run(null, problemReporter, registry_access);
ReflectionMethod.TILEENTITY_GET_NBT_1216.run(o, output);
answer = ReflectionMethod.NMS_TAG_VALUE_OUTPUT_TO_TAG_COMPOUND.run(output);
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
answer = ReflectionMethod.TILEENTITY_GET_NBT_1205.run(o, registry_access);
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_18_R1)) {
answer = ReflectionMethod.TILEENTITY_GET_NBT_1181.run(o);
} else {
answer = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
ReflectionMethod.TILEENTITY_GET_NBT.run(o, answer);
}
if (answer == null) {
throw new NbtApiException("Unable to get NBTCompound from TileEntity! " + tile + " " + o);
}
return answer;
} catch (Exception e) {
throw new NbtApiException("Exception while getting NBTCompound from TileEntity!", e);
}
}
/**
* Sets Vanilla tags from a NMS Compound to a TileEntity
*
* @param tile
* @param comp
*/
public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) {
try {
Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld());
Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld);
Object o = null;
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY_1_7_10.run(nmsworld, tile.getX(), tile.getY(),
tile.getZ());
} else {
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
}
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R5)) {
Object valueInput = ReflectionMethod.NMS_GET_TAG_VALUE_INPUT.run(null, problemReporter, registry_access, comp);
ReflectionMethod.TILEENTITY_SET_NBT_1216.run(o, valueInput);
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
ReflectionMethod.TILEENTITY_SET_NBT_1205.run(o, comp, registry_access);
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_17_R1)) {
ReflectionMethod.TILEENTITY_SET_NBT.run(o, comp);
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1)) {
Object blockData = ReflectionMethod.TILEENTITY_GET_BLOCKDATA.run(o);
ReflectionMethod.TILEENTITY_SET_NBT_LEGACY1161.run(o, blockData, comp);
} else {
ReflectionMethod.TILEENTITY_SET_NBT_LEGACY1151.run(o, comp);
}
} catch (Exception e) {
throw new NbtApiException("Exception while setting NBTData for a TileEntity!", e);
}
}
/**
* Gets the subCompound with a given name from a NMS Compound
*
* @param compound
* @param name
* @return NMS Compound or null
*/
public static Object getSubNBTTagCompound(Object compound, String name) {
try {
if ((boolean) ReflectionMethod.COMPOUND_HAS_KEY.run(compound, name)) {
Object comp = ReflectionMethod.COMPOUND_GET_COMPOUND.run(compound, name);
if (comp instanceof Optional) {
return ((Optional<?>) comp).orElse(null);
}
return comp;
} else {
throw new NbtApiException("Tried getting invalid compound '" + name + "' from '" + compound + "'!");
}
} catch (Exception e) {
throw new NbtApiException("Exception while getting NBT subcompounds!", e);
}
}
/**
* Creates a subCompound with a given name in the given NMS Compound
*
* @param comp
* @param name
*/
public static void addNBTTagCompound(NBTCompound comp, String name) {
if (name == null) {
remove(comp, name);
return;
}
Object nbttag = comp.getCompound();
if (nbttag == null) {
nbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!validCompound(comp)) {
return;
}
Object workingtag = getToCompount(nbttag, comp);
try {
ReflectionMethod.COMPOUND_SET.run(workingtag, name,
ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance());
comp.setCompound(nbttag);
} catch (Exception e) {
throw new NbtApiException("Exception while adding a Compound!", e);
}
}
/**
* Checks if the Compound is correctly linked to it's roots
*
* @param comp
* @return true if this is a valid Compound, else false
*/
public static boolean validCompound(NBTCompound comp) {
Object root = comp.getCompound();
if (root instanceof Optional) {
root = ((Optional<?>) root).orElse(null);
}
if (root == null) {
root = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
Object tmp = getToCompount(root, comp);
comp.setResolvedObject(tmp);
return tmp != null;
}
public static Object getToCompount(Object nbttag, NBTCompound comp) {
Deque<String> structure = new ArrayDeque<>();
while (comp.getParent() != null) {
structure.add(comp.getName());
comp = comp.getParent();
}
if (nbttag instanceof Optional) {
nbttag = ((Optional<?>) nbttag).orElse(null);
}
while (!structure.isEmpty()) {
String target = structure.pollLast();
nbttag = getSubNBTTagCompound(nbttag, target);
if (nbttag instanceof Optional) {
nbttag = ((Optional<?>) nbttag).orElse(null);
}
if (nbttag == null) {
throw new NbtApiException("Unable to find tag '" + target + "' in " + nbttag);
}
}
return nbttag;
}
/**
* Merges the second {@link NBTCompound} into the first one
*
* @param comp Target for the merge
* @param nbtcompoundSrc Data to merge
*/
public static void mergeOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompoundSrc) {
Object workingtagSrc = nbtcompoundSrc.getResolvedObject();
if (workingtagSrc == null) {
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!validCompound(comp))
throw new NbtApiException("The Compound wasn't able to be linked back to the root!");
Object workingtag = getToCompount(rootnbttag, comp);
try {
ReflectionMethod.COMPOUND_MERGE.run(workingtag, workingtagSrc);
comp.setCompound(rootnbttag);
} catch (Exception e) {
throw new NbtApiException("Exception while merging two NBTCompounds!", e);
}
}
/**
* Sets a key in a {@link NBTCompound} to a given value
*
* @param comp
* @param key
* @param val
*/
public static void set(NBTCompound comp, String key, Object val) {
if (val == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!validCompound(comp)) {
throw new NbtApiException("The Compound wasn't able to be linked back to the root!");
}
Object workingtag = getToCompount(rootnbttag, comp);
try {
ReflectionMethod.COMPOUND_SET.run(workingtag, key, val);
comp.setCompound(rootnbttag);
} catch (Exception e) {
throw new NbtApiException("Exception while setting key '" + key + "' to '" + val + "'!", e);
}
}
/**
* Returns the List saved with a given key.
*
* @param comp
* @param key
* @param type
* @param clazz
* @return The list at that key. Null if it's an invalid type
*/
@SuppressWarnings("unchecked")
public static <T> NBTList<T> getList(NBTCompound comp, String key, NBTType type, Class<T> clazz) {
Object workingtag = comp.getResolvedObject();
if (workingtag == null) {
workingtag = dummyNBT.getCompound(); // it creates a new ListTag if needed, but its unlinked
}
try {
Object nbt = null;
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R4)) {
nbt = ReflectionMethod.COMPOUND_GET_LIST.run(workingtag, key);
if (nbt instanceof Optional) {
nbt = ((Optional<?>) nbt).orElse(null);
}
if (nbt == null) {
nbt = ClassWrapper.NMS_NBTTAGLIST.getClazz().newInstance();
}
} else {
nbt = ReflectionMethod.COMPOUND_GET_LIST_LEGACY.run(workingtag, key, type.getId());
}
if (clazz == String.class) {
return (NBTList<T>) new NBTStringList(comp, key, type, nbt);
} else if (clazz == NBTListCompound.class) {
return (NBTList<T>) new NBTCompoundList(comp, key, type, nbt);
} else if (clazz == Integer.class) {
return (NBTList<T>) new NBTIntegerList(comp, key, type, nbt);
} else if (clazz == Float.class) {
return (NBTList<T>) new NBTFloatList(comp, key, type, nbt);
} else if (clazz == Double.class) {
return (NBTList<T>) new NBTDoubleList(comp, key, type, nbt);
} else if (clazz == Long.class) {
return (NBTList<T>) new NBTLongList(comp, key, type, nbt);
} else if (clazz == int[].class) {
return (NBTList<T>) new NBTIntArrayList(comp, key, type, nbt);
} else if (clazz == UUID.class) {
return (NBTList<T>) new NBTUUIDList(comp, key, type, nbt);
} else {
return null;
}
} catch (Exception ex) {
throw new NbtApiException("Exception while getting a list with the type '" + type + "'!", ex);
}
}
public static NBTType getListType(NBTCompound comp, String key) {
Object workingtag = comp.getResolvedObject();
if (workingtag == null) {
workingtag = dummyNBT.getCompound(); // it creates a new ListTag if needed, but its unlinked
}
try {
Object nbt = ReflectionMethod.COMPOUND_GET.run(workingtag, key);
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R4)) {
if (nbt instanceof Optional) {
nbt = ((Optional<?>) nbt).orElse(null);
}
if (nbt == null) {
return NBTType.NBTTagEnd;
}
if (new NBTStringList(comp, key, NBTType.NBTTagString, nbt).isEmpty()) {
return NBTType.NBTTagEnd;
}
Object compound = ReflectionMethod.LIST_GET.run(nbt, 0);
if (compound instanceof Optional) {
compound = ((Optional<?>) compound).orElse(null);
}
if (compound == null) {
return NBTType.NBTTagEnd;
}
return NBTType.fromName((String) ReflectionMethod.TAGTYPE_GET_NAME
.run(ReflectionMethod.TAGTYPE_OWN_TYPE.run(compound)));
}
String fieldname = "type";
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_17_R1)) {
fieldname = "w";
}
Field f;
try {
f = nbt.getClass().getDeclaredField(fieldname);
} catch (NoSuchFieldException ignore) {
// fallback try mojang mapped/legacy
f = nbt.getClass().getDeclaredField("type");
}
f.setAccessible(true);
return NBTType.valueOf(f.getByte(nbt));
} catch (Exception ex) {
throw new NbtApiException("Exception while getting the list type!", ex);
}
}
public static Object getEntry(NBTCompound comp, String key) {
Object workingtag = comp.getResolvedObject();
try {
return ReflectionMethod.COMPOUND_GET.run(workingtag, key);
} catch (Exception ex) {
throw new NbtApiException("Exception while getting an Entry!", ex);
}
}
/**
* Uses Gson to set a {@link Serializable} value in a Compound
*
* @param comp
* @param key
* @param value
*/
public static void setObject(NBTCompound comp, String key, Object value) {
if (!MinecraftVersion.hasGsonSupport())
return;
try {
String json = GsonWrapper.getString(value);
setData(comp, ReflectionMethod.COMPOUND_SET_STRING, key, json);
} catch (Exception e) {
throw new NbtApiException("Exception while setting the Object '" + value + "'!", e);
}
}
/**
* Uses Gson to load back a {@link Serializable} object from the Compound
*
* @param comp
* @param key
* @param type
* @return The loaded Object or null, if not found
*/
public static <T> T getObject(NBTCompound comp, String key, Class<T> type) {
if (!MinecraftVersion.hasGsonSupport())
return null;
String json = (String) getData(comp, ReflectionMethod.COMPOUND_GET_STRING, key);
if (json == null) {
return null;
}
return GsonWrapper.deserializeJson(json, type);
}
/**
* Deletes the given key
*
* @param comp
* @param key
*/
public static void remove(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
return;
}
if (!validCompound(comp))
return;
Object workingtag = getToCompount(rootnbttag, comp);
ReflectionMethod.COMPOUND_REMOVE_KEY.run(workingtag, key);
comp.setCompound(rootnbttag);
}
/**
* Gets the Keyset inside this Compound
*
* @param comp
* @return Set of all keys
*/
@SuppressWarnings("unchecked")
public static Set<String> getKeys(NBTCompound comp) {
Object workingtag = comp.getResolvedObject();
if (workingtag == null) {
return Collections.emptySet();
}
return (Set<String>) ReflectionMethod.COMPOUND_GET_KEYS.run(workingtag);
}
/**
* Sets data inside the Compound
*
* @param comp
* @param type
* @param key
* @param data
*/
public static void setData(NBTCompound comp, ReflectionMethod type, String key, Object data) {
if (data == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!validCompound(comp))
throw new NbtApiException("The Compound wasn't able to be linked back to the root!");
Object workingtag = getToCompount(rootnbttag, comp);
type.run(workingtag, key, data);
comp.setCompound(rootnbttag);
}
private final static NBTContainer dummyNBT = new NBTContainer();
/**
* Gets data from the Compound
*
* @param comp
* @param type
* @param key
* @return The value or default fallback from NMS
*/
public static Object getData(NBTCompound comp, ReflectionMethod type, String key) {
Object workingtag = comp.getResolvedObject();
// return default behavior data as if there was a compound
if (workingtag == null) {
workingtag = dummyNBT.getCompound();
}
if (workingtag instanceof Optional<?>) {
workingtag = ((Optional<Object>) workingtag).orElseGet(() -> dummyNBT.getCompound());
}
Object obj = type.run(workingtag, key);
if (obj instanceof Optional<?>) {
return ((Optional<Object>) obj).orElseGet(() -> getDefaultValue(type));
}
return obj;
}
private static Object getDefaultValue(ReflectionMethod type) {
if (type == ReflectionMethod.COMPOUND_GET_STRING) {
return "";
} else if (type == ReflectionMethod.COMPOUND_GET_BYTE) {
return (byte) 0;
} else if (type == ReflectionMethod.COMPOUND_GET_SHORT) {
return (short) 0;
} else if (type == ReflectionMethod.COMPOUND_GET_BOOLEAN) {
return false;
} else if (type == ReflectionMethod.COMPOUND_GET_INT) {
return 0;
} else if (type == ReflectionMethod.COMPOUND_GET_LONG) {
return 0L;
} else if (type == ReflectionMethod.COMPOUND_GET_FLOAT) {
return 0.0f;
} else if (type == ReflectionMethod.COMPOUND_GET_DOUBLE) {
return 0.0d;
} else if (type == ReflectionMethod.COMPOUND_GET_BYTEARRAY) {
return new byte[0];
} else if (type == ReflectionMethod.COMPOUND_GET_INTARRAY) {
return new int[0];
} else if (type == ReflectionMethod.COMPOUND_GET_LONGARRAY) {
return new long[0];
}
return null;
}
}
@@ -0,0 +1,47 @@
package de.tr7zw.changeme.nbtapi;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* String implementation for NBTLists
*
* @author tr7zw
*
*/
public class NBTStringList extends NBTList<String> {
protected NBTStringList(NBTCompound owner, String name, NBTType type, Object list) {
super(owner, name, type, list);
}
@Override
public String get(int index) {
try {
Object ret = ReflectionMethod.LIST_GET_STRING.run(listObject, index);
if (ret instanceof Optional<?>) {
return ((Optional<String>) ret).orElse("");
}
return (String) ret;
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
@Override
protected Object asTag(String object) {
try {
Constructor<?> con = ClassWrapper.NMS_NBTTAGSTRING.getClazz().getDeclaredConstructor(String.class);
con.setAccessible(true);
return con.newInstance(object);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
}
}
}
@@ -0,0 +1,114 @@
package de.tr7zw.changeme.nbtapi;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import de.tr7zw.changeme.nbtapi.utils.CheckUtil;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* NBT class to access vanilla tags from TileEntities. TileEntities don't
* support custom tags. Use the NBTInjector for custom tags. Changes will be
* instantly applied to the Tile, use the merge method to do many things at
* once.
*
* @author tr7zw
*
*/
public class NBTTileEntity extends NBTCompound {
private final BlockState tile;
private final boolean readonly;
private final Object compound;
private boolean closed = false;
/**
* @param tile BlockState from any TileEntity
* @param readonly Readonly makes a copy at init, only reading from that copy
*/
protected NBTTileEntity(BlockState tile, boolean readonly) {
super(null, null);
if (tile == null || (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3) && !tile.isPlaced())) {
throw new NullPointerException("Tile can't be null/not placed!");
}
this.tile = tile;
this.readonly = readonly;
if (readonly) {
this.compound = getCompound();
} else {
this.compound = null;
}
}
/**
* Deprecated: Please use the NBT class
*
* @param tile BlockState from any TileEntity
*/
@Deprecated
public NBTTileEntity(BlockState tile) {
super(null, null);
if (tile == null || (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3) && !tile.isPlaced())) {
throw new NullPointerException("Tile can't be null/not placed!");
}
this.readonly = false;
this.compound = null;
this.tile = tile;
}
@Override
protected void setClosed() {
this.closed = true;
}
@Override
protected boolean isClosed() {
return closed;
}
@Override
protected boolean isReadOnly() {
return readonly;
}
@Override
public Object getCompound() {
// this runs before async check, since it's just a copy
if (readonly && compound != null) {
return compound;
}
if (!Bukkit.isPrimaryThread())
throw new NbtApiException("BlockEntity NBT needs to be accessed sync!");
return NBTReflectionUtil.getTileEntityNBTTagCompound(tile);
}
@Override
protected void setCompound(Object compound) {
if (readonly) {
throw new NbtApiException("Tried setting data in read only mode!");
}
if (!Bukkit.isPrimaryThread())
throw new NbtApiException("BlockEntity NBT needs to be accessed sync!");
NBTReflectionUtil.setTileEntityNBTTagCompound(tile, compound);
}
/**
* Gets the NBTCompound used by spigots PersistentDataAPI. This method is only
* available for 1.14+!
*
* @return NBTCompound containing the data of the PersistentDataAPI
*/
public NBTCompound getPersistentDataContainer() {
CheckUtil.assertAvailable(MinecraftVersion.MC1_14_R1);
if (hasTag("PublicBukkitValues")) {
return getCompound("PublicBukkitValues");
} else {
NBTContainer container = new NBTContainer();
container.addCompound("PublicBukkitValues").setString("__nbtapi",
"Marker to make the PersistentDataContainer have content");
mergeCompound(container);
return getCompound("PublicBukkitValues");
}
}
}
@@ -0,0 +1,54 @@
package de.tr7zw.changeme.nbtapi;
/**
* Enum of all NBT Types Minecraft contains
*
* @author tr7zw
*
*/
@SuppressWarnings("javadoc")
public enum NBTType {
NBTTagEnd(0, ""), NBTTagByte(1, "BYTE"), NBTTagShort(2, "SHORT"), NBTTagInt(3, "INT"), NBTTagLong(4, "LONG"), NBTTagFloat(5, "FLOAT"), NBTTagDouble(6, "DOUBLE"),
NBTTagByteArray(7, "BYTE[]"), NBTTagString(8, "STRING"), NBTTagList(9, "LIST"), NBTTagCompound(10, "COMPOUND"), NBTTagIntArray(11, "INT[]"), NBTTagLongArray(12, "LONG[]");
NBTType(int i, String name) {
id = i;
this.name = name;
}
private final int id;
private final String name;
/**
* @return Id used by Minecraft internally
*/
public int getId() {
return id;
}
/**
* @return Name of the NBTType
*/
public String getName() {
return name;
}
/**
* @param id Internal Minecraft id
* @return Enum representing the id, NBTTagEnd for invalide ids
*/
public static NBTType valueOf(int id) {
for (NBTType t : values())
if (t.getId() == id)
return t;
return NBTType.NBTTagEnd;
}
public static NBTType fromName(String name) {
for (NBTType t : values())
if (t.getName().equals(name))
return t;
return NBTType.NBTTagEnd;
}
}
@@ -0,0 +1,53 @@
package de.tr7zw.changeme.nbtapi;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
import de.tr7zw.changeme.nbtapi.utils.UUIDUtil;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* Integer implementation for NBTLists
*
* @author tr7zw
*
*/
public class NBTUUIDList extends NBTList<UUID> {
private final NBTContainer tmpContainer;
protected NBTUUIDList(NBTCompound owner, String name, NBTType type, Object list) {
super(owner, name, type, list);
this.tmpContainer = new NBTContainer();
}
@Override
protected Object asTag(UUID object) {
try {
Constructor<?> con = ClassWrapper.NMS_NBTTAGINTARRAY.getClazz().getDeclaredConstructor(int[].class);
con.setAccessible(true);
return con.newInstance(UUIDUtil.uuidToIntArray(object));
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new NbtApiException("Error while wrapping the Object " + object + " to it's NMS object!", e);
}
}
@Override
public UUID get(int index) {
try {
Object obj = ReflectionMethod.LIST_GET.run(listObject, index);
ReflectionMethod.COMPOUND_SET.run(tmpContainer.getCompound(), "tmp", obj);
int[] val = tmpContainer.getIntArray("tmp");
tmpContainer.removeKey("tmp");
return UUIDUtil.uuidFromIntArray(val);
} catch (NumberFormatException nf) {
return null;
} catch (Exception ex) {
throw new NbtApiException(ex);
}
}
}
@@ -0,0 +1,68 @@
package de.tr7zw.changeme.nbtapi;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* A generic {@link RuntimeException} that can be thrown by most methods in the
* NBTAPI.
*
* @author tr7zw
*
*/
public class NbtApiException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = -993309714559452334L;
/**
* Keep track of the plugin selfcheck. Null = not
* checked(silentquickstart/shaded) true = selfcheck failed false = everything
* should be fine, but apparently wasn't?
*/
public static Boolean confirmedBroken = null;
/**
*
*/
public NbtApiException() {
super();
}
/**
* @param message
* @param cause
*/
public NbtApiException(String message, Throwable cause) {
super(generateMessage(message), cause);
}
/**
* @param message
*/
public NbtApiException(String message) {
super(generateMessage(message));
}
/**
* @param cause
*/
public NbtApiException(Throwable cause) {
super(generateMessage(cause == null ? null : cause.toString()), cause);
}
private static String generateMessage(String message) {
if (message == null)
return null;
if (confirmedBroken == null) {
return "[?][" + MinecraftVersion.getNBTAPIVersion() + "]" + message;
} else if (confirmedBroken == false) {
return "[Selfchecked][" + MinecraftVersion.getNBTAPIVersion() + "]" + message;
}
return "[" + MinecraftVersion.getVersion() + "][" + MinecraftVersion.getNBTAPIVersion()
+ "]There were errors detected during the server self-check! Please, make sure that NBT-API is up to date. Error message: "
+ message;
}
}
@@ -0,0 +1,89 @@
package de.tr7zw.changeme.nbtapi.handler;
import org.bukkit.inventory.ItemStack;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.iface.NBTHandler;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
public class NBTHandlers {
public static final NBTHandler<ItemStack> ITEM_STACK = new NBTHandler<ItemStack>() {
@Override
public boolean fuzzyMatch(Object obj) {
return obj instanceof ItemStack;
}
@Override
public void set(ReadWriteNBT nbt, String key, ItemStack value) {
nbt.removeKey(key);
ReadWriteNBT tag = nbt.getOrCreateCompound(key);
tag.mergeCompound(NBT.itemStackToNBT(value));
}
@Override
public ItemStack get(ReadableNBT nbt, String key) {
ReadableNBT tag = nbt.getCompound(key);
if (tag != null) {
return NBT.itemStackFromNBT(tag);
}
return null;
}
};
public static final NBTHandler<ReadableNBT> STORE_READABLE_TAG = new NBTHandler<ReadableNBT>() {
@Override
public boolean fuzzyMatch(Object obj) {
return obj instanceof ReadableNBT;
}
@Override
public void set(ReadWriteNBT nbt, String key, ReadableNBT value) {
nbt.removeKey(key);
nbt.getOrCreateCompound(key).mergeCompound(value);
}
@Override
public ReadableNBT get(ReadableNBT nbt, String key) {
ReadableNBT tag = nbt.getCompound(key);
if (tag != null) {
ReadWriteNBT value = NBT.createNBTObject();
value.mergeCompound(tag);
return value;
}
return null;
}
};
public static final NBTHandler<ReadWriteNBT> STORE_READWRITE_TAG = new NBTHandler<ReadWriteNBT>() {
@Override
public boolean fuzzyMatch(Object obj) {
return obj instanceof ReadWriteNBT;
}
@Override
public void set(ReadWriteNBT nbt, String key, ReadWriteNBT value) {
nbt.removeKey(key);
nbt.getOrCreateCompound(key).mergeCompound(value);
}
@Override
public ReadWriteNBT get(ReadableNBT nbt, String key) {
ReadableNBT tag = nbt.getCompound(key);
if (tag != null) {
ReadWriteNBT value = NBT.createNBTObject();
value.mergeCompound(tag);
return value;
}
return null;
}
};
}
@@ -0,0 +1,20 @@
package de.tr7zw.changeme.nbtapi.iface;
import java.io.File;
import java.io.IOException;
public interface NBTFileHandle extends ReadWriteNBT {
/**
* Saves the data to the file
*
* @throws IOException
*/
void save() throws IOException;
/**
* @return The File used to store the data
*/
File getFile();
}
@@ -0,0 +1,15 @@
package de.tr7zw.changeme.nbtapi.iface;
import javax.annotation.Nonnull;
public interface NBTHandler<T> {
public default boolean fuzzyMatch(Object obj) {
return false;
}
public void set(@Nonnull ReadWriteNBT nbt, @Nonnull String key, @Nonnull T value);
public T get(@Nonnull ReadableNBT nbt, @Nonnull String key);
}
@@ -0,0 +1,48 @@
package de.tr7zw.changeme.nbtapi.iface;
import java.util.function.BiConsumer;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import de.tr7zw.changeme.nbtapi.NBTItem;
public interface ReadWriteItemNBT extends ReadWriteNBT, ReadableItemNBT {
/**
* True, if the item has any tags now known for this item type.
*
* @return true when custom tags are present
*/
public boolean hasCustomNbtData();
/**
* Remove all custom (non-vanilla) NBT tags from the NBTItem.
*/
public void clearCustomNBT();
/**
* Gives save access to the {@link ItemMeta} of the internal {@link ItemStack}.
* Supported operations while inside this scope: - any get/set method of
* {@link ItemMeta} - any getter on {@link NBTItem}
*
* All changes made to the {@link NBTItem} during this scope will be reverted at
* the end.
*
* @param handler
*/
public void modifyMeta(BiConsumer<ReadableNBT, ItemMeta> handler);
/**
* Gives save access to the {@link ItemMeta} of the internal {@link ItemStack}.
* Supported operations while inside this scope: - any get/set method of
* {@link ItemMeta} - any getter on {@link NBTItem}
*
* All changes made to the {@link NBTItem} during this scope will be reverted at
* the end.
*
* @param handler
*/
public <T extends ItemMeta> void modifyMeta(Class<T> type, BiConsumer<ReadableNBT, T> handler);
}
@@ -0,0 +1,216 @@
package de.tr7zw.changeme.nbtapi.iface;
import java.util.UUID;
import javax.annotation.Nullable;
import org.bukkit.inventory.ItemStack;
public interface ReadWriteNBT extends ReadableNBT {
/**
* Merges all data from comp into this compound. This is done in one action, so
* it also works with Tiles/Entities
*
* @param comp
*/
void mergeCompound(ReadableNBT comp);
/**
* Setter
*
* @param key
* @param value
*/
void setString(String key, String value);
/**
* Setter
*
* @param key
* @param value
*/
void setInteger(String key, Integer value);
/**
* Setter
*
* @param key
* @param value
*/
void setDouble(String key, Double value);
/**
* Setter
*
* @param key
* @param value
*/
void setByte(String key, Byte value);
/**
* Setter
*
* @param key
* @param value
*/
void setShort(String key, Short value);
/**
* Setter
*
* @param key
* @param value
*/
void setLong(String key, Long value);
/**
* Setter
*
* @param key
* @param value
*/
void setFloat(String key, Float value);
/**
* Setter
*
* @param key
* @param value
*/
void setByteArray(String key, byte[] value);
/**
* Setter
*
* @param key
* @param value
*/
void setIntArray(String key, int[] value);
/**
* Setter
*
* Requires 1.16+
*
* @param key
* @param value
*/
void setLongArray(String key, long[] value);
/**
* Setter
*
* @param key
* @param value
*/
void setBoolean(String key, Boolean value);
/**
* Save an ItemStack as a compound under a given key
*
* @param key
* @param item
*/
void setItemStack(String key, ItemStack item);
/**
* Save an ItemStack Array as a compound under a given key
*
* @param key
* @param items
*/
void setItemStackArray(String key, ItemStack[] items);
/**
* Setter
*
* @param key
* @param value
*/
void setUUID(String key, UUID value);
/**
* @param key Deletes the given Key
*/
void removeKey(String key);
/**
* The same as addCompound, just with a name that better reflects what it does
*
* @param name
* @return
*/
ReadWriteNBT getOrCreateCompound(String name);
/**
* @param name
* @return The Compound instance or null
*/
@Nullable
ReadWriteNBT getCompound(String name);
/**
* Returns the resolved and creates compounds as required.
* <p>
*
* @param key Path key, seperated by '.'. For example: "foo.bar.baz". Dots can
* be escaped with a backslash.
* @return The resolved compound.
*/
ReadWriteNBT resolveOrCreateCompound(String key);
/**
* Set an Object to a key via the provided handler.
*
* @param <T>
* @param key
* @param value
* @param handler
*/
<T> void set(String key, T value, NBTHandler<T> handler);
/**
* Set a key to the given Enum value. It gets stored as a String. Passing null
* as value will call removeKey(key) instead.
*
* @param <E>
* @param key
* @param value
*/
<E extends Enum<?>> void setEnum(String key, E value);
@Override
ReadWriteNBTList<String> getStringList(String name);
@Override
ReadWriteNBTList<Integer> getIntegerList(String name);
@Override
ReadWriteNBTList<int[]> getIntArrayList(String name);
@Override
ReadWriteNBTList<UUID> getUUIDList(String name);
@Override
ReadWriteNBTList<Float> getFloatList(String name);
@Override
ReadWriteNBTList<Double> getDoubleList(String name);
@Override
ReadWriteNBTList<Long> getLongList(String name);
@Override
ReadWriteNBTCompoundList getCompoundList(String name);
@Override
@Nullable
ReadWriteNBT resolveCompound(String key);
/**
* Remove all keys from this compound
*/
void clearNBT();
}
@@ -0,0 +1,44 @@
package de.tr7zw.changeme.nbtapi.iface;
import java.util.function.Predicate;
public interface ReadWriteNBTCompoundList extends ReadableNBTList<ReadWriteNBT> {
/**
* Adds a new compound tag to the current compound tag
*
* @return A new instance of the class.
*/
ReadWriteNBT addCompound();
/**
* Adds a copy of the Compound to the end of the List and returns it. When null
* is given, a new Compound will be created
*
* @param comp
* @return
*/
ReadWriteNBT addCompound(ReadableNBT comp);
/**
* Removes the element at the specified position in this list
*
* @param i The index of the element to remove.
* @return A new instance of the class.
*/
ReadWriteNBT remove(int i);
/**
* Clears the contents of the list
*/
void clear();
/**
* Removes all elements of this list that satisfy the given predicate
*
* @param pred The predicate to use to test elements.
* @return A boolean value.
*/
boolean removeIf(Predicate<? super ReadWriteNBT> pred);
}
@@ -0,0 +1,116 @@
package de.tr7zw.changeme.nbtapi.iface;
import java.util.Collection;
import java.util.ListIterator;
import java.util.function.Predicate;
public interface ReadWriteNBTList<T> extends ReadableNBTList<T> {
/**
* Adds the specified element to this set if it is not already present.
*
* @param element The element to be added to the list.
* @return A boolean value.
*/
boolean add(T element);
/**
* Adds the specified element at the specified position in this list.
*
* @param index The index at which the specified element is to be inserted
* @param element The element to be added to the list.
*/
void add(int index, T element);
/**
* Replaces the element at the specified position in this list with the
* specified element.
*
* @param index The index of the element to replace
* @param element The element to be stored at the specified position
* @return The element that was previously at the specified position.
*/
T set(int index, T element);
/**
* Remove the element at index i and return it.
*
* @param i the index of the element to be removed
* @return The element that was removed.
*/
T remove(int i);
/**
* Clears the contents of the list
*/
void clear();
/**
* Adds all of the elements in the specified collection to this collection.
*
* @param c The collection to be added to the list.
* @return A boolean value.
*/
boolean addAll(Collection<? extends T> c);
/**
* Inserts all of the elements in the specified collection into this list,
* starting at the specified position.
*
* @param index The index at which the elements of the specified collection are
* to be inserted.
* @param c The collection to be added to the list.
* @return A boolean value.
*/
boolean addAll(int index, Collection<? extends T> c);
/**
* Removes from this collection all of its elements that are contained in the
* specified collection
*
* @param c The collection to be removed from this list.
* @return A boolean value.
*/
boolean removeAll(Collection<?> c);
/**
* Removes all of this collection's elements that are not contained in the
* specified collection.
*
* @param c The collection to be retained in this list
* @return A boolean value.
*/
boolean retainAll(Collection<?> c);
/**
* "Remove all elements from the list that match the given predicate."
*
* The Predicate interface is a functional interface that takes a single
* argument and returns a boolean
*
* @param pred The predicate to apply to each element to determine if it should
* be removed.
* @return A boolean value.
*/
boolean removeIf(Predicate<? super T> pred);
/**
* Removes the first occurrence of the specified element from this list, if it
* is present.
*
* @param o The object to be removed from the list.
* @return A boolean value.
*/
boolean remove(Object o);
/**
* Returns a list iterator over the elements in this list (in proper sequence),
* starting at the specified position in the list
*
* @param startIndex The index of the first element to be returned from the list
* iterator (by a call to the next method).
* @return A list iterator of the list starting at the specified index.
*/
ListIterator<T> listIterator(int startIndex);
}
@@ -0,0 +1,12 @@
package de.tr7zw.changeme.nbtapi.iface;
public interface ReadableItemNBT extends ReadableNBT {
/**
* Returns true if the item has NBT data.
*
* @return Does the ItemStack have a NBTCompound.
*/
public boolean hasNBTData();
}
@@ -0,0 +1,372 @@
package de.tr7zw.changeme.nbtapi.iface;
import java.io.OutputStream;
import java.util.Set;
import java.util.UUID;
import javax.annotation.Nullable;
import org.bukkit.inventory.ItemStack;
import de.tr7zw.changeme.nbtapi.NBTType;
/**
* This interface only exposes methods that get data without any changes to the
* underlying object.
*
* @author tr7zw
*
*/
public interface ReadableNBT {
/**
* Given a key, return the value associated with that key.
*
* @param key The key to get the value for.
* @return The value of the key.
*/
String getString(String key);
/**
* Given a key, return the value associated with that key as an Integer, or 0 if
* the key is not found.
*
* @param key The key to look up in the properties file.
* @return The value of the key.
*/
Integer getInteger(String key);
/**
* Returns the value associated with the given key as a double, or false of not
* found.
*
* @param key The key of the preference to retrieve.
* @return A double value
*/
Double getDouble(String key);
/**
* Get the value of the given key as a byte, or 0 if the key is not found.
*
* @param key The key to get the value for.
* @return A byte
*/
Byte getByte(String key);
/**
* Returns the value of the key as a Short, or 0 if the key is not found.
*
* @param key The key of the value you want to get.
* @return A short value
*/
Short getShort(String key);
/**
* Returns the value associated with the given key as a Long, or 0 if the key is
* not found.
*
* @param key The key of the value you want to get.
* @return A Long object
*/
Long getLong(String key);
/**
* Returns the value of the given key as a Float, or 0 if the key does not
* exist.
*
* @param key The key of the preference to retrieve.
* @return A float value
*/
Float getFloat(String key);
/**
* Returns the value associated with the given key as a byte array, or null if
* the key is not found.
*
* @param key The key to use to retrieve the value.
* @return A byte array.
*/
@Nullable
byte[] getByteArray(String key);
/**
* Returns the value associated with the given key as an array of integers, or
* null if the key does not exist.
*
* @param key The key of the value you want to get.
* @return An array of integers.
*/
@Nullable
int[] getIntArray(String key);
/**
* Returns the value associated with the given key as an array of longs, or null
* if the key does not exist.
*
* Requires 1.16+
*
* @param key The key of the value you want to get.
* @return An array of integers.
*/
@Nullable
long[] getLongArray(String key);
/**
* Returns the value associated with the given key, or false if the key is not
* found.
*
* @param key The key of the preference to retrieve.
* @return A boolean value.
*/
Boolean getBoolean(String key);
/**
* It returns an ItemStack associated with the given key, or null if the key
* does not exist.
*
* @param key The key of the itemstack you want to get.
* @return An ItemStack
*/
@Nullable
ItemStack getItemStack(String key);
/**
* Get an {@link ItemStack} array that was saved at the given key, or null if no
* stored data was found
*
* @param key key
* @return The stored {@link ItemStack} array, or null if stored data wasn't
* found
*/
@Nullable
ItemStack[] getItemStackArray(String key);
/**
* Given a key, return the UUID of the key.
*
* @param key The key to get the value from
* @return A UUID object.
*/
@Nullable
UUID getUUID(String key);
/**
* Checks whether the provided key exists
*
* @param key String key
* @return true, if the key is set
*/
boolean hasTag(String key);
/**
* Checks whether the provided key exists and has the specified type
*
* @param key String key
* @param type nbt tag type
* @return whether the key is set and has the specified type
*/
default boolean hasTag(String key, NBTType type) {
return hasTag(key) && getType(key) == type;
}
/**
* @return Set of all stored Keys
*/
Set<String> getKeys();
/**
* Checks whether this NBT is empty (has no stored data).
*
* @return whether this NBT is empty
*/
default boolean isEmpty() {
return getKeys().isEmpty();
}
/**
* @param name
* @return The Compound instance or null
*/
@Nullable
ReadableNBT getCompound(String name);
/**
* @param name
* @return The retrieved String List
*/
ReadableNBTList<String> getStringList(String name);
/**
* @param name
* @return The retrieved Integer List
*/
ReadableNBTList<Integer> getIntegerList(String name);
/**
* @param name
* @return The retrieved Integer List
*/
ReadableNBTList<int[]> getIntArrayList(String name);
/**
* @param name
* @return The retrieved Integer List
*/
ReadableNBTList<UUID> getUUIDList(String name);
/**
* @param name
* @return The retrieved Float List
*/
ReadableNBTList<Float> getFloatList(String name);
/**
* @param name
* @return The retrieved Double List
*/
ReadableNBTList<Double> getDoubleList(String name);
/**
* @param name
* @return The retrieved Long List
*/
ReadableNBTList<Long> getLongList(String name);
/**
* Returns the type of the list, null if not a list
*
* @param name
* @return
*/
@Nullable
NBTType getListType(String name);
/**
* @param name
* @return The retrieved Compound List
*/
ReadableNBTList<ReadWriteNBT> getCompoundList(String name);
/**
* Returns the stored value if exists, or provided value otherwise.
* <p>
* Supported types:
* {@code Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[], long[]},
* {@link String}, {@link UUID}, and {@link Enum}
*
* @param key key
* @param defaultValue default non-null value
* @param <T> value type
* @return Stored or provided value
*/
<T> T getOrDefault(String key, T defaultValue);
/**
* Returns the stored value if exists, or null.
* <p>
* Supported types:
* {@code Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[], long[]},
* {@link String}, {@link UUID}, and {@link Enum}
*
* @param key key
* @param type data type
* @param <T> value type
* @return Stored or provided value
*/
@Nullable
<T> T getOrNull(String key, Class<?> type);
/**
* Returns the resolved value if exists, or null.
* <p>
* Supported types:
* {@code Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[], long[]},
* {@link String}, {@link UUID}, and {@link Enum}
*
* @param key Path key, separated by '.'. For example: "foo.bar.baz". Dots can
* be escaped with a backslash.
* @param type data type
* @param <T> value type
* @return resolved or provided value
*/
@Nullable
<T> T resolveOrNull(String key, Class<?> type);
/**
* Returns the resolved value if exists, or provided value otherwise.
* <p>
* Supported types:
* {@code Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[], long[]},
* {@link String}, {@link UUID}, and {@link Enum}
*
* @param key Path key, separated by '.'. For example: "foo.bar.baz".
* Dots can be escaped with a backslash.
* @param defaultValue default non-null value
* @param <T> value type
* @return resolved or provided value
*/
<T> T resolveOrDefault(String key, T defaultValue);
/**
* Returns the resolved Compound if exists, or null.
* <p>
*
* @param key Path key, separated by '.'. For example: "foo.bar.baz". Dots can
* be escaped with a backslash.
* @return The resolved value if exists, or null.
*/
@Nullable
ReadableNBT resolveCompound(String key);
/**
* Get the object at the specified key via the handler.
*
* @param <T>
* @param key
* @param handler
* @return
*/
<T> T get(String key, NBTHandler<T> handler);
/**
* Get an Enum value that has been set via setEnum or setString(key,
* value.name()). Passing null/invalid keys will return null.
*
* @param <E>
* @param key
* @param type
* @return
*/
@Nullable
<E extends Enum<E>> E getEnum(String key, Class<E> type);
/**
* @param name
* @return The type of the given stored key or null
*/
NBTType getType(String name);
/**
* Write the content of this Compound into the provided stream.
*
* @param stream
*/
void writeCompound(OutputStream stream);
/**
* Compares this readable nbt to the other one
* and returns the difference.
* <p>Note: the result will only contain data that is present
* in this readable nbt and is missing/different in the provided one.
*
* @param other other readable nbt
* @return difference between readable nbts
*/
ReadWriteNBT extractDifference(ReadableNBT other);
/**
* @return The NBT as printable NBT-Json.
*/
String toString();
}
@@ -0,0 +1,117 @@
package de.tr7zw.changeme.nbtapi.iface;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import de.tr7zw.changeme.nbtapi.NBTType;
public interface ReadableNBTList<T> extends Iterable<T> {
/**
* Get the object with the given id.
*
* @param id The id of the object to get.
* @return The object with the given id.
*/
T get(int id);
/**
* Returns the number of elements in this list.
*
* @return The size of the list.
*/
int size();
/**
* Returns the type of this tag
*
* @return The type of the tag.
*/
NBTType getType();
/**
* Returns true if the list is empty, false otherwise.
*
* @return A boolean value.
*/
boolean isEmpty();
/**
* Returns true if this list contains the specified element.
*
* @param o The object to be searched for in the list.
* @return A boolean value.
*/
boolean contains(Object o);
/**
* Returns the index of the first occurrence of the specified element in this
* list, or -1 if this list does not contain the element.
*
* @param o The object to search for.
* @return The index of the first occurrence of the specified element in this
* list, or -1 if this list does not contain the element.
*/
int indexOf(Object o);
/**
* Returns true if this collection contains all of the elements in the specified
* collection
*
* @param c The collection to be checked for containment in this list
* @return A boolean value.
*/
boolean containsAll(Collection<?> c);
/**
* Returns the index of the last occurrence of the specified element in this
* list, or -1 if this list does not contain the element
*
* @param o The object to search for.
* @return The index of the last occurrence of the specified element in this
* list, or -1 if this list does not contain the element.
*/
int lastIndexOf(Object o);
/**
* Returns an array containing all of the elements in this list in proper
* sequence (from first to last element).
*
* @return An array of objects.
*/
Object[] toArray();
/**
* Returns an array containing all of the elements in this list in proper
* sequence (from first to last element).
*
* @param a The array into which the elements of the list are to be stored, if
* it is big enough; otherwise, a new array of the same runtime type is
* allocated for this purpose.
* @return An array of the elements in the list.
*/
<E> E[] toArray(E[] a);
/**
* Returns a view of the portion of this list between the specified fromIndex,
* inclusive, and toIndex, exclusive
*
* @param fromIndex The starting index of the sublist (inclusive).
* @param toIndex The index of the last element in the sublist.
* @return A view of the specified range within this list.
*/
List<T> subList(int fromIndex, int toIndex);
/**
* Create a new list containing all entries of this list.
*
* @return A list of the elements in the stream.
*/
default List<T> toListCopy() {
List<T> list = new ArrayList<>();
iterator().forEachRemaining(list::add);
return list;
}
}
@@ -0,0 +1,17 @@
package de.tr7zw.changeme.nbtapi.utils;
import de.tr7zw.changeme.nbtapi.NbtApiException;
public class CheckUtil {
private CheckUtil() {
// util
}
public static void assertAvailable(MinecraftVersion version) {
if (!MinecraftVersion.isAtLeastVersion(version))
throw new NbtApiException(
"This Method is only avaliable for the version " + version.name() + " and above!");
}
}
@@ -0,0 +1,150 @@
package de.tr7zw.changeme.nbtapi.utils;
import com.mojang.datafixers.DSL.TypeReference;
import com.mojang.datafixers.DataFixer;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.DynamicOps;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTReflectionUtil;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
public class DataFixerUtil {
// https://minecraft.wiki/w/Data_version
public static final int VERSION1_12R1 = 1343;
public static final int VERSION1_16R1 = 2586;
public static final int VERSION1_17R1 = 2730;
public static final int VERSION1_18R1 = 2975;
public static final int VERSION1_19R1 = 3120;
public static final int VERSION1_19R3 = 3337;
public static final int VERSION1_20R1 = 3465;
public static final int VERSION1_20R2 = 3578;
public static final int VERSION1_20R3 = 3700;
public static final int VERSION1_20R4 = 3837;
public static final int VERSION1_21R1 = 3953;
public static final int VERSION1_21R2 = 4080;
public static final int VERSION1_21R3 = 4189;
public static final int VERSION1_21R4 = 4323;
public static final int VERSION1_21R5 = 4435;
public static final int VERSION1_21R6 = 4554;
public static final int VERSION1_21R7 = 4671;
public static final int VERSION_26_1 = 4786;
public static final int VERSION_26_2 = 4903;
public static final int VERSION_26_3 = 5023;
// There was a mixup between version numbers and revisions, kept for compatibility, use the above revision numbers
@Deprecated
public static final int VERSION1_12_2 = 1343;
@Deprecated
public static final int VERSION1_16_5 = 2586;
@Deprecated
public static final int VERSION1_17_1 = 2730;
@Deprecated
public static final int VERSION1_18_2 = 2975;
@Deprecated
public static final int VERSION1_19_2 = 3120;
@Deprecated
public static final int VERSION1_19_4 = 3337;
@Deprecated
public static final int VERSION1_20_1 = 3465;
@Deprecated
public static final int VERSION1_20_2 = 3578;
@Deprecated
public static final int VERSION1_20_4 = 3700;
@Deprecated
public static final int VERSION1_20_5 = 3837;
// the 1.21 versions use Revision instead of patch versions, unlike the other above. kept for compatibility
@Deprecated
public static final int VERSION1_21 = 3953;
@Deprecated
public static final int VERSION1_21_2 = 4080;
@Deprecated
public static final int VERSION1_21_3 = 4189;
@Deprecated
public static final int VERSION1_21_4 = 4323;
@Deprecated
public static final int VERSION1_21_5 = 4435;
@SuppressWarnings("unchecked")
public static Object fixUpRawItemData(Object nbt, int fromVersion, int toVersion)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
DataFixer dataFixer = (DataFixer) ReflectionMethod.GET_DATAFIXER.run(null);
TypeReference itemStackReference = (TypeReference) ReflectionUtil.getMappedField(ClassWrapper.NMS_REFERENCES.getClazz(),"net.minecraft.util.datafix.fixes.References#ITEM_STACK").get(null);
DynamicOps<Object> nbtOps = (DynamicOps<Object>) ReflectionUtil.getMappedField(ClassWrapper.NMS_NBTOPS.getClazz(), "net.minecraft.nbt.NbtOps#INSTANCE").get(null);
Dynamic<Object> fixed = dataFixer.update(itemStackReference, new Dynamic<Object>(nbtOps, nbt), fromVersion,
toVersion);
return fixed.getValue();
}
public static ReadWriteNBT fixUpItemData(ReadWriteNBT nbt, int fromVersion, int toVersion)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
ReadWriteNBT tag = NBT.wrapNMSTag(fixUpRawItemData(
NBTReflectionUtil.getToCompount(((NBTCompound) nbt).getCompound(), ((NBTCompound) nbt)), fromVersion,
toVersion));
tag.setInteger("DataVersion", toVersion);
return tag;
}
public static ReadWriteNBT fixUpItemData(ReadWriteNBT nbt, int fromVersion)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
return fixUpItemData(nbt, fromVersion, getCurrentVersion());
}
/**
* This method will return the closest or exact version number of the current
* server. Only contains versions people will reasonably use and will fail with
* an exception, when the target version is before 1.12.2. (Assuming no one will
* update 1.8 items to 1.11, if so, provide the version numbers to the converter
* method directly)
*
* @return
*/
public static int getCurrentVersion() {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC26_3)) {
return VERSION_26_3;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC26_2)) {
return VERSION_26_2;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC26_1)) {
return VERSION_26_1;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R7)) {
return VERSION1_21R7;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R6)) {
return VERSION1_21R6;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R5)) {
return VERSION1_21R5;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R4)) {
return VERSION1_21R4;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R3)) {
return VERSION1_21R3;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R2)) {
return VERSION1_21R2;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R1)) {
return VERSION1_21R1;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
return VERSION1_20R4;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R3)) {
return VERSION1_20R3;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R1)) {
return VERSION1_20R1;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_19_R3)) {
return VERSION1_19R3;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_19_R1)) {
return VERSION1_19R1;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_18_R1)) {
return VERSION1_18R1;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_17_R1)) {
return VERSION1_17R1;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1)) {
return VERSION1_16R1;
} else if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_12_R1)) {
return VERSION1_12R1;
}
throw new NbtApiException(
"Trying to update data *to* a version before 1.12.2? Something is probably going wrong, contact the plugin author.");
}
}
@@ -0,0 +1,211 @@
package de.tr7zw.changeme.nbtapi.utils;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.UUID;
import javax.annotation.Nullable;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.PropertyMap;
import de.tr7zw.changeme.nbtapi.NBTType;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBTCompoundList;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBTList;
public class GameprofileUtil {
private static Method GET_NAME = null;
private static Method GET_ID = null;
private static Method GET_VALUE = null;
private static Method GET_SIGNATURE = null;
private static Method GET_PROPERTY_NAME = null;
private static Method GET_PROPERTIES = null;
static {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R6)) {
try {
GET_NAME = GameProfile.class.getDeclaredMethod("name");
GET_ID = GameProfile.class.getDeclaredMethod("id");
GET_VALUE = com.mojang.authlib.properties.Property.class.getDeclaredMethod("value");
GET_SIGNATURE = com.mojang.authlib.properties.Property.class.getDeclaredMethod("signature");
GET_PROPERTY_NAME = com.mojang.authlib.properties.Property.class.getDeclaredMethod("name");
GET_PROPERTIES = GameProfile.class.getDeclaredMethod("properties");
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}
@Nullable
public static GameProfile readGameProfile(ReadableNBT arg) {
String string = null;
UUID uUID = null;
if (arg.hasTag("Name") && arg.getType("Name") == NBTType.NBTTagString) {
string = arg.getString("Name");
} else if (arg.hasTag("name") && arg.getType("name") == NBTType.NBTTagString) {
string = arg.getString("name");
}
if (arg.hasTag("Id") && arg.getType("Id") == NBTType.NBTTagIntArray && arg.getIntArray("Id").length == 4) {
uUID = arg.getUUID("Id");
} else if (arg.hasTag("id") && arg.getType("id") == NBTType.NBTTagIntArray
&& arg.getIntArray("id").length == 4) {
uUID = arg.getUUID("id");
}
try {
GameProfile gameProfile = new GameProfile(uUID, string);
if (arg.hasTag("Properties") && arg.getType("Properties") == NBTType.NBTTagCompound) {
ReadableNBT compoundTag = arg.getCompound("Properties");
for (String string2 : compoundTag.getKeys()) {
ReadableNBTList<ReadWriteNBT> listTag = compoundTag.getCompoundList(string);
for (int i = 0; i < listTag.size(); ++i) {
ReadableNBT compoundTag2 = listTag.get(i);
String string3 = compoundTag2.getString("Value");
if (compoundTag2.hasTag("Signature")
&& compoundTag2.getType("Signature") == NBTType.NBTTagString) {
gameProfile.getProperties().put(string2, new com.mojang.authlib.properties.Property(string2,
string3, compoundTag2.getString("Signature")));
} else {
gameProfile.getProperties().put(string2,
new com.mojang.authlib.properties.Property(string2, string3));
}
}
}
} else if (arg.getType("properties") == NBTType.NBTTagList) { // 1.20.5+
ReadableNBTList<ReadWriteNBT> listTag = arg.getCompoundList("properties");
for (int i = 0; i < listTag.size(); ++i) {
ReadableNBT compoundTag2 = listTag.get(i);
String string2 = compoundTag2.getString("name");
String string3 = compoundTag2.getString("value");
if (compoundTag2.hasTag("signature")
&& compoundTag2.getType("signature") == NBTType.NBTTagString) {
gameProfile.getProperties().put(string2, new com.mojang.authlib.properties.Property(string2,
string3, compoundTag2.getString("signature")));
} else {
gameProfile.getProperties().put(string2,
new com.mojang.authlib.properties.Property(string2, string3));
}
}
}
return gameProfile;
} catch (Throwable var11) {
return null;
}
}
public static ReadWriteNBT writeGameProfile(ReadWriteNBT arg, GameProfile gameProfile) {
String name = getName(gameProfile);
if (!(name == null || name.isEmpty())) {
String nameKey = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4) ? "name" : "Name";
arg.setString(nameKey, getName(gameProfile));
}
UUID id = getId(gameProfile);
if (id != null) {
String idKey = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4) ? "id" : "Id";
arg.setUUID(idKey, id);
}
PropertyMap properties = getProperties(gameProfile);
if (!properties.isEmpty()) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
ReadWriteNBTCompoundList list = arg.getCompoundList("properties");
for (com.mojang.authlib.properties.Property property : properties.values()) {
ReadWriteNBT tag = list.addCompound();
tag.setString("name", getPropertyName(property));
tag.setString("value", getValue(property));
if (property.hasSignature()) {
tag.setString("signature", getSignature(property));
}
}
} else {
ReadWriteNBT compoundTag = arg.getOrCreateCompound("Properties");
for (String string : gameProfile.getProperties().keySet()) {
ReadWriteNBTCompoundList list = compoundTag.getCompoundList(string);
for (com.mojang.authlib.properties.Property property : properties.get(string)) {
ReadWriteNBT tag = list.addCompound();
tag.setString("Value", getValue(property));
if (property.hasSignature()) {
tag.setString("Signature", getSignature(property));
}
}
}
}
}
return arg;
}
private static String getName(GameProfile profile) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R6)) {
try {
return GET_NAME.invoke(profile).toString();
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new NbtApiException("Failed to get GameProfile name via reflection", e);
}
} else {
return profile.getName();
}
}
private static UUID getId(GameProfile profile) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R6)) {
try {
return (UUID) GET_ID.invoke(profile);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new NbtApiException("Failed to get GameProfile id via reflection", e);
}
} else {
return profile.getId();
}
}
private static String getValue(com.mojang.authlib.properties.Property property) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R6)) {
try {
return GET_VALUE.invoke(property).toString();
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new NbtApiException("Failed to get Property value via reflection", e);
}
} else {
return property.getValue();
}
}
private static String getSignature(com.mojang.authlib.properties.Property property) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R6)) {
try {
return GET_SIGNATURE.invoke(property).toString();
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new NbtApiException("Failed to get Property signature via reflection", e);
}
} else {
return property.getSignature();
}
}
private static String getPropertyName(com.mojang.authlib.properties.Property property) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R6)) {
try {
return GET_PROPERTY_NAME.invoke(property).toString();
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new NbtApiException("Failed to get Property name via reflection", e);
}
} else {
return property.getName();
}
}
private static PropertyMap getProperties(GameProfile profile) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R6)) {
try {
return (PropertyMap) GET_PROPERTIES.invoke(profile);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new NbtApiException("Failed to get GameProfile properties via reflection", e);
}
} else {
return profile.getProperties();
}
}
}
@@ -0,0 +1,62 @@
package de.tr7zw.changeme.nbtapi.utils;
import com.google.gson.Gson;
import de.tr7zw.changeme.nbtapi.NbtApiException;
/**
* Helper class for 1.7 servers without Gson
*
* Please consider your own Gson/Jackson instance instead of the built in
* methods.
*
* @author tr7zw
*
*/
@Deprecated
public class GsonWrapper {
/**
* Private constructor
*/
private GsonWrapper() {
}
private static Gson gson = new Gson();
/**
* Turns Objects into Json Strings
*
* @param obj
* @return Json, representing the Object
*/
public static String getString(Object obj) {
return gson.toJson(obj);
}
public static void overwriteGsonInstance(Gson replacement) {
gson = replacement;
}
/**
* Creates an Object of the given type using the Json String
*
* @param json
* @param type
* @return Object that got created, or null if the json is null
*/
public static <T> T deserializeJson(String json, Class<T> type) {
try {
if (json == null) {
return null;
}
T obj = gson.fromJson(json, type);
return type.cast(obj);
} catch (Exception ex) {
throw new NbtApiException("Error while converting json to " + type.getName(), ex);
}
}
}
@@ -0,0 +1,456 @@
package de.tr7zw.changeme.nbtapi.utils;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.DrilldownPie;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
* This class acts as the "Brain" of the NBTApi. It contains the main logger for
* other classes,registers bStats and checks rather Maven shading was done
* correctly.
*
* @author tr7zw
*
*/
@SuppressWarnings("javadoc")
public enum MinecraftVersion {
UNKNOWN(Integer.MAX_VALUE), // Use the newest known mappings
MC1_7_R4(174), MC1_8_R3(183), MC1_9_R1(191), MC1_9_R2(192), MC1_10_R1(1101), MC1_11_R1(1111), MC1_12_R1(1121),
MC1_13_R1(1131), MC1_13_R2(1132), MC1_14_R1(1141), MC1_15_R1(1151), MC1_16_R1(1161), MC1_16_R2(1162),
MC1_16_R3(1163), MC1_17_R1(1171), MC1_18_R1(1181, true), MC1_18_R2(1182, true), MC1_19_R1(1191, true),
MC1_19_R2(1192, true), MC1_19_R3(1193, true), MC1_20_R1(1201, true), MC1_20_R2(1202, true), MC1_20_R3(1203, true),
MC1_20_R4(1204, true), MC1_21_R1(1211, true), MC1_21_R2(1212, true), MC1_21_R3(1213, true), MC1_21_R4(1214, true),
MC1_21_R5(1215, true), MC1_21_R6(1216, true), MC1_21_R7(1217, true), MC26_1(260100, true), MC26_2(260200, true),
MC26_3(260300, true);
private static MinecraftVersion version;
private static Boolean hasGsonSupport;
private static Boolean isForgePresent;
private static Boolean isNeoForgePresent;
private static Boolean isFabricPresent;
private static Boolean isFoliaPresent;
private static boolean bStatsDisabled = false;
private static boolean disablePackageWarning = false;
private static boolean updateCheckDisabled = true;
/**
* Logger used by the api
*/
private static Logger logger = Logger.getLogger("NBTAPI");
// NBT-API Version
protected static final String VERSION = "2.16.1";
private final int versionId;
private final boolean mojangMapping;
// TODO: not nice
private static final Map<String, MinecraftVersion> VERSION_TO_REVISION = new HashMap<String, MinecraftVersion>() {
{
this.put("1.20", MC1_20_R1);
this.put("1.20.1", MC1_20_R1);
this.put("1.20.2", MC1_20_R2);
this.put("1.20.3", MC1_20_R3);
this.put("1.20.4", MC1_20_R3);
this.put("1.20.5", MC1_20_R4);
this.put("1.20.6", MC1_20_R4);
this.put("1.21", MC1_21_R1);
this.put("1.21.1", MC1_21_R1);
this.put("1.21.2", MC1_21_R2);
this.put("1.21.3", MC1_21_R2);
this.put("1.21.4", MC1_21_R3);
this.put("1.21.5", MC1_21_R4);
this.put("1.21.6", MC1_21_R5);
this.put("1.21.7", MC1_21_R5);
this.put("1.21.8", MC1_21_R5);
this.put("1.21.9", MC1_21_R6);
this.put("1.21.10", MC1_21_R6);
this.put("1.21.11", MC1_21_R7);
this.put("26.1", MC26_1);
this.put("26.2", MC26_2);
this.put("26.3", MC26_3);
}
};
MinecraftVersion(int versionId) {
this(versionId, false);
}
MinecraftVersion(int versionId, boolean mojangMapping) {
this.versionId = versionId;
this.mojangMapping = mojangMapping;
}
/**
* @return A simple comparable Integer, representing the version.
*/
public int getVersionId() {
return versionId;
}
/**
* @return True if method names are in Mojang format and need to be remapped
* internally
*/
public boolean isMojangMapping() {
return mojangMapping;
}
/**
* This method is required to hot-wire the plugin during mappings generation for
* newer mc versions thanks to md_5 not used mojmap.
*
* @return
*/
public String getPackageName() {
if (this == UNKNOWN) {
try {
return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
} catch (Exception ex) {
// ignore, paper without remap, will fail
}
}
return this.name().replace("MC", "v");
}
/**
* Returns true if the current versions is at least the given Version
*
* @param version The minimum version
* @return
*/
public static boolean isAtLeastVersion(MinecraftVersion version) {
return getVersion().getVersionId() >= version.getVersionId();
}
/**
* Returns true if the current versions newer (not equal) than the given version
*
* @param version The minimum version
* @return
*/
public static boolean isNewerThan(MinecraftVersion version) {
return getVersion().getVersionId() > version.getVersionId();
}
/**
* Getter for this servers MinecraftVersion. Also init's bStats and checks the
* shading.
*
* @return The enum for the MinecraftVersion this server is running
*/
public static MinecraftVersion getVersion() {
if (version != null) {
return version;
}
try {
final String ver = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
logger.info("[NBTAPI] Found Minecraft: " + ver + "! Trying to find NMS support");
version = MinecraftVersion.valueOf(ver.replace("v", "MC"));
} catch (Exception ex) {
logger.info("[NBTAPI] Found Minecraft: " + Bukkit.getServer().getBukkitVersion().split("-")[0]
+ "! Trying to find NMS support");
version = VERSION_TO_REVISION.get(Bukkit.getServer().getBukkitVersion().split("-")[0]);
if (version == null) {
// check for modern versions with the new versioning scheme, also the new paper version format
String versionString = Bukkit.getServer().getBukkitVersion().split("-")[0].split(".build")[0];
for (Entry<String, MinecraftVersion> entry : VERSION_TO_REVISION.entrySet()) {
if (versionString.startsWith(entry.getKey()) && version == null) {
version = entry.getValue();
// pick the highest revision that matches the version string, in case 26.1.3 is somehow different to 26.1
} else if (versionString.startsWith(entry.getKey()) && entry.getValue().getVersionId() > version.getVersionId()) {
version = entry.getValue();
}
}
}
if (version == null) {
version = UNKNOWN;
}
}
if (version != UNKNOWN) {
logger.info("[NBTAPI] NMS support '" + version.name() + "' loaded!");
} else {
logger.warning("[NBTAPI] This Server-Version(" + Bukkit.getServer().getBukkitVersion()
+ ") is not supported by this NBT-API Version(" + VERSION + ") located in "
+ VersionChecker.getPlugin()
+ ". The NBT-API will try to work as good as it can! Some functions may not work!");
}
init();
return version;
}
public static String getNBTAPIVersion() {
return VERSION;
}
private static void init() {
// Maven's Relocate is clever and changes strings, too. So we have to use this
// little "trick" ... :D (from bStats)
final String defaultPackage = new String(new byte[] { 'd', 'e', '.', 't', 'r', '7', 'z', 'w', '.', 'c', 'h',
'a', 'n', 'g', 'e', 'm', 'e', '.', 'n', 'b', 't', 'a', 'p', 'i', '.', 'u', 't', 'i', 'l', 's' });
final String reservedPackage = new String(new byte[] { 'd', 'e', '.', 't', 'r', '7', 'z', 'w', '.', 'n', 'b',
't', 'a', 'p', 'i', '.', 'u', 't', 'i', 'l', 's' });
try {
if (hasGsonSupport() && !bStatsDisabled) {
Plugin plugin = Bukkit.getPluginManager().getPlugin(VersionChecker.getPlugin());
if (plugin != null && plugin instanceof JavaPlugin) {
getLogger()
.info("[NBTAPI] Using the plugin '" + plugin.getName() + "' to create a bStats instance!");
Metrics metrics = new Metrics((JavaPlugin) plugin, 1058);
metrics.addCustomChart(new SimplePie("nbtapi_version", () -> {
return VERSION;
}));
metrics.addCustomChart(new DrilldownPie("nms_version", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();
Map<String, Integer> entry = new HashMap<>();
entry.put(Bukkit.getName(), 1);
map.put(getVersion().name(), entry);
return map;
}));
metrics.addCustomChart(new SimplePie("shaded", () -> {
return Boolean.toString(!"NBTAPI".equals(VersionChecker.getPlugin()));
}));
metrics.addCustomChart(new SimplePie("server_software", () -> {
return Bukkit.getName();
}));
metrics.addCustomChart(new SimplePie("parent_plugin", () -> {
return VersionChecker.getPluginforBStats();
}));
metrics.addCustomChart(new SimplePie("parent_plugin_type", () -> {
return VersionChecker.getPluginType();
}));
metrics.addCustomChart(new SimplePie("special_environment", () -> {
if (isFoliaPresent()) {
return "Folia";
} else if (isForgePresent()) {
return "Forge";
} else if (isFabricPresent()) {
return "Fabric";
} else if (isNeoForgePresent()) {
return "NeoForge";
} else {
return "None";
}
}));
metrics.addCustomChart(new SimplePie("bindings_check", () -> {
boolean failedBinding = false;
for (ClassWrapper c : ClassWrapper.values()) {
if (c.isEnabled() && c.getClazz() == null) {
failedBinding = true;
}
}
for (ReflectionMethod method : ReflectionMethod.values()) {
if (method.isCompatible() && !method.isLoaded()) {
failedBinding = true;
}
}
return failedBinding ? "Failed" : "Pass";
}));
} else if (plugin == null) {
getLogger().info("[NBTAPI] Unable to create a bStats instance!!");
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, "[NBTAPI] Error enabling Metrics!", ex);
}
if (hasGsonSupport() && !updateCheckDisabled)
new Thread(() -> {
try {
VersionChecker.checkForUpdates();
} catch (Exception ex) {
logger.log(Level.WARNING, "[NBTAPI] Error while checking for updates! Error: " + ex.getMessage());
}
}).start();
if (!disablePackageWarning && MinecraftVersion.class.getPackage().getName().equals(defaultPackage)) {
logger.warning(
"#########################################- NBTAPI -#########################################");
logger.warning(
"The NBT-API package has not been moved! This *will* cause problems with other plugins containing");
logger.warning(
"a different version of the api! Please read the guide on the plugin page on how to get the");
logger.warning(
"Maven Shade plugin to relocate the api to your personal location! If you are not the developer,");
logger.warning("please check your plugins and contact their developer, so they can fix this issue.");
logger.warning(
"#########################################- NBTAPI -#########################################");
}
if (!disablePackageWarning && !"NBTAPI".equals(VersionChecker.getPlugin())) { // we are not the nbtapi, check
// for common shading errors
if (!"de.tr7zw.nbtapi.utils".equals(reservedPackage)) {
logger.warning(
"#########################################- NBTAPI -#########################################");
logger.warning(
"The NBT-API inside " + VersionChecker.getPlugin() + " is the plugin version, not the API!");
logger.warning(
"The plugin itself should never be shaded! Remove the `-plugin` from the dependency and fix your shading setup.");
logger.warning(
"For more info check: https://github.com/tr7zw/Item-NBT-API/wiki/Using-Maven#option-2-shading-the-nbt-api-into-your-plugin");
logger.warning(
"#########################################- NBTAPI -#########################################");
return; // don't also print the second error
}
if (MinecraftVersion.class.getPackage().getName().equals("de.tr7zw.nbtapi.utils")) {
logger.warning(
"#########################################- NBTAPI -#########################################");
logger.warning(
"The NBT-API inside " + VersionChecker.getPlugin() + " is located at 'de.tr7zw.nbtapi.utils'!");
logger.warning(
"This package name is reserved for the official NBTAPI plugin, and not intended to be used for shading!");
logger.warning("Please change the relocate to something else. For example: com.example.util.nbtapi");
logger.warning(
"#########################################- NBTAPI -#########################################");
}
}
}
/**
* @return True, if Gson is usable
*/
public static boolean hasGsonSupport() {
if (hasGsonSupport != null) {
return hasGsonSupport;
}
try {
Class.forName("com.google.gson.Gson");
hasGsonSupport = true;
} catch (Exception ex) {
logger.info("[NBTAPI] Gson not found! This will not allow the usage of some methods!");
hasGsonSupport = false;
}
return hasGsonSupport;
}
/**
* @return True, if Fabric is present
*/
public static boolean isFabricPresent() {
if (isFabricPresent != null) {
return isFabricPresent;
}
try {
logger.info("[NBTAPI] Found Fabric: " + Class.forName("net.fabricmc.api.ModInitializer"));
isFabricPresent = true;
} catch (Exception ex) {
isFabricPresent = false;
}
return isFabricPresent;
}
/**
* @return True, if Forge is present
*/
public static boolean isForgePresent() {
if (isForgePresent != null) {
return isForgePresent;
}
try {
logger.info("[NBTAPI] Found Forge: "
+ (getVersion() == MinecraftVersion.MC1_7_R4 ? Class.forName("cpw.mods.fml.common.Loader")
: Class.forName("net.minecraftforge.fml.common.Loader")));
isForgePresent = true;
} catch (Exception ex) {
isForgePresent = false;
}
return isForgePresent;
}
/**
* @return True, if NeoForge is present
*/
public static boolean isNeoForgePresent() {
if (isNeoForgePresent != null) {
return isNeoForgePresent;
}
try {
logger.info("[NBTAPI] Found NeoForge: " + Class.forName("net.neoforged.neoforge.common.NeoForge"));
isNeoForgePresent = true;
} catch (Exception ex) {
isNeoForgePresent = false;
}
return isNeoForgePresent;
}
/**
* @return True, if Folia is present
*/
public static boolean isFoliaPresent() {
if (isFoliaPresent != null) {
return isFoliaPresent;
}
try {
logger.info("[NBTAPI] Found Folia: " + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"));
isFoliaPresent = true;
} catch (Exception ex) {
isFoliaPresent = false;
}
return isFoliaPresent;
}
/**
* Calling this function before the NBT-Api is used will disable bStats stats
* collection. Please consider not to do that, since it won't affect your plugin
* and helps the NBT-Api developer to see api's demand.
*/
public static void disableBStats() {
bStatsDisabled = true;
}
/**
* Disables the update check. Uses Spiget to get the current version and prints
* a warning when outdated.
*/
public static void disableUpdateCheck() {
updateCheckDisabled = true;
}
/**
* Enables the update check. Uses Spiget to get the current version and prints a
* warning when outdated.
*/
public static void enableUpdateCheck() {
updateCheckDisabled = false;
}
/**
* Forcefully disables the log message for plugins not shading the API to
* another location. This may be helpful for networks or development
* environments, but please don't use it for plugins that are uploaded to
* Spigotmc.
*/
public static void disablePackageWarning() {
disablePackageWarning = true;
}
/**
* @return Logger used by the NBT-API
*/
public static Logger getLogger() {
return logger;
}
/**
* Replaces the NBT-API logger with a custom implementation.
*
* @param logger The new logger(can not be null!)
*/
public static void replaceLogger(Logger logger) {
if (logger == null)
throw new NullPointerException("Logger can not be null!");
MinecraftVersion.logger = logger;
}
}
@@ -0,0 +1,41 @@
package de.tr7zw.changeme.nbtapi.utils;
import java.util.Optional;
import org.bukkit.inventory.ItemStack;
import com.google.gson.JsonElement;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.MojangToMapping;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
public class NBTJsonUtil {
/**
* 1.20.3-1.21.4 only. Used to convert items into Json, used in Chat Hover Components.
*
* @param itemStack
* @return
* @throws NbtApiException
*/
@SuppressWarnings("unchecked")
public static JsonElement itemStackToJson(ItemStack itemStack) {
try {
Codec<Object> itemStackCodec = (Codec<Object>) ClassWrapper.NMS_ITEMSTACK.getClazz()
.getField(MojangToMapping.getMapping().get("net.minecraft.world.item.ItemStack#CODEC")).get(null);
Object stack = ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, itemStack);
DataResult<JsonElement> result = itemStackCodec.encode(stack, JsonOps.INSTANCE,
JsonOps.INSTANCE.emptyMap());
Optional<JsonElement> opt = (Optional<JsonElement>) result.getClass().getMethod("result").invoke(result);
return opt.orElse(null);
} catch (Exception ex) {
throw new NbtApiException("Error trying to get Json of an ItemStack.", ex);
}
}
}
@@ -0,0 +1,60 @@
package de.tr7zw.changeme.nbtapi.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class PathUtil {
private static final Pattern pattern = Pattern.compile("[^\\\\](\\.)");
private static final Pattern indexPattern = Pattern.compile(".*\\[(-?[0-9]+)\\]");
public static List<PathSegment> splitPath(String path) {
List<PathSegment> list = new ArrayList<>();
Matcher matcher = pattern.matcher(path);
int startIndex = 0;
while (matcher.find(startIndex)) {
list.add(new PathSegment(path.substring(startIndex, matcher.end() - 1).replace("\\.", ".")));
startIndex = matcher.end();
}
list.add(new PathSegment(path.substring(startIndex).replace("\\.", ".")));
return list;
}
public static class PathSegment {
private final String path;
private final Integer index;
private PathSegment(String path) {
Matcher matcher = indexPattern.matcher(path);
if (matcher.find()) {
this.path = path.substring(0, path.indexOf("["));
this.index = Integer.parseInt(matcher.group(1));
} else {
this.path = path;
this.index = null;
}
}
public String getPath() {
return path;
}
public int getIndex() {
return index;
}
public boolean hasIndex() {
return index != null;
}
@Override
public String toString() {
return "PathSegment [path=" + path + ", index=" + index + "]";
}
}
}
@@ -0,0 +1,24 @@
package de.tr7zw.changeme.nbtapi.utils;
import java.lang.reflect.Field;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.MojangToMapping;
public final class ReflectionUtil {
public static Field getMappedField(Class<?> clazz, String mapping) {
String mojmapName = mapping.split("#")[1];
try {
return clazz.getField(mojmapName);
} catch (NoSuchFieldException | SecurityException e) {
// not Mojamp, try remapped
}
try {
return clazz.getDeclaredField(MojangToMapping.getMapping().get(mapping));
} catch (Exception e) {
throw new NbtApiException("Unable to find field " + mapping + " in class " + clazz.getName(), e);
}
}
}
@@ -0,0 +1,22 @@
package de.tr7zw.changeme.nbtapi.utils;
import java.util.UUID;
public class UUIDUtil {
public static UUID uuidFromIntArray(int[] is) {
return new UUID((long) is[0] << 32 | (long) is[1] & 4294967295L,
(long) is[2] << 32 | (long) is[3] & 4294967295L);
}
public static int[] uuidToIntArray(UUID uUID) {
long l = uUID.getMostSignificantBits();
long m = uUID.getLeastSignificantBits();
return leastMostToIntArray(l, m);
}
private static int[] leastMostToIntArray(long l, long m) {
return new int[] { (int) (l >> 32), (int) l, (int) (m >> 32), (int) m };
}
}
@@ -0,0 +1,196 @@
package de.tr7zw.changeme.nbtapi.utils;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.Level;
import org.bukkit.configuration.file.YamlConfiguration;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import de.tr7zw.changeme.nbtapi.NBTItem;
/**
* This class uses the Spiget API to check for updates
*
*/
public class VersionChecker {
private static final String USER_AGENT = "nbt-api Version check";
private static final String REQUEST_URL = "https://api.spiget.org/v2/resources/7939/versions?size=100";
public static boolean hideOk = false;
protected static void checkForUpdates() throws Exception {
URL url = new URL(REQUEST_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("User-Agent", USER_AGENT);// Set
// User-Agent
// If you're not sure if the request will be successful,
// you need to check the response code and use #getErrorStream if it
// returned an error code
InputStream inputStream = connection.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
// This could be either a JsonArray or JsonObject
JsonElement element = new JsonParser().parse(reader);
if (element.isJsonArray()) {
// Is JsonArray
JsonArray updates = (JsonArray) element;
JsonObject latest = (JsonObject) updates.get(updates.size() - 1);
int versionDifference = getVersionDifference(latest.get("name").getAsString());
if (versionDifference == -1) { // Outdated
MinecraftVersion.getLogger().log(Level.WARNING,
"[NBTAPI] The NBT-API in '" + getPlugin() + "' seems to be outdated!");
MinecraftVersion.getLogger().log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
+ "' Newest Version: " + latest.get("name").getAsString() + "'");
MinecraftVersion.getLogger().log(Level.WARNING,
"[NBTAPI] Please update the NBTAPI or the plugin that contains the api(nag the mod author when the newest release has an old version, not the NBTAPI dev)!");
} else if (versionDifference == 0) {
if (!hideOk)
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] The NBT-API seems to be up-to-date!");
} else if (versionDifference == 1) {
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] The NBT-API in '" + getPlugin()
+ "' seems to be a future Version, not yet released on Spigot/CurseForge! This is not an error!");
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
+ "' Newest Version: " + latest.get("name").getAsString() + "'");
}
} else {
// wut?!
MinecraftVersion.getLogger().log(Level.WARNING,
"[NBTAPI] Error when looking for Updates! Got non Json Array: '" + element.toString() + "'");
}
}
// -1 = we are outdated
// 0 = up to date
// 1 = using a future version
// This method is only able to compare the Format 0.0.0(-SNAPSHOT)
private static int getVersionDifference(String version) {
String current = MinecraftVersion.VERSION;
if (current.equals(version))
return 0;
String pattern = "\\.";
if (current.split(pattern).length != 3 || version.split(pattern).length != 3)
return -1;
int curMaj = Integer.parseInt(current.split(pattern)[0]);
int curMin = Integer.parseInt(current.split(pattern)[1]);
String curPatch = current.split(pattern)[2];
int relMaj = Integer.parseInt(version.split(pattern)[0]);
int relMin = Integer.parseInt(version.split(pattern)[1]);
String relPatch = version.split(pattern)[2];
if (curMaj < relMaj)
return -1;
if (curMaj > relMaj)
return 1;
if (curMin < relMin)
return -1;
if (curMin > relMin)
return 1;
int curPatchN = Integer.parseInt(curPatch.split("-")[0]);
int relPatchN = Integer.parseInt(relPatch.split("-")[0]);
if (curPatchN < relPatchN)
return -1;
if (curPatchN > relPatchN)
return 1;
if (!relPatch.contains("-") && curPatch.contains("-"))
return -1; // Release has no - but we do = We use a Snapshot of the
// release
if (relPatch.contains("-") && curPatch.contains("-"))
return 0; // Release and cur are Snapshots/alpha/beta
return 1;
}
protected static String getPlugin() {
ClassLoader classLoader = VersionChecker.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("paper-plugin.yml");
if (inputStream != null) {
try (InputStreamReader reader = new InputStreamReader(inputStream)) {
YamlConfiguration pluginYml = YamlConfiguration.loadConfiguration(reader);
return pluginYml.getString("name");
} catch (IOException e) {
// ignored
} catch (IllegalArgumentException e) {
// This can happen if the paper-plugin.yml is not formatted correctly
MinecraftVersion.getLogger().log(Level.WARNING, "[NBTAPI] Error reading paper-plugin.yml: " + e.getMessage());
}
}
inputStream = classLoader.getResourceAsStream("plugin.yml");
if (inputStream != null) {
try (InputStreamReader reader = new InputStreamReader(inputStream)) {
YamlConfiguration pluginYml = YamlConfiguration.loadConfiguration(reader);
return pluginYml.getString("name");
} catch (IOException e) {
// ignored
} catch (IllegalArgumentException e) {
// This can happen if the plugin.yml is not formatted correctly
MinecraftVersion.getLogger().log(Level.WARNING, "[NBTAPI] Error reading plugin.yml: " + e.getMessage());
}
}
return NBTItem.class.getPackage().getName();
}
protected static String getPluginforBStats() {
ClassLoader classLoader = VersionChecker.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("paper-plugin.yml");
if (inputStream != null) {
try (InputStreamReader reader = new InputStreamReader(inputStream)) {
YamlConfiguration pluginYml = YamlConfiguration.loadConfiguration(reader);
return pluginYml.getString("name");
} catch (IOException e) {
// ignored
} catch (IllegalArgumentException e) {
// This can happen if the paper-plugin.yml is not formatted correctly
MinecraftVersion.getLogger().log(Level.WARNING, "[NBTAPI] Error reading paper-plugin.yml: " + e.getMessage());
}
}
inputStream = classLoader.getResourceAsStream("plugin.yml");
if (inputStream != null) {
try (InputStreamReader reader = new InputStreamReader(inputStream)) {
YamlConfiguration pluginYml = YamlConfiguration.loadConfiguration(reader);
return pluginYml.getString("name");
} catch (IOException e) {
// ignored
} catch (IllegalArgumentException e) {
// This can happen if the plugin.yml is not formatted correctly
MinecraftVersion.getLogger().log(Level.WARNING, "[NBTAPI] Error reading plugin.yml: " + e.getMessage());
}
}
return "UnknownPlugin";
}
protected static String getPluginType() {
ClassLoader classLoader = VersionChecker.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("paper-plugin.yml");
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// ignored
}
return "PaperPlugin";
}
inputStream = classLoader.getResourceAsStream("plugin.yml");
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// ignored
}
return "SpigotPlugin";
}
return "UnknownPlugin";
}
}
@@ -0,0 +1,172 @@
package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.getLogger;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* Wraps NMS and CRAFT classes
*
* @author tr7zw
*
*/
@SuppressWarnings("javadoc")
public enum ClassWrapper {
CRAFT_ITEMSTACK(PackageWrapper.CRAFTBUKKIT, "inventory.CraftItemStack", null, null),
CRAFT_METAITEM(PackageWrapper.CRAFTBUKKIT, "inventory.CraftMetaItem", null, null),
CRAFT_ENTITY(PackageWrapper.CRAFTBUKKIT, "entity.CraftEntity", null, null),
CRAFT_WORLD(PackageWrapper.CRAFTBUKKIT, "CraftWorld", null, null),
CRAFT_SERVER(PackageWrapper.CRAFTBUKKIT, "CraftServer", null, null),
CRAFT_PERSISTENTDATACONTAINER(PackageWrapper.CRAFTBUKKIT, "persistence.CraftPersistentDataContainer",
MinecraftVersion.MC1_14_R1, null),
NMS_NBTBASE(PackageWrapper.NMS, "NBTBase", null, null, "net.minecraft.nbt", "net.minecraft.nbt.Tag"),
NMS_TAGTYPE(PackageWrapper.NMS, "NBTTagType", MinecraftVersion.MC1_21_R4, null, "net.minecraft.nbt", "net.minecraft.nbt.TagType"),
NMS_NBTTAGSTRING(PackageWrapper.NMS, "NBTTagString", null, null, "net.minecraft.nbt",
"net.minecraft.nbt.StringTag"),
NMS_NBTTAGINT(PackageWrapper.NMS, "NBTTagInt", null, null, "net.minecraft.nbt", "net.minecraft.nbt.IntTag"),
NMS_NBTTAGINTARRAY(PackageWrapper.NMS, "NBTTagIntArray", null, null, "net.minecraft.nbt",
"net.minecraft.nbt.IntArrayTag"),
NMS_NBTTAGFLOAT(PackageWrapper.NMS, "NBTTagFloat", null, null, "net.minecraft.nbt", "net.minecraft.nbt.FloatTag"),
NMS_NBTTAGDOUBLE(PackageWrapper.NMS, "NBTTagDouble", null, null, "net.minecraft.nbt",
"net.minecraft.nbt.DoubleTag"),
NMS_NBTTAGLONG(PackageWrapper.NMS, "NBTTagLong", null, null, "net.minecraft.nbt", "net.minecraft.nbt.LongTag"),
NMS_ITEMSTACK(PackageWrapper.NMS, "ItemStack", null, null, "net.minecraft.world.item",
"net.minecraft.world.item.ItemStack"),
NMS_NBTTAGCOMPOUND(PackageWrapper.NMS, "NBTTagCompound", null, null, "net.minecraft.nbt",
"net.minecraft.nbt.CompoundTag"),
NMS_NBTTAGLIST(PackageWrapper.NMS, "NBTTagList", null, null, "net.minecraft.nbt", "net.minecraft.nbt.ListTag"),
NMS_NBTCOMPRESSEDSTREAMTOOLS(PackageWrapper.NMS, "NBTCompressedStreamTools", null, null, "net.minecraft.nbt",
"net.minecraft.nbt.NbtIo"),
NMS_MOJANGSONPARSER(PackageWrapper.NMS, "MojangsonParser", null, null, "net.minecraft.nbt",
"net.minecraft.nbt.TagParser"),
NMS_TILEENTITY(PackageWrapper.NMS, "TileEntity", null, null, "net.minecraft.world.level.block.entity",
"net.minecraft.world.level.block.entity.BlockEntity"),
NMS_BLOCKPOSITION(PackageWrapper.NMS, "BlockPosition", MinecraftVersion.MC1_8_R3, null, "net.minecraft.core",
"net.minecraft.core.BlockPos"),
NMS_WORLDSERVER(PackageWrapper.NMS, "WorldServer", null, null, "net.minecraft.server.level",
"net.minecraft.server.level.ServerLevel"),
NMS_MINECRAFTSERVER(PackageWrapper.NMS, "MinecraftServer", null, null, "net.minecraft.server",
"net.minecraft.server.MinecraftServer"),
NMS_WORLD(PackageWrapper.NMS, "World", null, null, "net.minecraft.world.level", "net.minecraft.world.level.Level"),
NMS_ENTITY(PackageWrapper.NMS, "Entity", null, null, "net.minecraft.world.entity",
"net.minecraft.world.entity.Entity"),
NMS_ENTITYTYPES(PackageWrapper.NMS, "EntityTypes", null, null, "net.minecraft.world.entity",
"net.minecraft.world.entity.EntityType"),
NMS_REGISTRYSIMPLE(PackageWrapper.NMS, "RegistrySimple", MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_12_R1),
NMS_REGISTRYMATERIALS(PackageWrapper.NMS, "RegistryMaterials", null, null, "net.minecraft.core",
"net.minecraft.core.MappedRegistry"),
NMS_IREGISTRY(PackageWrapper.NMS, "IRegistry", null, null, "net.minecraft.core", "net.minecraft.core.Registry"),
NMS_MINECRAFTKEY(PackageWrapper.NMS, "MinecraftKey", MinecraftVersion.MC1_8_R3, null, "net.minecraft.resources",
"net.minecraft.resources.ResourceKey"),
NMS_GAMEPROFILESERIALIZER(PackageWrapper.NMS, "GameProfileSerializer", null, null, "net.minecraft.nbt",
"net.minecraft.nbt.NbtUtils"),
NMS_IBLOCKDATA(PackageWrapper.NMS, "IBlockData", MinecraftVersion.MC1_8_R3, null,
"net.minecraft.world.level.block.state", "net.minecraft.world.level.block.state.BlockState"),
NMS_NBTACCOUNTER(PackageWrapper.NMS, "NBTReadLimiter", MinecraftVersion.MC1_20_R3, null, "net.minecraft.nbt",
"net.minecraft.nbt.NbtAccounter"),
NMS_CUSTOMDATA(PackageWrapper.NMS, "CustomData", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.world.item.component", "net.minecraft.world.item.component.CustomData"),
NMS_DATACOMPONENTTYPE(PackageWrapper.NMS, "DataComponentType", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.core.component", "net.minecraft.core.component.DataComponentType"),
NMS_DATACOMPONENTS(PackageWrapper.NMS, "DataComponents", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.core.component", "net.minecraft.core.component.DataComponents"),
NMS_DATACOMPONENTHOLDER(PackageWrapper.NMS, "DataComponentHolder", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.core.component", "net.minecraft.core.component.DataComponentHolder"),
NMS_PROVIDER(PackageWrapper.NMS, "HolderLookup$a", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.core", "net.minecraft.core.HolderLookup$Provider"),
NMS_SERVER(PackageWrapper.NMS, "MinecraftServer", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.server", "net.minecraft.server.MinecraftServer"),
NMS_DATAFIXERS(PackageWrapper.NMS, "DataConverterRegistry", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.util.datafix", "net.minecraft.util.datafix.DataFixers"),
NMS_REFERENCES(PackageWrapper.NMS, "DataConverterTypes", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.util.datafix.fixes", "net.minecraft.util.datafix.fixes.References"),
NMS_NBTOPS(PackageWrapper.NMS, "DynamicOpsNBT", MinecraftVersion.MC1_20_R4, null,
"net.minecraft.nbt", "net.minecraft.nbt.NbtOps"),
NMS_PROBLEM_REPORTER(PackageWrapper.NMS, "ProblemReporter", MinecraftVersion.MC1_21_R5, null,
"net.minecraft.util", "net.minecraft.util.ProblemReporter"),
NMS_TAG_VALUE_INPUT(PackageWrapper.NMS, "TagValueInput", MinecraftVersion.MC1_21_R5, null,
"net.minecraft.world.level.storage", "net.minecraft.world.level.storage.TagValueInput"),
NMS_VALUE_INPUT(PackageWrapper.NMS, "ValueInput", MinecraftVersion.MC1_21_R5, null,
"net.minecraft.world.level.storage", "net.minecraft.world.level.storage.ValueInput"),
NMS_TAG_VALUE_OUTPUT(PackageWrapper.NMS, "TagValueOutput", MinecraftVersion.MC1_21_R5, null,
"net.minecraft.world.level.storage", "net.minecraft.world.level.storage.TagValueOutput"),
NMS_VALUE_OUTPUT(PackageWrapper.NMS, "ValueOutput", MinecraftVersion.MC1_21_R5, null,
"net.minecraft.world.level.storage", "net.minecraft.world.level.storage.ValueOutput"),
NMS_DYNAMICOPS(PackageWrapper.NONE, "DynamicOps", MinecraftVersion.MC1_21_R5, null,
"com.mojang.serialization", "com.mojang.serialization.DynamicOps"),
GAMEPROFILE(PackageWrapper.NONE, "com.mojang.authlib.GameProfile", MinecraftVersion.MC1_8_R3, null);
private Class<?> clazz;
private boolean enabled = false;
private final String mojangName;
ClassWrapper(PackageWrapper packageId, String clazzName, MinecraftVersion from, MinecraftVersion to) {
this(packageId, clazzName, from, to, null, null);
}
ClassWrapper(PackageWrapper packageId, String clazzName, MinecraftVersion from, MinecraftVersion to,
String mojangMap, String mojangName) {
this.mojangName = mojangName;
if (from != null && MinecraftVersion.getVersion().getVersionId() < from.getVersionId()) {
return;
}
if (to != null && MinecraftVersion.getVersion().getVersionId() > to.getVersionId()) {
return;
}
enabled = true;
try {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_18_R1) && mojangName != null) {
// check for Mojmapped enviroment
try {
clazz = Class.forName(mojangName);
return;
} catch (ClassNotFoundException ex) {
// ignored, not mojang mapped
}
}
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_17_R1) && mojangMap != null) {
clazz = Class.forName(mojangMap + "." + clazzName);
} else if (packageId == PackageWrapper.NONE) {
clazz = Class.forName(clazzName);
} else if (MinecraftVersion.isForgePresent() && MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4
&& Forge1710Mappings.getClassMappings().get(this.name()) != null) {
clazz = Class.forName(clazzName = Forge1710Mappings.getClassMappings().get(this.name()));
} else if (packageId == PackageWrapper.CRAFTBUKKIT) {
// this also works for un-remapped Paper 1.20+
clazz = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + "." + clazzName);
} else {
// fallback for old versions pre mojmap and in the nms package
String version = MinecraftVersion.getVersion().getPackageName();
clazz = Class.forName(packageId.getUri() + "." + version + "." + clazzName);
}
} catch (Throwable ex) {
getLogger().log(Level.WARNING, "[NBTAPI] Error while trying to resolve the class '" + clazzName + "'!", ex);
}
}
/**
* @return The wrapped class
*/
public Class<?> getClazz() {
return clazz;
}
/**
* @return Is this class available in this Version
*/
public boolean isEnabled() {
return enabled;
}
/**
* @return Package+Class name used by Mojang
*/
public String getMojangName() {
return mojangName;
}
}
@@ -0,0 +1,35 @@
package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
import java.util.Objects;
import java.util.Optional;
import de.tr7zw.changeme.nbtapi.NBTReflectionUtil;
import de.tr7zw.changeme.nbtapi.NbtApiException;
public class CodecHelper {
public static Object convertItemStackToNbt(Object itemStack) {
Object result = null;
try {
// FIXME caching, this has 0 exception handling
result = NBTReflectionUtil.itemstack_codec.encodeStart(NBTReflectionUtil.nbtRegistryOps, itemStack);
Objects.requireNonNull(result);
return ((Optional<Object>)result.getClass().getMethod("result").invoke(result)).get();
} catch (Exception e) {
throw new NbtApiException("Failed to convert ItemStack to NBT. " + result + " " + itemStack, e);
}
}
public static Object convertNbtToItemStack(Object nbt) {
Object result = null;
try {
// FIXME caching, this has 0 exception handling
result = NBTReflectionUtil.itemstack_codec.parse(NBTReflectionUtil.nbtRegistryOps, nbt);
Objects.requireNonNull(result);
return ((Optional<Object>)result.getClass().getMethod("result").invoke(result)).get();
} catch (Exception e) {
throw new NbtApiException("Failed to convert NBT to ItemStack. " + result + " " + nbt, e);
}
}
}
@@ -0,0 +1,126 @@
package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* Temporary solution to hold Forge1710 mappings.
*
* @author EverNife
*
*/
public class Forge1710Mappings {
private static Map<String, String> classMap = new HashMap<>();
private static Map<String, String> methodMap = new HashMap<>();
private static Method crucible_toString;
static {
// Fields
classMap.put("NMS_NBTBASE", "net.minecraft.nbt.NBTBase");
classMap.put("NMS_NBTTAGSTRING", "net.minecraft.nbt.NBTTagString");
classMap.put("NMS_NBTTAGINT", "net.minecraft.nbt.NBTTagInt");
classMap.put("NMS_NBTTAGINTARRAY", "net.minecraft.nbt.NBTTagIntArray");
classMap.put("NMS_NBTTAGFLOAT", "net.minecraft.nbt.NBTTagFloat");
classMap.put("NMS_NBTTAGDOUBLE", "net.minecraft.nbt.NBTTagDouble");
classMap.put("NMS_NBTTAGLONG", "net.minecraft.nbt.NBTTagLong");
classMap.put("NMS_ITEMSTACK", "net.minecraft.item.ItemStack");
classMap.put("NMS_NBTTAGCOMPOUND", "net.minecraft.nbt.NBTTagCompound");
classMap.put("NMS_NBTTAGLIST", "net.minecraft.nbt.NBTTagList");
classMap.put("NMS_NBTCOMPRESSEDSTREAMTOOLS", "net.minecraft.nbt.CompressedStreamTools");
classMap.put("NMS_MOJANGSONPARSER", "io.github.crucible.nbt.Crucible_JsonToNBT");
classMap.put("NMS_TILEENTITY", "net.minecraft.tileentity.TileEntity");
classMap.put("NMS_WORLDSERVER", "net.minecraft.world.WorldServer");
classMap.put("NMS_MINECRAFTSERVER", "net.minecraft.server.MinecraftServer");
classMap.put("NMS_WORLD", "net.minecraft.world.World");
classMap.put("NMS_ENTITY", "net.minecraft.entity.Entity");
classMap.put("NMS_ENTITYTYPES", "net.minecraft.entity.EntityList");
classMap.put("NMS_REGISTRYMATERIALS", "net.minecraft.util.RegistryNamespaced");
classMap.put("NMS_GAMEPROFILESERIALIZER", "net.minecraft.nbt.NBTUtil");
classMap.put("NMS_IREGISTRY", "net.minecraft.util.IRegistry");
// Methods
methodMap.put("COMPOUND_SET_FLOAT", "func_74776_a");
methodMap.put("COMPOUND_SET_STRING", "func_74778_a");
methodMap.put("COMPOUND_SET_INT", "func_74768_a");
methodMap.put("COMPOUND_SET_BYTEARRAY", "func_74773_a");
methodMap.put("COMPOUND_SET_INTARRAY", "func_74783_a");
methodMap.put("COMPOUND_SET_LONG", "func_74772_a");
methodMap.put("COMPOUND_SET_SHORT", "func_74777_a");
methodMap.put("COMPOUND_SET_BYTE", "func_74774_a");
methodMap.put("COMPOUND_SET_DOUBLE", "func_74780_a");
methodMap.put("COMPOUND_SET_BOOLEAN", "func_74757_a");
methodMap.put("COMPOUND_MERGE", "merge");// Only present on Crucible
methodMap.put("COMPOUND_SET", "func_74782_a");
methodMap.put("COMPOUND_GET", "func_74781_a");
methodMap.put("COMPOUND_GET_LIST_LEGACY", "func_150295_c");
methodMap.put("COMPOUND_OWN_TYPE_LEGACY", "func_74732_a");
methodMap.put("COMPOUND_GET_FLOAT", "func_74760_g");
methodMap.put("COMPOUND_GET_STRING", "func_74779_i");
methodMap.put("COMPOUND_GET_INT", "func_74762_e");
methodMap.put("COMPOUND_GET_BYTEARRAY", "func_74770_j");
methodMap.put("COMPOUND_GET_INTARRAY", "func_74759_k");
methodMap.put("COMPOUND_GET_LONG", "func_74763_f");
methodMap.put("COMPOUND_GET_SHORT", "func_74765_d");
methodMap.put("COMPOUND_GET_BYTE", "func_74771_c");
methodMap.put("COMPOUND_GET_DOUBLE", "func_74769_h");
methodMap.put("COMPOUND_GET_BOOLEAN", "func_74767_n");
methodMap.put("COMPOUND_GET_COMPOUND", "func_74775_l");
methodMap.put("COMPOUND_REMOVE_KEY", "func_82580_o");
methodMap.put("COMPOUND_HAS_KEY", "func_74764_b");
methodMap.put("COMPOUND_GET_KEYS", "func_150296_c");
methodMap.put("LISTCOMPOUND_GET_KEYS", "func_150296_c");
methodMap.put("NMSITEM_GETTAG", "func_77978_p");
methodMap.put("NMSITEM_SAVE", "func_77955_b");
methodMap.put("NMSITEM_CREATESTACK", "func_77949_a");
methodMap.put("ITEMSTACK_SET_TAG", "func_77982_d");
methodMap.put("LIST_SIZE", "func_74745_c");
methodMap.put("LEGACY_LIST_ADD", "func_74742_a");
methodMap.put("LIST_GET_STRING", "func_150307_f");
methodMap.put("LIST_GET_COMPOUND", "func_150305_b");
methodMap.put("LIST_GET", "func_150305_b");
methodMap.put("NMS_WORLD_GET_TILEENTITY_1_7_10", "func_147438_o");
methodMap.put("TILEENTITY_GET_NBT", "func_145841_b");
methodMap.put("TILEENTITY_SET_NBT", "func_145839_a");
methodMap.put("TILEENTITY_SET_NBT_LEGACY1151", "func_145839_a");
methodMap.put("NMS_ENTITY_GET_NBT", "func_70109_d");
methodMap.put("NMS_ENTITY_SET_NBT", "func_70020_e");
methodMap.put("NBTFILE_READ", "func_74796_a");
methodMap.put("NBTFILE_WRITE", "func_74799_a");
methodMap.put("PARSE_NBT", "getTagFromJson");
methodMap.put("GAMEPROFILE_DESERIALIZE", "func_152459_a");
// Crucible
try {
crucible_toString = Class.forName("net.minecraft.nbt.NBTTagCompound")
.getDeclaredMethod("crucible_toString");
} catch (Exception e) {
e.printStackTrace();
}
}
public static Map<String, String> getClassMappings() {
return classMap;
}
public static Map<String, String> getMethodMapping() {
return methodMap;
}
public static String toString(Object nbtTagCompound) {
if (crucible_toString == null)
throw new NbtApiException("Method not loaded! 'Forge1710Mappings.crucible_toString' ");
try {
return (String) crucible_toString.invoke(nbtTagCompound);
} catch (Exception ex) {
throw new NbtApiException(
"Error while calling the method 'crucible_toString', from Forge1710Mappings. Passed Class: "
+ Forge1710Mappings.class,
ex);
}
}
}
@@ -0,0 +1,367 @@
package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* Temporary solution to hold Mojang to unmapped Spigot mappings.
* Note years later: nothing is more permanent than a temporary solution.
*
* @author tr7zw
*
*/
public class MojangToMapping {
@SuppressWarnings("serial")
private static Map<String, String> MC1_18R1 = new HashMap<String, String>() {
{
put("net.minecraft.nbt.CompoundTag#contains(java.lang.String)", "e");
put("net.minecraft.nbt.CompoundTag#getCompound(java.lang.String)", "p");
put("net.minecraft.nbt.CompoundTag#getList(java.lang.String,int)", "c");
put("net.minecraft.nbt.CompoundTag#putByteArray(java.lang.String,byte[])", "a");
put("net.minecraft.nbt.CompoundTag#getDouble(java.lang.String)", "k");
put("net.minecraft.nbt.CompoundTag#putDouble(java.lang.String,double)", "a");
put("net.minecraft.nbt.CompoundTag#getByteArray(java.lang.String)", "m");
put("net.minecraft.nbt.CompoundTag#putInt(java.lang.String,int)", "a");
put("net.minecraft.nbt.CompoundTag#getIntArray(java.lang.String)", "n");
put("net.minecraft.nbt.CompoundTag#remove(java.lang.String)", "r");
put("net.minecraft.nbt.CompoundTag#get(java.lang.String)", "c");
put("net.minecraft.nbt.CompoundTag#merge(net.minecraft.nbt.CompoundTag)", "a");
put("net.minecraft.nbt.CompoundTag#putBoolean(java.lang.String,boolean)", "a");
put("net.minecraft.nbt.CompoundTag#getTagType(java.lang.String)", "d");
put("net.minecraft.nbt.CompoundTag#putLong(java.lang.String,long)", "a");
put("net.minecraft.nbt.CompoundTag#putLongArray(java.lang.String,long[])", "a");
put("net.minecraft.nbt.CompoundTag#getLongArray(java.lang.String)", "o");
put("net.minecraft.nbt.CompoundTag#getString(java.lang.String)", "l");
put("net.minecraft.nbt.CompoundTag#getInt(java.lang.String)", "h");
put("net.minecraft.nbt.CompoundTag#putString(java.lang.String,java.lang.String)", "a");
put("net.minecraft.nbt.CompoundTag#put(java.lang.String,net.minecraft.nbt.Tag)", "a");
put("net.minecraft.nbt.CompoundTag#getByte(java.lang.String)", "f");
put("net.minecraft.nbt.CompoundTag#putIntArray(java.lang.String,int[])", "a");
put("net.minecraft.nbt.CompoundTag#getShort(java.lang.String)", "g");
put("net.minecraft.nbt.CompoundTag#putByte(java.lang.String,byte)", "a");
put("net.minecraft.nbt.CompoundTag#getAllKeys()", "d");
put("net.minecraft.nbt.CompoundTag#putUUID(java.lang.String,java.util.UUID)", "a");
put("net.minecraft.nbt.CompoundTag#putShort(java.lang.String,short)", "a");
put("net.minecraft.nbt.CompoundTag#getLong(java.lang.String)", "i");
put("net.minecraft.nbt.CompoundTag#putFloat(java.lang.String,float)", "a");
put("net.minecraft.nbt.CompoundTag#getBoolean(java.lang.String)", "q");
put("net.minecraft.nbt.CompoundTag#getUUID(java.lang.String)", "a");
put("net.minecraft.nbt.CompoundTag#getFloat(java.lang.String)", "j");
put("net.minecraft.nbt.ListTag#addTag(int,net.minecraft.nbt.Tag)", "b");
put("net.minecraft.nbt.ListTag#setTag(int,net.minecraft.nbt.Tag)", "a");
put("net.minecraft.nbt.ListTag#getString(int)", "j");
put("net.minecraft.nbt.ListTag#remove(int)", "remove");
put("net.minecraft.nbt.ListTag#getCompound(int)", "a");
put("net.minecraft.nbt.ListTag#size()", "size");
put("net.minecraft.nbt.ListTag#get(int)", "get");
put("net.minecraft.nbt.NbtIo#readCompressed(java.io.InputStream)", "a");
put("net.minecraft.nbt.NbtIo#writeCompressed(net.minecraft.nbt.CompoundTag,java.io.OutputStream)", "a");
put("net.minecraft.nbt.NbtUtils#readGameProfile(net.minecraft.nbt.CompoundTag)", "a");
put("net.minecraft.nbt.NbtUtils#writeGameProfile(net.minecraft.nbt.CompoundTag,com.mojang.authlib.GameProfile)",
"a");
put("net.minecraft.nbt.TagParser#parseTag(java.lang.String)", "a");
put("net.minecraft.world.entity.Entity#getEncodeId()", "bk");
put("net.minecraft.world.entity.Entity#load(net.minecraft.nbt.CompoundTag)", "g");
put("net.minecraft.world.entity.Entity#saveWithoutId(net.minecraft.nbt.CompoundTag)", "f");
put("net.minecraft.world.item.ItemStack#setTag(net.minecraft.nbt.CompoundTag)", "c");
put("net.minecraft.world.item.ItemStack#getTag()", "s");
put("net.minecraft.world.item.ItemStack#save(net.minecraft.nbt.CompoundTag)", "b");
put("net.minecraft.world.level.block.entity.BlockEntity#saveWithId()", "n");
put("net.minecraft.world.level.block.entity.BlockEntity#getBlockState()", "q");
put("net.minecraft.world.level.block.entity.BlockEntity#load(net.minecraft.nbt.CompoundTag)", "a");
put("net.minecraft.server.level.ServerLevel#getBlockEntity(net.minecraft.core.BlockPos)", "c_");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_18R2 = new HashMap<String, String>() {
{
putAll(MC1_18R1);
put("net.minecraft.world.item.ItemStack#getTag()", "t");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_19R1 = new HashMap<String, String>() {
{
putAll(MC1_18R2);
put("net.minecraft.world.item.ItemStack#getTag()", "u");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_19R2 = new HashMap<String, String>() {
{
putAll(MC1_19R1);
put("net.minecraft.nbt.CompoundTag#getAllKeys()", "e");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_20R1 = new HashMap<String, String>() {
{
putAll(MC1_19R2);
put("net.minecraft.world.entity.Entity#getEncodeId()", "br");
put("net.minecraft.world.item.ItemStack#getTag()", "v");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_20R2 = new HashMap<String, String>() {
{
putAll(MC1_20R1);
put("net.minecraft.world.entity.Entity#getEncodeId()", "bu");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_20R3 = new HashMap<String, String>() {
{
putAll(MC1_20R2);
put("net.minecraft.nbt.NbtIo#readCompressed(java.io.InputStream,net.minecraft.nbt.NbtAccounter)", "a");
put("net.minecraft.nbt.NbtAccounter#unlimitedHeap()", "a");
put("net.minecraft.world.entity.Entity#getEncodeId()", "bw");
put("net.minecraft.world.level.block.entity.BlockEntity#saveWithId()", "p");
put("net.minecraft.world.level.block.entity.BlockEntity#getBlockState()", "r");
put("net.minecraft.world.item.ItemStack#CODEC", "a");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_20R4 = new HashMap<String, String>() {
{
putAll(MC1_20R3);
put("net.minecraft.world.entity.Entity#getEncodeId()", "bC");
put("net.minecraft.world.level.block.entity.BlockEntity#getBlockState()", "n");
put("net.minecraft.core.component.DataComponents#CUSTOM_DATA", "b");
put("net.minecraft.core.component.DataComponentHolder#get(net.minecraft.core.component.DataComponentType)", "a");
put("net.minecraft.world.item.component.CustomData#copyTag()", "c");
put("net.minecraft.world.item.ItemStack#set(net.minecraft.core.component.DataComponentType,java.lang.Object)", "b");
put("net.minecraft.world.item.ItemStack#save(net.minecraft.core.HolderLookup$Provider)", "a");
put("net.minecraft.server.MinecraftServer#registryAccess()", "bc");
put("net.minecraft.world.item.ItemStack#parseOptional(net.minecraft.core.HolderLookup$Provider,net.minecraft.nbt.CompoundTag)", "a");
put("net.minecraft.world.level.block.entity.BlockEntity#saveWithId(net.minecraft.core.HolderLookup$Provider)", "c");
put("net.minecraft.world.level.block.entity.BlockEntity#loadWithComponents(net.minecraft.nbt.CompoundTag,net.minecraft.core.HolderLookup$Provider)", "c");
put("net.minecraft.util.datafix.DataFixers#getDataFixer()", "a");
put("net.minecraft.util.datafix.fixes.References#ITEM_STACK", "t");
put("net.minecraft.nbt.NbtOps#INSTANCE", "a");
put("net.minecraft.world.item.ItemStack#CODEC", "b");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_21R1 = new HashMap<String, String>() {
{
putAll(MC1_20R4);
put("net.minecraft.world.entity.Entity#getEncodeId()", "bD");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_21R2 = new HashMap<String, String>() {
{
putAll(MC1_21R1);
put("net.minecraft.server.MinecraftServer#registryAccess()", "ba");
put("net.minecraft.world.entity.Entity#getEncodeId()", "bK");
put("net.minecraft.world.level.block.entity.BlockEntity#getBlockState()", "m");
put("net.minecraft.world.item.ItemStack#CODEC", "a");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_21R3 = new HashMap<String, String>() {
{
putAll(MC1_21R2);
put("net.minecraft.world.item.component.CustomData#copyTag()", "d");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_21R4 = new HashMap<String, String>() {
{
putAll(MC1_21R3);
put("net.minecraft.nbt.CompoundTag#getShort(java.lang.String)", "d");
put("net.minecraft.nbt.CompoundTag#getString(java.lang.String)", "i");
put("net.minecraft.nbt.CompoundTag#contains(java.lang.String)", "b");
put("net.minecraft.nbt.CompoundTag#getDouble(java.lang.String)", "h");
put("net.minecraft.nbt.CompoundTag#getByteArray(java.lang.String)", "j");
put("net.minecraft.nbt.CompoundTag#getFloat(java.lang.String)", "g");
put("net.minecraft.nbt.CompoundTag#get(java.lang.String)", "a");
put("net.minecraft.nbt.CompoundTag#getLong(java.lang.String)", "f");
put("net.minecraft.nbt.CompoundTag#getLongArray(java.lang.String)", "l");
put("net.minecraft.nbt.CompoundTag#getInt(java.lang.String)", "e");
put("net.minecraft.nbt.CompoundTag#getIntArray(java.lang.String)", "k");
put("net.minecraft.nbt.CompoundTag#getCompound(java.lang.String)", "m");
put("net.minecraft.nbt.CompoundTag#getByte(java.lang.String)", "c");
put("net.minecraft.nbt.ListTag#getString(int)", "m");
put("net.minecraft.world.entity.Entity#saveWithoutId(net.minecraft.nbt.CompoundTag)", "h");
put("net.minecraft.world.entity.Entity#getEncodeId()", "bI");
put("net.minecraft.world.entity.Entity#load(net.minecraft.nbt.CompoundTag)", "i");
put("net.minecraft.nbt.Tag#getType()", "c");
put("net.minecraft.nbt.TagType#getName()", "a");
put("net.minecraft.nbt.CompoundTag#getList(java.lang.String)", "o");
put("net.minecraft.world.item.ItemStack#parse(net.minecraft.core.HolderLookup$Provider,net.minecraft.nbt.Tag)", "a");
put("net.minecraft.world.item.ItemStack#CODEC", "b");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_21R5 = new HashMap<String, String>() {
{
putAll(MC1_21R3);
put("net.minecraft.core.HolderLookup$Provider#createSerializationContext(com.mojang.serialization.DynamicOps)", "a");
put("net.minecraft.nbt.CompoundTag#getByteArray(java.lang.String)", "j");
put("net.minecraft.nbt.CompoundTag#getDouble(java.lang.String)", "h");
put("net.minecraft.nbt.CompoundTag#keySet()", "e");
put("net.minecraft.nbt.CompoundTag#getLong(java.lang.String)", "f");
put("net.minecraft.nbt.CompoundTag#getList(java.lang.String)", "o");
put("net.minecraft.nbt.CompoundTag#getInt(java.lang.String)", "e");
put("net.minecraft.nbt.CompoundTag#getCompound(java.lang.String)", "m");
put("net.minecraft.nbt.CompoundTag#getByte(java.lang.String)", "c");
put("net.minecraft.nbt.CompoundTag#getShort(java.lang.String)", "d");
put("net.minecraft.nbt.CompoundTag#getIntArray(java.lang.String)", "k");
put("net.minecraft.nbt.CompoundTag#get(java.lang.String)", "a");
put("net.minecraft.nbt.CompoundTag#getString(java.lang.String)", "i");
put("net.minecraft.nbt.CompoundTag#getFloat(java.lang.String)", "g");
put("net.minecraft.nbt.CompoundTag#getLongArray(java.lang.String)", "l");
put("net.minecraft.nbt.CompoundTag#contains(java.lang.String)", "b");
put("net.minecraft.nbt.ListTag#getString(int)", "m");
put("net.minecraft.nbt.Tag#getType()", "c");
put("net.minecraft.nbt.TagParser#parseCompoundFully(java.lang.String)", "a");
put("net.minecraft.nbt.TagType#getName()", "a");
put("net.minecraft.world.entity.Entity#load(net.minecraft.world.level.storage.ValueInput)", "e");
put("net.minecraft.world.entity.Entity#getEncodeId()", "bN");
put("net.minecraft.world.entity.Entity#saveWithoutId(net.minecraft.world.level.storage.ValueOutput)", "d");
put("net.minecraft.world.level.block.entity.BlockEntity#saveWithId(net.minecraft.world.level.storage.ValueOutput)", "d");
put("net.minecraft.world.level.block.entity.BlockEntity#loadWithComponents(net.minecraft.world.level.storage.ValueInput)", "b");
put("net.minecraft.world.level.storage.TagValueInput#create(net.minecraft.util.ProblemReporter,net.minecraft.core.HolderLookup$Provider,net.minecraft.nbt.CompoundTag)", "a");
put("net.minecraft.world.level.storage.TagValueOutput#createWithContext(net.minecraft.util.ProblemReporter,net.minecraft.core.HolderLookup$Provider)", "a");
put("net.minecraft.world.level.storage.TagValueOutput#buildResult()", "b");
put("net.minecraft.world.item.ItemStack#CODEC", "b");
put("net.minecraft.util.ProblemReporter#DISCARDING", "a");
put("net.minecraft.util.datafix.fixes.References#ITEM_STACK", "u");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_21R6 = new HashMap<String, String>() {
{
putAll(MC1_21R5);
put("net.minecraft.server.MinecraftServer#registryAccess()", "bg");
put("net.minecraft.world.entity.Entity#load(net.minecraft.world.level.storage.ValueInput)", "d");
put("net.minecraft.world.entity.Entity#getEncodeId()", "bW");
put("net.minecraft.world.item.component.CustomData#copyTag()", "b");
put("net.minecraft.world.level.block.entity.BlockEntity#getBlockState()", "o");
put("net.minecraft.util.datafix.fixes.References#ITEM_STACK", "v");
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_21R7 = new HashMap<String, String>() {
{
putAll(MC1_21R6);
put("net.minecraft.nbt.NbtAccounter#unlimitedHeap()", "c");
put("net.minecraft.server.MinecraftServer#registryAccess()", "bc");
put("net.minecraft.world.entity.Entity#getEncodeId()", "ca");
put("net.minecraft.util.datafix.fixes.References#ITEM_STACK", "x");
}
};
public static Map<String, String> getMapping() {
// No mappings after 26.1
if(MinecraftVersion.getVersion() != MinecraftVersion.UNKNOWN && MinecraftVersion.getVersion().isAtLeastVersion(MinecraftVersion.MC26_1)) {
return Collections.EMPTY_MAP;
}
switch (MinecraftVersion.getVersion()) {
case MC1_21_R7:
return MC1_21R7;
case MC1_21_R6:
return MC1_21R6;
case MC1_21_R5:
return MC1_21R5;
case MC1_21_R4:
return MC1_21R4;
case MC1_21_R3:
return MC1_21R3;
case MC1_21_R2:
return MC1_21R2;
case MC1_21_R1:
return MC1_21R1;
case MC1_20_R4:
return MC1_20R4;
case MC1_20_R3:
return MC1_20R3;
case MC1_20_R2:
return MC1_20R2;
case MC1_20_R1:
return MC1_20R1;
case MC1_19_R3:
return MC1_19R2;
case MC1_19_R2:
return MC1_19R2;
case MC1_19_R1:
return MC1_19R1;
case MC1_18_R2:
return MC1_18R2;
case MC1_18_R1:
return MC1_18R1;
case UNKNOWN:
return MC1_21R7; // assume it's a future version, so try the latest known mappings
default:
// this should never happen, unless a version is forgotten here(like 1.19R3 which uses the 1.19R2 mappings)
throw new NbtApiException("No fitting mapping found for version " + MinecraftVersion.getVersion() + ". This is a bug!");
}
}
}
@@ -0,0 +1,58 @@
package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
import java.lang.reflect.Constructor;
import java.util.logging.Level;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.getLogger;
/**
* This Enum wraps Constructors for NMS classes
*
* @author tr7zw
*
*/
@SuppressWarnings("javadoc")
public enum ObjectCreator {
NMS_NBTTAGCOMPOUND(null, null, ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
NMS_CUSTOMDATA(MinecraftVersion.MC1_20_R4, null, ClassWrapper.NMS_CUSTOMDATA.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
NMS_BLOCKPOSITION(null, null, ClassWrapper.NMS_BLOCKPOSITION.getClazz(), int.class, int.class, int.class),
NMS_COMPOUNDFROMITEM(MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_20_R3, ClassWrapper.NMS_ITEMSTACK.getClazz(),
ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),;
private Constructor<?> construct;
private Class<?> targetClass;
ObjectCreator(MinecraftVersion from, MinecraftVersion to, Class<?> clazz, Class<?>... args) {
if (clazz == null)
return;
if (from != null && MinecraftVersion.getVersion().getVersionId() < from.getVersionId())
return;
if (to != null && MinecraftVersion.getVersion().getVersionId() > to.getVersionId())
return;
try {
this.targetClass = clazz;
construct = clazz.getDeclaredConstructor(args);
construct.setAccessible(true);
} catch (Exception ex) {
getLogger().log(Level.SEVERE, "Unable to find the constructor for the class '" + clazz.getName() + "'", ex);
}
}
/**
* Creates an Object instance with given args
*
* @param args
* @return Object created
*/
public Object getInstance(Object... args) {
try {
return construct.newInstance(args);
} catch (Exception ex) {
throw new NbtApiException("Exception while creating a new instance of '" + targetClass + "'", ex);
}
}
}
@@ -0,0 +1,30 @@
package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
/**
* Package enum
*
* @author tr7zw
*
*/
@SuppressWarnings("javadoc")
public enum PackageWrapper {
NMS(new String(new byte[] { 'n', 'e', 't', '.', 'm', 'i', 'n', 'e', 'c', 'r', 'a', 'f', 't', '.', 's', 'e', 'r',
'v', 'e', 'r' })),
CRAFTBUKKIT(new String(new byte[] { 'o', 'r', 'g', '.', 'b', 'u', 'k', 'k', 'i', 't', '.', 'c', 'r', 'a', 'f', 't',
'b', 'u', 'k', 'k', 'i', 't' })),
NONE("");
private final String uri;
private PackageWrapper(String uri) {
this.uri = uri;
}
/**
* @return The Uri for that package
*/
public String getUri() {
return uri;
}
}
@@ -0,0 +1,488 @@
package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.inventory.ItemStack;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* This class caches method reflections, keeps track of method name changes
* between versions and allows early checking for problems
*
* @author tr7zw
*
*/
@SuppressWarnings("javadoc")
public enum ReflectionMethod {
COMPOUND_SET_FLOAT(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, float.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setFloat"),
new Since(MinecraftVersion.MC1_18_R1, "putFloat(java.lang.String,float)")),
COMPOUND_SET_STRING(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, String.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setString"),
new Since(MinecraftVersion.MC1_18_R1, "putString(java.lang.String,java.lang.String)")),
COMPOUND_SET_INT(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, int.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setInt"),
new Since(MinecraftVersion.MC1_18_R1, "putInt(java.lang.String,int)")),
COMPOUND_SET_BYTEARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, byte[].class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setByteArray"),
new Since(MinecraftVersion.MC1_18_R1, "putByteArray(java.lang.String,byte[])")),
COMPOUND_SET_INTARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, int[].class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setIntArray"),
new Since(MinecraftVersion.MC1_18_R1, "putIntArray(java.lang.String,int[])")),
COMPOUND_SET_LONGARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, long[].class },
MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "a"),
new Since(MinecraftVersion.MC1_18_R1, "putLongArray(java.lang.String,long[])")),
COMPOUND_SET_LONG(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, long.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setLong"),
new Since(MinecraftVersion.MC1_18_R1, "putLong(java.lang.String,long)")),
COMPOUND_SET_SHORT(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, short.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setShort"),
new Since(MinecraftVersion.MC1_18_R1, "putShort(java.lang.String,short)")),
COMPOUND_SET_BYTE(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, byte.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setByte"),
new Since(MinecraftVersion.MC1_18_R1, "putByte(java.lang.String,byte)")),
COMPOUND_SET_DOUBLE(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, double.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setDouble"),
new Since(MinecraftVersion.MC1_18_R1, "putDouble(java.lang.String,double)")),
COMPOUND_SET_BOOLEAN(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, boolean.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setBoolean"),
new Since(MinecraftVersion.MC1_18_R1, "putBoolean(java.lang.String,boolean)")),
COMPOUND_SET_UUID(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, UUID.class },
MinecraftVersion.MC1_16_R1, MinecraftVersion.MC1_21_R3, new Since(MinecraftVersion.MC1_16_R1, "a"),
new Since(MinecraftVersion.MC1_18_R1, "putUUID(java.lang.String,java.util.UUID)")),
COMPOUND_MERGE(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "a"),
new Since(MinecraftVersion.MC1_18_R1, "merge(net.minecraft.nbt.CompoundTag)")),
COMPOUND_SET(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, ClassWrapper.NMS_NBTBASE.getClazz() },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "set"),
new Since(MinecraftVersion.MC1_18_R1, "put(java.lang.String,net.minecraft.nbt.Tag)")),
COMPOUND_GET(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "get"),
new Since(MinecraftVersion.MC1_18_R1, "get(java.lang.String)")),
COMPOUND_GET_LIST_LEGACY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class, int.class },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_21_R3, new Since(MinecraftVersion.MC1_7_R4, "getList"),
new Since(MinecraftVersion.MC1_18_R1, "getList(java.lang.String,int)")),
COMPOUND_GET_LIST(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_21_R4,
new Since(MinecraftVersion.MC1_21_R4, "getList(java.lang.String)")),
// Only needed for 1.7.10 getType
COMPOUND_OWN_TYPE_LEGACY(ClassWrapper.NMS_NBTBASE, new Class[] {}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getTypeId")),
TAGTYPE_OWN_TYPE(ClassWrapper.NMS_NBTBASE, new Class[] {}, MinecraftVersion.MC1_21_R4,
new Since(MinecraftVersion.MC1_21_R4, "getType()")),
TAGTYPE_GET_NAME(ClassWrapper.NMS_TAGTYPE, new Class[] {}, MinecraftVersion.MC1_21_R4,
new Since(MinecraftVersion.MC1_21_R4, "getName()")),
COMPOUND_GET_FLOAT(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getFloat"),
new Since(MinecraftVersion.MC1_18_R1, "getFloat(java.lang.String)")),
COMPOUND_GET_STRING(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getString"),
new Since(MinecraftVersion.MC1_18_R1, "getString(java.lang.String)")),
COMPOUND_GET_INT(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getInt"),
new Since(MinecraftVersion.MC1_18_R1, "getInt(java.lang.String)")),
COMPOUND_GET_BYTEARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getByteArray"),
new Since(MinecraftVersion.MC1_18_R1, "getByteArray(java.lang.String)")),
COMPOUND_GET_INTARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getIntArray"),
new Since(MinecraftVersion.MC1_18_R1, "getIntArray(java.lang.String)")),
COMPOUND_GET_LONGARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_16_R1,
new Since(MinecraftVersion.MC1_16_R1, "getLongArray"),
new Since(MinecraftVersion.MC1_18_R1, "getLongArray(java.lang.String)")),
COMPOUND_GET_LONG(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getLong"),
new Since(MinecraftVersion.MC1_18_R1, "getLong(java.lang.String)")),
COMPOUND_GET_SHORT(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getShort"),
new Since(MinecraftVersion.MC1_18_R1, "getShort(java.lang.String)")),
COMPOUND_GET_BYTE(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getByte"),
new Since(MinecraftVersion.MC1_18_R1, "getByte(java.lang.String)")),
COMPOUND_GET_DOUBLE(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getDouble"),
new Since(MinecraftVersion.MC1_18_R1, "getDouble(java.lang.String)")),
COMPOUND_GET_BOOLEAN(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getBoolean"),
new Since(MinecraftVersion.MC1_18_R1, "getBoolean(java.lang.String)")),
COMPOUND_GET_UUID(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_16_R1, MinecraftVersion.MC1_21_R3,
new Since(MinecraftVersion.MC1_16_R1, "a"),
new Since(MinecraftVersion.MC1_18_R1, "getUUID(java.lang.String)")),
COMPOUND_GET_COMPOUND(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getCompound"),
new Since(MinecraftVersion.MC1_18_R1, "getCompound(java.lang.String)")),
NMSITEM_GETTAG(ClassWrapper.NMS_ITEMSTACK, new Class[] {}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_20_R3,
new Since(MinecraftVersion.MC1_7_R4, "getTag"), new Since(MinecraftVersion.MC1_18_R1, "getTag()")),
NMSITEM_SAVE(ClassWrapper.NMS_ITEMSTACK, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_20_R3, new Since(MinecraftVersion.MC1_7_R4, "save"),
new Since(MinecraftVersion.MC1_18_R1, "save(net.minecraft.nbt.CompoundTag)")),
NMSITEM_CREATESTACK(ClassWrapper.NMS_ITEMSTACK, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_10_R1, new Since(MinecraftVersion.MC1_7_R4, "createStack")),
COMPOUND_REMOVE_KEY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "remove"),
new Since(MinecraftVersion.MC1_18_R1, "remove(java.lang.String)")),
COMPOUND_HAS_KEY(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "hasKey"),
new Since(MinecraftVersion.MC1_18_R1, "contains(java.lang.String)")),
COMPOUND_GET_TYPE(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] { String.class }, MinecraftVersion.MC1_8_R3, MinecraftVersion.MC1_21_R4,
new Since(MinecraftVersion.MC1_8_R3, "b"), new Since(MinecraftVersion.MC1_9_R1, "d"),
new Since(MinecraftVersion.MC1_15_R1, "e"), new Since(MinecraftVersion.MC1_16_R1, "d"),
new Since(MinecraftVersion.MC1_18_R1, "getTagType(java.lang.String)")),
COMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] {}, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys"),
new Since(MinecraftVersion.MC1_18_R1, "getAllKeys()"), new Since(MinecraftVersion.MC1_21_R5, "keySet()")),
// FIXME ?!?
// LISTCOMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[] {}, MinecraftVersion.MC1_7_R4,
// new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys"),
// new Since(MinecraftVersion.MC1_18_R1, "getAllKeys()")),
LIST_REMOVE_KEY(ClassWrapper.NMS_NBTTAGLIST, new Class[] { int.class }, MinecraftVersion.MC1_8_R3,
new Since(MinecraftVersion.MC1_8_R3, "a"), new Since(MinecraftVersion.MC1_9_R1, "remove"),
new Since(MinecraftVersion.MC1_18_R1, "remove(int)")),
LIST_SIZE(ClassWrapper.NMS_NBTTAGLIST, new Class[] {}, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "size"), new Since(MinecraftVersion.MC1_18_R1, "size()")),
LIST_SET(ClassWrapper.NMS_NBTTAGLIST, new Class[] { int.class, ClassWrapper.NMS_NBTBASE.getClazz() },
MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "a"),
new Since(MinecraftVersion.MC1_13_R1, "set"),
new Since(MinecraftVersion.MC1_18_R1, "setTag(int,net.minecraft.nbt.Tag)")),
LEGACY_LIST_ADD(ClassWrapper.NMS_NBTTAGLIST, new Class[] { ClassWrapper.NMS_NBTBASE.getClazz() },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_13_R2, new Since(MinecraftVersion.MC1_7_R4, "add")),
LIST_ADD(ClassWrapper.NMS_NBTTAGLIST, new Class[] { int.class, ClassWrapper.NMS_NBTBASE.getClazz() },
MinecraftVersion.MC1_14_R1, new Since(MinecraftVersion.MC1_14_R1, "add"),
new Since(MinecraftVersion.MC1_18_R1, "addTag(int,net.minecraft.nbt.Tag)")),
LIST_GET_STRING(ClassWrapper.NMS_NBTTAGLIST, new Class[] { int.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getString"), new Since(MinecraftVersion.MC1_18_R1, "getString(int)")),
LIST_GET_COMPOUND(ClassWrapper.NMS_NBTTAGLIST, new Class[] { int.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "get"), new Since(MinecraftVersion.MC1_18_R1, "getCompound(int)")),
LIST_GET(ClassWrapper.NMS_NBTTAGLIST, new Class[] { int.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "get"), new Since(MinecraftVersion.MC1_8_R3, "g"),
new Since(MinecraftVersion.MC1_9_R1, "h"), new Since(MinecraftVersion.MC1_12_R1, "i"),
new Since(MinecraftVersion.MC1_13_R1, "get"), new Since(MinecraftVersion.MC1_18_R1, "get(int)")),
ITEMSTACK_SET_TAG(ClassWrapper.NMS_ITEMSTACK, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_20_R3, new Since(MinecraftVersion.MC1_7_R4, "setTag"),
new Since(MinecraftVersion.MC1_18_R1, "setTag(net.minecraft.nbt.CompoundTag)")),
ITEMSTACK_NMSCOPY(ClassWrapper.CRAFT_ITEMSTACK, new Class[] { ItemStack.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "asNMSCopy")),
ITEMSTACK_BUKKITMIRROR(ClassWrapper.CRAFT_ITEMSTACK, new Class[] { ClassWrapper.NMS_ITEMSTACK.getClazz() },
MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, resolveItemStackBukkitMirrorMethodName())),
CRAFT_WORLD_GET_HANDLE(ClassWrapper.CRAFT_WORLD, new Class[] {}, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getHandle")),
NMS_WORLD_GET_TILEENTITY(ClassWrapper.NMS_WORLDSERVER, new Class[] { ClassWrapper.NMS_BLOCKPOSITION.getClazz() },
MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "getTileEntity"),
new Since(MinecraftVersion.MC1_18_R1, "getBlockEntity(net.minecraft.core.BlockPos)")),
NMS_WORLD_REMOVE_TILEENTITY(ClassWrapper.NMS_WORLDSERVER, new Class[] { ClassWrapper.NMS_BLOCKPOSITION.getClazz() },
MinecraftVersion.MC1_8_R3, MinecraftVersion.MC1_17_R1, new Since(MinecraftVersion.MC1_8_R3, "t"),
new Since(MinecraftVersion.MC1_9_R1, "s"), new Since(MinecraftVersion.MC1_13_R1, "n"),
new Since(MinecraftVersion.MC1_14_R1, "removeTileEntity")),
NMS_WORLD_GET_TILEENTITY_1_7_10(ClassWrapper.NMS_WORLDSERVER, new Class[] { int.class, int.class, int.class },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getTileEntity")),
TILEENTITY_LOAD_LEGACY191(ClassWrapper.NMS_TILEENTITY,
new Class[] { ClassWrapper.NMS_MINECRAFTSERVER.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_9_R1, MinecraftVersion.MC1_9_R1, new Since(MinecraftVersion.MC1_9_R1, "a")),
TILEENTITY_LOAD_LEGACY183(ClassWrapper.NMS_TILEENTITY, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_8_R3, MinecraftVersion.MC1_9_R2, new Since(MinecraftVersion.MC1_8_R3, "c"),
new Since(MinecraftVersion.MC1_9_R1, "a"), new Since(MinecraftVersion.MC1_9_R2, "c")),
TILEENTITY_LOAD_LEGACY1121(ClassWrapper.NMS_TILEENTITY,
new Class[] { ClassWrapper.NMS_WORLD.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_10_R1, MinecraftVersion.MC1_12_R1, new Since(MinecraftVersion.MC1_10_R1, "a"),
new Since(MinecraftVersion.MC1_12_R1, "create")),
TILEENTITY_LOAD_LEGACY1151(ClassWrapper.NMS_TILEENTITY, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_13_R1, MinecraftVersion.MC1_15_R1, new Since(MinecraftVersion.MC1_12_R1, "create")),
TILEENTITY_LOAD(ClassWrapper.NMS_TILEENTITY,
new Class[] { ClassWrapper.NMS_IBLOCKDATA.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_16_R1, MinecraftVersion.MC1_16_R3, new Since(MinecraftVersion.MC1_16_R1, "create")),
TILEENTITY_GET_NBT(ClassWrapper.NMS_TILEENTITY, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_17_R1, new Since(MinecraftVersion.MC1_7_R4, "b"),
new Since(MinecraftVersion.MC1_9_R1, "save")),
TILEENTITY_GET_NBT_1181(ClassWrapper.NMS_TILEENTITY, new Class[] {}, MinecraftVersion.MC1_18_R1, MinecraftVersion.MC1_20_R3,
new Since(MinecraftVersion.MC1_18_R1, "saveWithId()")),
TILEENTITY_SET_NBT_LEGACY1151(ClassWrapper.NMS_TILEENTITY,
new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() }, MinecraftVersion.MC1_7_R4,
MinecraftVersion.MC1_15_R1, new Since(MinecraftVersion.MC1_7_R4, "a"),
new Since(MinecraftVersion.MC1_12_R1, "load")),
TILEENTITY_SET_NBT_LEGACY1161(ClassWrapper.NMS_TILEENTITY,
new Class[] { ClassWrapper.NMS_IBLOCKDATA.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_16_R1, MinecraftVersion.MC1_16_R3, new Since(MinecraftVersion.MC1_16_R1, "load")),
TILEENTITY_SET_NBT(ClassWrapper.NMS_TILEENTITY, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_17_R1, MinecraftVersion.MC1_20_R4, new Since(MinecraftVersion.MC1_16_R1, "load"),
new Since(MinecraftVersion.MC1_18_R1, "load(net.minecraft.nbt.CompoundTag)")),
TILEENTITY_GET_BLOCKDATA(ClassWrapper.NMS_TILEENTITY, new Class[] {}, MinecraftVersion.MC1_16_R1,
new Since(MinecraftVersion.MC1_16_R1, "getBlock"),
new Since(MinecraftVersion.MC1_18_R1, "getBlockState()")),
CRAFT_ENTITY_GET_HANDLE(ClassWrapper.CRAFT_ENTITY, new Class[] {}, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "getHandle")),
NMS_ENTITY_SET_NBT(ClassWrapper.NMS_ENTITY, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_21_R4, new Since(MinecraftVersion.MC1_7_R4, "f"),
new Since(MinecraftVersion.MC1_16_R1, "load"),
new Since(MinecraftVersion.MC1_18_R1, "load(net.minecraft.nbt.CompoundTag)")),
NMS_ENTITY_GET_NBT(ClassWrapper.NMS_ENTITY, new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_21_R4, new Since(MinecraftVersion.MC1_7_R4, "e"),
new Since(MinecraftVersion.MC1_12_R1, "save"),
new Since(MinecraftVersion.MC1_18_R1, "saveWithoutId(net.minecraft.nbt.CompoundTag)")),
NMS_ENTITY_GETSAVEID(ClassWrapper.NMS_ENTITY, new Class[] {}, MinecraftVersion.MC1_14_R1,
new Since(MinecraftVersion.MC1_14_R1, "getSaveID"), new Since(MinecraftVersion.MC1_18_R1, "getEncodeId()")),
NBTFILE_READ(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS, new Class[] { InputStream.class },
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_20_R2, new Since(MinecraftVersion.MC1_7_R4, "a"),
new Since(MinecraftVersion.MC1_18_R1, "readCompressed(java.io.InputStream)")),
NBTFILE_READV2(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS,
new Class[] { InputStream.class, ClassWrapper.NMS_NBTACCOUNTER.getClazz() }, MinecraftVersion.MC1_20_R3,
new Since(MinecraftVersion.MC1_20_R3,
"readCompressed(java.io.InputStream,net.minecraft.nbt.NbtAccounter)")),
NBTACCOUNTER_CREATE_UNLIMITED(ClassWrapper.NMS_NBTACCOUNTER,
new Class[] {}, MinecraftVersion.MC1_20_R3,
new Since(MinecraftVersion.MC1_20_R3,
"unlimitedHeap()")),
NBTFILE_WRITE(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS,
new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), OutputStream.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "a"),
new Since(MinecraftVersion.MC1_18_R1,
"writeCompressed(net.minecraft.nbt.CompoundTag,java.io.OutputStream)")),
PARSE_NBT(ClassWrapper.NMS_MOJANGSONPARSER, new Class[] { String.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "parse"),
new Since(MinecraftVersion.MC1_18_R1, "parseTag(java.lang.String)"), new Since(MinecraftVersion.MC1_21_R5, "parseCompoundFully(java.lang.String)")),
REGISTRY_KEYSET(ClassWrapper.NMS_REGISTRYSIMPLE, new Class[] {}, MinecraftVersion.MC1_11_R1,
MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "keySet")),
REGISTRY_GET(ClassWrapper.NMS_REGISTRYSIMPLE, new Class[] { Object.class }, MinecraftVersion.MC1_11_R1,
MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "get")),
REGISTRY_SET(ClassWrapper.NMS_REGISTRYSIMPLE, new Class[] { Object.class, Object.class },
MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "a")),
REGISTRY_GET_INVERSE(ClassWrapper.NMS_REGISTRYMATERIALS, new Class[] { Object.class }, MinecraftVersion.MC1_11_R1,
MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "b")),
REGISTRYMATERIALS_KEYSET(ClassWrapper.NMS_REGISTRYMATERIALS, new Class[] {}, MinecraftVersion.MC1_13_R1,
MinecraftVersion.MC1_17_R1, new Since(MinecraftVersion.MC1_13_R1, "keySet")),
REGISTRYMATERIALS_GET(ClassWrapper.NMS_REGISTRYMATERIALS, new Class[] { ClassWrapper.NMS_MINECRAFTKEY.getClazz() },
MinecraftVersion.MC1_13_R1, MinecraftVersion.MC1_17_R1, new Since(MinecraftVersion.MC1_13_R1, "get")),
REGISTRYMATERIALS_GETKEY(ClassWrapper.NMS_REGISTRYMATERIALS, new Class[] { Object.class },
MinecraftVersion.MC1_13_R2, MinecraftVersion.MC1_17_R1, new Since(MinecraftVersion.MC1_13_R2, "getKey")),
GAMEPROFILE_DESERIALIZE(ClassWrapper.NMS_GAMEPROFILESERIALIZER,
new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() }, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_20_R3,
new Since(MinecraftVersion.MC1_7_R4, "deserialize"),
new Since(MinecraftVersion.MC1_18_R1, "readGameProfile(net.minecraft.nbt.CompoundTag)")),
GAMEPROFILE_SERIALIZE(ClassWrapper.NMS_GAMEPROFILESERIALIZER,
new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), ClassWrapper.GAMEPROFILE.getClazz() },
MinecraftVersion.MC1_8_R3, MinecraftVersion.MC1_20_R3, new Since(MinecraftVersion.MC1_8_R3, "serialize"),
new Since(MinecraftVersion.MC1_18_R1,
"writeGameProfile(net.minecraft.nbt.CompoundTag,com.mojang.authlib.GameProfile)")),
CRAFT_PERSISTENT_DATA_CONTAINER_TO_TAG(ClassWrapper.CRAFT_PERSISTENTDATACONTAINER, new Class[] {},
MinecraftVersion.MC1_14_R1, new Since(MinecraftVersion.MC1_14_R1, "toTagCompound")),
CRAFT_PERSISTENT_DATA_CONTAINER_GET_MAP(ClassWrapper.CRAFT_PERSISTENTDATACONTAINER, new Class[] {},
MinecraftVersion.MC1_14_R1, new Since(MinecraftVersion.MC1_14_R1, "getRaw")),
CRAFT_PERSISTENT_DATA_CONTAINER_PUT_ALL(ClassWrapper.CRAFT_PERSISTENTDATACONTAINER,
new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() }, MinecraftVersion.MC1_14_R1,
new Since(MinecraftVersion.MC1_14_R1, "putAll")),
// 1.20.5+ Stuff
NMSDATACOMPONENTHOLDER_GET(ClassWrapper.NMS_DATACOMPONENTHOLDER, new Class[] {ClassWrapper.NMS_DATACOMPONENTTYPE.getClazz()}, MinecraftVersion.MC1_20_R4,
new Since(MinecraftVersion.MC1_20_R4, "get(net.minecraft.core.component.DataComponentType)")),
NMSCUSTOMDATA_GETCOPY(ClassWrapper.NMS_CUSTOMDATA, new Class[] {}, MinecraftVersion.MC1_20_R4,
new Since(MinecraftVersion.MC1_20_R4, "copyTag()")),
NMSITEM_SET(ClassWrapper.NMS_ITEMSTACK, new Class[] {ClassWrapper.NMS_DATACOMPONENTTYPE.getClazz(), Object.class}, MinecraftVersion.MC1_20_R4,
new Since(MinecraftVersion.MC1_20_R4, "set(net.minecraft.core.component.DataComponentType,java.lang.Object)")),
NMSITEM_SAVE_MODERN(ClassWrapper.NMS_ITEMSTACK, new Class[] { ClassWrapper.NMS_PROVIDER.getClazz() },
MinecraftVersion.MC1_20_R4, MinecraftVersion.MC1_21_R4, new Since(MinecraftVersion.MC1_20_R4, "save(net.minecraft.core.HolderLookup$Provider)")),
NMSITEM_LOAD(ClassWrapper.NMS_ITEMSTACK, new Class[] { ClassWrapper.NMS_PROVIDER.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz() },
MinecraftVersion.MC1_20_R4, MinecraftVersion.MC1_21_R3, new Since(MinecraftVersion.MC1_20_R4, "parseOptional(net.minecraft.core.HolderLookup$Provider,net.minecraft.nbt.CompoundTag)")),
NMSITEM_LOAD_MODERN(ClassWrapper.NMS_ITEMSTACK, new Class[] { ClassWrapper.NMS_PROVIDER.getClazz(), ClassWrapper.NMS_NBTBASE.getClazz() },
MinecraftVersion.MC1_21_R4, MinecraftVersion.MC1_21_R4, new Since(MinecraftVersion.MC1_20_R4, "parse(net.minecraft.core.HolderLookup$Provider,net.minecraft.nbt.Tag)")),
NMSSERVER_GETREGISTRYACCESS(ClassWrapper.NMS_SERVER, new Class[] {},
MinecraftVersion.MC1_20_R4, new Since(MinecraftVersion.MC1_20_R4, "registryAccess()")),
NMSSERVER_GETSERVER(ClassWrapper.CRAFT_SERVER, new Class[] {},
MinecraftVersion.MC1_20_R4, new Since(MinecraftVersion.MC1_20_R4, "getServer()")),
TILEENTITY_GET_NBT_1205(ClassWrapper.NMS_TILEENTITY, new Class[] {ClassWrapper.NMS_PROVIDER.getClazz()}, MinecraftVersion.MC1_20_R4, MinecraftVersion.MC1_21_R4,
new Since(MinecraftVersion.MC1_20_R4, "saveWithId(net.minecraft.core.HolderLookup$Provider)")),
TILEENTITY_SET_NBT_1205(ClassWrapper.NMS_TILEENTITY, new Class[] {ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), ClassWrapper.NMS_PROVIDER.getClazz() },
MinecraftVersion.MC1_20_R4, MinecraftVersion.MC1_21_R4, new Since(MinecraftVersion.MC1_20_R4, "loadWithComponents(net.minecraft.nbt.CompoundTag,net.minecraft.core.HolderLookup$Provider)")),
GET_DATAFIXER(ClassWrapper.NMS_DATAFIXERS, new Class[] {}, MinecraftVersion.MC1_20_R4,
new Since(MinecraftVersion.MC1_20_R4, "getDataFixer()")),
// 1.21.6 Stuff
GET_SERIALIZATION_CONTEXT(ClassWrapper.NMS_PROVIDER, new Class[] {ClassWrapper.NMS_DYNAMICOPS.getClazz()}, MinecraftVersion.MC1_21_R5,
new Since(MinecraftVersion.MC1_21_R5, "createSerializationContext(com.mojang.serialization.DynamicOps)")),
NMS_GET_TAG_VALUE_INPUT(ClassWrapper.NMS_TAG_VALUE_INPUT, new Class[] {ClassWrapper.NMS_PROBLEM_REPORTER.getClazz(), ClassWrapper.NMS_PROVIDER.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_21_R5,
new Since(MinecraftVersion.MC1_21_R5, "create(net.minecraft.util.ProblemReporter,net.minecraft.core.HolderLookup$Provider,net.minecraft.nbt.CompoundTag)")),
NMS_GET_TAG_VALUE_OUTPUT(ClassWrapper.NMS_TAG_VALUE_OUTPUT, new Class[] {ClassWrapper.NMS_PROBLEM_REPORTER.getClazz(), ClassWrapper.NMS_PROVIDER.getClazz()}, MinecraftVersion.MC1_21_R5,
new Since(MinecraftVersion.MC1_21_R5, "createWithContext(net.minecraft.util.ProblemReporter,net.minecraft.core.HolderLookup$Provider)")),
NMS_TAG_VALUE_OUTPUT_TO_TAG_COMPOUND(ClassWrapper.NMS_TAG_VALUE_OUTPUT, new Class[] {}, MinecraftVersion.MC1_21_R5,
new Since(MinecraftVersion.MC1_21_R5, "buildResult()")),
NMS_ENTITY_SET_NBT_1216(ClassWrapper.NMS_ENTITY, new Class[] { ClassWrapper.NMS_VALUE_INPUT.getClazz() }, MinecraftVersion.MC1_21_R5,
new Since(MinecraftVersion.MC1_21_R5, "load(net.minecraft.world.level.storage.ValueInput)")
),
NMS_ENTITY_GET_NBT_1216(ClassWrapper.NMS_ENTITY, new Class[] { ClassWrapper.NMS_VALUE_OUTPUT.getClazz() }, MinecraftVersion.MC1_21_R5,
new Since(MinecraftVersion.MC1_21_R5, "saveWithoutId(net.minecraft.world.level.storage.ValueOutput)")),
TILEENTITY_GET_NBT_1216(ClassWrapper.NMS_TILEENTITY, new Class[] {ClassWrapper.NMS_VALUE_OUTPUT.getClazz()}, MinecraftVersion.MC1_21_R5,
new Since(MinecraftVersion.MC1_21_R5, "saveWithId(net.minecraft.world.level.storage.ValueOutput)")),
TILEENTITY_SET_NBT_1216(ClassWrapper.NMS_TILEENTITY, new Class[] {ClassWrapper.NMS_VALUE_INPUT.getClazz() },
MinecraftVersion.MC1_21_R5,
new Since(MinecraftVersion.MC1_21_R5, "loadWithComponents(net.minecraft.world.level.storage.ValueInput)")),
;
private MinecraftVersion removedAfter;
private Since targetVersion;
private Method method;
private boolean loaded = false;
private boolean compatible = false;
private String methodName = null;
private ClassWrapper parentClassWrapper;
ReflectionMethod(ClassWrapper targetClass, Class<?>[] args, MinecraftVersion addedSince,
MinecraftVersion removedAfter, Since... methodnames) {
this.removedAfter = removedAfter;
this.parentClassWrapper = targetClass;
// Special Case for Modded 1.7.10
boolean specialCase = (MinecraftVersion.isForgePresent() && this.name().equals("COMPOUND_MERGE")
&& MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4); // COMPOUND_MERGE is only present on
// Crucible, not on vanilla 1.7.10
if (!specialCase && (!MinecraftVersion.isAtLeastVersion(addedSince)
|| (this.removedAfter != null && MinecraftVersion.isNewerThan(removedAfter))))
return;
compatible = true;
MinecraftVersion server = MinecraftVersion.getVersion();
Since target = methodnames[0];
for (Since s : methodnames) {
if (s.version.getVersionId() <= server.getVersionId()
&& target.version.getVersionId() < s.version.getVersionId())
target = s;
}
targetVersion = target;
String targetMethodName = targetVersion.name;
try {
if (MinecraftVersion.isForgePresent() && MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
targetMethodName = Forge1710Mappings.getMethodMapping().getOrDefault(this.name(), targetMethodName);
} else if (targetVersion.version.isMojangMapping()) {
try {
// check for mojang mapped method
String name = targetVersion.name.split("\\(")[0];
method = targetClass.getClazz().getMethod(name, args);
method.setAccessible(true);
loaded = true;
methodName = name;
return;
} catch (NoSuchMethodException ignore) {
// not mojang mapped
}
targetMethodName = MojangToMapping.getMapping().getOrDefault(
targetClass.getMojangName() + "#" + targetVersion.name, "Unmapped" + targetVersion.name);
}
method = targetClass.getClazz().getDeclaredMethod(targetMethodName, args);
method.setAccessible(true);
loaded = true;
methodName = targetVersion.name;
} catch (NullPointerException | NoSuchMethodException | SecurityException ex) {
try {
if (targetVersion.version.isMojangMapping())
targetMethodName = MojangToMapping.getMapping().getOrDefault(
targetClass.getMojangName() + "#" + targetVersion.name, "Unmapped" + targetVersion.name);
method = targetClass.getClazz().getMethod(targetMethodName, args);
method.setAccessible(true);
loaded = true;
methodName = targetVersion.name;
} catch (NullPointerException | NoSuchMethodException | SecurityException ex2) {
MinecraftVersion.getLogger()
.warning("[NBTAPI] Unable to find the method '" + targetMethodName + "' in '"
+ (targetClass.getClazz() == null ? targetClass.getMojangName()
: targetClass.getClazz().getSimpleName())
+ "' Args: " + Arrays.toString(args) + " Enum: " + this); // NOSONAR This gets loaded
// before the logger is loaded
}
}
}
ReflectionMethod(ClassWrapper targetClass, Class<?>[] args, MinecraftVersion addedSince, Since... methodnames) {
this(targetClass, args, addedSince, null, methodnames);
}
private static String resolveItemStackBukkitMirrorMethodName() {
try {
ClassWrapper.CRAFT_ITEMSTACK.getClazz().getDeclaredMethod("asCraftMirror",
ClassWrapper.NMS_ITEMSTACK.getClazz());
return "asCraftMirror";
} catch (NullPointerException | NoSuchMethodException | SecurityException ignored) {
return "asBukkitMirror";
}
}
/**
* Runs the method on a given target object using the given args.
*
* @param target
* @param args
* @return Value returned by the method
*/
public Object run(Object target, Object... args) {
if (method == null)
throw new NbtApiException("Method not loaded! '" + this + "'");
try {
return method.invoke(target, args);
} catch (Exception ex) {
throw new NbtApiException("Error while calling the method '" + methodName + "', loaded: " + loaded
+ ", Enum: " + this + ", Passed Class: " + (target == null ? "null" : target.getClass()) + " Args: " + (args == null ? "null" : Arrays.toString(args)) +
" Classes: " + (args == null ? "null" : Arrays.asList(args).stream().map(a -> a == null ? "NULL" : a.getClass().getName()).collect(Collectors.toList())), ex);
}
}
/**
* @return The MethodName, used in this Minecraft Version
*/
public String getMethodName() {
return methodName;
}
/**
* @return Has this method been linked
*/
public boolean isLoaded() {
return loaded;
}
/**
* @return Is this method available in this Minecraft Version
*/
public boolean isCompatible() {
return compatible;
}
public Since getSelectedVersionInfo() {
return targetVersion;
}
/**
* @return Get Wrapper of the parent class
*/
public ClassWrapper getParentClassWrapper() {
return parentClassWrapper;
}
public static class Since {
public final MinecraftVersion version;
public final String name;
public Since(MinecraftVersion version, String name) {
this.version = version;
this.name = name;
}
}
}
@@ -0,0 +1,42 @@
package de.tr7zw.changeme.nbtapi.wrapper;
import java.util.function.UnaryOperator;
public enum Casing {
camelCase(s -> {
if (s.length() < 2) {
return s.toLowerCase();
}
return Character.toLowerCase(s.charAt(0)) + s.substring(1);
}), snake_case(s -> {
StringBuilder result = new StringBuilder();
// Convert the first letter to lowercase
result.append(Character.toLowerCase(s.charAt(0)));
// Iterate through the rest of the string
for (int i = 1; i < s.length(); i++) {
char currentChar = s.charAt(i);
// Convert uppercase letters to lowercase and add underscore
if (Character.isUpperCase(currentChar)) {
result.append('_').append(Character.toLowerCase(currentChar));
} else {
result.append(currentChar);
}
}
return result.toString();
}), PascalCase(s -> {
if (s.length() < 2) {
return s.toUpperCase();
}
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}), lowercase(String::toLowerCase), UPPERCASE(String::toUpperCase);
private UnaryOperator<String> convert;
Casing(UnaryOperator<String> function) {
this.convert = function;
}
public String convertString(String str) {
return convert.apply(str);
}
}
@@ -0,0 +1,55 @@
package de.tr7zw.changeme.nbtapi.wrapper;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import de.tr7zw.changeme.nbtapi.NbtApiException;
class DefaultMethodInvoker {
private static Method invokeDefaultMethod;
static {
try {
invokeDefaultMethod = InvocationHandler.class.getDeclaredMethod("invokeDefault",
new Class[] { Object.class, Method.class, Object[].class });
invokeDefaultMethod.setAccessible(true);
} catch (NoSuchMethodException | SecurityException e) {
// we are in java 8, use the fallback
}
}
/**
* Using reflections to access reflections, since some are still on java 8.
*
* @param target
* @param method
* @param args
* @return
*/
public static Object invokeDefault(Class<?> srcInt, Object target, Method method, Object[] args) {
if (invokeDefaultMethod != null) { // java 9+
try {
return invokeDefaultMethod.invoke(null, target, method, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new NbtApiException("Error while trying to invoke a default method for Java 9+. " + target + " "
+ method + " " + Arrays.toString(args), e);
}
} else {
try {
Constructor<Lookup> constructor = Lookup.class.getDeclaredConstructor(Class.class);
constructor.setAccessible(true);
return constructor.newInstance(srcInt).in(srcInt).unreflectSpecial(method, srcInt).bindTo(target)
.invokeWithArguments(args);
} catch (Throwable e) {
throw new NbtApiException("Error while trying to invoke a default method for Java 8. " + target + " "
+ method + " " + Arrays.toString(args), e);
}
}
}
}
@@ -0,0 +1,35 @@
package de.tr7zw.changeme.nbtapi.wrapper;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import de.tr7zw.changeme.nbtapi.iface.NBTHandler;
public interface NBTProxy {
final Map<Class<?>, NBTHandler<Object>> handlers = new HashMap<>();
public default void init() {
}
public default Casing getCasing() {
return Casing.PascalCase;
}
@SuppressWarnings("unchecked")
public default <T> NBTHandler<T> getHandler(Class<T> clazz) {
return (NBTHandler<T>) handlers.get(clazz);
}
public default Collection<NBTHandler<Object>> getHandlers() {
return handlers.values();
}
@SuppressWarnings("unchecked")
public default <T> void registerHandler(Class<T> clazz, NBTHandler<T> handler) {
handlers.put(clazz, (NBTHandler<Object>) handler);
}
}
@@ -0,0 +1,19 @@
package de.tr7zw.changeme.nbtapi.wrapper;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target(METHOD)
public @interface NBTTarget {
public String value();
public Type type() default Type.AUTOMATIC;
public enum Type {
AUTOMATIC, GET, SET, HAS
}
}
@@ -0,0 +1,99 @@
package de.tr7zw.changeme.nbtapi.wrapper;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBTCompoundList;
class ProxiedList<E extends NBTProxy> implements ProxyList<E> {
private final ReadWriteNBTCompoundList nbt;
private final Class<E> proxy;
public ProxiedList(ReadWriteNBTCompoundList nbt, Class<E> proxyClass) {
this.nbt = nbt;
this.proxy = proxyClass;
}
@Override
public E get(int index) {
ReadWriteNBT tag = nbt.get(index);
return new ProxyBuilder<E>(tag,proxy).build();
}
@Override
public int size() {
return nbt.size();
}
@Override
public void remove(int index) {
nbt.remove(index);
}
@Override
public Iterator<E> iterator() {
return new Itr();
}
@Override
public E addCompound() {
ReadWriteNBT tag = nbt.addCompound();
return new ProxyBuilder<E>(tag,proxy).build();
}
@Override
public boolean isEmpty() {
return nbt.isEmpty();
}
private class Itr implements Iterator<E> {
/**
* Index of element to be returned by subsequent call to next.
*/
int cursor = 0;
/**
* Index of element returned by most recent call to next or
* previous. Reset to -1 if this element is deleted by a call
* to remove.
*/
int lastRet = -1;
public boolean hasNext() {
return cursor != size();
}
public E next() {
try {
int i = cursor;
E next = get(i);
lastRet = i;
cursor = i + 1;
return next;
} catch (IndexOutOfBoundsException e) {
throw new NoSuchElementException();
}
}
public void remove() {
if (lastRet < 0)
throw new IllegalStateException();
try {
ProxiedList.this.remove(lastRet);
if (lastRet < cursor)
cursor--;
lastRet = -1;
} catch (IndexOutOfBoundsException e) {
throw new ConcurrentModificationException();
}
}
}
}
@@ -0,0 +1,213 @@
package de.tr7zw.changeme.nbtapi.wrapper;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import de.tr7zw.changeme.nbtapi.NBTType;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.NBTHandler;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.wrapper.NBTTarget.Type;
public class ProxyBuilder<T extends NBTProxy> implements InvocationHandler {
private static final Map<Method, Function<Arguments, Object>> METHOD_CACHE = new ConcurrentHashMap<>();
private final Class<T> target;
private final ReadWriteNBT nbt;
private boolean readOnly;
public ProxyBuilder(ReadWriteNBT nbt, Class<T> target) {
if (!target.isInterface()) {
throw new NbtApiException("A proxy can only be built from an interface! Check the wiki for examples.");
}
this.target = target;
this.nbt = nbt;
}
public ProxyBuilder<T> readOnly() {
this.readOnly = true;
return this;
}
@SuppressWarnings("unchecked")
public T build() {
T inst = (T) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { target }, this);
inst.init();
return inst;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
METHOD_CACHE.computeIfAbsent(method, m -> ProxyBuilder.createFunction((NBTProxy) proxy, m));
return METHOD_CACHE.get(method).apply(new Arguments(target, (NBTProxy) proxy, readOnly, nbt, args));
}
private static class Arguments {
Class<?> target;
NBTProxy proxy;
ReadWriteNBT nbt;
Object[] args;
boolean readOnly;
public Arguments(Class<?> target, NBTProxy proxy, boolean readOnly, ReadWriteNBT nbt, Object[] args) {
this.target = target;
this.proxy = proxy;
this.nbt = nbt;
this.args = args;
this.readOnly = readOnly;
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Function<Arguments, Object> createFunction(NBTProxy proxy, Method method) {
if ("toString".equals(method.getName()) && method.getParameterCount() == 0
&& method.getReturnType() == String.class) {
return (arguments) -> arguments.nbt.toString();
}
if (method.isDefault()) {
return (arguments) -> DefaultMethodInvoker.invokeDefault(arguments.target, arguments.proxy, method,
arguments.args);
}
Type action = getAction(method);
if (action == Type.SET) {
String fieldName = getNBTName(proxy.getCasing(), method);
return (arguments) -> {
if (arguments.readOnly) {
throw new NbtApiException("Tried calling a set method on a read only object.");
}
return setNBT(arguments.nbt, arguments.proxy, fieldName, arguments.args[0]);
};
}
if (action == Type.GET) {
Class<?> retType = method.getReturnType();
String fieldName = getNBTName(proxy.getCasing(), method);
// Allow stacking of proxies
if (retType.isInterface() && NBTProxy.class.isAssignableFrom(retType)) {
return (arguments) -> {
if (arguments.nbt.hasTag(fieldName) && arguments.nbt.getType(fieldName) != NBTType.NBTTagCompound) {
throw new NbtApiException("Tried getting a '" + retType + "' proxy from the field '" + fieldName
+ "', but it's not a TagCompound!");
}
return new ProxyBuilder<NBTProxy>(arguments.nbt.getOrCreateCompound(fieldName),
(Class<NBTProxy>) retType).build();
};
}
if (retType == ProxyList.class) {
Class<?> parameterType = (Class<?>) ((ParameterizedType) method.getGenericReturnType())
.getActualTypeArguments()[0];
if (parameterType != null && parameterType.isInterface()
&& NBTProxy.class.isAssignableFrom(parameterType)) {
return (arguments) -> {
return new ProxiedList(arguments.nbt.getCompoundList(fieldName), parameterType);
};
}
}
NBTHandler<Object> handler = (NBTHandler<Object>) proxy.getHandler(retType);
if (handler != null) {
return (arguments) -> handler.get(arguments.nbt, fieldName);
}
return (arguments) -> arguments.nbt.getOrNull(fieldName, retType);
}
if (action == Type.HAS) {
String fieldName = getNBTName(proxy.getCasing(), method);
return (arguments) -> arguments.nbt.hasTag(fieldName);
}
throw new IllegalArgumentException(
"The method '" + method.getName() + "' in '" + method.getDeclaringClass().getName()
+ "' can not be handled by the NBT-API. Please check the Wiki for examples!");
}
private static Type getAction(Method method) {
NBTTarget target = method.getAnnotation(NBTTarget.class);
if (target != null) {
if (target.type() == Type.HAS && method.getParameterCount() == 0
&& method.getReturnType() == boolean.class) {
return Type.HAS;
}
if (target.type() == Type.GET && method.getParameterCount() == 0) {
return Type.GET;
}
if (target.type() == Type.SET && method.getParameterCount() == 1) {
return Type.SET;
}
}
if (method.getName().startsWith("set") && method.getParameterCount() == 1) {
return Type.SET;
}
if (method.getName().startsWith("get") && method.getParameterCount() == 0) {
return Type.GET;
}
if (method.getName().startsWith("has") && method.getParameterCount() == 0
&& method.getReturnType() == boolean.class) {
return Type.HAS;
}
return null;
}
private static String getNBTName(Casing casing, Method method) {
NBTTarget target = method.getAnnotation(NBTTarget.class);
if (target != null) {
return target.value();
}
return casing.convertString(method.getName().substring(3));
}
private static Object setNBT(ReadWriteNBT nbt, NBTProxy proxy, String key, Object value) {
// welcome to the "I wish we all could use java 17" method. Thanks, legacy mc
// versions
if (value == null) {
nbt.removeKey(key);
} else if (value instanceof Boolean) {
nbt.setBoolean(key, (Boolean) value);
} else if (value instanceof Byte) {
nbt.setByte(key, (Byte) value);
} else if (value instanceof Short) {
nbt.setShort(key, (Short) value);
} else if (value instanceof Integer) {
nbt.setInteger(key, (Integer) value);
} else if (value instanceof Long) {
nbt.setLong(key, (Long) value);
} else if (value instanceof Float) {
nbt.setFloat(key, (Float) value);
} else if (value instanceof Double) {
nbt.setDouble(key, (Double) value);
} else if (value instanceof byte[]) {
nbt.setByteArray(key, (byte[]) value);
} else if (value instanceof int[]) {
nbt.setIntArray(key, (int[]) value);
} else if (value instanceof long[]) {
nbt.setLongArray(key, (long[]) value);
} else if (value instanceof String) {
nbt.setString(key, (String) value);
} else if (value instanceof UUID) {
nbt.setUUID(key, (UUID) value);
} else if (value.getClass().isEnum()) {
nbt.setEnum(key, (Enum<?>) value);
} else {
@SuppressWarnings("unchecked")
NBTHandler<Object> handler = (NBTHandler<Object>) proxy.getHandler(value.getClass());
if (handler != null) {
handler.set(nbt, key, value);
} else {
for (NBTHandler<Object> nbth : proxy.getHandlers()) {
if (nbth.fuzzyMatch(value)) {
nbth.set(nbt, key, value);
return null;
}
}
throw new IllegalArgumentException("Tried setting an object of type '" + value.getClass().getName()
+ "'. This is not a supported NBT value. Please check the Wiki for examples!");
}
}
return null;
}
}
@@ -0,0 +1,42 @@
package de.tr7zw.changeme.nbtapi.wrapper;
public interface ProxyList<T extends NBTProxy> extends Iterable<T> {
/**
* Adds a new compound tag to the current compound tag
*
* @return A new instance of the class.
*/
T addCompound();
/**
* Returns the number of elements in this collection. If this collection
* contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
*
* @return the number of elements in this collection
*/
int size();
/**
* Returns true if this collection contains no elements.
*
* @return true if this collection contains no elements
*/
boolean isEmpty();
/**
* Get the object with the given id.
*
* @param id The id of the object to get.
* @return The object with the given id.
*/
T get(int id);
/**
* Removes the element at the specified position in this list
*
* @param i The index of the element to remove.
*/
void remove(int i);
}
@@ -1,39 +0,0 @@
package de.tr7zw.itemnbtapi;
import org.bukkit.Bukkit;
public enum ClassWrapper {
CRAFT_ITEMSTACK("org.bukkit.craftbukkit.", ".inventory.CraftItemStack"),
CRAFT_ENTITY("org.bukkit.craftbukkit.", ".entity.CraftEntity"),
CRAFT_WORLD("org.bukkit.craftbukkit.", ".CraftWorld"),
NMS_NBTBASE("net.minecraft.server.", ".NBTBase"),
NMS_NBTTAGSTRING("net.minecraft.server.", ".NBTTagString"),
NMS_ITEMSTACK("net.minecraft.server.", ".ItemStack"),
NMS_NBTTAGCOMPOUND("net.minecraft.server.", ".NBTTagCompound"),
NMS_NBTTAGLIST("net.minecraft.server.", ".NBTTagList"),
NMS_NBTCOMPRESSEDSTREAMTOOLS("net.minecraft.server.", ".NBTCompressedStreamTools"),
NMS_MOJANGSONPARSER("net.minecraft.server.", ".MojangsonParser"),
NMS_TILEENTITY("net.minecraft.server.", ".TileEntity"),
NMS_BLOCKPOSITION("net.minecraft.server.", ".BlockPosition"),
NMS_WORLD("net.minecraft.server.", ".WorldServer"),
NMS_ENTITY("net.minecraft.server.", ".Entity"),
;
private Class<?> clazz;
ClassWrapper(String pre, String suffix){
try{
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
clazz = Class.forName(pre + version + suffix);
}catch(Exception ex){
ex.printStackTrace();
}
}
public Class<?> getClazz(){
return clazz;
}
}
@@ -1,200 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.util.Set;
import de.tr7zw.itemnbtapi.utils.MinecraftVersion;
public class NBTCompound {
private String compundName;
private NBTCompound parent;
protected NBTCompound(NBTCompound owner, String name) {
this.compundName = name;
this.parent = owner;
}
public String getName() {
return compundName;
}
protected Object getCompound() {
return parent.getCompound();
}
protected void setCompound(Object compound) {
parent.setCompound(compound);
}
public NBTCompound getParent() {
return parent;
}
public void mergeCompound(NBTCompound comp){
NBTReflectionUtil.addOtherNBTCompound(this, comp);
}
public void setString(String key, String value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_STRING, key, value);
}
public String getString(String key) {
return (String) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_STRING, key);
}
protected String getContent(String key) {
return NBTReflectionUtil.getContent(this, key);
}
public void setInteger(String key, Integer value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INT, key, value);
}
public Integer getInteger(String key) {
return (Integer) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INT, key);
}
public void setDouble(String key, Double value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_DOUBLE, key, value);
}
public Double getDouble(String key) {
return (Double) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_DOUBLE, key);
}
public void setByte(String key, Byte value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTE, key, value);
}
public Byte getByte(String key) {
return (Byte) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTE, key);
}
public void setShort(String key, Short value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_SHORT, key, value);
}
public Short getShort(String key) {
return (Short) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_SHORT, key);
}
public void setLong(String key, Long value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_LONG, key, value);
}
public Long getLong(String key) {
return (Long) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_LONG, key);
}
public void setFloat(String key, Float value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_FLOAT, key, value);
}
public Float getFloat(String key) {
return (Float) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_FLOAT, key);
}
public void setByteArray(String key, byte[] value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTEARRAY, key, value);
}
public byte[] getByteArray(String key) {
return (byte[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTEARRAY, key);
}
public void setIntArray(String key, int[] value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INTARRAY, key, value);
}
public int[] getIntArray(String key) {
return (int[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INTARRAY, key);
}
public void setBoolean(String key, Boolean value) {
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BOOLEAN, key, value);
}
protected void set(String key, Object val) {
NBTReflectionUtil.set(this, key, val);
}
public Boolean getBoolean(String key) {
return (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BOOLEAN, key);
}
public void setObject(String key, Object value) {
NBTReflectionUtil.setObject(this, key, value);
}
public <T> T getObject(String key, Class<T> type) {
return NBTReflectionUtil.getObject(this, key, type);
}
public Boolean hasKey(String key) {
Boolean b = (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_HAS_KEY, key);
if(b == null)return false;
return b;
}
public void removeKey(String key) {
NBTReflectionUtil.remove(this, key);
}
public Set<String> getKeys() {
return NBTReflectionUtil.getKeys(this);
}
public NBTCompound addCompound(String name) {
if(getType(name) == NBTType.NBTTagCompound)return getCompound(name);
NBTReflectionUtil.addNBTTagCompound(this, name);
return getCompound(name);
}
public NBTCompound getCompound(String name) {
NBTCompound next = new NBTCompound(this, name);
if (NBTReflectionUtil.valideCompound(next)) return next;
return null;
}
public NBTList getList(String name, NBTType type) {
return NBTReflectionUtil.getList(this, name, type);
}
public NBTType getType(String name) {
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) return null;
Object o = NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_TYPE, name);
if(o == null)return null;
return NBTType.valueOf((byte) o);
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
for (String key : getKeys()) {
result.append(toString(key));
}
return result.toString();
}
public String toString(String key) {
StringBuilder result = new StringBuilder();
NBTCompound compound = this;
while (compound.getParent() != null) {
result.append(" ");
compound = compound.getParent();
}
if (this.getType(key) == NBTType.NBTTagCompound) {
return this.getCompound(key).toString();
} else {
return result + "-" + key + ": " + getContent(key) + System.lineSeparator();
}
}
public String asNBTString(){
Object comp = NBTReflectionUtil.gettoCompount(getCompound(), this);
if(comp == null)return "{}";
return comp.toString();
}
}
@@ -1,35 +0,0 @@
package de.tr7zw.itemnbtapi;
public class NBTContainer extends NBTCompound{
private Object nbt;
public NBTContainer() {
super(null, null);
nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
protected NBTContainer(Object nbt){
super(null, null);
this.nbt = nbt;
}
public NBTContainer(String nbtString) throws IllegalArgumentException {
super(null, null);
try{
nbt = ReflectionMethod.PARSE_NBT.run(null, nbtString);
}catch(Exception ex){
ex.printStackTrace();
throw new IllegalArgumentException("Malformed Json: " + ex.getMessage());
}
}
protected Object getCompound() {
return nbt;
}
protected void setCompound(Object tag) {
nbt = tag;
}
}
@@ -1,22 +0,0 @@
package de.tr7zw.itemnbtapi;
import org.bukkit.entity.Entity;
public class NBTEntity extends NBTCompound {
private final Entity ent;
public NBTEntity(Entity entity) {
super(null, null);
ent = entity;
}
protected Object getCompound() {
return NBTReflectionUtil.getEntityNBTTagCompound(NBTReflectionUtil.getNMSEntity(ent));
}
protected void setCompound(Object compound) {
NBTReflectionUtil.setEntityNBTTag(compound, NBTReflectionUtil.getNMSEntity(ent));
}
}
@@ -1,46 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class NBTFile extends NBTCompound {
private final File file;
private Object nbt;
public NBTFile(File file) throws IOException {
super(null, null);
this.file = file;
if (file.exists()) {
FileInputStream inputsteam = new FileInputStream(file);
nbt = NBTReflectionUtil.readNBTFile(inputsteam);
} else {
nbt = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
save();
}
}
public void save() throws IOException {
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
FileOutputStream outStream = new FileOutputStream(file);
NBTReflectionUtil.saveNBTFile(nbt, outStream);
}
public File getFile() {
return file;
}
protected Object getCompound() {
return nbt;
}
protected void setCompound(Object compound) {
nbt = compound;
}
}
@@ -1,53 +0,0 @@
package de.tr7zw.itemnbtapi;
import org.bukkit.inventory.ItemStack;
public class NBTItem extends NBTCompound {
private ItemStack bukkitItem;
public NBTItem(ItemStack item) {
super(null, null);
if(item == null){
throw new NullPointerException("ItemStack can't be null!");
}
bukkitItem = item.clone();
}
protected Object getCompound() {
return NBTReflectionUtil.getItemRootNBTTagCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem));
}
protected void setCompound(Object compound) {
Object stack = ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, bukkitItem);
ReflectionMethod.ITEMSTACK_SET_TAG.run(stack, compound);
bukkitItem = (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null, stack);
}
public ItemStack getItem() {
return bukkitItem;
}
protected void setItem(ItemStack item) {
bukkitItem = item;
}
/**
* This may return true even when the NBT is empty.
*
* @return Does the ItemStack have a NBTCompound.
*/
public boolean hasNBTData(){
return getCompound() != null;
}
public static NBTContainer convertItemtoNBT(ItemStack item){
return NBTReflectionUtil.convertNMSItemtoNBTCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, item));
}
public static ItemStack convertNBTtoItem(NBTCompound comp){
return (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null, NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp));
}
}
@@ -1,127 +0,0 @@
package de.tr7zw.itemnbtapi;
import de.tr7zw.itemnbtapi.utils.MinecraftVersion;
public class NBTList {
private String listName;
private NBTCompound parent;
private NBTType type;
private Object listObject;
protected NBTList(NBTCompound owner, String name, NBTType type, Object list) {
parent = owner;
listName = name;
this.type = type;
this.listObject = list;
if (!(type == NBTType.NBTTagString || type == NBTType.NBTTagCompound)) {
System.err.println("List types != String/Compound are currently not implemented!");
}
}
protected void save() {
parent.set(listName, listObject);
}
public NBTListCompound addCompound() {
if (type != NBTType.NBTTagCompound) {
new Throwable("Using Compound method on a non Compound list!").printStackTrace();
return null;
}
try {
Object compound = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
ReflectionMethod.LIST_ADD.run(listObject, 0, compound);
} else {
ReflectionMethod.LEGACY_LIST_ADD.run(listObject, compound);
}
return new NBTListCompound(this, compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public NBTListCompound getCompound(int id) {
if (type != NBTType.NBTTagCompound) {
new Throwable("Using Compound method on a non Compound list!").printStackTrace();
return null;
}
try {
Object compound = ReflectionMethod.LIST_GET.run(listObject, id);
return new NBTListCompound(this, compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public String getString(int i) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return null;
}
try {
return (String) ReflectionMethod.LIST_GET_STRING.run(listObject, i);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public void addString(String s) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return;
}
try {
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
ReflectionMethod.LIST_ADD.run(listObject, 0,
ClassWrapper.NMS_NBTTAGSTRING.getClazz().getConstructor(String.class).newInstance(s));
} else {
ReflectionMethod.LEGACY_LIST_ADD.run(listObject,
ClassWrapper.NMS_NBTTAGSTRING.getClazz().getConstructor(String.class).newInstance(s));
}
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void setString(int i, String s) {
if (type != NBTType.NBTTagString) {
new Throwable("Using String method on a non String list!").printStackTrace();
return;
}
try {
ReflectionMethod.LIST_SET.run(listObject, i,
ClassWrapper.NMS_NBTTAGSTRING.getClazz().getConstructor(String.class).newInstance(s));
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void remove(int i) {
try {
ReflectionMethod.LIST_REMOVE_KEY.run(listObject, i);
save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public int size() {
try {
return (int) ReflectionMethod.LIST_SIZE.run(listObject);
} catch (Exception ex) {
ex.printStackTrace();
}
return -1;
}
public NBTType getType() {
return type;
}
}
@@ -1,102 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.util.HashSet;
import java.util.Set;
public class NBTListCompound {
private NBTList owner;
private Object compound;
protected NBTListCompound(NBTList parent, Object obj) {
owner = parent;
compound = obj;
}
public void setString(String key, String value) {
if (value == null) {
remove(key);
return;
}
try {
compound.getClass().getMethod("setString", String.class, String.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void setInteger(String key, int value) {
try {
compound.getClass().getMethod("setInt", String.class, int.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public int getInteger(String value) {
try {
return (int) compound.getClass().getMethod("getInt", String.class).invoke(compound, value);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
public void setDouble(String key, double value) {
try {
compound.getClass().getMethod("setDouble", String.class, double.class).invoke(compound, key, value);
owner.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public double getDouble(String key) {
try {
return (double) compound.getClass().getMethod("getDouble", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
public String getString(String key) {
try {
return (String) compound.getClass().getMethod("getString", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return "";
}
public boolean hasKey(String key) {
try {
return (boolean) compound.getClass().getMethod("hasKey", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
@SuppressWarnings("unchecked")
public Set<String> getKeys() {
try {
return (Set<String>) ReflectionMethod.LISTCOMPOUND_GET_KEYS.run(compound);
} catch (Exception ex) {
ex.printStackTrace();
}
return new HashSet<>();
}
public void remove(String key) {
try {
compound.getClass().getMethod("remove", String.class).invoke(compound, key);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
@@ -1,348 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.Stack;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import de.tr7zw.itemnbtapi.utils.GsonWrapper;
import de.tr7zw.itemnbtapi.utils.MinecraftVersion;
public class NBTReflectionUtil {
public static Object getNMSEntity(Entity entity) {
try {
return ReflectionMethod.CRAFT_ENTITY_GET_HANDLE.run(ClassWrapper.CRAFT_ENTITY.getClazz().cast(entity));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object readNBTFile(FileInputStream stream) {
try {
return ReflectionMethod.NBTFILE_READ.run(null, stream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object saveNBTFile(Object nbt, FileOutputStream stream) {
try {
return ReflectionMethod.NBTFILE_WRITE.run(null, nbt, stream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object getItemRootNBTTagCompound(Object nmsitem) {
@SuppressWarnings("rawtypes")
Class clazz = nmsitem.getClass();
Method method;
try {
method = clazz.getMethod("getTag");
Object answer = method.invoke(nmsitem);
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) {
@SuppressWarnings("rawtypes")
Class clazz = ClassWrapper.NMS_ITEMSTACK.getClazz();
try {
if(MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_12_R1.getVersionId()){
Constructor<?> constructor = clazz.getConstructor(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz());
constructor.setAccessible(true);
return constructor.newInstance(nbtcompound.getCompound());
}else{
Method method = clazz.getMethod("createStack", ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz());
method.setAccessible(true);
return method.invoke(null, nbtcompound.getCompound());
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings({"unchecked"})
public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) {
@SuppressWarnings("rawtypes")
Class clazz = nmsitem.getClass();
Method method;
try {
method = clazz.getMethod("save", ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz());
Object answer = method.invoke(nmsitem, ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance());
return new NBTContainer(answer);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object getEntityNBTTagCompound(Object NMSEntity) {
try {
Object nbt = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
Object answer = ReflectionMethod.NMS_ENTITY_GET_NBT.run(NMSEntity, nbt);
if (answer == null)
answer = nbt;
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object setEntityNBTTag(Object NBTTag, Object NMSEntity) {
try {
ReflectionMethod.NMS_ENTITY_SET_NBT.run(NMSEntity, NBTTag);
return NMSEntity;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Object getTileEntityNBTTagCompound(BlockState tile) {
try {
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld());
Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld);
Object o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
Object tag = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
Object answer = ReflectionMethod.TILEENTITY_GET_NBT.run(o, tag);
if (answer == null)
answer = tag;
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) {
try {
Object pos = ObjectCreator.NMS_BLOCKPOSITION.getInstance(tile.getX(), tile.getY(), tile.getZ());
Object cworld = ClassWrapper.CRAFT_WORLD.getClazz().cast(tile.getWorld());
Object nmsworld = ReflectionMethod.CRAFT_WORLD_GET_HANDLE.run(cworld);
Object o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
ReflectionMethod.TILEENTITY_SET_NBT.run(o, comp);
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public static Object getSubNBTTagCompound(Object compound, String name) {
@SuppressWarnings("rawtypes")
Class c = compound.getClass();
Method method;
try {
method = c.getMethod("getCompound", String.class);
Object answer = method.invoke(compound, name);
return answer;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void addNBTTagCompound(NBTCompound comp, String name) {
if (name == null) {
remove(comp, name);
return;
}
Object nbttag = comp.getCompound();
if (nbttag == null) {
nbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(nbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("set", String.class, ClassWrapper.NMS_NBTBASE.getClazz());
method.invoke(workingtag, name, ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance());
comp.setCompound(nbttag);
return;
} catch (Exception ex) {
ex.printStackTrace();
}
return;
}
public static Boolean valideCompound(NBTCompound comp) {
Object root = comp.getCompound();
if (root == null) {
root = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
return (gettoCompount(root, comp)) != null;
}
static Object gettoCompount(Object nbttag, NBTCompound comp) {
Stack<String> structure = new Stack<>();
while (comp.getParent() != null) {
structure.add(comp.getName());
comp = comp.getParent();
}
while (!structure.isEmpty()) {
nbttag = getSubNBTTagCompound(nbttag, structure.pop());
if (nbttag == null) {
return null;
}
}
return nbttag;
}
public static void addOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompound) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
try {
ReflectionMethod.COMPOUND_ADD.run(workingtag, nbtcompound.getCompound());
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static String getContent(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("get", String.class);
return method.invoke(workingtag, key).toString();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void set(NBTCompound comp, String key, Object val) {
if (val == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) {
new Throwable("InvalideCompound").printStackTrace();
return;
}
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("set", String.class, ClassWrapper.NMS_NBTBASE.getClazz());
method.invoke(workingtag, key, val);
comp.setCompound(rootnbttag);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static NBTList getList(NBTCompound comp, String key, NBTType type) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try {
method = workingtag.getClass().getMethod("getList", String.class, int.class);
return new NBTList(comp, key, type, method.invoke(workingtag, key, type.getId()));
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void setObject(NBTCompound comp, String key, Object value) {
if (!MinecraftVersion.hasGsonSupport()) return;
try {
String json = GsonWrapper.getString(value);
setData(comp, ReflectionMethod.COMPOUND_SET_STRING, key, json);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static <T> T getObject(NBTCompound comp, String key, Class<T> type) {
if (!MinecraftVersion.hasGsonSupport()) return null;
String json = (String) getData(comp, ReflectionMethod.COMPOUND_GET_STRING, key);
if (json == null) {
return null;
}
return GsonWrapper.deserializeJson(json, type);
}
public static void remove(NBTCompound comp, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
ReflectionMethod.COMPOUND_REMOVE_KEY.run(workingtag, key);
comp.setCompound(rootnbttag);
}
@SuppressWarnings("unchecked")
public static Set<String> getKeys(NBTCompound comp) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
return (Set<String>) ReflectionMethod.COMPOUND_GET_KEYS.run(workingtag);
}
public static void setData(NBTCompound comp, ReflectionMethod type, String key, Object data) {
if (data == null) {
remove(comp, key);
return;
}
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
}
if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp);
type.run(workingtag, key, data);
comp.setCompound(rootnbttag);
}
public static Object getData(NBTCompound comp, ReflectionMethod type, String key) {
Object rootnbttag = comp.getCompound();
if (rootnbttag == null) {
return null;
}
if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp);
return type.run(workingtag, key);
}
}
@@ -1,22 +0,0 @@
package de.tr7zw.itemnbtapi;
import org.bukkit.block.BlockState;
public class NBTTileEntity extends NBTCompound {
private final BlockState tile;
public NBTTileEntity(BlockState tile) {
super(null, null);
this.tile = tile;
}
protected Object getCompound() {
return NBTReflectionUtil.getTileEntityNBTTagCompound(tile);
}
protected void setCompound(Object compound) {
NBTReflectionUtil.setTileEntityNBTTagCompound(tile, compound);
}
}
@@ -1,34 +0,0 @@
package de.tr7zw.itemnbtapi;
public enum NBTType {
NBTTagEnd(0),
NBTTagByte(1),
NBTTagShort(2),
NBTTagInt(3),
NBTTagLong(4),
NBTTagFloat(5),
NBTTagDouble(6),
NBTTagByteArray(7),
NBTTagIntArray(11),
NBTTagString(8),
NBTTagList(9),
NBTTagCompound(10);
NBTType(int i) {
id = i;
}
private final int id;
public int getId() {
return id;
}
public static NBTType valueOf(int id) {
for (NBTType t : values())
if (t.getId() == id)
return t;
return NBTType.NBTTagEnd;
}
}
@@ -1,28 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.lang.reflect.Constructor;
public enum ObjectCreator {
NMS_NBTTAGCOMPOUND(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
NMS_BLOCKPOSITION(ClassWrapper.NMS_BLOCKPOSITION.getClazz(), int.class, int.class, int.class);
private Constructor<?> construct;
ObjectCreator(Class<?> clazz, Class<?>... args){
try{
construct = clazz.getConstructor(args);
}catch(Exception ex){
ex.printStackTrace();
}
}
public Object getInstance(Object... args){
try{
return construct.newInstance(args);
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
}
@@ -1,128 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import org.bukkit.inventory.ItemStack;
import de.tr7zw.itemnbtapi.utils.MinecraftVersion;
public enum ReflectionMethod {
COMPOUND_SET_FLOAT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, float.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setFloat")),
COMPOUND_SET_STRING(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setString")),
COMPOUND_SET_INT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setInt")),
COMPOUND_SET_BYTEARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, byte[].class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setByteArray")),
COMPOUND_SET_INTARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, int[].class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setIntArray")),
COMPOUND_SET_LONG(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, long.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setLong")),
COMPOUND_SET_SHORT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, short.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setShort")),
COMPOUND_SET_BYTE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, byte.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setByte")),
COMPOUND_SET_DOUBLE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, double.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setDouble")),
COMPOUND_SET_BOOLEAN(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, boolean.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setBoolean")),
COMPOUND_ADD(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
COMPOUND_GET_FLOAT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getFloat")),
COMPOUND_GET_STRING(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getString")),
COMPOUND_GET_INT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getInt")),
COMPOUND_GET_BYTEARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getByteArray")),
COMPOUND_GET_INTARRAY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getIntArray")),
COMPOUND_GET_LONG(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getLong")),
COMPOUND_GET_SHORT(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getShort")),
COMPOUND_GET_BYTE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getByte")),
COMPOUND_GET_DOUBLE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getDouble")),
COMPOUND_GET_BOOLEAN(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getBoolean")),
COMPOUND_REMOVE_KEY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "remove")),
COMPOUND_HAS_KEY(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "hasKey")),
COMPOUND_GET_TYPE(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "b"), new Since(MinecraftVersion.MC1_9_R1, "d")), //FIXME: No Spigot mapping!
COMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys")),
LISTCOMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys")),
LIST_REMOVE_KEY(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a"), new Since(MinecraftVersion.MC1_9_R1, "remove")),
LIST_SIZE(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "size")),
LIST_SET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class, ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a"), new Since(MinecraftVersion.MC1_13_R1, "set")),
LEGACY_LIST_ADD(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_13_R2, new Since(MinecraftVersion.MC1_7_R4, "add")),
LIST_ADD(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class, ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_14_R1, new Since(MinecraftVersion.MC1_14_R1, "add")),
LIST_GET_STRING(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getString")),
LIST_GET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "get")),
ITEMSTACK_SET_TAG(ClassWrapper.NMS_ITEMSTACK.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setTag")),
ITEMSTACK_NMSCOPY(ClassWrapper.CRAFT_ITEMSTACK.getClazz(), new Class[]{ItemStack.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "asNMSCopy")),
ITEMSTACK_BUKKITMIRROR(ClassWrapper.CRAFT_ITEMSTACK.getClazz(), new Class[]{ClassWrapper.NMS_ITEMSTACK.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "asCraftMirror")),
CRAFT_WORLD_GET_HANDLE(ClassWrapper.CRAFT_WORLD.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getHandle")),
NMS_WORLD_GET_TILEENTITY(ClassWrapper.NMS_WORLD.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTileEntity")),
TILEENTITY_GET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "b"), new Since(MinecraftVersion.MC1_9_R1, "save")),
TILEENTITY_SET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "a"), new Since(MinecraftVersion.MC1_12_R1, "load")),
CRAFT_ENTITY_GET_HANDLE(ClassWrapper.CRAFT_ENTITY.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getHandle")),
NMS_ENTITY_SET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "f")), //FIXME: No Spigot mapping!
NMS_ENTITY_GET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "e"), new Since(MinecraftVersion.MC1_12_R1, "save")),
NBTFILE_READ(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS.getClazz(), new Class[]{InputStream.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
NBTFILE_WRITE(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), OutputStream.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a")), //FIXME: No Spigot mapping!
PARSE_NBT(ClassWrapper.NMS_MOJANGSONPARSER.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "parse")),
;
private MinecraftVersion removedAfter;
private Since targetVersion;
private Method method;
private boolean loaded = false;
private boolean compatible = false;
ReflectionMethod(Class<?> targetClass, Class<?>[] args, MinecraftVersion addedSince, MinecraftVersion removedAfter, Since... methodnames){
this.removedAfter = removedAfter;
MinecraftVersion server = MinecraftVersion.getVersion();
if(server.compareTo(addedSince) < 0 || (this.removedAfter != null && server.getVersionId() > this.removedAfter.getVersionId()))return;
compatible = true;
Since target = methodnames[0];
for(Since s : methodnames){
if(s.version.getVersionId() <= server.getVersionId() && target.version.getVersionId() < s.version.getVersionId())
target = s;
}
targetVersion = target;
try{
method = targetClass.getMethod(targetVersion.name, args);
method.setAccessible(true);
loaded = true;
}catch(NullPointerException | NoSuchMethodException | SecurityException ex){
ex.printStackTrace();
}
}
ReflectionMethod(Class<?> targetClass, Class<?>[] args, MinecraftVersion addedSince, Since... methodnames){
this(targetClass, args, addedSince, null, methodnames);
}
public Object run(Object target, Object... args){
try{
return method.invoke(target, args);
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
public boolean isLoaded() {
return loaded;
}
public boolean isCompatible() {
return compatible;
}
public static class Since{
public final MinecraftVersion version;
public final String name;
public Since(MinecraftVersion version, String name) {
this.version = version;
this.name = name;
}
}
}
@@ -1,27 +0,0 @@
package de.tr7zw.itemnbtapi.utils;
import com.google.gson.Gson;
public class GsonWrapper {
private static final Gson gson = new Gson();
public static String getString(Object obj) {
return gson.toJson(obj);
}
public static <T> T deserializeJson(String json, Class<T> type) {
try {
if (json == null) {
return null;
}
T obj = gson.fromJson(json, type);
return type.cast(obj);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}
@@ -1,63 +0,0 @@
package de.tr7zw.itemnbtapi.utils;
import org.bukkit.Bukkit;
public enum MinecraftVersion {
Unknown(Integer.MAX_VALUE),//Use the newest known mappings
MC1_7_R4(174),
MC1_8_R3(183),
MC1_9_R1(191),
MC1_9_R2(192),
MC1_10_R1(1101),
MC1_11_R1(1111),
MC1_12_R1(1121),
MC1_13_R1(1131),
MC1_13_R2(1132),
MC1_14_R1(1141);
private static MinecraftVersion version;
private static Boolean hasGsonSupport;
private final int versionId;
MinecraftVersion(int versionId) {
this.versionId = versionId;
}
public int getVersionId() {
return versionId;
}
public static MinecraftVersion getVersion() {
if (version != null) {
return version;
}
final String ver = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
System.out.println("[NBTAPI] Found Spigot: " + ver + "! Trying to find NMS support");
try {
version = MinecraftVersion.valueOf(ver.replace("v", "MC"));
} catch (IllegalArgumentException ex) {
version = MinecraftVersion.Unknown;
}
if (version != Unknown) {
System.out.println("[NBTAPI] NMS support '" + version.name() + "' loaded!");
} else {
System.out.println("[NBTAPI] Wasn't able to find NMS Support! Some functions may not work!");
}
return version;
}
public static boolean hasGsonSupport() {
if (hasGsonSupport != null) {
return hasGsonSupport;
}
try {
System.out.println("Found Gson: " + Class.forName("com.google.gson.Gson"));
hasGsonSupport = true;
} catch (Exception ex) {
hasGsonSupport = false;
}
return hasGsonSupport;
}
}
+5 -6
View File
@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 tr7zw
Copyright (c) 2015 - 2021, tr7zw
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -9,14 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+124 -71
View File
@@ -1,73 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>1.8.3-SNAPSHOT</version>
</parent>
<artifactId>item-nbt-api-plugin</artifactId>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>de.tr7zw.itemnbtapi</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>1.8.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit-lite</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.16.1</version>
</parent>
<artifactId>item-nbt-api-plugin</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.16.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>datafixerupper</artifactId>
<version>4.0.26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.2.1</version>
<!-- Overwrite to provided -->
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>de.tr7zw.changeme.nbtapi</pattern>
<shadedPattern>de.tr7zw.nbtapi</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>LICENSE</resource>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<id>shade</id>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<!-- Start and Stop a SpigotMC server automatically before and after the integration-test phase. -->
<plugin>
<groupId>de.tr7zw.spigotmc.maven</groupId>
<artifactId>tr-spigotmc-maven-plugin</artifactId>
<version>0.0.3-SNAPSHOT</version>
<configuration>
<!-- 1.8.8-R0.1-SNAPSHOT-latest, 1.9.2-R0.1-SNAPSHOT-latest, 1.9.4-R0.1-SNAPSHOT-latest, 1.10.2-R0.1-SNAPSHOT-latest,1.11.2,1.12.2,1.13.2,1.14.4,1.15.1,1.16.1,1.16.2 -->
<versions>
https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.8.8-R0.1-SNAPSHOT/spigot-1.8.8-R0.1-20190527.160303-7.jar,
https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-20190527.160755-2.jar,
https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.10.2-R0.1-SNAPSHOT/spigot-1.10.2-R0.1-20190527.154910-2.jar,
https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.11.2-R0.1-SNAPSHOT/spigot-1.11.2-R0.1-20191216.091129-1.jar,
https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.12.2-R0.1-SNAPSHOT/spigot-1.12.2-R0.1-20190527.155359-34.jar,
<!--https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.13.2-R0.1-SNAPSHOT/spigot-1.13.2-R0.1-20191113.201242-53.jar,-->
https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.14.4-R0.1-SNAPSHOT/spigot-1.14.4-R0.1-20191224.232152-15.jar,
https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.15.2-R0.1-SNAPSHOT/spigot-1.15.2-R0.1-20200625.172449-18.jar,
https://repo.codemc.io/repository/nms/org/spigotmc/spigot/1.16.5-R0.1-SNAPSHOT/spigot-1.16.5-R0.1-20210611.090701-17.jar
</versions>
<works>Success! This version of NBT-API</works>
<error>WARNING! This version of NBT-API</error>
<filename>item-nbt-api-plugin-${project.version}.jar</filename>
<foldername>item-nbt-plugin</foldername>
</configuration>
<executions>
<execution>
<id>start-server</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-server</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>nbtapi-javadoc-plugin</artifactId>
<version>3.4.2-SNAPSHOT</version>
<executions>
<execution>
<id>bundle-javadoc</id>
<goals>
<goal>aggregate-jar</goal>
</goals>
<phase>package</phase>
<configuration>
<detectOfflineLinks>false</detectOfflineLinks>
<includeDependencySources>true</includeDependencySources>
<sourcepath>src/main/java;${project.parent.basedir}/item-nbt-api/src/main/java;${project.build.directory}/javadoc-relocate;${defines.dir}</sourcepath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -1,382 +0,0 @@
package de.tr7zw.itemnbtapi;
import java.io.File;
import java.util.logging.Level;
import org.bstats.bukkit.MetricsLite;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Monster;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import de.tr7zw.itemnbtapi.utils.MinecraftVersion;
public class ItemNBTAPI extends JavaPlugin {
private static boolean compatible = true;
private static boolean jsonCompatible = true;
@Deprecated
public static ItemNBTAPI instance;
public static ItemNBTAPI getInstance() {
return instance;
}
@Override
public void onEnable() {
instance = this;
new MetricsLite(this);
getLogger().info("Checking bindings...");
getLogger().info("Minecraft Version:");
MinecraftVersion.getVersion();
getLogger().info("Gson:");
MinecraftVersion.hasGsonSupport();
getLogger().info("Classes:");
for (ClassWrapper c : ClassWrapper.values()) {
if (c.getClazz() == null) {
getLogger().warning(c.name() + " did not find it's class!");
compatible = false;
}
}
getLogger().info("Methods:");
for (ReflectionMethod method : ReflectionMethod.values()) {
if (method.isCompatible() && !method.isLoaded()) {
getLogger().warning(method.name() + " did not find the method!");
compatible = false;
}
}
getLogger().info("Running NBT reflection test...");
try {
//Item
ItemStack item = new ItemStack(Material.STONE, 1);
NBTItem nbtItem = new NBTItem(item);
nbtItem.setString(STRING_TEST_KEY, STRING_TEST_VALUE);
nbtItem.setInteger(INT_TEST_KEY, INT_TEST_VALUE);
nbtItem.setDouble(DOUBLE_TEST_KEY, DOUBLE_TEST_VALUE);
nbtItem.setBoolean(BOOLEAN_TEST_KEY, BOOLEAN_TEST_VALUE);
nbtItem.setByte(BYTE_TEST_KEY, BYTE_TEST_VALUE);
nbtItem.setShort(SHORT_TEST_KEY, SHORT_TEST_VALUE);
nbtItem.setLong(LONG_TEST_KEY, LONG_TEST_VALUE);
nbtItem.setFloat(FLOAT_TEST_KEY, FLOAT_TEST_VALUE);
nbtItem.setIntArray(INTARRAY_TEST_KEY, INTARRAY_TEST_VALUE);
nbtItem.setByteArray(BYTEARRAY_TEST_KEY, BYTEARRAY_TEST_VALUE);
nbtItem.addCompound(COMP_TEST_KEY);
NBTCompound comp = nbtItem.getCompound(COMP_TEST_KEY);
comp.setString(STRING_TEST_KEY, STRING_TEST_VALUE + "2");
comp.setInteger(INT_TEST_KEY, INT_TEST_VALUE * 2);
comp.setDouble(DOUBLE_TEST_KEY, DOUBLE_TEST_VALUE * 2);
NBTList list = comp.getList("testlist", NBTType.NBTTagString);
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
getLogger().warning(
"Skipped the NBTList check, because 1.7 doesn't fully support it! The Item-NBT-API may not work!");
} else {
list.addString("test1");
list.addString("test2");
list.addString("test3");
list.addString("test4");
list.setString(2, "test42");
list.remove(1);
}
NBTList taglist = comp.getList("complist", NBTType.NBTTagCompound);
NBTListCompound lcomp = taglist.addCompound();
lcomp.setDouble("double1", 0.3333);
lcomp.setInteger("int1", 42);
lcomp.setString("test1", "test1");
lcomp.setString("test2", "test2");
lcomp.remove("test1");
item = nbtItem.getItem();
nbtItem = new NBTItem(item);
if (!nbtItem.hasKey(STRING_TEST_KEY)) {
getLogger().warning("Wasn't able to check a key! The Item-NBT-API may not work!");
compatible = false;
}
if (!(STRING_TEST_VALUE).equals(nbtItem.getString(STRING_TEST_KEY))
|| nbtItem.getInteger(INT_TEST_KEY) != INT_TEST_VALUE
|| nbtItem.getDouble(DOUBLE_TEST_KEY) != DOUBLE_TEST_VALUE
|| nbtItem.getByte(BYTE_TEST_KEY) != BYTE_TEST_VALUE
|| nbtItem.getShort(SHORT_TEST_KEY) != SHORT_TEST_VALUE
|| nbtItem.getFloat(FLOAT_TEST_KEY) != FLOAT_TEST_VALUE
|| nbtItem.getLong(LONG_TEST_KEY) != LONG_TEST_VALUE
|| nbtItem.getIntArray(INTARRAY_TEST_KEY).length != (INTARRAY_TEST_VALUE).length
|| nbtItem.getByteArray(BYTEARRAY_TEST_KEY).length != (BYTEARRAY_TEST_VALUE).length
|| !nbtItem.getBoolean(BOOLEAN_TEST_KEY).equals(BOOLEAN_TEST_VALUE)) {
getLogger().warning("One key does not equal the original value! The Item-NBT-API may not work!");
compatible = false;
}
nbtItem.setString(STRING_TEST_KEY, null);
if (nbtItem.getKeys().size() != 10) {
getLogger().warning("Wasn't able to remove a key (Got " + nbtItem.getKeys().size()
+ " when expecting 10)! The Item-NBT-API may not work!");
compatible = false;
}
comp = nbtItem.getCompound(COMP_TEST_KEY);
if (comp == null) {
getLogger().warning("Wasn't able to get the NBTCompound! The Item-NBT-API may not work!");
compatible = false;
}
if (!comp.hasKey(STRING_TEST_KEY)) {
getLogger().warning("Wasn't able to check a compound key! The Item-NBT-API may not work!");
compatible = false;
}
if (!(STRING_TEST_VALUE + "2").equals(comp.getString(STRING_TEST_KEY))
|| comp.getInteger(INT_TEST_KEY) != INT_TEST_VALUE * 2
|| comp.getDouble(DOUBLE_TEST_KEY) != DOUBLE_TEST_VALUE * 2
|| comp.getBoolean(BOOLEAN_TEST_KEY) == BOOLEAN_TEST_VALUE) {
getLogger()
.warning("One key does not equal the original compound value! The Item-NBT-API may not work!");
compatible = false;
}
list = comp.getList("testlist", NBTType.NBTTagString);
if (comp.getType("testlist") != NBTType.NBTTagList) {
getLogger().warning("Wasn't able to get the correct Tag type! The Item-NBT-API may not work!");
compatible = false;
}
if (!list.getString(1).equals("test42") || list.size() != 3) {
getLogger().warning("The List support got an error, and may not work!");
}
taglist = comp.getList("complist", NBTType.NBTTagCompound);
if (taglist.size() == 1) {
lcomp = taglist.getCompound(0);
if (lcomp.getKeys().size() != 3) {
getLogger().warning("Wrong key amount in Taglist (" + lcomp.getKeys().size()
+ ")! The Item-NBT-API may not work!");
compatible = false;
} else if (!(lcomp.getDouble("double1") == 0.3333 && lcomp.getInteger("int1") == 42
&& lcomp.getString("test2").equals("test2") && !lcomp.hasKey("test1"))) {
getLogger().warning("One key in the Taglist changed! The Item-NBT-API may not work!");
compatible = false;
}
} else {
getLogger().warning("Taglist is empty! The Item-NBT-API may not work!");
compatible = false;
}
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
compatible = false;
}
testJson();
try {
//File
NBTFile file = new NBTFile(new File(getDataFolder(), "test.nbt"));
file.addCompound("testcomp").setString("test1", "ok");
NBTCompound comp = file.getCompound("testcomp");
comp.setString("test2", "ok");
file.setLong("time", System.currentTimeMillis());
file.setString("test", "test");
file.save();
file = null;
file = new NBTFile(new File(getDataFolder(), "test.nbt"));
System.out.println(file.asNBTString());
file.getFile().delete();
//String
String str = file.asNBTString();
NBTContainer rebuild = new NBTContainer(str);
if (!str.equals(rebuild.asNBTString())) {
getLogger().warning("Wasn't able to parse NBT from a String! The Item-NBT-API may not work!");
compatible = false;
}
//Item->NBT->String->NBT->Item
ItemStack preitem = new ItemStack(Material.STICK, 5);
ItemMeta premeta = preitem.getItemMeta();
premeta.setDisplayName("test");
preitem.setItemMeta(premeta);
// String itemasString = NBTItem.convertItemtoNBT(preitem).asNBTString();
//ItemStack afteritem = NBTItem.convertNBTtoItem(new NBTContainer(itemasString));
//if(!preitem.isSimilar(afteritem)){
// getLogger().warning("Wasn't able to convert an Item to String and back to Item! The Item-NBT-API may not work!");
// compatible = false;
//}
//mergingtags
NBTContainer test1 = new NBTContainer();
test1.setString("test1", "test");
NBTContainer test2 = new NBTContainer();
test2.setString("test2", "test");
test2.addCompound("test").setLong("time", System.currentTimeMillis());
test1.mergeCompound(test2);
if (!test1.getString("test1").equals(test1.getString("test2"))) {
getLogger().warning("Wasn't able to merge Compounds! The Item-NBT-API may not work!");
compatible = false;
}
if (!Bukkit.getWorlds().isEmpty()) {
World world = Bukkit.getWorlds().get(0);
try {
if (!world.getEntitiesByClasses(Animals.class, Monster.class).isEmpty()) {
getLogger().info("Testing Entity NBT!");
NBTEntity nbte = new NBTEntity(
world.getEntitiesByClasses(Animals.class, Monster.class).iterator().next());
getLogger().info(nbte.asNBTString());
nbte.setString("INVALIDEKEY", "test");
getLogger().info("Entity NBT seems to work!");
}
} catch (Exception ex) {
getLogger().warning("Wasn't able to use NBTEntities! The Item-NBT-API may not work!");
compatible = false;
ex.printStackTrace();
}
/* try {
Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 255, world.getSpawnLocation().getBlockZ());
if (block.getType() == Material.AIR) {
getLogger().info("Testing Tile NBT!");
block.setType(Material.CHEST);
NBTTileEntity tile = new NBTTileEntity(block.getState());
getLogger().info(tile.asNBTString());
tile.setString("Lock", "test");
getLogger().info(tile.asNBTString());
block.setType(Material.AIR);
getLogger().info("Tile NBT seems to work!");
}
} catch (Exception ex) {
getLogger().warning("Wasn't able to use NBTTiles! The Item-NBT-API may not work!");
compatible = false;
ex.printStackTrace();
}*/
}
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
compatible = false;
}
String checkMessage = "Plugins that don't check properly may throw Exeptions, crash or have unexpected behaviors!";
if (compatible) {
if (jsonCompatible) {
getLogger().info("Success! This version of Item-NBT-API is compatible with your server.");
} else {
getLogger()
.info("General Success! This version of Item-NBT-API is mostly compatible with your server. JSON serialization is not working properly. "
+ checkMessage);
}
} else {
getLogger().warning("WARNING! This version of Item-NBT-API seems to be broken with your Spigot version! "
+ checkMessage);
}
}
public void testJson() {
if (!MinecraftVersion.hasGsonSupport()) {
getLogger().warning(
"Wasn't able to find Gson! The Item-NBT-API may not work with Json serialization/deserialization!");
return;
}
try {
ItemStack item = new ItemStack(Material.STONE, 1);
NBTItem nbtItem = new NBTItem(item);
nbtItem.setObject(JSON_TEST_KEY, new SimpleJsonTestObject());
if (!nbtItem.hasKey(JSON_TEST_KEY)) {
getLogger().warning(
"Wasn't able to find JSON key! The Item-NBT-API may not work with Json serialization/deserialization!");
jsonCompatible = false;
} else {
SimpleJsonTestObject simpleObject = nbtItem.getObject(JSON_TEST_KEY, SimpleJsonTestObject.class);
if (simpleObject == null) {
getLogger().warning(
"Wasn't able to check JSON key! The Item-NBT-API may not work with Json serialization/deserialization!");
jsonCompatible = false;
} else if (!(STRING_TEST_VALUE).equals(simpleObject.getTestString())
|| simpleObject.getTestInteger() != INT_TEST_VALUE
|| simpleObject.getTestDouble() != DOUBLE_TEST_VALUE
|| !simpleObject.isTestBoolean() == BOOLEAN_TEST_VALUE) {
getLogger().warning(
"One key does not equal the original value in JSON! The Item-NBT-API may not work with Json serialization/deserialization!");
jsonCompatible = false;
}
}
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
getLogger().warning(ex.getMessage());
jsonCompatible = false;
}
}
public boolean isCompatible() {
return compatible;
}
public static NBTItem getNBTItem(ItemStack item) {
return new NBTItem(item);
}
//region STATIC FINAL VARIABLES
private static final String STRING_TEST_KEY = "stringTest";
private static final String INT_TEST_KEY = "intTest";
private static final String DOUBLE_TEST_KEY = "doubleTest";
private static final String BOOLEAN_TEST_KEY = "booleanTest";
private static final String JSON_TEST_KEY = "jsonTest";
private static final String COMP_TEST_KEY = "componentTest";
private static final String SHORT_TEST_KEY = "shortTest";
private static final String BYTE_TEST_KEY = "byteTest";
private static final String FLOAT_TEST_KEY = "floatTest";
private static final String LONG_TEST_KEY = "longTest";
private static final String INTARRAY_TEST_KEY = "intarrayTest";
private static final String BYTEARRAY_TEST_KEY = "bytearrayTest";
private static final String STRING_TEST_VALUE = "TestString";
private static final int INT_TEST_VALUE = 42;
private static final double DOUBLE_TEST_VALUE = 1.5d;
private static final boolean BOOLEAN_TEST_VALUE = true;
private static final short SHORT_TEST_VALUE = 64;
private static final byte BYTE_TEST_VALUE = 7;
private static final float FLOAT_TEST_VALUE = 13.37f;
private static final long LONG_TEST_VALUE = (long) Integer.MAX_VALUE + 42L;
private static final int[] INTARRAY_TEST_VALUE = new int[] { 1337, 42, 69 };
private static final byte[] BYTEARRAY_TEST_VALUE = new byte[] { 8, 7, 3, 2 };
//end region STATIC FINAL VARIABLES
public static class SimpleJsonTestObject {
private String testString = STRING_TEST_VALUE;
private int testInteger = INT_TEST_VALUE;
private double testDouble = DOUBLE_TEST_VALUE;
private boolean testBoolean = BOOLEAN_TEST_VALUE;
public SimpleJsonTestObject() {
}
public String getTestString() {
return testString;
}
public void setTestString(String testString) {
this.testString = testString;
}
public int getTestInteger() {
return testInteger;
}
public void setTestInteger(int testInteger) {
this.testInteger = testInteger;
}
public double getTestDouble() {
return testDouble;
}
public void setTestDouble(double testDouble) {
this.testDouble = testDouble;
}
public boolean isTestBoolean() {
return testBoolean;
}
public void setTestBoolean(boolean testBoolean) {
this.testBoolean = testBoolean;
}
}
}
@@ -0,0 +1,241 @@
package de.tr7zw.nbtapi.plugin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import org.bukkit.plugin.java.JavaPlugin;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.VersionChecker;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
import de.tr7zw.nbtapi.plugin.tests.GameprofileTest;
import de.tr7zw.nbtapi.plugin.tests.NBTFileTest;
import de.tr7zw.nbtapi.plugin.tests.blocks.BlockNBTTest;
import de.tr7zw.nbtapi.plugin.tests.chunks.ChunkNBTPersistentTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.CompoundDifferenceTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.EnumTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.EqualsTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.ForEachTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.GetterSetterTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.InterfaceTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.IteratorTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.ListTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.LongArrayTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.MergeTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.ModernSubCompoundsTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.RemovingKeys;
import de.tr7zw.nbtapi.plugin.tests.compounds.ResolveTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.StreamTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.SubCompoundsTest;
import de.tr7zw.nbtapi.plugin.tests.compounds.TypeTest;
import de.tr7zw.nbtapi.plugin.tests.entities.EntityCustomNbtPersistentTest;
import de.tr7zw.nbtapi.plugin.tests.entities.EntityTest;
import de.tr7zw.nbtapi.plugin.tests.items.ComponentsTest;
import de.tr7zw.nbtapi.plugin.tests.items.DirectApplyMetaTest;
import de.tr7zw.nbtapi.plugin.tests.items.DirectApplyTest;
import de.tr7zw.nbtapi.plugin.tests.items.EmptyItemTest;
import de.tr7zw.nbtapi.plugin.tests.items.ItemConversionTest;
import de.tr7zw.nbtapi.plugin.tests.items.ItemJsonTest;
import de.tr7zw.nbtapi.plugin.tests.items.ItemMergingTest;
import de.tr7zw.nbtapi.plugin.tests.items.ItemStackConversionTest;
import de.tr7zw.nbtapi.plugin.tests.items.LegacyItemTest;
import de.tr7zw.nbtapi.plugin.tests.items.MetaTest;
import de.tr7zw.nbtapi.plugin.tests.items.NBTModifyItemTest;
import de.tr7zw.nbtapi.plugin.tests.items.SmuggleTest;
import de.tr7zw.nbtapi.plugin.tests.proxy.SimpleProxyTest;
import de.tr7zw.nbtapi.plugin.tests.tiles.TileTest;
import de.tr7zw.nbtapi.plugin.tests.tiles.TilesCustomNBTPersistentTest;
public class NBTAPI extends JavaPlugin {
private boolean compatible = true;
private List<de.tr7zw.nbtapi.plugin.tests.Test> apiTests = new ArrayList<>();
private static NBTAPI instance;
public static NBTAPI getInstance() {
return instance;
}
@Override
public void onLoad() {
getConfig().options().copyDefaults(true);
getConfig().addDefault("bStats.enabled", true);
getConfig().addDefault("updateCheck.enabled", true);
getConfig().addDefault("silentquickstart", false);
saveConfig();
if (!getConfig().getBoolean("bStats.enabled")) {
getLogger().info("bStats disabled");
MinecraftVersion.disableBStats();
}
if (!getConfig().getBoolean("updateCheck.enabled")) {
getLogger().info("Update check disabled");
MinecraftVersion.disableUpdateCheck();
} else {
MinecraftVersion.enableUpdateCheck();
}
// NBTCompounds
apiTests.add(new GetterSetterTest());
apiTests.add(new TypeTest());
apiTests.add(new RemovingKeys());
apiTests.add(new EnumTest());
apiTests.add(new InterfaceTest());
apiTests.add(new ResolveTest());
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) // 1.7.10 list support is not complete at all
apiTests.add(new ListTest());
apiTests.add(new SubCompoundsTest());
apiTests.add(new ModernSubCompoundsTest());
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) // 1.7.10 not a thing
apiTests.add(new MergeTest());
apiTests.add(new ForEachTest());
apiTests.add(new StreamTest());
apiTests.add(new EqualsTest());
apiTests.add(new CompoundDifferenceTest());
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) // 1.7.10 list support is not complete at all
apiTests.add(new IteratorTest());
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1))
apiTests.add(new LongArrayTest());
// Items
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) { // 1.7.10 not a thing
apiTests.add(new ItemConversionTest());
apiTests.add(new ItemStackConversionTest());
}
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
apiTests.add(new LegacyItemTest());
}
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4) && !MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_21_R4)) {
apiTests.add(new ItemJsonTest());
}
apiTests.add(new ComponentsTest());
apiTests.add(new EmptyItemTest());
apiTests.add(new SmuggleTest());
apiTests.add(new MetaTest());
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) { // 1.7.10 not a thing
apiTests.add(new ItemMergingTest());
apiTests.add(new DirectApplyTest());
apiTests.add(new DirectApplyMetaTest());
apiTests.add(new NBTModifyItemTest());
}
// Proxies
apiTests.add(new SimpleProxyTest());
// Entity
apiTests.add(new EntityTest());
apiTests.add(new EntityCustomNbtPersistentTest());
// Tiles
apiTests.add(new TileTest());
apiTests.add(new TilesCustomNBTPersistentTest());
// Chunks
apiTests.add(new ChunkNBTPersistentTest());
// Blocks
apiTests.add(new BlockNBTTest());
// Files
apiTests.add(new NBTFileTest());
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3))
apiTests.add(new GameprofileTest());
}
@Override
public void onEnable() {
instance = this; // NOSONAR
// new MetricsLite(this); The metrics moved into the API
if (getConfig().getBoolean("silentquickstart")) {
// we are silent, won't check anything or pre-init
VersionChecker.hideOk = true;
return;
}
MinecraftVersion.hasGsonSupport(); // init gson(if it hasn't already)
getLogger().info("Checking bindings...");
MinecraftVersion.getVersion();
boolean classUnlinked = false;
for (ClassWrapper c : ClassWrapper.values()) {
if (c.isEnabled() && c.getClazz() == null) {
if (!classUnlinked)
getLogger().info("Classes:");
getLogger().warning(c.name() + " did not find it's class!");
compatible = false;
classUnlinked = true;
}
}
if (!classUnlinked)
getLogger().info("All Classes were able to link!");
boolean methodUnlinked = false;
for (ReflectionMethod method : ReflectionMethod.values()) {
if (method.isCompatible() && !method.isLoaded()) {
if (!methodUnlinked)
getLogger().info("Methods:");
getLogger().warning(method.name() + " did not find the method!");
compatible = false;
methodUnlinked = true;
}
}
if (!methodUnlinked)
getLogger().info("All Methods were able to link!");
getLogger().info("Running NBT reflection test...");
Map<de.tr7zw.nbtapi.plugin.tests.Test, Exception> results = new HashMap<>();
for (de.tr7zw.nbtapi.plugin.tests.Test test : apiTests) {
try {
test.test();
results.put(test, null);
} catch (Exception ex) {
results.put(test, ex);
getLogger().log(Level.WARNING, "Error during '" + test.getClass().getSimpleName() + "' test!", ex);
} catch (Throwable th) { // NOSONAR
getLogger().log(Level.SEVERE, "Servere error during '" + test.getClass().getSimpleName() + "' test!");
getLogger().warning(
"WARNING! This version of Item-NBT-API seems to be broken with your Spigot version! Canceled the other tests!");
throw th;
}
}
for (Entry<de.tr7zw.nbtapi.plugin.tests.Test, Exception> entry : results.entrySet()) {
if (entry.getValue() != null) {
compatible = false;
getLogger().info(entry.getKey().getClass().getSimpleName() + ": " + entry.getValue().getMessage());
}
}
String checkMessage = "Plugins that don't check properly may throw Exeptions, crash or have unexpected behaviors!";
if (compatible) {
NbtApiException.confirmedBroken = false;
getLogger().info("Success! This version of NBT-API is compatible with your server.");
} else {
NbtApiException.confirmedBroken = true;
getLogger().warning(
"WARNING! This version of NBT-API seems to be broken with your Spigot version! " + checkMessage);
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
getLogger().warning(
"1.7.10 is only partally supported! Some thing will not work/are not yet avaliable in 1.7.10!");
}
}
}
/**
* @return True if all selfchecks succeeded
*/
public boolean isCompatible() {
return compatible;
}
}
@@ -0,0 +1,24 @@
package de.tr7zw.nbtapi.plugin.tests;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
public class GameprofileTest implements Test {
@Override
public void test() throws Exception {
UUID uuid = UUID.randomUUID();
GameProfile profile = new GameProfile(uuid, "random");
ReadWriteNBT nbt = NBT.gameProfileToNBT(profile);
GameProfile profile2 = NBT.gameProfileFromNBT(nbt);
if (profile == null || !profile.equals(profile2)) {
throw new NbtApiException("Error when converting a GameProfile from/to NBT!");
}
}
}
@@ -0,0 +1,63 @@
package de.tr7zw.nbtapi.plugin.tests;
import java.io.File;
import java.nio.file.Files;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.NBTFileHandle;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.nbtapi.plugin.NBTAPI;
public class NBTFileTest implements Test {
@Override
public void test() throws Exception {
NBTAPI.getInstance().getDataFolder().mkdirs();
File testFile = new File(NBTAPI.getInstance().getDataFolder(), "test.nbt");
Files.deleteIfExists(testFile.toPath());
NBTFileHandle file = NBT.getFileHandle(testFile);
file.getOrCreateCompound("testcomp").setString("test1", "ok");
ReadWriteNBT comp = file.getOrCreateCompound("testcomp");
if (comp == null) {
throw new NbtApiException("Error getting compound!");
}
comp.setString("test2", "ok");
file.setLong("time", System.currentTimeMillis());
file.setString("test", "test");
ReadWriteNBT chunks = file.getOrCreateCompound("chunks");
ReadWriteNBT chunk = chunks.getOrCreateCompound("somechunk");
ReadWriteNBT block = chunk.getOrCreateCompound("someblock");
block.setString("type", "wool");
file.save();
if (!"wool".equals(block.getString("type"))) {
throw new NbtApiException("SubCompounds did not work!");
}
NBTFileHandle fileLoaded = NBT.getFileHandle(testFile);
if (!fileLoaded.getString("test").equals("test")) {
throw new NbtApiException("Wasn't able to load NBT File with the correct content!");
}
Files.deleteIfExists(fileLoaded.getFile().toPath());
// String
String str = fileLoaded.toString();
ReadWriteNBT rebuild = NBT.parseNBT(str);
if (!str.equals(rebuild.toString())) {
throw new NbtApiException("Wasn't able to parse NBT from a String!");
}
ReadWriteNBT dummy = NBT.createNBTObject();
dummy.setString("test1", "key1");
NBT.writeFile(testFile, dummy);
dummy = NBT.createNBTObject();
dummy.setString("test2", "key2");
NBT.writeFile(testFile, dummy);
dummy = NBT.readFile(testFile);
if (dummy.hasTag("test1") || !dummy.getString("test2").equals("key2")) {
throw new NbtApiException("Wasn't able to save NBT File with the correct content!");
}
Files.deleteIfExists(fileLoaded.getFile().toPath());
}
}
@@ -0,0 +1,7 @@
package de.tr7zw.nbtapi.plugin.tests;
public interface Test {
public void test() throws Exception; // NOSONAR
}
@@ -0,0 +1,78 @@
package de.tr7zw.nbtapi.plugin.tests.blocks;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTType;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.Block;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.nbtapi.plugin.tests.Test;
import java.util.List;
public class BlockNBTTest implements Test {
@Override
public void test() throws Exception {
if (MinecraftVersion.getVersion().getVersionId() < MinecraftVersion.MC1_16_R3.getVersionId())
return;
List<World> loadedWorlds = Bukkit.getWorlds();
if (loadedWorlds.isEmpty())
return;
World world = loadedWorlds.get(0);
Chunk[] loadedChunks = world.getLoadedChunks();
if (loadedChunks.length == 0)
return;
try {
Chunk chunk = loadedChunks[0];
Block block = chunk.getBlock(0, 254, 0);
String blockKey = block.getX() + "_" + block.getY() + "_" + block.getZ();
NBT.modifyChunkPDC(block, nbt -> nbt.setString("Too", "Bar"));
boolean storedDataPresent = NBT.readAndGetChunkPDC(chunk, nbt -> {
if (!nbt.hasTag("blocks", NBTType.NBTTagCompound)) return false;
ReadableNBT blocksNbt = nbt.getCompound("blocks");
if (blocksNbt == null || !blocksNbt.hasTag(blockKey, NBTType.NBTTagCompound)) return false;
ReadableNBT blockNbt = blocksNbt.getCompound(blockKey);
return blockNbt != null && blockNbt.hasTag("Too", NBTType.NBTTagString) && "Bar".equals(blockNbt.getString("Too"));
});
if (!storedDataPresent) {
throw new NbtApiException("Custom Data did not save to a Block!");
}
if (!NBT.readAndGetChunkPDC(block, nbt -> nbt.hasTag("Too"))) {
throw new NbtApiException("Custom Data did not save to a Block!");
}
boolean blockHadOnlyTestKey = NBT.readAndGetChunkPDC(block, nbt -> nbt.getKeys().size() == 1);
boolean chunkHadOnlyOneBlock = NBT.readAndGetChunkPDC(chunk, nbt -> nbt.getCompound("blocks").getKeys().size() == 1);
NBT.modifyChunkPDC(block, nbt -> nbt.removeKey("Too"));
if (NBT.readAndGetChunkPDC(block, nbt -> nbt.hasTag("Too"))) {
throw new NbtApiException("Unable to remove key from Block!");
}
if (chunkHadOnlyOneBlock) {
if (NBT.readAndGetChunkPDC(chunk, nbt -> nbt.hasTag("blocks"))) {
throw new NbtApiException("Chunk data wasn't cleaned up (hanging \"blocks\" compound)!");
}
} else if (blockHadOnlyTestKey) {
if (NBT.readAndGetChunkPDC(chunk, nbt -> nbt.getCompound("blocks").hasTag(blockKey))) {
throw new NbtApiException("Chunk data wasn't cleaned up (hanging block location compound)!");
}
}
} catch (Exception ex) {
throw new NbtApiException("Wasn't able to use NBTBlocks!", ex);
}
}
}
@@ -0,0 +1,47 @@
package de.tr7zw.nbtapi.plugin.tests.chunks;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTType;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.nbtapi.plugin.tests.Test;
import java.util.List;
public class ChunkNBTPersistentTest implements Test {
@Override
public void test() throws Exception {
if (MinecraftVersion.getVersion().getVersionId() < MinecraftVersion.MC1_16_R3.getVersionId())
return;
List<World> loadedWorlds = Bukkit.getWorlds();
if (loadedWorlds.isEmpty())
return;
World world = loadedWorlds.get(0);
Chunk[] loadedChunks = world.getLoadedChunks();
if (loadedChunks.length == 0)
return;
Chunk chunk = loadedChunks[0];
try {
NBT.modifyChunkPDC(chunk, nbt -> nbt.setString("Foo", "Bar"));
if (!NBT.readAndGetChunkPDC(chunk, nbt -> nbt.hasTag("Foo", NBTType.NBTTagString) && "Bar".equals(nbt.getString("Foo")))) {
throw new NbtApiException("Custom Data did not save to the Chunk!");
}
NBT.modifyChunkPDC(chunk, nbt -> nbt.removeKey("Foo"));
if (NBT.readAndGetChunkPDC(chunk, nbt -> nbt.hasTag("Foo"))) {
throw new NbtApiException("Unable to remove key from Chunk!");
}
} catch (Exception ex) {
throw new NbtApiException("Wasn't able to use NBTChunks!", ex);
}
}
}
@@ -0,0 +1,69 @@
package de.tr7zw.nbtapi.plugin.tests.compounds;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.nbtapi.plugin.tests.Test;
import java.util.Arrays;
public class CompoundDifferenceTest implements Test {
@Override
public void test() throws Exception {
ReadWriteNBT nbt1 = NBT.createNBTObject();
nbt1.setInteger("intTag", 1);
ReadWriteNBT tmp = NBT.createNBTObject();
tmp.setInteger("foo", 1);
nbt1.getCompoundList("compoundList1").addCompound(tmp);
nbt1.setIntArray("intArray", new int[]{1, 2, 3});
tmp = NBT.createNBTObject();
tmp.setIntArray("foo", new int[]{1, 2, 3});
nbt1.getCompoundList("compoundList2").addCompound(tmp);
nbt1.getOrCreateCompound("compoundTag").setFloat("floatTag", 20F);
nbt1.getOrCreateCompound("compoundTag").setBoolean("booleanTag", true);
nbt1.getOrCreateCompound("compoundTag").getDoubleList("doubleList").addAll(Arrays.asList(1D, 2D, 3D));
nbt1.getOrCreateCompound("compoundTag").getFloatList("floatList").addAll(Arrays.asList(1F, 2F));
nbt1.getOrCreateCompound("compoundTagTwo").setString("stringTag", "string");
ReadWriteNBT nbt2 = NBT.createNBTObject();
nbt2.setInteger("intTag", 1);
tmp = NBT.createNBTObject();
tmp.setInteger("foo", 1);
nbt2.getCompoundList("compoundList1").addCompound(tmp);
nbt2.setInteger("alsoIntTag", 2);
tmp = NBT.createNBTObject();
tmp.setInteger("foo", 2);
nbt2.getCompoundList("compoundList2").addCompound(tmp);
nbt2.getOrCreateCompound("compoundTag").setFloat("floatTag", 20F);
nbt2.getOrCreateCompound("compoundTag").setBoolean("booleanTag", false);
nbt2.getOrCreateCompound("compoundTag").getDoubleList("doubleList").addAll(Arrays.asList(1D, 2D, 3D, 4D));
nbt2.getOrCreateCompound("compoundTag").getFloatList("floatList").addAll(Arrays.asList(1F, 2F));
nbt2.getOrCreateCompound("compoundTagTwo").setString("stringTag", "string");
ReadWriteNBT expectedDiff1 = NBT.createNBTObject();
tmp = NBT.createNBTObject();
tmp.setIntArray("foo", new int[]{1, 2, 3});
expectedDiff1.getCompoundList("compoundList2").addCompound(tmp);
expectedDiff1.setIntArray("intArray", new int[]{1, 2, 3});
expectedDiff1.getOrCreateCompound("compoundTag").setBoolean("booleanTag", true);
expectedDiff1.getOrCreateCompound("compoundTag").getDoubleList("doubleList").addAll(Arrays.asList(1D, 2D, 3D));
ReadWriteNBT expectedDiff2 = NBT.createNBTObject();
tmp = NBT.createNBTObject();
tmp.setInteger("foo", 2);
expectedDiff2.getCompoundList("compoundList2").addCompound(tmp);
expectedDiff2.setInteger("alsoIntTag", 2);
expectedDiff2.getOrCreateCompound("compoundTag").setBoolean("booleanTag", false);
expectedDiff2.getOrCreateCompound("compoundTag").getDoubleList("doubleList").addAll(Arrays.asList(1D, 2D, 3D, 4D));
ReadWriteNBT diff1 = nbt1.extractDifference(nbt2);
ReadWriteNBT diff2 = nbt2.extractDifference(nbt1);
if (!expectedDiff1.equals(diff1)) {
throw new NbtApiException("Diff1: Compounds did not match! " + expectedDiff1 + " " + diff1);
}
if (!expectedDiff2.equals(diff2)) {
throw new NbtApiException("Diff2: Compounds did not match! " + expectedDiff2 + " " + diff2);
}
}
}
@@ -0,0 +1,24 @@
package de.tr7zw.nbtapi.plugin.tests.compounds;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTType;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.nbtapi.plugin.tests.Test;
public class EnumTest implements Test {
@Override
public void test() throws Exception {
ReadWriteNBT comp = NBT.createNBTObject();
comp.setEnum("test", NBTType.NBTTagEnd);
NBTType type = comp.getEnum("test", NBTType.class);
NBTType typeNonNull = comp.getOrNull("test", NBTType.class);
NBTType typeDefault = comp.getOrDefault("invalid", NBTType.NBTTagByte);
NBTType typeDefaultFound = comp.getOrDefault("test", NBTType.NBTTagByte);
if (type != NBTType.NBTTagEnd || typeNonNull != NBTType.NBTTagEnd || typeDefaultFound != NBTType.NBTTagEnd
|| typeDefault != NBTType.NBTTagByte)
throw new NbtApiException("One enum did not match what it should have been!");
}
}
@@ -0,0 +1,53 @@
package de.tr7zw.nbtapi.plugin.tests.compounds;
import java.util.Arrays;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.nbtapi.plugin.tests.Test;
public class EqualsTest implements Test {
@Override
public void test() throws Exception {
ReadWriteNBT cont = NBT.createNBTObject();
cont.setString("hello", "world");
cont.setInteger("theAnswer", 42);
cont.getOrCreateCompound("sub").setString("me", "too");
cont.getStringList("somelist").addAll(Arrays.asList("a", "b", "c"));
ItemStack item = new ItemStack(Material.STONE);
NBT.modify(item, nbti -> {
ReadWriteNBT customData = nbti.getOrCreateCompound("customData");
// reverse order
customData.getOrCreateCompound("sub").setString("me", "too");
customData.setInteger("theAnswer", 42);
customData.setString("hello", "world");
customData.getStringList("somelist").addAll(Arrays.asList("a", "b", "c"));
if (!customData.equals(cont)) {
throw new NbtApiException("Compounds did not match! " + customData + " " + cont);
}
});
// empty test
if (!NBT.createNBTObject().equals(NBT.createNBTObject())) {
throw new NbtApiException("Two empty tags did not match!");
}
// not equal test
ReadWriteNBT part1 = NBT.createNBTObject();
part1.setString("a", "a");
part1.setString("b", "b");
ReadWriteNBT part2 = NBT.createNBTObject();
part2.setString("a", "a");
part2.setString("b", "a");
if (part1.equals(part2)) {
throw new NbtApiException("Missmatched nbt did match!");
}
}
}
@@ -0,0 +1,50 @@
package de.tr7zw.nbtapi.plugin.tests.compounds;
import java.util.ListIterator;
import de.tr7zw.changeme.nbtapi.NBTCompoundList;
import de.tr7zw.changeme.nbtapi.NBTContainer;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.nbtapi.plugin.tests.Test;
/**
* Test requested by TAU on Discord
*
*/
public class ForEachTest implements Test {
@SuppressWarnings("unused")
@Override
public void test() throws Exception {
NBTContainer comp = new NBTContainer();
NBTCompoundList compList = comp.getCompoundList("testkey");
if (compList != null) {
compList.addCompound().setInteger("id", 1);
compList.addCompound().setInteger("id", 2);
compList.addCompound().setInteger("id", 3);
int count = 0;
for (ReadWriteNBT listComp : compList) {
count++;
}
if (count != compList.size())
throw new NbtApiException("For loop did not get all Entries!");
count = 0;
ListIterator<ReadWriteNBT> lit = compList.listIterator();
while (lit.hasNext()) {
lit.next();
count++;
}
if (count != compList.size())
throw new NbtApiException("ListIterator did not get all Entries!");
count = 0;
while (lit.hasPrevious()) {
lit.previous();
count++;
}
if (count != compList.size())
throw new NbtApiException("ListIterator previous did not get all Entries!");
}
}
}
Loaded 100 of 159 files, more files were not shown because too many files have changed in this diff. Show more