Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0602a2b8c3 | ||
|
|
e0c060a982 | ||
|
|
caa37d4cb0 | ||
|
|
de9f2a786f | ||
|
|
423f0a07e4 | ||
|
|
eda1d60ccc | ||
|
|
acb5a376e9 | ||
|
|
165bb4ce68 | ||
|
|
08bde0923f | ||
|
|
a78b68d16f | ||
|
|
87204ac4a0 | ||
|
|
71701d4a3a | ||
|
|
6b156c47e4 | ||
|
|
f783db7fca | ||
|
|
394c093981 | ||
|
|
1f94a8452e | ||
|
|
8e96e4cb7d | ||
|
|
b08f6c193f | ||
|
|
30d6b7cb01 | ||
|
|
d08b2fcb11 | ||
|
|
fb4ef48d7a | ||
|
|
441fedf1e8 | ||
|
|
fe7b04d6d6 | ||
|
|
05826a5ed5 | ||
|
|
e8a508623b | ||
|
|
7b65e54ac7 | ||
|
|
44ff2fa973 | ||
|
|
595357f4c6 | ||
|
|
03475a3f76 | ||
|
|
8e05513122 | ||
|
|
d43447c721 | ||
|
|
50edbaeed3 | ||
|
|
01afd25131 | ||
|
|
601cb2f56c | ||
|
|
442a6e935b | ||
|
|
2213ab879d | ||
|
|
00c2ce951b | ||
|
|
60d8101b9f | ||
|
|
ef56b44629 | ||
|
|
5859276c11 | ||
|
|
f588e6fec9 | ||
|
|
413b0f38f4 | ||
|
|
a40eb5b4b4 | ||
|
|
a4deb2a1ee | ||
|
|
feaf59998f | ||
|
|
cc1a88cdc8 | ||
|
|
b58215d4bf | ||
|
|
689c354443 | ||
|
|
ff3a7c3add | ||
|
|
7d76d3c342 | ||
|
|
2107d6f53d | ||
|
|
f3e912723b | ||
|
|
47f29234e3 | ||
|
|
bd1ebac035 | ||
|
|
ea9ccdc077 | ||
|
|
f2d13e9b4e | ||
|
|
17c689699d | ||
|
|
c8110b0637 | ||
|
|
2daec88667 | ||
|
|
01aec6c272 | ||
|
|
b74ba362c8 | ||
|
|
65a86027ba | ||
|
|
580c07fc3f | ||
|
|
c38ca2cb35 | ||
|
|
1ebd2a8ed1 | ||
|
|
19300566c2 | ||
|
|
6b6783e7c6 | ||
|
|
7e5b5a1ff4 | ||
|
|
ff50036688 | ||
|
|
7c0b63d0e3 | ||
|
|
8f4dad62bd | ||
|
|
6667682c6c | ||
|
|
0123652cc7 | ||
|
|
0d9c200e88 | ||
|
|
ab3c52ada1 | ||
|
|
443fb2d3c0 | ||
|
|
0de8279b4b | ||
|
|
003e015d1d | ||
|
|
b5dc20683f | ||
|
|
bda2845a79 | ||
|
|
817b104757 | ||
|
|
d4ab47d287 | ||
|
|
cd30dd1303 | ||
|
|
ff6a0361b7 | ||
|
|
97042b9fc1 | ||
|
|
6234e359eb | ||
|
|
32070b8f19 | ||
|
|
a371a33766 | ||
|
|
8ad527057e | ||
|
|
cf5fe7c083 | ||
|
|
0255ef044f | ||
|
|
faeea97934 | ||
|
|
b4a59cdede | ||
|
|
c47ca55e84 | ||
|
|
8cbf4b1cf6 | ||
|
|
67bf920ba7 | ||
|
|
af0a8f1d4c | ||
|
|
7fa614b3d5 | ||
|
|
55a3f8b1b1 | ||
|
|
2a432e68ab | ||
|
|
efbd6912ab | ||
|
|
70579b649d | ||
|
|
cdeabe7364 | ||
|
|
f4f32d9303 | ||
|
|
5cb25ad47d | ||
|
|
1fb0945f1d | ||
|
|
d31e2849b3 | ||
|
|
ca2bb4d0b3 | ||
|
|
550ae33051 | ||
|
|
1b7bf63982 | ||
|
|
d89edc6738 | ||
|
|
71f4cb764e | ||
|
|
bba58df6c3 | ||
|
|
a9bb1bc839 | ||
|
|
75249b556e | ||
|
|
8aba56ff70 | ||
|
|
27761ac95a | ||
|
|
c6b3055a15 |
No files matched your search
@@ -139,6 +139,7 @@
|
||||
"avatar_url": "https://www.spigotmc.org/data/avatars/l/88/88296.jpg?1563463602",
|
||||
"profile": "https://www.spigotmc.org/members/lonedev.88296",
|
||||
"contributions": [
|
||||
"code",
|
||||
"ideas",
|
||||
"financial"
|
||||
],
|
||||
@@ -158,6 +159,18 @@
|
||||
"links": {
|
||||
"financial": "https://tr7zw.dev/donate/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"login": "Peaches_MLG",
|
||||
"name": "Peaches_MLG",
|
||||
"avatar_url": "https://www.spigotmc.org/data/avatars/l/194/194338.jpg?1561235996",
|
||||
"profile": "https://www.spigotmc.org/members/peaches_mlg100.194338/",
|
||||
"contributions": [
|
||||
"financial"
|
||||
],
|
||||
"links": {
|
||||
"financial": "https://tr7zw.dev/donate/"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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.1
|
||||
- 2.14.0
|
||||
- 2.14.1
|
||||
- 2.15.0
|
||||
@@ -51,6 +51,7 @@ tmp/
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.factorypath
|
||||
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
language: java
|
||||
addons:
|
||||
sonarcloud:
|
||||
organization: "tr7zw-github"
|
||||
script:
|
||||
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar
|
||||
@@ -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.
|
||||
@@ -4,15 +4,22 @@ Add custom NBT tags to Items/Tiles/Entities without NMS! Modify NBT and store it
|
||||
|
||||
### Build/Maven/Sonar Status
|
||||
[](https://ci.codemc.org/job/Tr7zw/job/Item-NBT-API/)[](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)
|
||||
[](https://discordapp.com/invite/yk4caxM)
|
||||
[](https://www.patreon.com/tr7zw)
|
||||
|
||||
### SpigotMC Status
|
||||
[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://bstats.org/plugin/bukkit/ItemNBTAPI)[](https://bstats.org/plugin/bukkit/ItemNBTAPI)[](#contributors-%e2%9c%a8)
|
||||
|
||||
[](https://bstats.org/plugin/bukkit/ItemNBTAPI)
|
||||
[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://bstats.org/plugin/bukkit/ItemNBTAPI)[](https://bstats.org/plugin/bukkit/ItemNBTAPI)[](#contributors-%e2%9c%a8)
|
||||
|
||||
## Getting started
|
||||
Import the API [using Maven](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Maven), 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/Set-a-skull's-skin-using-NBT-API).
|
||||
|
||||
### bStats
|
||||
|
||||
[](https://bstats.org/plugin/bukkit/ItemNBTAPI)
|
||||
|
||||
### Github Stargazers
|
||||
<img src="https://starchart.cc/tr7zw/Item-NBT-API.svg" alt="stargazers" width="800"/>
|
||||
|
||||
## Contributors ✨
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
@@ -34,8 +41,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
||||
<td align="center"><a href="https://github.com/MrDienns"><img src="https://avatars3.githubusercontent.com/u/15938901?s=460&v=4" width="100px;" alt=""/><br /><sub><b>Dennis van der Veeke</b></sub></a><br /><a href="https://tr7zw.dev/donate/" title="Financial Support">💵</a></td>
|
||||
<td align="center"><a href="https://github.com/iGabyTM"><img src="https://avatars2.githubusercontent.com/u/32105478?s=460&v=4" width="100px;" alt=""/><br /><sub><b>Gabriel Dumitru</b></sub></a><br /><a href="#discord-iGabyTM" title="Discord help">🤝</a></td>
|
||||
<td align="center"><a href="https://github.com/TauCubed"><img src="https://avatars0.githubusercontent.com/u/35522873?s=460&v=4" width="100px;" alt=""/><br /><sub><b>TauCubed</b></sub></a><br /><a href="#discord-TauCubed" title="Discord help">🤝</a></td>
|
||||
<td align="center"><a href="https://www.spigotmc.org/members/lonedev.88296"><img src="https://www.spigotmc.org/data/avatars/l/88/88296.jpg?1563463602" width="100px;" alt=""/><br /><sub><b>LoneDev</b></sub></a><br /><a href="https://www.spigotmc.org/threads/nbt-api.70503/page-7#post-3652832" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://tr7zw.dev/donate/" title="Financial Support">💵</a></td>
|
||||
<td align="center"><a href="https://www.spigotmc.org/members/lonedev.88296"><img src="https://www.spigotmc.org/data/avatars/l/88/88296.jpg?1563463602" width="100px;" alt=""/><br /><sub><b>LoneDev</b></sub></a><br /><a href="https://github.com/tr7zw/Item-NBT-API/commits?author=LoneDev" title="Code">💻</a> <a href="https://www.spigotmc.org/threads/nbt-api.70503/page-7#post-3652832" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://tr7zw.dev/donate/" title="Financial Support">💵</a></td>
|
||||
<td align="center"><a href="https://www.spigotmc.org/members/gc.25090"><img src="https://www.spigotmc.org/data/avatars/l/25/25090.jpg?1502396477" width="100px;" alt=""/><br /><sub><b>GC.</b></sub></a><br /><a href="https://tr7zw.dev/donate/" title="Financial Support">💵</a></td>
|
||||
<td align="center"><a href="https://www.spigotmc.org/members/peaches_mlg100.194338/"><img src="https://www.spigotmc.org/data/avatars/l/194/194338.jpg?1561235996" width="100px;" alt=""/><br /><sub><b>Peaches_MLG</b></sub></a><br /><a href="https://tr7zw.dev/donate/" title="Financial Support">💵</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- markdownlint-enable -->
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# (Item)-NBT-API
|
||||
Add custom NBT tags to Items/Tiles/Entities without NMS! Modify NBT and store it 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
|
||||
[](https://ci.codemc.org/job/Tr7zw/job/Item-NBT-API/)[](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)
|
||||
Discord:[](https://discordapp.com/invite/yk4caxM)
|
||||
[](https://www.patreon.com/tr7zw)
|
||||
|
||||
### SpigotMC Status
|
||||
[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[](https://bstats.org/plugin/bukkit/ItemNBTAPI)[](https://bstats.org/plugin/bukkit/ItemNBTAPI)
|
||||
|
||||
## Getting started
|
||||
Import the API [using Maven](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Maven), 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/Set-a-skull's-skin-using-NBT-API).
|
||||
|
||||
### bStats
|
||||
[](https://bstats.org/plugin/bukkit/ItemNBTAPI)
|
||||
@@ -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.
|
||||
+56
-53
@@ -1,60 +1,63 @@
|
||||
<?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>2.3.0</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>functional-annotations</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>functional-annotations</artifactId>
|
||||
<version>0.1-SNAPSHOT</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.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shade</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>de.tr7zw.annotations</pattern>
|
||||
<shadedPattern>de.tr7zw.changeme.nbtapi.utils.annotations</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<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.2.4</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>de.tr7zw.annotations</pattern>
|
||||
<shadedPattern>de.tr7zw.changeme.nbtapi.utils.annotations</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>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.tr7zw.changeme.nbtapi;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
public NBTCompound getData() {
|
||||
return nbtChunk.getPersistentDataContainer().getOrCreateCompound("blocks").getOrCreateCompound(block.getX() + "_" + block.getY() + "_" + block.getZ());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package de.tr7zw.changeme.nbtapi;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
import de.tr7zw.annotations.FAUtil;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import de.tr7zw.changeme.nbtapi.utils.annotations.AvailableSince;
|
||||
import de.tr7zw.changeme.nbtapi.utils.annotations.CheckUtil;
|
||||
|
||||
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
|
||||
*/
|
||||
@AvailableSince(version = MinecraftVersion.MC1_16_R3)
|
||||
public NBTCompound getPersistentDataContainer() {
|
||||
FAUtil.check(this::getPersistentDataContainer, CheckUtil::isAvaliable);
|
||||
return new NBTPersistentDataContainer(chunk.getPersistentDataContainer());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,13 @@ package de.tr7zw.changeme.nbtapi;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -18,6 +24,10 @@ import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
*/
|
||||
public class NBTCompound {
|
||||
|
||||
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
|
||||
private final Lock readLock = readWriteLock.readLock();
|
||||
private final Lock writeLock = readWriteLock.writeLock();
|
||||
|
||||
private String compundName;
|
||||
private NBTCompound parent;
|
||||
|
||||
@@ -26,11 +36,19 @@ public class NBTCompound {
|
||||
this.parent = owner;
|
||||
}
|
||||
|
||||
protected void saveCompound(){
|
||||
if(parent != null)
|
||||
protected Lock getReadLock() {
|
||||
return readLock;
|
||||
}
|
||||
|
||||
protected Lock getWriteLock() {
|
||||
return writeLock;
|
||||
}
|
||||
|
||||
protected void saveCompound() {
|
||||
if (parent != null)
|
||||
parent.saveCompound();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The Compound name
|
||||
*/
|
||||
@@ -63,8 +81,13 @@ public class NBTCompound {
|
||||
* @param comp
|
||||
*/
|
||||
public void mergeCompound(NBTCompound comp) {
|
||||
NBTReflectionUtil.mergeOtherNBTCompound(this, comp);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.mergeOtherNBTCompound(this, comp);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,8 +97,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setString(String key, String value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_STRING, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_STRING, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +113,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public String getString(String key) {
|
||||
return (String) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_STRING, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (String) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_STRING, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected String getContent(String key) {
|
||||
@@ -99,8 +132,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setInteger(String key, Integer value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INT, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INT, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +148,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Integer getInteger(String key) {
|
||||
return (Integer) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INT, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Integer) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INT, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,8 +163,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setDouble(String key, Double value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_DOUBLE, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_DOUBLE, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +179,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Double getDouble(String key) {
|
||||
return (Double) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_DOUBLE, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Double) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_DOUBLE, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,8 +194,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setByte(String key, Byte value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTE, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTE, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +210,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Byte getByte(String key) {
|
||||
return (Byte) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTE, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Byte) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTE, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,8 +225,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setShort(String key, Short value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_SHORT, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_SHORT, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,7 +241,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Short getShort(String key) {
|
||||
return (Short) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_SHORT, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Short) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_SHORT, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,8 +256,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setLong(String key, Long value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_LONG, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_LONG, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +272,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Long getLong(String key) {
|
||||
return (Long) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_LONG, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Long) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_LONG, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,8 +287,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setFloat(String key, Float value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_FLOAT, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_FLOAT, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,7 +303,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Float getFloat(String key) {
|
||||
return (Float) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_FLOAT, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Float) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_FLOAT, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,8 +318,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setByteArray(String key, byte[] value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTEARRAY, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BYTEARRAY, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,7 +334,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public byte[] getByteArray(String key) {
|
||||
return (byte[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTEARRAY, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (byte[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BYTEARRAY, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,8 +349,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setIntArray(String key, int[] value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INTARRAY, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_INTARRAY, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +365,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public int[] getIntArray(String key) {
|
||||
return (int[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INTARRAY, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (int[]) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_INTARRAY, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,8 +380,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setBoolean(String key, Boolean value) {
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BOOLEAN, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_BOOLEAN, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected void set(String key, Object val) {
|
||||
@@ -283,7 +401,12 @@ public class NBTCompound {
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public Boolean getBoolean(String key) {
|
||||
return (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BOOLEAN, key);
|
||||
try {
|
||||
readLock.lock();
|
||||
return (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_BOOLEAN, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,8 +416,13 @@ public class NBTCompound {
|
||||
* @param value
|
||||
*/
|
||||
public void setObject(String key, Object value) {
|
||||
NBTReflectionUtil.setObject(this, key, value);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setObject(this, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,29 +433,75 @@ public class NBTCompound {
|
||||
* @return The created Object or null if empty
|
||||
*/
|
||||
public <T> T getObject(String key, Class<T> type) {
|
||||
return NBTReflectionUtil.getObject(this, key, type);
|
||||
try {
|
||||
readLock.lock();
|
||||
return NBTReflectionUtil.getObject(this, key, type);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save an ItemStack as a compound under a given key
|
||||
*
|
||||
* @param key
|
||||
* @param item
|
||||
*/
|
||||
public void setItemStack(String key, ItemStack item){
|
||||
removeKey(key);
|
||||
addCompound(key).mergeCompound(NBTItem.convertItemtoNBT(item));
|
||||
public void setItemStack(String key, ItemStack item) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
removeKey(key);
|
||||
addCompound(key).mergeCompound(NBTItem.convertItemtoNBT(item));
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an ItemStack that was saved at the given key
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public ItemStack getItemStack(String key){
|
||||
NBTCompound comp = getCompound(key);
|
||||
return NBTItem.convertNBTtoItem(comp);
|
||||
public ItemStack getItemStack(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
NBTCompound comp = getCompound(key);
|
||||
return NBTItem.convertNBTtoItem(comp);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void setUUID(String key, UUID value) {
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.setData(this, ReflectionMethod.COMPOUND_SET_UUID, key, value);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter
|
||||
*
|
||||
* @param key
|
||||
* @return The stored value or NMS fallback
|
||||
*/
|
||||
public UUID getUUID(String key) {
|
||||
try {
|
||||
readLock.lock();
|
||||
return (UUID) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_UUID, key);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,42 +509,62 @@ public class NBTCompound {
|
||||
* @return True if the key is set
|
||||
*/
|
||||
public Boolean hasKey(String key) {
|
||||
Boolean b = (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_HAS_KEY, key);
|
||||
if (b == null)
|
||||
return false;
|
||||
return b;
|
||||
try {
|
||||
readLock.lock();
|
||||
Boolean b = (Boolean) NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_HAS_KEY, key);
|
||||
if (b == null)
|
||||
return false;
|
||||
return b;
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key Deletes the given Key
|
||||
*/
|
||||
public void removeKey(String key) {
|
||||
NBTReflectionUtil.remove(this, key);
|
||||
saveCompound();
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.remove(this, key);
|
||||
saveCompound();
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Set of all stored Keys
|
||||
*/
|
||||
public Set<String> getKeys() {
|
||||
return NBTReflectionUtil.getKeys(this);
|
||||
try {
|
||||
readLock.lock();
|
||||
return NBTReflectionUtil.getKeys(this);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a subCompound
|
||||
* Creates a subCompound, or returns it if already provided
|
||||
*
|
||||
* @param name Key to use
|
||||
* @return The subCompound Object
|
||||
*/
|
||||
public NBTCompound addCompound(String name) {
|
||||
if (getType(name) == NBTType.NBTTagCompound)
|
||||
return getCompound(name);
|
||||
NBTReflectionUtil.addNBTTagCompound(this, name);
|
||||
NBTCompound comp = getCompound(name);
|
||||
if(comp == null)
|
||||
throw new NbtApiException("Error while adding Compound, got null!");
|
||||
saveCompound();
|
||||
return comp;
|
||||
try {
|
||||
writeLock.lock();
|
||||
if (getType(name) == NBTType.NBTTagCompound)
|
||||
return getCompound(name);
|
||||
NBTReflectionUtil.addNBTTagCompound(this, name);
|
||||
NBTCompound comp = getCompound(name);
|
||||
if (comp == null)
|
||||
throw new NbtApiException("Error while adding Compound, got null!");
|
||||
saveCompound();
|
||||
return comp;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,12 +572,27 @@ public class NBTCompound {
|
||||
* @return The Compound instance or null
|
||||
*/
|
||||
public NBTCompound getCompound(String name) {
|
||||
if (getType(name) != NBTType.NBTTagCompound)
|
||||
try {
|
||||
readLock.lock();
|
||||
if (getType(name) != NBTType.NBTTagCompound)
|
||||
return null;
|
||||
NBTCompound next = new NBTCompound(this, name);
|
||||
if (NBTReflectionUtil.valideCompound(next))
|
||||
return next;
|
||||
return null;
|
||||
NBTCompound next = new NBTCompound(this, name);
|
||||
if (NBTReflectionUtil.valideCompound(next))
|
||||
return next;
|
||||
return null;
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The same as addCompound, just with a name that better reflects what it does
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public NBTCompound getOrCreateCompound(String name) {
|
||||
return addCompound(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,9 +600,14 @@ public class NBTCompound {
|
||||
* @return The retrieved String List
|
||||
*/
|
||||
public NBTList<String> getStringList(String name) {
|
||||
NBTList<String> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagString, String.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<String> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagString, String.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,39 +615,76 @@ public class NBTCompound {
|
||||
* @return The retrieved Integer List
|
||||
*/
|
||||
public NBTList<Integer> getIntegerList(String name) {
|
||||
NBTList<Integer> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagInt, Integer.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<Integer> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagInt, Integer.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return The retrieved Float List
|
||||
*/
|
||||
public NBTList<Float> getFloatList(String name) {
|
||||
NBTList<Float> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagFloat, Float.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<Float> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagFloat, Float.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return The retrieved Double List
|
||||
*/
|
||||
public NBTList<Double> getDoubleList(String name) {
|
||||
NBTList<Double> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagDouble, Double.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<Double> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagDouble, Double.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return The retrieved Long List
|
||||
*/
|
||||
public NBTList<Long> getLongList(String name) {
|
||||
NBTList<Long> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagLong, Long.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTList<Long> list = NBTReflectionUtil.getList(this, name, NBTType.NBTTagLong, Long.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the list, null if not a list
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public NBTType getListType(String name) {
|
||||
try {
|
||||
readLock.lock();
|
||||
if (getType(name) != NBTType.NBTTagList)
|
||||
return null;
|
||||
return NBTReflectionUtil.getListType(this, name);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,9 +692,15 @@ public class NBTCompound {
|
||||
* @return The retrieved Compound List
|
||||
*/
|
||||
public NBTCompoundList getCompoundList(String name) {
|
||||
NBTCompoundList list = (NBTCompoundList) NBTReflectionUtil.getList(this, name, NBTType.NBTTagCompound, NBTListCompound.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTCompoundList list = (NBTCompoundList) NBTReflectionUtil.getList(this, name, NBTType.NBTTagCompound,
|
||||
NBTListCompound.class);
|
||||
saveCompound();
|
||||
return list;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -451,25 +708,38 @@ public class NBTCompound {
|
||||
* @return The type of the given stored key or null
|
||||
*/
|
||||
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);
|
||||
try {
|
||||
readLock.lock();
|
||||
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) {
|
||||
Object nbtbase = NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET, name);
|
||||
if(nbtbase == null)
|
||||
return null;
|
||||
return NBTType.valueOf((byte)ReflectionMethod.COMPOUND_OWN_TYPE.run(nbtbase));
|
||||
}
|
||||
Object o = NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_TYPE, name);
|
||||
if (o == null)
|
||||
return null;
|
||||
return NBTType.valueOf((byte) o);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void writeCompound(OutputStream stream) {
|
||||
NBTReflectionUtil.writeApiNBT(this, stream);
|
||||
try {
|
||||
writeLock.lock();
|
||||
NBTReflectionUtil.writeApiNBT(this, stream);
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
/*StringBuilder result = new StringBuilder();
|
||||
for (String key : getKeys()) {
|
||||
result.append(toString(key));
|
||||
}
|
||||
return result.toString();*/
|
||||
/*
|
||||
* StringBuilder result = new StringBuilder(); for (String key : getKeys()) {
|
||||
* result.append(toString(key)); } return result.toString();
|
||||
*/
|
||||
return asNBTString();
|
||||
}
|
||||
|
||||
@@ -480,30 +750,31 @@ public class NBTCompound {
|
||||
*/
|
||||
@Deprecated
|
||||
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();
|
||||
}*/
|
||||
/*
|
||||
* 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(); }
|
||||
*/
|
||||
return asNBTString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Just use toString()
|
||||
* @return A json valid nbt string for this Compound
|
||||
* @return A {@link String} representation of the NBT in Mojang JSON. This is different from normal JSON!
|
||||
*/
|
||||
@Deprecated
|
||||
public String asNBTString() {
|
||||
Object comp = NBTReflectionUtil.gettoCompount(getCompound(), this);
|
||||
if (comp == null)
|
||||
return "{}";
|
||||
return comp.toString();
|
||||
try {
|
||||
readLock.lock();
|
||||
Object comp = NBTReflectionUtil.gettoCompount(getCompound(), this);
|
||||
if (comp == null)
|
||||
return "{}";
|
||||
return comp.toString();
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -512,8 +783,7 @@ public class NBTCompound {
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the nbt-string to match this compound with another object.
|
||||
* This allows two "technically" different Compounds to match, if they have the same content
|
||||
* Does a deep compare to check if everything is the same
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@@ -521,7 +791,49 @@ public class NBTCompound {
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
return toString().equals(obj.toString());
|
||||
if(obj instanceof NBTCompound) {
|
||||
NBTCompound other = (NBTCompound) obj;
|
||||
if(getKeys().equals(other.getKeys())) {
|
||||
for(String key : getKeys()) {
|
||||
if(!isEqual(this, other, key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static boolean isEqual(NBTCompound compA, NBTCompound compB, String key) {
|
||||
if(compA.getType(key) != compB.getType(key))return false;
|
||||
switch(compA.getType(key)) {
|
||||
case NBTTagByte:
|
||||
return compA.getByte(key).equals(compB.getByte(key));
|
||||
case NBTTagByteArray:
|
||||
return Arrays.equals(compA.getByteArray(key), compB.getByteArray(key));
|
||||
case NBTTagCompound:
|
||||
return compA.getCompound(key).equals(compB.getCompound(key));
|
||||
case NBTTagDouble:
|
||||
return compA.getDouble(key).equals(compB.getDouble(key));
|
||||
case NBTTagEnd:
|
||||
return true; //??
|
||||
case NBTTagFloat:
|
||||
return compA.getFloat(key).equals(compB.getFloat(key));
|
||||
case NBTTagInt:
|
||||
return compA.getInteger(key).equals(compB.getInteger(key));
|
||||
case NBTTagIntArray:
|
||||
return Arrays.equals(compA.getIntArray(key), compB.getIntArray(key));
|
||||
case NBTTagList:
|
||||
return NBTReflectionUtil.getEntry(compA, key).toString().equals(NBTReflectionUtil.getEntry(compB, key).toString()); // Just string compare the 2 lists
|
||||
case NBTTagLong:
|
||||
return compA.getLong(key).equals(compB.getLong(key));
|
||||
case NBTTagShort:
|
||||
return compA.getShort(key).equals(compB.getShort(key));
|
||||
case NBTTagString:
|
||||
return compA.getString(key).equals(compB.getString(key));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package de.tr7zw.changeme.nbtapi;
|
||||
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
|
||||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
@@ -70,7 +68,7 @@ public class NBTCompoundList extends NBTList<NBTListCompound> {
|
||||
@Override
|
||||
public void add(int index, NBTListCompound element) {
|
||||
if (element != null) {
|
||||
throw new NotImplementedException("You need to pass null! ListCompounds from other lists won't work.");
|
||||
throw new NbtApiException("You need to pass null! ListCompounds from other lists won't work.");
|
||||
}
|
||||
try {
|
||||
Object compound = ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz().newInstance();
|
||||
@@ -97,7 +95,7 @@ public class NBTCompoundList extends NBTList<NBTListCompound> {
|
||||
|
||||
@Override
|
||||
public NBTListCompound set(int index, NBTListCompound element) {
|
||||
throw new NotImplementedException("This method doesn't work in the ListCompound context.");
|
||||
throw new NbtApiException("This method doesn't work in the ListCompound context.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.bukkit.entity.Entity;
|
||||
|
||||
import de.tr7zw.annotations.FAUtil;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import de.tr7zw.changeme.nbtapi.utils.annotations.AvaliableSince;
|
||||
import de.tr7zw.changeme.nbtapi.utils.annotations.AvailableSince;
|
||||
import de.tr7zw.changeme.nbtapi.utils.annotations.CheckUtil;
|
||||
|
||||
/**
|
||||
@@ -24,8 +24,8 @@ public class NBTEntity extends NBTCompound {
|
||||
*/
|
||||
public NBTEntity(Entity entity) {
|
||||
super(null, null);
|
||||
if (entity == null || entity.isDead()) {
|
||||
throw new NullPointerException("Entity can't be null/dead!");
|
||||
if (entity == null) {
|
||||
throw new NullPointerException("Entity can't be null!");
|
||||
}
|
||||
ent = entity;
|
||||
}
|
||||
@@ -46,18 +46,10 @@ public class NBTEntity extends NBTCompound {
|
||||
*
|
||||
* @return NBTCompound containing the data of the PersistentDataAPI
|
||||
*/
|
||||
@AvaliableSince(version = MinecraftVersion.MC1_14_R1)
|
||||
@AvailableSince(version = MinecraftVersion.MC1_14_R1)
|
||||
public NBTCompound getPersistentDataContainer() {
|
||||
FAUtil.check(this::getPersistentDataContainer, CheckUtil::isAvaliable);
|
||||
if (hasKey("BukkitValues")) {
|
||||
return getCompound("BukkitValues");
|
||||
} else {
|
||||
NBTContainer container = new NBTContainer();
|
||||
container.addCompound("BukkitValues").setString("__nbtapi",
|
||||
"Marker to make the PersistentDataContainer have content");
|
||||
mergeCompound(container);
|
||||
return getCompound("BukkitValues");
|
||||
}
|
||||
return new NBTPersistentDataContainer(ent.getPersistentDataContainer());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,13 +46,18 @@ public class NBTFile extends NBTCompound {
|
||||
* @throws IOException
|
||||
*/
|
||||
public void save() throws IOException {
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
if (!file.createNewFile())
|
||||
throw new IOException("Unable to create file at " + file.getAbsolutePath());
|
||||
try {
|
||||
getWriteLock().lock();
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
if (!file.createNewFile())
|
||||
throw new IOException("Unable to create file at " + file.getAbsolutePath());
|
||||
}
|
||||
FileOutputStream outStream = new FileOutputStream(file);
|
||||
NBTReflectionUtil.writeNBT(nbt, outStream);
|
||||
} finally {
|
||||
getWriteLock().unlock();
|
||||
}
|
||||
FileOutputStream outStream = new FileOutputStream(file);
|
||||
NBTReflectionUtil.writeNBT(nbt, outStream);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.tr7zw.changeme.nbtapi;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
@@ -15,6 +16,8 @@ import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
public class NBTItem extends NBTCompound {
|
||||
|
||||
private ItemStack bukkitItem;
|
||||
private boolean directApply;
|
||||
private ItemStack originalSrcStack = null;
|
||||
|
||||
/**
|
||||
* Constructor for NBTItems. The ItemStack will be cloned!
|
||||
@@ -22,11 +25,27 @@ public class NBTItem extends NBTCompound {
|
||||
* @param item
|
||||
*/
|
||||
public NBTItem(ItemStack item) {
|
||||
this(item, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public NBTItem(ItemStack item, boolean directApply) {
|
||||
super(null, null);
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
throw new NullPointerException("ItemStack can't be null/Air!");
|
||||
}
|
||||
this.directApply = directApply;
|
||||
bukkitItem = item.clone();
|
||||
if(directApply) {
|
||||
this.originalSrcStack = item;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,6 +60,69 @@ public class NBTItem extends NBTCompound {
|
||||
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
|
||||
*/
|
||||
public void applyNBT(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
throw new NullPointerException("ItemStack can't be null/Air!");
|
||||
}
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public void mergeCustomNBT(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
throw new NullPointerException("ItemStack can't be null/Air!");
|
||||
}
|
||||
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
|
||||
*/
|
||||
public boolean hasCustomNbtData() {
|
||||
ItemMeta meta = bukkitItem.getItemMeta();
|
||||
return !NBTReflectionUtil.getUnhandledNBTTags(meta).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all custom (non-vanilla) NBT tags from the NBTItem.
|
||||
*/
|
||||
public void clearCustomNBT() {
|
||||
ItemMeta meta = bukkitItem.getItemMeta();
|
||||
NBTReflectionUtil.getUnhandledNBTTags(meta).clear();
|
||||
bukkitItem.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The modified ItemStack
|
||||
*/
|
||||
@@ -84,4 +166,11 @@ public class NBTItem extends NBTCompound {
|
||||
NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveCompound() {
|
||||
if(directApply) {
|
||||
applyNBT(originalSrcStack);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,14 +31,14 @@ public abstract class NBTList<T> implements List<T> {
|
||||
this.type = type;
|
||||
this.listObject = list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Name of this list-compound
|
||||
*/
|
||||
public String getName(){
|
||||
public String getName() {
|
||||
return listName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The Compound's parent Object
|
||||
*/
|
||||
@@ -55,6 +55,7 @@ public abstract class NBTList<T> implements List<T> {
|
||||
@Override
|
||||
public boolean add(T element) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
|
||||
ReflectionMethod.LIST_ADD.run(listObject, size(), asTag(element));
|
||||
} else {
|
||||
@@ -64,12 +65,15 @@ public abstract class NBTList<T> implements List<T> {
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, T element) {
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_14_R1.getVersionId()) {
|
||||
ReflectionMethod.LIST_ADD.run(listObject, index, asTag(element));
|
||||
} else {
|
||||
@@ -78,37 +82,48 @@ public abstract class NBTList<T> implements List<T> {
|
||||
save();
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T set(int index, T element) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public T remove(int i) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
return (int) ReflectionMethod.LIST_SIZE.run(listObject);
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException(ex);
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,89 +148,134 @@ public abstract class NBTList<T> implements List<T> {
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (o.equals(get(i)))
|
||||
return true;
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (o.equals(get(i)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (o.equals(get(i)))
|
||||
return i;
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (o.equals(get(i)))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> c) {
|
||||
int size = size();
|
||||
for (T ele : c) {
|
||||
add(ele);
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
for (T ele : c) {
|
||||
add(ele);
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
return size != size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends T> c) {
|
||||
int size = size();
|
||||
for (T ele : c) {
|
||||
add(index++, ele);
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
for (T ele : c) {
|
||||
add(index++, ele);
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
return size != size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
for (Object ele : c) {
|
||||
if (!contains(ele))
|
||||
return false;
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
for (Object ele : c) {
|
||||
if (!contains(ele))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
int index = -1;
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (o.equals(get(i)))
|
||||
index = i;
|
||||
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();
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
int size = size();
|
||||
for (Object obj : c) {
|
||||
remove(obj);
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
for (Object obj : c) {
|
||||
remove(obj);
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
return size != size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
int size = size();
|
||||
for (Object obj : c) {
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (!obj.equals(get(i))) {
|
||||
remove(i--);
|
||||
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();
|
||||
}
|
||||
return size != size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int size = size();
|
||||
int id = -1;
|
||||
while ((id = indexOf(o)) != -1) {
|
||||
remove(id);
|
||||
try {
|
||||
parent.getWriteLock().lock();
|
||||
int size = size();
|
||||
int id = -1;
|
||||
while ((id = indexOf(o)) != -1) {
|
||||
remove(id);
|
||||
}
|
||||
return size != size();
|
||||
} finally {
|
||||
parent.getWriteLock().unlock();
|
||||
}
|
||||
return size != size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,6 +295,12 @@ public abstract class NBTList<T> implements List<T> {
|
||||
throw new NoSuchElementException();
|
||||
return get(++index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
NBTList.this.remove(index);
|
||||
index--;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -292,6 +358,7 @@ public abstract class NBTList<T> implements List<T> {
|
||||
@Override
|
||||
public void remove() {
|
||||
list.remove(index);
|
||||
index--;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -303,41 +370,60 @@ public abstract class NBTList<T> implements List<T> {
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
Object[] ar = new Object[size()];
|
||||
for (int i = 0; i < size(); i++)
|
||||
ar[i] = get(i);
|
||||
return ar;
|
||||
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) {
|
||||
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.");
|
||||
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();
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> subList(int fromIndex, int toIndex) {
|
||||
ArrayList<T> list = new ArrayList<>();
|
||||
for (int i = fromIndex; i < toIndex; i++)
|
||||
list.add(get(i));
|
||||
return list;
|
||||
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 String toString() {
|
||||
return listObject.toString();
|
||||
try {
|
||||
parent.getReadLock().lock();
|
||||
return listObject.toString();
|
||||
} finally {
|
||||
parent.getReadLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
|
||||
protected NBTPersistentDataContainer(PersistentDataContainer container) {
|
||||
super(null, null);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,12 +3,15 @@ package de.tr7zw.changeme.nbtapi;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.utils.GsonWrapper;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
@@ -25,6 +28,17 @@ import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
*/
|
||||
public class NBTReflectionUtil {
|
||||
|
||||
private static Field field_unhandledTags = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
field_unhandledTags = ClassWrapper.CRAFT_METAITEM.getClazz().getDeclaredField("unhandledTags");
|
||||
field_unhandledTags.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hidden constructor
|
||||
*/
|
||||
@@ -146,6 +160,21 @@ public class NBTReflectionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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")
|
||||
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
|
||||
*
|
||||
@@ -188,14 +217,26 @@ public class NBTReflectionUtil {
|
||||
*/
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
Object answer = null;
|
||||
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);
|
||||
@@ -210,11 +251,23 @@ public class NBTReflectionUtil {
|
||||
*/
|
||||
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);
|
||||
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_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);
|
||||
}
|
||||
@@ -254,8 +307,9 @@ public class NBTReflectionUtil {
|
||||
if (nbttag == null) {
|
||||
nbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
|
||||
}
|
||||
if (!valideCompound(comp))
|
||||
if (!valideCompound(comp)) {
|
||||
return;
|
||||
}
|
||||
Object workingtag = gettoCompount(nbttag, comp);
|
||||
try {
|
||||
ReflectionMethod.COMPOUND_SET.run(workingtag, name,
|
||||
@@ -414,6 +468,44 @@ public class NBTReflectionUtil {
|
||||
throw new NbtApiException("Exception while getting a list with the type '" + type + "'!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static NBTType getListType(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);
|
||||
try {
|
||||
Object nbt = ReflectionMethod.COMPOUND_GET.run(workingtag, key);
|
||||
String fieldname = "type";
|
||||
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_17_R1)) {
|
||||
fieldname = "w";
|
||||
}
|
||||
Field f = nbt.getClass().getDeclaredField(fieldname);
|
||||
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 rootnbttag = comp.getCompound();
|
||||
if (rootnbttag == null) {
|
||||
rootnbttag = ObjectCreator.NMS_NBTTAGCOMPOUND.getInstance();
|
||||
}
|
||||
if (!valideCompound(comp))
|
||||
return null;
|
||||
Object workingtag = gettoCompount(rootnbttag, comp);
|
||||
try {
|
||||
Object nbt = ReflectionMethod.COMPOUND_GET.run(workingtag, key);
|
||||
return nbt;
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException("Exception while getting an Entry!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses Gson to set a {@link Serializable} value in a Compound
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.bukkit.block.BlockState;
|
||||
|
||||
import de.tr7zw.annotations.FAUtil;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import de.tr7zw.changeme.nbtapi.utils.annotations.AvaliableSince;
|
||||
import de.tr7zw.changeme.nbtapi.utils.annotations.AvailableSince;
|
||||
import de.tr7zw.changeme.nbtapi.utils.annotations.CheckUtil;
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,7 @@ public class NBTTileEntity extends NBTCompound {
|
||||
*/
|
||||
public NBTTileEntity(BlockState tile) {
|
||||
super(null, null);
|
||||
if (tile == null || !tile.isPlaced()) {
|
||||
if (tile == null || (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3) && !tile.isPlaced())) {
|
||||
throw new NullPointerException("Tile can't be null/not placed!");
|
||||
}
|
||||
this.tile = tile;
|
||||
@@ -47,7 +47,7 @@ public class NBTTileEntity extends NBTCompound {
|
||||
*
|
||||
* @return NBTCompound containing the data of the PersistentDataAPI
|
||||
*/
|
||||
@AvaliableSince(version = MinecraftVersion.MC1_14_R1)
|
||||
@AvailableSince(version = MinecraftVersion.MC1_14_R1)
|
||||
public NBTCompound getPersistentDataContainer() {
|
||||
FAUtil.check(this::getPersistentDataContainer, CheckUtil::isAvaliable);
|
||||
if (hasKey("PublicBukkitValues")) {
|
||||
|
||||
@@ -22,7 +22,8 @@ import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.logger;
|
||||
|
||||
import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.getLogger;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
@@ -135,7 +136,7 @@ public class ApiMetricsLite {
|
||||
if(Bukkit.isPrimaryThread()){
|
||||
Bukkit.getServicesManager().register(ApiMetricsLite.class, this, plugin, ServicePriority.Normal);
|
||||
if (!fFound) {
|
||||
logger.info("[NBTAPI] Using the plugin '" + plugin.getName() + "' to create a bStats instance!");
|
||||
getLogger().info("[NBTAPI] Using the plugin '" + plugin.getName() + "' to create a bStats instance!");
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
@@ -143,7 +144,7 @@ public class ApiMetricsLite {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Bukkit.getServicesManager().register(ApiMetricsLite.class, this, plugin, ServicePriority.Normal);
|
||||
if (!fFound) {
|
||||
logger.info("[NBTAPI] Using the plugin '" + plugin.getName() + "' to create a bStats instance!");
|
||||
getLogger().info("[NBTAPI] Using the plugin '" + plugin.getName() + "' to create a bStats instance!");
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
@@ -276,7 +277,7 @@ public class ApiMetricsLite {
|
||||
} catch (ClassNotFoundException e) {
|
||||
// minecraft version 1.14+
|
||||
if (logFailedRequests) {
|
||||
logger.log(Level.WARNING, "[NBTAPI][BSTATS] Encountered exception while posting request!", e);
|
||||
getLogger().log(Level.WARNING, "[NBTAPI][BSTATS] Encountered exception while posting request!", e);
|
||||
// Not using the plugins logger since the plugin isn't the plugin containing the NBT-Api most of the time
|
||||
//this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception ", e);
|
||||
}
|
||||
@@ -301,7 +302,7 @@ public class ApiMetricsLite {
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
logger.log(Level.WARNING, "[NBTAPI][BSTATS] Could not submit plugin stats of " + plugin.getName(), e);
|
||||
getLogger().log(Level.WARNING, "[NBTAPI][BSTATS] Could not submit plugin stats of " + plugin.getName(), e);
|
||||
// Not using the plugins logger since the plugin isn't the plugin containing the NBT-Api most of the time
|
||||
//plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
@@ -360,7 +361,7 @@ public class ApiMetricsLite {
|
||||
}
|
||||
bufferedReader.close();
|
||||
if (logResponseStatusText) {
|
||||
logger.info("[NBTAPI][BSTATS] Sent data to bStats and received response: " + builder.toString());
|
||||
getLogger().info("[NBTAPI][BSTATS] Sent data to bStats and received response: " + builder.toString());
|
||||
// Not using the plugins logger since the plugin isn't the plugin containing the NBT-Api most of the time
|
||||
//plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
|
||||
}
|
||||
|
||||
@@ -16,17 +16,8 @@ import org.bukkit.Bukkit;
|
||||
@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_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);
|
||||
|
||||
private static MinecraftVersion version;
|
||||
private static Boolean hasGsonSupport;
|
||||
@@ -36,15 +27,21 @@ public enum MinecraftVersion {
|
||||
/**
|
||||
* Logger used by the api
|
||||
*/
|
||||
public static final Logger logger = Logger.getLogger("NBTAPI");
|
||||
|
||||
private static Logger logger = Logger.getLogger("NBTAPI");
|
||||
|
||||
// NBT-API Version
|
||||
protected static final String VERSION = "2.3.0";
|
||||
protected static final String VERSION = "2.9.0";
|
||||
|
||||
private final int versionId;
|
||||
private final boolean mojangMapping;
|
||||
|
||||
MinecraftVersion(int versionId) {
|
||||
MinecraftVersion(int versionId) {
|
||||
this(versionId, false);
|
||||
}
|
||||
|
||||
MinecraftVersion(int versionId, boolean mojangMapping) {
|
||||
this.versionId = versionId;
|
||||
this.mojangMapping = mojangMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,6 +51,40 @@ public enum MinecraftVersion {
|
||||
return versionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if method names are in Mojang format and need to be remapped internally
|
||||
*/
|
||||
public boolean isMojangMapping() {
|
||||
return mojangMapping;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
if(this == UNKNOWN) {
|
||||
return values()[values().length-1].name().replace("MC", "v");
|
||||
}
|
||||
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.
|
||||
@@ -74,7 +105,7 @@ public enum MinecraftVersion {
|
||||
if (version != UNKNOWN) {
|
||||
logger.info("[NBTAPI] NMS support '" + version.name() + "' loaded!");
|
||||
} else {
|
||||
logger.warning("[NBTAPI] Wasn't able to find NMS Support! Some functions may not work!");
|
||||
logger.warning("[NBTAPI] This Server-Version(" + ver + ") is not supported by this NBT-API Version(" + VERSION + ") located at " + MinecraftVersion.class.getName() + ". The NBT-API will try to work as good as it can! Some functions may not work!");
|
||||
}
|
||||
init();
|
||||
return version;
|
||||
@@ -82,17 +113,20 @@ public enum MinecraftVersion {
|
||||
|
||||
private static void init() {
|
||||
try {
|
||||
if (!bStatsDisabled)
|
||||
if (hasGsonSupport() && !bStatsDisabled)
|
||||
new ApiMetricsLite();
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.WARNING, "[NBTAPI] Error enabeling Metrics!", ex);
|
||||
}
|
||||
try {
|
||||
if(!updateCheckDisabled)
|
||||
VersionChecker.checkForUpdates();
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.WARNING, "[NBTAPI] Error while checking for updates!", 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!", ex);
|
||||
}
|
||||
}).start();
|
||||
// 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',
|
||||
@@ -137,10 +171,10 @@ public enum MinecraftVersion {
|
||||
public static void disableBStats() {
|
||||
bStatsDisabled = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disables the update check. Uses Spiget to get the current version and
|
||||
* prints a warning when outdated.
|
||||
* Disables the update check. Uses Spiget to get the current version and prints
|
||||
* a warning when outdated.
|
||||
*/
|
||||
public static void disableUpdateCheck() {
|
||||
updateCheckDisabled = true;
|
||||
@@ -155,5 +189,22 @@ public enum MinecraftVersion {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ 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);
|
||||
@@ -42,24 +43,25 @@ public class VersionChecker {
|
||||
JsonObject latest = (JsonObject) updates.get(updates.size() - 1);
|
||||
int versionDifference = getVersionDifference(latest.get("name").getAsString());
|
||||
if (versionDifference == -1) { // Outdated
|
||||
MinecraftVersion.logger.log(Level.WARNING,
|
||||
"[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage() + "' seems to be outdated!");
|
||||
MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
|
||||
MinecraftVersion.getLogger().log(Level.WARNING,
|
||||
"[NBTAPI] The NBT-API located at '" + NBTItem.class.getPackage() + "' seems to be outdated!");
|
||||
MinecraftVersion.getLogger().log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
|
||||
+ "' Newest Version: " + latest.get("name").getAsString() + "'");
|
||||
MinecraftVersion.logger.log(Level.WARNING,
|
||||
"[NBTAPI] Please update the nbt-api or the plugin that contains the api!");
|
||||
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) {
|
||||
MinecraftVersion.logger.log(Level.INFO, "[NBTAPI] The NBT-API seems to be up-to-date!");
|
||||
if(!hideOk)
|
||||
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] The NBT-API seems to be up-to-date!");
|
||||
} else if (versionDifference == 1) {
|
||||
MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage()
|
||||
+ "' seems to be a future Version, not yet released on Spigot!");
|
||||
MinecraftVersion.logger.log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
|
||||
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage()
|
||||
+ "' 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.logger.log(Level.WARNING,
|
||||
MinecraftVersion.getLogger().log(Level.WARNING,
|
||||
"[NBTAPI] Error when looking for Updates! Got non Json Array: '" + element.toString() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({ METHOD })
|
||||
public @interface AvaliableSince {
|
||||
public @interface AvailableSince {
|
||||
|
||||
MinecraftVersion version();
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
public class CheckUtil {
|
||||
|
||||
public static boolean isAvaliable(Method method) {
|
||||
if(MinecraftVersion.getVersion().getVersionId() < method.getAnnotation(AvaliableSince.class).version().getVersionId())
|
||||
throw new NbtApiException("The Method '" + method.getName() + "' is only avaliable for the Versions " + method.getAnnotation(AvaliableSince.class).version() + "+, but still got called!");
|
||||
if(MinecraftVersion.getVersion().getVersionId() < method.getAnnotation(AvailableSince.class).version().getVersionId())
|
||||
throw new NbtApiException("The Method '" + method.getName() + "' is only avaliable for the Versions " + method.getAnnotation(AvailableSince.class).version() + "+, but still got called!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+73
-52
@@ -1,10 +1,10 @@
|
||||
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;
|
||||
import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.logger;
|
||||
|
||||
/**
|
||||
* Wraps NMS and CRAFT classes
|
||||
@@ -14,69 +14,90 @@ import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.logger;
|
||||
*/
|
||||
@SuppressWarnings("javadoc")
|
||||
public enum ClassWrapper {
|
||||
CRAFT_ITEMSTACK(PackageWrapper.CRAFTBUKKIT, "inventory.CraftItemStack"),
|
||||
CRAFT_ENTITY(PackageWrapper.CRAFTBUKKIT, "entity.CraftEntity"),
|
||||
CRAFT_WORLD(PackageWrapper.CRAFTBUKKIT, "CraftWorld"),
|
||||
NMS_NBTBASE(PackageWrapper.NMS, "NBTBase"),
|
||||
NMS_NBTTAGSTRING(PackageWrapper.NMS, "NBTTagString"),
|
||||
NMS_NBTTAGINT(PackageWrapper.NMS, "NBTTagInt"),
|
||||
NMS_NBTTAGFLOAT(PackageWrapper.NMS, "NBTTagFloat"),
|
||||
NMS_NBTTAGDOUBLE(PackageWrapper.NMS, "NBTTagDouble"),
|
||||
NMS_NBTTAGLONG(PackageWrapper.NMS, "NBTTagLong"),
|
||||
NMS_ITEMSTACK(PackageWrapper.NMS, "ItemStack"),
|
||||
NMS_NBTTAGCOMPOUND(PackageWrapper.NMS, "NBTTagCompound"),
|
||||
NMS_NBTTAGLIST(PackageWrapper.NMS, "NBTTagList"),
|
||||
NMS_NBTCOMPRESSEDSTREAMTOOLS(PackageWrapper.NMS, "NBTCompressedStreamTools"),
|
||||
NMS_MOJANGSONPARSER(PackageWrapper.NMS, "MojangsonParser"),
|
||||
NMS_TILEENTITY(PackageWrapper.NMS, "TileEntity"),
|
||||
NMS_BLOCKPOSITION(PackageWrapper.NMS, "BlockPosition"),
|
||||
NMS_WORLDSERVER(PackageWrapper.NMS, "WorldServer"),
|
||||
NMS_MINECRAFTSERVER(PackageWrapper.NMS, "MinecraftServer"),
|
||||
NMS_WORLD(PackageWrapper.NMS, "World"),
|
||||
NMS_ENTITY(PackageWrapper.NMS, "Entity"),
|
||||
NMS_ENTITYTYPES(PackageWrapper.NMS, "EntityTypes"),
|
||||
NMS_REGISTRYSIMPLE(PackageWrapper.NMS, "RegistrySimple", MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_12_R1),
|
||||
NMS_REGISTRYMATERIALS(PackageWrapper.NMS, "RegistryMaterials"),
|
||||
NMS_IREGISTRY(PackageWrapper.NMS, "IRegistry"),
|
||||
NMS_MINECRAFTKEY(PackageWrapper.NMS, "MinecraftKey"),
|
||||
NMS_GAMEPROFILESERIALIZER(PackageWrapper.NMS, "GameProfileSerializer")
|
||||
;
|
||||
|
||||
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_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_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_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"),
|
||||
GAMEPROFILE(PackageWrapper.NONE, "com.mojang.authlib.GameProfile", MinecraftVersion.MC1_8_R3, null);
|
||||
|
||||
private Class<?> clazz;
|
||||
private boolean enabled = false;
|
||||
|
||||
ClassWrapper(PackageWrapper packageId, String suffix){
|
||||
this(packageId, suffix, null, null);
|
||||
private final String mojangName;
|
||||
|
||||
ClassWrapper(PackageWrapper packageId, String clazzName, MinecraftVersion from, MinecraftVersion to) {
|
||||
this(packageId, clazzName, from, to, null, null);
|
||||
}
|
||||
|
||||
ClassWrapper(PackageWrapper packageId, String suffix, MinecraftVersion from, MinecraftVersion to){
|
||||
if(from != null && MinecraftVersion.getVersion().getVersionId() < from.getVersionId()) {
|
||||
return;
|
||||
}
|
||||
if(to != null && MinecraftVersion.getVersion().getVersionId() > to.getVersionId()) {
|
||||
return;
|
||||
}
|
||||
enabled = true;
|
||||
try{
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
clazz = Class.forName(packageId.getUri() + "." + version + "." + suffix);
|
||||
}catch(Exception ex){
|
||||
logger.log(Level.WARNING, "[NBTAPI] Error while trying to resolve the class '" + suffix + "'!", ex);
|
||||
|
||||
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_17_R1) && mojangMap != null) {
|
||||
clazz = Class.forName(mojangMap + "." + clazzName);
|
||||
} else if (packageId == PackageWrapper.NONE) {
|
||||
clazz = Class.forName(clazzName);
|
||||
} else {
|
||||
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(){
|
||||
public Class<?> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Is this class available in this Version
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Package+Class name used by Mojang
|
||||
*/
|
||||
public String getMojangName() {
|
||||
return mojangName;
|
||||
}
|
||||
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Temporary solution to hold Mojang to unmapped Spigot mappings.
|
||||
*
|
||||
* @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#put(java.lang.String,net.minecraft.nbt.Tag)", "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#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#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_");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static Map<String, String> getMapping(){
|
||||
return MC1_18R1;
|
||||
}
|
||||
|
||||
}
|
||||
+36
-35
@@ -6,7 +6,7 @@ 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.logger;
|
||||
import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.getLogger;
|
||||
|
||||
/**
|
||||
* This Enum wraps Constructors for NMS classes
|
||||
@@ -16,40 +16,41 @@ import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.logger;
|
||||
*/
|
||||
@SuppressWarnings("javadoc")
|
||||
public enum ObjectCreator {
|
||||
NMS_NBTTAGCOMPOUND(null, null, ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
|
||||
NMS_BLOCKPOSITION(null, null, ClassWrapper.NMS_BLOCKPOSITION.getClazz(), int.class, int.class, int.class),
|
||||
NMS_COMPOUNDFROMITEM(MinecraftVersion.MC1_11_R1, null, ClassWrapper.NMS_ITEMSTACK.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
|
||||
;
|
||||
NMS_NBTTAGCOMPOUND(null, null, ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),
|
||||
NMS_BLOCKPOSITION(null, null, ClassWrapper.NMS_BLOCKPOSITION.getClazz(), int.class, int.class, int.class),
|
||||
NMS_COMPOUNDFROMITEM(MinecraftVersion.MC1_11_R1, null, ClassWrapper.NMS_ITEMSTACK.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()),;
|
||||
|
||||
private Constructor<?> construct;
|
||||
private Class<?> targetClass;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
ObjectCreator(MinecraftVersion from, MinecraftVersion to, Class<?> clazz, Class<?>... args){
|
||||
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){
|
||||
logger.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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+3
-2
@@ -8,8 +8,9 @@ package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
|
||||
*/
|
||||
@SuppressWarnings("javadoc")
|
||||
public enum PackageWrapper {
|
||||
NMS("net.minecraft.server"),
|
||||
CRAFTBUKKIT("org.bukkit.craftbukkit"),
|
||||
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;
|
||||
|
||||
+123
-85
@@ -3,11 +3,11 @@ 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 org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NbtApiException;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
|
||||
@@ -20,90 +20,103 @@ import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
@SuppressWarnings("javadoc")
|
||||
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_MERGE(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_SET(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, ClassWrapper.NMS_NBTBASE.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "set")),
|
||||
COMPOUND_GET(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "get")),
|
||||
COMPOUND_GET_LIST(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getList")),
|
||||
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_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, 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, "put(java.lang.String,net.minecraft.nbt.Tag)")),
|
||||
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(ClassWrapper.NMS_NBTTAGCOMPOUND, new Class[]{String.class, int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getList"), new Since(MinecraftVersion.MC1_18_R1, "getList(java.lang.String,int)")),
|
||||
COMPOUND_OWN_TYPE(ClassWrapper.NMS_NBTBASE, new Class[]{}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTypeId")), // Only needed for 1.7.10 getType
|
||||
|
||||
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_GET_COMPOUND(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getCompound")),
|
||||
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_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, 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.getClazz(), new Class[] {}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTag")),
|
||||
NMSITEM_SAVE(ClassWrapper.NMS_ITEMSTACK.getClazz(), new Class[] {ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "save")),
|
||||
NMSITEM_CREATESTACK(ClassWrapper.NMS_ITEMSTACK.getClazz(), new Class[] {ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_10_R1, new Since(MinecraftVersion.MC1_7_R4, "createStack")),
|
||||
NMSITEM_GETTAG(ClassWrapper.NMS_ITEMSTACK, new Class[] {}, MinecraftVersion.MC1_7_R4, 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, 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.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"), new Since(MinecraftVersion.MC1_15_R1, "e")), //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")),
|
||||
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, 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()")),
|
||||
|
||||
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_COMPOUND(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "get")),
|
||||
LIST_GET(ClassWrapper.NMS_NBTTAGLIST.getClazz(), new Class[]{int.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "g"), new Since(MinecraftVersion.MC1_9_R1, "h"), new Since(MinecraftVersion.MC1_12_R1, "i"), new Since(MinecraftVersion.MC1_13_R1, "get")),
|
||||
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()")), // FIXME ?!?
|
||||
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.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")),
|
||||
ITEMSTACK_SET_TAG(ClassWrapper.NMS_ITEMSTACK, new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, 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, "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_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTileEntity")),
|
||||
NMS_WORLD_SET_TILEENTITY(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz(), ClassWrapper.NMS_TILEENTITY.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "setTileEntity")),
|
||||
NMS_WORLD_REMOVE_TILEENTITY(ClassWrapper.NMS_WORLDSERVER.getClazz(), new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "t"), new Since(MinecraftVersion.MC1_9_R1, "s"), new Since(MinecraftVersion.MC1_13_R1, "n"), new Since(MinecraftVersion.MC1_14_R1, "removeTileEntity")),
|
||||
|
||||
TILEENTITY_LOAD_LEGACY191(ClassWrapper.NMS_TILEENTITY.getClazz(), 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")), //FIXME: No Spigot mapping!
|
||||
TILEENTITY_LOAD_LEGACY183(ClassWrapper.NMS_TILEENTITY.getClazz(), 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")), //FIXME: No Spigot mapping!
|
||||
TILEENTITY_LOAD_LEGACY1121(ClassWrapper.NMS_TILEENTITY.getClazz(), 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(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_12_R1, "create")),
|
||||
|
||||
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_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_SET_TILEENTITY(ClassWrapper.NMS_WORLDSERVER, new Class[]{ClassWrapper.NMS_BLOCKPOSITION.getClazz(), ClassWrapper.NMS_TILEENTITY.getClazz()}, MinecraftVersion.MC1_8_R3, MinecraftVersion.MC1_16_R3, new Since(MinecraftVersion.MC1_8_R3, "setTileEntity")),
|
||||
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")),
|
||||
|
||||
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")),
|
||||
NMS_ENTITY_GETSAVEID(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{}, MinecraftVersion.MC1_14_R1,new Since(MinecraftVersion.MC1_14_R1, "getSaveID")),
|
||||
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")),
|
||||
|
||||
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")),
|
||||
REGISTRY_KEYSET (ClassWrapper.NMS_REGISTRYSIMPLE.getClazz(), new Class[]{}, MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "keySet")),
|
||||
REGISTRY_GET (ClassWrapper.NMS_REGISTRYSIMPLE.getClazz(), new Class[]{Object.class}, MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "get")),
|
||||
REGISTRY_SET (ClassWrapper.NMS_REGISTRYSIMPLE.getClazz(), new Class[]{Object.class, Object.class}, MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "a")), //FIXME: No Spigot mapping!
|
||||
REGISTRY_GET_INVERSE (ClassWrapper.NMS_REGISTRYMATERIALS.getClazz(), new Class[]{Object.class}, MinecraftVersion.MC1_11_R1, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_11_R1, "b")), //FIXME: No Spigot mapping!
|
||||
REGISTRYMATERIALS_KEYSET (ClassWrapper.NMS_REGISTRYMATERIALS.getClazz(), new Class[]{}, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_13_R1, "keySet")),
|
||||
REGISTRYMATERIALS_GET (ClassWrapper.NMS_REGISTRYMATERIALS.getClazz(), new Class[]{ClassWrapper.NMS_MINECRAFTKEY.getClazz()}, MinecraftVersion.MC1_13_R1, new Since(MinecraftVersion.MC1_13_R1, "get")),
|
||||
REGISTRYMATERIALS_GETKEY (ClassWrapper.NMS_REGISTRYMATERIALS.getClazz(), new Class[]{Object.class}, MinecraftVersion.MC1_13_R2, new Since(MinecraftVersion.MC1_13_R2, "getKey")),
|
||||
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")), //FIXME: No Spigot mapping!
|
||||
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")), //FIXME: No Spigot mapping!
|
||||
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, 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, 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()")),
|
||||
|
||||
GAMEPROFILE_DESERIALIZE (ClassWrapper.NMS_GAMEPROFILESERIALIZER.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "deserialize")),
|
||||
GAMEPROFILE_SERIALIZE (ClassWrapper.NMS_GAMEPROFILESERIALIZER.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), GameProfile.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "serialize")),
|
||||
;
|
||||
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, 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, 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, new Since(MinecraftVersion.MC1_7_R4, "a"), new Since(MinecraftVersion.MC1_18_R1, "readCompressed(java.io.InputStream)")),
|
||||
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)")),
|
||||
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")), //FIXME: No Spigot mapping!
|
||||
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")), //FIXME: No Spigot mapping!
|
||||
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, 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, 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")),
|
||||
;
|
||||
|
||||
private MinecraftVersion removedAfter;
|
||||
private Since targetVersion;
|
||||
@@ -111,29 +124,43 @@ public enum ReflectionMethod {
|
||||
private boolean loaded = false;
|
||||
private boolean compatible = false;
|
||||
private String methodName = null;
|
||||
private ClassWrapper parentClassWrapper;
|
||||
|
||||
ReflectionMethod(Class<?> targetClass, Class<?>[] args, MinecraftVersion addedSince, MinecraftVersion removedAfter, Since... methodnames){
|
||||
ReflectionMethod(ClassWrapper 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;
|
||||
this.parentClassWrapper = targetClass;
|
||||
if(!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{
|
||||
method = targetClass.getMethod(targetVersion.name, args);
|
||||
if(targetVersion.version.isMojangMapping())
|
||||
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){
|
||||
System.out.println("[NBTAPI] Unable to find the method '" + targetVersion.name + "' in '" + targetClass.getSimpleName() + "' Enum: " + this); //NOSONAR This gets loaded before the logger is loaded
|
||||
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){
|
||||
System.out.println("[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(Class<?> targetClass, Class<?>[] args, MinecraftVersion addedSince, Since... methodnames){
|
||||
ReflectionMethod(ClassWrapper targetClass, Class<?>[] args, MinecraftVersion addedSince, Since... methodnames){
|
||||
this(targetClass, args, addedSince, null, methodnames);
|
||||
}
|
||||
|
||||
@@ -150,7 +177,7 @@ public enum ReflectionMethod {
|
||||
try{
|
||||
return method.invoke(target, args);
|
||||
}catch(Exception ex){
|
||||
throw new NbtApiException("Error while calling the method '" + methodName + "', loaded: " + loaded + ", Enum: " + this, ex);
|
||||
throw new NbtApiException("Error while calling the method '" + methodName + "', loaded: " + loaded + ", Enum: " + this + " Passed Class: " + target.getClass(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,8 +201,19 @@ public enum ReflectionMethod {
|
||||
public boolean isCompatible() {
|
||||
return compatible;
|
||||
}
|
||||
|
||||
public Since getSelectedVersionInfo() {
|
||||
return targetVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Get Wrapper of the parent class
|
||||
*/
|
||||
public ClassWrapper getParentClassWrapper() {
|
||||
return parentClassWrapper;
|
||||
}
|
||||
|
||||
protected static class Since{
|
||||
public static class Since{
|
||||
public final MinecraftVersion version;
|
||||
public final String name;
|
||||
public Since(MinecraftVersion version, String name) {
|
||||
|
||||
@@ -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.
|
||||
+47
-24
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.9.0</version>
|
||||
</parent>
|
||||
<artifactId>item-nbt-api-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -12,19 +12,19 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>nbt-injector</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>nbt-data-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -39,31 +39,62 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shade</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<version>3.2.4</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<createDependencyReducedPom>true</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>de.tr7zw.changeme.nbtapi</pattern>
|
||||
<shadedPattern>de.tr7zw.nbtapi</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>javassist</pattern>
|
||||
<shadedPattern>de.tr7zw.nbtinjector.javassist</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>de.tr7zw.annotations</pattern>
|
||||
<shadedPattern>de.tr7zw.nbtapi.utils.annotations</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.1-SNAPSHOT</version>
|
||||
<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>
|
||||
@@ -78,14 +109,6 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<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 -->
|
||||
<versions>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.15.2</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>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -10,13 +10,17 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
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.EqualsTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.compounds.ForEachTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.compounds.GetterSetterTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.compounds.IteratorTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.compounds.ListTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.compounds.MergeTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.compounds.RemovingKeys;
|
||||
@@ -30,10 +34,13 @@ import de.tr7zw.nbtapi.plugin.tests.injector.EntityCustomNbtInjectorTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.injector.MergeTileSubCompoundTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.injector.SpawnEntityCustomNbtInjectorTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.injector.TilesCustomNBTInjectorTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.items.DirectApplyTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.items.EmptyItemTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.items.ItemConvertionTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.tiles.TileTest;
|
||||
import de.tr7zw.nbtapi.plugin.tests.tiles.TilesCustomNBTPersistentTest;
|
||||
import de.tr7zw.nbtinjector.NBTInjector;
|
||||
import de.tr7zw.nbtapi.plugin.tests.items.ItemMergingTest;
|
||||
|
||||
public class NBTAPI extends JavaPlugin {
|
||||
|
||||
@@ -49,38 +56,73 @@ public class NBTAPI extends JavaPlugin {
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
||||
//Disabled by default since 2.1. Enable it yourself by calling NBTInjector.inject(); during onLoad.
|
||||
/*getLogger().info("Injecting custom NBT");
|
||||
try {
|
||||
NBTInjector.inject();
|
||||
getLogger().info("Injected!");
|
||||
} catch (Throwable ex) { // NOSONAR
|
||||
getLogger().log(Level.SEVERE, "Error while Injecting custom Tile/Entity classes!", ex);
|
||||
compatible = false;
|
||||
}*/
|
||||
getConfig().options().copyDefaults(true);
|
||||
getConfig().addDefault("nbtInjector.enabled", false);
|
||||
getConfig().addDefault("bStats.enabled", true);
|
||||
getConfig().addDefault("updateCheck.enabled", true);
|
||||
getConfig().addDefault("silentstart", 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();
|
||||
}
|
||||
|
||||
//Disabled by default since 2.1. Enable it yourself by calling NBTInjector.inject(); during onLoad/config
|
||||
if(getConfig().getBoolean("nbtInjector.enabled")) {
|
||||
getLogger().info("Injecting custom NBT");
|
||||
try {
|
||||
NBTInjector.inject();
|
||||
getLogger().info("Injected!");
|
||||
} catch (Throwable ex) { // NOSONAR
|
||||
getLogger().log(Level.SEVERE, "Error while Injecting custom Tile/Entity classes!", ex);
|
||||
compatible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// NBTCompounds
|
||||
apiTests.add(new GetterSetterTest());
|
||||
apiTests.add(new TypeTest());
|
||||
apiTests.add(new RemovingKeys());
|
||||
apiTests.add(new ListTest());
|
||||
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 MergeTest());
|
||||
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());
|
||||
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) // 1.7.10 list support is not complete at all
|
||||
apiTests.add(new IteratorTest());
|
||||
|
||||
// Items
|
||||
apiTests.add(new ItemConvertionTest());
|
||||
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) // 1.7.10 not a thing
|
||||
apiTests.add(new ItemConvertionTest());
|
||||
apiTests.add(new EmptyItemTest());
|
||||
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) { // 1.7.10 not a thing
|
||||
apiTests.add(new ItemMergingTest());
|
||||
apiTests.add(new DirectApplyTest());
|
||||
}
|
||||
|
||||
// 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());
|
||||
|
||||
@@ -93,7 +135,8 @@ public class NBTAPI extends JavaPlugin {
|
||||
apiTests.add(new EntityCustomNbtInjectorTest());
|
||||
apiTests.add(new SpawnEntityCustomNbtInjectorTest());
|
||||
|
||||
apiTests.add(new GameprofileTest());
|
||||
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3))
|
||||
apiTests.add(new GameprofileTest());
|
||||
|
||||
}
|
||||
|
||||
@@ -101,36 +144,43 @@ public class NBTAPI extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
instance = this; // NOSONAR
|
||||
// new MetricsLite(this); The metrics moved into the API
|
||||
|
||||
if(getConfig().getBoolean("nbtInjector.enabled")) {
|
||||
// we are silent, won't check anything or pre-init
|
||||
VersionChecker.hideOk = true;
|
||||
return;
|
||||
}
|
||||
getLogger().info("Adding listeners...");
|
||||
Bukkit.getPluginManager().registerEvents(new ReloadListener(), this);
|
||||
getLogger().info("Checking bindings...");
|
||||
MinecraftVersion.getVersion();
|
||||
getLogger().info("Gson:");
|
||||
MinecraftVersion.hasGsonSupport();
|
||||
getLogger().info("Classes:");
|
||||
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 where able to link!");
|
||||
getLogger().info("All Classes were able to link!");
|
||||
|
||||
getLogger().info("Methods:");
|
||||
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 where able to link!");
|
||||
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<>();
|
||||
@@ -141,7 +191,7 @@ public class NBTAPI extends JavaPlugin {
|
||||
} catch (Exception ex) {
|
||||
results.put(test, ex);
|
||||
getLogger().log(Level.WARNING, "Error during '" + test.getClass().getSimpleName() + "' test!", ex);
|
||||
} catch (Throwable th) { // NOSONAR
|
||||
} catch (NoSuchFieldError 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!");
|
||||
@@ -150,10 +200,11 @@ public class NBTAPI extends JavaPlugin {
|
||||
}
|
||||
|
||||
for (Entry<de.tr7zw.nbtapi.plugin.tests.Test, Exception> entry : results.entrySet()) {
|
||||
if (entry.getValue() != null)
|
||||
if (entry.getValue() != null) {
|
||||
compatible = false;
|
||||
getLogger().info(entry.getKey().getClass().getSimpleName() + ": "
|
||||
+ (entry.getValue() == null ? "Ok" : entry.getValue().getMessage()));
|
||||
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!";
|
||||
@@ -162,6 +213,9 @@ public class NBTAPI extends JavaPlugin {
|
||||
} else {
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.tr7zw.nbtapi.plugin.tests.blocks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTBlock;
|
||||
import de.tr7zw.changeme.nbtapi.NbtApiException;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import de.tr7zw.nbtapi.plugin.tests.Test;
|
||||
|
||||
public class BlockNBTTest implements Test {
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
if(MinecraftVersion.getVersion().getVersionId() < MinecraftVersion.MC1_16_R3.getVersionId())return;
|
||||
if (!Bukkit.getWorlds().isEmpty()) {
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
try {
|
||||
if (world.getLoadedChunks().length > 1) {
|
||||
Chunk chunk = world.getLoadedChunks()[0];
|
||||
Block block = chunk.getBlock(0, 254, 0);
|
||||
NBTBlock comp = new NBTBlock(block);
|
||||
comp.getData().removeKey("Too");
|
||||
if(comp.getData().hasKey("Too")) {
|
||||
throw new NbtApiException("Unable to remove key from Block!");
|
||||
}
|
||||
comp.getData().setString("Too", "Bar");
|
||||
if (!new NBTBlock(block).getData().getString("Too").equals("Bar")) {
|
||||
throw new NbtApiException("Custom Data did not save to a Block!");
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException("Wasn't able to use NBTBlocks!", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package de.tr7zw.nbtapi.plugin.tests.chunks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTChunk;
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NbtApiException;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import de.tr7zw.nbtapi.plugin.tests.Test;
|
||||
|
||||
public class ChunkNBTPersistentTest implements Test {
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
if(MinecraftVersion.getVersion().getVersionId() < MinecraftVersion.MC1_16_R3.getVersionId())return;
|
||||
if (!Bukkit.getWorlds().isEmpty()) {
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
try {
|
||||
if (world.getLoadedChunks().length > 1) {
|
||||
Chunk chunk = world.getLoadedChunks()[0];
|
||||
NBTChunk comp = new NBTChunk(chunk);
|
||||
NBTCompound persistentData = comp.getPersistentDataContainer();
|
||||
persistentData.removeKey("Foo");
|
||||
if(persistentData.hasKey("Foo")) {
|
||||
throw new NbtApiException("Unable to remove key from Chunk!");
|
||||
}
|
||||
persistentData.setString("Foo", "Bar");
|
||||
if (!new NBTChunk(chunk).getPersistentDataContainer().getString("Foo").equals("Bar")) {
|
||||
throw new NbtApiException("Custom Data did not save to the Chunk!");
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException("Wasn't able to use NBTChunks!", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.tr7zw.nbtapi.plugin.tests.compounds;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -17,6 +19,7 @@ public class EqualsTest implements Test{
|
||||
cont.setString("hello", "world");
|
||||
cont.setInteger("theAnswer", 42);
|
||||
cont.addCompound("sub").setString("me", "too");
|
||||
cont.getStringList("somelist").addAll(Arrays.asList("a", "b", "c"));
|
||||
ItemStack item = new ItemStack(Material.STONE);
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
NBTCompound customData = nbti.addCompound("customData");
|
||||
@@ -24,9 +27,27 @@ public class EqualsTest implements Test{
|
||||
customData.addCompound("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(!new NBTContainer().equals(new NBTContainer())) {
|
||||
throw new NbtApiException("Two empty tags did not match!");
|
||||
}
|
||||
|
||||
// not equal test
|
||||
NBTContainer part1 = new NBTContainer();
|
||||
part1.setString("a", "a");
|
||||
part1.setString("b", "b");
|
||||
NBTContainer part2 = new NBTContainer();
|
||||
part2.setString("a", "a");
|
||||
part2.setString("b", "a");
|
||||
if(part1.equals(part2)) {
|
||||
throw new NbtApiException("Missmatched nbt did match!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package de.tr7zw.nbtapi.plugin.tests.compounds;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTContainer;
|
||||
import de.tr7zw.changeme.nbtapi.NBTList;
|
||||
import de.tr7zw.changeme.nbtapi.NbtApiException;
|
||||
import de.tr7zw.nbtapi.plugin.tests.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class IteratorTest implements Test {
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
NBTList<Integer> testList;
|
||||
|
||||
testList = initIntegerList();
|
||||
testIterator(testList.iterator());
|
||||
|
||||
testList = initIntegerList();
|
||||
testIterator(testList.listIterator());
|
||||
}
|
||||
|
||||
private NBTList<Integer> initIntegerList() {
|
||||
NBTContainer comp = new NBTContainer();
|
||||
NBTList<Integer> list = comp.getIntegerList("test");
|
||||
list.add(1);
|
||||
list.add(2);
|
||||
list.add(3);
|
||||
list.add(4);
|
||||
return list;
|
||||
}
|
||||
|
||||
private static void testIterator(Iterator<Integer> iterator) {
|
||||
assertTrue(iterator.hasNext());
|
||||
assertTrue(iterator.next() == 1);
|
||||
assertTrue(iterator.hasNext());
|
||||
assertTrue(iterator.next() == 2);
|
||||
iterator.remove();
|
||||
assertTrue(iterator.hasNext());
|
||||
assertTrue(iterator.next() == 3);
|
||||
assertTrue(iterator.hasNext());
|
||||
assertTrue(iterator.next() == 4);
|
||||
testNoMoreElements(iterator);
|
||||
}
|
||||
|
||||
private static void testNoMoreElements(Iterator<Integer> iterator) {
|
||||
assertTrue(!iterator.hasNext());
|
||||
try {
|
||||
iterator.next();
|
||||
} catch(NoSuchElementException expected) {
|
||||
return;
|
||||
} catch(Exception e) {
|
||||
throw new NbtApiException("iterator threw wrong exception: " + e.toString());
|
||||
}
|
||||
throw new NbtApiException("iterator did not throw exception");
|
||||
}
|
||||
|
||||
private static void assertTrue(boolean condition) {
|
||||
if(!condition) {
|
||||
throw new NbtApiException("iterator test failed");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,6 +67,10 @@ public class ListTest implements Test {
|
||||
} else {
|
||||
throw new NbtApiException("Taglist is empty! The Item-NBT-API may not work!");
|
||||
}
|
||||
|
||||
if(comp.getListType("complist") != NBTType.NBTTagCompound) {
|
||||
throw new NbtApiException("complist had the wrong type! The Item-NBT-API may not work!");
|
||||
}
|
||||
|
||||
// Integer
|
||||
NBTList<Integer> intlist = comp.getIntegerList("inttest");
|
||||
@@ -77,6 +81,10 @@ public class ListTest implements Test {
|
||||
} else {
|
||||
throw new NbtApiException("IntList is not correct! " + Arrays.toString(intlist.toArray(new Integer[0])));
|
||||
}
|
||||
|
||||
if(comp.getListType("inttest") != NBTType.NBTTagInt) {
|
||||
throw new NbtApiException("inttest had the wrong type! The Item-NBT-API may not work!");
|
||||
}
|
||||
|
||||
// Double
|
||||
NBTList<Double> doublelist = comp.getDoubleList("doubletest");
|
||||
@@ -87,6 +95,10 @@ public class ListTest implements Test {
|
||||
} else {
|
||||
throw new NbtApiException("DoubleList is not correct! " + Arrays.toString(doublelist.toArray(new Double[0])));
|
||||
}
|
||||
|
||||
if(comp.getListType("doubletest") != NBTType.NBTTagDouble) {
|
||||
throw new NbtApiException("doubletest had the wrong type! The Item-NBT-API may not work!");
|
||||
}
|
||||
|
||||
// Float
|
||||
NBTList<Float> floatlist = comp.getFloatList("floattest");
|
||||
@@ -97,6 +109,10 @@ public class ListTest implements Test {
|
||||
} else {
|
||||
throw new NbtApiException("FloatList is not correct! " + Arrays.toString(floatlist.toArray(new Float[0])));
|
||||
}
|
||||
|
||||
if(comp.getListType("floattest") != NBTType.NBTTagFloat) {
|
||||
throw new NbtApiException("floattest had the wrong type! The Item-NBT-API may not work!");
|
||||
}
|
||||
|
||||
// Long
|
||||
NBTList<Long> longlist = comp.getLongList("longtest");
|
||||
@@ -108,6 +124,10 @@ public class ListTest implements Test {
|
||||
throw new NbtApiException("LongList is not correct! " + Arrays.toString(longlist.toArray(new Long[0])));
|
||||
}
|
||||
|
||||
if(comp.getListType("longtest") != NBTType.NBTTagLong) {
|
||||
throw new NbtApiException("longtest had the wrong type! The Item-NBT-API may not work!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -45,6 +45,12 @@ public class SubCompoundsTest implements Test {
|
||||
|| comp.getBoolean(BOOLEAN_TEST_KEY) == BOOLEAN_TEST_VALUE) {
|
||||
throw new NbtApiException("One key does not equal the original compound value!");
|
||||
}
|
||||
|
||||
// Using getOrCreateCompound twice
|
||||
comp.getOrCreateCompound("someName").setString("test", "abc");
|
||||
if(!comp.getOrCreateCompound("someName").getString("test").equals("abc")) {
|
||||
throw new NbtApiException("getOrCreateCompound did not return the same compound!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-20
@@ -1,14 +1,11 @@
|
||||
package de.tr7zw.nbtapi.plugin.tests.entities;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Monster;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTEntity;
|
||||
import de.tr7zw.changeme.nbtapi.NBTTileEntity;
|
||||
import de.tr7zw.changeme.nbtapi.NbtApiException;
|
||||
import de.tr7zw.nbtapi.plugin.tests.Test;
|
||||
|
||||
@@ -25,23 +22,7 @@ public class EntityTest implements Test {
|
||||
nbte.setString("INVALIDEKEY", "test");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException("Wasn't able to use NBTEntities!");
|
||||
}
|
||||
try {
|
||||
Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 255,
|
||||
world.getSpawnLocation().getBlockZ());
|
||||
if (block.getType() == Material.AIR) {
|
||||
block.setType(Material.CHEST);
|
||||
NBTTileEntity tile = new NBTTileEntity(block.getState());
|
||||
tile.setString("Lock", "test");
|
||||
if (!tile.asNBTString().contains("Lock:\"test\"")) {
|
||||
block.setType(Material.AIR);
|
||||
throw new NbtApiException("The Lock wasn't successfully set.");
|
||||
}
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException("Wasn't able to use NBTTiles!", ex);
|
||||
throw new NbtApiException("Wasn't able to use NBTEntities!", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.tr7zw.nbtapi.plugin.tests.items;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import de.tr7zw.changeme.nbtapi.NbtApiException;
|
||||
import de.tr7zw.nbtapi.plugin.tests.Test;
|
||||
|
||||
public class DirectApplyTest implements Test{
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
ItemStack baseItem = new ItemStack(Material.STONE);
|
||||
NBTItem nbti = new NBTItem(baseItem, true);
|
||||
nbti.setString("SomeKey", "SomeValue");
|
||||
if(!baseItem.equals(nbti.getItem()) || !new NBTItem(baseItem).hasKey("SomeKey")) {
|
||||
throw new NbtApiException("The item's where not equal!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,14 @@ public class EmptyItemTest implements Test {
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
if (nbti.getBoolean("test") == null || nbti.getString("test") == null)
|
||||
throw new NbtApiException("Getters return null instead of the default value");
|
||||
|
||||
try {
|
||||
Material barrel = Material.valueOf("BARREL");
|
||||
item = new ItemStack(barrel);
|
||||
nbti = new NBTItem(item);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// old version
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.tr7zw.nbtapi.plugin.tests.items;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import de.tr7zw.changeme.nbtapi.NbtApiException;
|
||||
import de.tr7zw.nbtapi.plugin.tests.Test;
|
||||
|
||||
public class ItemMergingTest implements Test {
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
ItemStack item = new ItemStack(Material.WRITTEN_BOOK);
|
||||
BookMeta bookMeta = (BookMeta) item.getItemMeta();
|
||||
bookMeta.setAuthor("Author");
|
||||
bookMeta.setDisplayName("name");
|
||||
item.setItemMeta(bookMeta);
|
||||
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
nbti.setString("author", "New Author");
|
||||
nbti.setString("test", "value");
|
||||
|
||||
nbti.mergeCustomNBT(item);
|
||||
if (!new NBTItem(item).hasKey("test"))
|
||||
throw new NbtApiException("Couldn't merge custom NBT tag!");
|
||||
if ("New Author".equals(new NBTItem(item).getString("author")))
|
||||
throw new NbtApiException("Vanilla NBT tag was merged when shouldn't!");
|
||||
|
||||
nbti.setString("test", "New Value");
|
||||
nbti.mergeNBT(item);
|
||||
if (!"New Author".equals(new NBTItem(item).getString("author")) || !"New Value".equals(new NBTItem(item).getString("test")))
|
||||
throw new NbtApiException("Couldn't replace NBT tag while merging!");
|
||||
|
||||
ItemStack test = new ItemStack(Material.WRITTEN_BOOK);
|
||||
nbti.applyNBT(test);
|
||||
if (!item.isSimilar(test))
|
||||
throw new NbtApiException("ItemStacks didn't match! " + new NBTItem(item) + " " + new NBTItem(test));
|
||||
|
||||
test = new ItemStack(Material.STONE);
|
||||
nbti.applyNBT(test);
|
||||
if (!nbti.hasKey("test"))
|
||||
throw new NbtApiException("Couldn't merge custom NBT tag!");
|
||||
if (!item.getItemMeta().getDisplayName().equals(test.getItemMeta().getDisplayName()))
|
||||
throw new NbtApiException("Couldn't merge vanilla NBT tag!");
|
||||
|
||||
nbti.setBoolean("remove", true);
|
||||
nbti.clearCustomNBT();
|
||||
if (nbti.hasKey("remove"))
|
||||
throw new NbtApiException("Couldn't clear custom NBT tags!");
|
||||
if (!nbti.hasKey("author"))
|
||||
throw new NbtApiException("Vanilla tag was removed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package de.tr7zw.nbtapi.plugin.tests.tiles;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTTileEntity;
|
||||
import de.tr7zw.changeme.nbtapi.NbtApiException;
|
||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||
import de.tr7zw.nbtapi.plugin.tests.Test;
|
||||
|
||||
public class TileTest implements Test {
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
if (!Bukkit.getWorlds().isEmpty()) {
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
try {
|
||||
Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 254,
|
||||
world.getSpawnLocation().getBlockZ());
|
||||
if (block.getType() == Material.AIR) {
|
||||
block.setType(Material.CHEST);
|
||||
NBTTileEntity tile = new NBTTileEntity(block.getState());
|
||||
if(!MinecraftVersion.isNewerThan(MinecraftVersion.MC1_17_R1)) {
|
||||
if(tile.getInteger("y") != 254) {
|
||||
block.setType(Material.AIR);
|
||||
throw new NbtApiException("The Tile Y pos wasn't correct!");
|
||||
}
|
||||
}
|
||||
tile.setString("Lock", "test");
|
||||
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3) && !tile.hasKey("Lock") && !"test".equals(tile.getString("test"))) {
|
||||
block.setType(Material.AIR);
|
||||
throw new NbtApiException("The Lock wasn't successfully set.");
|
||||
}
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new NbtApiException("Wasn't able to use NBTTiles!", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -19,14 +19,14 @@ public class TilesCustomNBTPersistentTest implements Test {
|
||||
if (!Bukkit.getWorlds().isEmpty()) {
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
try {
|
||||
Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 255,
|
||||
Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 250,
|
||||
world.getSpawnLocation().getBlockZ());
|
||||
if (block.getType() == Material.AIR) {
|
||||
block.setType(Material.CHEST);
|
||||
NBTTileEntity comp = new NBTTileEntity(block.getState());
|
||||
NBTCompound persistentData = comp.getPersistentDataContainer();
|
||||
persistentData.setString("Foo", "Bar");
|
||||
if (!new NBTTileEntity(block.getState()).getPersistentDataContainer().toString().contains("Foo:\"Bar\"")) {
|
||||
if (!new NBTTileEntity(block.getState()).getPersistentDataContainer().getString("Foo").equals("Bar")) {
|
||||
block.setType(Material.AIR);
|
||||
throw new NbtApiException("Custom Data did not save to the Tile!");
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@ main: de.tr7zw.nbtapi.plugin.NBTAPI
|
||||
name: NBTAPI
|
||||
version: ${project.version}
|
||||
author: tr7zw
|
||||
loadbefore: [ItemNBTAPI]
|
||||
loadbefore: [ItemNBTAPI]
|
||||
api-version: 1.13
|
||||
@@ -0,0 +1 @@
|
||||
*.txt
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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>2.9.0</version>
|
||||
</parent>
|
||||
<artifactId>mappings-parser</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<defaultGoal>clean</defaultGoal>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,82 @@
|
||||
package dev.tr7zw.mappingsparser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
|
||||
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Internal class to be used to port SpecialSource mapping txt files to nbt-api internal mappings
|
||||
*
|
||||
* @author tr7zw
|
||||
*
|
||||
*/
|
||||
public class MappingsParser {
|
||||
|
||||
public static StringBuilder builder = new StringBuilder();
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
File input = new File("minecraft_server.1.18-pre8.txt");
|
||||
List<String> lines = Files.readAllLines(input.toPath());
|
||||
|
||||
Map<String, ClassWrapper> classes = new HashMap<>();
|
||||
for(ClassWrapper wrapper : ClassWrapper.values()) {
|
||||
if(wrapper.getMojangName() != null) {
|
||||
classes.put(wrapper.getMojangName(), wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
String currentClass = null;
|
||||
String mojangName = null;
|
||||
String unmappedName = null;
|
||||
ClassWrapper nmsWrapper = null;
|
||||
Map<ReflectionMethod, String> mappedNames = null;
|
||||
for(String line : lines) {
|
||||
if(!line.startsWith(" ")) {
|
||||
if(nmsWrapper != null && mappedNames != null) {
|
||||
proccessMapping(nmsWrapper, mappedNames);
|
||||
}
|
||||
currentClass = line.split(" ")[0];
|
||||
nmsWrapper = classes.get(currentClass);
|
||||
mappedNames = new HashMap<>();
|
||||
for(ReflectionMethod method : ReflectionMethod.values()) {
|
||||
if(method.getParentClassWrapper() == nmsWrapper && method.isCompatible()) {
|
||||
mappedNames.put(method, null);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(nmsWrapper == null)continue;
|
||||
mojangName = line.trim().split(" ")[1];
|
||||
unmappedName = line.trim().split(" ")[3];
|
||||
classes.remove(currentClass);
|
||||
for(ReflectionMethod method : mappedNames.keySet()) {
|
||||
if(method.getSelectedVersionInfo() == null)continue;
|
||||
if(!mojangName.contains("("))continue;
|
||||
if(mojangName.equals(method.getSelectedVersionInfo().name)) {
|
||||
mappedNames.put(method, unmappedName);
|
||||
}
|
||||
}
|
||||
//System.out.println(currentClass + ": " + mojangName + " -> " + unmappedName);
|
||||
}
|
||||
System.out.println(builder);
|
||||
}
|
||||
|
||||
public static void proccessMapping(ClassWrapper nmsWrapper, Map<ReflectionMethod, String> mappedNames) {
|
||||
for(Entry<ReflectionMethod, String> entry : mappedNames.entrySet()) {
|
||||
if(entry.getValue() == null) {
|
||||
System.out.println("Missing mapping in class " + nmsWrapper.getMojangName() + " method " + entry.getKey().name());
|
||||
} else {
|
||||
builder.append("put(\"" + nmsWrapper.getMojangName() + "#" + entry.getKey().getSelectedVersionInfo().name + "\", \"" + entry.getValue() + "\");\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
+14
-16
@@ -1,28 +1,26 @@
|
||||
<?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>2.3.0</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>nbt-data-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>nbt-data-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install javadoc:javadoc</defaultGoal>
|
||||
</build>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install javadoc:javadoc</defaultGoal>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -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.
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.9.0</version>
|
||||
</parent>
|
||||
<artifactId>nbt-injector</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -12,13 +12,13 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>3.27.0-GA</version>
|
||||
<version>3.28.0-GA</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -179,6 +179,10 @@ public class ClassGenerator {
|
||||
: "void";
|
||||
String writeName = ReflectionMethod.TILEENTITY_GET_NBT.getMethodName();
|
||||
String readName = ReflectionMethod.TILEENTITY_SET_NBT.getMethodName();
|
||||
if(MinecraftVersion.getVersion().getVersionId() < MinecraftVersion.MC1_16_R1.getVersionId()) {
|
||||
readName = ReflectionMethod.TILEENTITY_SET_NBT_LEGACY1151.getMethodName();
|
||||
}
|
||||
|
||||
String writeMethod = "public " + writeReturn + " " + writeName + "(NBTTagCompound compound) {\n"
|
||||
+ " compound = writeExtraCompound(compound);\n"
|
||||
// + " System.out.println(\"Save: \" +compound);\n"
|
||||
|
||||
@@ -22,7 +22,7 @@ import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
|
||||
import de.tr7zw.nbtinjector.NBTInjector.Entity;
|
||||
import de.tr7zw.nbtinjector.NBTInjector.TileEntity;
|
||||
import javassist.ClassPool;
|
||||
import static de.tr7zw.changeme.nbtapi.utils.MinecraftVersion.logger;
|
||||
import static de.tr7zw.nbtinjector.NBTInjector.logger;
|
||||
|
||||
/**
|
||||
* Contains the internal methods for different Minecraft Versions of injecting
|
||||
|
||||
@@ -34,7 +34,7 @@ public class NBTInjector {
|
||||
|
||||
}
|
||||
|
||||
static Logger logger = Logger.getLogger("NBTInjector");
|
||||
protected static Logger logger = Logger.getLogger("NBTInjector");
|
||||
private static boolean isInjected = false;
|
||||
private static final String NOT_INJECTED_MESSAGE = "The NBTInjector has not been enabled!\n"
|
||||
+ "You need to call 'NBTInjector.inject()' during the Method 'onLoad' of your Plugin!"
|
||||
@@ -48,6 +48,10 @@ public class NBTInjector {
|
||||
*/
|
||||
public static void inject() {
|
||||
if(isInjected)return;
|
||||
if(MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4 || MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1)) {
|
||||
logger.warning("[NBTINJECTOR] The NBT-Injector is not compatibel with this Minecraft Version! For 1.16+ please use the persistent storage API.");
|
||||
return;
|
||||
}
|
||||
isInjected = true;
|
||||
try {
|
||||
ClassPool classPool = ClassPool.getDefault();
|
||||
|
||||
@@ -3,13 +3,26 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.9.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<inceptionYear>2015</inceptionYear>
|
||||
<organization>
|
||||
<name>tr7zw</name>
|
||||
<url>https://github.com/tr7zw/</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>https://opensource.org/licenses/mit-license.php</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<modules>
|
||||
<module>item-nbt-api</module>
|
||||
<module>nbt-injector</module>
|
||||
<module>nbt-data-api</module>
|
||||
<module>nbt-data-api</module>
|
||||
<module>item-nbt-plugin</module>
|
||||
<module>mappings-parser</module>
|
||||
</modules>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -18,7 +31,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -99,7 +112,10 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
@@ -108,14 +124,11 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.github.ekryd.sortpom</groupId>
|
||||
<artifactId>sortpom-maven-plugin</artifactId>
|
||||
<version>2.11.0</version>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sortpom</id>
|
||||
@@ -138,6 +151,16 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>license-maven-plugin</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<configuration>
|
||||
<licenseName>mit</licenseName>
|
||||
<licenseFile>LICENSE</licenseFile>
|
||||
<force>true</force>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,289 @@
|
||||
[B][SIZE=6](Item/Entity/Tile) NBT API[/SIZE][/B]
|
||||
[URL='https://ci.codemc.io/job/Tr7zw/job/Item-NBT-API/'][IMG]https://ci.codemc.org/buildStatus/icon?job=Tr7zw%2FItem-NBT-API[/IMG][/URL] [URL='https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent'][IMG]https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=ncloc[/IMG][/URL] [URL='https://bstats.org/plugin/bukkit/ItemNBTAPI'][IMG]https://img.shields.io/bstats/servers/1058.svg?color=green&label=OnlineServers&style=plastic[/IMG][/URL] [URL='https://bstats.org/plugin/bukkit/ItemNBTAPI'][IMG]https://img.shields.io/bstats/players/1058.svg?color=green&label=OnlinePlayers&style=plastic[/IMG] [/URL][URL='https://discordapp.com/invite/yk4caxM'][IMG]https://img.shields.io/discord/342814924310970398?color=%237289DA&label=Discord&logo=discord&logoColor=white[/IMG][/URL]
|
||||
The NBT API allows you to add custom NBT tags to Itemstacks, TileEntities and Entities, or modify excisting ones!
|
||||
It completely uses reflections to interact with NMS code and works with all the latest versions. On server start the plugin checks all reflections.
|
||||
|
||||
Tested on Spigot
|
||||
[LIST]
|
||||
[*](1.7*)1.8.8-1.17.*
|
||||
[*]The NBTInjector will not work with: 1.12.0, 1.12.1, 1.13.0 (Please just update to the final release of your chosen version)
|
||||
|
||||
[*]On startup you will get a notification if there is a version problem!
|
||||
[/LIST]
|
||||
* 1.7 Notes: Use a 1.7 with R4 (1.7.10), NBTLists may not work, everything using Gson is disabled(Add Gson before the NBTAPI loads, to turn it back on), and you can't get the NBTTypes, because 1.7 is missing this feature. TLDR: 1.7.10 is somewhat broken and not everything might work due to 1.7.10 limitations.
|
||||
|
||||
[B]What do I have to do as a server owner?[/B]
|
||||
Just download the jar and drop it in the plugins folder. Done.
|
||||
Note that outdated plugins may ask for "ItemNBTAPI". In this case download version 1.8.3 from the versions tab. The outdated "ItemNBTAPI" and "NBTApi" can be used at the same time.
|
||||
[B]Important for version 2.0.0:[/B] Don't reload while using the NBTInjector. Reloading, in general, is a horrible thing and it will break the NBTInjector in horrible ways! When updating plugins/changing configs always restart the server normally!
|
||||
|
||||
[B]How can I use the API as developer?[/B]
|
||||
Create the NBT Wrapper:
|
||||
[CODE]NBTItem nbti = new NBTItem(item);
|
||||
NBTEntity nbtent = new NBTEntity(zombie); //Only for vanilla tags!
|
||||
NBTTileEntity tent = new NBTTileEntity(block.getState()); //Only for vanilla tags!
|
||||
NBTFile file = new NBTFile(new File(getDataFolder(), "test.nbt"));
|
||||
NBTContainer container = new NBTContainer(json); //Parse in json
|
||||
[/CODE]
|
||||
|
||||
Add/Get/Override NBT tags:
|
||||
[CODE]//Set
|
||||
nbti.setString("Stringtest", "Teststring");
|
||||
nbti.setInteger("Inttest", 42);
|
||||
nbti.setDouble("Doubletest", 1.5d);
|
||||
nbti.setBoolean("Booleantest", true);
|
||||
//More are avaible!
|
||||
//Get
|
||||
nbti.getString("Stringtest");
|
||||
nbti.getInteger("Inttest");
|
||||
nbti.getDouble("Doubletest");
|
||||
nbti.getBoolean("Booleantest");
|
||||
//Get all Tags
|
||||
nbti.getKeys();
|
||||
//Check for an tag
|
||||
nbti.hasKey("Key");
|
||||
//Remove a tag
|
||||
nbti.removeKey("Key");
|
||||
//or
|
||||
nbti.setString("Stringtest", null);
|
||||
//Create NBTTagCombounds(Imagine folders)
|
||||
nbti.addCompound("subtag");
|
||||
//Get Compound
|
||||
NBTCompound comp = nbti.getCompound("subtag");
|
||||
//Get Compound parent(null at root)
|
||||
comp.getParent();
|
||||
//Save Objects via Gson
|
||||
nbti.setObject("myobject", new SimpleJsonTestObject());
|
||||
//Get Objects
|
||||
SimpleJsonTestObject simpleObject = nbti.getObject("myobject", SimpleJsonTestObject.class);
|
||||
//Merge the data from compound A into B (Like the /data merge command)
|
||||
B.mergeCompound(A);
|
||||
//Get the nbt as json
|
||||
comp.asNBTString();
|
||||
|
||||
//Access/create lists
|
||||
nbtent.getCompoundList("Attributes");
|
||||
nbtent.getStringList("Attributes");
|
||||
[/CODE]
|
||||
|
||||
And finally get back the Bukkit Itemstack(Changes on Tiles/Entities will happen directly):
|
||||
[CODE]nbti.getItem();[/CODE]
|
||||
Saving the NBTFile:
|
||||
[CODE]file.save();[/CODE]
|
||||
|
||||
[B]Important note regarding Tiles/Entities
|
||||
[B]Starting with 1.14+ you can use the getPersistentDataContainer() (for NBT(Tile)-Entity's) to save custom tags. This replaces the now mentioned NBT-Injector.[/B][/B]
|
||||
Non-vanilla tags can't usually be added to to Tiles/Entities. Thanks to
|
||||
[URL='https://www.spigotmc.org/members/inventivetalent.6643/'][IMG]https://tr7zw.dev/nbtapi/spigotPeople.php?id=6643[/IMG][/URL] the NBTAPI now includes a tool called "NBTInjector", that compiles custom (Tile-)Entity classes during runtime to allow custom nbt. The custom data will remain during chunk unloads/server restarts. [B]Data will be lost when chunks get loaded without the NBTAPI loaded! Since 2.1.0 the NBTInjector won't be enabled by default! Please enable it during onLoad with NBTInjector.inject(); if you are using it![/B]
|
||||
Adding custom nbt to tiles:
|
||||
[CODE]
|
||||
NBTCompound comp = NBTInjector.getNbtData(block.getState());
|
||||
comp.setString("Foo", "Bar");
|
||||
[/CODE]
|
||||
Adding custom nbt to entities:
|
||||
[CODE]
|
||||
Entity ent = world.getEntitiesByClasses(Animals.class, Monster.class).iterator().next();
|
||||
ent = NBTInjector.patchEntity(ent); //This needs to be called at least once on the entity to enable custom nbt!
|
||||
NBTCompound comp = NBTInjector.getNbtData(ent);
|
||||
comp.setString("Hello", "World");
|
||||
[/CODE]
|
||||
[B]Note[/B]: Before NBTInjector.getNbtData can be used on an Entity, NBTInjector.patchEntity has to be used on it at least once. This method will check if the entity is patched, and if not remove the entity and respawn it with the correct class. This destroys the original entity reference(the new one is returned) and the entity will blink once ingame. Bestcase you call this method right when the entity is spawned to prevent unwanted behavior(the blink, entities interacting with the Entity beeing patched like riding/leashes/combat may have problems).
|
||||
|
||||
[B]Maven[/B]
|
||||
(Historicly it was Jitpack. Don't use it anymore!)
|
||||
NBTApi is hosted and compiled by CodeMC.
|
||||
[URL='https://ci.codemc.org/job/Tr7zw/job/Item-NBT-API/']JenkinsBuild[/URL] [URL='https://github.com/CodeMC/CI-Documentation']CodeMC-Info[/URL]
|
||||
[code]<repositories>
|
||||
...
|
||||
<!-- CodeMC -->
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
...
|
||||
</repositories>
|
||||
[/code]
|
||||
The API can be used in different ways:
|
||||
[SPOILER="Normal Plugin dependency"]
|
||||
Just use the Plugin as Maven dependency and remember to add "NBTAPI" as dependency into the plugin.yml. This way server owners will have to install the api and keep it updated.
|
||||
[CODE]
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api-plugin</artifactId>
|
||||
<version>2.6.0</version>
|
||||
</dependency>
|
||||
[/CODE]
|
||||
[/SPOILER]
|
||||
[SPOILER="Shading the API into your plugin"]
|
||||
Using this method the API gets copied into your plugin. Server owners don't have to install the API on their own, but you need to keep it updated. Also [B]relocating is required[/B]!
|
||||
[CODE]
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.6.0</version>
|
||||
</dependency>
|
||||
...
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shade</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>de.tr7zw.changeme.nbtapi</pattern>
|
||||
<shadedPattern>YOUR PACKGE WHERE THE API SHOULD END UP</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
[/CODE]
|
||||
[/SPOILER]
|
||||
|
||||
[B]Example Code[/B]
|
||||
[SPOILER="Zombie that will pickup loot and does 0.5 Hearts of damage"]
|
||||
[CODE]
|
||||
Zombie z = (Zombie) b.getWorld().spawnEntity(b.getLocation().add(0, 1, 0), EntityType.ZOMBIE);
|
||||
NBTEntity nbtent = new NBTEntity(z);
|
||||
nbtent.setByte("CanPickUpLoot", (byte) 1);
|
||||
NBTList list = nbtent.getCompoundList("Attributes");
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
NBTListCompound lc = list.getCompound(i);
|
||||
if(lc.getString("Name").equals("generic.attackDamage")){
|
||||
lc.setDouble("Base", 0.5d);
|
||||
}
|
||||
}
|
||||
[/CODE]
|
||||
[/SPOILER]
|
||||
|
||||
[SPOILER="Simulate the command /data merge entity @e[type=zombie] {Silent:1b,Invulnerable:1b,Glowing:1b,IsBaby:1b}"]
|
||||
[CODE]
|
||||
NBTEntity nbtent = new NBTEntity(zombie);
|
||||
nbtent.mergeCompound(new NBTContainer("{Silent:1b,Invulnerable:1b,Glowing:1b,IsBaby:1b}"));
|
||||
[/CODE]
|
||||
[/SPOILER]
|
||||
|
||||
[SPOILER="Creating a Head with texture, healthboost and some more tags"]
|
||||
[CODE]
|
||||
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
NBTItem nbti = new NBTItem(head);
|
||||
NBTCompound disp = nbti.addCompound("display");
|
||||
disp.setString("Name", "Testitem");
|
||||
List<String> l = disp.getStringList("Lore");
|
||||
l.add("Some lore");
|
||||
NBTCompound skull = nbti.addCompound("SkullOwner");
|
||||
skull.setString("Name", "tr7zw");
|
||||
skull.setString("Id", "fce0323d-7f50-4317-9720-5f6b14cf78ea");
|
||||
NBTListCompound texture = skull.addCompound("Properties").getCompoundList("textures").addCompound();
|
||||
texture.setString("Signature", "XpRfRz6/vXE6ip7/vq+40H6W70GFB0yjG6k8hG4pmFdnJFR+VQhslE0gXX/i0OAGThcAVSIT+/W1685wUxNofAiy+EhcxGNxNSJkYfOgXEVHTCuugpr+EQCUBI6muHDKms3PqY8ECxdbFTUEuWxdeiJsGt9VjHZMmUukkGhk0IobjQS3hjQ44FiT1tXuUU86oAxqjlKFpXG/iXtpcoXa33IObSI1S3gCKzVPOkMGlHZqRqKKElB54I2Qo4g5CJ+noudIDTzxPFwEEM6XrbM0YBi+SOdRvTbmrlkWF+ndzVWEINoEf++2hkO0gfeCqFqSMHuklMSgeNr/YtFZC5ShJRRv7zbyNF33jZ5DYNVR+KAK9iLO6prZhCVUkZxb1/BjOze6aN7kyN01u3nurKX6n3yQsoQQ0anDW6gNLKzO/mCvoCEvgecjaOQarktl/xYtD4YvdTTlnAlv2bfcXUtc++3UPIUbzf/jpf2g2wf6BGomzFteyPDu4USjBdpeWMBz9PxVzlVpDAtBYClFH/PFEQHMDtL5Q+VxUPu52XlzlUreMHpLT9EL92xwCAwVBBhrarQQWuLjAQXkp3oBdw6hlX6Fj0AafMJuGkFrYzcD7nNr61l9ErZmTWnqTxkJWZfZxmYBsFgV35SKc8rkRSHBNjcdKJZVN4GA+ZQH5B55mi4=");
|
||||
texture.setString("Value", "eyJ0aW1lc3RhbXAiOjE0OTMwNDkwMTcxNTIsInByb2ZpbGVJZCI6ImZjZTAzMjNkN2Y1MDQzMTc5NzIwNWY2YjE0Y2Y3OGVhIiwicHJvZmlsZU5hbWUiOiJ0cjd6dyIsInNpZ25hdHVyZVJlcXVpcmVkIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTI3NDZlNWU5OGMwZWRmZTU1YTI3ZGRjNjUxMmJmNjllYzJiYmNlNmM3ZmNhNTQ5YmEzNjZkYThiNTRjZTRkYiJ9fX0=");
|
||||
|
||||
NBTCompoundList attribute = nbti.getCompoundList("AttributeModifiers");
|
||||
NBTListCompound mod1 = attribute.addCompound();
|
||||
mod1.setInteger("Amount", 10);
|
||||
mod1.setString("AttributeName", "generic.maxHealth");
|
||||
mod1.setString("Name", "generic.maxHealth");
|
||||
mod1.setInteger("Operation", 0);
|
||||
mod1.setInteger("UUIDLeast", 59664);
|
||||
mod1.setInteger("UUIDMost", 31453);
|
||||
|
||||
nbti.setInteger("HideFlags", 4);
|
||||
nbti.setBoolean("Unbreakable", true);
|
||||
head = nbti.getItem();
|
||||
e.getPlayer().getInventory().addItem(head);
|
||||
[/CODE]
|
||||
[/SPOILER]
|
||||
|
||||
[SPOILER="Printing the NBT tags"]
|
||||
[CODE]
|
||||
Ocelot m = (Ocelot) e.getPlayer().getWorld().spawnEntity(e.getPlayer().getLocation(), EntityType.OCELOT);
|
||||
NBTEntity ent = new NBTEntity(m);
|
||||
System.out.println(ent);
|
||||
[/CODE]
|
||||
Output:
|
||||
[CODE]
|
||||
-AgeLocked: 0b
|
||||
-HurtByTimestamp: 0
|
||||
-CatType: 0
|
||||
-Leashed: 0b
|
||||
-Health: 10.0f
|
||||
-Sitting: 0b
|
||||
-Attributes: [0:{Base:10.0d,Name:"generic.maxHealth"},1:{Base:0.0d,Name:"generic.knockbackResistance"},2:{Base:0.30000001192092896d,Name:"generic.movementSpeed"},3:{Base:0.0d,Name:"generic.armor"},4:{Base:0.0d,Name:"generic.armorToughness"},5:{Base:16.0d,Modifiers:[0:{UUIDMost:-8783172028836920024L,UUIDLeast:-6820414278857408689L,Amount:-0.030166473586416633d,Operation:1,Name:"Random spawn bonus"}],Name:"generic.followRange"}]
|
||||
-FallFlying: 0b
|
||||
-LeftHanded: 0b
|
||||
-ForcedAge: 0
|
||||
-AbsorptionAmount: 0.0f
|
||||
-HandItems: [0:{},1:{}]
|
||||
-ArmorDropChances: [0:0.085f,1:0.085f,2:0.085f,3:0.085f]
|
||||
-OwnerUUID: ""
|
||||
-InLove: 0
|
||||
-DeathTime: 0s
|
||||
-ArmorItems: [0:{},1:{},2:{},3:{}]
|
||||
-CanPickUpLoot: 0b
|
||||
-HandDropChances: [0:0.085f,1:0.085f]
|
||||
-PersistenceRequired: 0b
|
||||
-HurtTime: 0s
|
||||
-Age: 0
|
||||
[/CODE]
|
||||
[/SPOILER]
|
||||
|
||||
[SPOILER="Locking Chests"]
|
||||
[CODE] NBTTileEntity tent = new NBTTileEntity(b.getState());
|
||||
tent.setString("Lock", "test");[/CODE]
|
||||
[/SPOILER]
|
||||
|
||||
[B]More Infos:[/B]
|
||||
[LIST]
|
||||
[*][URL]https://www.spigotmc.org/threads/override-base-item-attribute-value.236434/#post-2387235[/URL]
|
||||
[/LIST]
|
||||
|
||||
[B]This API can't be used for:[/B]
|
||||
[LIST]
|
||||
[*][I][SIZE=4][S]Adding custom tags to TileEntities/Entities[/S] [/SIZE][/I][SIZE=4]Not true anymore, check the NBTInjector examples above.*[/SIZE]
|
||||
*This only is required for <= 1.13, 1.14+ can just use the getPersistentDataContainer method on NBTEntity/NBTTileEntity to store custom data.
|
||||
[/LIST]
|
||||
Git: [URL='https://github.com/tr7zw/Item-NBT-API']Github[/URL]
|
||||
Maven Repo: [URL='https://repo.codemc.org/#browse/browse:maven-public:de%2Ftr7zw%2Fitem-nbt-api-plugin']CodeMC[/URL]
|
||||
Jenkins: [URL='https://ci.codemc.org/job/Tr7zw/job/Item-NBT-API/']Jenkins[/URL]
|
||||
Discord server for help: [URL='https://discord.gg/yk4caxM']Discord[/URL]
|
||||
Feel free to create forks for your need! (Send me a message on [S]Spigot[/S] the Discord server if you want stuff to be added/need help)
|
||||
Yes you are allowed to integrate the API into your plugin(remember to shade)! (Send me a link to your project so I can check it out ;))
|
||||
|
||||
[B][SIZE=5]Projects using the API(That I know of)[/SIZE]
|
||||
[U][SIZE=4]Plugins[/SIZE][/U][/B]
|
||||
[URL='https://www.spigotmc.org/resources/crazy-enchantments.16470/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=16470&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/levelledmobs-for-1-16-x-1-17-x.74304/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=74304&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/backpacks.45622/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=45622&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/gravy.45288/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=45288&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/interactivebooks.45604/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=45604&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/vouchers.13654/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=13654&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/itemcommands.49543/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=49543&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/comparable-hoppers-2.45058/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=45058&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/nottooexpensive.62680/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=62680&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/papermoney.70361/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=70361&[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/blockstackerx-recoded.73749/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=73749[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/63020/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=63020&reload[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/resources/72810/'][IMG]https://tr7zw.dev/nbtapi/linkedProjects.php?id=72810&reload[/IMG][/URL]
|
||||
[U][B]Server/Networks[/B][/U]
|
||||
[URL='http://Timolia.de'][IMG]http://status.mclive.eu/Timolia.de/timolia.de/25565/banner.png[/IMG][/URL]
|
||||
[U][B]Other[/B][/U]
|
||||
- [URL='https://github.com/LogisticsCraft/Logistics-API']Logistics-API[/URL]
|
||||
|
||||
[SIZE=4][SIZE=4][U][B]Donators[/B][/U]
|
||||
[U][B][URL='https://www.spigotmc.org/members/mrdienns.35704/'][IMG]https://tr7zw.dev/nbtapi/spigotPeople.php?id=35704[/IMG][/URL] [/B][/U]
|
||||
[U][B][URL='https://www.spigotmc.org/members/mraxetv.27720/'][IMG]https://tr7zw.dev/nbtapi/spigotPeople.php?id=27720[/IMG][/URL] [/B][/U]
|
||||
[URL='https://www.spigotmc.org/members/lonedev.88296/'][IMG]https://tr7zw.dev/nbtapi/spigotPeople.php?id=88296[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/members/gc.25090/'][IMG]https://tr7zw.dev/nbtapi/spigotPeople.php?id=25090[/IMG][/URL]
|
||||
[URL='https://www.spigotmc.org/members/peaches_mlg100.194338/'][IMG]https://tr7zw.dev/nbtapi/spigotPeople.php?id=194338[/IMG][/URL][/SIZE][/SIZE]
|
||||
[IMG]https://bstats.org/signatures/bukkit/ItemNBTAPI.svg[/IMG]
|
||||
Reference in new issue
Block a user