-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add luckperms context support for worldgroup.
- Loading branch information
1 parent
3baac10
commit 1d52822
Showing
4 changed files
with
69 additions
and
2 deletions.
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