Spigot NBT API 2.7.1

Add custom NBT tags or modify tags of Items/Entities/Tiles without NMS!

  1. tr7zw updated NBT API with a new update entry:

    2.1.0

    Read the rest of this update entry...
     
  2. Actually there is. nbti.getStringList("listname");. The list even implements the List<String> interface so it behaves exactly like an String Arraylist.

    Also I added 3 plugins to the pluginlist that I know about.
     
    #122 tr7zw, Sep 24, 2019
    Last edited: Sep 24, 2019
  3. Hey I saw that method, but I don't see a method for setting the list. Would I use setObject?
     
  4. It's a list.
    List<String> list = nbti.getStringList("listname");
    list.add("test1");
    list.add("test2");

    The list is linked to the the NBT Compound and will update the data in there with each add/remove like a setter.
     
  5. Tau

    Tau

    Hey there, would it be more efficient to have an internal Compound/Container#getSize(Size.BYTES) method for the NBT data? Currently I'm converting it to a string and checking the strings length, this is not reliable as there could be non-utf8 data and then i'd need even more checks (I'm trying to find an efficient way to gauge how much data an nbt compound (and all of it's components) holds)

    Or would there be no practical efficiency gain vs the string method?
    Thanks, awesome API btw!
     
  6. LoneDev

    Supporter

    @tr7zw To update this to 1.15 update this in ReflectionMethod:
    Code (Text):
        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!
     
    Update also MinecraftVersion:
    Code (Text):
        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);
     
  7. Aw well just saw it after I was done updating^^. A pullrequest would have been better noticable. Also two constructors where made private.
     
  8. LoneDev

    Supporter

    Sorry! Didn't think about this
     
  9. Tau

    Tau

    Your zombie example code doesn't work anymore, how do we get a Compound List?
     
  10. tr7zw updated NBT API with a new update entry:

    Update 2.2.0: Java11, Bugfixes and more

    Read the rest of this update entry...
     
  11. Updated the example code, the method got renamed to getCompoundList(key). I'm also always reachable via the LogisticsCraft Discord https://discord.gg/yk4caxM
     
  12. Got this strange error.

    Code (Text):
    [04:30:31 INFO]: Starting minecraft server version 1.15.1
    [04:30:31 INFO]: Loading properties
    [04:30:31 INFO]: This server is running Paper version git-Paper-33 (MC: 1.15.1) (Implementing API version 1.15.1-R0.1-SNAPSHOT)
    Code (Text):
    [04:30:46 INFO]: [NBTAPI] Enabling NBTAPI v2.2.0*
    [04:30:46 INFO]: [NBTAPI] Adding listeners...
    [04:30:46 INFO]: [NBTAPI] Checking bindings...
    [04:30:46 INFO]: [NBTAPI] [NBTAPI] Found Spigot: v1_15_R1! Trying to find NMS support
    [04:30:46 INFO]: [NBTAPI] [NBTAPI] NMS support 'MC1_15_R1' loaded!
    [04:30:46 INFO]: [NBTAPI] [NBTAPI] The NBT-API seems to be up-to-date!
    [04:30:46 INFO]: [NBTAPI] Gson:
    [04:30:46 INFO]: [NBTAPI] [NBTAPI] Found Gson: class com.google.gson.Gson
    [04:30:46 INFO]: [NBTAPI] Classes:
    [04:30:46 INFO]: [NBTAPI] All Classes where able to link!
    [04:30:46 INFO]: [NBTAPI] Methods:
    [04:30:46 INFO]: [NBTAPI] All Methods where able to link!
    [04:30:46 INFO]: [NBTAPI] Running NBT reflection test...
    [04:30:46 WARN]: [NBTAPI] Error during 'NBTFileTest' test!
    de.tr7zw.nbtapi.NbtApiException: Exception while reading a NBT File!
            at de.tr7zw.nbtapi.NBTReflectionUtil.readNBTFile(NBTReflectionUtil.java:59) ~[?:?]
            at de.tr7zw.nbtapi.NBTFile.<init>(NBTFile.java:33) ~[?:?]
            at de.tr7zw.nbtapi.plugin.tests.NBTFileTest.test(NBTFileTest.java:17) ~[?:?]
            at de.tr7zw.nbtapi.plugin.NBTAPI.onEnable(NBTAPI.java:118) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[patched_1.15.1.jar:git-Paper-33]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:338) ~[patched_1.15.1.jar:git-Paper-33]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:420) ~[patched_1.15.1.jar:git-Paper-33]
            at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:468) ~[patched_1.15.1.jar:git-Paper-33]
            at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:382) ~[patched_1.15.1.jar:git-Paper-33]
            at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:481) ~[patched_1.15.1.jar:git-Paper-33]
            at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:290) ~[patched_1.15.1.jar:git-Paper-33]
            at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:884) ~[patched_1.15.1.jar:git-Paper-33]
            at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]
    Caused by: de.tr7zw.nbtapi.NbtApiException: Error while calling the method 'a', loaded: true, Enum: NBTFILE_READ
            at de.tr7zw.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:148) ~[?:?]
            at de.tr7zw.nbtapi.NBTReflectionUtil.readNBTFile(NBTReflectionUtil.java:57) ~[?:?]
            ... 12 more
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_232]
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_232]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_232]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_232]
            at de.tr7zw.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:146) ~[?:?]
            at de.tr7zw.nbtapi.NBTReflectionUtil.readNBTFile(NBTReflectionUtil.java:57) ~[?:?]
            ... 12 more
    Caused by: java.io.EOFException
            at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:268) ~[?:1.8.0_232]
            at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:258) ~[?:1.8.0_232]
            at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:164) ~[?:1.8.0_232]
            at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:79) ~[?:1.8.0_232]
            at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:91) ~[?:1.8.0_232]
            at net.minecraft.server.v1_15_R1.NBTCompressedStreamTools.a(NBTCompressedStreamTools.java:18) ~[patched_1.15.1.jar:git-Paper-33]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_232]
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_232]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_232]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_232]
            at de.tr7zw.nbtapi.utils.nmsmappings.ReflectionMethod.run(ReflectionMethod.java:146) ~[?:?]
            at de.tr7zw.nbtapi.NBTReflectionUtil.readNBTFile(NBTReflectionUtil.java:57) ~[?:?]
            ... 12 more
    [04:30:46 INFO]: [NBTAPI] MergeTest: Ok
    [04:30:46 INFO]: [NBTAPI] ForEachTest: Ok
    [04:30:46 INFO]: [NBTAPI] TilesCustomNBTTest: Ok
    [04:30:46 INFO]: [NBTAPI] NBTFileTest: Exception while reading a NBT File!
    [04:30:46 INFO]: [NBTAPI] GetterSetterTest: Ok
    [04:30:46 INFO]: [NBTAPI] EntityTest: Ok
    [04:30:46 INFO]: [NBTAPI] EntityCustomNbtTest: Ok
    [04:30:46 INFO]: [NBTAPI] RemovingKeys: Ok
    [04:30:46 INFO]: [NBTAPI] ItemConvertionTest: Ok
    [04:30:46 INFO]: [NBTAPI] TypeTest: Ok
    [04:30:46 INFO]: [NBTAPI] EmptyItemTest: Ok
    [04:30:46 INFO]: [NBTAPI] SubCompoundsTest: Ok
    [04:30:46 INFO]: [NBTAPI] ListTest: Ok
    [04:30:46 WARN]: [NBTAPI] WARNING! This version of NBT-API seems to be broken with your Spigot version! Plugins that don't check properly may throw Exeptions, crash or have unexpected behaviors!
     
  13. Huh thats not directly a "broken" problem, just a selfcheck failing because the testfile seems to be broken. Try deleting the "plugins/nbtapi/test.nbt" file. For the next version I'll add an autodelete before, so a broken nbt testfile won't spam the console every startup.
     
  14. LoneDev

    Supporter

  15. Well, the nbt api has way more features (for example lists, access vanilla data, converting data like Items/Entities/Tiles into json/nbt, using nbt files etc) and works in 1.8-1.15 (not 1.14+). For performance the PersistantDataContainers are probably faster since they are able to modify the server itself. But thanks for pointing this api out, I'm currently working on a data api that allows way deeper and simple access to vanilla data, and it could be interesting to add wrappers for any nbt compound you want, implementing the PersistantDataContainer. I'll also look into how it saves custom data to Entities, maybe it will allow me to discontinue the nbt-injector for 1.14+ and just fake the data into the right location.
     
  16. LoneDev

    Supporter

    Thanks a lot! You should probably add this message to FAQ :D

    I will stay with NBT api, as it's less limited
     
  17. Hi tr7zw, first of all thanks for creating this API but I have a problem that may be really stupid.
    When I imported all the files of the NBT API into my project I got an error, two of the classes (NBTTileEntity and NBTEntity) have an import (de.tr7zw.annotations.FAUtil that isn't in the files that I imported. I went to github to search this class but I couldn't find it, if you could tel me where can I find this class I'll be really gratefull!
     
    #137 Nemo_64, Jan 17, 2020
    Last edited: Jan 18, 2020
  18. Join the discord for better/quicker talking with each other. The FAUtil import has been added in the newest commits and so far is only in the repo and in the not yet released snapshots. How did you import the API? Did you use Maven? Have you shaded the correct Project(item-nbt-api, not item-nbt-api-plugin)?
     
  19. Just as an FYI: Managed to hijack the NBTTag used by the PersistentDataAPI as a NBT-Injector replacement. The newest snapshots allow the 1.14/1.15 to migrate the injector data to the PersistentData Storage. With 1.16 I'll stop updating the Injector and just add rewire it to use the new api.
     
    • Useful Useful x 1
  20. I dowloaded it from github and imported the item-nbt-api folder