-
-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix-count-entities #4356
Open
ch4ika
wants to merge
5
commits into
IntellectualSites:main
Choose a base branch
from
ch4ika:fix-count-entities
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix-count-entities #4356
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5de34d
fix-count-entities
ch4ika 9c6078c
Simplify array assignment
ch4ika f8c7124
Fix entity filtering in chunk to match plot boundaries
ch4ika a120e49
Fix asynchronous loading issue causing premature count return
ch4ika 9720a91
Implement asynchronous entity check
ch4ika File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1220,15 +1220,13 @@ public boolean removeFlag(final @NonNull PlotFlag<?, ?> flag) { | |
*/ | ||
public int[] countEntities() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably deprecate the "old" sync methods if moving to async |
||
int[] count = new int[6]; | ||
for (Plot current : this.getConnectedPlots()) { | ||
int[] result = this.regionManager.countEntities(current); | ||
count[CAP_ENTITY] += result[CAP_ENTITY]; | ||
count[CAP_ANIMAL] += result[CAP_ANIMAL]; | ||
count[CAP_MONSTER] += result[CAP_MONSTER]; | ||
count[CAP_MOB] += result[CAP_MOB]; | ||
count[CAP_VEHICLE] += result[CAP_VEHICLE]; | ||
count[CAP_MISC] += result[CAP_MISC]; | ||
} | ||
int[] result = this.regionManager.countEntities(this); | ||
count[CAP_ENTITY] += result[CAP_ENTITY]; | ||
count[CAP_ANIMAL] += result[CAP_ANIMAL]; | ||
count[CAP_MONSTER] += result[CAP_MONSTER]; | ||
count[CAP_MOB] += result[CAP_MOB]; | ||
count[CAP_VEHICLE] += result[CAP_VEHICLE]; | ||
count[CAP_MISC] += result[CAP_MISC]; | ||
ch4ika marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return count; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loading chunks async will break things;
count
is returned before the chunk is loaded (that was flawed before too, I guess). For very large plots, this might be important, but that means we either need to come up with something clever or load all chunks before starting counting.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it and played around, but unfortunately I can't really think of a simple idea that would allow for performance-friendly loading for larger plots without making any really big changes.
The whole thing is now in sync and works perfectly, but would cause lag on larger properties.
Unfortunately, the way it is currently being done is not the right solution either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution would be to query the async and if it overwrites the caps, remove the entity.
There would still be a meta missing, in the time when it hasn't been removed yet, that you can't remove or kill it.
Before I continue with it, the question is whether it makes sense or whether there is a better option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the short-term best solution is to just ignore unloaded chunks. That will result in the same behavior as the current code if I didn't miss anything. It also isn't a problem for a vast majority of servers I guess.
Long-term, we probably need to rethink the concept or come up with a solution to store the entity count of unloaded chunks somehow.
Removing entities later likely is a bad idea, as we would need to track how the entity was created (i.e. via spawn eggs, you'd need to give the spawn egg back to the player, etc...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. As an alternative, I'm also thinking of caching the whole thing somehow.
Because the solution with checkAsync works, but as you already said, too many additional checks would have to be made and the events would not really be cancelable.
The whole thing is breaking my head. If anyone wants to give that, I would be grateful. Otherwise, I would try it again as soon as I have time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably just open an issue for it so we can keep track of it. I don't think it's worth to spend too much time on it right now, the fix for merged plots is far more important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is I had already made several tickets about it, but @OneLiteFeather kept marking them as invalid because she didn't understand the problem and wasn't open to discussing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are open for discussions but not mixing up contexts or creating incorrect issues. Also we do no private support including voicechat and discord dms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, you can now be sure that this problem exists and that you can reproduce it without any problems. I'll write another proper ticket in a few days to record it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue to keep track of it: #4362