NBT Tag not working?

Discussion in 'Plugin Development' started by StaticJava, Dec 25, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    StaticJava

    Hello Bukkit,

    I am using the NBT Tag Lib located at http://bukkit.org/threads/library-edit-or-create-nbt-tags-with-a-compact-class-no-obc-nms.178464/ or https://github.com/aadnk/AttributeStorage, but am having an issue - I don't know whether it is I who is doing something wrong or it is the library.

    I am essentially writing a test method to grab the SkullOwner tag from the ItemStack if and only if it is a Skull Item. Here is the method: http://pastebin.com/EGcHgdWm

    Here is the error: http://pastebin.com/hyq0ERQw

    Any help is appreciated,
    ~StaticJava

    @Comphenix
     
    Last edited: Dec 25, 2014
  2. Offline

    teej107

    You don't need to use NBT data to get the skull owner. And the error is this:

    1. Caused by: java.lang.ClassCastException: com.comphenix.attribute.NbtFactory$NbtCompound cannot be cast to java.lang.String
    2. at me.staticjava.BackPack.saveNBT(BackPack.java:126) ~[?:?]
     
    Konato_K likes this.
  3. Offline

    StaticJava

    I know I don't need to use NBT for this, but I need NBT for other things I will be doing, so I wrote this method as an easy test to check if it worked. Additionally, I don't see what is wrong - I am not casting an NBTCompound to a String; I am using the getPath() method within the NBTCompound class... @teej107
     
  4. Offline

    teej107

  5. Offline

    StaticJava

    @teej107 On the first pastebin in OP, I wrote a comment ("error on this line").
     
  6. Offline

    teej107

    @StaticJava Ah, Well com.comphenix.attribute.NbtFactory$NbtCompound obviously can't be cast to a String. Check its methods to see what you can do with it.
     
  7. Offline

    StaticJava

    @teej107 I'm not casting it to a String though... :/ I'm using the method getPath().....
     
  8. Offline

    teej107

    @StaticJava You are assigning it to a String
     
  9. Offline

    StaticJava

    @teej107 But that's not casting it... In the NbtCompound class, there is a method called getPath which returns any Object... Why would that return an error?
     
  10. Offline

    teej107

    Because you are assigning the Object to a String but the Object is not a String!
     
  11. Offline

    StaticJava

    @teej107 So how can I fix this? How can I use NBT to get the skull owner?
     
  12. Offline

    teej107

    I haven't used the library but from looking at the library's thread, try
    compound.getString();
     
  13. Offline

    StaticJava

    @teej107 I still get that exact error. :/
     
  14. Offline

    teej107

  15. Offline

    StaticJava

  16. Offline

    teej107

    @StaticJava Are you sure the data you are getting is even a String?
     
  17. Offline

    StaticJava

    It's the SkullOwner tag... @teej107
     
  18. Offline

    Konato_K

    @StaticJava Isn't the tag a nbt compung including the name, the texture, and other fancy data?
     
  19. Offline

    StaticJava

    @Konato_K Yes, that is what an NBT Tag is. :)
     
  20. Offline

    Konato_K

    @StaticJava and you can't figure out the problem? The method returns a NBT tag object, and you're trying to casting to a String.
     
  21. Offline

    StaticJava

    @Konato_K Sorry, I'm really new to this. So how would I get the SkullOwner from an NbtCompound?
     
  22. Offline

    Konato_K

    @StaticJava I have never used NBT to do stuff with Minecraft, but NBTTagCompound has a getString method, so I guess something like getString("owner") or getString("name") might work, but as I said, I've never worked with this before.
     
  23. Offline

    StaticJava

    @Konato_K That's what I'm doing...and I get that error.
     
  24. Offline

    CorrieKay

    Hmm. Try "SkullOwner.Name" real quick, instead of "SkullOwner". See if that works.

    The reasoning that its saying youre trying to cast it into a string, is because, well, while YOU yourself are not attempting to cast it into a string, the api you're using IS.

    Code:
    @SuppressWarnings("unchecked")
    public <T> T getPath(String path) {
      List<String> entries = getPathElements(path);
      NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
      
      if (map != null) {
        return (T) map.get(entries.get(entries.size() - 1));
      }
      return null;
    }
    
    See how its using the generic T? You somehow set it to return a string, and its automatically attempting to cast the return into a string.

    [​IMG]
    Considering "SkullOwner" is a compound tag, not a string, that contains a string tag called "Name", its trying to cast a CompoundTag into a String.
     
    StaticJava likes this.
  25. Offline

    Konato_K

    @StaticJava I mean, to use "SkullOwner" to get the tag compount AND use getString in that tag, you're just getting the tag and cast it.
     
  26. Offline

    StaticJava

  27. Offline

    nverdier

    So this is solved?
     
  28. Offline

    StaticJava

    @nverdier @CorrieKay @Konato_K Actually, one more problem.

    When putting data into an NbtCompound, it never actually appears to have an effect on the item. Here is how I load NBT:

    Load method - http://pastebin.com/stcXGgJT
    Load method in use - http://pastebin.com/HWKeJ15e

    As seen in the load method, the NbtCompound is indeed being populated by a correct SkullOwner. However, in-game, the skull has no SkullOwner and is named Head as opposed to StaticJava's head. Is the NbtCompound being reset or not even being applied to the itemstack?

    Thanks!
     
    Last edited: Dec 25, 2014
Thread Status:
Not open for further replies.

Share This Page