[Question] Is there anything you can identify a horse/donkey with?

Discussion in 'Spigot Plugin Development' started by TheMrJezza, Jun 23, 2015.

  1. Hey everyone, I just have a quick question. is there anything like a UUID you can identify a horse with? I would just use UUID's but they change every time the server starts so they are no good. And that's it, thanks in advance. And I'm sorry if the answer is really obvious. :)
     
  2. sothatsit

    Patron

    I wouldn't think the UUID's should change, but they may do. If the UUID doesn't work try the entity's internal id.

    You can use Entity.getEntityId() to get the entities internal id.

    Otherwise i don't know how you would track them.

    You could append your own id to their display name using ChatColor's, but this isn't ideal, you would have to manage players renaming their horses. Try the entity id first, and if that doesn't work then post here again.
     
  3. Nope the entityId changes after a restart just like the UUID. Any other ideas? All need this for is so I can save the horse to a file under its owners uuid and load it when I need it.
     
  4. This is how you get the horse
    Code (Text):
    Horse horse = (whatever way you get the horse)

    Variant v = horse.getVariant();
    This is how you set the horse
    PHP:
              Location loc = p.getLocation();
              World w = p.getWorld();
              String world = w.getName();
              Horse horse = (Horse)Bukkit.getWorld(world).spawnEntity(loc, EntityType.HORSE);


    horse.setVariant(v);

    try to save the variant in a yml config file if you want!
     
  5. sothatsit

    Patron

    You can either save all the details about the horse in a database/config. Removing the horse on chunk unload and loading it again on chunk load. Or, you could put your own unique Id in its display name. To put an ID in its display name you would convert your own integer id to chat colours, then append the chat colours to its display name. To convert it to chat colours you can convert the number to hexadecimal and prepend each character with an &, then use the translateAlternateColorCodes method to turn it into chat colours. To convert it back again you would use the stripColor method and then convert it from hexadecimal to an int.
     
  6. Is it possible to set fixed metadata to an entity? It could work.
     
    #7 TheMrJezza, Jun 24, 2015
    Last edited: Jun 24, 2015
  7. Custom MetaData will clear after server restart.
    One of possible methods is UUID because Entity UUID doesn't change after server restart.
    But if I'm wrong and Entity UUID will change after server restart just save it to the config file.
     
  8. I was thinking of using getOwner() and setOwner, but the owner would reset when another player sits on the horse won't it?
     
  9. Yes it does, I have tried it and tested it. I even made a command just to see uuid's, a restart resets them. Thanks for the idea though.

    These reset with a server restart.
    - EntityID's
    - Entity UUID's
     
  10. Rly? The last idea which I have is saving Entity UUID's to file.
     
  11. As already mentioned try out adding color codes to the display name as a unique identifier
     
  12. Tux

    Tux

    I haven't observed UUIDs resetting on server restart, but this was with villagers and in the spawn chunks.
     
  13. I want to save the horse to a file somehow, but if I use UUID's or EntityID's, they will change so it won't be the same as the file and it will become 100% useless after a restart.
     
  14. Hey what about the color code thing?
     
  15. @Janmm14 do you mean ChatColor.RESET + "Horse Name"...?

    Edit: I'm just worried about how many combinations I could use before I run out
     
    #17 TheMrJezza, Jun 24, 2015
    Last edited: Jun 24, 2015
  16. Try adding NBT tags to the horse.
     
  17. Never used NBT, so I wouldn't know how.
     
  18. sothatsit

    Patron