Cleanup various message localisations, limit the size of the PermissionRegistry

This commit is contained in:
Luck 2018-06-19 22:27:43 +01:00
parent 2036127612
commit 379eb00b69
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
93 changed files with 702 additions and 434 deletions

View File

@ -77,7 +77,7 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements
}
@Override
public List<String> getObjectList(String path, List<String> def) {
public List<String> getKeys(String path, List<String> def) {
ConfigurationSection section = this.configuration.getConfigurationSection(path);
if (section == null) {
return def;

View File

@ -99,7 +99,7 @@ public final class LPPermissionMap extends ForwardingMap<String, Permission> {
Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
this.plugin.getPermissionRegistry().offer(key);
this.plugin.getPermissionRegistry().insert(key);
Permission ret = super.put(key, value);
update();
return ret;
@ -107,9 +107,9 @@ public final class LPPermissionMap extends ForwardingMap<String, Permission> {
@Override
public void putAll(@Nonnull Map<? extends String, ? extends Permission> m) {
this.plugin.getPermissionRegistry().offerAll(m.keySet());
super.putAll(m);
update();
for (Map.Entry<? extends String, ? extends Permission> ent : m.entrySet()) {
put(ent.getKey(), ent.getValue());
}
}
@Override
@ -117,7 +117,7 @@ public final class LPPermissionMap extends ForwardingMap<String, Permission> {
Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
this.plugin.getPermissionRegistry().offer(key);
this.plugin.getPermissionRegistry().insert(key);
Permission ret = super.putIfAbsent(key, value);
update();
return ret;

View File

@ -82,7 +82,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements
}
@Override
public List<String> getObjectList(String path, List<String> def) {
public List<String> getKeys(String path, List<String> def) {
Configuration section = this.configuration.getSection(path);
if (section == null) {
return def;

View File

@ -323,10 +323,6 @@ public abstract class AbstractCachedData implements CachedData {
return CompletableFuture.allOf(keys.stream().map(this::reloadMeta).toArray(CompletableFuture[]::new));
}
public CompletableFuture<Void> reloadAll() {
return CompletableFuture.allOf(reloadPermissions(), reloadMeta());
}
@Override
public void preCalculate(@Nonnull Contexts contexts) {
Objects.requireNonNull(contexts, "contexts");

View File

@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.command.abstraction.Command;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.access.CommandPermission;
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.commands.group.CreateGroup;
@ -97,13 +98,16 @@ public class CommandManager {
// the default executor to run commands on
private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final List<Command> mainCommands;
private final TabCompletions tabCompletions;
private final List<Command<?, ?>> mainCommands;
public CommandManager(LuckPermsPlugin plugin) {
this.plugin = plugin;
LocaleManager locale = plugin.getLocaleManager();
this.mainCommands = ImmutableList.<Command>builder()
this.tabCompletions = new TabCompletions(plugin);
this.mainCommands = ImmutableList.<Command<?, ?>>builder()
.add(new UserMainCommand(locale))
.add(new GroupMainCommand(locale))
.add(new TrackMainCommand(locale))
@ -137,6 +141,10 @@ public class CommandManager {
return this.plugin;
}
public TabCompletions getTabCompletions() {
return this.tabCompletions;
}
public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args) {
return onCommand(sender, label, args, this.executor);
}
@ -170,7 +178,7 @@ public class CommandManager {
}
// Look for the main command.
Optional<Command> o = this.mainCommands.stream()
Optional<Command<?, ?>> o = this.mainCommands.stream()
.filter(m -> m.getName().equalsIgnoreCase(arguments.get(0)))
.limit(1)
.findAny();
@ -263,8 +271,7 @@ public class CommandManager {
.filter(Command::shouldDisplay)
.filter(c -> c.isAuthorized(sender))
.forEach(c -> {
@SuppressWarnings("unchecked")
String permission = (String) c.getPermission().map(p -> ((CommandPermission) p).getPermission()).orElse("None");
String permission = c.getPermission().map(CommandPermission::getPermission).orElse("None");
TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR)
.toBuilder().applyDeep(comp -> {

View File

@ -27,7 +27,6 @@ package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -120,7 +119,7 @@ public abstract class MainCommand<T, I> extends Command<Void, T> {
final List<String> objects = getTargets(plugin);
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equals("")) {
if (args.isEmpty() || args.get(0).trim().isEmpty()) {
return objects;
}
@ -134,7 +133,7 @@ public abstract class MainCommand<T, I> extends Command<Void, T> {
.collect(Collectors.toList());
if (args.size() == 2) {
if (args.get(1).equals("")) {
if (args.get(1).trim().isEmpty()) {
return subs.stream()
.map(m -> m.getName().toLowerCase())
.collect(Collectors.toList());
@ -171,12 +170,10 @@ public abstract class MainCommand<T, I> extends Command<Void, T> {
.collect(Collectors.toList());
if (!subs.isEmpty()) {
MessageUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format(getUsage(), label) + " ...)");
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format(getUsage(), label));
for (Command s : subs) {
s.sendUsage(sender, label);
}
} else {
Message.COMMAND_NO_PERMISSION.send(sender);
}

View File

@ -27,7 +27,6 @@ package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.utils.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
@ -143,9 +142,9 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
if (!subs.isEmpty()) {
if (user) {
MessageUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format("/%s user <user> " + getName().toLowerCase() + " ...)", label));
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s user <user> " + getName().toLowerCase(), label));
} else {
MessageUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format("/%s group <group> " + getName().toLowerCase() + " ...)", label));
Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s group <group> " + getName().toLowerCase(), label));
}
for (SharedSubCommand s : subs) {

View File

@ -27,9 +27,9 @@ package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.command.Argument;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -99,22 +99,22 @@ public abstract class SharedSubCommand {
public void sendUsage(Sender sender) {
StringBuilder sb = new StringBuilder();
if (getArgs() != null) {
sb.append("&3 - &7");
sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager()));
for (Argument arg : getArgs()) {
sb.append(arg.asPrettyString()).append(" ");
sb.append(arg.asPrettyString(sender.getPlatform().getLocaleManager())).append(" ");
}
}
MessageUtils.sendPluginMessage(sender, "&3> &a" + getName() + sb.toString());
Message.COMMAND_USAGE_BRIEF.send(sender, getName(), sb.toString());
}
public void sendDetailedUsage(Sender sender) {
MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName());
MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription());
Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
if (getArgs() != null) {
MessageUtils.sendPluginMessage(sender, "&3Arguments:");
Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs()) {
MessageUtils.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription());
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlatform().getLocaleManager()), arg.getDescription());
}
}
}

View File

@ -27,9 +27,9 @@ package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.command.Argument;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -56,23 +56,23 @@ public abstract class SingleCommand extends Command<Void, Void> {
public void sendUsage(Sender sender, String label) {
StringBuilder sb = new StringBuilder();
if (getArgs().isPresent()) {
sb.append("&3 - &7");
sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager()));
for (Argument arg : getArgs().get()) {
sb.append(arg.asPrettyString()).append(" ");
sb.append(arg.asPrettyString(sender.getPlatform().getLocaleManager())).append(" ");
}
}
MessageUtils.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + sb.toString());
Message.COMMAND_USAGE_BRIEF.send(sender, getName().toLowerCase(), sb.toString());
}
@Override
public void sendDetailedUsage(Sender sender, String label) {
MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName());
MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription());
Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
if (getArgs().isPresent()) {
MessageUtils.sendPluginMessage(sender, "&3Arguments:");
Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs().get()) {
MessageUtils.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription());
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlatform().getLocaleManager()), arg.getDescription());
}
}
}

View File

@ -26,9 +26,9 @@
package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.command.Argument;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.sender.Sender;
import java.util.function.Predicate;
@ -51,23 +51,23 @@ public abstract class SubCommand<T> extends Command<T, Void> {
public void sendUsage(Sender sender, String label) {
StringBuilder sb = new StringBuilder();
if (getArgs().isPresent()) {
sb.append("&3 - &7");
sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager()));
for (Argument arg : getArgs().get()) {
sb.append(arg.asPrettyString()).append(" ");
sb.append(arg.asPrettyString(sender.getPlatform().getLocaleManager())).append(" ");
}
}
MessageUtils.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + sb.toString());
Message.COMMAND_USAGE_BRIEF.send(sender, getName().toLowerCase(), sb.toString());
}
@Override
public void sendDetailedUsage(Sender sender, String label) {
MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName());
MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription());
Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
if (getArgs().isPresent()) {
MessageUtils.sendPluginMessage(sender, "&3Arguments:");
Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs().get()) {
MessageUtils.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription());
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlatform().getLocaleManager()), arg.getDescription());
}
}
}

View File

@ -0,0 +1,53 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.command.tabcomplete;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public interface CompletionSupplier {
CompletionSupplier EMPTY = partial -> Collections.emptyList();
static CompletionSupplier startsWith(String... strings) {
return partial -> Arrays.stream(strings).filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList());
}
static CompletionSupplier startsWith(Collection<String> strings) {
return partial -> strings.stream().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList());
}
static CompletionSupplier startsWith(Supplier<? extends Collection<String>> stringsSupplier) {
return partial -> stringsSupplier.get().stream().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList());
}
List<String> supplyCompletions(String partial);
}

View File

@ -0,0 +1,110 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.command.tabcomplete;
import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
/**
* Utility for computing tab completion results
*/
public class TabCompleter {
public static TabCompleter create() {
return new TabCompleter();
}
private final Map<Integer, CompletionSupplier> suppliers = new HashMap<>();
private int from = Integer.MAX_VALUE;
private TabCompleter() {
}
/**
* Marks that the given completion supplier should be used to compute tab
* completions at the given index.
*
* @param position the position
* @param supplier the supplier
* @return this
*/
public TabCompleter at(int position, CompletionSupplier supplier) {
Preconditions.checkState(position < from);
this.suppliers.put(position, supplier);
return this;
}
/**
* Marks that the given completion supplier should be used to compute tab
* completions at the given index and at all subsequent indexes infinitely.
*
* @param position the position
* @param supplier the supplier
* @return this
*/
public TabCompleter from(int position, CompletionSupplier supplier) {
Preconditions.checkState(this.from == Integer.MAX_VALUE);
this.suppliers.put(position, supplier);
this.from = position;
return this;
}
public List<String> complete(List<String> args) {
int lastIndex = 0;
String partial;
// nothing entered yet
if (args.isEmpty() || (partial = args.get((lastIndex = args.size() - 1))).trim().isEmpty()) {
return getCompletions(lastIndex, "");
}
// started typing something
return getCompletions(lastIndex, partial);
}
private List<String> getCompletions(int position, String partial) {
if (position >= this.from) {
return this.suppliers.get(this.from).supplyCompletions(partial);
}
return this.suppliers.getOrDefault(position, CompletionSupplier.EMPTY).supplyCompletions(partial);
}
static Predicate<String> startsWithIgnoreCase(String prefix) {
return string -> {
if (string.length() < prefix.length()) {
return false;
}
return string.regionMatches(true, 0, prefix, 0, prefix.length());
};
}
}

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.command.utils;
package me.lucko.luckperms.common.command.tabcomplete;
import com.google.common.base.Splitter;
@ -32,43 +32,36 @@ import me.lucko.luckperms.common.treeview.PermissionRegistry;
import me.lucko.luckperms.common.treeview.TreeNode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Utility methods for handling tab completion.
* Common completion suppliers used by the plugin
*/
public final class TabCompletions {
public static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) {
return getTabComplete(new ArrayList<>(plugin.getGroupManager().getAll().keySet()), args);
}
private static final CompletionSupplier BOOLEAN = CompletionSupplier.startsWith("true", "false");
public static List<String> getTrackTabComplete(List<String> args, LuckPermsPlugin plugin) {
return getTabComplete(new ArrayList<>(plugin.getTrackManager().getAll().keySet()), args);
}
private final CompletionSupplier groups;
private final CompletionSupplier tracks;
private final CompletionSupplier permissions;
public static List<String> getBoolTabComplete(List<String> args) {
if (args.size() == 2) {
return Arrays.asList("true", "false");
} else {
return Collections.emptyList();
}
}
public TabCompletions(LuckPermsPlugin plugin) {
this.groups = CompletionSupplier.startsWith(() -> plugin.getGroupManager().getAll().keySet());
this.tracks = CompletionSupplier.startsWith(() -> plugin.getTrackManager().getAll().keySet());
this.permissions = partial -> {
PermissionRegistry cache = plugin.getPermissionRegistry();
public static List<String> getPermissionTabComplete(List<String> args, PermissionRegistry cache) {
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equals("")) {
if (partial.isEmpty()) {
return cache.getRootNode().getChildren()
.map(Map::keySet)
.map(s -> (List<String>) new ArrayList<>(s))
.<List<String>>map(ArrayList::new)
.orElse(Collections.emptyList());
}
String start = args.get(0).toLowerCase();
String start = partial.toLowerCase();
List<String> parts = new ArrayList<>(Splitter.on('.').splitToList(start));
TreeNode root = cache.getRootNode();
@ -77,7 +70,7 @@ public final class TabCompletions {
return Collections.emptyList();
}
return root.getChildren().get().keySet().stream().filter(s -> s.startsWith(start)).collect(Collectors.toList());
return root.getChildren().get().keySet().stream().filter(TabCompleter.startsWithIgnoreCase(start)).collect(Collectors.toList());
}
String incomplete = parts.remove(parts.size() - 1);
@ -100,25 +93,29 @@ public final class TabCompletions {
}
return root.getChildren().get().keySet().stream()
.filter(s -> s.startsWith(incomplete))
.filter(TabCompleter.startsWithIgnoreCase(incomplete))
.map(s -> parts.stream().collect(Collectors.joining(".")) + "." + s)
.collect(Collectors.toList());
}
return Collections.emptyList();
};
}
private static List<String> getTabComplete(List<String> options, List<String> args) {
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return options;
}
// bit of a weird pattern, but meh it kinda works, reduces the boilerplate
// of calling the commandmanager + tabcompletions getters every time
return options.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
}
return Collections.emptyList();
public static CompletionSupplier booleans() {
return BOOLEAN;
}
public static CompletionSupplier groups(LuckPermsPlugin plugin) {
return plugin.getCommandManager().getTabCompletions().groups;
}
public static CompletionSupplier tracks(LuckPermsPlugin plugin) {
return plugin.getCommandManager().getTabCompletions().tracks;
}
public static CompletionSupplier permissions(LuckPermsPlugin plugin) {
return plugin.getCommandManager().getTabCompletions().permissions;
}
private TabCompletions() {}
}

View File

@ -29,16 +29,15 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.sender.Sender;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public final class MessageUtils {
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]");
/**
* Sends a message to the sender, formatted with the plugin prefix and color scheme
@ -47,40 +46,8 @@ public final class MessageUtils {
* @param message the message content
*/
public static void sendPluginMessage(Sender sender, String message) {
String prefix = sender.getPlatform().getLocaleManager().getTranslation(Message.PREFIX);
if (prefix == null) {
prefix = Message.PREFIX.getMessage();
}
sender.sendMessage(color(prefix + message));
}
/**
* Colorizes a message.
*
* @param s the message to colorize
* @return a colored message
*/
public static String color(String s) {
char[] b = s.toCharArray();
for (int i = 0; i < b.length - 1; ++i) {
if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) {
b[i] = 167;
b[i + 1] = Character.toLowerCase(b[i + 1]);
}
}
return new String(b);
}
/**
* Strips all color from a message
*
* @param s the message to strip color from
* @return the message without color
*/
public static String stripColor(String s) {
return s == null ? null : STRIP_COLOR_PATTERN.matcher(s).replaceAll("");
String prefix = Message.PREFIX.asString(sender.getPlatform().getLocaleManager());
sender.sendMessage(Message.colorize(prefix + message));
}
public static String toCommaSep(Collection<String> strings) {
@ -163,19 +130,20 @@ public final class MessageUtils {
/**
* Produces a string representing a Nodes context, suitable for appending onto another message line.
*
* @param localeManager the locale manager
* @param node the node to query context from
* @return a string representing the nodes context, or an empty string if the node applies globally.
*/
public static String getAppendableNodeContextString(Node node) {
public static String getAppendableNodeContextString(LocaleManager localeManager, Node node) {
StringBuilder sb = new StringBuilder();
if (node.isServerSpecific()) {
sb.append(" ").append(contextToString(Contexts.SERVER_KEY, node.getServer().get()));
sb.append(" ").append(contextToString(localeManager, Contexts.SERVER_KEY, node.getServer().get()));
}
if (node.isWorldSpecific()) {
sb.append(" ").append(contextToString(Contexts.WORLD_KEY, node.getWorld().get()));
sb.append(" ").append(contextToString(localeManager, Contexts.WORLD_KEY, node.getWorld().get()));
}
for (Map.Entry<String, String> c : node.getContexts().toSet()) {
sb.append(" ").append(contextToString(c.getKey(), c.getValue()));
sb.append(" ").append(contextToString(localeManager, c.getKey(), c.getValue()));
}
return sb.toString();
@ -184,27 +152,29 @@ public final class MessageUtils {
/**
* Converts a context pair to a formatted string, surrounded by ( ) brackets.
*
*
* @param localeManager the locale manager
* @param key the context key
* @param value the context value
* @return a formatted string
*/
public static String contextToString(String key, String value) {
return Message.CONTEXT_PAIR.asString(null, key, value);
public static String contextToString(LocaleManager localeManager, String key, String value) {
return Message.CONTEXT_PAIR.asString(localeManager, key, value);
}
public static String contextSetToString(ContextSet set) {
public static String contextSetToString(LocaleManager localeManager, ContextSet set) {
if (set.isEmpty()) {
return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(null);
return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(localeManager);
}
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> e : set.toSet()) {
sb.append(Message.CONTEXT_PAIR_INLINE.asString(null, e.getKey(), e.getValue()));
sb.append(Message.CONTEXT_PAIR_SEP.asString(null));
sb.append(Message.CONTEXT_PAIR_INLINE.asString(localeManager, e.getKey(), e.getValue()));
sb.append(Message.CONTEXT_PAIR_SEP.asString(localeManager));
}
return sb.delete(sb.length() - Message.CONTEXT_PAIR_SEP.asString(null).length(), sb.length()).toString();
return sb.delete(sb.length() - Message.CONTEXT_PAIR_SEP.asString(localeManager).length(), sb.length()).toString();
}
private MessageUtils() {}

View File

@ -29,7 +29,6 @@ import me.lucko.luckperms.api.ChatMetaType;
import me.lucko.luckperms.api.DataMutateResult;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
@ -85,7 +84,7 @@ public class MetaAddChatMeta extends SharedSubCommand {
DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
if (result.asBoolean()) {
TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
@ -100,7 +99,7 @@ public class MetaAddChatMeta extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context));
Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}

View File

@ -30,7 +30,6 @@ import me.lucko.luckperms.api.DataMutateResult;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
@ -95,7 +94,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
if (ret.getKey().asBoolean()) {
duration = ret.getValue().getExpiryUnixTime();
TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
@ -110,7 +109,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context));
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}

View File

@ -104,9 +104,9 @@ public class MetaClear extends SharedSubCommand {
int changed = before - holder.enduringData().immutable().size();
if (changed == 1) {
Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(context), changed);
Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.META_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(context), changed);
Message.META_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
ExtendedLogEntry.build().actor(sender).acted(holder)

View File

@ -29,7 +29,6 @@ import com.google.common.collect.Maps;
import me.lucko.luckperms.api.ChatMetaType;
import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
@ -124,12 +123,12 @@ public class MetaInfo extends SharedSubCommand {
for (LocalizedNode m : meta) {
String location = processLocation(m, holder);
if (m.hasSpecificContext()) {
String context = MessageUtils.getAppendableNodeContextString(m);
TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context), CommandManager.SECTION_CHAR).toBuilder();
String context = MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), m);
TextComponent.Builder builder = Message.META_ENTRY_WITH_CONTEXT.asComponent(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context).toBuilder();
builder.applyDeep(makeFancy(holder, label, m));
sender.sendMessage(builder.build());
} else {
TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location), CommandManager.SECTION_CHAR).toBuilder();
TextComponent.Builder builder = Message.META_ENTRY.asComponent(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location).toBuilder();
builder.applyDeep(makeFancy(holder, label, m));
sender.sendMessage(builder.build());
}
@ -140,12 +139,12 @@ public class MetaInfo extends SharedSubCommand {
for (Map.Entry<Integer, LocalizedNode> e : meta) {
String location = processLocation(e.getValue(), holder);
if (e.getValue().hasSpecificContext()) {
String context = MessageUtils.getAppendableNodeContextString(e.getValue());
TextComponent.Builder builder = TextUtils.fromLegacy(Message.CHAT_META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location, context), CommandManager.SECTION_CHAR).toBuilder();
String context = MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), e.getValue());
TextComponent.Builder builder = Message.CHAT_META_ENTRY_WITH_CONTEXT.asComponent(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location, context).toBuilder();
builder.applyDeep(makeFancy(type, holder, label, e.getValue()));
sender.sendMessage(builder.build());
} else {
TextComponent.Builder builder = TextUtils.fromLegacy(Message.CHAT_META_ENTRY.asString(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location), CommandManager.SECTION_CHAR).toBuilder();
TextComponent.Builder builder = Message.CHAT_META_ENTRY.asComponent(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location).toBuilder();
builder.applyDeep(makeFancy(type, holder, label, e.getValue()));
sender.sendMessage(builder.build());
}

View File

@ -29,7 +29,6 @@ import me.lucko.luckperms.api.ChatMetaType;
import me.lucko.luckperms.api.DataMutateResult;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
@ -91,7 +90,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
!n.isTemporary() &&
n.getFullContexts().makeImmutable().equals(context.makeImmutable())
);
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(context));
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("meta" , "remove" + this.type.name().toLowerCase(), priority, "*", context)
@ -104,7 +103,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
if (result.asBoolean()) {
TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
TextComponent.Builder builder = Message.REMOVE_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
@ -119,7 +118,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_HAVE_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context));
Message.DOES_NOT_HAVE_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}

View File

@ -29,7 +29,6 @@ import me.lucko.luckperms.api.ChatMetaType;
import me.lucko.luckperms.api.DataMutateResult;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
@ -91,7 +90,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
!n.isPermanent() &&
n.getFullContexts().makeImmutable().equals(context.makeImmutable())
);
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(context));
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("meta" , "removetemp" + this.type.name().toLowerCase(), priority, "*", context)
@ -104,7 +103,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).setExpiry(10L).withExtraContext(context).build());
if (result.asBoolean()) {
TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
TextComponent.Builder builder = Message.REMOVE_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥'
@ -119,7 +118,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context));
Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}

View File

@ -82,14 +82,14 @@ public class MetaSet extends SharedSubCommand {
Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).build();
if (holder.hasPermission(NodeMapType.ENDURING, n, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
Message.ALREADY_HAS_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(context));
Message.ALREADY_HAS_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
holder.clearMetaKeys(key, context, false);
holder.setPermission(n);
TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), MessageUtils.contextSetToString(context))).toBuilder();
TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value),
'¥'

View File

@ -29,7 +29,6 @@ import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.StandardNodeEquality;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
@ -88,14 +87,14 @@ public class MetaSetTemp extends SharedSubCommand {
Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).setExpiry(duration).build();
if (holder.hasPermission(NodeMapType.ENDURING, n, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(context));
Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
holder.clearMetaKeys(key, context, true);
duration = holder.setPermission(n, modifier).getValue().getExpiryUnixTime();
TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_TEMP_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
TextComponent.Builder builder = Message.SET_META_TEMP_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value),
'¥'

View File

@ -71,7 +71,7 @@ public class MetaUnset extends SharedSubCommand {
}
if (holder.clearMetaKeys(key, context, false)) {
Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("meta", "unset", key, context)
@ -80,7 +80,7 @@ public class MetaUnset extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOESNT_HAVE_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(context));
Message.DOESNT_HAVE_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}

View File

@ -71,7 +71,7 @@ public class MetaUnsetTemp extends SharedSubCommand {
}
if (holder.clearMetaKeys(key, context, true)) {
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("meta", "unsettemp", key, context)
@ -80,7 +80,7 @@ public class MetaUnsetTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOESNT_HAVE_TEMP_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(context));
Message.DOESNT_HAVE_TEMP_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}

View File

@ -74,9 +74,9 @@ public class HolderClear<T extends PermissionHolder> extends SubCommand<T> {
int changed = before - holder.enduringData().immutable().size();
if (changed == 1) {
Message.CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
Message.CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
Message.CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
ExtendedLogEntry.build().actor(sender).acted(holder)

View File

@ -86,7 +86,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T>
.collect(Collectors.toList());
for (Track t : tracks) {
lines.add(Maps.immutableEntry(t, MessageUtils.getAppendableNodeContextString(node) + "\n" + MessageUtils.listToArrowSep(t.getGroups(), groupName)));
lines.add(Maps.immutableEntry(t, MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node) + "\n" + MessageUtils.listToArrowSep(t.getGroups(), groupName)));
}
}
} else {

View File

@ -33,6 +33,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;
@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentAdd extends SharedSubCommand {
public ParentAdd(LocaleManager locale) {
super(CommandSpec.PARENT_ADD.localize(locale), "add", CommandPermission.USER_PARENT_ADD, CommandPermission.GROUP_PARENT_ADD, Predicates.is(0));
@ -83,7 +83,7 @@ public class ParentAdd extends SharedSubCommand {
DataMutateResult result = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
if (result.asBoolean()) {
Message.SET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.SET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "add", group.getName(), context)
@ -92,13 +92,15 @@ public class ParentAdd extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -34,6 +34,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;
@ -53,8 +55,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.Map;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentAddTemp extends SharedSubCommand {
public ParentAddTemp(LocaleManager locale) {
super(CommandSpec.PARENT_ADD_TEMP.localize(locale), "addtemp", CommandPermission.USER_PARENT_ADD_TEMP, CommandPermission.GROUP_PARENT_ADD_TEMP, Predicates.inRange(0, 1));
@ -88,7 +88,7 @@ public class ParentAddTemp extends SharedSubCommand {
}
if (group.getName().equalsIgnoreCase(holder.getObjectName())) {
Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
@ -96,7 +96,7 @@ public class ParentAddTemp extends SharedSubCommand {
if (ret.getKey().asBoolean()) {
duration = ret.getValue().getExpiryUnixTime();
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(context));
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "addtemp", group.getName(), duration, context)
@ -105,13 +105,15 @@ public class ParentAddTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -74,9 +74,9 @@ public class ParentClear extends SharedSubCommand {
int changed = before - holder.enduringData().immutable().size();
if (changed == 1) {
Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.PARENT_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
Message.PARENT_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
ExtendedLogEntry.build().actor(sender).acted(holder)

View File

@ -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;
@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getTrackTabComplete;
public class ParentClearTrack extends SharedSubCommand {
public ParentClearTrack(LocaleManager locale) {
super(CommandSpec.PARENT_CLEAR_TRACK.localize(locale), "cleartrack", CommandPermission.USER_PARENT_CLEAR_TRACK, CommandPermission.GROUP_PARENT_CLEAR_TRACK, Predicates.is(0));
@ -105,9 +105,9 @@ public class ParentClearTrack extends SharedSubCommand {
int changed = before - holder.enduringData().immutable().size();
if (changed == 1) {
Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(context), changed);
Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(context), changed);
Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
ExtendedLogEntry.build().actor(sender).acted(holder)
@ -120,6 +120,8 @@ public class ParentClearTrack extends SharedSubCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getTrackTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.tracks(plugin))
.complete(args);
}
}

View File

@ -112,7 +112,7 @@ public class ParentInfo extends SharedSubCommand {
// send content
for (LocalizedNode node : content) {
String s = "&3> &a" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node);
String s = "&3> &a" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node);
if (node.isTemporary()) {
s += "\n&2 expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime());
}

View File

@ -33,6 +33,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;
@ -49,8 +51,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentRemove extends SharedSubCommand {
public ParentRemove(LocaleManager locale) {
super(CommandSpec.PARENT_REMOVE.localize(locale), "remove", CommandPermission.USER_PARENT_REMOVE, CommandPermission.GROUP_PARENT_REMOVE, Predicates.is(0));
@ -92,7 +92,7 @@ public class ParentRemove extends SharedSubCommand {
DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).withExtraContext(context).build());
if (result.asBoolean()) {
Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "remove", groupName, context)
@ -105,13 +105,15 @@ public class ParentRemove extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
Message.DOES_NOT_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -33,6 +33,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;
@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentRemoveTemp extends SharedSubCommand {
public ParentRemoveTemp(LocaleManager locale) {
super(CommandSpec.PARENT_REMOVE_TEMP.localize(locale), "removetemp", CommandPermission.USER_PARENT_REMOVE_TEMP, CommandPermission.GROUP_PARENT_REMOVE_TEMP, Predicates.is(0));
@ -77,7 +77,7 @@ public class ParentRemoveTemp extends SharedSubCommand {
DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).setExpiry(10L).withExtraContext(context).build());
if (result.asBoolean()) {
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "removetemp", groupName, context)
@ -86,13 +86,15 @@ public class ParentRemoveTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_TEMP_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
Message.DOES_NOT_TEMP_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -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;
@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentSet extends SharedSubCommand {
public ParentSet(LocaleManager locale) {
super(CommandSpec.PARENT_SET.localize(locale), "set", CommandPermission.USER_PARENT_SET, CommandPermission.GROUP_PARENT_SET, Predicates.is(0));
@ -86,7 +86,7 @@ public class ParentSet extends SharedSubCommand {
((User) holder).getPrimaryGroup().setStoredValue(group.getName());
}
Message.SET_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.SET_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "set", group.getName(), context)
@ -98,6 +98,8 @@ public class ParentSet extends SharedSubCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -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;
@ -49,9 +51,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getTrackTabComplete;
public class ParentSetTrack extends SharedSubCommand {
public ParentSetTrack(LocaleManager locale) {
super(CommandSpec.PARENT_SET_TRACK.localize(locale), "settrack", CommandPermission.USER_PARENT_SET_TRACK, CommandPermission.GROUP_PARENT_SET_TRACK, Predicates.inRange(0, 1));
@ -117,7 +116,7 @@ public class ParentSetTrack extends SharedSubCommand {
holder.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName()));
holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "settrack", track.getName(), groupName, context)
@ -129,11 +128,9 @@ public class ParentSetTrack extends SharedSubCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.isEmpty() || args.size() == 1) {
return getTrackTabComplete(args, plugin);
}
args.remove(0);
return getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.tracks(plugin))
.at(1, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -32,6 +32,8 @@ import me.lucko.luckperms.common.command.CommandResult;
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.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class UserSwitchPrimaryGroup extends SharedSubCommand {
public UserSwitchPrimaryGroup(LocaleManager locale) {
super(CommandSpec.USER_SWITCHPRIMARYGROUP.localize(locale), "switchprimarygroup", CommandPermission.USER_PARENT_SWITCHPRIMARYGROUP, null, Predicates.not(1));
@ -102,6 +102,8 @@ public class UserSwitchPrimaryGroup extends SharedSubCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -33,6 +33,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.locale.LocaleManager;
@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionCheck extends SharedSubCommand {
public PermissionCheck(LocaleManager locale) {
super(CommandSpec.PERMISSION_CHECK.localize(locale), "check", CommandPermission.USER_PERM_CHECK, CommandPermission.GROUP_PERM_CHECK, Predicates.is(0));
@ -67,12 +67,14 @@ public class PermissionCheck extends SharedSubCommand {
Tristate result = holder.hasPermission(NodeMapType.ENDURING, NodeFactory.builder(node).withExtraContext(context).build(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
String s = MessageUtils.formatTristate(result);
Message.CHECK_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context));
Message.CHECK_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.SUCCESS;
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionRegistry());
return TabCompleter.create()
.at(0, TabCompletions.permissions(plugin))
.complete(args);
}
}

View File

@ -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.locale.LocaleManager;
@ -46,8 +48,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionCheckInherits extends SharedSubCommand {
public PermissionCheckInherits(LocaleManager locale) {
super(CommandSpec.PERMISSION_CHECK_INHERITS.localize(locale), "checkinherits", CommandPermission.USER_PERM_CHECK_INHERITS, CommandPermission.GROUP_PERM_CHECK_INHERITS, Predicates.is(0));
@ -71,12 +71,14 @@ public class PermissionCheckInherits extends SharedSubCommand {
}
String s = MessageUtils.formatTristate(result.getResult());
Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context), String.valueOf(location));
Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context), String.valueOf(location));
return CommandResult.SUCCESS;
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionRegistry());
return TabCompleter.create()
.at(0, TabCompletions.permissions(plugin))
.complete(args);
}
}

View File

@ -74,9 +74,9 @@ public class PermissionClear extends SharedSubCommand {
int changed = before - holder.enduringData().immutable().size();
if (changed == 1) {
Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.PERMISSION_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
Message.PERMISSION_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
ExtendedLogEntry.build().actor(sender).acted(holder)

View File

@ -81,8 +81,7 @@ public class PermissionInfo extends SharedSubCommand {
// remove irrelevant types (these are displayed in the other info commands)
nodes.removeIf(node -> (node.isGroupNode() && node.getValue() && plugin.getGroupManager().isLoaded(node.getGroupName())) ||
// remove if the node is a meta node
node.isPrefix() || node.isSuffix() || node.isMeta()
);
node.isPrefix() || node.isSuffix() || node.isMeta());
// handle empty
if (nodes.isEmpty()) {
@ -115,7 +114,7 @@ public class PermissionInfo extends SharedSubCommand {
// send content
for (LocalizedNode node : content) {
String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission() + (sender.isConsole() ? " &7(" + node.getValue() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(node);
String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission() + (sender.isConsole() ? " &7(" + node.getValue() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node);
if (node.isTemporary()) {
s += "\n&2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime());
}

View File

@ -33,6 +33,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;
@ -47,9 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getBoolTabComplete;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionSet extends SharedSubCommand {
public PermissionSet(LocaleManager locale) {
super(CommandSpec.PERMISSION_SET.localize(locale), "set", CommandPermission.USER_PERM_SET, CommandPermission.GROUP_PERM_SET, Predicates.is(0));
@ -79,7 +78,7 @@ public class PermissionSet extends SharedSubCommand {
DataMutateResult result = holder.setPermission(NodeFactory.builder(node).setValue(value).withExtraContext(context).build());
if (result.asBoolean()) {
Message.SETPERMISSION_SUCCESS.send(sender, node, value, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.SETPERMISSION_SUCCESS.send(sender, node, value, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("permission", "set", node, value, context)
@ -88,17 +87,16 @@ public class PermissionSet extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HASPERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context));
Message.ALREADY_HASPERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
List<String> ret = getBoolTabComplete(args);
if (!ret.isEmpty()) {
return ret;
}
return getPermissionTabComplete(args, plugin.getPermissionRegistry());
return TabCompleter.create()
.at(0, TabCompletions.permissions(plugin))
.at(1, TabCompletions.booleans())
.complete(args);
}
}

View File

@ -34,6 +34,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;
@ -52,9 +54,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.Map;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getBoolTabComplete;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionSetTemp extends SharedSubCommand {
public PermissionSetTemp(LocaleManager locale) {
super(CommandSpec.PERMISSION_SETTEMP.localize(locale), "settemp", CommandPermission.USER_PERM_SET_TEMP, CommandPermission.GROUP_PERM_SET_TEMP, Predicates.inRange(0, 2));
@ -87,7 +86,7 @@ public class PermissionSetTemp extends SharedSubCommand {
if (result.getKey().asBoolean()) {
duration = result.getValue().getExpiryUnixTime();
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, holder.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(context));
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, holder.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("permission", "settemp", node, value, duration, context)
@ -96,17 +95,16 @@ public class PermissionSetTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context));
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
List<String> ret = getBoolTabComplete(args);
if (!ret.isEmpty()) {
return ret;
}
return getPermissionTabComplete(args, plugin.getPermissionRegistry());
return TabCompleter.create()
.at(0, TabCompletions.permissions(plugin))
.at(1, TabCompletions.booleans())
.complete(args);
}
}

View File

@ -33,6 +33,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;
@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionUnset extends SharedSubCommand {
public PermissionUnset(LocaleManager locale) {
super(CommandSpec.PERMISSION_UNSET.localize(locale), "unset", CommandPermission.USER_PERM_UNSET, CommandPermission.GROUP_PERM_UNSET, Predicates.is(0));
@ -77,7 +77,7 @@ public class PermissionUnset extends SharedSubCommand {
DataMutateResult result = holder.unsetPermission(NodeFactory.builder(node).withExtraContext(context).build());
if (result.asBoolean()) {
Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("permission", "unset", node, context)
@ -86,13 +86,15 @@ public class PermissionUnset extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_HAVE_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context));
Message.DOES_NOT_HAVE_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionRegistry());
return TabCompleter.create()
.at(0, TabCompletions.permissions(plugin))
.complete(args);
}
}

View File

@ -33,6 +33,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;
@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionUnsetTemp extends SharedSubCommand {
public PermissionUnsetTemp(LocaleManager locale) {
super(CommandSpec.PERMISSION_UNSETTEMP.localize(locale), "unsettemp", CommandPermission.USER_PERM_UNSET_TEMP, CommandPermission.GROUP_PERM_UNSET_TEMP, Predicates.is(0));
@ -77,7 +77,7 @@ public class PermissionUnsetTemp extends SharedSubCommand {
DataMutateResult result = holder.unsetPermission(NodeFactory.builder(node).setExpiry(10L).withExtraContext(context).build());
if (result.asBoolean()) {
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(holder)
.action("permission", "unsettemp", node, context)
@ -86,13 +86,15 @@ public class PermissionUnsetTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context));
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
}
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return getPermissionTabComplete(args, plugin.getPermissionRegistry());
return TabCompleter.create()
.at(0, TabCompletions.permissions(plugin))
.complete(args);
}
}

View File

@ -31,7 +31,8 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -88,6 +89,8 @@ public class DeleteGroup extends SingleCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -75,15 +75,15 @@ public class GroupInfo extends SubCommand<Group> {
if (!parents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (Node node : parents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node));
}
}
if (!tempParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (Node node : tempParents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
Message.EMPTY.send(sender, "&f- &2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()));
Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node));
Message.INFO_PARENT_ENTRY_EXPIRY.send(sender, DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()));
}
}
return CommandResult.SUCCESS;

View File

@ -142,7 +142,7 @@ public class GroupListMembers extends SubCommand<Group> {
headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), ent.getValue().asNode());
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
sender.sendMessage(message);
}

View File

@ -83,7 +83,7 @@ public class GroupSetDisplayName extends SubCommand<Group> {
group.removeIf(context, n -> n.getTypeData(DisplayNameType.KEY).isPresent());
if (name.equals(group.getName())) {
Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, group.getName(), MessageUtils.contextSetToString(context));
Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(group)
.action("setdisplayname", name, context)
@ -95,7 +95,7 @@ public class GroupSetDisplayName extends SubCommand<Group> {
group.setPermission(NodeFactory.builder("displayname." + name).withExtraContext(context).build());
Message.GROUP_SET_DISPLAY_NAME.send(sender, name, group.getName(), MessageUtils.contextSetToString(context));
Message.GROUP_SET_DISPLAY_NAME.send(sender, name, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(group)
.action("setdisplayname", name, context)

View File

@ -25,7 +25,6 @@
package me.lucko.luckperms.common.commands.group;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
@ -37,7 +36,6 @@ import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
@ -74,16 +72,16 @@ public class ListGroups extends SingleCommand {
TextComponent component;
if (tracks.isEmpty()) {
component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY.asString(plugin.getLocaleManager(),
component = Message.GROUPS_LIST_ENTRY.asComponent(plugin.getLocaleManager(),
group.getFriendlyName(),
group.getWeight().orElse(0)
), CommandManager.SECTION_CHAR);
);
} else {
component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asString(plugin.getLocaleManager(),
component = Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asComponent(plugin.getLocaleManager(),
group.getFriendlyName(),
group.getWeight().orElse(0),
MessageUtils.toCommaSep(tracks)
), CommandManager.SECTION_CHAR);
);
}
component = component.toBuilder().applyDeep(c -> {

View File

@ -30,8 +30,9 @@ import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand;
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.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -109,6 +110,8 @@ public class LogGroupHistory extends SubCommand<Log> {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -30,8 +30,9 @@ import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand;
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.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -109,6 +110,8 @@ public class LogTrackHistory extends SubCommand<Log> {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getTrackTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.tracks(plugin))
.complete(args);
}
}

View File

@ -141,17 +141,17 @@ public class ApplyEditsCommand extends SingleCommand {
Message.APPLY_EDITS_SUCCESS.send(sender, holder.getFriendlyName());
Message.APPLY_EDITS_SUCCESS_SUMMARY.send(sender, additions, additionsSummary, deletions, deletionsSummary);
for (Node n : diffAdded) {
Message.APPLY_EDITS_DIFF_ADDED.send(sender, formatNode(n));
Message.APPLY_EDITS_DIFF_ADDED.send(sender, formatNode(plugin.getLocaleManager(), n));
}
for (Node n : diffRemoved) {
Message.APPLY_EDITS_DIFF_REMOVED.send(sender, formatNode(n));
Message.APPLY_EDITS_DIFF_REMOVED.send(sender, formatNode(plugin.getLocaleManager(), n));
}
StorageAssistant.save(holder, sender, plugin);
return true;
}
private static String formatNode(Node n) {
return n.getPermission() + " &7(" + (n.getValue() ? "&a" : "&c") + n.getValue() + "&7)" + MessageUtils.getAppendableNodeContextString(n) +
private static String formatNode(LocaleManager localeManager, Node n) {
return n.getPermission() + " &7(" + (n.getValue() ? "&a" : "&c") + n.getValue() + "&7)" + MessageUtils.getAppendableNodeContextString(localeManager, n) +
(n.isTemporary() ? " &7(" + DurationFormatter.CONCISE.formatDateDiff(n.getExpiryUnixTime()) + ")" : "");
}

View File

@ -29,8 +29,10 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -75,15 +77,9 @@ public class CheckCommand extends SingleCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.isEmpty()) {
return plugin.getBootstrap().getPlayerList().collect(Collectors.toList());
}
if (args.size() == 1) {
return plugin.getBootstrap().getPlayerList().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
}
args.remove(0);
return TabCompletions.getPermissionTabComplete(args, plugin.getPermissionRegistry());
return TabCompleter.create()
.at(0, CompletionSupplier.startsWith(() -> plugin.getBootstrap().getPlayerList().collect(Collectors.toList())))
.at(1, TabCompletions.permissions(plugin))
.complete(args);
}
}

View File

@ -55,10 +55,9 @@ public class InfoCommand extends SingleCommand {
plugin.getBootstrap().getServerVersion()
);
Message.EMPTY.send(sender, "&f- &bStorage:");
Message.EMPTY.send(sender, "&f- &3Type: &f" + plugin.getStorage().getName());
Message.INFO_STORAGE.send(sender, plugin.getStorage().getName());
for (Map.Entry<String, String> e : plugin.getStorage().getMeta().entrySet()) {
Message.EMPTY.send(sender, "&f- &3" + e.getKey() + ": " + formatValue(e.getValue()));
Message.INFO_STORAGE_META.send(sender, e.getKey(), formatValue(e.getValue()));
}
Message.INFO_MIDDLE.send(sender,

View File

@ -38,9 +38,10 @@ import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
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.TabCompletions;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
@ -123,7 +124,9 @@ public class SearchCommand extends SingleCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getPermissionTabComplete(args, plugin.getPermissionRegistry());
return TabCompleter.create()
.at(0, TabCompletions.permissions(plugin))
.complete(args);
}
private static <T extends Comparable<T>> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page, Comparison comparison) {
@ -154,7 +157,7 @@ public class SearchCommand extends SingleCommand {
permission = "&7 - (" + ent.getValue().getPermission() + ")";
}
String s = "&3> &b" + ent.getKey() + permission + "&7 - " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
String s = "&3> &b" + ent.getKey() + permission + "&7 - " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), ent.getValue().asNode());
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
sender.sendMessage(message);
}

View File

@ -31,7 +31,8 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -80,6 +81,8 @@ public class DeleteTrack extends SingleCommand {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getTrackTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.tracks(plugin))
.complete(args);
}
}

View File

@ -30,9 +30,10 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand;
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.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -85,6 +86,8 @@ public class TrackAppend extends SubCommand<Track> {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -30,9 +30,10 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand;
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.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -99,6 +100,8 @@ public class TrackInsert extends SubCommand<Track> {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -30,9 +30,10 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand;
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.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -79,6 +80,8 @@ public class TrackRemove extends SubCommand<Track> {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getGroupTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.groups(plugin))
.complete(args);
}
}

View File

@ -33,10 +33,11 @@ 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;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -115,7 +116,7 @@ public class UserDemote extends SubCommand<User> {
String groupFrom = result.getGroupFrom().get();
String groupTo = result.getGroupTo().get();
Message.USER_DEMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(context));
Message.USER_DEMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
if (!silent) {
Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupTo, groupFrom, true));
}
@ -135,6 +136,8 @@ public class UserDemote extends SubCommand<User> {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getTrackTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.tracks(plugin))
.complete(args);
}
}

View File

@ -85,15 +85,15 @@ public class UserInfo extends SubCommand<User> {
if (!parents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (Node node : parents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node));
}
}
if (!tempParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (Node node : tempParents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
Message.EMPTY.send(sender, "&f- &2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()));
Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node));
Message.INFO_PARENT_ENTRY_EXPIRY.send(sender, DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()));
}
}
@ -106,7 +106,7 @@ public class UserInfo extends SubCommand<User> {
ContextSet contextSet = contexts.getContexts();
if (!contextSet.isEmpty()) {
context = contextSet.toSet().stream()
.map(e -> MessageUtils.contextToString(e.getKey(), e.getValue()))
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
.collect(Collectors.joining(" "));
}
@ -121,7 +121,7 @@ public class UserInfo extends SubCommand<User> {
ListMultimap<String, String> metaMap = data.getMetaMultimap();
if (!metaMap.isEmpty()) {
meta = metaMap.entries().stream()
.map(e -> MessageUtils.contextToString(e.getKey(), e.getValue()))
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
.collect(Collectors.joining(" "));
}
}

View File

@ -33,10 +33,11 @@ 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;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
@ -101,7 +102,7 @@ public class UserPromote extends SubCommand<User> {
return CommandResult.STATE_ERROR;
case ADDED_TO_FIRST_GROUP: {
Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getFriendlyName(), result.getGroupTo().get(), MessageUtils.contextSetToString(context));
Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getFriendlyName(), result.getGroupTo().get(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
ExtendedLogEntry.build().actor(sender).acted(user)
.action("promote", track.getName(), context)
@ -115,7 +116,7 @@ public class UserPromote extends SubCommand<User> {
String groupFrom = result.getGroupFrom().get();
String groupTo = result.getGroupTo().get();
Message.USER_PROMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(context));
Message.USER_PROMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
if (!silent) {
Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupFrom, groupTo, false));
}
@ -135,6 +136,8 @@ public class UserPromote extends SubCommand<User> {
@Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
return TabCompletions.getTrackTabComplete(args, plugin);
return TabCompleter.create()
.at(0, TabCompletions.tracks(plugin))
.complete(args);
}
}

View File

@ -106,10 +106,6 @@ public class AbstractConfiguration implements LuckPermsConfiguration {
getPlugin().getEventFactory().handleConfigReload();
}
public ConfigurationAdapter getAdapter() {
return this.adapter;
}
@Override
public LuckPermsPlugin getPlugin() {
return this.plugin;

View File

@ -373,7 +373,7 @@ public final class ConfigKeys {
* The default assignments being applied by the plugin
*/
public static final ConfigKey<List<AssignmentRule>> DEFAULT_ASSIGNMENTS = CustomKey.of(c -> {
return c.getObjectList("default-assignments", ImmutableList.of()).stream().map(name -> {
return c.getKeys("default-assignments", ImmutableList.of()).stream().map(name -> {
String hasTrue = c.getString("default-assignments." + name + ".if.has-true", null);
String hasFalse = c.getString("default-assignments." + name + ".if.has-false", null);
String lacks = c.getString("default-assignments." + name + ".if.lacks", null);

View File

@ -44,7 +44,7 @@ public interface ConfigurationAdapter {
List<String> getList(String path, List<String> def);
List<String> getObjectList(String path, List<String> def);
List<String> getKeys(String path, List<String> def);
Map<String, String> getMap(String path, Map<String, String> def);

View File

@ -38,6 +38,7 @@ import java.io.BufferedReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.EnumMap;
import java.util.Map;
public class LocaleManager {
@ -71,8 +72,8 @@ public class LocaleManager {
@SuppressWarnings("unchecked")
public void loadFromFile(Path file) throws Exception {
try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
ImmutableMap.Builder<Message, String> messages = ImmutableMap.builder();
ImmutableMap.Builder<CommandSpec, CommandSpecData> commands = ImmutableMap.builder();
EnumMap<Message, String> messages = new EnumMap<>(Message.class);
EnumMap<CommandSpec, CommandSpecData> commands = new EnumMap<>(CommandSpec.class);
Map<String, Object> data = (Map<String, Object>) new Yaml().load(reader);
for (Map.Entry<String, Object> entry : data.entrySet()) {
@ -124,20 +125,11 @@ public class LocaleManager {
}
}
this.messages = messages.build();
this.commands = commands.build();
this.messages = ImmutableMap.copyOf(messages);
this.commands = ImmutableMap.copyOf(commands);
}
}
/**
* Gets the size of loaded translations
*
* @return the size of the loaded translations
*/
public int getSize() {
return this.messages.size() + this.commands.size();
}
/**
* Gets a translation for a given message key
*

View File

@ -27,6 +27,11 @@ package me.lucko.luckperms.common.locale.command;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.message.Message;
import javax.annotation.Nullable;
public class Argument {
public static Argument create(String name, boolean required, String description) {
return new Argument(name, required, description);
@ -46,8 +51,8 @@ public class Argument {
this.description = description;
}
public String asPrettyString() {
return this.required ? "&8<&7" + this.name + "&8>" : "&8[&7" + this.name + "&8]";
public String asPrettyString(@Nullable LocaleManager localeManager) {
return (this.required ? Message.REQUIRED_ARGUMENT : Message.OPTIONAL_ARGUMENT).asString(localeManager, this.name);
}
public String getName() {

View File

@ -25,11 +25,13 @@
package me.lucko.luckperms.common.locale.message;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.utils.TextUtils;
import net.kyori.text.TextComponent;
import javax.annotation.Nullable;
/**
@ -65,7 +67,7 @@ public enum Message {
"{PREFIX}&3LOG &3&l> &f{}",
false
),
VERBOSE_LOG("&3VB &3&l> {}", true),
VERBOSE_LOG("&3VB &3&l> &a{}&7 - &a{}&7 - {}{}", true),
EXPORT_LOG("&3EXPORT &3&l> &f{}", true),
EXPORT_LOG_PROGRESS("&3EXPORT &3&l> &7{}", true),
MIGRATION_LOG("&3MIGRATION &7[&3{}&7] &3&l> &f{}", true),
@ -78,6 +80,19 @@ public enum Message {
COMMAND_NOT_RECOGNISED("&cCommand not recognised.", true),
COMMAND_NO_PERMISSION("&cYou do not have permission to use this command!", true),
MAIN_COMMAND_USAGE_HEADER("&b{} Sub Commands: &7({} ...)", true),
COMMAND_USAGE_ARGUMENT_JOIN("&3 - &7", false),
COMMAND_USAGE_BRIEF("&3> &a{}{}", false),
COMMAND_USAGE_DETAILED_HEADER(
"{PREFIX}&3&lCommand Usage &3- &b{}" + "\n" +
"{PREFIX}&b> &7{}",
false
),
COMMAND_USAGE_DETAILED_ARGS_HEADER("&3Arguments:", true),
COMMAND_USAGE_DETAILED_ARG("&b- {}&3 -> &7{}", true),
REQUIRED_ARGUMENT("&8<&7{}&8>", false),
OPTIONAL_ARGUMENT("&8[&7{}&8]", false),
/*
* Loading / Saving
@ -180,6 +195,15 @@ public enum Message {
"{PREFIX}&f- {}",
false
),
INFO_STORAGE(
"{PREFIX}&f- &bStorage:" + "\n" +
"{PREFIX}&f- &3Type: &f{}",
false
),
INFO_STORAGE_META("&f- &3{}: {}", true),
INFO_MIDDLE(
"{PREFIX}&f- &bMessaging: &f{}" + "\n" +
"{PREFIX}&f- &bInstance:" + "\n" +
@ -326,6 +350,8 @@ public enum Message {
INFO_PARENT_HEADER("&f- &aParent Groups:", true),
INFO_TEMP_PARENT_HEADER("&f- &aTemporary Parent Groups:", true),
INFO_PARENT_ENTRY("&f- &3> &f{}{}", true),
INFO_PARENT_ENTRY_EXPIRY("&f- &2- expires in {}", true),
USER_REMOVEGROUP_ERROR_PRIMARY("&aYou cannot remove a user from their primary group.", true),
USER_PRIMARYGROUP_SUCCESS("&b{}&a's primary group was set to &b{}&a.", true),
USER_PRIMARYGROUP_WARN_OPTION("&aWarning: The primary group calculation method being used by this server &7({}) &amay not reflect this change.", true),
@ -433,19 +459,6 @@ public enum Message {
IMPORT_END_ERROR_CONTENT("&b(Import) &b-> &c{}", true),
IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", true);
public static final Object SKIP_ELEMENT = new Object();
private static String format(String s, Object... objects) {
for (int i = 0; i < objects.length; i++) {
Object o = objects[i];
if (o != SKIP_ELEMENT) {
s = s.replace("{" + i + "}", String.valueOf(o));
}
}
return s;
}
private final String message;
private final boolean showPrefix;
@ -459,31 +472,67 @@ public enum Message {
return this.message;
}
public String asString(@Nullable LocaleManager localeManager, Object... objects) {
private String getTranslatedMessage(@Nullable LocaleManager localeManager) {
String prefix = null;
if (localeManager != null) {
prefix = localeManager.getTranslation(PREFIX);
prefix = localeManager.getTranslation(this);
}
if (prefix == null) {
prefix = PREFIX.getMessage();
prefix = this.getMessage();
}
return prefix;
}
String s = null;
if (localeManager != null) {
s = localeManager.getTranslation(this);
}
if (s == null) {
s = this.message;
}
private String format(@Nullable LocaleManager localeManager, Object... objects) {
String prefix = PREFIX.getTranslatedMessage(localeManager);
String msg = format(
this.getTranslatedMessage(localeManager)
.replace("{PREFIX}", prefix)
.replace("\\n", "\n"),
objects
);
return this.showPrefix ? prefix + msg : msg;
}
s = format(s.replace("{PREFIX}", prefix).replace("\\n", "\n"), objects);
return MessageUtils.color(this.showPrefix ? prefix + s : s);
public String asString(@Nullable LocaleManager localeManager, Object... objects) {
return colorize(format(localeManager, objects));
}
public TextComponent asComponent(@Nullable LocaleManager localeManager, Object... objects) {
return TextUtils.fromLegacy(format(localeManager, objects), CommandManager.AMPERSAND_CHAR);
}
public void send(Sender sender, Object... objects) {
sender.sendMessage(asString(sender.getPlatform().getLocaleManager(), objects));
}
private static String format(String s, Object... objects) {
for (int i = 0; i < objects.length; i++) {
Object o = objects[i];
s = s.replace("{" + i + "}", String.valueOf(o));
}
return s;
}
/**
* Colorizes a message.
*
* @param s the message to colorize
* @return a colored message
*/
public static String colorize(String s) {
char[] b = s.toCharArray();
for (int i = 0; i < b.length - 1; ++i) {
if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) {
b[i] = 167;
b[i + 1] = Character.toLowerCase(b[i + 1]);
}
}
return new String(b);
}
/**
* Prints this Message enum in a yml format, for reading by the locale manager
* @param args not needed

View File

@ -32,7 +32,6 @@ import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.buffers.BufferedRequest;
import me.lucko.luckperms.common.buffers.UpdateTaskBuffer;
import me.lucko.luckperms.common.calculators.CalculatorFactory;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.config.AbstractConfiguration;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
@ -44,6 +43,7 @@ import me.lucko.luckperms.common.event.AbstractEventBus;
import me.lucko.luckperms.common.event.EventFactory;
import me.lucko.luckperms.common.inheritance.InheritanceHandler;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.messaging.InternalMessagingService;
import me.lucko.luckperms.common.messaging.MessagingFactory;
import me.lucko.luckperms.common.plugin.logging.PluginLogger;
@ -318,9 +318,9 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
}
private void displayBanner(Sender sender) {
sender.sendMessage(MessageUtils.color("&b &3 __ "));
sender.sendMessage(MessageUtils.color("&b | &3|__) " + "&2LuckPerms &bv" + getBootstrap().getVersion()));
sender.sendMessage(MessageUtils.color("&b |___ &3| " + "&8Running on " + getBootstrap().getType().getFriendlyName() + " - " + getBootstrap().getServerBrand()));
sender.sendMessage(Message.colorize("&b &3 __ "));
sender.sendMessage(Message.colorize("&b | &3|__) " + "&2LuckPerms &bv" + getBootstrap().getVersion()));
sender.sendMessage(Message.colorize("&b |___ &3| " + "&8Running on " + getBootstrap().getType().getFriendlyName() + " - " + getBootstrap().getServerBrand()));
sender.sendMessage("");
}
}

View File

@ -242,7 +242,7 @@ public interface LuckPermsPlugin {
*/
Sender getConsoleSender();
default List<Command> getExtraCommands() {
default List<Command<?, ?>> getExtraCommands() {
return Collections.emptyList();
}

View File

@ -86,16 +86,17 @@ public class ImmutableTreeNode implements Comparable<ImmutableTreeNode> {
List<Map.Entry<Integer, String>> results = new ArrayList<>();
for (Map.Entry<String, ImmutableTreeNode> node : this.children.entrySet()) {
String value = node.getKey();
// add self
results.add(Maps.immutableEntry(0, node.getKey()));
results.add(Maps.immutableEntry(0, value));
// add child nodes, incrementing their level & appending their prefix node
results.addAll(node.getValue().getNodeEndings().stream()
.map(e -> Maps.immutableEntry(
e.getKey() + 1, // increment level
// add this node's key infront of the child value
node.getKey() + "." + e.getValue())
value + "." + e.getValue())
)
.collect(Collectors.toList()));
}

View File

@ -26,17 +26,13 @@
package me.lucko.luckperms.common.treeview;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;
import me.lucko.luckperms.common.utils.RepeatingTask;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@ -50,16 +46,12 @@ public class PermissionRegistry extends RepeatingTask {
// the root node in the tree
private final TreeNode rootNode;
// the known permissions already in the vault
private final Set<String> knownPermissions;
// a queue of permission strings to be processed by the tree
private final Queue<String> queue;
public PermissionRegistry(SchedulerAdapter scheduler) {
super(scheduler, 1, TimeUnit.SECONDS);
this.rootNode = new TreeNode();
this.knownPermissions = ConcurrentHashMap.newKeySet(3000);
this.queue = new ConcurrentLinkedQueue<>();
}
@ -70,15 +62,7 @@ public class PermissionRegistry extends RepeatingTask {
@Override
protected void tick() {
for (String e; (e = this.queue.poll()) != null; ) {
try {
String s = e.toLowerCase();
// only attempt an insert if we're not seen this permission before
if (this.knownPermissions.add(s)) {
insert(s);
}
} catch (Exception ex) {
ex.printStackTrace();
}
insert(e);
}
}
@ -89,12 +73,12 @@ public class PermissionRegistry extends RepeatingTask {
this.queue.offer(permission);
}
public void offerAll(Collection<? extends String> permissions) {
this.queue.addAll(permissions);
}
public Set<String> getKnownPermissions() {
return ImmutableSet.copyOf(this.knownPermissions);
public void insert(String permission) {
try {
doInsert(permission);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public List<String> rootAsList() {
@ -105,14 +89,17 @@ public class PermissionRegistry extends RepeatingTask {
return this.rootNode.getDeepSize();
}
private void insert(String permission) {
private void doInsert(String permission) {
// split the permission up into parts
List<String> parts = DOT_SPLIT.splitToList(permission);
// insert the permission into the node structure
TreeNode current = this.rootNode;
for (String part : parts) {
current = current.resolve(part);
current = current.tryInsert(part);
if (current == null) {
return;
}
}
}

View File

@ -31,12 +31,53 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
/**
* Represents one "branch" or "level" of the node tree
*/
public class TreeNode {
private static boolean allowInsert(TreeNode node) {
/*
We enforce a limit of the size of the node tree to ensure memory
usage remains sane. some plugins check for "dynamic" permissions (cc: griefprevention)
which means this tree can grow to very large sizes and use tons of memory
the rules for limiting the tree size are designed to ensure the system is
still useful, but that unnecessarily large amounts of data aren't stored
the rules are:
1. there can be an unlimited number of root nodes e.g. (luckperms, minecraft)
2. each root node can then have up to 500 child nodes
3. *but*, each root node can have an unlimited number of 2nd level nodes (e.g. luckperms.user)
this takes priority over #2
*/
if (node.level == 2) {
// only allow up to a deep size of 500
return node.parent.getDeepSize() < 500;
}
return true;
}
private Map<String, TreeNode> children = null;
private final int level;
private final TreeNode parent;
private int cachedDeepSize = Integer.MIN_VALUE;
public TreeNode() {
this.level = 0;
this.parent = null;
}
TreeNode(TreeNode parent) {
this.level = parent.level + 1;
this.parent = parent;
}
// lazy init
private synchronized Map<String, TreeNode> getChildMap() {
if (this.children == null) {
@ -45,8 +86,35 @@ public class TreeNode {
return this.children;
}
public TreeNode resolve(String s) {
return getChildMap().computeIfAbsent(s, x -> new TreeNode());
@Nullable
public TreeNode tryInsert(String s) {
Map<String, TreeNode> childMap = getChildMap();
if (!allowInsert(this)) {
return null;
}
return childMap.compute(s, (key, prev) -> {
if (prev != null) {
return prev;
}
// dirty the cache & return a new node
this.cachedDeepSize = Integer.MIN_VALUE;
return new TreeNode(this);
});
}
public TreeNode forceInsert(String s) {
Map<String, TreeNode> childMap = getChildMap();
return childMap.compute(s, (key, prev) -> {
if (prev != null) {
return prev;
}
// dirty the cache & return a new node
this.cachedDeepSize = Integer.MIN_VALUE;
return new TreeNode(this);
});
}
public Optional<Map<String, TreeNode>> getChildren() {
@ -54,10 +122,14 @@ public class TreeNode {
}
public int getDeepSize() {
if (this.cachedDeepSize != Integer.MIN_VALUE) {
return this.cachedDeepSize;
}
if (this.children == null) {
return 1;
return (this.cachedDeepSize = 1);
} else {
return this.children.values().stream().mapToInt(TreeNode::getDeepSize).sum();
return (this.cachedDeepSize = this.children.values().stream().mapToInt(TreeNode::getDeepSize).sum());
}
}

View File

@ -136,20 +136,29 @@ public class VerboseListener {
}
private void sendNotification(CheckData data) {
String msg = "&a" + data.getCheckTarget() + "&7 - &a" + data.getPermission() + "&7 - " + getTristateColor(data.getResult()) + data.getResult().name().toLowerCase();
if (this.notifiedSender.isConsole()) {
// just send as a raw message
Message.VERBOSE_LOG.send(this.notifiedSender, msg);
Message.VERBOSE_LOG.send(this.notifiedSender,
data.getCheckTarget(),
data.getPermission(),
getTristateColor(data.getResult()),
data.getResult().name().toLowerCase()
);
return;
}
// form a hoverevent from the check trace
TextComponent textComponent = TextUtils.fromLegacy(Message.VERBOSE_LOG.asString(this.notifiedSender.getPlatform().getLocaleManager(), msg));
TextComponent textComponent = Message.VERBOSE_LOG.asComponent(this.notifiedSender.getPlatform().getLocaleManager(),
data.getCheckTarget(),
data.getPermission(),
getTristateColor(data.getResult()),
data.getResult().name().toLowerCase()
);
// build the text
List<String> hover = new ArrayList<>();
hover.add("&bOrigin: &2" + data.getCheckOrigin().name());
hover.add("&bContext: &r" + MessageUtils.contextSetToString(data.getCheckContext()));
hover.add("&bContext: &r" + MessageUtils.contextSetToString(this.notifiedSender.getPlatform().getLocaleManager(), data.getCheckContext()));
hover.add("&bTrace: &r");
Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str));

View File

@ -77,7 +77,7 @@ public class NukkitConfigAdapter extends AbstractConfigurationAdapter implements
}
@Override
public List<String> getObjectList(String path, List<String> def) {
public List<String> getKeys(String path, List<String> def) {
ConfigSection section = this.configuration.getSection(path);
if (section == null) {
return def;

View File

@ -94,7 +94,7 @@ public final class LPPermissionMap extends ForwardingMap<String, Permission> {
@Override
public Permission put(@Nonnull String key, @Nonnull Permission value) {
this.plugin.getPermissionRegistry().offer(key);
this.plugin.getPermissionRegistry().insert(key);
Permission ret = super.put(key, value);
update();
return ret;
@ -102,14 +102,14 @@ public final class LPPermissionMap extends ForwardingMap<String, Permission> {
@Override
public void putAll(@Nonnull Map<? extends String, ? extends Permission> m) {
this.plugin.getPermissionRegistry().offerAll(m.keySet());
super.putAll(m);
update();
for (Map.Entry<? extends String, ? extends Permission> ent : m.entrySet()) {
put(ent.getKey(), ent.getValue());
}
}
@Override
public Permission putIfAbsent(String key, Permission value) {
this.plugin.getPermissionRegistry().offer(key);
this.plugin.getPermissionRegistry().insert(key);
Permission ret = super.putIfAbsent(key, value);
update();
return ret;

View File

@ -94,8 +94,6 @@ public final class DescriptionBuilder implements PermissionDescription.Builder {
roleSubject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue());
}
this.service.getPlugin().getPermissionRegistry().offer(this.id);
// null stuff so this instance can be reused
this.roles.clear();
this.id = null;

View File

@ -94,8 +94,6 @@ public final class DescriptionBuilder implements PermissionDescription.Builder {
roleSubject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue());
}
this.service.getPlugin().getPermissionRegistry().offer(this.id);
// null stuff so this instance can be reused
this.roles.clear();
this.id = null;

View File

@ -166,7 +166,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
// before registering our permission service, copy any existing permission descriptions
PermissionRegistry permissionRegistry = getPermissionRegistry();
this.bootstrap.getGame().getServiceManager().provide(PermissionService.class)
.ifPresent(ps -> ps.getDescriptions().stream().map(PermissionDescription::getId).forEach(permissionRegistry::offer));
.ifPresent(ps -> ps.getDescriptions().stream().map(PermissionDescription::getId).forEach(permissionRegistry::insert));
if (this.bootstrap.getGame().getPluginManager().getPlugin("permissionsex").isPresent()) {
getLogger().warn("Detected PermissionsEx - assuming it's loaded for migration.");
@ -268,7 +268,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
}
@Override
public List<Command> getExtraCommands() {
public List<Command<?, ?>> getExtraCommands() {
return Collections.singletonList(new SpongeMainCommand(this));
}

View File

@ -99,7 +99,7 @@ public class SpongeConfigAdapter extends AbstractConfigurationAdapter implements
}
@Override
public List<String> getObjectList(String path, List<String> def) {
public List<String> getKeys(String path, List<String> def) {
ConfigurationNode node = resolvePath(path);
if (node.isVirtual()) {
return def;

View File

@ -53,7 +53,7 @@ public class OptionClear extends SubCommand<LPSubjectData> {
MessageUtils.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a.");
} else {
subjectData.clearOptions(contextSet);
MessageUtils.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
MessageUtils.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
}
return CommandResult.SUCCESS;
}

View File

@ -60,7 +60,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
}
for (Map.Entry<ImmutableContextSet, ImmutableMap<String, String>> e : options.entrySet()) {
MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.optionsToString(e.getValue()));
MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey(), plugin.getLocaleManager()) + "\n" + SpongeCommandUtils.optionsToString(e.getValue()));
}
} else {
@ -71,7 +71,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
}
MessageUtils.sendPluginMessage(sender, "&aShowing options matching contexts &b" +
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.optionsToString(options));
SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()) + "&a.\n" + SpongeCommandUtils.optionsToString(options));
}
return CommandResult.SUCCESS;

View File

@ -52,7 +52,7 @@ public class OptionSet extends SubCommand<LPSubjectData> {
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
if (subjectData.setOption(contextSet, key, value).join()) {
MessageUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
MessageUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?");
}

View File

@ -51,7 +51,7 @@ public class OptionUnset extends SubCommand<LPSubjectData> {
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(1, args);
if (subjectData.unsetOption(contextSet, key).join()) {
MessageUtils.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
MessageUtils.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to unset option. Are you sure the Subject has it set?");
}

View File

@ -70,7 +70,7 @@ public class ParentAdd extends SubCommand<LPSubjectData> {
if (subjectData.addParent(contextSet, subject.toReference()).join()) {
MessageUtils.sendPluginMessage(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() +
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to add parent. Does the Subject already have it added?");
}

View File

@ -53,7 +53,7 @@ public class ParentClear extends SubCommand<LPSubjectData> {
MessageUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a.");
} else {
subjectData.clearParents(contextSet);
MessageUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
MessageUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
}
return CommandResult.SUCCESS;
}

View File

@ -61,7 +61,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
}
for (Map.Entry<ImmutableContextSet, ImmutableList<LPSubjectReference>> e : parents.entrySet()) {
MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey(), plugin.getLocaleManager()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
}
} else {
@ -72,7 +72,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
}
MessageUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &b" +
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.parentsToString(parents));
SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()) + "&a.\n" + SpongeCommandUtils.parentsToString(parents));
}
return CommandResult.SUCCESS;

View File

@ -70,7 +70,7 @@ public class ParentRemove extends SubCommand<LPSubjectData> {
if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
MessageUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() +
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?");
}

View File

@ -53,7 +53,7 @@ public class PermissionClear extends SubCommand<LPSubjectData> {
MessageUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a.");
} else {
subjectData.clearPermissions(contextSet);
MessageUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
MessageUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
}
return CommandResult.SUCCESS;
}

View File

@ -60,7 +60,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
}
for (Map.Entry<ImmutableContextSet, ImmutableMap<String, Boolean>> e : permissions.entrySet()) {
MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue()));
MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey(), plugin.getLocaleManager()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue()));
}
} else {
@ -71,7 +71,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
}
MessageUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &b" +
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.nodesToString(permissions));
SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()) + "&a.\n" + SpongeCommandUtils.nodesToString(permissions));
}
return CommandResult.SUCCESS;

View File

@ -54,7 +54,7 @@ public class PermissionSet extends SubCommand<LPSubjectData> {
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
if (subjectData.setPermission(contextSet, node, tristate).join()) {
MessageUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
MessageUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?");
}

View File

@ -29,6 +29,7 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.common.command.utils.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.sponge.service.model.LPSubjectReference;
import java.util.List;
@ -85,8 +86,8 @@ public final class SpongeCommandUtils {
return sb.toString();
}
public static String contextToString(ContextSet set) {
return MessageUtils.contextSetToString(set);
public static String contextToString(ContextSet set, LocaleManager localeManager) {
return MessageUtils.contextSetToString(localeManager, set);
}
private SpongeCommandUtils() {}

View File

@ -199,7 +199,7 @@ public class LuckPermsService implements LPPermissionService {
public LPPermissionDescription registerPermissionDescription(String id, Text description, PluginContainer owner) {
SimplePermissionDescription desc = new SimplePermissionDescription(this, id, description, owner);
this.permissionDescriptions.put(id, desc);
this.plugin.getPermissionRegistry().offer(id);
this.plugin.getPermissionRegistry().insert(id);
return desc;
}
@ -214,7 +214,7 @@ public class LuckPermsService implements LPPermissionService {
Map<String, LPPermissionDescription> descriptions = new HashMap<>(this.permissionDescriptions);
// collect known values from the permission vault
for (String perm : this.plugin.getPermissionRegistry().getKnownPermissions()) {
for (String perm : this.plugin.getPermissionRegistry().rootAsList()) {
// don't override plugin defined values
if (!descriptions.containsKey(perm)) {
descriptions.put(perm, new SimplePermissionDescription(this, perm, null, null));