-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add luckperms context support for worldgroup. #438
Open
benwoo1110
wants to merge
1
commit into
main
Choose a base branch
from
luckperms-contexts
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
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions
41
...java/com/onarandombox/multiverseinventories/dependencies/WorldGroupContextCalculator.java
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.onarandombox.multiverseinventories.dependencies; | ||
|
||
import com.onarandombox.multiverseinventories.MultiverseInventories; | ||
import com.onarandombox.multiverseinventories.WorldGroup; | ||
import net.luckperms.api.context.ContextCalculator; | ||
import net.luckperms.api.context.ContextConsumer; | ||
import net.luckperms.api.context.ContextSet; | ||
import net.luckperms.api.context.ImmutableContextSet; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class WorldGroupContextCalculator implements ContextCalculator<Player> { | ||
|
||
private static final String WORLD_GROUP_CONTEXT_KEY = "mvinv:worldgroup"; | ||
|
||
private final MultiverseInventories plugin; | ||
|
||
public WorldGroupContextCalculator(MultiverseInventories plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public void calculate(@NotNull Player player, @NotNull ContextConsumer contextConsumer) { | ||
ImmutableContextSet.Builder contextBuilder = ImmutableContextSet.builder(); | ||
this.plugin.getGroupManager() | ||
.getGroupsForWorld(player.getWorld().getName()) | ||
.forEach(worldGroup -> contextBuilder.add(WORLD_GROUP_CONTEXT_KEY, worldGroup.getName())); | ||
|
||
contextConsumer.accept(contextBuilder.build()); | ||
} | ||
|
||
@Override | ||
public ContextSet estimatePotentialContexts() { | ||
ImmutableContextSet.Builder contextBuilder = ImmutableContextSet.builder(); | ||
this.plugin.getGroupManager() | ||
.getGroups() | ||
.forEach(worldGroup -> contextBuilder.add(WORLD_GROUP_CONTEXT_KEY, worldGroup.getName())); | ||
|
||
return contextBuilder.build(); | ||
} | ||
} |
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
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.
Is the API something that has to be enabled by the user? Or is this an actual error?
Just wondering because it might be annoying if someone purposefully disables the API and gets a warning every time they start their server.
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.
If luckperms is installed (checking alr done above), it should always be enabled unless luckperms crashed on their server.
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.
Okay, looks good then.
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.
Actually I just took a look at ContextCalculator's Javadoc, do you know if the calculation is thread-safe?
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.
it needs to be thread-safe bcu calls may be async. Source code has 3 pointers to take note:
https://github.com/lucko/LuckPerms/blob/5ea2aee2f49a317e8b6aa242ded2fe81384343ed/api/src/main/java/net/luckperms/api/context/ContextCalculator.java#L39-L53
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.
Yeah that's what I read, I was asking if the code you wrote is thread-safe.
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.
Multiverse-Inventories/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java
Lines 54 to 66 in f704fa2
hmm yea
getGroupsForWorld
does have the chance of modifying... I think usinggetGroups
then filter is a safer option since makes a copy