Solved Possible to load a plugin before entities are loaded?

Discussion in 'Plugin Development' started by Phiwa, Mar 6, 2013.

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

    Phiwa

    Hey guys and lads,

    like some of you know, I am the developer of the plugin "DragonTravel" and we use reflection to implement the ne entity "XemDragon" on plugin-startup to be able to control dragons.
    We also have a function which enables admins to create "stationary dragons" which only contribute to the design of the server. ;)

    I now came across a problem because on server-startup, all stationary dragons are skipped by the server because it loads the entities before it loads DragonTravel and therefore simply does not know the entity "XemDragon" when loading the entities.

    Is there a way similar to the dependencies on other plugins to be able to force the server to first load DragonTravel and after that the entities?
    I guess not because this would mess up the whole starting-process of the server, but maybe there is a genius among you who knows to achieve that and this way helps me to avoid spawning all dragons manually which would require me to save them in another database. ;)

    Kind Regards
    Phiwa
     
  2. You can make your plugin load beofre the main world is loaded by adding
    Code:
    load: STARTUP
    to your plugin.yml file, but that won't solve your problem, at least if I remember my attempts correctly ;)

    The entity is stored just like a normal one in the world file. The server loses track of the information that it used to be your special custom entity as soon as it saves it in NBT format.
    In order to get your dragon to work, you probably modified the mappings in the EntityTypes class so it displays on the client. Well, this is also used when saving and loading entities. And because you told it that "MyCustomDragonClass" has a representation of a dragon, that's what it's saved as.

    When loading, you can no longer distinguish between a standard dragon and your custom one. And minecraft doesn't automatically construct your custom class.


    Here's what I do (it's pesky, I know):
    - when the plugin disables / the chunk unloads / the world unloads
    ---> check for custom entities, store their UUIDs
    - whenever a chunk loads, iterate over entities and "hot-swap" matching UUIDs with your custom class; depending on the amount of details that you need to retain, this might become ugly.

    Alternatively, you could manually despawn the entity when unloading and store all of its attributes. So nothing is actually saved in the world file itself.
    Then, when the world/plugin loads, spawn all your custom classes back in and load their data.
    Note that this is most likely the more elegant solution, for 2 reasons:
    1. The world file stays untouched, so when your plugin is removed, there won't be any dragons set on free foot (or wings :O) because your plugin is no longer controlling them ;)
    2. You can easily use the built-in save and load methods of entities to get the data into and from NBT format.


    I hope you can go somewhere with these basic ideas ^^
     
  3. Offline

    Phiwa

    First of all big thanks for your detailed answer!

    Might be worth a try. :)

    It stores it as a XemDragon at that position, but when trying to spawn a XemDragon on server-startup it gives the message
    for each XemDragon it has stored.
    XemsDragons are a new entity-class extending the EnderDragon-entity

    I thought I could avoid that, but if the above solution does not work, I'll do that.
    The good thing is that there are no information needed except the position which I would then store in a flatfile-db like the stations/destinations/homes etc., so I simply need to spawn a new XemDragon for each entry in the database and I'm finished. :)

    1. This ia a good point, but maybe I don't want admins to be able to live without DragonTravel. :p
      Only joking. ;)
    2. Isn't even needed in my case, but if the dragons had more customization, this would be important.
    Thanks for this great answer within this short period of time!
    Have a nice day. :)




    EDIT:
    The solution of "load: STARTUP" in the plugin.yml really works!
    Thanks mate! :)
     
Thread Status:
Not open for further replies.

Share This Page