Compare commits

...
38 Commits
Author SHA1 Message Date
tr7zw 817b104757 Merge pull request #85 from LoneDev6/master
1.16.1 support
2020-06-25 15:47:54 +02:00
tr7zw d4ab47d287 Release 2.4.1: 1.16.1 Update 2020-06-25 15:46:57 +02:00
tr7zw cd30dd1303 Fix 1.16 TileEntities 2020-06-25 15:36:44 +02:00
tr7zw ff6a0361b7 Merge branch 'master' into pr/85 2020-06-25 15:36:24 +02:00
tr7zw 97042b9fc1 Merge pull request #86 from Leonardo-DGS/patch-1
Fix mistake in MinecraftVersion.java
2020-06-25 15:33:24 +02:00
Leonardo Di Gianfelice Stornelli 6234e359eb Fix mistake in MinecraftVersion.java 2020-06-25 15:22:58 +02:00
LoneDev6 32070b8f19 Merge branch 'master' of https://github.com/LoneDev6/Item-NBT-API 2020-06-25 13:17:55 +02:00
LoneDev6 a371a33766 Fixed imports 2020-06-25 13:17:44 +02:00
tr7zw 8ad527057e Update pom.xml 2020-06-25 13:16:48 +02:00
LoneDev6 cf5fe7c083 Merge branch 'master' of https://github.com/LoneDev6/Item-NBT-API 2020-06-25 13:08:07 +02:00
LoneDev6 0255ef044f Get and set UUID (1.16.1+) 2020-06-25 13:08:04 +02:00
tr7zw faeea97934 Update pom.xml 2020-06-25 13:06:31 +02:00
tr7zw b4a59cdede Update pom.xml 2020-06-25 13:05:49 +02:00
tr7zw c47ca55e84 Update pom.xml 2020-06-25 13:05:28 +02:00
tr7zw 8cbf4b1cf6 Bump version 2020-06-25 13:05:15 +02:00
LoneDev6 67bf920ba7 1.16.1 support
- 1.16.1 support
- incremented api version
2020-06-25 12:36:26 +02:00
tr7zw af0a8f1d4c Merge pull request #82 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.2.4
Bump maven-shade-plugin from 3.2.3 to 3.2.4
2020-06-16 12:23:41 +02:00
dependabot-preview[bot] 7fa614b3d5 Bump maven-shade-plugin from 3.2.3 to 3.2.4
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.3 to 3.2.4.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.3...maven-shade-plugin-3.2.4)

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

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-04-14 05:20:37 +00:00
tr7zw 75249b556e Bump to 2.3.2 (no spigot release), prevent shading to change the nms packet names 2020-04-11 16:32:30 +02:00
tr7zw 8aba56ff70 2.3.1 fixes
Added the api-version 1.13. Only >= 1.13 uses this so doesn't use legacy materials. Fixes #74
The versioncheck was doing a http request in the mainthread, which was fine for the plugin version since it happend during enable, but shaded versions might do that sometime later when players are online, causing a short lag.
2020-04-09 19:28:04 +02:00
tr7zw 27761ac95a Bump to 2.4.0-SNAPSHOT 2020-04-04 18:00:36 +02:00
tr7zw c6b3055a15 Add Peaches_MLG 2020-04-04 17:59:37 +02:00
20 changed files with 671 additions and 242 deletions

No files matched your search

+12
View File
@@ -158,6 +158,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/"
}
}
]
}
+4 -1
View File
@@ -4,9 +4,11 @@ Add custom NBT tags to Items/Tiles/Entities without NMS! Modify NBT and store it
### Build/Maven/Sonar Status
[![Build Status](https://ci.codemc.org/buildStatus/icon?job=Tr7zw%2FItem-NBT-API)](https://ci.codemc.org/job/Tr7zw/job/Item-NBT-API/)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=alert_status)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=ncloc)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)[![](https://sonarcloud.io/api/project_badges/measure?project=de.tr7zw%3Aitem-nbt-parent&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=de.tr7zw%3Aitem-nbt-parent)
[![Discord](https://img.shields.io/discord/342814924310970398?color=%237289DA&label=Discord&logo=discord&logoColor=white)](https://discordapp.com/invite/yk4caxM)
[![Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.herokuapp.com%2Ftr7zw%2Fpledges&style=for-the-badge)](https://www.patreon.com/tr7zw)
### SpigotMC Status
[![Version](https://badges.spiget.org/resources/version/Version-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![Rating](https://badges.spiget.org/resources/rating/Rating-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![Rating](https://badges.spiget.org/resources/downloads/SpigotDownloads-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![bStats Servers](https://img.shields.io/bstats/servers/1058.svg?color=green&label=OnlineServers&style=plastic)](https://bstats.org/plugin/bukkit/ItemNBTAPI)[![bStats Players](https://img.shields.io/bstats/players/1058.svg?color=green&label=OnlinePlayers&style=plastic)](https://bstats.org/plugin/bukkit/ItemNBTAPI)[![All Contributors](https://img.shields.io/badge/all_contributors-12-green.svg?style=plastic)](#contributors-%e2%9c%a8)
[![Version](https://badges.spiget.org/resources/version/Version-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![Rating](https://badges.spiget.org/resources/rating/Rating-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![Rating](https://badges.spiget.org/resources/downloads/SpigotDownloads-yellow-7939.svg)](https://www.spigotmc.org/resources/item-entity-tile-nbt-api.7939/)[![bStats Servers](https://img.shields.io/bstats/servers/1058.svg?color=green&label=OnlineServers&style=plastic)](https://bstats.org/plugin/bukkit/ItemNBTAPI)[![bStats Players](https://img.shields.io/bstats/players/1058.svg?color=green&label=OnlinePlayers&style=plastic)](https://bstats.org/plugin/bukkit/ItemNBTAPI)[![All Contributors](https://img.shields.io/badge/all_contributors-13-green.svg?style=plastic)](#contributors-%e2%9c%a8)
[![bStats Stats](https://bstats.org/signatures/bukkit/ItemNBTAPI.svg)](https://bstats.org/plugin/bukkit/ItemNBTAPI)
@@ -36,6 +38,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<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/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 -->
+2 -2
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
</parent>
<artifactId>item-nbt-api</artifactId>
@@ -34,7 +34,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.4</version>
<executions>
<execution>
<id>shade</id>
@@ -3,6 +3,10 @@ package de.tr7zw.changeme.nbtapi;
import java.io.OutputStream;
import java.io.Serializable;
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 +22,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 +34,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 +79,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 +95,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 +111,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 +130,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 +146,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 +161,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 +177,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 +192,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 +208,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 +223,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 +239,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 +254,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 +270,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 +285,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 +301,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 +316,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 +332,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 +347,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 +363,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 +378,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 +399,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 +414,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 +431,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,25 +507,40 @@ 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();
}
}
/**
@@ -363,14 +550,19 @@ public class NBTCompound {
* @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 +570,17 @@ 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();
}
}
/**
@@ -391,9 +588,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 +603,59 @@ 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();
}
}
/**
@@ -441,9 +663,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 +679,34 @@ 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)
return null;
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 +717,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 +750,8 @@ 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
* 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
*/
@Override
public boolean equals(Object obj) {
@@ -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,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);
}
/**
@@ -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();
}
}
}
@@ -214,7 +214,12 @@ public class NBTReflectionUtil {
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);
if(MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_16_R1.getVersionId()) {
Object blockData = ReflectionMethod.TILEENTITY_GET_BLOCKDATA.run(o);
ReflectionMethod.TILEENTITY_SET_NBT.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);
}
@@ -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);
private static MinecraftVersion version;
private static Boolean hasGsonSupport;
@@ -37,9 +28,9 @@ public enum MinecraftVersion {
* Logger used by the api
*/
public static final Logger logger = Logger.getLogger("NBTAPI");
// NBT-API Version
protected static final String VERSION = "2.3.0";
protected static final String VERSION = "2.4.1";
private final int versionId;
@@ -85,14 +76,17 @@ public enum MinecraftVersion {
if (!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 (!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 +131,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;
@@ -39,7 +39,8 @@ NMS_REGISTRYSIMPLE(PackageWrapper.NMS, "RegistrySimple", MinecraftVersion.MC1_11
NMS_REGISTRYMATERIALS(PackageWrapper.NMS, "RegistryMaterials"),
NMS_IREGISTRY(PackageWrapper.NMS, "IRegistry"),
NMS_MINECRAFTKEY(PackageWrapper.NMS, "MinecraftKey"),
NMS_GAMEPROFILESERIALIZER(PackageWrapper.NMS, "GameProfileSerializer")
NMS_GAMEPROFILESERIALIZER(PackageWrapper.NMS, "GameProfileSerializer"),
NMS_IBLOCKDATA(PackageWrapper.NMS, "IBlockData")
;
private Class<?> clazz;
@@ -8,8 +8,8 @@ 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'})),
;
private final String uri;
@@ -3,6 +3,7 @@ package de.tr7zw.changeme.nbtapi.utils.nmsmappings;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.UUID;
import org.bukkit.inventory.ItemStack;
@@ -30,6 +31,7 @@ public enum ReflectionMethod {
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_SET_UUID(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class, UUID.class}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "a")),
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")),
@@ -45,6 +47,7 @@ public enum ReflectionMethod {
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_UUID(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "a")),
COMPOUND_GET_COMPOUND(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{String.class}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getCompound")),
NMSITEM_GETTAG(ClassWrapper.NMS_ITEMSTACK.getClazz(), new Class[] {}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "getTag")),
@@ -53,7 +56,7 @@ public enum ReflectionMethod {
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_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"), new Since(MinecraftVersion.MC1_16_R1, "d")), //FIXME: No Spigot mapping!
COMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys")),
LISTCOMPOUND_GET_KEYS(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), new Class[]{}, MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "c"), new Since(MinecraftVersion.MC1_13_R1, "getKeys")),
@@ -78,13 +81,16 @@ public enum ReflectionMethod {
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_LOAD_LEGACY1151(ClassWrapper.NMS_TILEENTITY.getClazz(), 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.getClazz(), new Class[]{ClassWrapper.NMS_IBLOCKDATA.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_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")),
TILEENTITY_SET_NBT_LEGACY1151(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, MinecraftVersion.MC1_15_R1, new Since(MinecraftVersion.MC1_8_R3, "a"), new Since(MinecraftVersion.MC1_12_R1, "load")),
TILEENTITY_SET_NBT(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{ClassWrapper.NMS_IBLOCKDATA.getClazz(), ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "load")),
TILEENTITY_GET_BLOCKDATA(ClassWrapper.NMS_TILEENTITY.getClazz(), new Class[]{}, MinecraftVersion.MC1_16_R1, new Since(MinecraftVersion.MC1_16_R1, "getBlock")),
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_SET_NBT(ClassWrapper.NMS_ENTITY.getClazz(), new Class[]{ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()}, MinecraftVersion.MC1_8_R3, new Since(MinecraftVersion.MC1_8_R3, "f"), new Since(MinecraftVersion.MC1_16_R1, "load")), //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")),
+7 -7
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.3.0</version>
<version>2.4.1</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.4.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>nbt-injector</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>nbt-data-api</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
@@ -39,7 +39,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.4</version>
<executions>
<execution>
<id>shade</id>
@@ -50,7 +50,7 @@
</execution>
</executions>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<createDependencyReducedPom>true</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>de.tr7zw.changeme.nbtapi</pattern>
@@ -80,7 +80,7 @@
</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>
<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.2,1.16.1</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>
@@ -17,6 +17,7 @@ import de.tr7zw.nbtapi.plugin.tests.NBTFileTest;
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;
@@ -69,6 +70,7 @@ public class NBTAPI extends JavaPlugin {
apiTests.add(new ForEachTest());
apiTests.add(new StreamTest());
apiTests.add(new EqualsTest());
apiTests.add(new IteratorTest());
// Items
apiTests.add(new ItemConvertionTest());
@@ -108,29 +110,32 @@ public class NBTAPI extends JavaPlugin {
MinecraftVersion.getVersion();
getLogger().info("Gson:");
MinecraftVersion.hasGsonSupport();
getLogger().info("Classes:");
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 +146,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!");
@@ -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");
}
}
}
@@ -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
}
}
}
@@ -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
+2 -2
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
</parent>
<artifactId>nbt-data-api</artifactId>
@@ -16,7 +16,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
</parent>
<artifactId>nbt-injector</artifactId>
<packaging>jar</packaging>
@@ -12,7 +12,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
<scope>compile</scope>
</dependency>
<dependency>
+1 -1
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.3.0</version>
<version>2.4.1</version>
<packaging>pom</packaging>
<modules>
<module>item-nbt-api</module>