From 379eb00b69dfc209c7213be11b1186a14d5944e4 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 19 Jun 2018 22:27:43 +0100 Subject: [PATCH] Cleanup various message localisations, limit the size of the PermissionRegistry --- .../luckperms/bukkit/BukkitConfigAdapter.java | 2 +- .../bukkit/model/server/LPPermissionMap.java | 10 +- .../luckperms/bungee/BungeeConfigAdapter.java | 2 +- .../common/caching/AbstractCachedData.java | 4 - .../common/command/CommandManager.java | 17 ++- .../command/abstraction/MainCommand.java | 9 +- .../abstraction/SharedMainCommand.java | 5 +- .../command/abstraction/SharedSubCommand.java | 16 +-- .../command/abstraction/SingleCommand.java | 16 +-- .../command/abstraction/SubCommand.java | 16 +-- .../tabcomplete/CompletionSupplier.java | 53 +++++++++ .../command/tabcomplete/TabCompleter.java | 110 ++++++++++++++++++ .../TabCompletions.java | 69 ++++++----- .../common/command/utils/MessageUtils.java | 64 +++------- .../generic/meta/MetaAddChatMeta.java | 5 +- .../generic/meta/MetaAddTempChatMeta.java | 5 +- .../commands/generic/meta/MetaClear.java | 4 +- .../commands/generic/meta/MetaInfo.java | 13 +-- .../generic/meta/MetaRemoveChatMeta.java | 7 +- .../generic/meta/MetaRemoveTempChatMeta.java | 7 +- .../common/commands/generic/meta/MetaSet.java | 4 +- .../commands/generic/meta/MetaSetTemp.java | 5 +- .../commands/generic/meta/MetaUnset.java | 4 +- .../commands/generic/meta/MetaUnsetTemp.java | 4 +- .../commands/generic/other/HolderClear.java | 4 +- .../generic/other/HolderShowTracks.java | 2 +- .../commands/generic/parent/ParentAdd.java | 12 +- .../generic/parent/ParentAddTemp.java | 14 ++- .../commands/generic/parent/ParentClear.java | 4 +- .../generic/parent/ParentClearTrack.java | 12 +- .../commands/generic/parent/ParentInfo.java | 2 +- .../commands/generic/parent/ParentRemove.java | 12 +- .../generic/parent/ParentRemoveTemp.java | 12 +- .../commands/generic/parent/ParentSet.java | 10 +- .../generic/parent/ParentSetTrack.java | 17 ++- .../parent/UserSwitchPrimaryGroup.java | 8 +- .../generic/permission/PermissionCheck.java | 10 +- .../permission/PermissionCheckInherits.java | 10 +- .../generic/permission/PermissionClear.java | 4 +- .../generic/permission/PermissionInfo.java | 5 +- .../generic/permission/PermissionSet.java | 18 ++- .../generic/permission/PermissionSetTemp.java | 18 ++- .../generic/permission/PermissionUnset.java | 12 +- .../permission/PermissionUnsetTemp.java | 12 +- .../common/commands/group/DeleteGroup.java | 7 +- .../common/commands/group/GroupInfo.java | 6 +- .../commands/group/GroupListMembers.java | 2 +- .../commands/group/GroupSetDisplayName.java | 4 +- .../common/commands/group/ListGroups.java | 10 +- .../common/commands/log/LogGroupHistory.java | 7 +- .../common/commands/log/LogTrackHistory.java | 7 +- .../commands/misc/ApplyEditsCommand.java | 8 +- .../common/commands/misc/CheckCommand.java | 18 ++- .../common/commands/misc/InfoCommand.java | 5 +- .../common/commands/misc/SearchCommand.java | 9 +- .../common/commands/track/DeleteTrack.java | 7 +- .../common/commands/track/TrackAppend.java | 7 +- .../common/commands/track/TrackInsert.java | 7 +- .../common/commands/track/TrackRemove.java | 7 +- .../common/commands/user/UserDemote.java | 9 +- .../common/commands/user/UserInfo.java | 10 +- .../common/commands/user/UserPromote.java | 11 +- .../common/config/AbstractConfiguration.java | 4 - .../luckperms/common/config/ConfigKeys.java | 2 +- .../config/adapter/ConfigurationAdapter.java | 2 +- .../common/locale/LocaleManager.java | 18 +-- .../common/locale/command/Argument.java | 9 +- .../common/locale/message/Message.java | 103 +++++++++++----- .../plugin/AbstractLuckPermsPlugin.java | 8 +- .../common/plugin/LuckPermsPlugin.java | 2 +- .../common/treeview/ImmutableTreeNode.java | 5 +- .../common/treeview/PermissionRegistry.java | 37 ++---- .../luckperms/common/treeview/TreeNode.java | 80 ++++++++++++- .../common/verbose/VerboseListener.java | 17 ++- .../luckperms/nukkit/NukkitConfigAdapter.java | 2 +- .../nukkit/model/server/LPPermissionMap.java | 10 +- .../proxy/api6/DescriptionBuilder.java | 2 - .../proxy/api7/DescriptionBuilder.java | 2 - .../luckperms/sponge/LPSpongePlugin.java | 4 +- .../luckperms/sponge/SpongeConfigAdapter.java | 2 +- .../sponge/commands/OptionClear.java | 2 +- .../luckperms/sponge/commands/OptionInfo.java | 4 +- .../luckperms/sponge/commands/OptionSet.java | 2 +- .../sponge/commands/OptionUnset.java | 2 +- .../luckperms/sponge/commands/ParentAdd.java | 2 +- .../sponge/commands/ParentClear.java | 2 +- .../luckperms/sponge/commands/ParentInfo.java | 4 +- .../sponge/commands/ParentRemove.java | 2 +- .../sponge/commands/PermissionClear.java | 2 +- .../sponge/commands/PermissionInfo.java | 4 +- .../sponge/commands/PermissionSet.java | 2 +- .../sponge/commands/SpongeCommandUtils.java | 5 +- .../sponge/service/LuckPermsService.java | 4 +- 93 files changed, 702 insertions(+), 434 deletions(-) create mode 100644 common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/CompletionSupplier.java create mode 100644 common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompleter.java rename common/src/main/java/me/lucko/luckperms/common/command/{utils => tabcomplete}/TabCompletions.java (65%) diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java index 499a86f47..03d1c782a 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java @@ -77,7 +77,7 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public List getObjectList(String path, List def) { + public List getKeys(String path, List def) { ConfigurationSection section = this.configuration.getConfigurationSection(path); if (section == null) { return def; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/server/LPPermissionMap.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/server/LPPermissionMap.java index 218887291..dc8dbd6ab 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/server/LPPermissionMap.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/server/LPPermissionMap.java @@ -99,7 +99,7 @@ public final class LPPermissionMap extends ForwardingMap { Objects.requireNonNull(key, "key"); Objects.requireNonNull(value, "value"); - this.plugin.getPermissionRegistry().offer(key); + this.plugin.getPermissionRegistry().insert(key); Permission ret = super.put(key, value); update(); return ret; @@ -107,9 +107,9 @@ public final class LPPermissionMap extends ForwardingMap { @Override public void putAll(@Nonnull Map m) { - this.plugin.getPermissionRegistry().offerAll(m.keySet()); - super.putAll(m); - update(); + for (Map.Entry ent : m.entrySet()) { + put(ent.getKey(), ent.getValue()); + } } @Override @@ -117,7 +117,7 @@ public final class LPPermissionMap extends ForwardingMap { Objects.requireNonNull(key, "key"); Objects.requireNonNull(value, "value"); - this.plugin.getPermissionRegistry().offer(key); + this.plugin.getPermissionRegistry().insert(key); Permission ret = super.putIfAbsent(key, value); update(); return ret; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java index c510beb62..c1eafb652 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java @@ -82,7 +82,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public List getObjectList(String path, List def) { + public List getKeys(String path, List def) { Configuration section = this.configuration.getSection(path); if (section == null) { return def; diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/AbstractCachedData.java b/common/src/main/java/me/lucko/luckperms/common/caching/AbstractCachedData.java index 41966bc47..1f523aa6e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/AbstractCachedData.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/AbstractCachedData.java @@ -323,10 +323,6 @@ public abstract class AbstractCachedData implements CachedData { return CompletableFuture.allOf(keys.stream().map(this::reloadMeta).toArray(CompletableFuture[]::new)); } - public CompletableFuture reloadAll() { - return CompletableFuture.allOf(reloadPermissions(), reloadMeta()); - } - @Override public void preCalculate(@Nonnull Contexts contexts) { Objects.requireNonNull(contexts, "contexts"); diff --git a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java index 993bef626..9857be5c1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java @@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableList; import me.lucko.luckperms.common.command.abstraction.Command; import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.commands.group.CreateGroup; @@ -97,13 +98,16 @@ public class CommandManager { // the default executor to run commands on private final ExecutorService executor = Executors.newSingleThreadExecutor(); - private final List mainCommands; + private final TabCompletions tabCompletions; + + private final List> mainCommands; public CommandManager(LuckPermsPlugin plugin) { this.plugin = plugin; LocaleManager locale = plugin.getLocaleManager(); - this.mainCommands = ImmutableList.builder() + this.tabCompletions = new TabCompletions(plugin); + this.mainCommands = ImmutableList.>builder() .add(new UserMainCommand(locale)) .add(new GroupMainCommand(locale)) .add(new TrackMainCommand(locale)) @@ -137,6 +141,10 @@ public class CommandManager { return this.plugin; } + public TabCompletions getTabCompletions() { + return this.tabCompletions; + } + public CompletableFuture onCommand(Sender sender, String label, List args) { return onCommand(sender, label, args, this.executor); } @@ -170,7 +178,7 @@ public class CommandManager { } // Look for the main command. - Optional o = this.mainCommands.stream() + Optional> o = this.mainCommands.stream() .filter(m -> m.getName().equalsIgnoreCase(arguments.get(0))) .limit(1) .findAny(); @@ -263,8 +271,7 @@ public class CommandManager { .filter(Command::shouldDisplay) .filter(c -> c.isAuthorized(sender)) .forEach(c -> { - @SuppressWarnings("unchecked") - String permission = (String) c.getPermission().map(p -> ((CommandPermission) p).getPermission()).orElse("None"); + String permission = c.getPermission().map(CommandPermission::getPermission).orElse("None"); TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR) .toBuilder().applyDeep(comp -> { diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/MainCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/MainCommand.java index 03ad1a1bc..04c0e17d9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/MainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/MainCommand.java @@ -27,7 +27,6 @@ package me.lucko.luckperms.common.command.abstraction; import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; -import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -120,7 +119,7 @@ public abstract class MainCommand extends Command { final List objects = getTargets(plugin); if (args.size() <= 1) { - if (args.isEmpty() || args.get(0).equals("")) { + if (args.isEmpty() || args.get(0).trim().isEmpty()) { return objects; } @@ -134,7 +133,7 @@ public abstract class MainCommand extends Command { .collect(Collectors.toList()); if (args.size() == 2) { - if (args.get(1).equals("")) { + if (args.get(1).trim().isEmpty()) { return subs.stream() .map(m -> m.getName().toLowerCase()) .collect(Collectors.toList()); @@ -171,12 +170,10 @@ public abstract class MainCommand extends Command { .collect(Collectors.toList()); if (!subs.isEmpty()) { - MessageUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format(getUsage(), label) + " ...)"); - + Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format(getUsage(), label)); for (Command s : subs) { s.sendUsage(sender, label); } - } else { Message.COMMAND_NO_PERMISSION.send(sender); } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedMainCommand.java index 3e66630b3..0ca20c451 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedMainCommand.java @@ -27,7 +27,6 @@ package me.lucko.luckperms.common.command.abstraction; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.utils.ArgumentParser; -import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.PermissionHolder; @@ -143,9 +142,9 @@ public class SharedMainCommand extends SubCommand if (!subs.isEmpty()) { if (user) { - MessageUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format("/%s user " + getName().toLowerCase() + " ...)", label)); + Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s user " + getName().toLowerCase(), label)); } else { - MessageUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format("/%s group " + getName().toLowerCase() + " ...)", label)); + Message.MAIN_COMMAND_USAGE_HEADER.send(sender, getName(), String.format("/%s group " + getName().toLowerCase(), label)); } for (SharedSubCommand s : subs) { diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedSubCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedSubCommand.java index 84ed46902..99acd0963 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedSubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SharedSubCommand.java @@ -27,9 +27,9 @@ package me.lucko.luckperms.common.command.abstraction; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.access.CommandPermission; -import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.locale.command.Argument; import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec; +import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; @@ -99,22 +99,22 @@ public abstract class SharedSubCommand { public void sendUsage(Sender sender) { StringBuilder sb = new StringBuilder(); if (getArgs() != null) { - sb.append("&3 - &7"); + sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager())); for (Argument arg : getArgs()) { - sb.append(arg.asPrettyString()).append(" "); + sb.append(arg.asPrettyString(sender.getPlatform().getLocaleManager())).append(" "); } } - MessageUtils.sendPluginMessage(sender, "&3> &a" + getName() + sb.toString()); + Message.COMMAND_USAGE_BRIEF.send(sender, getName(), sb.toString()); } public void sendDetailedUsage(Sender sender) { - MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); - MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription()); + Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription()); + if (getArgs() != null) { - MessageUtils.sendPluginMessage(sender, "&3Arguments:"); + Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender); for (Argument arg : getArgs()) { - MessageUtils.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription()); + Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlatform().getLocaleManager()), arg.getDescription()); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SingleCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SingleCommand.java index cadf9249a..a6b68a436 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SingleCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SingleCommand.java @@ -27,9 +27,9 @@ package me.lucko.luckperms.common.command.abstraction; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.access.CommandPermission; -import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.locale.command.Argument; import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec; +import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; @@ -56,23 +56,23 @@ public abstract class SingleCommand extends Command { public void sendUsage(Sender sender, String label) { StringBuilder sb = new StringBuilder(); if (getArgs().isPresent()) { - sb.append("&3 - &7"); + sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager())); for (Argument arg : getArgs().get()) { - sb.append(arg.asPrettyString()).append(" "); + sb.append(arg.asPrettyString(sender.getPlatform().getLocaleManager())).append(" "); } } - MessageUtils.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + sb.toString()); + Message.COMMAND_USAGE_BRIEF.send(sender, getName().toLowerCase(), sb.toString()); } @Override public void sendDetailedUsage(Sender sender, String label) { - MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); - MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription()); + Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription()); + if (getArgs().isPresent()) { - MessageUtils.sendPluginMessage(sender, "&3Arguments:"); + Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender); for (Argument arg : getArgs().get()) { - MessageUtils.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription()); + Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlatform().getLocaleManager()), arg.getDescription()); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SubCommand.java b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SubCommand.java index 576398e67..d30948498 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/abstraction/SubCommand.java @@ -26,9 +26,9 @@ package me.lucko.luckperms.common.command.abstraction; import me.lucko.luckperms.common.command.access.CommandPermission; -import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.locale.command.Argument; import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec; +import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.sender.Sender; import java.util.function.Predicate; @@ -51,23 +51,23 @@ public abstract class SubCommand extends Command { public void sendUsage(Sender sender, String label) { StringBuilder sb = new StringBuilder(); if (getArgs().isPresent()) { - sb.append("&3 - &7"); + sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlatform().getLocaleManager())); for (Argument arg : getArgs().get()) { - sb.append(arg.asPrettyString()).append(" "); + sb.append(arg.asPrettyString(sender.getPlatform().getLocaleManager())).append(" "); } } - MessageUtils.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + sb.toString()); + Message.COMMAND_USAGE_BRIEF.send(sender, getName().toLowerCase(), sb.toString()); } @Override public void sendDetailedUsage(Sender sender, String label) { - MessageUtils.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); - MessageUtils.sendPluginMessage(sender, "&b> &7" + getDescription()); + Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription()); + if (getArgs().isPresent()) { - MessageUtils.sendPluginMessage(sender, "&3Arguments:"); + Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender); for (Argument arg : getArgs().get()) { - MessageUtils.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription()); + Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlatform().getLocaleManager()), arg.getDescription()); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/CompletionSupplier.java b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/CompletionSupplier.java new file mode 100644 index 000000000..23745f331 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/CompletionSupplier.java @@ -0,0 +1,53 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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 strings) { + return partial -> strings.stream().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList()); + } + + static CompletionSupplier startsWith(Supplier> stringsSupplier) { + return partial -> stringsSupplier.get().stream().filter(TabCompleter.startsWithIgnoreCase(partial)).collect(Collectors.toList()); + } + + List supplyCompletions(String partial); + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompleter.java b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompleter.java new file mode 100644 index 000000000..2aca683fd --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompleter.java @@ -0,0 +1,110 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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 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 complete(List 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 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 startsWithIgnoreCase(String prefix) { + return string -> { + if (string.length() < prefix.length()) { + return false; + } + return string.regionMatches(true, 0, prefix, 0, prefix.length()); + }; + } + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/command/utils/TabCompletions.java b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java similarity index 65% rename from common/src/main/java/me/lucko/luckperms/common/command/utils/TabCompletions.java rename to common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java index cf712121c..f3b1eb57a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/utils/TabCompletions.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/tabcomplete/TabCompletions.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.command.utils; +package me.lucko.luckperms.common.command.tabcomplete; import com.google.common.base.Splitter; @@ -32,43 +32,36 @@ import me.lucko.luckperms.common.treeview.PermissionRegistry; import me.lucko.luckperms.common.treeview.TreeNode; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** - * Utility methods for handling tab completion. + * Common completion suppliers used by the plugin */ public final class TabCompletions { - public static List getGroupTabComplete(List args, LuckPermsPlugin plugin) { - return getTabComplete(new ArrayList<>(plugin.getGroupManager().getAll().keySet()), args); - } + private static final CompletionSupplier BOOLEAN = CompletionSupplier.startsWith("true", "false"); - public static List getTrackTabComplete(List args, LuckPermsPlugin plugin) { - return getTabComplete(new ArrayList<>(plugin.getTrackManager().getAll().keySet()), args); - } + private final CompletionSupplier groups; + private final CompletionSupplier tracks; + private final CompletionSupplier permissions; - public static List getBoolTabComplete(List args) { - if (args.size() == 2) { - return Arrays.asList("true", "false"); - } else { - return Collections.emptyList(); - } - } + public TabCompletions(LuckPermsPlugin plugin) { + this.groups = CompletionSupplier.startsWith(() -> plugin.getGroupManager().getAll().keySet()); + this.tracks = CompletionSupplier.startsWith(() -> plugin.getTrackManager().getAll().keySet()); + this.permissions = partial -> { + PermissionRegistry cache = plugin.getPermissionRegistry(); - public static List getPermissionTabComplete(List args, PermissionRegistry cache) { - if (args.size() <= 1) { - if (args.isEmpty() || args.get(0).equals("")) { + if (partial.isEmpty()) { return cache.getRootNode().getChildren() .map(Map::keySet) - .map(s -> (List) new ArrayList<>(s)) + .>map(ArrayList::new) .orElse(Collections.emptyList()); } - String start = args.get(0).toLowerCase(); + String start = partial.toLowerCase(); List parts = new ArrayList<>(Splitter.on('.').splitToList(start)); TreeNode root = cache.getRootNode(); @@ -77,7 +70,7 @@ public final class TabCompletions { return Collections.emptyList(); } - return root.getChildren().get().keySet().stream().filter(s -> s.startsWith(start)).collect(Collectors.toList()); + return root.getChildren().get().keySet().stream().filter(TabCompleter.startsWithIgnoreCase(start)).collect(Collectors.toList()); } String incomplete = parts.remove(parts.size() - 1); @@ -100,25 +93,29 @@ public final class TabCompletions { } return root.getChildren().get().keySet().stream() - .filter(s -> s.startsWith(incomplete)) + .filter(TabCompleter.startsWithIgnoreCase(incomplete)) .map(s -> parts.stream().collect(Collectors.joining(".")) + "." + s) .collect(Collectors.toList()); - } - - return Collections.emptyList(); + }; } - private static List getTabComplete(List options, List args) { - if (args.size() <= 1) { - if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) { - return options; - } + // bit of a weird pattern, but meh it kinda works, reduces the boilerplate + // of calling the commandmanager + tabcompletions getters every time - return options.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList()); - } - - return Collections.emptyList(); + public static CompletionSupplier booleans() { + return BOOLEAN; + } + + public static CompletionSupplier groups(LuckPermsPlugin plugin) { + return plugin.getCommandManager().getTabCompletions().groups; + } + + public static CompletionSupplier tracks(LuckPermsPlugin plugin) { + return plugin.getCommandManager().getTabCompletions().tracks; + } + + public static CompletionSupplier permissions(LuckPermsPlugin plugin) { + return plugin.getCommandManager().getTabCompletions().permissions; } - private TabCompletions() {} } diff --git a/common/src/main/java/me/lucko/luckperms/common/command/utils/MessageUtils.java b/common/src/main/java/me/lucko/luckperms/common/command/utils/MessageUtils.java index c4b6bd55e..0cdd931e8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/utils/MessageUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/utils/MessageUtils.java @@ -29,16 +29,15 @@ import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; +import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.sender.Sender; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.regex.Pattern; public final class MessageUtils { - private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]"); /** * Sends a message to the sender, formatted with the plugin prefix and color scheme @@ -47,40 +46,8 @@ public final class MessageUtils { * @param message the message content */ public static void sendPluginMessage(Sender sender, String message) { - String prefix = sender.getPlatform().getLocaleManager().getTranslation(Message.PREFIX); - if (prefix == null) { - prefix = Message.PREFIX.getMessage(); - } - sender.sendMessage(color(prefix + message)); - } - - /** - * Colorizes a message. - * - * @param s the message to colorize - * @return a colored message - */ - public static String color(String s) { - char[] b = s.toCharArray(); - - for (int i = 0; i < b.length - 1; ++i) { - if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) { - b[i] = 167; - b[i + 1] = Character.toLowerCase(b[i + 1]); - } - } - - return new String(b); - } - - /** - * Strips all color from a message - * - * @param s the message to strip color from - * @return the message without color - */ - public static String stripColor(String s) { - return s == null ? null : STRIP_COLOR_PATTERN.matcher(s).replaceAll(""); + String prefix = Message.PREFIX.asString(sender.getPlatform().getLocaleManager()); + sender.sendMessage(Message.colorize(prefix + message)); } public static String toCommaSep(Collection strings) { @@ -163,19 +130,20 @@ public final class MessageUtils { /** * Produces a string representing a Nodes context, suitable for appending onto another message line. * + * @param localeManager the locale manager * @param node the node to query context from * @return a string representing the nodes context, or an empty string if the node applies globally. */ - public static String getAppendableNodeContextString(Node node) { + public static String getAppendableNodeContextString(LocaleManager localeManager, Node node) { StringBuilder sb = new StringBuilder(); if (node.isServerSpecific()) { - sb.append(" ").append(contextToString(Contexts.SERVER_KEY, node.getServer().get())); + sb.append(" ").append(contextToString(localeManager, Contexts.SERVER_KEY, node.getServer().get())); } if (node.isWorldSpecific()) { - sb.append(" ").append(contextToString(Contexts.WORLD_KEY, node.getWorld().get())); + sb.append(" ").append(contextToString(localeManager, Contexts.WORLD_KEY, node.getWorld().get())); } for (Map.Entry c : node.getContexts().toSet()) { - sb.append(" ").append(contextToString(c.getKey(), c.getValue())); + sb.append(" ").append(contextToString(localeManager, c.getKey(), c.getValue())); } return sb.toString(); @@ -184,27 +152,29 @@ public final class MessageUtils { /** * Converts a context pair to a formatted string, surrounded by ( ) brackets. * + * + * @param localeManager the locale manager * @param key the context key * @param value the context value * @return a formatted string */ - public static String contextToString(String key, String value) { - return Message.CONTEXT_PAIR.asString(null, key, value); + public static String contextToString(LocaleManager localeManager, String key, String value) { + return Message.CONTEXT_PAIR.asString(localeManager, key, value); } - public static String contextSetToString(ContextSet set) { + public static String contextSetToString(LocaleManager localeManager, ContextSet set) { if (set.isEmpty()) { - return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(null); + return Message.CONTEXT_PAIR__GLOBAL_INLINE.asString(localeManager); } StringBuilder sb = new StringBuilder(); for (Map.Entry e : set.toSet()) { - sb.append(Message.CONTEXT_PAIR_INLINE.asString(null, e.getKey(), e.getValue())); - sb.append(Message.CONTEXT_PAIR_SEP.asString(null)); + sb.append(Message.CONTEXT_PAIR_INLINE.asString(localeManager, e.getKey(), e.getValue())); + sb.append(Message.CONTEXT_PAIR_SEP.asString(localeManager)); } - return sb.delete(sb.length() - Message.CONTEXT_PAIR_SEP.asString(null).length(), sb.length()).toString(); + return sb.delete(sb.length() - Message.CONTEXT_PAIR_SEP.asString(localeManager).length(), sb.length()).toString(); } private MessageUtils() {} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java index 6b33152d0..e48170679 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java @@ -29,7 +29,6 @@ import me.lucko.luckperms.api.ChatMetaType; import me.lucko.luckperms.api.DataMutateResult; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; -import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; @@ -85,7 +84,7 @@ public class MetaAddChatMeta extends SharedSubCommand { DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build()); if (result.asBoolean()) { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder(); + TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( "¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥' @@ -100,7 +99,7 @@ public class MetaAddChatMeta extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)); + Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java index 3391da003..d4570ef6b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java @@ -30,7 +30,6 @@ import me.lucko.luckperms.api.DataMutateResult; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; -import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; @@ -95,7 +94,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand { if (ret.getKey().asBoolean()) { duration = ret.getValue().getExpiryUnixTime(); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder(); + TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( "¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥' @@ -110,7 +109,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)); + Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java index 80834ef0f..dca606369 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java @@ -104,9 +104,9 @@ public class MetaClear extends SharedSubCommand { int changed = before - holder.enduringData().immutable().size(); if (changed == 1) { - Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(context), changed); + Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { - Message.META_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(context), changed); + Message.META_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } ExtendedLogEntry.build().actor(sender).acted(holder) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java index 4b299acbb..604774d10 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java @@ -29,7 +29,6 @@ import com.google.common.collect.Maps; import me.lucko.luckperms.api.ChatMetaType; import me.lucko.luckperms.api.LocalizedNode; -import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; @@ -124,12 +123,12 @@ public class MetaInfo extends SharedSubCommand { for (LocalizedNode m : meta) { String location = processLocation(m, holder); if (m.hasSpecificContext()) { - String context = MessageUtils.getAppendableNodeContextString(m); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context), CommandManager.SECTION_CHAR).toBuilder(); + String context = MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), m); + TextComponent.Builder builder = Message.META_ENTRY_WITH_CONTEXT.asComponent(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context).toBuilder(); builder.applyDeep(makeFancy(holder, label, m)); sender.sendMessage(builder.build()); } else { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location), CommandManager.SECTION_CHAR).toBuilder(); + TextComponent.Builder builder = Message.META_ENTRY.asComponent(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location).toBuilder(); builder.applyDeep(makeFancy(holder, label, m)); sender.sendMessage(builder.build()); } @@ -140,12 +139,12 @@ public class MetaInfo extends SharedSubCommand { for (Map.Entry e : meta) { String location = processLocation(e.getValue(), holder); if (e.getValue().hasSpecificContext()) { - String context = MessageUtils.getAppendableNodeContextString(e.getValue()); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.CHAT_META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location, context), CommandManager.SECTION_CHAR).toBuilder(); + String context = MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), e.getValue()); + TextComponent.Builder builder = Message.CHAT_META_ENTRY_WITH_CONTEXT.asComponent(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location, context).toBuilder(); builder.applyDeep(makeFancy(type, holder, label, e.getValue())); sender.sendMessage(builder.build()); } else { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.CHAT_META_ENTRY.asString(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location), CommandManager.SECTION_CHAR).toBuilder(); + TextComponent.Builder builder = Message.CHAT_META_ENTRY.asComponent(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location).toBuilder(); builder.applyDeep(makeFancy(type, holder, label, e.getValue())); sender.sendMessage(builder.build()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java index a7f759264..a29b030f3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java @@ -29,7 +29,6 @@ import me.lucko.luckperms.api.ChatMetaType; import me.lucko.luckperms.api.DataMutateResult; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; -import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; @@ -91,7 +90,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand { !n.isTemporary() && n.getFullContexts().makeImmutable().equals(context.makeImmutable()) ); - Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(context)); + Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("meta" , "remove" + this.type.name().toLowerCase(), priority, "*", context) @@ -104,7 +103,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand { DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build()); if (result.asBoolean()) { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder(); + TextComponent.Builder builder = Message.REMOVE_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( "¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥' @@ -119,7 +118,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.DOES_NOT_HAVE_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)); + Message.DOES_NOT_HAVE_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java index 79cf8a734..970d00792 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java @@ -29,7 +29,6 @@ import me.lucko.luckperms.api.ChatMetaType; import me.lucko.luckperms.api.DataMutateResult; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; -import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; @@ -91,7 +90,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand { !n.isPermanent() && n.getFullContexts().makeImmutable().equals(context.makeImmutable()) ); - Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(context)); + Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("meta" , "removetemp" + this.type.name().toLowerCase(), priority, "*", context) @@ -104,7 +103,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand { DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).setExpiry(10L).withExtraContext(context).build()); if (result.asBoolean()) { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder(); + TextComponent.Builder builder = Message.REMOVE_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( "¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥' @@ -119,7 +118,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context)); + Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java index dcad6c3e8..661b4ed3c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java @@ -82,14 +82,14 @@ public class MetaSet extends SharedSubCommand { Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).build(); if (holder.hasPermission(NodeMapType.ENDURING, n, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { - Message.ALREADY_HAS_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(context)); + Message.ALREADY_HAS_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } holder.clearMetaKeys(key, context, false); holder.setPermission(n); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), MessageUtils.contextSetToString(context))).toBuilder(); + TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥' diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java index 30726b7a6..7e2ce344e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java @@ -29,7 +29,6 @@ import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.StandardNodeEquality; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; -import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; @@ -88,14 +87,14 @@ public class MetaSetTemp extends SharedSubCommand { Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).setExpiry(duration).build(); if (holder.hasPermission(NodeMapType.ENDURING, n, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) { - Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(context)); + Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } holder.clearMetaKeys(key, context, true); duration = holder.setPermission(n, modifier).getValue().getExpiryUnixTime(); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_TEMP_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder(); + TextComponent.Builder builder = Message.SET_META_TEMP_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥' diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java index 40fb57bac..191c4f723 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java @@ -71,7 +71,7 @@ public class MetaUnset extends SharedSubCommand { } if (holder.clearMetaKeys(key, context, false)) { - Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("meta", "unset", key, context) @@ -80,7 +80,7 @@ public class MetaUnset extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.DOESNT_HAVE_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(context)); + Message.DOESNT_HAVE_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java index e79b7cd99..19b3ff6a4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java @@ -71,7 +71,7 @@ public class MetaUnsetTemp extends SharedSubCommand { } if (holder.clearMetaKeys(key, context, true)) { - Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("meta", "unsettemp", key, context) @@ -80,7 +80,7 @@ public class MetaUnsetTemp extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.DOESNT_HAVE_TEMP_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(context)); + Message.DOESNT_HAVE_TEMP_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java index 88a221a27..6814e76bd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderClear.java @@ -74,9 +74,9 @@ public class HolderClear extends SubCommand { int changed = before - holder.enduringData().immutable().size(); if (changed == 1) { - Message.CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed); + Message.CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { - Message.CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed); + Message.CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } ExtendedLogEntry.build().actor(sender).acted(holder) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java index 0e8f29942..4a9410ea0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderShowTracks.java @@ -86,7 +86,7 @@ public class HolderShowTracks extends SubCommand .collect(Collectors.toList()); for (Track t : tracks) { - lines.add(Maps.immutableEntry(t, MessageUtils.getAppendableNodeContextString(node) + "\n" + MessageUtils.listToArrowSep(t.getGroups(), groupName))); + lines.add(Maps.immutableEntry(t, MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node) + "\n" + MessageUtils.listToArrowSep(t.getGroups(), groupName))); } } } else { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java index ea04ff4bc..e2121846a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAdd.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete; - public class ParentAdd extends SharedSubCommand { public ParentAdd(LocaleManager locale) { super(CommandSpec.PARENT_ADD.localize(locale), "add", CommandPermission.USER_PARENT_ADD, CommandPermission.GROUP_PARENT_ADD, Predicates.is(0)); @@ -83,7 +83,7 @@ public class ParentAdd extends SharedSubCommand { DataMutateResult result = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build()); if (result.asBoolean()) { - Message.SET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.SET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("parent", "add", group.getName(), context) @@ -92,13 +92,15 @@ public class ParentAdd extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java index b40ba3338..edefd09ab 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentAddTemp.java @@ -34,6 +34,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -53,8 +55,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; import java.util.Map; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete; - public class ParentAddTemp extends SharedSubCommand { public ParentAddTemp(LocaleManager locale) { super(CommandSpec.PARENT_ADD_TEMP.localize(locale), "addtemp", CommandPermission.USER_PARENT_ADD_TEMP, CommandPermission.GROUP_PARENT_ADD_TEMP, Predicates.inRange(0, 1)); @@ -88,7 +88,7 @@ public class ParentAddTemp extends SharedSubCommand { } if (group.getName().equalsIgnoreCase(holder.getObjectName())) { - Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } @@ -96,7 +96,7 @@ public class ParentAddTemp extends SharedSubCommand { if (ret.getKey().asBoolean()) { duration = ret.getValue().getExpiryUnixTime(); - Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(context)); + Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("parent", "addtemp", group.getName(), duration, context) @@ -105,13 +105,15 @@ public class ParentAddTemp extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java index f5ff4c8a9..b78fd5f8f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClear.java @@ -74,9 +74,9 @@ public class ParentClear extends SharedSubCommand { int changed = before - holder.enduringData().immutable().size(); if (changed == 1) { - Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed); + Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { - Message.PARENT_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed); + Message.PARENT_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } ExtendedLogEntry.build().actor(sender).acted(holder) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java index bead6a413..ad27ab130 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentClearTrack.java @@ -32,6 +32,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getTrackTabComplete; - public class ParentClearTrack extends SharedSubCommand { public ParentClearTrack(LocaleManager locale) { super(CommandSpec.PARENT_CLEAR_TRACK.localize(locale), "cleartrack", CommandPermission.USER_PARENT_CLEAR_TRACK, CommandPermission.GROUP_PARENT_CLEAR_TRACK, Predicates.is(0)); @@ -105,9 +105,9 @@ public class ParentClearTrack extends SharedSubCommand { int changed = before - holder.enduringData().immutable().size(); if (changed == 1) { - Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(context), changed); + Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { - Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(context), changed); + Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } ExtendedLogEntry.build().actor(sender).acted(holder) @@ -120,6 +120,8 @@ public class ParentClearTrack extends SharedSubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getTrackTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.tracks(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java index ff53fb288..401eb6c44 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentInfo.java @@ -112,7 +112,7 @@ public class ParentInfo extends SharedSubCommand { // send content for (LocalizedNode node : content) { - String s = "&3> &a" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node); + String s = "&3> &a" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node); if (node.isTemporary()) { s += "\n&2 expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java index 6ffa40a37..99d8c16a1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -49,8 +51,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete; - public class ParentRemove extends SharedSubCommand { public ParentRemove(LocaleManager locale) { super(CommandSpec.PARENT_REMOVE.localize(locale), "remove", CommandPermission.USER_PARENT_REMOVE, CommandPermission.GROUP_PARENT_REMOVE, Predicates.is(0)); @@ -92,7 +92,7 @@ public class ParentRemove extends SharedSubCommand { DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).withExtraContext(context).build()); if (result.asBoolean()) { - Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context)); + Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("parent", "remove", groupName, context) @@ -105,13 +105,15 @@ public class ParentRemove extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.DOES_NOT_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context)); + Message.DOES_NOT_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java index 978ff1b47..e173d277d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete; - public class ParentRemoveTemp extends SharedSubCommand { public ParentRemoveTemp(LocaleManager locale) { super(CommandSpec.PARENT_REMOVE_TEMP.localize(locale), "removetemp", CommandPermission.USER_PARENT_REMOVE_TEMP, CommandPermission.GROUP_PARENT_REMOVE_TEMP, Predicates.is(0)); @@ -77,7 +77,7 @@ public class ParentRemoveTemp extends SharedSubCommand { DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).setExpiry(10L).withExtraContext(context).build()); if (result.asBoolean()) { - Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context)); + Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("parent", "removetemp", groupName, context) @@ -86,13 +86,15 @@ public class ParentRemoveTemp extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.DOES_NOT_TEMP_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context)); + Message.DOES_NOT_TEMP_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java index 8b24c7a45..694a0e161 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java @@ -32,6 +32,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete; - public class ParentSet extends SharedSubCommand { public ParentSet(LocaleManager locale) { super(CommandSpec.PARENT_SET.localize(locale), "set", CommandPermission.USER_PARENT_SET, CommandPermission.GROUP_PARENT_SET, Predicates.is(0)); @@ -86,7 +86,7 @@ public class ParentSet extends SharedSubCommand { ((User) holder).getPrimaryGroup().setStoredValue(group.getName()); } - Message.SET_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.SET_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("parent", "set", group.getName(), context) @@ -98,6 +98,8 @@ public class ParentSet extends SharedSubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java index e5422f24c..cd92d8873 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSetTrack.java @@ -32,6 +32,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -49,9 +51,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getTrackTabComplete; - public class ParentSetTrack extends SharedSubCommand { public ParentSetTrack(LocaleManager locale) { super(CommandSpec.PARENT_SET_TRACK.localize(locale), "settrack", CommandPermission.USER_PARENT_SET_TRACK, CommandPermission.GROUP_PARENT_SET_TRACK, Predicates.inRange(0, 1)); @@ -117,7 +116,7 @@ public class ParentSetTrack extends SharedSubCommand { holder.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName())); holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build()); - Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), group.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), group.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("parent", "settrack", track.getName(), groupName, context) @@ -129,11 +128,9 @@ public class ParentSetTrack extends SharedSubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - if (args.isEmpty() || args.size() == 1) { - return getTrackTabComplete(args, plugin); - } - - args.remove(0); - return getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.tracks(plugin)) + .at(1, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java index b23ff27ad..10011876f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/UserSwitchPrimaryGroup.java @@ -32,6 +32,8 @@ import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.StorageAssistant; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.locale.LocaleManager; @@ -48,8 +50,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getGroupTabComplete; - public class UserSwitchPrimaryGroup extends SharedSubCommand { public UserSwitchPrimaryGroup(LocaleManager locale) { super(CommandSpec.USER_SWITCHPRIMARYGROUP.localize(locale), "switchprimarygroup", CommandPermission.USER_PARENT_SWITCHPRIMARYGROUP, null, Predicates.not(1)); @@ -102,6 +102,8 @@ public class UserSwitchPrimaryGroup extends SharedSubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java index 22e5ad071..602333641 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheck.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.locale.LocaleManager; @@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete; - public class PermissionCheck extends SharedSubCommand { public PermissionCheck(LocaleManager locale) { super(CommandSpec.PERMISSION_CHECK.localize(locale), "check", CommandPermission.USER_PERM_CHECK, CommandPermission.GROUP_PERM_CHECK, Predicates.is(0)); @@ -67,12 +67,14 @@ public class PermissionCheck extends SharedSubCommand { Tristate result = holder.hasPermission(NodeMapType.ENDURING, NodeFactory.builder(node).withExtraContext(context).build(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY); String s = MessageUtils.formatTristate(result); - Message.CHECK_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context)); + Message.CHECK_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.SUCCESS; } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getPermissionTabComplete(args, plugin.getPermissionRegistry()); + return TabCompleter.create() + .at(0, TabCompletions.permissions(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java index 0119d3ada..b8e1bdeae 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionCheckInherits.java @@ -32,6 +32,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.locale.LocaleManager; @@ -46,8 +48,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete; - public class PermissionCheckInherits extends SharedSubCommand { public PermissionCheckInherits(LocaleManager locale) { super(CommandSpec.PERMISSION_CHECK_INHERITS.localize(locale), "checkinherits", CommandPermission.USER_PERM_CHECK_INHERITS, CommandPermission.GROUP_PERM_CHECK_INHERITS, Predicates.is(0)); @@ -71,12 +71,14 @@ public class PermissionCheckInherits extends SharedSubCommand { } String s = MessageUtils.formatTristate(result.getResult()); - Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context), String.valueOf(location)); + Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context), String.valueOf(location)); return CommandResult.SUCCESS; } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getPermissionTabComplete(args, plugin.getPermissionRegistry()); + return TabCompleter.create() + .at(0, TabCompletions.permissions(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java index 32d814cfa..fbbe58294 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionClear.java @@ -74,9 +74,9 @@ public class PermissionClear extends SharedSubCommand { int changed = before - holder.enduringData().immutable().size(); if (changed == 1) { - Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed); + Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { - Message.PERMISSION_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed); + Message.PERMISSION_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } ExtendedLogEntry.build().actor(sender).acted(holder) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java index 3cd151c43..44f89b63c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionInfo.java @@ -81,8 +81,7 @@ public class PermissionInfo extends SharedSubCommand { // remove irrelevant types (these are displayed in the other info commands) nodes.removeIf(node -> (node.isGroupNode() && node.getValue() && plugin.getGroupManager().isLoaded(node.getGroupName())) || // remove if the node is a meta node - node.isPrefix() || node.isSuffix() || node.isMeta() - ); + node.isPrefix() || node.isSuffix() || node.isMeta()); // handle empty if (nodes.isEmpty()) { @@ -115,7 +114,7 @@ public class PermissionInfo extends SharedSubCommand { // send content for (LocalizedNode node : content) { - String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission() + (sender.isConsole() ? " &7(" + node.getValue() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(node); + String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission() + (sender.isConsole() ? " &7(" + node.getValue() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node); if (node.isTemporary()) { s += "\n&2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java index 9b1bd1932..0f91131c7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSet.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -47,9 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getBoolTabComplete; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete; - public class PermissionSet extends SharedSubCommand { public PermissionSet(LocaleManager locale) { super(CommandSpec.PERMISSION_SET.localize(locale), "set", CommandPermission.USER_PERM_SET, CommandPermission.GROUP_PERM_SET, Predicates.is(0)); @@ -79,7 +78,7 @@ public class PermissionSet extends SharedSubCommand { DataMutateResult result = holder.setPermission(NodeFactory.builder(node).setValue(value).withExtraContext(context).build()); if (result.asBoolean()) { - Message.SETPERMISSION_SUCCESS.send(sender, node, value, holder.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.SETPERMISSION_SUCCESS.send(sender, node, value, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("permission", "set", node, value, context) @@ -88,17 +87,16 @@ public class PermissionSet extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.ALREADY_HASPERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context)); + Message.ALREADY_HASPERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - List ret = getBoolTabComplete(args); - if (!ret.isEmpty()) { - return ret; - } - return getPermissionTabComplete(args, plugin.getPermissionRegistry()); + return TabCompleter.create() + .at(0, TabCompletions.permissions(plugin)) + .at(1, TabCompletions.booleans()) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java index a9f56202d..1d1e749fe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionSetTemp.java @@ -34,6 +34,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -52,9 +54,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; import java.util.Map; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getBoolTabComplete; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete; - public class PermissionSetTemp extends SharedSubCommand { public PermissionSetTemp(LocaleManager locale) { super(CommandSpec.PERMISSION_SETTEMP.localize(locale), "settemp", CommandPermission.USER_PERM_SET_TEMP, CommandPermission.GROUP_PERM_SET_TEMP, Predicates.inRange(0, 2)); @@ -87,7 +86,7 @@ public class PermissionSetTemp extends SharedSubCommand { if (result.getKey().asBoolean()) { duration = result.getValue().getExpiryUnixTime(); - Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, holder.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(context)); + Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, holder.getFriendlyName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("permission", "settemp", node, value, duration, context) @@ -96,17 +95,16 @@ public class PermissionSetTemp extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context)); + Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - List ret = getBoolTabComplete(args); - if (!ret.isEmpty()) { - return ret; - } - return getPermissionTabComplete(args, plugin.getPermissionRegistry()); + return TabCompleter.create() + .at(0, TabCompletions.permissions(plugin)) + .at(1, TabCompletions.booleans()) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java index 1c0a52d8c..0bf02a822 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnset.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete; - public class PermissionUnset extends SharedSubCommand { public PermissionUnset(LocaleManager locale) { super(CommandSpec.PERMISSION_UNSET.localize(locale), "unset", CommandPermission.USER_PERM_UNSET, CommandPermission.GROUP_PERM_UNSET, Predicates.is(0)); @@ -77,7 +77,7 @@ public class PermissionUnset extends SharedSubCommand { DataMutateResult result = holder.unsetPermission(NodeFactory.builder(node).withExtraContext(context).build()); if (result.asBoolean()) { - Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("permission", "unset", node, context) @@ -86,13 +86,15 @@ public class PermissionUnset extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.DOES_NOT_HAVE_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context)); + Message.DOES_NOT_HAVE_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getPermissionTabComplete(args, plugin.getPermissionRegistry()); + return TabCompleter.create() + .at(0, TabCompletions.permissions(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java index 958b07629..efb305c5d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/PermissionUnsetTemp.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SharedSubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; @@ -47,8 +49,6 @@ import me.lucko.luckperms.common.utils.Predicates; import java.util.List; -import static me.lucko.luckperms.common.command.utils.TabCompletions.getPermissionTabComplete; - public class PermissionUnsetTemp extends SharedSubCommand { public PermissionUnsetTemp(LocaleManager locale) { super(CommandSpec.PERMISSION_UNSETTEMP.localize(locale), "unsettemp", CommandPermission.USER_PERM_UNSET_TEMP, CommandPermission.GROUP_PERM_UNSET_TEMP, Predicates.is(0)); @@ -77,7 +77,7 @@ public class PermissionUnsetTemp extends SharedSubCommand { DataMutateResult result = holder.unsetPermission(NodeFactory.builder(node).setExpiry(10L).withExtraContext(context).build()); if (result.asBoolean()) { - Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(context)); + Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(holder) .action("permission", "unsettemp", node, context) @@ -86,13 +86,15 @@ public class PermissionUnsetTemp extends SharedSubCommand { StorageAssistant.save(holder, sender, plugin); return CommandResult.SUCCESS; } else { - Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context)); + Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } } @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return getPermissionTabComplete(args, plugin.getPermissionRegistry()); + return TabCompleter.create() + .at(0, TabCompletions.permissions(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java index f57de2f12..6d59cdc52 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java @@ -31,7 +31,8 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.access.CommandPermission; -import me.lucko.luckperms.common.command.utils.TabCompletions; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -88,6 +89,8 @@ public class DeleteGroup extends SingleCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java index 37e7b2fbb..426a76ebc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupInfo.java @@ -75,15 +75,15 @@ public class GroupInfo extends SubCommand { if (!parents.isEmpty()) { Message.INFO_PARENT_HEADER.send(sender); for (Node node : parents) { - Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node)); + Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node)); } } if (!tempParents.isEmpty()) { Message.INFO_TEMP_PARENT_HEADER.send(sender); for (Node node : tempParents) { - Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node)); - Message.EMPTY.send(sender, "&f- &2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime())); + Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node)); + Message.INFO_PARENT_ENTRY_EXPIRY.send(sender, DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime())); } } return CommandResult.SUCCESS; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java index b7abd8b1d..3bb31934d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java @@ -142,7 +142,7 @@ public class GroupListMembers extends SubCommand { headerMessage.send(sender, page, pages.size(), results.size()); for (Map.Entry> ent : mappedContent) { - String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode()); + String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), ent.getValue().asNode()); TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build(); sender.sendMessage(message); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java index 9035c36a9..29af6e180 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupSetDisplayName.java @@ -83,7 +83,7 @@ public class GroupSetDisplayName extends SubCommand { group.removeIf(context, n -> n.getTypeData(DisplayNameType.KEY).isPresent()); if (name.equals(group.getName())) { - Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, group.getName(), MessageUtils.contextSetToString(context)); + Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(group) .action("setdisplayname", name, context) @@ -95,7 +95,7 @@ public class GroupSetDisplayName extends SubCommand { group.setPermission(NodeFactory.builder("displayname." + name).withExtraContext(context).build()); - Message.GROUP_SET_DISPLAY_NAME.send(sender, name, group.getName(), MessageUtils.contextSetToString(context)); + Message.GROUP_SET_DISPLAY_NAME.send(sender, name, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(group) .action("setdisplayname", name, context) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java index 94d5aa69a..1a22639e5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/ListGroups.java @@ -25,7 +25,6 @@ package me.lucko.luckperms.common.commands.group; -import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.access.CommandPermission; @@ -37,7 +36,6 @@ import me.lucko.luckperms.common.model.Track; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.utils.Predicates; -import me.lucko.luckperms.common.utils.TextUtils; import net.kyori.text.TextComponent; import net.kyori.text.event.ClickEvent; @@ -74,16 +72,16 @@ public class ListGroups extends SingleCommand { TextComponent component; if (tracks.isEmpty()) { - component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY.asString(plugin.getLocaleManager(), + component = Message.GROUPS_LIST_ENTRY.asComponent(plugin.getLocaleManager(), group.getFriendlyName(), group.getWeight().orElse(0) - ), CommandManager.SECTION_CHAR); + ); } else { - component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asString(plugin.getLocaleManager(), + component = Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asComponent(plugin.getLocaleManager(), group.getFriendlyName(), group.getWeight().orElse(0), MessageUtils.toCommaSep(tracks) - ), CommandManager.SECTION_CHAR); + ); } component = component.toBuilder().applyDeep(c -> { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogGroupHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogGroupHistory.java index b5a73bc7c..f72909985 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogGroupHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogGroupHistory.java @@ -30,8 +30,9 @@ import me.lucko.luckperms.common.actionlog.Log; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -109,6 +110,8 @@ public class LogGroupHistory extends SubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogTrackHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogTrackHistory.java index 49c0b2c82..92d02009f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogTrackHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogTrackHistory.java @@ -30,8 +30,9 @@ import me.lucko.luckperms.common.actionlog.Log; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -109,6 +110,8 @@ public class LogTrackHistory extends SubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getTrackTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.tracks(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java index 575f8c8ef..af1d7319e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ApplyEditsCommand.java @@ -141,17 +141,17 @@ public class ApplyEditsCommand extends SingleCommand { Message.APPLY_EDITS_SUCCESS.send(sender, holder.getFriendlyName()); Message.APPLY_EDITS_SUCCESS_SUMMARY.send(sender, additions, additionsSummary, deletions, deletionsSummary); for (Node n : diffAdded) { - Message.APPLY_EDITS_DIFF_ADDED.send(sender, formatNode(n)); + Message.APPLY_EDITS_DIFF_ADDED.send(sender, formatNode(plugin.getLocaleManager(), n)); } for (Node n : diffRemoved) { - Message.APPLY_EDITS_DIFF_REMOVED.send(sender, formatNode(n)); + Message.APPLY_EDITS_DIFF_REMOVED.send(sender, formatNode(plugin.getLocaleManager(), n)); } StorageAssistant.save(holder, sender, plugin); return true; } - private static String formatNode(Node n) { - return n.getPermission() + " &7(" + (n.getValue() ? "&a" : "&c") + n.getValue() + "&7)" + MessageUtils.getAppendableNodeContextString(n) + + private static String formatNode(LocaleManager localeManager, Node n) { + return n.getPermission() + " &7(" + (n.getValue() ? "&a" : "&c") + n.getValue() + "&7)" + MessageUtils.getAppendableNodeContextString(localeManager, n) + (n.isTemporary() ? " &7(" + DurationFormatter.CONCISE.formatDateDiff(n.getExpiryUnixTime()) + ")" : ""); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/CheckCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/CheckCommand.java index 468b5d4b4..450ebd1e0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/CheckCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/CheckCommand.java @@ -29,8 +29,10 @@ import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.MessageUtils; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -75,15 +77,9 @@ public class CheckCommand extends SingleCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - if (args.isEmpty()) { - return plugin.getBootstrap().getPlayerList().collect(Collectors.toList()); - } - - if (args.size() == 1) { - return plugin.getBootstrap().getPlayerList().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList()); - } - - args.remove(0); - return TabCompletions.getPermissionTabComplete(args, plugin.getPermissionRegistry()); + return TabCompleter.create() + .at(0, CompletionSupplier.startsWith(() -> plugin.getBootstrap().getPlayerList().collect(Collectors.toList()))) + .at(1, TabCompletions.permissions(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java index 9c6dad1fa..bc45be317 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java @@ -55,10 +55,9 @@ public class InfoCommand extends SingleCommand { plugin.getBootstrap().getServerVersion() ); - Message.EMPTY.send(sender, "&f- &bStorage:"); - Message.EMPTY.send(sender, "&f- &3Type: &f" + plugin.getStorage().getName()); + Message.INFO_STORAGE.send(sender, plugin.getStorage().getName()); for (Map.Entry 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, diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java index 64f7f8d0b..3f3fbaa9f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java @@ -38,9 +38,10 @@ import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; @@ -123,7 +124,9 @@ public class SearchCommand extends SingleCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getPermissionTabComplete(args, plugin.getPermissionRegistry()); + return TabCompleter.create() + .at(0, TabCompletions.permissions(plugin)) + .complete(args); } private static > void sendResult(Sender sender, List> results, Function lookupFunction, Message headerMessage, HolderType holderType, String label, int page, Comparison comparison) { @@ -154,7 +157,7 @@ public class SearchCommand extends SingleCommand { permission = "&7 - (" + ent.getValue().getPermission() + ")"; } - String s = "&3> &b" + ent.getKey() + permission + "&7 - " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode()); + String s = "&3> &b" + ent.getKey() + permission + "&7 - " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(sender.getPlatform().getLocaleManager(), ent.getValue().asNode()); TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build(); sender.sendMessage(message); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java index 1cae0d195..574318436 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java @@ -31,7 +31,8 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.access.CommandPermission; -import me.lucko.luckperms.common.command.utils.TabCompletions; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -80,6 +81,8 @@ public class DeleteTrack extends SingleCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getTrackTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.tracks(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java index fbf0c8bf0..12bb195ec 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackAppend.java @@ -30,9 +30,10 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -85,6 +86,8 @@ public class TrackAppend extends SubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java index 08fd21dc2..1d6da6e8f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackInsert.java @@ -30,9 +30,10 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -99,6 +100,8 @@ public class TrackInsert extends SubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRemove.java index ff0e5d7a9..f2f1cf493 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackRemove.java @@ -30,9 +30,10 @@ import me.lucko.luckperms.common.actionlog.ExtendedLogEntry; import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -79,6 +80,8 @@ public class TrackRemove extends SubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getGroupTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.groups(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java index 159ca8763..f29fb4a68 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java @@ -33,10 +33,11 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -115,7 +116,7 @@ public class UserDemote extends SubCommand { String groupFrom = result.getGroupFrom().get(); String groupTo = result.getGroupTo().get(); - Message.USER_DEMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(context)); + Message.USER_DEMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); if (!silent) { Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupTo, groupFrom, true)); } @@ -135,6 +136,8 @@ public class UserDemote extends SubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getTrackTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.tracks(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java index ff18522de..49063f73f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserInfo.java @@ -85,15 +85,15 @@ public class UserInfo extends SubCommand { if (!parents.isEmpty()) { Message.INFO_PARENT_HEADER.send(sender); for (Node node : parents) { - Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node)); + Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node)); } } if (!tempParents.isEmpty()) { Message.INFO_TEMP_PARENT_HEADER.send(sender); for (Node node : tempParents) { - Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node)); - Message.EMPTY.send(sender, "&f- &2- expires in " + DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime())); + Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node)); + Message.INFO_PARENT_ENTRY_EXPIRY.send(sender, DurationFormatter.LONG.formatDateDiff(node.getExpiryUnixTime())); } } @@ -106,7 +106,7 @@ public class UserInfo extends SubCommand { ContextSet contextSet = contexts.getContexts(); if (!contextSet.isEmpty()) { context = contextSet.toSet().stream() - .map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())) + .map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue())) .collect(Collectors.joining(" ")); } @@ -121,7 +121,7 @@ public class UserInfo extends SubCommand { ListMultimap metaMap = data.getMetaMultimap(); if (!metaMap.isEmpty()) { meta = metaMap.entries().stream() - .map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())) + .map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue())) .collect(Collectors.joining(" ")); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java index 76a86297a..77d029950 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java @@ -33,10 +33,11 @@ import me.lucko.luckperms.common.command.abstraction.CommandException; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; +import me.lucko.luckperms.common.command.tabcomplete.TabCompleter; +import me.lucko.luckperms.common.command.tabcomplete.TabCompletions; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.StorageAssistant; -import me.lucko.luckperms.common.command.utils.TabCompletions; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -101,7 +102,7 @@ public class UserPromote extends SubCommand { return CommandResult.STATE_ERROR; case ADDED_TO_FIRST_GROUP: { - Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getFriendlyName(), result.getGroupTo().get(), MessageUtils.contextSetToString(context)); + Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getFriendlyName(), result.getGroupTo().get(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); ExtendedLogEntry.build().actor(sender).acted(user) .action("promote", track.getName(), context) @@ -115,7 +116,7 @@ public class UserPromote extends SubCommand { String groupFrom = result.getGroupFrom().get(); String groupTo = result.getGroupTo().get(); - Message.USER_PROMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(context)); + Message.USER_PROMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), groupFrom, groupTo, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); if (!silent) { Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), groupFrom, groupTo, false)); } @@ -135,6 +136,8 @@ public class UserPromote extends SubCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { - return TabCompletions.getTrackTabComplete(args, plugin); + return TabCompleter.create() + .at(0, TabCompletions.tracks(plugin)) + .complete(args); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java index fe370fa30..1bbd9408e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java @@ -106,10 +106,6 @@ public class AbstractConfiguration implements LuckPermsConfiguration { getPlugin().getEventFactory().handleConfigReload(); } - public ConfigurationAdapter getAdapter() { - return this.adapter; - } - @Override public LuckPermsPlugin getPlugin() { return this.plugin; diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index 410ff2017..f5c37f9ba 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -373,7 +373,7 @@ public final class ConfigKeys { * The default assignments being applied by the plugin */ public static final ConfigKey> DEFAULT_ASSIGNMENTS = CustomKey.of(c -> { - return c.getObjectList("default-assignments", ImmutableList.of()).stream().map(name -> { + return c.getKeys("default-assignments", ImmutableList.of()).stream().map(name -> { String hasTrue = c.getString("default-assignments." + name + ".if.has-true", null); String hasFalse = c.getString("default-assignments." + name + ".if.has-false", null); String lacks = c.getString("default-assignments." + name + ".if.lacks", null); diff --git a/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurationAdapter.java b/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurationAdapter.java index 8a23cf045..6e71f6a8d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurationAdapter.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurationAdapter.java @@ -44,7 +44,7 @@ public interface ConfigurationAdapter { List getList(String path, List def); - List getObjectList(String path, List def); + List getKeys(String path, List def); Map getMap(String path, Map def); diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java b/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java index 7bd157655..88c98831e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java @@ -38,6 +38,7 @@ import java.io.BufferedReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.EnumMap; import java.util.Map; public class LocaleManager { @@ -71,8 +72,8 @@ public class LocaleManager { @SuppressWarnings("unchecked") public void loadFromFile(Path file) throws Exception { try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { - ImmutableMap.Builder messages = ImmutableMap.builder(); - ImmutableMap.Builder commands = ImmutableMap.builder(); + EnumMap messages = new EnumMap<>(Message.class); + EnumMap commands = new EnumMap<>(CommandSpec.class); Map data = (Map) new Yaml().load(reader); for (Map.Entry entry : data.entrySet()) { @@ -124,20 +125,11 @@ public class LocaleManager { } } - this.messages = messages.build(); - this.commands = commands.build(); + this.messages = ImmutableMap.copyOf(messages); + this.commands = ImmutableMap.copyOf(commands); } } - /** - * Gets the size of loaded translations - * - * @return the size of the loaded translations - */ - public int getSize() { - return this.messages.size() + this.commands.size(); - } - /** * Gets a translation for a given message key * diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/command/Argument.java b/common/src/main/java/me/lucko/luckperms/common/locale/command/Argument.java index d4d6962b4..16b4701fd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/command/Argument.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/command/Argument.java @@ -27,6 +27,11 @@ package me.lucko.luckperms.common.locale.command; import com.google.common.collect.ImmutableList; +import me.lucko.luckperms.common.locale.LocaleManager; +import me.lucko.luckperms.common.locale.message.Message; + +import javax.annotation.Nullable; + public class Argument { public static Argument create(String name, boolean required, String description) { return new Argument(name, required, description); @@ -46,8 +51,8 @@ public class Argument { this.description = description; } - public String asPrettyString() { - return this.required ? "&8<&7" + this.name + "&8>" : "&8[&7" + this.name + "&8]"; + public String asPrettyString(@Nullable LocaleManager localeManager) { + return (this.required ? Message.REQUIRED_ARGUMENT : Message.OPTIONAL_ARGUMENT).asString(localeManager, this.name); } public String getName() { diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java b/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java index a8165c79f..53f165a15 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java @@ -25,11 +25,13 @@ package me.lucko.luckperms.common.locale.message; -import me.lucko.luckperms.common.command.utils.MessageUtils; +import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.utils.TextUtils; +import net.kyori.text.TextComponent; + import javax.annotation.Nullable; /** @@ -65,7 +67,7 @@ public enum Message { "{PREFIX}&3LOG &3&l> &f{}", false ), - VERBOSE_LOG("&3VB &3&l> {}", true), + VERBOSE_LOG("&3VB &3&l> &a{}&7 - &a{}&7 - {}{}", true), EXPORT_LOG("&3EXPORT &3&l> &f{}", true), EXPORT_LOG_PROGRESS("&3EXPORT &3&l> &7{}", true), MIGRATION_LOG("&3MIGRATION &7[&3{}&7] &3&l> &f{}", true), @@ -78,6 +80,19 @@ public enum Message { COMMAND_NOT_RECOGNISED("&cCommand not recognised.", true), COMMAND_NO_PERMISSION("&cYou do not have permission to use this command!", true), + MAIN_COMMAND_USAGE_HEADER("&b{} Sub Commands: &7({} ...)", true), + COMMAND_USAGE_ARGUMENT_JOIN("&3 - &7", false), + COMMAND_USAGE_BRIEF("&3> &a{}{}", false), + COMMAND_USAGE_DETAILED_HEADER( + "{PREFIX}&3&lCommand Usage &3- &b{}" + "\n" + + "{PREFIX}&b> &7{}", + false + ), + COMMAND_USAGE_DETAILED_ARGS_HEADER("&3Arguments:", true), + COMMAND_USAGE_DETAILED_ARG("&b- {}&3 -> &7{}", true), + REQUIRED_ARGUMENT("&8<&7{}&8>", false), + OPTIONAL_ARGUMENT("&8[&7{}&8]", false), + /* * Loading / Saving @@ -180,6 +195,15 @@ public enum Message { "{PREFIX}&f- {}", false ), + + INFO_STORAGE( + "{PREFIX}&f- &bStorage:" + "\n" + + "{PREFIX}&f- &3Type: &f{}", + false + ), + + INFO_STORAGE_META("&f- &3{}: {}", true), + INFO_MIDDLE( "{PREFIX}&f- &bMessaging: &f{}" + "\n" + "{PREFIX}&f- &bInstance:" + "\n" + @@ -326,6 +350,8 @@ public enum Message { INFO_PARENT_HEADER("&f- &aParent Groups:", true), INFO_TEMP_PARENT_HEADER("&f- &aTemporary Parent Groups:", true), + INFO_PARENT_ENTRY("&f- &3> &f{}{}", true), + INFO_PARENT_ENTRY_EXPIRY("&f- &2- expires in {}", true), USER_REMOVEGROUP_ERROR_PRIMARY("&aYou cannot remove a user from their primary group.", true), USER_PRIMARYGROUP_SUCCESS("&b{}&a's primary group was set to &b{}&a.", true), USER_PRIMARYGROUP_WARN_OPTION("&aWarning: The primary group calculation method being used by this server &7({}) &amay not reflect this change.", true), @@ -433,19 +459,6 @@ public enum Message { IMPORT_END_ERROR_CONTENT("&b(Import) &b-> &c{}", true), IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", true); - public static final Object SKIP_ELEMENT = new Object(); - - private static String format(String s, Object... objects) { - for (int i = 0; i < objects.length; i++) { - Object o = objects[i]; - - if (o != SKIP_ELEMENT) { - s = s.replace("{" + i + "}", String.valueOf(o)); - } - } - return s; - } - private final String message; private final boolean showPrefix; @@ -459,31 +472,67 @@ public enum Message { return this.message; } - public String asString(@Nullable LocaleManager localeManager, Object... objects) { + private String getTranslatedMessage(@Nullable LocaleManager localeManager) { String prefix = null; if (localeManager != null) { - prefix = localeManager.getTranslation(PREFIX); + prefix = localeManager.getTranslation(this); } if (prefix == null) { - prefix = PREFIX.getMessage(); + prefix = this.getMessage(); } + return prefix; + } - String s = null; - if (localeManager != null) { - s = localeManager.getTranslation(this); - } - if (s == null) { - s = this.message; - } + private String format(@Nullable LocaleManager localeManager, Object... objects) { + String prefix = PREFIX.getTranslatedMessage(localeManager); + String msg = format( + this.getTranslatedMessage(localeManager) + .replace("{PREFIX}", prefix) + .replace("\\n", "\n"), + objects + ); + return this.showPrefix ? prefix + msg : msg; + } - s = format(s.replace("{PREFIX}", prefix).replace("\\n", "\n"), objects); - return MessageUtils.color(this.showPrefix ? prefix + s : s); + public String asString(@Nullable LocaleManager localeManager, Object... objects) { + return colorize(format(localeManager, objects)); + } + + public TextComponent asComponent(@Nullable LocaleManager localeManager, Object... objects) { + return TextUtils.fromLegacy(format(localeManager, objects), CommandManager.AMPERSAND_CHAR); } public void send(Sender sender, Object... objects) { sender.sendMessage(asString(sender.getPlatform().getLocaleManager(), objects)); } + private static String format(String s, Object... objects) { + for (int i = 0; i < objects.length; i++) { + Object o = objects[i]; + s = s.replace("{" + i + "}", String.valueOf(o)); + } + return s; + } + + /** + * Colorizes a message. + * + * @param s the message to colorize + * @return a colored message + */ + public static String colorize(String s) { + char[] b = s.toCharArray(); + + for (int i = 0; i < b.length - 1; ++i) { + if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) { + b[i] = 167; + b[i + 1] = Character.toLowerCase(b[i + 1]); + } + } + + return new String(b); + } + /** * Prints this Message enum in a yml format, for reading by the locale manager * @param args not needed diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/AbstractLuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/AbstractLuckPermsPlugin.java index 1fd73992f..a23e41c31 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/AbstractLuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/AbstractLuckPermsPlugin.java @@ -32,7 +32,6 @@ import me.lucko.luckperms.common.api.LuckPermsApiProvider; import me.lucko.luckperms.common.buffers.BufferedRequest; import me.lucko.luckperms.common.buffers.UpdateTaskBuffer; import me.lucko.luckperms.common.calculators.CalculatorFactory; -import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.config.AbstractConfiguration; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.config.LuckPermsConfiguration; @@ -44,6 +43,7 @@ import me.lucko.luckperms.common.event.AbstractEventBus; import me.lucko.luckperms.common.event.EventFactory; import me.lucko.luckperms.common.inheritance.InheritanceHandler; import me.lucko.luckperms.common.locale.LocaleManager; +import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.messaging.InternalMessagingService; import me.lucko.luckperms.common.messaging.MessagingFactory; import me.lucko.luckperms.common.plugin.logging.PluginLogger; @@ -318,9 +318,9 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin { } private void displayBanner(Sender sender) { - sender.sendMessage(MessageUtils.color("&b &3 __ ")); - sender.sendMessage(MessageUtils.color("&b | &3|__) " + "&2LuckPerms &bv" + getBootstrap().getVersion())); - sender.sendMessage(MessageUtils.color("&b |___ &3| " + "&8Running on " + getBootstrap().getType().getFriendlyName() + " - " + getBootstrap().getServerBrand())); + sender.sendMessage(Message.colorize("&b &3 __ ")); + sender.sendMessage(Message.colorize("&b | &3|__) " + "&2LuckPerms &bv" + getBootstrap().getVersion())); + sender.sendMessage(Message.colorize("&b |___ &3| " + "&8Running on " + getBootstrap().getType().getFriendlyName() + " - " + getBootstrap().getServerBrand())); sender.sendMessage(""); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java index f86e0aeff..4cb4c115f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java @@ -242,7 +242,7 @@ public interface LuckPermsPlugin { */ Sender getConsoleSender(); - default List getExtraCommands() { + default List> getExtraCommands() { return Collections.emptyList(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/treeview/ImmutableTreeNode.java b/common/src/main/java/me/lucko/luckperms/common/treeview/ImmutableTreeNode.java index ffe696005..8041b649c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/treeview/ImmutableTreeNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/treeview/ImmutableTreeNode.java @@ -86,16 +86,17 @@ public class ImmutableTreeNode implements Comparable { List> results = new ArrayList<>(); for (Map.Entry node : this.children.entrySet()) { + String value = node.getKey(); // add self - results.add(Maps.immutableEntry(0, node.getKey())); + results.add(Maps.immutableEntry(0, value)); // add child nodes, incrementing their level & appending their prefix node results.addAll(node.getValue().getNodeEndings().stream() .map(e -> Maps.immutableEntry( e.getKey() + 1, // increment level // add this node's key infront of the child value - node.getKey() + "." + e.getValue()) + value + "." + e.getValue()) ) .collect(Collectors.toList())); } diff --git a/common/src/main/java/me/lucko/luckperms/common/treeview/PermissionRegistry.java b/common/src/main/java/me/lucko/luckperms/common/treeview/PermissionRegistry.java index 7d2e9925e..154becf20 100644 --- a/common/src/main/java/me/lucko/luckperms/common/treeview/PermissionRegistry.java +++ b/common/src/main/java/me/lucko/luckperms/common/treeview/PermissionRegistry.java @@ -26,17 +26,13 @@ package me.lucko.luckperms.common.treeview; import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter; import me.lucko.luckperms.common.utils.RepeatingTask; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Queue; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -50,16 +46,12 @@ public class PermissionRegistry extends RepeatingTask { // the root node in the tree private final TreeNode rootNode; - // the known permissions already in the vault - private final Set knownPermissions; - // a queue of permission strings to be processed by the tree private final Queue queue; public PermissionRegistry(SchedulerAdapter scheduler) { super(scheduler, 1, TimeUnit.SECONDS); this.rootNode = new TreeNode(); - this.knownPermissions = ConcurrentHashMap.newKeySet(3000); this.queue = new ConcurrentLinkedQueue<>(); } @@ -70,15 +62,7 @@ public class PermissionRegistry extends RepeatingTask { @Override protected void tick() { for (String e; (e = this.queue.poll()) != null; ) { - try { - String s = e.toLowerCase(); - // only attempt an insert if we're not seen this permission before - if (this.knownPermissions.add(s)) { - insert(s); - } - } catch (Exception ex) { - ex.printStackTrace(); - } + insert(e); } } @@ -89,12 +73,12 @@ public class PermissionRegistry extends RepeatingTask { this.queue.offer(permission); } - public void offerAll(Collection permissions) { - this.queue.addAll(permissions); - } - - public Set getKnownPermissions() { - return ImmutableSet.copyOf(this.knownPermissions); + public void insert(String permission) { + try { + doInsert(permission); + } catch (Exception ex) { + ex.printStackTrace(); + } } public List rootAsList() { @@ -105,14 +89,17 @@ public class PermissionRegistry extends RepeatingTask { return this.rootNode.getDeepSize(); } - private void insert(String permission) { + private void doInsert(String permission) { // split the permission up into parts List parts = DOT_SPLIT.splitToList(permission); // insert the permission into the node structure TreeNode current = this.rootNode; for (String part : parts) { - current = current.resolve(part); + current = current.tryInsert(part); + if (current == null) { + return; + } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/treeview/TreeNode.java b/common/src/main/java/me/lucko/luckperms/common/treeview/TreeNode.java index 3ef500cdf..209e7f68a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/treeview/TreeNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/treeview/TreeNode.java @@ -31,12 +31,53 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nullable; + /** * Represents one "branch" or "level" of the node tree */ public class TreeNode { + + private static boolean allowInsert(TreeNode node) { + /* + We enforce a limit of the size of the node tree to ensure memory + usage remains sane. some plugins check for "dynamic" permissions (cc: griefprevention) + which means this tree can grow to very large sizes and use tons of memory + + the rules for limiting the tree size are designed to ensure the system is + still useful, but that unnecessarily large amounts of data aren't stored + + the rules are: + 1. there can be an unlimited number of root nodes e.g. (luckperms, minecraft) + 2. each root node can then have up to 500 child nodes + 3. *but*, each root node can have an unlimited number of 2nd level nodes (e.g. luckperms.user) + this takes priority over #2 + */ + + if (node.level == 2) { + // only allow up to a deep size of 500 + return node.parent.getDeepSize() < 500; + } + return true; + } + private Map children = null; + private final int level; + private final TreeNode parent; + + private int cachedDeepSize = Integer.MIN_VALUE; + + public TreeNode() { + this.level = 0; + this.parent = null; + } + + TreeNode(TreeNode parent) { + this.level = parent.level + 1; + this.parent = parent; + } + // lazy init private synchronized Map getChildMap() { if (this.children == null) { @@ -45,8 +86,35 @@ public class TreeNode { return this.children; } - public TreeNode resolve(String s) { - return getChildMap().computeIfAbsent(s, x -> new TreeNode()); + @Nullable + public TreeNode tryInsert(String s) { + Map 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 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> getChildren() { @@ -54,10 +122,14 @@ public class TreeNode { } public int getDeepSize() { + if (this.cachedDeepSize != Integer.MIN_VALUE) { + return this.cachedDeepSize; + } + if (this.children == null) { - return 1; + return (this.cachedDeepSize = 1); } else { - return this.children.values().stream().mapToInt(TreeNode::getDeepSize).sum(); + return (this.cachedDeepSize = this.children.values().stream().mapToInt(TreeNode::getDeepSize).sum()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java index 21837b0b7..b6a13f963 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java @@ -136,20 +136,29 @@ public class VerboseListener { } private void sendNotification(CheckData data) { - String msg = "&a" + data.getCheckTarget() + "&7 - &a" + data.getPermission() + "&7 - " + getTristateColor(data.getResult()) + data.getResult().name().toLowerCase(); if (this.notifiedSender.isConsole()) { // just send as a raw message - Message.VERBOSE_LOG.send(this.notifiedSender, msg); + Message.VERBOSE_LOG.send(this.notifiedSender, + data.getCheckTarget(), + data.getPermission(), + getTristateColor(data.getResult()), + data.getResult().name().toLowerCase() + ); return; } // form a hoverevent from the check trace - TextComponent textComponent = TextUtils.fromLegacy(Message.VERBOSE_LOG.asString(this.notifiedSender.getPlatform().getLocaleManager(), msg)); + TextComponent textComponent = Message.VERBOSE_LOG.asComponent(this.notifiedSender.getPlatform().getLocaleManager(), + data.getCheckTarget(), + data.getPermission(), + getTristateColor(data.getResult()), + data.getResult().name().toLowerCase() + ); // build the text List hover = new ArrayList<>(); hover.add("&bOrigin: &2" + data.getCheckOrigin().name()); - hover.add("&bContext: &r" + MessageUtils.contextSetToString(data.getCheckContext())); + hover.add("&bContext: &r" + MessageUtils.contextSetToString(this.notifiedSender.getPlatform().getLocaleManager(), data.getCheckContext())); hover.add("&bTrace: &r"); Consumer printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str)); diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitConfigAdapter.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitConfigAdapter.java index 73e099207..a3aa69ac4 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitConfigAdapter.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitConfigAdapter.java @@ -77,7 +77,7 @@ public class NukkitConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public List getObjectList(String path, List def) { + public List getKeys(String path, List def) { ConfigSection section = this.configuration.getSection(path); if (section == null) { return def; diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/model/server/LPPermissionMap.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/model/server/LPPermissionMap.java index 65525ac8f..00c5887e5 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/model/server/LPPermissionMap.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/model/server/LPPermissionMap.java @@ -94,7 +94,7 @@ public final class LPPermissionMap extends ForwardingMap { @Override public Permission put(@Nonnull String key, @Nonnull Permission value) { - this.plugin.getPermissionRegistry().offer(key); + this.plugin.getPermissionRegistry().insert(key); Permission ret = super.put(key, value); update(); return ret; @@ -102,14 +102,14 @@ public final class LPPermissionMap extends ForwardingMap { @Override public void putAll(@Nonnull Map m) { - this.plugin.getPermissionRegistry().offerAll(m.keySet()); - super.putAll(m); - update(); + for (Map.Entry ent : m.entrySet()) { + put(ent.getKey(), ent.getValue()); + } } @Override public Permission putIfAbsent(String key, Permission value) { - this.plugin.getPermissionRegistry().offer(key); + this.plugin.getPermissionRegistry().insert(key); Permission ret = super.putIfAbsent(key, value); update(); return ret; diff --git a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/DescriptionBuilder.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/DescriptionBuilder.java index ed67af593..c283c30e5 100644 --- a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/DescriptionBuilder.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/DescriptionBuilder.java @@ -94,8 +94,6 @@ public final class DescriptionBuilder implements PermissionDescription.Builder { roleSubject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue()); } - this.service.getPlugin().getPermissionRegistry().offer(this.id); - // null stuff so this instance can be reused this.roles.clear(); this.id = null; diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/DescriptionBuilder.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/DescriptionBuilder.java index 881435dc7..51594bb26 100644 --- a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/DescriptionBuilder.java +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/DescriptionBuilder.java @@ -94,8 +94,6 @@ public final class DescriptionBuilder implements PermissionDescription.Builder { roleSubject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue()); } - this.service.getPlugin().getPermissionRegistry().offer(this.id); - // null stuff so this instance can be reused this.roles.clear(); this.id = null; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index f37075cae..aa5b9fedc 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -166,7 +166,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin { // before registering our permission service, copy any existing permission descriptions PermissionRegistry permissionRegistry = getPermissionRegistry(); this.bootstrap.getGame().getServiceManager().provide(PermissionService.class) - .ifPresent(ps -> ps.getDescriptions().stream().map(PermissionDescription::getId).forEach(permissionRegistry::offer)); + .ifPresent(ps -> ps.getDescriptions().stream().map(PermissionDescription::getId).forEach(permissionRegistry::insert)); if (this.bootstrap.getGame().getPluginManager().getPlugin("permissionsex").isPresent()) { getLogger().warn("Detected PermissionsEx - assuming it's loaded for migration."); @@ -268,7 +268,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin { } @Override - public List getExtraCommands() { + public List> getExtraCommands() { return Collections.singletonList(new SpongeMainCommand(this)); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfigAdapter.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfigAdapter.java index 4ba20574c..b9e12124a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfigAdapter.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfigAdapter.java @@ -99,7 +99,7 @@ public class SpongeConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public List getObjectList(String path, List def) { + public List getKeys(String path, List def) { ConfigurationNode node = resolvePath(path); if (node.isVirtual()) { return def; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java index 5ce24009f..c1c64e97d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java @@ -53,7 +53,7 @@ public class OptionClear extends SubCommand { MessageUtils.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a."); } else { subjectData.clearOptions(contextSet); - MessageUtils.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeCommandUtils.contextToString(contextSet)); + MessageUtils.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager())); } return CommandResult.SUCCESS; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java index 9f0204686..5854982e5 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java @@ -60,7 +60,7 @@ public class OptionInfo extends SubCommand { } for (Map.Entry> e : options.entrySet()) { - MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.optionsToString(e.getValue())); + MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey(), plugin.getLocaleManager()) + "\n" + SpongeCommandUtils.optionsToString(e.getValue())); } } else { @@ -71,7 +71,7 @@ public class OptionInfo extends SubCommand { } 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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java index 39b71e45e..afadd69b9 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java @@ -52,7 +52,7 @@ public class OptionSet extends SubCommand { ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args); if (subjectData.setOption(contextSet, key, value).join()) { - MessageUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet)); + MessageUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager())); } else { MessageUtils.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?"); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java index 131e3b378..7f98c800d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java @@ -51,7 +51,7 @@ public class OptionUnset extends SubCommand { ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(1, args); if (subjectData.unsetOption(contextSet, key).join()) { - MessageUtils.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet)); + MessageUtils.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager())); } else { MessageUtils.sendPluginMessage(sender, "Unable to unset option. Are you sure the Subject has it set?"); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java index cb20e8511..f0ea829d4 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java @@ -70,7 +70,7 @@ public class ParentAdd extends SubCommand { if (subjectData.addParent(contextSet, subject.toReference()).join()) { MessageUtils.sendPluginMessage(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() + - "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet)); + "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager())); } else { MessageUtils.sendPluginMessage(sender, "Unable to add parent. Does the Subject already have it added?"); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java index 9b4b1ebfd..ef9dc1c37 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java @@ -53,7 +53,7 @@ public class ParentClear extends SubCommand { MessageUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a."); } else { subjectData.clearParents(contextSet); - MessageUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet)); + MessageUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager())); } return CommandResult.SUCCESS; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java index eec1246e0..92ff30646 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java @@ -61,7 +61,7 @@ public class ParentInfo extends SubCommand { } for (Map.Entry> e : parents.entrySet()) { - MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue())); + MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey(), plugin.getLocaleManager()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue())); } } else { @@ -72,7 +72,7 @@ public class ParentInfo extends SubCommand { } 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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java index 03ee51fbe..b846182ee 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java @@ -70,7 +70,7 @@ public class ParentRemove extends SubCommand { if (subjectData.removeParent(contextSet, subject.toReference()).join()) { MessageUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() + - "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet)); + "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager())); } else { MessageUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?"); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java index 26d5f62c5..adc9f2aab 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java @@ -53,7 +53,7 @@ public class PermissionClear extends SubCommand { MessageUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a."); } else { subjectData.clearPermissions(contextSet); - MessageUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet)); + MessageUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager())); } return CommandResult.SUCCESS; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java index 0f04a6158..f8afd7354 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java @@ -60,7 +60,7 @@ public class PermissionInfo extends SubCommand { } for (Map.Entry> e : permissions.entrySet()) { - MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue())); + MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey(), plugin.getLocaleManager()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue())); } } else { @@ -71,7 +71,7 @@ public class PermissionInfo extends SubCommand { } 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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java index 8bfa98e05..4ea211e99 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java @@ -54,7 +54,7 @@ public class PermissionSet extends SubCommand { ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args); if (subjectData.setPermission(contextSet, node, tristate).join()) { - MessageUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeCommandUtils.contextToString(contextSet)); + MessageUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager())); } else { MessageUtils.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?"); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeCommandUtils.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeCommandUtils.java index 937ae0aa3..38626e588 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeCommandUtils.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeCommandUtils.java @@ -29,6 +29,7 @@ import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; +import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.sponge.service.model.LPSubjectReference; import java.util.List; @@ -85,8 +86,8 @@ public final class SpongeCommandUtils { return sb.toString(); } - public static String contextToString(ContextSet set) { - return MessageUtils.contextSetToString(set); + public static String contextToString(ContextSet set, LocaleManager localeManager) { + return MessageUtils.contextSetToString(localeManager, set); } private SpongeCommandUtils() {} diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java index 6d1a6b4ef..6c167be98 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java @@ -199,7 +199,7 @@ public class LuckPermsService implements LPPermissionService { public LPPermissionDescription registerPermissionDescription(String id, Text description, PluginContainer owner) { SimplePermissionDescription desc = new SimplePermissionDescription(this, id, description, owner); this.permissionDescriptions.put(id, desc); - this.plugin.getPermissionRegistry().offer(id); + this.plugin.getPermissionRegistry().insert(id); return desc; } @@ -214,7 +214,7 @@ public class LuckPermsService implements LPPermissionService { Map descriptions = new HashMap<>(this.permissionDescriptions); // collect known values from the permission vault - for (String perm : this.plugin.getPermissionRegistry().getKnownPermissions()) { + for (String perm : this.plugin.getPermissionRegistry().rootAsList()) { // don't override plugin defined values if (!descriptions.containsKey(perm)) { descriptions.put(perm, new SimplePermissionDescription(this, perm, null, null));