add luckperms context
This commit is contained in:
+3
-1
@@ -46,7 +46,7 @@ dependencies {
|
|||||||
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
|
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
|
||||||
|
|
||||||
compileOnly 'org.jetbrains:annotations:22.0.0'
|
compileOnly 'org.jetbrains:annotations:22.0.0'
|
||||||
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT'
|
||||||
compileOnly('com.github.Realizedd:TokenManager:3.2.4') {
|
compileOnly('com.github.Realizedd:TokenManager:3.2.4') {
|
||||||
transitive = false
|
transitive = false
|
||||||
}
|
}
|
||||||
@@ -66,6 +66,8 @@ dependencies {
|
|||||||
transitive = false
|
transitive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileOnly 'net.luckperms:api:5.4'
|
||||||
|
|
||||||
compileOnly 'com.github.LlmDl:Towny:25fc18a'
|
compileOnly 'com.github.LlmDl:Towny:25fc18a'
|
||||||
testImplementation 'com.github.LlmDl:Towny:25fc18a'
|
testImplementation 'com.github.LlmDl:Towny:25fc18a'
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package sh.okx.rankup.hook;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import net.luckperms.api.context.ContextSet;
|
||||||
|
import net.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import net.luckperms.api.model.group.Group;
|
||||||
|
import net.luckperms.api.model.user.User;
|
||||||
|
import net.luckperms.api.node.types.InheritanceNode;
|
||||||
|
|
||||||
|
public class LuckPermsGroupProvider implements GroupProvider {
|
||||||
|
|
||||||
|
private final LuckPerms luckPerms;
|
||||||
|
private final ContextSet contextSet;
|
||||||
|
|
||||||
|
public LuckPermsGroupProvider(LuckPerms luckPerms, ContextSet contextSet) {
|
||||||
|
this.luckPerms = luckPerms;
|
||||||
|
this.contextSet = contextSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LuckPermsGroupProvider createFromString(LuckPerms luckPerms, String context) {
|
||||||
|
try {
|
||||||
|
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||||
|
for (String contextPair : context.split(" ")) {
|
||||||
|
String[] keyValue = contextPair.split("=", 2);
|
||||||
|
if (keyValue.length == 2) {
|
||||||
|
builder.add(keyValue[0], keyValue[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LuckPermsGroupProvider(luckPerms, builder.build());
|
||||||
|
} catch (NullPointerException | IllegalArgumentException ex) {
|
||||||
|
throw new IllegalArgumentException("Context is invalid: " + context, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(UUID uuid, String group) {
|
||||||
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
|
for (Group lpGroup : user.getInheritedGroups(user.getQueryOptions().toBuilder().context(contextSet).build())) {
|
||||||
|
if (lpGroup.getName().equals(group)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addGroup(UUID uuid, String group) {
|
||||||
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
|
user.data().add(InheritanceNode.builder(group).context(contextSet).build());
|
||||||
|
|
||||||
|
luckPerms.getUserManager().saveUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeGroup(UUID uuid, String group) {
|
||||||
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
|
user.data().remove(InheritanceNode.builder(group).context(contextSet).build());
|
||||||
|
|
||||||
|
luckPerms.getUserManager().saveUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package sh.okx.rankup.hook;
|
package sh.okx.rankup.hook;
|
||||||
|
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import sh.okx.rankup.RankupPlugin;
|
import sh.okx.rankup.RankupPlugin;
|
||||||
|
|
||||||
@@ -26,6 +28,14 @@ public class VaultPermissionManager implements PermissionManager {
|
|||||||
if (!provider.hasGroupSupport()) {
|
if (!provider.hasGroupSupport()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
String lpContext = plugin.getConfig().getString("luckperms-context");
|
||||||
|
if (lpContext != null && !lpContext.isEmpty()) {
|
||||||
|
RegisteredServiceProvider<LuckPerms> lpProvider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
|
||||||
|
if (lpProvider != null) {
|
||||||
|
return LuckPermsGroupProvider.createFromString(lpProvider.getProvider(), lpContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new VaultGroupProvider(provider);
|
return new VaultGroupProvider(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,15 @@ notify-update: true
|
|||||||
# use commands to change a player's group or permission.
|
# use commands to change a player's group or permission.
|
||||||
permission-rankup: false
|
permission-rankup: false
|
||||||
|
|
||||||
|
# if not empty, these are the contexts to use when modifying groups if LuckPerms is enabled
|
||||||
|
# if empty, this will be based on your LuckPerms config.yml 'use-vault-server' and 'vault-server'
|
||||||
|
# this option will only if permission-rankup is disabled
|
||||||
|
#
|
||||||
|
# luckperms-context: 'server=global' # to make all rankups global
|
||||||
|
# luckperms-context: 'server=survival' # to make all rankups specific to survival
|
||||||
|
# luckperms-context: 'server=survival world=world_nether' # to make all rankups specific to the nether world in survival
|
||||||
|
luckperms-context: ''
|
||||||
|
|
||||||
# if players can use /rankup noconfirm to bypass any confirmation
|
# if players can use /rankup noconfirm to bypass any confirmation
|
||||||
# the permission rankup.noconfirm is used for this command, but it is true by default
|
# the permission rankup.noconfirm is used for this command, but it is true by default
|
||||||
# the console can always do /rankup noconfirm <player>
|
# the console can always do /rankup noconfirm <player>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ version: "${version}"
|
|||||||
main: sh.okx.rankup.RankupPlugin
|
main: sh.okx.rankup.RankupPlugin
|
||||||
author: Okx
|
author: Okx
|
||||||
depend: [Vault]
|
depend: [Vault]
|
||||||
softdepend: [PlaceholderAPI, mcMMO, AdvancedAchievements, Towny, SuperbVote, VotingPlugin]
|
softdepend: [PlaceholderAPI, mcMMO, AdvancedAchievements, Towny, SuperbVote, VotingPlugin, LuckPerms]
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
|
|||||||
Reference in New Issue
Block a user