mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-16 21:31:35 +01:00
Allow context calculators to define "potential contexts", and use these for tab completions
This commit is contained in:
parent
4b793d1f14
commit
f0e42c6db6
@ -94,4 +94,17 @@ public interface ContextCalculator<T> {
|
||||
*/
|
||||
void calculate(@NonNull T target, @NonNull ContextConsumer consumer);
|
||||
|
||||
/**
|
||||
* Gets a {@link ContextSet}, containing some/all of the contexts this
|
||||
* calculator could potentially submit.
|
||||
*
|
||||
* <p>The result of this call is primarily intended on providing
|
||||
* suggestions to end users when defining permissions.</p>
|
||||
*
|
||||
* @return a set of potential contexts
|
||||
*/
|
||||
default ContextSet estimatePotentialContexts() {
|
||||
return ImmutableContextSet.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,23 +25,27 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.context;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import net.luckperms.api.context.ContextCalculator;
|
||||
import net.luckperms.api.context.ContextConsumer;
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class WorldCalculator implements ContextCalculator<Player> {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public WorldCalculator(LuckPermsPlugin plugin) {
|
||||
public WorldCalculator(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -54,4 +58,14 @@ public class WorldCalculator implements ContextCalculator<Player> {
|
||||
world = this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextSet estimatePotentialContexts() {
|
||||
List<World> worlds = this.plugin.getBootstrap().getServer().getWorlds();
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (World world : worlds) {
|
||||
builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
@ -25,16 +25,20 @@
|
||||
|
||||
package me.lucko.luckperms.bungee.context;
|
||||
|
||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import net.luckperms.api.context.ContextCalculator;
|
||||
import net.luckperms.api.context.ContextConsumer;
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -44,9 +48,9 @@ public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer>
|
||||
return player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName().toLowerCase());
|
||||
}
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
public BackendServerCalculator(LuckPermsPlugin plugin) {
|
||||
public BackendServerCalculator(LPBungeePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -59,4 +63,14 @@ public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer>
|
||||
server = this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(server, server).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextSet estimatePotentialContexts() {
|
||||
Collection<ServerInfo> servers = this.plugin.getBootstrap().getProxy().getServers().values();
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (ServerInfo server : servers) {
|
||||
builder.add(DefaultContextKeys.WORLD_KEY, server.getName().toLowerCase());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
|
||||
import net.luckperms.api.context.ContextConsumer;
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.context.StaticContextCalculator;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@ -43,4 +45,18 @@ public class RedisBungeeCalculator implements StaticContextCalculator {
|
||||
consumer.accept(PROXY_KEY, redisBungee.getServerId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextSet estimatePotentialContexts() {
|
||||
RedisBungeeAPI redisBungee = RedisBungee.getApi();
|
||||
if (redisBungee == null) {
|
||||
return ImmutableContextSet.empty();
|
||||
}
|
||||
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (String server : redisBungee.getAllServers()) {
|
||||
builder.add(PROXY_KEY, server);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +31,12 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.treeview.PermissionRegistry;
|
||||
import me.lucko.luckperms.common.treeview.TreeNode;
|
||||
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -47,6 +49,7 @@ public final class TabCompletions {
|
||||
private final CompletionSupplier groups;
|
||||
private final CompletionSupplier tracks;
|
||||
private final CompletionSupplier permissions;
|
||||
private final CompletionSupplier contexts;
|
||||
|
||||
public TabCompletions(LuckPermsPlugin plugin) {
|
||||
this.groups = CompletionSupplier.startsWith(() -> plugin.getGroupManager().getAll().keySet());
|
||||
@ -54,13 +57,6 @@ public final class TabCompletions {
|
||||
this.permissions = partial -> {
|
||||
PermissionRegistry cache = plugin.getPermissionRegistry();
|
||||
|
||||
if (partial.isEmpty()) {
|
||||
return cache.getRootNode().getChildren()
|
||||
.map(Map::keySet)
|
||||
.<List<String>>map(ArrayList::new)
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
String start = partial.toLowerCase();
|
||||
List<String> parts = new ArrayList<>(Splitter.on('.').splitToList(start));
|
||||
TreeNode root = cache.getRootNode();
|
||||
@ -70,7 +66,7 @@ public final class TabCompletions {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return root.getChildren().get().keySet().stream().filter(TabCompleter.startsWithIgnoreCase(start)).collect(Collectors.toList());
|
||||
return CompletionSupplier.startsWith(root.getChildren().get().keySet()).supplyCompletions(start);
|
||||
}
|
||||
|
||||
String incomplete = parts.remove(parts.size() - 1);
|
||||
@ -97,6 +93,28 @@ public final class TabCompletions {
|
||||
.map(s -> String.join(".", parts) + "." + s)
|
||||
.collect(Collectors.toList());
|
||||
};
|
||||
this.contexts = partial -> {
|
||||
ImmutableContextSet potentialContexts = plugin.getContextManager().getPotentialContexts();
|
||||
|
||||
int index = partial.indexOf('=');
|
||||
if (index == -1) {
|
||||
// cursor is specifying the key
|
||||
return CompletionSupplier.startsWith(potentialContexts.toMap().keySet()).supplyCompletions(partial);
|
||||
}
|
||||
|
||||
// cursor is specifying the value
|
||||
String key = partial.substring(0, index);
|
||||
if (key.equals("") || key.trim().isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String value = partial.substring(index + 1).trim();
|
||||
Set<String> potentialValues = potentialContexts.getValues(key);
|
||||
return potentialValues.stream()
|
||||
.filter(TabCompleter.startsWithIgnoreCase(value))
|
||||
.map(s -> key + "=" + s)
|
||||
.collect(Collectors.toList());
|
||||
};
|
||||
}
|
||||
|
||||
// bit of a weird pattern, but meh it kinda works, reduces the boilerplate
|
||||
@ -118,4 +136,8 @@ public final class TabCompletions {
|
||||
return plugin.getCommandManager().getTabCompletions().permissions;
|
||||
}
|
||||
|
||||
public static CompletionSupplier contexts(LuckPermsPlugin plugin) {
|
||||
return plugin.getCommandManager().getTabCompletions().contexts;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -106,4 +108,11 @@ public class MetaAddChatMeta extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -115,4 +117,11 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(3, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -118,4 +120,11 @@ public class MetaClear extends SharedSubCommand {
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(0, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -123,4 +125,11 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -123,4 +125,11 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -102,4 +104,11 @@ public class MetaSet extends SharedSubCommand {
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -142,4 +144,11 @@ public class MetaSetChatMeta extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -107,4 +109,11 @@ public class MetaSetTemp extends SharedSubCommand {
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(3, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -155,4 +157,11 @@ public class MetaSetTempChatMeta extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -84,4 +86,11 @@ public class MetaUnset extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -84,4 +86,11 @@ public class MetaUnsetTemp extends SharedSubCommand {
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -89,4 +91,11 @@ public class HolderClear<T extends PermissionHolder> extends SubCommand<T> {
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(0, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ public class ParentAdd extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ public class ParentAddTemp extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -87,4 +89,11 @@ public class ParentClear extends SharedSubCommand {
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(0, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +123,7 @@ public class ParentClearTrack extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ public class ParentRemove extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ public class ParentRemoveTemp extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ public class ParentSet extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.groups(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,7 @@ public class ParentSetTrack extends SharedSubCommand {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.at(1, TabCompletions.groups(plugin))
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ public class PermissionCheck extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ public class PermissionCheckInherits extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -90,4 +92,11 @@ public class PermissionClear extends SharedSubCommand {
|
||||
StorageAssistant.save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(0, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ public class PermissionSet extends SharedSubCommand {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.at(1, TabCompletions.booleans())
|
||||
.from(2, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ public class PermissionSetTemp extends SharedSubCommand {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.at(1, TabCompletions.booleans())
|
||||
.from(3, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ public class PermissionUnset extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ public class PermissionUnsetTemp extends SharedSubCommand {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.permissions(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
|
||||
import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
|
||||
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentParser;
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
||||
@ -106,4 +108,11 @@ public class GroupSetDisplayName extends SubCommand<Group> {
|
||||
StorageAssistant.save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -151,6 +151,7 @@ public class UserDemote extends SubCommand<User> {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -151,6 +151,7 @@ public class UserPromote extends SubCommand<User> {
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, TabCompletions.tracks(plugin))
|
||||
.from(1, TabCompletions.contexts(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,14 @@ public abstract class ContextManager<T> {
|
||||
return ImmutableList.copyOf(this.staticCalculators);
|
||||
}
|
||||
|
||||
public ImmutableContextSet getPotentialContexts() {
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (ContextCalculator<? super T> calculator : this.calculators) {
|
||||
builder.addAll(calculator.estimatePotentialContexts());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public Class<T> getSubjectClass() {
|
||||
return this.subjectClass;
|
||||
}
|
||||
|
@ -29,7 +29,9 @@ import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
|
||||
import net.luckperms.api.context.ContextConsumer;
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.context.StaticContextCalculator;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@ -50,4 +52,10 @@ public class LPStaticContextsCalculator implements StaticContextCalculator {
|
||||
consumer.accept(this.config.getContextsFile().getStaticContexts());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextSet estimatePotentialContexts() {
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
calculate(builder::add);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,11 @@ public final class WebEditor {
|
||||
arr.add(perm);
|
||||
}
|
||||
})
|
||||
).toJson();
|
||||
)
|
||||
.consume(o -> {
|
||||
o.add("potentialContexts", ContextSetJsonSerializer.serializeContextSet(plugin.getContextManager().getPotentialContexts()));
|
||||
})
|
||||
.toJson();
|
||||
}
|
||||
|
||||
public static JsonObject readDataFromBytebin(BytebinClient bytebin, String id) {
|
||||
|
@ -26,23 +26,27 @@
|
||||
package me.lucko.luckperms.nukkit.context;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||
|
||||
import net.luckperms.api.context.ContextCalculator;
|
||||
import net.luckperms.api.context.ContextConsumer;
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
import cn.nukkit.level.Level;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class WorldCalculator implements ContextCalculator<Player> {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final LPNukkitPlugin plugin;
|
||||
|
||||
public WorldCalculator(LuckPermsPlugin plugin) {
|
||||
public WorldCalculator(LPNukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -55,4 +59,14 @@ public class WorldCalculator implements ContextCalculator<Player> {
|
||||
world = this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextSet estimatePotentialContexts() {
|
||||
Collection<Level> worlds = this.plugin.getBootstrap().getServer().getLevels().values();
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (Level world : worlds) {
|
||||
builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
@ -26,24 +26,29 @@
|
||||
package me.lucko.luckperms.sponge.context;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import net.luckperms.api.context.ContextCalculator;
|
||||
import net.luckperms.api.context.ContextConsumer;
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class WorldCalculator implements ContextCalculator<Subject> {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
public WorldCalculator(LuckPermsPlugin plugin) {
|
||||
public WorldCalculator(LPSpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -62,7 +67,20 @@ public class WorldCalculator implements ContextCalculator<Subject> {
|
||||
consumer.accept(DefaultContextKeys.WORLD_KEY, world);
|
||||
world = this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextSet estimatePotentialContexts() {
|
||||
Game game = this.plugin.getBootstrap().getGame();
|
||||
if (!game.isServerAvailable()) {
|
||||
return ImmutableContextSet.empty();
|
||||
}
|
||||
|
||||
Collection<World> worlds = game.getServer().getWorlds();
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (World world : worlds) {
|
||||
builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
@ -26,16 +26,20 @@
|
||||
package me.lucko.luckperms.velocity.context;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.velocity.LPVelocityPlugin;
|
||||
|
||||
import net.luckperms.api.context.ContextCalculator;
|
||||
import net.luckperms.api.context.ContextConsumer;
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -45,9 +49,9 @@ public class BackendServerCalculator implements ContextCalculator<Player> {
|
||||
return player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName().toLowerCase() : null;
|
||||
}
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final LPVelocityPlugin plugin;
|
||||
|
||||
public BackendServerCalculator(LuckPermsPlugin plugin) {
|
||||
public BackendServerCalculator(LPVelocityPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -60,4 +64,14 @@ public class BackendServerCalculator implements ContextCalculator<Player> {
|
||||
server = this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(server, server).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextSet estimatePotentialContexts() {
|
||||
Collection<RegisteredServer> servers = this.plugin.getBootstrap().getProxy().getAllServers();
|
||||
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
|
||||
for (RegisteredServer server : servers) {
|
||||
builder.add(DefaultContextKeys.WORLD_KEY, server.getServerInfo().getName().toLowerCase());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user