Solved Persistent Custom Entities in 1.15.1?

Discussion in 'Spigot Plugin Development' started by SeanOMik, Jan 20, 2020.

  1. Is there a way I could create a persistent custom entity in Spigot 1.15.1?
     
  2. Could you elaborate on what you mean? You man an entitiy with custom attributes? If you set whatever-entity to never despawn, it will be persistent unless killed by command
     
  3. I'm the author of this plugin: https://www.spigotmc.org/resources/tamable-foxes-1-14-2-1-14-4-1-15-1.69537/ and currently users report a lot of issues with the custom tamable fox entity not staying tamed or disappearing after a server restart. The reason this happens is because the custom entity doesn't stay in the world after a server restart so I have to save all the data for a specific fox in a yml file and find the EntityFox (which is what EntityTamableFox extends and what they get replaced by after a server restart) that matches a specific fox, spawn a tamable fox and kill the EntityFox.

    This of course doesn't always work and throws NullExceptions a lot, makes foxes disappear, or have them not be tamed after a server restart.

    Edit: Theres also a github on that plugin page if you want to look at some code. If you need more info, ask me.
     
  4. First off damn that's cute af. Love those foxes.

    But why on earth is that plugin 30 MB large? :|
     
  5. I'm not really sure tbh. You could check the github: https://github.com/SeanOMik/TamableFoxes. Right now I'm trying to make the plugin stable though.

    Edit: If it matters, when I use my own command to spawn a fox, they spawn fine. They're still not server restart persistent.
     
  6. youre shading spigot into your jar, set its scope to provided <scope>provided</scope>
     
    • Informative Informative x 1
    • Useful Useful x 1
  7. I think's that something you should definitly investigate, according the github should only be like 200 kB at most? I can't really say im not very experienced yet.

    Did you anywhere try to do use .setPersistent and/or .setRemoveWhenFarAway on your custom foxes? i couldnt find that anywhere on the git
     
  8. Yeah, that the reason. The jar file is now 112kB.

    I did try the `.setPersistent` but that doesn't fix the issue. I'm trying to fix that when the server restarts, the fox turns into a EntityFox instead of a EntityTamableFox
     
  9. oh im sorry, then i misunderstood you. i thought you meant that your entities despawn
     
  10. You need to save the tamed entity into a file or a database and once the server restart spawn them again
     
  11. I remember this being an issue in previous Spigot versions with custom NMS entities not being properly registered. You could create an instance of that custom entity once, but once the server restarted it would switch back to its vanilla version. I'd have to look into how it works in 1.15, because NMS tends to change with each update, but I'd be willing to bet that's it
     
  12. Thats exactly whats happening.

    I'm already doing that but it causes issues. Check the discussion tab https://www.spigotmc.org/resources/tamable-foxes-1-14-2-1-14-4.69537/
     
  13. https://www.spigotmc.org/threads/tamable-foxes-1-14-2-1-14-4-1-15-1.384841/page-2#post-3484826
    https://www.spigotmc.org/threads/tamable-foxes-1-14-2-1-14-4-1-15-1.384841/page-2#post-3484829
    https://www.spigotmc.org/threads/tamable-foxes-1-14-2-1-14-4-1-15-1.384841/page-3#post-3569918

    And its that sometimes the plugin doesn't find a spawned entity, or sometimes it doesn't save a fox's data or a wrong UUID. I'm not sure why it doesn't always work because I feel like it should theoretically
     
  14. What I would do for that kind of plugin:
    On disable: delete every tamed foxes, save their info in a file or a database (owner uuid, location, anything else that matters EXCEPT the entity ID cause this is useless, we deleted the entity).
    On enable: query from the file or database to get every tamed foxes and if their owner is online spawn them at the saved location, give them the name from the database and stuff
     
  15. Okay, I'll try that. Thanks!
     
  16. I didn’t know foxes even existed in Java! Maybe use a database instead of a yml, and save the database inside the world’s folder?
     
  17. Have you tried to register your EntityType before world loading ? Also if you want to save the owner you have to override the Entity#save and Entity#load methods.

    If you want to save manually your custom entity and spawn it after server load you can save its data in a .dat file using an API like EntityMetadataApi. With this API you can get your fox's NBTTagCompound then save/load it using NBTOutputStream/NBTInputStream.

    NBT (.dat) is the format used by Minecraft to save data. It's very lightweight and fast to read/write
     
    #18 Il_totore, Jan 21, 2020
    Last edited: Jan 21, 2020
  18. Usw the persistent data API of Spigot instead.
     
  19. The persistent data API is not very useful here because the example with EntityMetadataAPI was for saving the entity in external file to make it persistent if the injection method doesn't work.