mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-31 18:07:56 +01:00
Some fixes, improvements & annotations for group sync
This commit is contained in:
parent
14d7b0eed7
commit
51fd9ef6d8
@ -174,9 +174,8 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConne
|
|||||||
// Service provider
|
// Service provider
|
||||||
server().getServicesManager().register(DiscordSRVApi.class, this, plugin(), ServicePriority.Normal);
|
server().getServicesManager().register(DiscordSRVApi.class, this, plugin(), ServicePriority.Normal);
|
||||||
|
|
||||||
// Adventure audiences, connection listener
|
// Adventure audiences
|
||||||
this.audiences = BukkitAudiences.create(bootstrap.getPlugin());
|
this.audiences = BukkitAudiences.create(bootstrap.getPlugin());
|
||||||
server().getPluginManager().registerEvents(new BukkitConnectionListener(this), plugin());
|
|
||||||
|
|
||||||
// Command handler
|
// Command handler
|
||||||
commandHandler = AbstractBukkitCommandHandler.get(this);
|
commandHandler = AbstractBukkitCommandHandler.get(this);
|
||||||
@ -193,6 +192,9 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConne
|
|||||||
registerIntegration("com.discordsrv.bukkit.integration.VaultIntegration");
|
registerIntegration("com.discordsrv.bukkit.integration.VaultIntegration");
|
||||||
|
|
||||||
super.enable();
|
super.enable();
|
||||||
|
|
||||||
|
// Connection listener
|
||||||
|
server().getPluginManager().registerEvents(new BukkitConnectionListener(this), plugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import net.milkbowl.vault.permission.Permission;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.ServicesManager;
|
import org.bukkit.plugin.ServicesManager;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -137,7 +138,7 @@ public class VaultIntegration extends PluginIntegration<BukkitDiscordSRV> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> hasGroup(UUID player, String groupName, boolean includeInherited) {
|
public CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited) {
|
||||||
if (permission == null || !permission.isEnabled() || !permission.hasGroupSupport()) {
|
if (permission == null || !permission.isEnabled() || !permission.hasGroupSupport()) {
|
||||||
return unsupported(permission);
|
return unsupported(permission);
|
||||||
}
|
}
|
||||||
@ -149,7 +150,7 @@ public class VaultIntegration extends PluginIntegration<BukkitDiscordSRV> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> addGroup(UUID player, String groupName) {
|
public CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName) {
|
||||||
if (permission == null || !permission.isEnabled() || !permission.hasGroupSupport()) {
|
if (permission == null || !permission.isEnabled() || !permission.hasGroupSupport()) {
|
||||||
return unsupported(permission);
|
return unsupported(permission);
|
||||||
}
|
}
|
||||||
@ -162,7 +163,7 @@ public class VaultIntegration extends PluginIntegration<BukkitDiscordSRV> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> removeGroup(UUID player, String groupName) {
|
public CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName) {
|
||||||
if (permission == null || !permission.isEnabled() || !permission.hasGroupSupport()) {
|
if (permission == null || !permission.isEnabled() || !permission.hasGroupSupport()) {
|
||||||
return unsupported(permission);
|
return unsupported(permission);
|
||||||
}
|
}
|
||||||
@ -175,7 +176,7 @@ public class VaultIntegration extends PluginIntegration<BukkitDiscordSRV> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> hasPermission(UUID player, String permissionNode) {
|
public CompletableFuture<Boolean> hasPermission(@NotNull UUID player, @NotNull String permissionNode) {
|
||||||
if (permission == null || !permission.isEnabled()) {
|
if (permission == null || !permission.isEnabled()) {
|
||||||
return unsupported(permission);
|
return unsupported(permission);
|
||||||
}
|
}
|
||||||
@ -187,7 +188,7 @@ public class VaultIntegration extends PluginIntegration<BukkitDiscordSRV> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<String> getPrefix(UUID player) {
|
public CompletableFuture<String> getPrefix(@NotNull UUID player) {
|
||||||
if (chat == null || !chat.isEnabled()) {
|
if (chat == null || !chat.isEnabled()) {
|
||||||
return unsupported(chat);
|
return unsupported(chat);
|
||||||
}
|
}
|
||||||
@ -199,7 +200,7 @@ public class VaultIntegration extends PluginIntegration<BukkitDiscordSRV> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<String> getSuffix(UUID player) {
|
public CompletableFuture<String> getSuffix(@NotNull UUID player) {
|
||||||
if (chat == null || !chat.isEnabled()) {
|
if (chat == null || !chat.isEnabled()) {
|
||||||
return unsupported(chat);
|
return unsupported(chat);
|
||||||
}
|
}
|
||||||
|
@ -323,9 +323,10 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
|
|||||||
Object module;
|
Object module;
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = Class.forName(className);
|
Class<?> clazz = Class.forName(className);
|
||||||
Constructor<?> constructor = clazz.getConstructor(getClass());
|
Constructor<?> constructor = clazz.getConstructors()[0];
|
||||||
module = constructor.newInstance(this);
|
module = constructor.newInstance(this);
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable e) {
|
||||||
|
moduleManager.logger().debug("Failed to load integration: " + className, e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
moduleManager.registerModule(this, d -> (AbstractModule<?>) module);
|
moduleManager.registerModule(this, d -> (AbstractModule<?>) module);
|
||||||
|
@ -201,7 +201,7 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
|
|||||||
PermissionDataProvider.Groups permissionProvider = getPermissionProvider();
|
PermissionDataProvider.Groups permissionProvider = getPermissionProvider();
|
||||||
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) {
|
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) {
|
||||||
return ((PermissionDataProvider.GroupsContext) permissionProvider)
|
return ((PermissionDataProvider.GroupsContext) permissionProvider)
|
||||||
.hasGroup(player, groupName, false, serverContext);
|
.hasGroup(player, groupName, false, serverContext != null ? Collections.singleton(serverContext) : null);
|
||||||
} else {
|
} else {
|
||||||
return permissionProvider.hasGroup(player, groupName, false);
|
return permissionProvider.hasGroup(player, groupName, false);
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
|
|||||||
PermissionDataProvider.Groups permissionProvider = getPermissionProvider();
|
PermissionDataProvider.Groups permissionProvider = getPermissionProvider();
|
||||||
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) {
|
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) {
|
||||||
return ((PermissionDataProvider.GroupsContext) permissionProvider)
|
return ((PermissionDataProvider.GroupsContext) permissionProvider)
|
||||||
.addGroup(player, groupName, serverContext);
|
.addGroup(player, groupName, Collections.singleton(serverContext));
|
||||||
} else {
|
} else {
|
||||||
return permissionProvider.addGroup(player, groupName);
|
return permissionProvider.addGroup(player, groupName);
|
||||||
}
|
}
|
||||||
@ -229,7 +229,7 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
|
|||||||
PermissionDataProvider.Groups permissionProvider = getPermissionProvider();
|
PermissionDataProvider.Groups permissionProvider = getPermissionProvider();
|
||||||
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) {
|
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) {
|
||||||
return ((PermissionDataProvider.GroupsContext) permissionProvider)
|
return ((PermissionDataProvider.GroupsContext) permissionProvider)
|
||||||
.removeGroup(player, groupName, serverContext);
|
.removeGroup(player, groupName, Collections.singleton(serverContext));
|
||||||
} else {
|
} else {
|
||||||
return permissionProvider.removeGroup(player, groupName);
|
return permissionProvider.removeGroup(player, groupName);
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@ import net.luckperms.api.node.NodeType;
|
|||||||
import net.luckperms.api.node.types.InheritanceNode;
|
import net.luckperms.api.node.types.InheritanceNode;
|
||||||
import net.luckperms.api.query.QueryMode;
|
import net.luckperms.api.query.QueryMode;
|
||||||
import net.luckperms.api.query.QueryOptions;
|
import net.luckperms.api.query.QueryOptions;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@ -109,13 +111,15 @@ public class LuckPermsIntegration extends PluginIntegration<DiscordSRV> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> hasGroup(UUID player, String groupName, boolean includeInherited, String serverContext) {
|
public CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited, @Nullable Set<String> serverContext) {
|
||||||
return user(player).thenApply(user -> {
|
return user(player).thenApply(user -> {
|
||||||
MutableContextSet context = luckPerms.getContextManager().getStaticContext().mutableCopy();
|
MutableContextSet context = luckPerms.getContextManager().getStaticContext().mutableCopy();
|
||||||
if (serverContext != null) {
|
if (serverContext != null) {
|
||||||
context.removeAll(DefaultContextKeys.SERVER_KEY);
|
context.removeAll(DefaultContextKeys.SERVER_KEY);
|
||||||
if (!serverContext.equals("global")) {
|
if (isNotGlobalOnly(serverContext)) {
|
||||||
context.add(DefaultContextKeys.SERVER_KEY, serverContext);
|
for (String ctx : serverContext) {
|
||||||
|
context.add(DefaultContextKeys.SERVER_KEY, ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,23 +130,23 @@ public class LuckPermsIntegration extends PluginIntegration<DiscordSRV> implemen
|
|||||||
.map(Group::getName)
|
.map(Group::getName)
|
||||||
: user.getNodes(NodeType.INHERITANCE)
|
: user.getNodes(NodeType.INHERITANCE)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(node -> node.getContexts().isSatisfiedBy(context))
|
.filter(node -> context.isSatisfiedBy(node.getContexts()))
|
||||||
.map(InheritanceNode::getGroupName)
|
.map(InheritanceNode::getGroupName)
|
||||||
).anyMatch(name -> name.equalsIgnoreCase(groupName));
|
).anyMatch(name -> name.equalsIgnoreCase(groupName));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> addGroup(UUID player, String groupName, String serverContext) {
|
public CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName, @Nullable Set<String> serverContext) {
|
||||||
return groupMutate(player, groupName, serverContext, NodeMap::add);
|
return groupMutate(player, groupName, serverContext, NodeMap::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> removeGroup(UUID player, String groupName, String serverContext) {
|
public CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName, @Nullable Set<String> serverContext) {
|
||||||
return groupMutate(player, groupName, serverContext, NodeMap::remove);
|
return groupMutate(player, groupName, serverContext, NodeMap::remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<Void> groupMutate(UUID player, String groupName, String serverContext, BiFunction<NodeMap, Node, DataMutateResult> function) {
|
private CompletableFuture<Void> groupMutate(UUID player, String groupName, Set<String> serverContext, BiFunction<NodeMap, Node, DataMutateResult> function) {
|
||||||
Group group = luckPerms.getGroupManager().getGroup(groupName);
|
Group group = luckPerms.getGroupManager().getGroup(groupName);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return CompletableFutureUtil.failed(new MessageException("Group does not exist"));
|
return CompletableFutureUtil.failed(new MessageException("Group does not exist"));
|
||||||
@ -150,8 +154,12 @@ public class LuckPermsIntegration extends PluginIntegration<DiscordSRV> implemen
|
|||||||
return user(player).thenCompose(user -> {
|
return user(player).thenCompose(user -> {
|
||||||
ContextSet contexts;
|
ContextSet contexts;
|
||||||
if (serverContext != null) {
|
if (serverContext != null) {
|
||||||
if (!serverContext.equals("global")) {
|
if (isNotGlobalOnly(serverContext)) {
|
||||||
contexts = ImmutableContextSet.of(DefaultContextKeys.SERVER_KEY, serverContext);
|
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||||
|
for (String ctx : serverContext) {
|
||||||
|
builder.add(DefaultContextKeys.SERVER_KEY, ctx);
|
||||||
|
}
|
||||||
|
contexts = builder.build();
|
||||||
} else {
|
} else {
|
||||||
contexts = ImmutableContextSet.empty();
|
contexts = ImmutableContextSet.empty();
|
||||||
}
|
}
|
||||||
@ -173,24 +181,28 @@ public class LuckPermsIntegration extends PluginIntegration<DiscordSRV> implemen
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNotGlobalOnly(Set<String> context) {
|
||||||
|
return context.size() != 1 || !context.iterator().next().equals("global");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> hasPermission(UUID player, String permission) {
|
public CompletableFuture<Boolean> hasPermission(@NotNull UUID player, @NotNull String permission) {
|
||||||
return user(player).thenApply(
|
return user(player).thenApply(
|
||||||
user -> user.getCachedData().getPermissionData().checkPermission(permission).asBoolean());
|
user -> user.getCachedData().getPermissionData().checkPermission(permission).asBoolean());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<String> getPrefix(UUID player) {
|
public CompletableFuture<String> getPrefix(@NotNull UUID player) {
|
||||||
return user(player).thenApply(user -> user.getCachedData().getMetaData().getPrefix());
|
return user(player).thenApply(user -> user.getCachedData().getMetaData().getPrefix());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<String> getSuffix(UUID player) {
|
public CompletableFuture<String> getSuffix(@NotNull UUID player) {
|
||||||
return user(player).thenApply(user -> user.getCachedData().getMetaData().getSuffix());
|
return user(player).thenApply(user -> user.getCachedData().getMetaData().getSuffix());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<String> getMeta(UUID player, String key) throws UnsupportedOperationException {
|
public CompletableFuture<String> getMeta(@NotNull UUID player, @NotNull String key) throws UnsupportedOperationException {
|
||||||
return user(player).thenApply(user -> user.getCachedData().getMetaData().getMetaValue(key));
|
return user(player).thenApply(user -> user.getCachedData().getMetaData().getMetaValue(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,9 @@ public class ModuleManager {
|
|||||||
Module bestCandidate = null;
|
Module bestCandidate = null;
|
||||||
int bestCandidatePriority = Integer.MIN_VALUE;
|
int bestCandidatePriority = Integer.MIN_VALUE;
|
||||||
for (Module module : modules) {
|
for (Module module : modules) {
|
||||||
|
if (!module.isEnabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int priority;
|
int priority;
|
||||||
if (moduleType.isAssignableFrom(module.getClass()) && ((priority = module.priority(moduleType)) > bestCandidatePriority)) {
|
if (moduleType.isAssignableFrom(module.getClass()) && ((priority = module.priority(moduleType)) > bestCandidatePriority)) {
|
||||||
bestCandidate = module;
|
bestCandidate = module;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package com.discordsrv.common.module.type;
|
package com.discordsrv.common.module.type;
|
||||||
|
|
||||||
import com.discordsrv.api.module.type.Module;
|
import com.discordsrv.api.module.type.Module;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,43 +36,43 @@ public interface PermissionDataProvider extends Module {
|
|||||||
|
|
||||||
interface Groups extends PermissionDataProvider {
|
interface Groups extends PermissionDataProvider {
|
||||||
List<String> getGroups();
|
List<String> getGroups();
|
||||||
CompletableFuture<Boolean> hasGroup(UUID player, String groupName, boolean includeInherited);
|
CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited);
|
||||||
CompletableFuture<Void> addGroup(UUID player, String groupName);
|
CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName);
|
||||||
CompletableFuture<Void> removeGroup(UUID player, String groupName);
|
CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Permissions extends PermissionDataProvider {
|
interface Permissions extends PermissionDataProvider {
|
||||||
CompletableFuture<Boolean> hasPermission(UUID player, String permission);
|
CompletableFuture<Boolean> hasPermission(@NotNull UUID player, @NotNull String permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PrefixAndSuffix extends PermissionDataProvider {
|
interface PrefixAndSuffix extends PermissionDataProvider {
|
||||||
CompletableFuture<String> getPrefix(UUID player);
|
CompletableFuture<String> getPrefix(@NotNull UUID player);
|
||||||
CompletableFuture<String> getSuffix(UUID player);
|
CompletableFuture<String> getSuffix(@NotNull UUID player);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Meta extends PermissionDataProvider {
|
interface Meta extends PermissionDataProvider {
|
||||||
CompletableFuture<String> getMeta(UUID player, String key);
|
CompletableFuture<String> getMeta(@NotNull UUID player, @NotNull String key);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GroupsContext extends Groups {
|
interface GroupsContext extends Groups {
|
||||||
|
|
||||||
Set<String> getDefaultServerContext();
|
Set<String> getDefaultServerContext();
|
||||||
CompletableFuture<Boolean> hasGroup(UUID player, String groupName, boolean includeInherited, @Nullable String serverContext);
|
CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited, @Nullable Set<String> serverContext);
|
||||||
CompletableFuture<Void> addGroup(UUID player, String groupName, @Nullable String serverContext);
|
CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName, @Nullable Set<String> serverContext);
|
||||||
CompletableFuture<Void> removeGroup(UUID player, String groupName, @Nullable String serverContext);
|
CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName, @Nullable Set<String> serverContext);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default CompletableFuture<Boolean> hasGroup(UUID player, String groupName, boolean includeInherited) {
|
default CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited) {
|
||||||
return hasGroup(player, groupName, includeInherited, null);
|
return hasGroup(player, groupName, includeInherited, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default CompletableFuture<Void> addGroup(UUID player, String groupName) {
|
default CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName) {
|
||||||
return addGroup(player, groupName, null);
|
return addGroup(player, groupName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default CompletableFuture<Void> removeGroup(UUID player, String groupName) {
|
default CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName) {
|
||||||
return removeGroup(player, groupName, null);
|
return removeGroup(player, groupName, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user