Custom Name of Non-Living Entity

Discussion in 'Plugin Development' started by Techy4198, Apr 26, 2014.

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

    Techy4198

    Hi, i'm working on something and i need to know how to get the custom name of a minecart. i know for definite that it's stored, because....
    1) i checked with an nbt editing plugin (PowerNBT), the minecart DOES store a 'CustomName' tag.
    2) if you rename a minecart to 123examplename, place it on a rail, clear your inventory, then break the minecart and look at the dropped item, you will see that it is still called 123examplename.

    the trouble is, bukkit only supports getting the name of living entities, unless you start doing all sorts of version-dependent code (org.bukkit.craftbukkit.[VERSION].blablabla). i do not want this. i need a way to get the custom name of the minecart through bukkit.
     
  2. Offline

    DPOH-VAR

  3. Offline

    Techy4198

    also worth noting, i already tried using CraftMinecart entities to get the name, which was for some reason throwing NPEs all the time.
     
  4. Offline

    Superckl1

    You need to use some sort of reflection if you don't want it to be version dependent. Whether it is through a library or not is up to you.
     
  5. Offline

    Techy4198

    Superckl1 i never said i wasnt going to use reflection... i just said that if i DO make it version dependent, it gives errors, i havent tested using reflection yet though. if that throws errors too, i will post my code here and see if anyone can spot a mistake.
     
  6. For anyone who found this thread:
    I found the solution :D
    Code:
    EntityMinecartAbstract handle = (EntityMinecartAbstract) ((CraftEntity) minecart).getHandle();
    
    handle.a("Custom Name");
    Works for StorageMinecarts
     
Thread Status:
Not open for further replies.

Share This Page