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 @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); ConfigurationSection section = this.configuration.getConfigurationSection(path);
if (section == null) { if (section == null) {
return def; return def;

View File

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

View File

@ -82,7 +82,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements
} }
@Override @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); Configuration section = this.configuration.getSection(path);
if (section == null) { if (section == null) {
return def; 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)); return CompletableFuture.allOf(keys.stream().map(this::reloadMeta).toArray(CompletableFuture[]::new));
} }
public CompletableFuture<Void> reloadAll() {
return CompletableFuture.allOf(reloadPermissions(), reloadMeta());
}
@Override @Override
public void preCalculate(@Nonnull Contexts contexts) { public void preCalculate(@Nonnull Contexts contexts) {
Objects.requireNonNull(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.Command;
import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.commands.group.CreateGroup; import me.lucko.luckperms.common.commands.group.CreateGroup;
@ -97,13 +98,16 @@ public class CommandManager {
// the default executor to run commands on // the default executor to run commands on
private final ExecutorService executor = Executors.newSingleThreadExecutor(); private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final List<Command> mainCommands; private final TabCompletions tabCompletions;
private final List<Command<?, ?>> mainCommands;
public CommandManager(LuckPermsPlugin plugin) { public CommandManager(LuckPermsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
LocaleManager locale = plugin.getLocaleManager(); 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 UserMainCommand(locale))
.add(new GroupMainCommand(locale)) .add(new GroupMainCommand(locale))
.add(new TrackMainCommand(locale)) .add(new TrackMainCommand(locale))
@ -137,6 +141,10 @@ public class CommandManager {
return this.plugin; return this.plugin;
} }
public TabCompletions getTabCompletions() {
return this.tabCompletions;
}
public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args) { public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args) {
return onCommand(sender, label, args, this.executor); return onCommand(sender, label, args, this.executor);
} }
@ -170,7 +178,7 @@ public class CommandManager {
} }
// Look for the main command. // 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))) .filter(m -> m.getName().equalsIgnoreCase(arguments.get(0)))
.limit(1) .limit(1)
.findAny(); .findAny();
@ -263,8 +271,7 @@ public class CommandManager {
.filter(Command::shouldDisplay) .filter(Command::shouldDisplay)
.filter(c -> c.isAuthorized(sender)) .filter(c -> c.isAuthorized(sender))
.forEach(c -> { .forEach(c -> {
@SuppressWarnings("unchecked") String permission = c.getPermission().map(CommandPermission::getPermission).orElse("None");
String permission = (String) c.getPermission().map(p -> ((CommandPermission) p).getPermission()).orElse("None");
TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR) TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR)
.toBuilder().applyDeep(comp -> { .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.CommandManager;
import me.lucko.luckperms.common.command.CommandResult; 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.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; 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); final List<String> objects = getTargets(plugin);
if (args.size() <= 1) { if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equals("")) { if (args.isEmpty() || args.get(0).trim().isEmpty()) {
return objects; return objects;
} }
@ -134,7 +133,7 @@ public abstract class MainCommand<T, I> extends Command<Void, T> {
.collect(Collectors.toList()); .collect(Collectors.toList());
if (args.size() == 2) { if (args.size() == 2) {
if (args.get(1).equals("")) { if (args.get(1).trim().isEmpty()) {
return subs.stream() return subs.stream()
.map(m -> m.getName().toLowerCase()) .map(m -> m.getName().toLowerCase())
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -171,12 +170,10 @@ public abstract class MainCommand<T, I> extends Command<Void, T> {
.collect(Collectors.toList()); .collect(Collectors.toList());
if (!subs.isEmpty()) { 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) { for (Command s : subs) {
s.sendUsage(sender, label); s.sendUsage(sender, label);
} }
} else { } else {
Message.COMMAND_NO_PERMISSION.send(sender); 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.CommandResult;
import me.lucko.luckperms.common.command.utils.ArgumentParser; 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.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.PermissionHolder;
@ -143,9 +142,9 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
if (!subs.isEmpty()) { if (!subs.isEmpty()) {
if (user) { 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 { } 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) { 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.CommandResult;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.Argument;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec; 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.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.sender.Sender;
@ -99,22 +99,22 @@ public abstract class SharedSubCommand {
public void sendUsage(Sender sender) { public void sendUsage(Sender sender) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (getArgs() != null) { if (getArgs() != null) {
sb.append("&3 - &7"); sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager()));
for (Argument arg : getArgs()) { 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) { public void sendDetailedUsage(Sender sender) {
MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription());
if (getArgs() != null) { if (getArgs() != null) {
MessageUtils.sendPluginMessage(sender, "&3Arguments:"); Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs()) { 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.CommandResult;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.Argument;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec; 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.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender; 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) { public void sendUsage(Sender sender, String label) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (getArgs().isPresent()) { if (getArgs().isPresent()) {
sb.append("&3 - &7"); sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager()));
for (Argument arg : getArgs().get()) { 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 @Override
public void sendDetailedUsage(Sender sender, String label) { public void sendDetailedUsage(Sender sender, String label) {
MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription());
if (getArgs().isPresent()) { if (getArgs().isPresent()) {
MessageUtils.sendPluginMessage(sender, "&3Arguments:"); Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs().get()) { 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; package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.Argument;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec; import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.sender.Sender;
import java.util.function.Predicate; 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) { public void sendUsage(Sender sender, String label) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (getArgs().isPresent()) { if (getArgs().isPresent()) {
sb.append("&3 - &7"); sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager()));
for (Argument arg : getArgs().get()) { 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 @Override
public void sendDetailedUsage(Sender sender, String label) { public void sendDetailedUsage(Sender sender, String label) {
MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription());
if (getArgs().isPresent()) { if (getArgs().isPresent()) {
MessageUtils.sendPluginMessage(sender, "&3Arguments:"); Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs().get()) { 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. * SOFTWARE.
*/ */
package me.lucko.luckperms.common.command.utils; package me.lucko.luckperms.common.command.tabcomplete;
import com.google.common.base.Splitter; 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 me.lucko.luckperms.common.treeview.TreeNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* Utility methods for handling tab completion. * Common completion suppliers used by the plugin
*/ */
public final class TabCompletions { public final class TabCompletions {
public static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) { private static final CompletionSupplier BOOLEAN = CompletionSupplier.startsWith("true", "false");
return getTabComplete(new ArrayList<>(plugin.getGroupManager().getAll().keySet()), args);
}
public static List<String> getTrackTabComplete(List<String> args, LuckPermsPlugin plugin) { private final CompletionSupplier groups;
return getTabComplete(new ArrayList<>(plugin.getTrackManager().getAll().keySet()), args); private final CompletionSupplier tracks;
} private final CompletionSupplier permissions;
public static List<String> getBoolTabComplete(List<String> args) { public TabCompletions(LuckPermsPlugin plugin) {
if (args.size() == 2) { this.groups = CompletionSupplier.startsWith(() -> plugin.getGroupManager().getAll().keySet());
return Arrays.asList("true", "false"); this.tracks = CompletionSupplier.startsWith(() -> plugin.getTrackManager().getAll().keySet());
} else { this.permissions = partial -> {
return Collections.emptyList(); PermissionRegistry cache = plugin.getPermissionRegistry();
}
}
public static List<String> getPermissionTabComplete(List<String> args, PermissionRegistry cache) { if (partial.isEmpty()) {
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equals("")) {
return cache.getRootNode().getChildren() return cache.getRootNode().getChildren()
.map(Map::keySet) .map(Map::keySet)
.map(s -> (List<String>) new ArrayList<>(s)) .<List<String>>map(ArrayList::new)
.orElse(Collections.emptyList()); .orElse(Collections.emptyList());
} }
String start = args.get(0).toLowerCase(); String start = partial.toLowerCase();
List<String> parts = new ArrayList<>(Splitter.on('.').splitToList(start)); List<String> parts = new ArrayList<>(Splitter.on('.').splitToList(start));
TreeNode root = cache.getRootNode(); TreeNode root = cache.getRootNode();
@ -77,7 +70,7 @@ public final class TabCompletions {
return Collections.emptyList(); 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); String incomplete = parts.remove(parts.size() - 1);
@ -100,25 +93,29 @@ public final class TabCompletions {
} }
return root.getChildren().get().keySet().stream() return root.getChildren().get().keySet().stream()
.filter(s -> s.startsWith(incomplete)) .filter(TabCompleter.startsWithIgnoreCase(incomplete))
.map(s -> parts.stream().collect(Collectors.joining(".")) + "." + s) .map(s -> parts.stream().collect(Collectors.joining(".")) + "." + s)
.collect(Collectors.toList()); .collect(Collectors.toList());
} };
return Collections.emptyList();
} }
private static List<String> getTabComplete(List<String> options, List<String> args) { // bit of a weird pattern, but meh it kinda works, reduces the boilerplate
if (args.size() <= 1) { // of calling the commandmanager + tabcompletions getters every time
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
return options;
}
return options.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList()); public static CompletionSupplier booleans() {
} return BOOLEAN;
}
return Collections.emptyList();
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.Node;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet; 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.locale.message.Message;
import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.sender.Sender;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
public final class MessageUtils { 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 * 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 * @param message the message content
*/ */
public static void sendPluginMessage(Sender sender, String message) { public static void sendPluginMessage(Sender sender, String message) {
String prefix = sender.getPlatform().getLocaleManager().getTranslation(Message.PREFIX); String prefix = Message.PREFIX.asString(sender.getPlatform().getLocaleManager());
if (prefix == null) { sender.sendMessage(Message.colorize(prefix + message));
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("");
} }
public static String toCommaSep(Collection<String> strings) { 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. * 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 * @param node the node to query context from
* @return a string representing the nodes context, or an empty string if the node applies globally. * @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(); StringBuilder sb = new StringBuilder();
if (node.isServerSpecific()) { 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()) { 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()) { 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(); return sb.toString();
@ -184,27 +152,29 @@ public final class MessageUtils {
/** /**
* Converts a context pair to a formatted string, surrounded by ( ) brackets. * Converts a context pair to a formatted string, surrounded by ( ) brackets.
* *
*
* @param localeManager the locale manager
* @param key the context key * @param key the context key
* @param value the context value * @param value the context value
* @return a formatted string * @return a formatted string
*/ */
public static String contextToString(String key, String value) { public static String contextToString(LocaleManager localeManager, String key, String value) {
return Message.CONTEXT_PAIR.asString(null, key, 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()) { if (set.isEmpty()) {
return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(null); return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(localeManager);
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> e : set.toSet()) { 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_INLINE.asString(localeManager, e.getKey(), e.getValue()));
sb.append(Message.CONTEXT_PAIR_SEP.asString(null)); 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() {} 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.DataMutateResult;
import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; 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()); DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
if (result.asBoolean()) { 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( HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, "¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥' '¥'
@ -100,7 +99,7 @@ public class MetaAddChatMeta extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; 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.Node;
import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
@ -95,7 +94,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
if (ret.getKey().asBoolean()) { if (ret.getKey().asBoolean()) {
duration = ret.getValue().getExpiryUnixTime(); 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( HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, "¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥' '¥'
@ -110,7 +109,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }

View File

@ -104,9 +104,9 @@ public class MetaClear extends SharedSubCommand {
int changed = before - holder.enduringData().immutable().size(); int changed = before - holder.enduringData().immutable().size();
if (changed == 1) { 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 { } 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) 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.ChatMetaType;
import me.lucko.luckperms.api.LocalizedNode; 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
@ -124,12 +123,12 @@ public class MetaInfo extends SharedSubCommand {
for (LocalizedNode m : meta) { for (LocalizedNode m : meta) {
String location = processLocation(m, holder); String location = processLocation(m, holder);
if (m.hasSpecificContext()) { if (m.hasSpecificContext()) {
String context = MessageUtils.getAppendableNodeContextString(m); String context = MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), 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(); 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)); builder.applyDeep(makeFancy(holder, label, m));
sender.sendMessage(builder.build()); sender.sendMessage(builder.build());
} else { } 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)); builder.applyDeep(makeFancy(holder, label, m));
sender.sendMessage(builder.build()); sender.sendMessage(builder.build());
} }
@ -140,12 +139,12 @@ public class MetaInfo extends SharedSubCommand {
for (Map.Entry<Integer, LocalizedNode> e : meta) { for (Map.Entry<Integer, LocalizedNode> e : meta) {
String location = processLocation(e.getValue(), holder); String location = processLocation(e.getValue(), holder);
if (e.getValue().hasSpecificContext()) { if (e.getValue().hasSpecificContext()) {
String context = MessageUtils.getAppendableNodeContextString(e.getValue()); String context = MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), 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(); 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())); builder.applyDeep(makeFancy(type, holder, label, e.getValue()));
sender.sendMessage(builder.build()); sender.sendMessage(builder.build());
} else { } 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())); builder.applyDeep(makeFancy(type, holder, label, e.getValue()));
sender.sendMessage(builder.build()); 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.DataMutateResult;
import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
@ -91,7 +90,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
!n.isTemporary() && !n.isTemporary() &&
n.getFullContexts().makeImmutable().equals(context.makeImmutable()) 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("meta" , "remove" + this.type.name().toLowerCase(), priority, "*", context) .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()); DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
if (result.asBoolean()) { 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( HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, "¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥' '¥'
@ -119,7 +118,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; 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.DataMutateResult;
import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand;
@ -91,7 +90,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
!n.isPermanent() && !n.isPermanent() &&
n.getFullContexts().makeImmutable().equals(context.makeImmutable()) 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("meta" , "removetemp" + this.type.name().toLowerCase(), priority, "*", context) .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()); DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).setExpiry(10L).withExtraContext(context).build());
if (result.asBoolean()) { 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( HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, "¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
'¥' '¥'
@ -119,7 +118,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }

View File

@ -82,14 +82,14 @@ public class MetaSet extends SharedSubCommand {
Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).build(); Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).build();
if (holder.hasPermission(NodeMapType.ENDURING, n, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { 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; return CommandResult.STATE_ERROR;
} }
holder.clearMetaKeys(key, context, false); holder.clearMetaKeys(key, context, false);
holder.setPermission(n); 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( HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), 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.StandardNodeEquality;
import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; 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(); Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).setExpiry(duration).build();
if (holder.hasPermission(NodeMapType.ENDURING, n, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { 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; return CommandResult.STATE_ERROR;
} }
holder.clearMetaKeys(key, context, true); holder.clearMetaKeys(key, context, true);
duration = holder.setPermission(n, modifier).getValue().getExpiryUnixTime(); 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( HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), 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)) { 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("meta", "unset", key, context) .action("meta", "unset", key, context)
@ -80,7 +80,7 @@ public class MetaUnset extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }

View File

@ -71,7 +71,7 @@ public class MetaUnsetTemp extends SharedSubCommand {
} }
if (holder.clearMetaKeys(key, context, true)) { 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("meta", "unsettemp", key, context) .action("meta", "unsettemp", key, context)
@ -80,7 +80,7 @@ public class MetaUnsetTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; 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(); int changed = before - holder.enduringData().immutable().size();
if (changed == 1) { 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 { } 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) ExtendedLogEntry.build().actor(sender).acted(holder)

View File

@ -86,7 +86,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T>
.collect(Collectors.toList()); .collect(Collectors.toList());
for (Track t : tracks) { 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 { } 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentAdd extends SharedSubCommand { public class ParentAdd extends SharedSubCommand {
public ParentAdd(LocaleManager locale) { public ParentAdd(LocaleManager locale) {
super(CommandSpec.PARENT_ADD.localize(locale), "add", CommandPermission.USER_PARENT_ADD, CommandPermission.GROUP_PARENT_ADD, Predicates.is(0)); 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()); DataMutateResult result = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
if (result.asBoolean()) { 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "add", group.getName(), context) .action("parent", "add", group.getName(), context)
@ -92,13 +92,15 @@ public class ParentAdd extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; 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.List;
import java.util.Map; import java.util.Map;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentAddTemp extends SharedSubCommand { public class ParentAddTemp extends SharedSubCommand {
public ParentAddTemp(LocaleManager locale) { 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)); 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())) { 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; return CommandResult.STATE_ERROR;
} }
@ -96,7 +96,7 @@ public class ParentAddTemp extends SharedSubCommand {
if (ret.getKey().asBoolean()) { if (ret.getKey().asBoolean()) {
duration = ret.getValue().getExpiryUnixTime(); 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "addtemp", group.getName(), duration, context) .action("parent", "addtemp", group.getName(), duration, context)
@ -105,13 +105,15 @@ public class ParentAddTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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(); int changed = before - holder.enduringData().immutable().size();
if (changed == 1) { 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 { } 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) 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getTrackTabComplete;
public class ParentClearTrack extends SharedSubCommand { public class ParentClearTrack extends SharedSubCommand {
public ParentClearTrack(LocaleManager locale) { 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)); 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(); int changed = before - holder.enduringData().immutable().size();
if (changed == 1) { 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 { } 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) ExtendedLogEntry.build().actor(sender).acted(holder)
@ -120,6 +120,8 @@ public class ParentClearTrack extends SharedSubCommand {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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 // send content
for (LocalizedNode node : 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()) { if (node.isTemporary()) {
s += "\n&2 expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()); 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -49,8 +51,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentRemove extends SharedSubCommand { public class ParentRemove extends SharedSubCommand {
public ParentRemove(LocaleManager locale) { public ParentRemove(LocaleManager locale) {
super(CommandSpec.PARENT_REMOVE.localize(locale), "remove", CommandPermission.USER_PARENT_REMOVE, CommandPermission.GROUP_PARENT_REMOVE, Predicates.is(0)); 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()); DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).withExtraContext(context).build());
if (result.asBoolean()) { 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "remove", groupName, context) .action("parent", "remove", groupName, context)
@ -105,13 +105,15 @@ public class ParentRemove extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentRemoveTemp extends SharedSubCommand { public class ParentRemoveTemp extends SharedSubCommand {
public ParentRemoveTemp(LocaleManager locale) { 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)); 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()); DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).setExpiry(10L).withExtraContext(context).build());
if (result.asBoolean()) { 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "removetemp", groupName, context) .action("parent", "removetemp", groupName, context)
@ -86,13 +86,15 @@ public class ParentRemoveTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class ParentSet extends SharedSubCommand { public class ParentSet extends SharedSubCommand {
public ParentSet(LocaleManager locale) { public ParentSet(LocaleManager locale) {
super(CommandSpec.PARENT_SET.localize(locale), "set", CommandPermission.USER_PARENT_SET, CommandPermission.GROUP_PARENT_SET, Predicates.is(0)); 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()); ((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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "set", group.getName(), context) .action("parent", "set", group.getName(), context)
@ -98,6 +98,8 @@ public class ParentSet extends SharedSubCommand {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -49,9 +51,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; 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 class ParentSetTrack extends SharedSubCommand {
public ParentSetTrack(LocaleManager locale) { 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)); 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.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName()));
holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build()); 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("parent", "settrack", track.getName(), groupName, context) .action("parent", "settrack", track.getName(), groupName, context)
@ -129,11 +128,9 @@ public class ParentSetTrack extends SharedSubCommand {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.isEmpty() || args.size() == 1) { return TabCompleter.create()
return getTrackTabComplete(args, plugin); .at(0, TabCompletions.tracks(plugin))
} .at(1, TabCompletions.groups(plugin))
.complete(args);
args.remove(0);
return getGroupTabComplete(args, plugin);
} }
} }

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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.command.utils.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.LocaleManager;
@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete;
public class UserSwitchPrimaryGroup extends SharedSubCommand { public class UserSwitchPrimaryGroup extends SharedSubCommand {
public UserSwitchPrimaryGroup(LocaleManager locale) { public UserSwitchPrimaryGroup(LocaleManager locale) {
super(CommandSpec.USER_SWITCHPRIMARYGROUP.localize(locale), "switchprimarygroup", CommandPermission.USER_PARENT_SWITCHPRIMARYGROUP, null, Predicates.not(1)); 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 @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.LocaleManager;
@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionCheck extends SharedSubCommand { public class PermissionCheck extends SharedSubCommand {
public PermissionCheck(LocaleManager locale) { public PermissionCheck(LocaleManager locale) {
super(CommandSpec.PERMISSION_CHECK.localize(locale), "check", CommandPermission.USER_PERM_CHECK, CommandPermission.GROUP_PERM_CHECK, Predicates.is(0)); 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); Tristate result = holder.hasPermission(NodeMapType.ENDURING, NodeFactory.builder(node).withExtraContext(context).build(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
String s = MessageUtils.formatTristate(result); 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; return CommandResult.SUCCESS;
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.LocaleManager;
@ -46,8 +48,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionCheckInherits extends SharedSubCommand { public class PermissionCheckInherits extends SharedSubCommand {
public PermissionCheckInherits(LocaleManager locale) { 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)); 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()); 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; return CommandResult.SUCCESS;
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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(); int changed = before - holder.enduringData().immutable().size();
if (changed == 1) { 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 { } 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) 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) // remove irrelevant types (these are displayed in the other info commands)
nodes.removeIf(node -> (node.isGroupNode() && node.getValue() && plugin.getGroupManager().isLoaded(node.getGroupName())) || nodes.removeIf(node -> (node.isGroupNode() && node.getValue() && plugin.getGroupManager().isLoaded(node.getGroupName())) ||
// remove if the node is a meta node // remove if the node is a meta node
node.isPrefix() || node.isSuffix() || node.isMeta() node.isPrefix() || node.isSuffix() || node.isMeta());
);
// handle empty // handle empty
if (nodes.isEmpty()) { if (nodes.isEmpty()) {
@ -115,7 +114,7 @@ public class PermissionInfo extends SharedSubCommand {
// send content // send content
for (LocalizedNode node : 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()) { if (node.isTemporary()) {
s += "\n&2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()); 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -47,9 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; 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 class PermissionSet extends SharedSubCommand {
public PermissionSet(LocaleManager locale) { public PermissionSet(LocaleManager locale) {
super(CommandSpec.PERMISSION_SET.localize(locale), "set", CommandPermission.USER_PERM_SET, CommandPermission.GROUP_PERM_SET, Predicates.is(0)); 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()); DataMutateResult result = holder.setPermission(NodeFactory.builder(node).setValue(value).withExtraContext(context).build());
if (result.asBoolean()) { 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("permission", "set", node, value, context) .action("permission", "set", node, value, context)
@ -88,17 +87,16 @@ public class PermissionSet extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
List<String> ret = getBoolTabComplete(args); return TabCompleter.create()
if (!ret.isEmpty()) { .at(0, TabCompletions.permissions(plugin))
return ret; .at(1, TabCompletions.booleans())
} .complete(args);
return getPermissionTabComplete(args, plugin.getPermissionRegistry());
} }
} }

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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; 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.List;
import java.util.Map; 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 class PermissionSetTemp extends SharedSubCommand {
public PermissionSetTemp(LocaleManager locale) { 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)); 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()) { if (result.getKey().asBoolean()) {
duration = result.getValue().getExpiryUnixTime(); 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("permission", "settemp", node, value, duration, context) .action("permission", "settemp", node, value, duration, context)
@ -96,17 +95,16 @@ public class PermissionSetTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
List<String> ret = getBoolTabComplete(args); return TabCompleter.create()
if (!ret.isEmpty()) { .at(0, TabCompletions.permissions(plugin))
return ret; .at(1, TabCompletions.booleans())
} .complete(args);
return getPermissionTabComplete(args, plugin.getPermissionRegistry());
} }
} }

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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionUnset extends SharedSubCommand { public class PermissionUnset extends SharedSubCommand {
public PermissionUnset(LocaleManager locale) { public PermissionUnset(LocaleManager locale) {
super(CommandSpec.PERMISSION_UNSET.localize(locale), "unset", CommandPermission.USER_PERM_UNSET, CommandPermission.GROUP_PERM_UNSET, Predicates.is(0)); 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()); DataMutateResult result = holder.unsetPermission(NodeFactory.builder(node).withExtraContext(context).build());
if (result.asBoolean()) { 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("permission", "unset", node, context) .action("permission", "unset", node, context)
@ -86,13 +86,15 @@ public class PermissionUnset extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.command.utils.StorageAssistant;
@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.List; import java.util.List;
import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete;
public class PermissionUnsetTemp extends SharedSubCommand { public class PermissionUnsetTemp extends SharedSubCommand {
public PermissionUnsetTemp(LocaleManager locale) { public PermissionUnsetTemp(LocaleManager locale) {
super(CommandSpec.PERMISSION_UNSETTEMP.localize(locale), "unsettemp", CommandPermission.USER_PERM_UNSET_TEMP, CommandPermission.GROUP_PERM_UNSET_TEMP, Predicates.is(0)); 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()); DataMutateResult result = holder.unsetPermission(NodeFactory.builder(node).setExpiry(10L).withExtraContext(context).build());
if (result.asBoolean()) { 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) ExtendedLogEntry.build().actor(sender).acted(holder)
.action("permission", "unsettemp", node, context) .action("permission", "unsettemp", node, context)
@ -86,13 +86,15 @@ public class PermissionUnsetTemp extends SharedSubCommand {
StorageAssistant.save(holder, sender, plugin); StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} else { } 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; return CommandResult.STATE_ERROR;
} }
} }
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -88,6 +89,8 @@ public class DeleteGroup extends SingleCommand {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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()) { if (!parents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender); Message.INFO_PARENT_HEADER.send(sender);
for (Node node : parents) { 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()) { if (!tempParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender); Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (Node node : tempParents) { for (Node node : tempParents) {
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));
Message.EMPTY.send(sender, "&f- &2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime())); Message.INFO_PARENT_ENTRY_EXPIRY.send(sender, DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()));
} }
} }
return CommandResult.SUCCESS; return CommandResult.SUCCESS;

View File

@ -142,7 +142,7 @@ public class GroupListMembers extends SubCommand<Group> {
headerMessage.send(sender, page, pages.size(), results.size()); headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) { 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(); TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
sender.sendMessage(message); sender.sendMessage(message);
} }

View File

@ -83,7 +83,7 @@ public class GroupSetDisplayName extends SubCommand<Group> {
group.removeIf(context, n -> n.getTypeData(DisplayNameType.KEY).isPresent()); group.removeIf(context, n -> n.getTypeData(DisplayNameType.KEY).isPresent());
if (name.equals(group.getName())) { 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) ExtendedLogEntry.build().actor(sender).acted(group)
.action("setdisplayname", name, context) .action("setdisplayname", name, context)
@ -95,7 +95,7 @@ public class GroupSetDisplayName extends SubCommand<Group> {
group.setPermission(NodeFactory.builder("displayname." + name).withExtraContext(context).build()); 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) ExtendedLogEntry.build().actor(sender).acted(group)
.action("setdisplayname", name, context) .action("setdisplayname", name, context)

View File

@ -25,7 +25,6 @@
package me.lucko.luckperms.common.commands.group; 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.TextUtils;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent; import net.kyori.text.event.ClickEvent;
@ -74,16 +72,16 @@ public class ListGroups extends SingleCommand {
TextComponent component; TextComponent component;
if (tracks.isEmpty()) { if (tracks.isEmpty()) {
component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY.asString(plugin.getLocaleManager(), component = Message.GROUPS_LIST_ENTRY.asComponent(plugin.getLocaleManager(),
group.getFriendlyName(), group.getFriendlyName(),
group.getWeight().orElse(0) group.getWeight().orElse(0)
), CommandManager.SECTION_CHAR); );
} else { } 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.getFriendlyName(),
group.getWeight().orElse(0), group.getWeight().orElse(0),
MessageUtils.toCommaSep(tracks) MessageUtils.toCommaSep(tracks)
), CommandManager.SECTION_CHAR); );
} }
component = component.toBuilder().applyDeep(c -> { 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.abstraction.SubCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -109,6 +110,8 @@ public class LogGroupHistory extends SubCommand<Log> {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.abstraction.SubCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -109,6 +110,8 @@ public class LogTrackHistory extends SubCommand<Log> {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.send(sender, holder.getFriendlyName());
Message.APPLY_EDITS_SUCCESS_SUMMARY.send(sender, additions, additionsSummary, deletions, deletionsSummary); Message.APPLY_EDITS_SUCCESS_SUMMARY.send(sender, additions, additionsSummary, deletions, deletionsSummary);
for (Node n : diffAdded) { 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) { 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); StorageAssistant.save(holder, sender, plugin);
return true; return true;
} }
private static String formatNode(Node n) { private static String formatNode(LocaleManager localeManager, Node n) {
return n.getPermission() + " &7(" + (n.getValue() ? "&a" : "&c") + n.getValue() + "&7)" + MessageUtils.getAppendableNodeContextString(n) + return n.getPermission() + " &7(" + (n.getValue() ? "&a" : "&c") + n.getValue() + "&7)" + MessageUtils.getAppendableNodeContextString(localeManager, n) +
(n.isTemporary() ? " &7(" + DurationFormatter.CONCISE.formatDateDiff(n.getExpiryUnixTime()) + ")" : ""); (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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.MessageUtils;
import me.lucko.luckperms.common.command.utils.TabCompletions;
import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -75,15 +77,9 @@ public class CheckCommand extends SingleCommand {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.isEmpty()) { return TabCompleter.create()
return plugin.getBootstrap().getPlayerList().collect(Collectors.toList()); .at(0, CompletionSupplier.startsWith(() -> plugin.getBootstrap().getPlayerList().collect(Collectors.toList())))
} .at(1, TabCompletions.permissions(plugin))
.complete(args);
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());
} }
} }

View File

@ -55,10 +55,9 @@ public class InfoCommand extends SingleCommand {
plugin.getBootstrap().getServerVersion() plugin.getBootstrap().getServerVersion()
); );
Message.EMPTY.send(sender, "&f- &bStorage:"); Message.INFO_STORAGE.send(sender, plugin.getStorage().getName());
Message.EMPTY.send(sender, "&f- &3Type: &f" + plugin.getStorage().getName());
for (Map.Entry<String, String> e : plugin.getStorage().getMeta().entrySet()) { 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, 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; 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.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
@ -123,7 +124,9 @@ public class SearchCommand extends SingleCommand {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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) { 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() + ")"; 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(); TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
sender.sendMessage(message); 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -80,6 +81,8 @@ public class DeleteTrack extends SingleCommand {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.abstraction.SubCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; 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.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -85,6 +86,8 @@ public class TrackAppend extends SubCommand<Track> {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.abstraction.SubCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; 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.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -99,6 +100,8 @@ public class TrackInsert extends SubCommand<Track> {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.abstraction.SubCommand;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; 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.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -79,6 +80,8 @@ public class TrackRemove extends SubCommand<Track> {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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.abstraction.SubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; 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.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -115,7 +116,7 @@ public class UserDemote extends SubCommand<User> {
String groupFrom = result.getGroupFrom().get(); String groupFrom = result.getGroupFrom().get();
String groupTo = result.getGroupTo().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) { if (!silent) {
Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupTo, groupFrom, true)); Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupTo, groupFrom, true));
} }
@ -135,6 +136,8 @@ public class UserDemote extends SubCommand<User> {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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()) { if (!parents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender); Message.INFO_PARENT_HEADER.send(sender);
for (Node node : parents) { 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()) { if (!tempParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender); Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (Node node : tempParents) { for (Node node : tempParents) {
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));
Message.EMPTY.send(sender, "&f- &2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime())); 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(); ContextSet contextSet = contexts.getContexts();
if (!contextSet.isEmpty()) { if (!contextSet.isEmpty()) {
context = contextSet.toSet().stream() 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(" ")); .collect(Collectors.joining(" "));
} }
@ -121,7 +121,7 @@ public class UserInfo extends SubCommand<User> {
ListMultimap<String, String> metaMap = data.getMetaMultimap(); ListMultimap<String, String> metaMap = data.getMetaMultimap();
if (!metaMap.isEmpty()) { if (!metaMap.isEmpty()) {
meta = metaMap.entries().stream() 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(" ")); .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.abstraction.SubCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission; 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.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant; 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.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.locale.message.Message;
@ -101,7 +102,7 @@ public class UserPromote extends SubCommand<User> {
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
case ADDED_TO_FIRST_GROUP: { 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) ExtendedLogEntry.build().actor(sender).acted(user)
.action("promote", track.getName(), context) .action("promote", track.getName(), context)
@ -115,7 +116,7 @@ public class UserPromote extends SubCommand<User> {
String groupFrom = result.getGroupFrom().get(); String groupFrom = result.getGroupFrom().get();
String groupTo = result.getGroupTo().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) { if (!silent) {
Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupFrom, groupTo, false)); Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupFrom, groupTo, false));
} }
@ -135,6 +136,8 @@ public class UserPromote extends SubCommand<User> {
@Override @Override
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) { 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(); getPlugin().getEventFactory().handleConfigReload();
} }
public ConfigurationAdapter getAdapter() {
return this.adapter;
}
@Override @Override
public LuckPermsPlugin getPlugin() { public LuckPermsPlugin getPlugin() {
return this.plugin; return this.plugin;

View File

@ -373,7 +373,7 @@ public final class ConfigKeys {
* The default assignments being applied by the plugin * The default assignments being applied by the plugin
*/ */
public static final ConfigKey<List<AssignmentRule>> DEFAULT_ASSIGNMENTS = CustomKey.of(c -> { 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 hasTrue = c.getString("default-assignments." + name + ".if.has-true", null);
String hasFalse = c.getString("default-assignments." + name + ".if.has-false", null); String hasFalse = c.getString("default-assignments." + name + ".if.has-false", null);
String lacks = c.getString("default-assignments." + name + ".if.lacks", 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> 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); 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.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.EnumMap;
import java.util.Map; import java.util.Map;
public class LocaleManager { public class LocaleManager {
@ -71,8 +72,8 @@ public class LocaleManager {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void loadFromFile(Path file) throws Exception { public void loadFromFile(Path file) throws Exception {
try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
ImmutableMap.Builder<Message, String> messages = ImmutableMap.builder(); EnumMap<Message, String> messages = new EnumMap<>(Message.class);
ImmutableMap.Builder<CommandSpec, CommandSpecData> commands = ImmutableMap.builder(); EnumMap<CommandSpec, CommandSpecData> commands = new EnumMap<>(CommandSpec.class);
Map<String, Object> data = (Map<String, Object>) new Yaml().load(reader); Map<String, Object> data = (Map<String, Object>) new Yaml().load(reader);
for (Map.Entry<String, Object> entry : data.entrySet()) { for (Map.Entry<String, Object> entry : data.entrySet()) {
@ -124,20 +125,11 @@ public class LocaleManager {
} }
} }
this.messages = messages.build(); this.messages = ImmutableMap.copyOf(messages);
this.commands = commands.build(); 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 * 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 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 class Argument {
public static Argument create(String name, boolean required, String description) { public static Argument create(String name, boolean required, String description) {
return new Argument(name, required, description); return new Argument(name, required, description);
@ -46,8 +51,8 @@ public class Argument {
this.description = description; this.description = description;
} }
public String asPrettyString() { public String asPrettyString(@Nullable LocaleManager localeManager) {
return this.required ? "&8<&7" + this.name + "&8>" : "&8[&7" + this.name + "&8]"; return (this.required ? Message.REQUIRED_ARGUMENT : Message.OPTIONAL_ARGUMENT).asString(localeManager, this.name);
} }
public String getName() { public String getName() {

View File

@ -25,11 +25,13 @@
package me.lucko.luckperms.common.locale.message; 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.locale.LocaleManager;
import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.utils.TextUtils; import me.lucko.luckperms.common.utils.TextUtils;
import net.kyori.text.TextComponent;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -65,7 +67,7 @@ public enum Message {
"{PREFIX}&3LOG &3&l> &f{}", "{PREFIX}&3LOG &3&l> &f{}",
false 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("&3EXPORT &3&l> &f{}", true),
EXPORT_LOG_PROGRESS("&3EXPORT &3&l> &7{}", true), EXPORT_LOG_PROGRESS("&3EXPORT &3&l> &7{}", true),
MIGRATION_LOG("&3MIGRATION &7[&3{}&7] &3&l> &f{}", 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_NOT_RECOGNISED("&cCommand not recognised.", true),
COMMAND_NO_PERMISSION("&cYou do not have permission to use this command!", 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 * Loading / Saving
@ -180,6 +195,15 @@ public enum Message {
"{PREFIX}&f- {}", "{PREFIX}&f- {}",
false false
), ),
INFO_STORAGE(
"{PREFIX}&f- &bStorage:" + "\n" +
"{PREFIX}&f- &3Type: &f{}",
false
),
INFO_STORAGE_META("&f- &3{}: {}", true),
INFO_MIDDLE( INFO_MIDDLE(
"{PREFIX}&f- &bMessaging: &f{}" + "\n" + "{PREFIX}&f- &bMessaging: &f{}" + "\n" +
"{PREFIX}&f- &bInstance:" + "\n" + "{PREFIX}&f- &bInstance:" + "\n" +
@ -326,6 +350,8 @@ public enum Message {
INFO_PARENT_HEADER("&f- &aParent Groups:", true), INFO_PARENT_HEADER("&f- &aParent Groups:", true),
INFO_TEMP_PARENT_HEADER("&f- &aTemporary Parent 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_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_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), 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_CONTENT("&b(Import) &b-> &c{}", true),
IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", 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 String message;
private final boolean showPrefix; private final boolean showPrefix;
@ -459,31 +472,67 @@ public enum Message {
return this.message; return this.message;
} }
public String asString(@Nullable LocaleManager localeManager, Object... objects) { private String getTranslatedMessage(@Nullable LocaleManager localeManager) {
String prefix = null; String prefix = null;
if (localeManager != null) { if (localeManager != null) {
prefix = localeManager.getTranslation(PREFIX); prefix = localeManager.getTranslation(this);
} }
if (prefix == null) { if (prefix == null) {
prefix = PREFIX.getMessage(); prefix = this.getMessage();
} }
return prefix;
}
String s = null; private String format(@Nullable LocaleManager localeManager, Object... objects) {
if (localeManager != null) { String prefix = PREFIX.getTranslatedMessage(localeManager);
s = localeManager.getTranslation(this); String msg = format(
} this.getTranslatedMessage(localeManager)
if (s == null) { .replace("{PREFIX}", prefix)
s = this.message; .replace("\\n", "\n"),
} objects
);
return this.showPrefix ? prefix + msg : msg;
}
s = format(s.replace("{PREFIX}", prefix).replace("\\n", "\n"), objects); public String asString(@Nullable LocaleManager localeManager, Object... objects) {
return MessageUtils.color(this.showPrefix ? prefix + s : s); 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) { public void send(Sender sender, Object... objects) {
sender.sendMessage(asString(sender.getPlatform().getLocaleManager(), 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 * Prints this Message enum in a yml format, for reading by the locale manager
* @param args not needed * @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.BufferedRequest;
import me.lucko.luckperms.common.buffers.UpdateTaskBuffer; import me.lucko.luckperms.common.buffers.UpdateTaskBuffer;
import me.lucko.luckperms.common.calculators.CalculatorFactory; 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.AbstractConfiguration;
import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.LuckPermsConfiguration; 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.event.EventFactory;
import me.lucko.luckperms.common.inheritance.InheritanceHandler; import me.lucko.luckperms.common.inheritance.InheritanceHandler;
import me.lucko.luckperms.common.locale.LocaleManager; 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.InternalMessagingService;
import me.lucko.luckperms.common.messaging.MessagingFactory; import me.lucko.luckperms.common.messaging.MessagingFactory;
import me.lucko.luckperms.common.plugin.logging.PluginLogger; import me.lucko.luckperms.common.plugin.logging.PluginLogger;
@ -318,9 +318,9 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
} }
private void displayBanner(Sender sender) { private void displayBanner(Sender sender) {
sender.sendMessage(MessageUtils.color("&b &3 __ ")); sender.sendMessage(Message.colorize("&b &3 __ "));
sender.sendMessage(MessageUtils.color("&b | &3|__) " + "&2LuckPerms &bv" + getBootstrap().getVersion())); sender.sendMessage(Message.colorize("&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| " + "&8Running on " + getBootstrap().getType().getFriendlyName() + " - " + getBootstrap().getServerBrand()));
sender.sendMessage(""); sender.sendMessage("");
} }
} }

View File

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

View File

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

View File

@ -26,17 +26,13 @@
package me.lucko.luckperms.common.treeview; package me.lucko.luckperms.common.treeview;
import com.google.common.base.Splitter; 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.plugin.scheduler.SchedulerAdapter;
import me.lucko.luckperms.common.utils.RepeatingTask; import me.lucko.luckperms.common.utils.RepeatingTask;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -50,16 +46,12 @@ public class PermissionRegistry extends RepeatingTask {
// the root node in the tree // the root node in the tree
private final TreeNode rootNode; 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 // a queue of permission strings to be processed by the tree
private final Queue<String> queue; private final Queue<String> queue;
public PermissionRegistry(SchedulerAdapter scheduler) { public PermissionRegistry(SchedulerAdapter scheduler) {
super(scheduler, 1, TimeUnit.SECONDS); super(scheduler, 1, TimeUnit.SECONDS);
this.rootNode = new TreeNode(); this.rootNode = new TreeNode();
this.knownPermissions = ConcurrentHashMap.newKeySet(3000);
this.queue = new ConcurrentLinkedQueue<>(); this.queue = new ConcurrentLinkedQueue<>();
} }
@ -70,15 +62,7 @@ public class PermissionRegistry extends RepeatingTask {
@Override @Override
protected void tick() { protected void tick() {
for (String e; (e = this.queue.poll()) != null; ) { for (String e; (e = this.queue.poll()) != null; ) {
try { insert(e);
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();
}
} }
} }
@ -89,12 +73,12 @@ public class PermissionRegistry extends RepeatingTask {
this.queue.offer(permission); this.queue.offer(permission);
} }
public void offerAll(Collection<? extends String> permissions) { public void insert(String permission) {
this.queue.addAll(permissions); try {
} doInsert(permission);
} catch (Exception ex) {
public Set<String> getKnownPermissions() { ex.printStackTrace();
return ImmutableSet.copyOf(this.knownPermissions); }
} }
public List<String> rootAsList() { public List<String> rootAsList() {
@ -105,14 +89,17 @@ public class PermissionRegistry extends RepeatingTask {
return this.rootNode.getDeepSize(); return this.rootNode.getDeepSize();
} }
private void insert(String permission) { private void doInsert(String permission) {
// split the permission up into parts // split the permission up into parts
List<String> parts = DOT_SPLIT.splitToList(permission); List<String> parts = DOT_SPLIT.splitToList(permission);
// insert the permission into the node structure // insert the permission into the node structure
TreeNode current = this.rootNode; TreeNode current = this.rootNode;
for (String part : parts) { 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.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
/** /**
* Represents one "branch" or "level" of the node tree * Represents one "branch" or "level" of the node tree
*/ */
public class TreeNode { 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 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 // lazy init
private synchronized Map<String, TreeNode> getChildMap() { private synchronized Map<String, TreeNode> getChildMap() {
if (this.children == null) { if (this.children == null) {
@ -45,8 +86,35 @@ public class TreeNode {
return this.children; return this.children;
} }
public TreeNode resolve(String s) { @Nullable
return getChildMap().computeIfAbsent(s, x -> new TreeNode()); 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() { public Optional<Map<String, TreeNode>> getChildren() {
@ -54,10 +122,14 @@ public class TreeNode {
} }
public int getDeepSize() { public int getDeepSize() {
if (this.cachedDeepSize != Integer.MIN_VALUE) {
return this.cachedDeepSize;
}
if (this.children == null) { if (this.children == null) {
return 1; return (this.cachedDeepSize = 1);
} else { } 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) { 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()) { if (this.notifiedSender.isConsole()) {
// just send as a raw message // 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; return;
} }
// form a hoverevent from the check trace // 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 // build the text
List<String> hover = new ArrayList<>(); List<String> hover = new ArrayList<>();
hover.add("&bOrigin: &2" + data.getCheckOrigin().name()); 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"); hover.add("&bTrace: &r");
Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str)); Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -53,7 +53,7 @@ public class OptionClear extends SubCommand<LPSubjectData> {
MessageUtils.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a."); MessageUtils.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a.");
} else { } else {
subjectData.clearOptions(contextSet); 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; 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()) { 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 { } else {
@ -71,7 +71,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
} }
MessageUtils.sendPluginMessage(sender, "&aShowing options matching contexts &b" + 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; return CommandResult.SUCCESS;

View File

@ -52,7 +52,7 @@ public class OptionSet extends SubCommand<LPSubjectData> {
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args); ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
if (subjectData.setOption(contextSet, key, value).join()) { 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 { } else {
MessageUtils.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?"); 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); ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(1, args);
if (subjectData.unsetOption(contextSet, key).join()) { 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 { } else {
MessageUtils.sendPluginMessage(sender, "Unable to unset option. Are you sure the Subject has it set?"); 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()) { if (subjectData.addParent(contextSet, subject.toReference()).join()) {
MessageUtils.sendPluginMessage(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() + 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 { } else {
MessageUtils.sendPluginMessage(sender, "Unable to add parent. Does the Subject already have it added?"); 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."); MessageUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a.");
} else { } else {
subjectData.clearParents(contextSet); 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; return CommandResult.SUCCESS;
} }

View File

@ -61,7 +61,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
} }
for (Map.Entry<ImmutableContextSet, ImmutableList<LPSubjectReference>> e : parents.entrySet()) { 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 { } else {
@ -72,7 +72,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
} }
MessageUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &b" + 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; return CommandResult.SUCCESS;

View File

@ -70,7 +70,7 @@ public class ParentRemove extends SubCommand<LPSubjectData> {
if (subjectData.removeParent(contextSet, subject.toReference()).join()) { if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
MessageUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() + 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 { } else {
MessageUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?"); 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."); MessageUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a.");
} else { } else {
subjectData.clearPermissions(contextSet); 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; 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()) { 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 { } else {
@ -71,7 +71,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
} }
MessageUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &b" + 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; return CommandResult.SUCCESS;

View File

@ -54,7 +54,7 @@ public class PermissionSet extends SubCommand<LPSubjectData> {
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args); ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
if (subjectData.setPermission(contextSet, node, tristate).join()) { 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 { } else {
MessageUtils.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?"); 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.api.context.ContextSet;
import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.ArgumentParser;
import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.sponge.service.model.LPSubjectReference; import me.lucko.luckperms.sponge.service.model.LPSubjectReference;
import java.util.List; import java.util.List;
@ -85,8 +86,8 @@ public final class SpongeCommandUtils {
return sb.toString(); return sb.toString();
} }
public static String contextToString(ContextSet set) { public static String contextToString(ContextSet set, LocaleManager localeManager) {
return MessageUtils.contextSetToString(set); return MessageUtils.contextSetToString(localeManager, set);
} }
private SpongeCommandUtils() {} private SpongeCommandUtils() {}

View File

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