Paper icon indicating copy to clipboard operation
Paper copied to clipboard

NamespacedKey based plugin chunk tickets

Open Trigary opened this issue 5 years ago • 18 comments

A work-in-progress (at the time of creation) implementation of NamespacedKey based plugin chunk tickets. The reasoning behind the creation of this API can be found in https://github.com/PaperMC/Paper/issues/4147

State of draft PR:

  • ~~yet to be tested~~
  • ~~yet to receive JavaDocs~~

Trigary avatar Aug 22 '20 12:08 Trigary

Thanks for the review, I shall make these changes.

Trigary avatar Sep 10 '20 09:09 Trigary

I apologize for the delays, I finally made the requested changes.

There is one thing that's definitely not finished yet (they produce a compile error at the moment): there are two getter methods that list chunks that have these keyed plugin chunk tickets. What should they return?

  • return Chunk instances, possibly forcing sync chunk loads
  • return some sort int-int pair (the X, Z coordinates of the chunk) (I don't think this chunk coord pair class exists in the API yet)
  • return Chunk instances for loaded chunks and specify in the JavaDocs that only already loaded chunks are returned, so not yet loaded chunks must be handled manually somehow

Another questionable implementation is CraftWorld#removeKeyedPluginChunkTicket(x, z, org.bukkit.NamespacedKey). It iterates over the TickingLevel values and tries to remove them one-by-one. The alternative is to iterate over the tickets that actually exist in the chunk and remove the correct iterator. The issue with this 2nd option is that removing a ticket is a bit harder to implement, I'm afraid I might make mistakes. And the issue with the 1st option is the performance overhead, heap allocations.

All of these WIP / not finished methods have TODOs in them, that's an easy way to find them.

Trigary avatar Nov 30 '20 12:11 Trigary

I think you have a slight bit of confusion. TickingLevel.NONE is still going to be returned in Loaded Chunks.

These chunks will be loaded, just at BORDER status. TickingLevel.NONE = Border

aikar avatar Nov 30 '20 15:11 aikar

They will be loaded, but only asynchronously as far as I know, but I might be wrong. So the getter method might catch them when they are not yet loaded, just being loaded. In this case a Chunk does not yet exist AFAIK.

Trigary avatar Nov 30 '20 15:11 Trigary

Hmm I see, in that this API is meant to return chunks that have a plugin ticket but since they are loaded async does present a window they havent finished yet.

Returning a collection of Long's does make more sense than chunks, and people can re-map it to Chunk objects and filter by loaded status on their own if needed.

Or even provide a .getKeyedPluginChunkTicketLoadedChunks that does the filtering for you.

aikar avatar Nov 30 '20 15:11 aikar

Thank you for your response, I shall make the necessary changes and finalize the PR.

Trigary avatar Nov 30 '20 16:11 Trigary

I am considering this done, apart from testing: I am yet to actually test these additions in action.

Ignore the failed GitHub Actions check. It worked fine locally on WSL and on Git Bash (on 2 separate PCs) and Z750 also believes that GitHub Actions is the culprit here.

Trigary avatar Dec 03 '20 19:12 Trigary

I have finished testing, everything seems to be in order, I am marking this PR as ready, non-draft. For possible future uses, this is what I used for testing: https://pastebin.com/S1B4NKAC

Trigary avatar Dec 12 '20 10:12 Trigary

The CI does not seem to be in order, actually :p

Proximyst avatar Dec 13 '20 15:12 Proximyst

@Proximyst

The CI does not seem to be in order, actually :p

Have you read the 2nd paragraph of this comment of mine? https://github.com/PaperMC/Paper/pull/4173#issuecomment-738248042

Trigary avatar Dec 13 '20 15:12 Trigary

Tried forcepushing to have GH Actions retry? We can't merge without it passing 😅

Proximyst avatar Dec 13 '20 15:12 Proximyst

CI is having none of it by the looks of it

Trigary avatar Dec 13 '20 16:12 Trigary

Well that's because it's trying to merge 1.16.3 code into 1.16.4; there will quite often be some kind of issue. I've rebased your PR for you.

Proximyst avatar Dec 13 '20 16:12 Proximyst

Makes sense, thank you.

Trigary avatar Dec 13 '20 16:12 Trigary

I have improved the JavaDocs. There was some outdated stuff in there, I removed that. I improved the wording here and there. I also documented what happens when chunk tickets are added to unloaded chunks (the chunk gets loaded async).

I have also moved the removeKeyedPluginChunkTickets(Plugin) call from removePluginChunkTickets(Plugin) to SimplePluginManager. Aikar once told me to put it inside removePluginChunkTickets(Plugin), but I'm confident keyed plugin chunk tickets shouldn't be removed just because non-keyed ones are removed through removePluginChunkTickets(Plugin). Feel free to tell me to revert that though if you believe this change is bad.

I have moved the TickingLevel class to the io.papermc.paper.world package from io.papermc.paper. I have also switched to using import statements. Again, feel free to tell me to revert.

Still awaiting review.

Trigary avatar Feb 10 '21 22:02 Trigary

Closing PR, as it seems that this has gone inactive.

If you're still interested in continuing this PR, feel free to leave a comment and we can reopen it for you. 😄

Owen1212055 avatar Oct 23 '22 15:10 Owen1212055

I am still interested in continuing this PR. I am just waiting for a review.

Trigary avatar Oct 23 '22 20:10 Trigary

I am still interested in continuing this PR. I am just waiting for a review.

Would you be able to rebase it? 😄

Owen1212055 avatar Oct 23 '22 21:10 Owen1212055

See above, if you are still interested in continuing, please feel free to rebase this pr. 😄 It should be noted that upstream has added some methods to get tick levels for chunks to the API.

Owen1212055 avatar May 18 '23 12:05 Owen1212055