Does cancelling a ChunkUnloadEvent really keeps the chunk alive?

Discussion in 'Plugin Development' started by maystorm, Mar 18, 2014.

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

    maystorm

    Hi all,

    I am working on a plugin which prevents chunks from being unloaded. My current implementation follows this simple logic:

    - A listener method is called upon each ChunkUnloadEvent
    - In this method I compare the chunk to be unloaded with the coordinates of my chunk which should stay loaded
    - If the comparison is true the method event.setCancelled(true) is called and a broadcastMessage() is sent so I can see that and when this happens.

    So far it seems to work fine. When I walk far away from the chunk I eventually receive the message that my chunk is going to be unloaded and that this event is being cancelled. I am quite sure that this is working as the system tries to unload the same chunk again and again every 30 seconds but due to my cancel request it stays loaded.

    However, now to my question: Does a chunk of which the unload has been cancelled really stays alive? With "alive" I mean do seeds and trees keep growing and would items despawn over time? I made some tests but unfortunately the unload-blocked chunk seems to be "dead" as my seeds which I had planted before wouldn't grow during my absence.

    Am I missing something or do loaded chunks need players in the neigbourhood to receive/process nature events?

    Many TIA!
    maystorm
     
  2. Offline

    AtomSponge

    After cancelling the event, schedule a delayed task with a delay of one tick and load the chunk again.
     
  3. Offline

    maystorm

    AtomSponge: Hmm, doesn't seem to make any difference. Additionally, explicitly chunk.load()'ing a chunk of which the unload has been cancelled doesn't generate a ChunkLoadEvent (which would make sense since the chunk is still loaded after the cancellation).

    So, I'm pretty sure the prevention of chunk unload is working and the chunk is persistent now, however, still no plants are growing or items are decaying.

    EDIT:

    I need to correct myself: items ARE actually decaying in the persistent chunk. However, any idea how to get seeds and plants (e.g. cacti) to grow?
     
  4. Offline

    AtomSponge

    maystorm: Hm... but redstone and stuff is still processing, right? Are you sure, that plants aren't growing?
    Have you tried a longer delay?
     
  5. Offline

    maystorm

    AtomSponge: Yes, I waited for like half an hour before I returned to the chunk. Items (like dropped dirt blocks) have despawned in the meantime (they were still there in adjacent but non-persistent chunks), but my seeds have not grown a single millimeter and saplings are still saplings. Leaves blocks from a cut down tree have also not decayed.

    This evening I will run some tests with redstone circuits to see whether this stuff is working and try out other plants like cacti and sugar canes.

    And yes, for the delayed scheduler task I also tried values like 5 and 10 instead of 1 tick, but to no avail.
     
  6. Offline

    RawCode

    what about opening source code of cbukkit and checking what happens if event is cancelled?

    answer yes.
     
  7. Offline

    maystorm

    RawCode: If the answer is yes why would plants not grow?

    For me it seems that everything block related (e.g. growing seeds & saplings, leaves decaying, dirt blocks turning into grass blocks etc) does not work in a persistant chunk if there is no player in close distance. If this is the intended behaviour than this would answer my question and I don't need to look further down the road.
     
  8. Offline

    RawCode

    open source and you will have answers.

    vanilla do have permanently loaded chunks - spawn area, just check how it handled and do exactly same.
     
  9. Offline

    maystorm

    Yes, I could dig into the sources and spend days to understand them. By doing this almost every question here can be answered and we wouldn't need a forum.

    I thought that someone would have an answer by heart and would be willing to share his/her knowledge. If this is not the case then the last ressort, of course, is always the source code.
     
  10. Offline

    RawCode

    you never opened source, how can you estimate time required to understand it?
     
  11. Offline

    maystorm

    Do you think that you can estimate the time I need to understand the code?

    Can we get back to topic, pls? I appreciate your hint to look up the source code. But I only would like to write a simple and small 20-liner plugin using the Bukkit API and would like to avoid crawling into someone else's sources just to find out how the core works. This is one of the the reasons why the API is there, right?

    Perhaps there is someone around who knows by heart how it works and is willing to share his knowledge of how chunks and their containing blocks are updated?

    TIA

    Well, wrong hint.

    Although spawn area has persistent chunks the same happens there: items like dropped blocks despawn, but plants wouldn't grow and leaves blocks wouldn't decay unless a player is nearby.

    I come to the conclusion that keeping chunks unloaded alone doesn't cater for block events taking place. Items/drops/objects, however, do seem to get processed. Redstone needs to be tested yet.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
    AtomSponge likes this.
  12. Offline

    RawCode

    dig more, world update ticks have separate method with set of checks.

    also you can just add dummy players at areas you want to hold active.
     
  13. Offline

    maystorm

    If I asked: "How are dummy players added to the world?" will I get usable help or just a simple "Dig into the sources?"

    In case of the former: TIA.
     
  14. Offline

    RawCode

  15. Offline

    maystorm

    Thanks.

    Nope, doesn't work at all.

    Using that plugin and placing a virtual player at a certain location doesn't do any updates to the world's environment at that location. No item despawning nor any other block updates. The server is obviously not aware of those virtual players.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page