Convert to text components and implement new translation system

This commit is contained in:
Luck 2020-10-14 12:26:09 +01:00 committed by GitHub
parent 63878166db
commit 4811129ab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
162 changed files with 6181 additions and 3729 deletions

View File

@ -54,4 +54,17 @@ public interface InheritanceOriginMetadata {
*/
PermissionHolder.@NonNull Identifier getOrigin();
/**
* Gets whether the associated node was inherited from another holder.
*
* <p>In other terms, it returns whether the origin is not equal to the given holder.</p>
*
* @param holder the holder defining the node
* @return if true the node was inherited, false if it was defined by the same holder
* @since 5.3
*/
default boolean wasInherited(PermissionHolder.@NonNull Identifier holder) {
return !holder.equals(getOrigin());
}
}

View File

@ -11,7 +11,7 @@ dependencies {
compile project(':common')
compileOnly 'com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT'
compileOnly 'net.kyori:text-adapter-bukkit:3.0.5'
compileOnly 'me.lucko:adventure-platform-bukkit:4.0.0'
compileOnly 'me.lucko:commodore:1.7'
compileOnly('net.milkbowl.vault:VaultAPI:1.6') {
exclude(module: 'bukkit')
@ -50,7 +50,7 @@ shadowJar {
include(dependency('me.lucko.luckperms:.*'))
}
relocate 'net.kyori.text', 'me.lucko.luckperms.lib.text'
relocate 'net.kyori.adventure', 'me.lucko.luckperms.lib.adventure'
relocate 'net.kyori.event', 'me.lucko.luckperms.lib.eventbus'
relocate 'com.github.benmanes.caffeine', 'me.lucko.luckperms.lib.caffeine'
relocate 'okio', 'me.lucko.luckperms.lib.okio'

View File

@ -27,10 +27,9 @@ package me.lucko.luckperms.bukkit;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.sender.SenderFactory;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.Component;
import net.kyori.text.adapter.bukkit.TextAdapter;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.luckperms.api.util.Tristate;
import org.bukkit.command.CommandSender;
@ -41,8 +40,11 @@ import org.bukkit.entity.Player;
import java.util.UUID;
public class BukkitSenderFactory extends SenderFactory<LPBukkitPlugin, CommandSender> {
private final BukkitAudiences audiences;
public BukkitSenderFactory(LPBukkitPlugin plugin) {
super(plugin);
this.audiences = BukkitAudiences.create(plugin.getBootstrap());
}
@Override
@ -61,27 +63,14 @@ public class BukkitSenderFactory extends SenderFactory<LPBukkitPlugin, CommandSe
return Sender.CONSOLE_UUID;
}
@Override
protected void sendMessage(CommandSender sender, String s) {
// we can safely send async for players and the console
if (sender instanceof Player || sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender) {
sender.sendMessage(s);
return;
}
// otherwise, send the message sync
getPlugin().getBootstrap().getScheduler().executeSync(new SyncMessengerAgent(sender, s));
}
@Override
protected void sendMessage(CommandSender sender, Component message) {
if (sender instanceof Player) {
TextAdapter.sendComponent(sender, message);
return;
// we can safely send async for players and the console - otherwise, send it sync
if (sender instanceof Player || sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender) {
this.audiences.sender(sender).sendMessage(message);
} else {
getPlugin().getBootstrap().getScheduler().executeSync(() -> sendMessage(sender, message));
}
// Fallback to legacy format
sendMessage(sender, TextUtils.toLegacy(message));
}
@Override
@ -105,19 +94,9 @@ public class BukkitSenderFactory extends SenderFactory<LPBukkitPlugin, CommandSe
getPlugin().getBootstrap().getServer().dispatchCommand(sender, command);
}
private static final class SyncMessengerAgent implements Runnable {
private final CommandSender sender;
private final String message;
private SyncMessengerAgent(CommandSender sender, String message) {
this.sender = sender;
this.message = message;
}
@Override
public void run() {
this.sender.sendMessage(this.message);
}
@Override
public void close() {
super.close();
this.audiences.close();
}
}

View File

@ -117,7 +117,8 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
@Override
protected Set<Dependency> getGlobalDependencies() {
Set<Dependency> dependencies = super.getGlobalDependencies();
dependencies.add(Dependency.TEXT_ADAPTER_BUKKIT);
dependencies.add(Dependency.ADVENTURE_PLATFORM);
dependencies.add(Dependency.ADVENTURE_PLATFORM_BUKKIT);
if (isBrigadierSupported()) {
dependencies.add(Dependency.COMMODORE);
}

View File

@ -29,10 +29,15 @@ import me.lucko.luckperms.bukkit.LPBukkitPlugin;
import me.lucko.luckperms.bukkit.inject.permissible.LuckPermsPermissible;
import me.lucko.luckperms.bukkit.inject.permissible.PermissibleInjector;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.locale.TranslationManager;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.translation.GlobalTranslator;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -122,7 +127,9 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
// deny the connection
this.deniedAsyncLogin.add(e.getUniqueId());
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager()));
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), TranslationManager.DEFAULT_LOCALE);
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(e.getUniqueId(), e.getName(), null);
}
}
@ -169,7 +176,9 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
if (this.detectedCraftBukkitOfflineMode) {
printCraftBukkitOfflineModeError();
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_STATE_ERROR_CB_OFFLINE_MODE.asString(this.plugin.getLocaleManager()));
Component reason = GlobalTranslator.render(Message.LOADING_STATE_ERROR_CB_OFFLINE_MODE.build(), TranslationManager.parseLocale(player.getLocale(), TranslationManager.DEFAULT_LOCALE));
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
return;
}
@ -179,7 +188,8 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
" - denying login.");
}
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager()));
Component reason = GlobalTranslator.render(Message.LOADING_STATE_ERROR.build(), TranslationManager.parseLocale(player.getLocale(), TranslationManager.DEFAULT_LOCALE));
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
return;
}
@ -197,7 +207,8 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
player.getUniqueId() + " - " + player.getName() + " - denying login.");
t.printStackTrace();
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_SETUP_ERROR.asString(this.plugin.getLocaleManager()));
Component reason = GlobalTranslator.render(Message.LOADING_SETUP_ERROR.build(), TranslationManager.parseLocale(player.getLocale(), TranslationManager.DEFAULT_LOCALE));
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
return;
}

View File

@ -27,7 +27,7 @@ package me.lucko.luckperms.bukkit.listeners;
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
@ -75,7 +75,7 @@ public class BukkitPlatformListener implements Listener {
if (OP_COMMAND_PATTERN.matcher(cmdLine).matches()) {
event.setCancelled(true);
sender.sendMessage(Message.OP_DISABLED.asString(this.plugin.getLocaleManager()));
Message.OP_DISABLED.send(this.plugin.getSenderFactory().wrap(sender));
}
}

View File

@ -34,11 +34,10 @@ import de.bananaco.bpermissions.api.WorldManager;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
@ -78,8 +77,8 @@ public class MigrationBPermissions extends ChildCommand<Object> {
}
}
public MigrationBPermissions(LocaleManager locale) {
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "bpermissions", CommandPermission.MIGRATION, Predicates.alwaysFalse());
public MigrationBPermissions() {
super(CommandSpec.MIGRATION_COMMAND, "bpermissions", CommandPermission.MIGRATION, Predicates.alwaysFalse());
}
@Override

View File

@ -28,11 +28,10 @@ package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.UserIdentifier;
@ -70,8 +69,8 @@ import java.util.function.Function;
import java.util.stream.Collectors;
public class MigrationGroupManager extends ChildCommand<Object> {
public MigrationGroupManager(LocaleManager locale) {
super(CommandSpec.MIGRATION_GROUPMANAGER.localize(locale), "groupmanager", CommandPermission.MIGRATION, Predicates.is(0));
public MigrationGroupManager() {
super(CommandSpec.MIGRATION_GROUPMANAGER, "groupmanager", CommandPermission.MIGRATION, Predicates.is(0));
}
@Override

View File

@ -30,11 +30,10 @@ import com.platymuus.bukkit.permissions.PermissionsPlugin;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
@ -58,8 +57,8 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public class MigrationPermissionsBukkit extends ChildCommand<Object> {
public MigrationPermissionsBukkit(LocaleManager locale) {
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "permissionsbukkit", CommandPermission.MIGRATION, Predicates.alwaysFalse());
public MigrationPermissionsBukkit() {
super(CommandSpec.MIGRATION_COMMAND, "permissionsbukkit", CommandPermission.MIGRATION, Predicates.alwaysFalse());
}
@Override

View File

@ -30,11 +30,10 @@ import com.google.common.base.Strings;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.Track;
@ -103,8 +102,8 @@ public class MigrationPermissionsEx extends ChildCommand<Object> {
}
}
public MigrationPermissionsEx(LocaleManager locale) {
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "permissionsex", CommandPermission.MIGRATION, Predicates.alwaysFalse());
public MigrationPermissionsEx() {
super(CommandSpec.MIGRATION_COMMAND, "permissionsex", CommandPermission.MIGRATION, Predicates.alwaysFalse());
}
@Override

View File

@ -36,12 +36,11 @@ import com.zaxxer.hikari.HikariDataSource;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.manager.group.GroupManager;
@ -80,8 +79,8 @@ import java.util.concurrent.atomic.AtomicInteger;
// Only supports the latest versions of the PP API. (it seems to change randomly almost every release)
public class MigrationPowerfulPerms extends ChildCommand<Object> {
public MigrationPowerfulPerms(LocaleManager locale) {
super(CommandSpec.MIGRATION_POWERFULPERMS.localize(locale), "powerfulperms", CommandPermission.MIGRATION, Predicates.not(5));
public MigrationPowerfulPerms() {
super(CommandSpec.MIGRATION_POWERFULPERMS, "powerfulperms", CommandPermission.MIGRATION, Predicates.not(5));
}
@Override

View File

@ -28,11 +28,10 @@ package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.Track;
@ -70,8 +69,8 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public class MigrationZPermissions extends ChildCommand<Object> {
public MigrationZPermissions(LocaleManager locale) {
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "zpermissions", CommandPermission.MIGRATION, Predicates.alwaysFalse());
public MigrationZPermissions() {
super(CommandSpec.MIGRATION_COMMAND, "zpermissions", CommandPermission.MIGRATION, Predicates.alwaysFalse());
}
@Override

View File

@ -6,7 +6,7 @@ dependencies {
compile project(':common')
compileOnly 'net.md-5:bungeecord-api:1.15-SNAPSHOT'
compileOnly 'net.kyori:text-adapter-bungeecord:3.0.4'
compileOnly 'me.lucko:adventure-platform-bungeecord:4.0.0'
compileOnly 'com.imaginarycode.minecraft:RedisBungee:0.4'
// migration plugins
@ -36,7 +36,7 @@ shadowJar {
include(dependency('me.lucko.luckperms:.*'))
}
relocate 'net.kyori.text', 'me.lucko.luckperms.lib.text'
relocate 'net.kyori.adventure', 'me.lucko.luckperms.lib.adventure'
relocate 'net.kyori.event', 'me.lucko.luckperms.lib.eventbus'
relocate 'com.github.benmanes.caffeine', 'me.lucko.luckperms.lib.caffeine'
relocate 'okio', 'me.lucko.luckperms.lib.okio'

View File

@ -28,10 +28,9 @@ package me.lucko.luckperms.bungee;
import me.lucko.luckperms.bungee.event.TristateCheckEvent;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.sender.SenderFactory;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.Component;
import net.kyori.text.adapter.bungeecord.TextAdapter;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.kyori.adventure.text.Component;
import net.luckperms.api.util.Tristate;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -39,8 +38,11 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.UUID;
public class BungeeSenderFactory extends SenderFactory<LPBungeePlugin, CommandSender> {
private final BungeeAudiences audiences;
public BungeeSenderFactory(LPBungeePlugin plugin) {
super(plugin);
this.audiences = BungeeAudiences.create(plugin.getBootstrap());
}
@Override
@ -59,14 +61,9 @@ public class BungeeSenderFactory extends SenderFactory<LPBungeePlugin, CommandSe
return Sender.CONSOLE_UUID;
}
@Override
protected void sendMessage(CommandSender sender, String s) {
sendMessage(sender, TextUtils.fromLegacy(s));
}
@Override
protected void sendMessage(CommandSender sender, Component message) {
TextAdapter.sendComponent(sender, message);
this.audiences.sender(sender).sendMessage(message);
}
@Override
@ -83,4 +80,10 @@ public class BungeeSenderFactory extends SenderFactory<LPBungeePlugin, CommandSe
protected void performCommand(CommandSender sender, String command) {
getPlugin().getBootstrap().getProxy().getPluginManager().dispatchCommand(sender, command);
}
@Override
public void close() {
super.close();
this.audiences.close();
}
}

View File

@ -92,7 +92,8 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
@Override
protected Set<Dependency> getGlobalDependencies() {
Set<Dependency> dependencies = super.getGlobalDependencies();
dependencies.add(Dependency.TEXT_ADAPTER_BUNGEECORD);
dependencies.add(Dependency.ADVENTURE_PLATFORM);
dependencies.add(Dependency.ADVENTURE_PLATFORM_BUNGEECORD);
return dependencies;
}

View File

@ -27,11 +27,14 @@ package me.lucko.luckperms.bungee.listeners;
import me.lucko.luckperms.bungee.LPBungeePlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.locale.TranslationManager;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
import net.md_5.bungee.api.chat.TextComponent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.kyori.adventure.translation.GlobalTranslator;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.LoginEvent;
@ -97,7 +100,8 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
// there was some error loading
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// cancel the login attempt
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager())));
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), TranslationManager.DEFAULT_LOCALE);
e.setCancelReason(BungeeComponentSerializer.get().serialize(reason));
e.setCancelled(true);
}
this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(c.getUniqueId(), c.getName(), null);
@ -128,7 +132,8 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// disconnect the user
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager())));
Component reason = GlobalTranslator.render(Message.LOADING_DATABASE_ERROR.build(), player.getLocale());
e.getPlayer().disconnect(BungeeComponentSerializer.get().serialize(reason));
} else {
// just send a message
this.plugin.getBootstrap().getProxy().getScheduler().schedule(this.plugin.getBootstrap(), () -> {
@ -136,7 +141,7 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
return;
}
player.sendMessage(TextComponent.fromLegacyText(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager())));
Message.LOADING_STATE_ERROR.send(this.plugin.getSenderFactory().wrap(player));
}, 1, TimeUnit.SECONDS);
}
}

View File

@ -28,11 +28,10 @@ package me.lucko.luckperms.bungee.migration;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.node.types.Prefix;
@ -57,8 +56,8 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
public class MigrationBungeePerms extends ChildCommand<Object> {
public MigrationBungeePerms(LocaleManager locale) {
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "bungeeperms", CommandPermission.MIGRATION, Predicates.alwaysFalse());
public MigrationBungeePerms() {
super(CommandSpec.MIGRATION_COMMAND, "bungeeperms", CommandPermission.MIGRATION, Predicates.alwaysFalse());
}
@Override

View File

@ -2,16 +2,9 @@ dependencies {
compile project(':api')
compile 'org.checkerframework:checker-qual:2.5.5'
compile('net.kyori:text-api:3.0.4') {
compile('me.lucko:adventure-api:4.0.0') {
exclude(module: 'checker-qual')
}
compile('net.kyori:text-serializer-legacy:3.0.4') {
exclude(module: 'text-api')
}
compile('net.kyori:text-serializer-gson:3.0.4') {
exclude(module: 'text-api')
exclude(module: 'gson')
}
compile('net.kyori:event-api:3.0.0') {
exclude(module: 'checker-qual')
exclude(module: 'guava')

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.common.actionlog;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.commands.log.LogNotify;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -72,12 +72,7 @@ public class LogDispatcher {
boolean shouldCancel = LogNotify.isIgnoring(this.plugin, s.getUniqueId()) || (sender != null && s.getUniqueId().equals(sender.getUniqueId()));
return !this.plugin.getEventDispatcher().dispatchLogNotify(shouldCancel, entry, origin, s);
})
.forEach(s -> Message.LOG.send(s,
entry.getSourceFriendlyString(),
Character.toString(LoggedAction.getTypeCharacter(entry.getTarget().getType())),
entry.getTargetFriendlyString(),
entry.getDescription()
));
.forEach(s -> Message.LOG.send(s, entry));
}
public void dispatch(LoggedAction entry, Sender sender) {

View File

@ -29,7 +29,7 @@ import com.google.gson.JsonObject;
import me.lucko.luckperms.common.http.AbstractHttpClient;
import me.lucko.luckperms.common.http.UnsuccessfulRequestException;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
@ -90,7 +90,7 @@ public abstract class Exporter implements Runnable {
this.includeUsers = includeUsers;
this.includeGroups = includeGroups;
this.log = new ProgressLogger(Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS, null);
this.log = new ProgressLogger(Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS);
this.log.addListener(plugin.getConsoleSender());
this.log.addListener(executor);
}
@ -238,7 +238,7 @@ public abstract class Exporter implements Runnable {
e.printStackTrace();
}
this.log.getListeners().forEach(l -> Message.LOG_EXPORT_SUCCESS.send(l, this.filePath.toFile().getAbsolutePath()));
this.log.getListeners().forEach(l -> Message.EXPORT_FILE_SUCCESS.send(l, this.filePath.toFile().getAbsolutePath()));
}
}
@ -263,12 +263,12 @@ public abstract class Exporter implements Runnable {
try {
String pasteId = this.plugin.getBytebin().postContent(bytesOut.toByteArray(), AbstractHttpClient.JSON_TYPE, false).key();
this.log.getListeners().forEach(l -> Message.EXPORT_CODE.send(l, pasteId, this.label, pasteId));
this.log.getListeners().forEach(l -> Message.EXPORT_WEB_SUCCESS.send(l, pasteId, this.label));
} catch (UnsuccessfulRequestException e) {
this.log.getListeners().forEach(l -> Message.EXPORT_HTTP_REQUEST_FAILURE.send(l, e.getResponse().code(), e.getResponse().message()));
this.log.getListeners().forEach(l -> Message.HTTP_REQUEST_FAILURE.send(l, e.getResponse().code(), e.getResponse().message()));
} catch (IOException e) {
new RuntimeException("Error uploading data to bytebin", e).printStackTrace();
this.log.getListeners().forEach(Message.EXPORT_HTTP_UNKNOWN_FAILURE::send);
this.log.getListeners().forEach(Message.HTTP_UNKNOWN_FAILURE::send);
}
}
}

View File

@ -31,7 +31,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
@ -242,7 +242,7 @@ public class Importer implements Runnable {
private void sendProgress(int processedCount, int total) {
int percent = (processedCount * 100) / total;
this.notify.forEach(s -> Message.IMPORT_PROGRESS.send(s, percent, processedCount, total, 0));
this.notify.forEach(s -> Message.IMPORT_PROGRESS.send(s, percent, processedCount, total));
}
}

View File

@ -29,7 +29,6 @@ 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.CompletionSupplier;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
@ -58,18 +57,16 @@ import me.lucko.luckperms.common.commands.track.DeleteTrack;
import me.lucko.luckperms.common.commands.track.ListTracks;
import me.lucko.luckperms.common.commands.track.TrackParentCommand;
import me.lucko.luckperms.common.commands.user.UserParentCommand;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.ImmutableCollectors;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collection;
import java.util.Collections;
@ -97,35 +94,33 @@ public class CommandManager {
public CommandManager(LuckPermsPlugin plugin) {
this.plugin = plugin;
LocaleManager locale = plugin.getLocaleManager();
this.tabCompletions = new TabCompletions(plugin);
this.mainCommands = ImmutableList.<Command<?>>builder()
.add(new UserParentCommand(locale))
.add(new GroupParentCommand(locale))
.add(new TrackParentCommand(locale))
.add(new UserParentCommand())
.add(new GroupParentCommand())
.add(new TrackParentCommand())
.addAll(plugin.getExtraCommands())
.add(new LogParentCommand(locale))
.add(new SyncCommand(locale))
.add(new InfoCommand(locale))
.add(new EditorCommand(locale))
.add(new VerboseCommand(locale))
.add(new TreeCommand(locale))
.add(new SearchCommand(locale))
.add(new CheckCommand(locale))
.add(new NetworkSyncCommand(locale))
.add(new ImportCommand(locale))
.add(new ExportCommand(locale))
.add(new ReloadConfigCommand(locale))
.add(new BulkUpdateCommand(locale))
.add(new MigrationParentCommand(locale))
.add(new ApplyEditsCommand(locale))
.add(new CreateGroup(locale))
.add(new DeleteGroup(locale))
.add(new ListGroups(locale))
.add(new CreateTrack(locale))
.add(new DeleteTrack(locale))
.add(new ListTracks(locale))
.add(new LogParentCommand())
.add(new SyncCommand())
.add(new InfoCommand())
.add(new EditorCommand())
.add(new VerboseCommand())
.add(new TreeCommand())
.add(new SearchCommand())
.add(new CheckCommand())
.add(new NetworkSyncCommand())
.add(new ImportCommand())
.add(new ExportCommand())
.add(new ReloadConfigCommand())
.add(new BulkUpdateCommand())
.add(new MigrationParentCommand())
.add(new ApplyEditsCommand())
.add(new CreateGroup())
.add(new DeleteGroup())
.add(new ListGroups())
.add(new CreateTrack())
.add(new DeleteTrack())
.add(new ListTracks())
.build()
.stream()
.collect(ImmutableCollectors.toMap(c -> c.getName().toLowerCase(), Function.identity()));
@ -160,7 +155,15 @@ public class CommandManager {
// Handle no arguments
if (arguments.isEmpty() || (arguments.size() == 1 && arguments.get(0).trim().isEmpty())) {
Message.BLANK.send(sender, "&2Running &b" + AbstractLuckPermsPlugin.getPluginName() + " v" + this.plugin.getBootstrap().getVersion() + "&2.");
sender.sendMessage(Message.prefixed(Component.text()
.color(NamedTextColor.DARK_GREEN)
.append(Component.text("Running "))
.append(Component.text(AbstractLuckPermsPlugin.getPluginName(), NamedTextColor.AQUA))
.append(Component.space())
.append(Component.text("v" + this.plugin.getBootstrap().getVersion(), NamedTextColor.AQUA))
.append(Message.FULL_STOP)
));
if (hasPermissionForAny(sender)) {
Message.VIEW_AVAILABLE_COMMANDS_PROMPT.send(sender, label);
return CommandResult.SUCCESS;
@ -232,27 +235,25 @@ public class CommandManager {
}
private void sendCommandUsage(Sender sender, String label) {
Message.BLANK.send(sender, "&2Running &b" + AbstractLuckPermsPlugin.getPluginName() + " v" + this.plugin.getBootstrap().getVersion() + "&2.");
sender.sendMessage(Message.prefixed(Component.text()
.color(NamedTextColor.DARK_GREEN)
.append(Component.text("Running "))
.append(Component.text(AbstractLuckPermsPlugin.getPluginName(), NamedTextColor.AQUA))
.append(Component.space())
.append(Component.text("v" + this.plugin.getBootstrap().getVersion(), NamedTextColor.AQUA))
.append(Message.FULL_STOP)
));
this.mainCommands.values().stream()
.filter(Command::shouldDisplay)
.filter(c -> c.isAuthorized(sender))
.forEach(c -> {
String permission = c.getPermission().map(CommandPermission::getPermission).orElse("None");
TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), TextUtils.AMPERSAND_CHAR)
.toBuilder().applyDeep(comp -> {
comp.hoverEvent(HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&bCommand: &2" + c.getName(),
"&bDescription: &2" + c.getDescription(),
"&bUsage: &2" + String.format(c.getUsage(), label),
"&bPermission: &2" + permission,
" ",
"&7Click to auto-complete."
), TextUtils.AMPERSAND_CHAR)));
comp.clickEvent(ClickEvent.suggestCommand(String.format(c.getUsage(), label)));
}).build();
sender.sendMessage(component);
});
.forEach(c -> sender.sendMessage(Component.text()
.append(Component.text('>', NamedTextColor.DARK_AQUA))
.append(Component.space())
.append(Component.text(String.format(c.getUsage(), label), NamedTextColor.GREEN))
.clickEvent(ClickEvent.suggestCommand(String.format(c.getUsage(), label)))
.build()
));
}
/**

View File

@ -26,19 +26,25 @@
package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.access.CommandPermission;
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.command.spec.Argument;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.sender.Sender;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* Abstract SubCommand class
*/
public abstract class ChildCommand<T> extends Command<T> {
public ChildCommand(LocalizedCommandSpec spec, String name, CommandPermission permission, Predicate<Integer> argumentCheck) {
public ChildCommand(CommandSpec spec, String name, CommandPermission permission, Predicate<Integer> argumentCheck) {
super(spec, name, permission, argumentCheck);
}
@ -49,25 +55,31 @@ public abstract class ChildCommand<T> extends Command<T> {
*/
@Override
public void sendUsage(Sender sender, String label) {
StringBuilder sb = new StringBuilder();
TextComponent.Builder builder = Component.text()
.append(Component.text('>', NamedTextColor.DARK_AQUA))
.append(Component.space())
.append(Component.text(getName().toLowerCase(), NamedTextColor.GREEN));
if (getArgs().isPresent()) {
sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlugin().getLocaleManager()));
for (Argument arg : getArgs().get()) {
sb.append(arg.asPrettyString(sender.getPlugin().getLocaleManager())).append(" ");
}
List<Component> argUsages = getArgs().get().stream()
.map(Argument::asPrettyString)
.collect(Collectors.toList());
builder.append(Component.text(" - ", NamedTextColor.DARK_AQUA))
.append(Component.join(Component.space(), argUsages))
.build();
}
Message.COMMAND_USAGE_BRIEF.send(sender, getName().toLowerCase(), sb.toString());
sender.sendMessage(builder.build());
}
@Override
public void sendDetailedUsage(Sender sender, String label) {
Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
if (getArgs().isPresent()) {
Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs().get()) {
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlugin().getLocaleManager()), arg.getDescription());
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(), arg.getDescription());
}
}
}

View File

@ -27,12 +27,14 @@ 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.spec.Argument;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.command.Argument;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -53,7 +55,7 @@ public abstract class Command<T> {
*
* Contains details about usage, description, etc
*/
private final @NonNull LocalizedCommandSpec spec;
private final @NonNull CommandSpec spec;
/**
* The name of the command. Should be properly capitalised.
@ -70,7 +72,7 @@ public abstract class Command<T> {
*/
private final @NonNull Predicate<Integer> argumentCheck;
public Command(@NonNull LocalizedCommandSpec spec, @NonNull String name, @Nullable CommandPermission permission, @NonNull Predicate<Integer> argumentCheck) {
public Command(@NonNull CommandSpec spec, @NonNull String name, @Nullable CommandPermission permission, @NonNull Predicate<Integer> argumentCheck) {
this.spec = spec;
this.name = name;
this.permission = permission;
@ -82,7 +84,7 @@ public abstract class Command<T> {
*
* @return the command spec
*/
public @NonNull LocalizedCommandSpec getSpec() {
public @NonNull CommandSpec getSpec() {
return this.spec;
}
@ -121,7 +123,7 @@ public abstract class Command<T> {
*
* @return the description
*/
public String getDescription() {
public Component getDescription() {
return getSpec().description();
}

View File

@ -27,18 +27,23 @@ 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.spec.Argument;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
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.locale.Message;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* A sub command which can be be applied to both groups and users.
@ -46,7 +51,7 @@ import java.util.function.Predicate;
*/
public abstract class GenericChildCommand {
private final LocalizedCommandSpec spec;
private final CommandSpec spec;
/**
* The name of the sub command
@ -64,7 +69,7 @@ public abstract class GenericChildCommand {
*/
private final Predicate<? super Integer> argumentCheck;
public GenericChildCommand(LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission, Predicate<? super Integer> argumentCheck) {
public GenericChildCommand(CommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission, Predicate<? super Integer> argumentCheck) {
this.spec = spec;
this.name = name;
this.userPermission = userPermission;
@ -78,7 +83,7 @@ public abstract class GenericChildCommand {
return Collections.emptyList();
}
public LocalizedCommandSpec getSpec() {
public CommandSpec getSpec() {
return this.spec;
}
@ -99,24 +104,30 @@ public abstract class GenericChildCommand {
}
public void sendUsage(Sender sender) {
StringBuilder sb = new StringBuilder();
TextComponent.Builder builder = Component.text()
.append(Component.text('>', NamedTextColor.DARK_AQUA))
.append(Component.space())
.append(Component.text(getName().toLowerCase(), NamedTextColor.GREEN));
if (getArgs() != null) {
sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlugin().getLocaleManager()));
for (Argument arg : getArgs()) {
sb.append(arg.asPrettyString(sender.getPlugin().getLocaleManager())).append(" ");
}
List<Component> argUsages = getArgs().stream()
.map(Argument::asPrettyString)
.collect(Collectors.toList());
builder.append(Component.text(" - ", NamedTextColor.DARK_AQUA))
.append(Component.join(Component.space(), argUsages))
.build();
}
Message.COMMAND_USAGE_BRIEF.send(sender, getName(), sb.toString());
sender.sendMessage(builder.build());
}
public void sendDetailedUsage(Sender sender) {
Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
if (getArgs() != null) {
Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs()) {
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlugin().getLocaleManager()), arg.getDescription());
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(), arg.getDescription());
}
}
}
@ -132,7 +143,7 @@ public abstract class GenericChildCommand {
}
}
public String getDescription() {
public Component getDescription() {
return this.spec.description();
}

View File

@ -26,11 +26,11 @@
package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -52,7 +52,7 @@ public class GenericParentCommand<T extends PermissionHolder> extends ChildComma
private final HolderType type;
public GenericParentCommand(LocalizedCommandSpec spec, String name, HolderType type, List<GenericChildCommand> children) {
public GenericParentCommand(CommandSpec spec, String name, HolderType type, List<GenericChildCommand> children) {
super(spec, name, null, Predicates.alwaysFalse());
this.children = children;
this.type = type;

View File

@ -26,11 +26,11 @@
package me.lucko.luckperms.common.command.abstraction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
@ -49,7 +49,7 @@ public abstract class ParentCommand<T, I> extends Command<Void> {
/** The type of parent command */
private final Type type;
public ParentCommand(LocalizedCommandSpec spec, String name, Type type, List<Command<T>> children) {
public ParentCommand(CommandSpec spec, String name, Type type, List<Command<T>> children) {
super(spec, name, null, Predicates.alwaysFalse());
this.children = children;
this.type = type;

View File

@ -27,21 +27,27 @@ 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.spec.Argument;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
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.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* Represents a single "main" command (one without any children)
*/
public abstract class SingleCommand extends Command<Void> {
public SingleCommand(LocalizedCommandSpec spec, String name, CommandPermission permission, Predicate<Integer> argumentCheck) {
public SingleCommand(CommandSpec spec, String name, CommandPermission permission, Predicate<Integer> argumentCheck) {
super(spec, name, permission, argumentCheck);
}
@ -54,25 +60,31 @@ public abstract class SingleCommand extends Command<Void> {
@Override
public void sendUsage(Sender sender, String label) {
StringBuilder sb = new StringBuilder();
TextComponent.Builder builder = Component.text()
.append(Component.text('>', NamedTextColor.DARK_AQUA))
.append(Component.space())
.append(Component.text(getName().toLowerCase(), NamedTextColor.GREEN));
if (getArgs().isPresent()) {
sb.append(Message.COMMAND_USAGE_ARGUMENT_JOIN.asString(sender.getPlugin().getLocaleManager()));
for (Argument arg : getArgs().get()) {
sb.append(arg.asPrettyString(sender.getPlugin().getLocaleManager())).append(" ");
}
List<Component> argUsages = getArgs().get().stream()
.map(Argument::asPrettyString)
.collect(Collectors.toList());
builder.append(Component.text(" - ", NamedTextColor.DARK_AQUA))
.append(Component.join(Component.space(), argUsages))
.build();
}
Message.COMMAND_USAGE_BRIEF.send(sender, getName().toLowerCase(), sb.toString());
sender.sendMessage(builder.build());
}
@Override
public void sendDetailedUsage(Sender sender, String label) {
Message.COMMAND_USAGE_DETAILED_HEADER.send(sender, getName(), getDescription());
if (getArgs().isPresent()) {
Message.COMMAND_USAGE_DETAILED_ARGS_HEADER.send(sender);
for (Argument arg : getArgs().get()) {
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(sender.getPlugin().getLocaleManager()), arg.getDescription());
Message.COMMAND_USAGE_DETAILED_ARG.send(sender, arg.asPrettyString(), arg.getDescription());
}
}
}

View File

@ -23,38 +23,23 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.locale.command;
package me.lucko.luckperms.common.command.spec;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.message.Message;
import org.checkerframework.checker.nullness.qual.Nullable;
import net.kyori.adventure.text.Component;
public class Argument {
public static Argument create(String name, boolean required, String description) {
return new Argument(name, required, description);
}
public static ImmutableList<Argument> list(Argument... args) {
return ImmutableList.copyOf(args);
}
private final String name;
private final boolean required;
private final String description;
private final Component description;
private Argument(String name, boolean required, String description) {
Argument(String name, boolean required, Component description) {
this.name = name;
this.required = required;
this.description = description;
}
public String asPrettyString(@Nullable LocaleManager localeManager) {
return (this.required ? Message.REQUIRED_ARGUMENT : Message.OPTIONAL_ARGUMENT).asString(localeManager, this.name);
}
public String getName() {
return this.name;
}
@ -63,7 +48,11 @@ public class Argument {
return this.required;
}
public String getDescription() {
public Component getDescription() {
return this.description;
}
public Component asPrettyString() {
return (this.required ? Message.REQUIRED_ARGUMENT : Message.OPTIONAL_ARGUMENT).build(this.name);
}
}

View File

@ -0,0 +1,477 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.command.spec;
import me.lucko.luckperms.common.util.ImmutableCollectors;
import net.kyori.adventure.text.Component;
import java.util.Arrays;
import java.util.List;
/**
* An enumeration of the command defintion/usage messages used in the plugin.
*/
@SuppressWarnings("SpellCheckingInspection")
public enum CommandSpec {
USER("/%s user <user>"),
GROUP("/%s group <group>"),
TRACK("/%s track <track>"),
LOG("/%s log"),
SYNC("/%s sync"),
INFO("/%s info"),
EDITOR("/%s editor [type]",
arg("type", false),
arg("filter", false)
),
DEBUG("/%s debug"),
VERBOSE("/%s verbose <on|record|off|upload> [filter]",
arg("action", "on|record|off|upload|command", true),
arg("filter", false),
arg("commandas", "<me|player> <command>", false)
),
TREE("/%s tree [scope] [player]",
arg("scope", false),
arg("player", false)
),
SEARCH("/%s search <permission>",
arg("permission", true),
arg("page", false)
),
CHECK("/%s check <user> <permission>",
arg("user", true),
arg("permission", true)
),
NETWORK_SYNC("/%s networksync"),
IMPORT("/%s import <file>",
arg("file", true),
arg("replace", "--replace", false)
),
EXPORT("/%s export <file>",
arg("file", true),
arg("without-users", "--without-users", false)
),
RELOAD_CONFIG("/%s reloadconfig"),
BULK_UPDATE("/%s bulkupdate",
arg("data type", true),
arg("action", true),
arg("action field", false),
arg("action value", false),
arg("constraint...", false)
),
MIGRATION("/%s migration"),
APPLY_EDITS("/%s applyedits <code> [target]",
arg("code", true),
arg("target", false)
),
CREATE_GROUP("/%s creategroup <group>",
arg("name", true)
),
DELETE_GROUP("/%s deletegroup <group>",
arg("name", true)
),
LIST_GROUPS("/%s listgroups"),
CREATE_TRACK("/%s createtrack <track>",
arg("name", true)
),
DELETE_TRACK("/%s deletetrack <track>",
arg("name", true)
),
LIST_TRACKS("/%s listtracks"),
USER_INFO,
USER_SWITCHPRIMARYGROUP(
(arg("group", true))
),
USER_PROMOTE(
arg("track", false),
arg("context...", false),
arg("dont-add-to-first", "--dont-add-to-first", false)
),
USER_DEMOTE(
arg("track", false),
arg("context...", false),
arg("dont-remove-from-first", "--dont-remove-from-first", false)
),
USER_CLONE(
arg("user", true)
),
GROUP_INFO,
GROUP_LISTMEMBERS(
arg("page", false)
),
GROUP_SETWEIGHT(
arg("weight", true)
),
GROUP_SET_DISPLAY_NAME(
arg("name", true),
arg("context...", false)
),
GROUP_RENAME(
arg("name", true)
),
GROUP_CLONE(
arg("name", true)
),
HOLDER_EDITOR,
HOLDER_SHOWTRACKS,
HOLDER_CLEAR(
arg("context...", false)
),
PERMISSION,
PARENT,
META,
PERMISSION_INFO(
arg("page", false),
arg("sort mode", false)
),
PERMISSION_SET(
arg("node", true),
arg("value", "true|false", false),
arg("context...", false)
),
PERMISSION_UNSET(
arg("node", true),
arg("context...", false)
),
PERMISSION_SETTEMP(
arg("node", true),
arg("value", "true|false", false),
arg("duration", true),
arg("temporary modifier", false),
arg("context...", false)
),
PERMISSION_UNSETTEMP(
arg("node", true),
arg("duration", false),
arg("context...", false)
),
PERMISSION_CHECK(
arg("node", true),
arg("context...", false)
),
PERMISSION_CHECK_INHERITS(
arg("node", true),
arg("context...", false)
),
PERMISSION_CLEAR(
arg("context...", false)
),
PARENT_INFO(
arg("page", false),
arg("sort mode", false)
),
PARENT_SET(
arg("group", true),
arg("context...", false)
),
PARENT_ADD(
arg("group", true),
arg("context...", false)
),
PARENT_REMOVE(
arg("group", true),
arg("context...", false)
),
PARENT_SET_TRACK(
arg("track", true),
arg("group", true),
arg("context...", false)
),
PARENT_ADD_TEMP(
arg("group", true),
arg("duration", true),
arg("temporary modifier", false),
arg("context...", false)
),
PARENT_REMOVE_TEMP(
arg("group", true),
arg("duration", false),
arg("context...", false)
),
PARENT_CLEAR(
arg("context...", false)
),
PARENT_CLEAR_TRACK(
arg("track", true),
arg("context...", false)
),
META_INFO,
META_SET(
arg("key", true),
arg("value", true),
arg("context...", false)
),
META_UNSET(
arg("key", true),
arg("context...", false)
),
META_SETTEMP(
arg("key", true),
arg("value", true),
arg("duration", true),
arg("context...", false)
),
META_UNSETTEMP(
arg("key", true),
arg("context...", false)
),
META_ADDPREFIX(
arg("priority", true),
arg("prefix", true),
arg("context...", false)
),
META_ADDSUFFIX(
arg("priority", true),
arg("suffix", true),
arg("context...", false)
),
META_SETPREFIX(
arg("priority", false),
arg("prefix", true),
arg("context...", false)
),
META_SETSUFFIX(
arg("priority", false),
arg("suffix", true),
arg("context...", false)
),
META_REMOVEPREFIX(
arg("priority", true),
arg("prefix", false),
arg("context...", false)
),
META_REMOVESUFFIX(
arg("priority", true),
arg("suffix", false),
arg("context...", false)
),
META_ADDTEMP_PREFIX(
arg("priority", true),
arg("prefix", true),
arg("duration", true),
arg("context...", false)
),
META_ADDTEMP_SUFFIX(
arg("priority", true),
arg("suffix", true),
arg("duration", true),
arg("context...", false)
),
META_SETTEMP_PREFIX(
arg("priority", true),
arg("prefix", true),
arg("duration", true),
arg("context...", false)
),
META_SETTEMP_SUFFIX(
arg("priority", true),
arg("suffix", true),
arg("duration", true),
arg("context...", false)
),
META_REMOVETEMP_PREFIX(
arg("priority", true),
arg("prefix", false),
arg("context...", false)
),
META_REMOVETEMP_SUFFIX(
arg("priority", true),
arg("suffix", false),
arg("context...", false)
),
META_CLEAR(
arg("type", false),
arg("context...", false)
),
TRACK_INFO,
TRACK_APPEND(
arg("group", true)
),
TRACK_INSERT(
arg("group", true),
arg("position", true)
),
TRACK_REMOVE(
arg("group", true)
),
TRACK_CLEAR,
TRACK_RENAME(
arg("name", true)
),
TRACK_CLONE(
arg("name", true)
),
LOG_RECENT(
arg("user", false),
arg("page", false)
),
LOG_SEARCH(
arg("query", true),
arg("page", false)
),
LOG_NOTIFY(
arg("toggle", "on|off", false)
),
LOG_USER_HISTORY(
arg("user", true),
arg("page", false)
),
LOG_GROUP_HISTORY(
arg("group", true),
arg("page", false)
),
LOG_TRACK_HISTORY(
arg("track", true),
arg("page", false)
),
SPONGE("/%s sponge <collection> <subject>",
arg("collection", true),
arg("subject", true)
),
SPONGE_PERMISSION_INFO(
arg("contexts...", false)
),
SPONGE_PERMISSION_SET(
arg("node", true),
arg("tristate", true),
arg("contexts...", false)
),
SPONGE_PERMISSION_CLEAR(
arg("contexts...", false)
),
SPONGE_PARENT_INFO(
arg("contexts...", false)
),
SPONGE_PARENT_ADD(
arg("collection", true),
arg("subject", true),
arg("contexts...", false)
),
SPONGE_PARENT_REMOVE(
arg("collection", true),
arg("subject", true),
arg("contexts...", false)
),
SPONGE_PARENT_CLEAR(
arg("contexts...", false)
),
SPONGE_OPTION_INFO(
arg("contexts...", false)
),
SPONGE_OPTION_SET(
arg("key", true),
arg("value", true),
arg("contexts...", false)
),
SPONGE_OPTION_UNSET(
arg("key", true),
arg("contexts...", false)
),
SPONGE_OPTION_CLEAR(
arg("contexts...", false)
),
MIGRATION_COMMAND,
MIGRATION_GROUPMANAGER(
arg("migrate as global", true)
),
MIGRATION_POWERFULPERMS(
arg("address", true),
arg("database", true),
arg("username", true),
arg("password", true),
arg("db table", true)
);
private final String usage;
private final List<Argument> args;
CommandSpec(String usage, PartialArgument... args) {
this.usage = usage;
this.args = args.length == 0 ? null : Arrays.stream(args)
.map(builder -> {
String key = builder.id.replace(".", "").replace(' ', '-');
Component description = Component.translatable("luckperms.usage." + key() + ".argument." + key);
return new Argument(builder.name, builder.required, description);
})
.collect(ImmutableCollectors.toList());
}
CommandSpec(PartialArgument... args) {
this(null, args);
}
public Component description() {
return Component.translatable("luckperms.usage." + this.key() + ".description");
}
public String usage() {
return this.usage;
}
public List<Argument> args() {
return this.args;
}
public String key() {
return name().toLowerCase().replace('_', '-');
}
private static PartialArgument arg(String id, String name, boolean required) {
return new PartialArgument(id, name, required);
}
private static PartialArgument arg(String name, boolean required) {
return new PartialArgument(name, name, required);
}
private static final class PartialArgument {
private final String id;
private final String name;
private final boolean required;
private PartialArgument(String id, String name, boolean required) {
this.id = id;
this.name = name;
this.required = required;
}
}
}

View File

@ -29,7 +29,7 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.Command;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.sender.Sender;
public abstract class ArgumentException extends CommandException {

View File

@ -1,162 +0,0 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.command.utils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.message.Message;
import net.luckperms.api.context.Context;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.node.Node;
import net.luckperms.api.util.Tristate;
import java.util.Collection;
import java.util.List;
public final class MessageUtils {
private MessageUtils() {}
public static String toCommaSep(Collection<String> strings) {
if (strings.isEmpty()) {
return "&bNone";
}
StringBuilder sb = new StringBuilder();
strings.forEach(s -> sb.append("&3").append(s).append("&7, "));
return sb.delete(sb.length() - 2, sb.length()).toString();
}
public static String listToArrowSep(Collection<String> strings, String highlight) {
if (strings.isEmpty()) {
return "&bNone";
}
StringBuilder sb = new StringBuilder();
strings.forEach(s -> sb.append(s.equalsIgnoreCase(highlight) ? "&b" : "&3").append(s).append("&7 ---> "));
return sb.delete(sb.length() - 6, sb.length()).toString();
}
public static String listToArrowSep(Collection<String> strings, String highlightFirst, String highlightSecond, boolean reversed) {
if (strings.isEmpty()) {
return "&6None";
}
StringBuilder sb = new StringBuilder();
for (String s : strings) {
if (s.equalsIgnoreCase(highlightFirst)) {
sb.append("&b").append(s).append("&4");
} else if (s.equalsIgnoreCase(highlightSecond)) {
sb.append("&b").append(s).append("&7");
} else {
sb.append("&3").append(s).append("&7");
}
sb.append(reversed ? " <--- " : " ---> ");
}
return sb.delete(sb.length() - 6, sb.length()).toString();
}
public static String listToArrowSep(List<String> strings) {
if (strings.isEmpty()) {
return "&6None";
}
StringBuilder sb = new StringBuilder();
strings.forEach(s -> sb.append("&3").append(s).append("&b ---> "));
return sb.delete(sb.length() - 6, sb.length()).toString();
}
/**
* Formats a boolean to a colored string
*
* @param b the boolean value
* @return a formatted boolean string
*/
public static String formatBoolean(boolean b) {
return b ? "&atrue" : "&cfalse";
}
/**
* Formats a tristate to a colored string
*
* @param t the tristate value
* @return a formatted tristate string
*/
public static String formatTristate(Tristate t) {
switch (t) {
case TRUE:
return "&atrue";
case FALSE:
return "&cfalse";
default:
return "&cundefined";
}
}
/**
* 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(LocaleManager localeManager, Node node) {
StringBuilder sb = new StringBuilder();
for (Context c : node.getContexts()) {
sb.append(" ").append(contextToString(localeManager, c.getKey(), c.getValue()));
}
return sb.toString();
}
/**
* 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(LocaleManager localeManager, String key, String value) {
return Message.CONTEXT_PAIR.asString(localeManager, key, value);
}
public static String contextSetToString(LocaleManager localeManager, ContextSet set) {
if (set.isEmpty()) {
return Message.CONTEXT_PAIR_GLOBAL_INLINE.asString(localeManager);
}
StringBuilder sb = new StringBuilder();
for (Context e : set) {
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(localeManager).length(), sb.length()).toString();
}
}

View File

@ -26,7 +26,7 @@
package me.lucko.luckperms.common.command.utils;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.messaging.InternalMessagingService;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.HolderType;

View File

@ -29,32 +29,31 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.abstraction.GenericParentCommand;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
public class CommandMeta<T extends PermissionHolder> extends GenericParentCommand<T> {
public CommandMeta(LocaleManager locale, HolderType type) {
super(CommandSpec.META.localize(locale), "Meta", type, ImmutableList.<GenericChildCommand>builder()
.add(new MetaInfo(locale))
.add(new MetaSet(locale))
.add(new MetaUnset(locale))
.add(new MetaSetTemp(locale))
.add(new MetaUnsetTemp(locale))
.add(MetaAddChatMeta.forPrefix(locale))
.add(MetaAddChatMeta.forSuffix(locale))
.add(MetaSetChatMeta.forPrefix(locale))
.add(MetaSetChatMeta.forSuffix(locale))
.add(MetaRemoveChatMeta.forPrefix(locale))
.add(MetaRemoveChatMeta.forSuffix(locale))
.add(MetaAddTempChatMeta.forPrefix(locale))
.add(MetaAddTempChatMeta.forSuffix(locale))
.add(MetaSetTempChatMeta.forPrefix(locale))
.add(MetaSetTempChatMeta.forSuffix(locale))
.add(MetaRemoveTempChatMeta.forPrefix(locale))
.add(MetaRemoveTempChatMeta.forSuffix(locale))
.add(new MetaClear(locale))
public CommandMeta(HolderType type) {
super(CommandSpec.META, "Meta", type, ImmutableList.<GenericChildCommand>builder()
.add(new MetaInfo())
.add(new MetaSet())
.add(new MetaUnset())
.add(new MetaSetTemp())
.add(new MetaUnsetTemp())
.add(MetaAddChatMeta.forPrefix())
.add(MetaAddChatMeta.forSuffix())
.add(MetaSetChatMeta.forPrefix())
.add(MetaSetChatMeta.forSuffix())
.add(MetaRemoveChatMeta.forPrefix())
.add(MetaRemoveChatMeta.forSuffix())
.add(MetaAddTempChatMeta.forPrefix())
.add(MetaAddTempChatMeta.forSuffix())
.add(MetaSetTempChatMeta.forPrefix())
.add(MetaSetTempChatMeta.forSuffix())
.add(MetaRemoveTempChatMeta.forPrefix())
.add(MetaRemoveTempChatMeta.forSuffix())
.add(new MetaClear())
.build());
}
}

View File

@ -31,23 +31,17 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.data.DataType;
@ -57,20 +51,20 @@ import java.util.List;
public class MetaAddChatMeta extends GenericChildCommand {
public static MetaAddChatMeta forPrefix(LocaleManager locale) {
public static MetaAddChatMeta forPrefix() {
return new MetaAddChatMeta(
ChatMetaType.PREFIX,
CommandSpec.META_ADDPREFIX.localize(locale),
CommandSpec.META_ADDPREFIX,
"addprefix",
CommandPermission.USER_META_ADD_PREFIX,
CommandPermission.GROUP_META_ADD_PREFIX
);
}
public static MetaAddChatMeta forSuffix(LocaleManager locale) {
public static MetaAddChatMeta forSuffix() {
return new MetaAddChatMeta(
ChatMetaType.SUFFIX,
CommandSpec.META_ADDSUFFIX.localize(locale),
CommandSpec.META_ADDSUFFIX,
"addsuffix",
CommandPermission.USER_META_ADD_SUFFIX,
CommandPermission.GROUP_META_ADD_SUFFIX
@ -79,7 +73,7 @@ public class MetaAddChatMeta extends GenericChildCommand {
private final ChatMetaType type;
private MetaAddChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
private MetaAddChatMeta(ChatMetaType type, CommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
super(spec, name, userPermission, groupPermission, Predicates.inRange(0, 1));
this.type = type;
}
@ -103,13 +97,7 @@ public class MetaAddChatMeta extends GenericChildCommand {
DataMutateResult result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
if (result.wasSuccessful()) {
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
'§'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
Message.ADD_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
LoggedAction.build().source(sender).target(target)
.description("meta" , "add" + this.type.name().toLowerCase(), priority, meta, context)
@ -118,7 +106,7 @@ public class MetaAddChatMeta extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_HAS_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,25 +31,18 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.data.DataType;
@ -61,20 +54,20 @@ import java.util.List;
public class MetaAddTempChatMeta extends GenericChildCommand {
public static MetaAddTempChatMeta forPrefix(LocaleManager locale) {
public static MetaAddTempChatMeta forPrefix() {
return new MetaAddTempChatMeta(
ChatMetaType.PREFIX,
CommandSpec.META_ADDTEMP_PREFIX.localize(locale),
CommandSpec.META_ADDTEMP_PREFIX,
"addtempprefix",
CommandPermission.USER_META_ADD_TEMP_PREFIX,
CommandPermission.GROUP_META_ADD_TEMP_PREFIX
);
}
public static MetaAddTempChatMeta forSuffix(LocaleManager locale) {
public static MetaAddTempChatMeta forSuffix() {
return new MetaAddTempChatMeta(
ChatMetaType.SUFFIX,
CommandSpec.META_ADDTEMP_SUFFIX.localize(locale),
CommandSpec.META_ADDTEMP_SUFFIX,
"addtempsuffix",
CommandPermission.USER_META_ADD_TEMP_SUFFIX,
CommandPermission.GROUP_META_ADD_TEMP_SUFFIX
@ -83,7 +76,7 @@ public class MetaAddTempChatMeta extends GenericChildCommand {
private final ChatMetaType type;
private MetaAddTempChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
private MetaAddTempChatMeta(ChatMetaType type, CommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
super(spec, name, userPermission, groupPermission, Predicates.inRange(0, 2));
this.type = type;
}
@ -112,13 +105,7 @@ public class MetaAddTempChatMeta extends GenericChildCommand {
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
'§'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
Message.ADD_TEMP_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, duration, context);
LoggedAction.build().source(sender).target(target)
.description("meta" , "addtemp" + this.type.name().toLowerCase(), priority, meta, duration, context)
@ -127,7 +114,7 @@ public class MetaAddTempChatMeta extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -51,8 +49,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class MetaClear extends GenericChildCommand {
public MetaClear(LocaleManager locale) {
super(CommandSpec.META_CLEAR.localize(locale), "clear", CommandPermission.USER_META_CLEAR, CommandPermission.GROUP_META_CLEAR, Predicates.alwaysFalse());
public MetaClear() {
super(CommandSpec.META_CLEAR, "clear", CommandPermission.USER_META_CLEAR, CommandPermission.GROUP_META_CLEAR, Predicates.alwaysFalse());
}
@Override
@ -107,11 +105,7 @@ public class MetaClear extends GenericChildCommand {
}
int changed = before - target.normalData().size();
if (changed == 1) {
Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.META_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
Message.META_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), type.name().toLowerCase(), context, changed);
LoggedAction.build().source(sender).target(target)
.description("meta", "clear", context)

View File

@ -31,29 +31,18 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
import me.lucko.luckperms.common.node.factory.NodeCommandFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.metadata.types.InheritanceOriginMetadata;
import net.luckperms.api.node.types.ChatMetaNode;
import net.luckperms.api.node.types.MetaNode;
import net.luckperms.api.node.types.PrefixNode;
@ -65,11 +54,10 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.function.Consumer;
public class MetaInfo extends GenericChildCommand {
public MetaInfo(LocaleManager locale) {
super(CommandSpec.META_INFO.localize(locale), "info", CommandPermission.USER_META_INFO, CommandPermission.GROUP_META_INFO, Predicates.alwaysFalse());
public MetaInfo() {
super(CommandSpec.META_INFO, "info", CommandPermission.USER_META_INFO, CommandPermission.GROUP_META_INFO, Predicates.alwaysFalse());
}
@Override
@ -104,117 +92,32 @@ public class MetaInfo extends GenericChildCommand {
Message.CHAT_META_PREFIX_NONE.send(sender, target.getFormattedDisplayName());
} else {
Message.CHAT_META_PREFIX_HEADER.send(sender, target.getFormattedDisplayName());
sendChatMetaMessage(prefixes, sender, target, label);
for (Map.Entry<Integer, PrefixNode> e : prefixes) {
Message.CHAT_META_ENTRY.send(sender, e.getValue(), target, label);
}
}
if (suffixes.isEmpty()) {
Message.CHAT_META_SUFFIX_NONE.send(sender, target.getFormattedDisplayName());
} else {
Message.CHAT_META_SUFFIX_HEADER.send(sender, target.getFormattedDisplayName());
sendChatMetaMessage(suffixes, sender, target, label);
for (Map.Entry<Integer, SuffixNode> e : suffixes) {
Message.CHAT_META_ENTRY.send(sender, e.getValue(), target, label);
}
}
if (meta.isEmpty()) {
Message.META_NONE.send(sender, target.getFormattedDisplayName());
} else {
Message.META_HEADER.send(sender, target.getFormattedDisplayName());
sendMetaMessage(meta, sender, target, label);
for (MetaNode node : meta) {
Message.META_ENTRY.send(sender, node, target, label);
}
}
return CommandResult.SUCCESS;
}
private static String processLocation(Node node, PermissionHolder holder) {
String location = node.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
return location.equalsIgnoreCase(holder.getObjectName()) ? "self" : location;
}
private static void sendMetaMessage(Set<MetaNode> meta, Sender sender, PermissionHolder holder, String label) {
for (MetaNode m : meta) {
String location = processLocation(m, holder);
if (!m.getContexts().isEmpty()) {
String context = MessageUtils.getAppendableNodeContextString(sender.getPlugin().getLocaleManager(), m);
TextComponent.Builder builder = Message.META_ENTRY_WITH_CONTEXT.asComponent(sender.getPlugin().getLocaleManager(), m.getMetaKey(), m.getMetaValue(), location, context).toBuilder();
builder.applyDeep(makeFancy(holder, label, m));
sender.sendMessage(builder.build());
} else {
TextComponent.Builder builder = Message.META_ENTRY.asComponent(sender.getPlugin().getLocaleManager(), m.getMetaKey(), m.getMetaValue(), location).toBuilder();
builder.applyDeep(makeFancy(holder, label, m));
sender.sendMessage(builder.build());
}
}
}
private static void sendChatMetaMessage(SortedSet<? extends Map.Entry<Integer, ? extends ChatMetaNode<?, ?>>> meta, Sender sender, PermissionHolder holder, String label) {
for (Map.Entry<Integer, ? extends ChatMetaNode<?, ?>> e : meta) {
String location = processLocation(e.getValue(), holder);
if (!e.getValue().getContexts().isEmpty()) {
String context = MessageUtils.getAppendableNodeContextString(sender.getPlugin().getLocaleManager(), e.getValue());
TextComponent.Builder builder = Message.CHAT_META_ENTRY_WITH_CONTEXT.asComponent(sender.getPlugin().getLocaleManager(), e.getKey(), e.getValue().getMetaValue(), location, context).toBuilder();
builder.applyDeep(makeFancy(holder, label, e.getValue()));
sender.sendMessage(builder.build());
} else {
TextComponent.Builder builder = Message.CHAT_META_ENTRY.asComponent(sender.getPlugin().getLocaleManager(), e.getKey(), e.getValue().getMetaValue(), location).toBuilder();
builder.applyDeep(makeFancy(holder, label, e.getValue()));
sender.sendMessage(builder.build());
}
}
}
private static Consumer<ComponentBuilder<?, ?>> makeFancy(PermissionHolder holder, String label, ChatMetaNode<?, ?> node) {
String location = node.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
if (!location.equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(location);
if (group != null) {
holder = group;
}
}
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"§3> §a" + node.getPriority() + " §7- §r" + node.getMetaValue(),
" ",
"§7Click to remove this " + node.getMetaType().name().toLowerCase() + " from " + holder.getPlainDisplayName()
), '§'));
String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName();
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
String command = "/" + label + " " + NodeCommandFactory.undoCommand(node, id, holder.getType(), explicitGlobalContext);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
private static Consumer<ComponentBuilder<?, ?>> makeFancy(PermissionHolder holder, String label, MetaNode node) {
String location = node.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
if (!location.equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(location);
if (group != null) {
holder = group;
}
}
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"§3> §r" + node.getMetaKey() + " §7- §r" + node.getMetaValue(),
" ",
"§7Click to remove this meta pair from " + holder.getPlainDisplayName()
), '§'));
String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getPlainDisplayName();
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
String command = "/" + label + " " + NodeCommandFactory.undoCommand(node, id, holder.getType(), explicitGlobalContext);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
private static final class MetaComparator implements Comparator<Map.Entry<Integer, ? extends ChatMetaNode<?, ?>>> {
public static final MetaComparator INSTANCE = new MetaComparator();

View File

@ -31,23 +31,17 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.data.DataType;
@ -57,20 +51,20 @@ import java.util.List;
public class MetaRemoveChatMeta extends GenericChildCommand {
public static MetaRemoveChatMeta forPrefix(LocaleManager locale) {
public static MetaRemoveChatMeta forPrefix() {
return new MetaRemoveChatMeta(
ChatMetaType.PREFIX,
CommandSpec.META_REMOVEPREFIX.localize(locale),
CommandSpec.META_REMOVEPREFIX,
"removeprefix",
CommandPermission.USER_META_REMOVE_PREFIX,
CommandPermission.GROUP_META_REMOVE_PREFIX
);
}
public static MetaRemoveChatMeta forSuffix(LocaleManager locale) {
public static MetaRemoveChatMeta forSuffix() {
return new MetaRemoveChatMeta(
ChatMetaType.SUFFIX,
CommandSpec.META_REMOVESUFFIX.localize(locale),
CommandSpec.META_REMOVESUFFIX,
"removesuffix",
CommandPermission.USER_META_REMOVE_SUFFIX,
CommandPermission.GROUP_META_REMOVE_SUFFIX
@ -79,7 +73,7 @@ public class MetaRemoveChatMeta extends GenericChildCommand {
private final ChatMetaType type;
private MetaRemoveChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
private MetaRemoveChatMeta(ChatMetaType type, CommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
super(spec, name, userPermission, groupPermission, Predicates.is(0));
this.type = type;
}
@ -104,7 +98,7 @@ public class MetaRemoveChatMeta extends GenericChildCommand {
// Handle bulk removal
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
target.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && !n.hasExpiry()), false);
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type, priority, context);
LoggedAction.build().source(sender).target(target)
.description("meta" , "remove" + this.type.name().toLowerCase(), priority, "*", context)
@ -117,13 +111,7 @@ public class MetaRemoveChatMeta extends GenericChildCommand {
DataMutateResult result = target.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build());
if (result.wasSuccessful()) {
TextComponent.Builder builder = Message.REMOVE_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
'§'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
Message.REMOVE_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
LoggedAction.build().source(sender).target(target)
.description("meta" , "remove" + this.type.name().toLowerCase(), priority, meta, context)
@ -132,7 +120,7 @@ public class MetaRemoveChatMeta extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_HAVE_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.DOES_NOT_HAVE_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,23 +31,17 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.data.DataType;
@ -57,20 +51,20 @@ import java.util.List;
public class MetaRemoveTempChatMeta extends GenericChildCommand {
public static MetaRemoveTempChatMeta forPrefix(LocaleManager locale) {
public static MetaRemoveTempChatMeta forPrefix() {
return new MetaRemoveTempChatMeta(
ChatMetaType.PREFIX,
CommandSpec.META_REMOVETEMP_PREFIX.localize(locale),
CommandSpec.META_REMOVETEMP_PREFIX,
"removetempprefix",
CommandPermission.USER_META_REMOVE_TEMP_PREFIX,
CommandPermission.GROUP_META_REMOVE_TEMP_PREFIX
);
}
public static MetaRemoveTempChatMeta forSuffix(LocaleManager locale) {
public static MetaRemoveTempChatMeta forSuffix() {
return new MetaRemoveTempChatMeta(
ChatMetaType.SUFFIX,
CommandSpec.META_REMOVETEMP_SUFFIX.localize(locale),
CommandSpec.META_REMOVETEMP_SUFFIX,
"removetempsuffix",
CommandPermission.USER_META_REMOVE_TEMP_SUFFIX,
CommandPermission.GROUP_META_REMOVE_TEMP_SUFFIX
@ -79,7 +73,7 @@ public class MetaRemoveTempChatMeta extends GenericChildCommand {
private final ChatMetaType type;
private MetaRemoveTempChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
private MetaRemoveTempChatMeta(ChatMetaType type, CommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
super(spec, name, userPermission, groupPermission, Predicates.is(0));
this.type = type;
}
@ -104,7 +98,7 @@ public class MetaRemoveTempChatMeta extends GenericChildCommand {
// Handle bulk removal
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
target.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && n.hasExpiry()), false);
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type, priority, context);
LoggedAction.build().source(sender).target(target)
.description("meta" , "removetemp" + this.type.name().toLowerCase(), priority, "*", context)
@ -117,13 +111,7 @@ public class MetaRemoveTempChatMeta extends GenericChildCommand {
DataMutateResult result = target.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).expiry(10L).withContext(context).build());
if (result.wasSuccessful()) {
TextComponent.Builder builder = Message.REMOVE_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
'§'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
Message.REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
LoggedAction.build().source(sender).target(target)
.description("meta" , "removetemp" + this.type.name().toLowerCase(), priority, meta, context)
@ -132,7 +120,7 @@ public class MetaRemoveTempChatMeta extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,23 +31,18 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.types.Meta;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.node.Node;
@ -57,8 +52,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class MetaSet extends GenericChildCommand {
public MetaSet(LocaleManager locale) {
super(CommandSpec.META_SET.localize(locale), "set", CommandPermission.USER_META_SET, CommandPermission.GROUP_META_SET, Predicates.inRange(0, 1));
public MetaSet() {
super(CommandSpec.META_SET, "set", CommandPermission.USER_META_SET, CommandPermission.GROUP_META_SET, Predicates.inRange(0, 1));
}
@Override
@ -82,20 +77,14 @@ public class MetaSet extends GenericChildCommand {
Node node = Meta.builder(key, value).withContext(context).build();
if (target.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
Message.ALREADY_HAS_META.send(sender, target.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_HAS_META.send(sender, target.getFormattedDisplayName(), key, value, context);
return CommandResult.STATE_ERROR;
}
target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
target.setNode(DataType.NORMAL, node, true);
TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
TextUtils.joinNewline("§3Raw key: §r" + key, "§3Raw value: §r" + value),
'§'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
Message.SET_META_SUCCESS.send(sender, key, value, target.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("meta", "set", key, value, context)

View File

@ -32,25 +32,19 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.data.DataType;
@ -61,20 +55,20 @@ import java.util.OptionalInt;
public class MetaSetChatMeta extends GenericChildCommand {
public static MetaSetChatMeta forPrefix(LocaleManager locale) {
public static MetaSetChatMeta forPrefix() {
return new MetaSetChatMeta(
ChatMetaType.PREFIX,
CommandSpec.META_SETPREFIX.localize(locale),
CommandSpec.META_SETPREFIX,
"setprefix",
CommandPermission.USER_META_SET_PREFIX,
CommandPermission.GROUP_META_SET_PREFIX
);
}
public static MetaSetChatMeta forSuffix(LocaleManager locale) {
public static MetaSetChatMeta forSuffix() {
return new MetaSetChatMeta(
ChatMetaType.SUFFIX,
CommandSpec.META_SETSUFFIX.localize(locale),
CommandSpec.META_SETSUFFIX,
"setsuffix",
CommandPermission.USER_META_SET_SUFFIX,
CommandPermission.GROUP_META_SET_SUFFIX
@ -83,7 +77,7 @@ public class MetaSetChatMeta extends GenericChildCommand {
private final ChatMetaType type;
private MetaSetChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
private MetaSetChatMeta(ChatMetaType type, CommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
super(spec, name, userPermission, groupPermission, Predicates.is(0));
this.type = type;
}
@ -138,13 +132,7 @@ public class MetaSetChatMeta extends GenericChildCommand {
DataMutateResult result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
if (result.wasSuccessful()) {
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
'§'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
Message.ADD_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
LoggedAction.build().source(sender).target(target)
.description("meta" , "set" + this.type.name().toLowerCase(), priority, meta, context)
@ -153,7 +141,7 @@ public class MetaSetChatMeta extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_HAS_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,25 +31,19 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.types.Meta;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.data.TemporaryNodeMergeStrategy;
@ -61,8 +55,8 @@ import java.time.Duration;
import java.util.List;
public class MetaSetTemp extends GenericChildCommand {
public MetaSetTemp(LocaleManager locale) {
super(CommandSpec.META_SETTEMP.localize(locale), "settemp", CommandPermission.USER_META_SET_TEMP, CommandPermission.GROUP_META_SET_TEMP, Predicates.inRange(0, 2));
public MetaSetTemp() {
super(CommandSpec.META_SETTEMP, "settemp", CommandPermission.USER_META_SET_TEMP, CommandPermission.GROUP_META_SET_TEMP, Predicates.inRange(0, 2));
}
@Override
@ -88,20 +82,14 @@ public class MetaSetTemp extends GenericChildCommand {
Node node = Meta.builder(key, value).withContext(context).expiry(duration).build();
if (target.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
Message.ALREADY_HAS_TEMP_META.send(sender, target.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_HAS_TEMP_META.send(sender, target.getFormattedDisplayName(), key, value, context);
return CommandResult.STATE_ERROR;
}
target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false);
duration = target.setNode(DataType.NORMAL, node, modifier).getMergedNode().getExpiryDuration();
TextComponent.Builder builder = Message.SET_META_TEMP_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, target.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
TextUtils.joinNewline("§3Raw key: §r" + key, "§3Raw value: §r" + value),
'§'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
Message.SET_META_TEMP_SUCCESS.send(sender, key, value, target.getFormattedDisplayName(), duration, context);
LoggedAction.build().source(sender).target(target)
.description("meta", "settemp", key, value, duration, context)

View File

@ -32,27 +32,20 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.command.LocalizedCommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.data.DataType;
@ -65,20 +58,20 @@ import java.util.OptionalInt;
public class MetaSetTempChatMeta extends GenericChildCommand {
public static MetaSetTempChatMeta forPrefix(LocaleManager locale) {
public static MetaSetTempChatMeta forPrefix() {
return new MetaSetTempChatMeta(
ChatMetaType.PREFIX,
CommandSpec.META_SETTEMP_PREFIX.localize(locale),
CommandSpec.META_SETTEMP_PREFIX,
"settempprefix",
CommandPermission.USER_META_SET_TEMP_PREFIX,
CommandPermission.GROUP_META_SET_TEMP_PREFIX
);
}
public static MetaSetTempChatMeta forSuffix(LocaleManager locale) {
public static MetaSetTempChatMeta forSuffix() {
return new MetaSetTempChatMeta(
ChatMetaType.SUFFIX,
CommandSpec.META_SETTEMP_SUFFIX.localize(locale),
CommandSpec.META_SETTEMP_SUFFIX,
"settempsuffix",
CommandPermission.USER_META_SET_TEMP_SUFFIX,
CommandPermission.GROUP_META_SET_TEMP_SUFFIX
@ -87,7 +80,7 @@ public class MetaSetTempChatMeta extends GenericChildCommand {
private final ChatMetaType type;
private MetaSetTempChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
private MetaSetTempChatMeta(ChatMetaType type, CommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) {
super(spec, name, userPermission, groupPermission, Predicates.inRange(0, 1));
this.type = type;
}
@ -151,13 +144,7 @@ public class MetaSetTempChatMeta extends GenericChildCommand {
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(
"§3Raw " + this.type.name().toLowerCase() + ": §r" + meta,
'§'
));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
Message.ADD_TEMP_CHATMETA_SUCCESS.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, duration, context);
LoggedAction.build().source(sender).target(target)
.description("meta" , "settemp" + this.type.name().toLowerCase(), priority, meta, duration, context)
@ -166,7 +153,7 @@ public class MetaSetTempChatMeta extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, target.getFormattedDisplayName(), this.type, meta, priority, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -51,8 +49,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class MetaUnset extends GenericChildCommand {
public MetaUnset(LocaleManager locale) {
super(CommandSpec.META_UNSET.localize(locale), "unset", CommandPermission.USER_META_UNSET, CommandPermission.GROUP_META_UNSET, Predicates.is(0));
public MetaUnset() {
super(CommandSpec.META_UNSET, "unset", CommandPermission.USER_META_UNSET, CommandPermission.GROUP_META_UNSET, Predicates.is(0));
}
@Override
@ -73,7 +71,7 @@ public class MetaUnset extends GenericChildCommand {
}
if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
Message.UNSET_META_SUCCESS.send(sender, key, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.UNSET_META_SUCCESS.send(sender, key, target.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("meta", "unset", key, context)
@ -82,7 +80,7 @@ public class MetaUnset extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOESNT_HAVE_META.send(sender, target.getFormattedDisplayName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.DOESNT_HAVE_META.send(sender, target.getFormattedDisplayName(), key, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -51,8 +49,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class MetaUnsetTemp extends GenericChildCommand {
public MetaUnsetTemp(LocaleManager locale) {
super(CommandSpec.META_UNSETTEMP.localize(locale), "unsettemp", CommandPermission.USER_META_UNSET_TEMP, CommandPermission.GROUP_META_UNSET_TEMP, Predicates.is(0));
public MetaUnsetTemp() {
super(CommandSpec.META_UNSETTEMP, "unsettemp", CommandPermission.USER_META_UNSET_TEMP, CommandPermission.GROUP_META_UNSET_TEMP, Predicates.is(0));
}
@Override
@ -73,7 +71,7 @@ public class MetaUnsetTemp extends GenericChildCommand {
}
if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, target.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("meta", "unsettemp", key, context)
@ -82,7 +80,7 @@ public class MetaUnsetTemp extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOESNT_HAVE_TEMP_META.send(sender, target.getFormattedDisplayName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.DOESNT_HAVE_TEMP_META.send(sender, target.getFormattedDisplayName(), key, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -51,8 +49,8 @@ import net.luckperms.api.model.data.DataType;
import java.util.List;
public class HolderClear<T extends PermissionHolder> extends ChildCommand<T> {
public HolderClear(LocaleManager locale, HolderType type) {
super(CommandSpec.HOLDER_CLEAR.localize(locale), "clear", type == HolderType.USER ? CommandPermission.USER_CLEAR : CommandPermission.GROUP_CLEAR, Predicates.alwaysFalse());
public HolderClear(HolderType type) {
super(CommandSpec.HOLDER_CLEAR, "clear", type == HolderType.USER ? CommandPermission.USER_CLEAR : CommandPermission.GROUP_CLEAR, Predicates.alwaysFalse());
}
@Override
@ -79,11 +77,7 @@ public class HolderClear<T extends PermissionHolder> extends ChildCommand<T> {
}
int changed = before - target.normalData().size();
if (changed == 1) {
Message.CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
Message.CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), context, changed);
LoggedAction.build().source(sender).target(target)
.description("clear", context)

View File

@ -29,12 +29,11 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.commands.misc.EditorCommand;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
@ -61,8 +60,8 @@ import java.util.Map;
import java.util.UUID;
public class HolderEditor<T extends PermissionHolder> extends ChildCommand<T> {
public HolderEditor(LocaleManager locale, HolderType type) {
super(CommandSpec.HOLDER_EDITOR.localize(locale), "editor", type == HolderType.USER ? CommandPermission.USER_EDITOR : CommandPermission.GROUP_EDITOR, Predicates.alwaysFalse());
public HolderEditor(HolderType type) {
super(CommandSpec.HOLDER_EDITOR, "editor", type == HolderType.USER ? CommandPermission.USER_EDITOR : CommandPermission.GROUP_EDITOR, Predicates.alwaysFalse());
}
@Override

View File

@ -31,11 +31,9 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
@ -44,6 +42,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import net.kyori.adventure.text.Component;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.InheritanceNode;
@ -54,8 +53,8 @@ import java.util.Set;
import java.util.stream.Collectors;
public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T> {
public HolderShowTracks(LocaleManager locale, HolderType type) {
super(CommandSpec.HOLDER_SHOWTRACKS.localize(locale), "showtracks", type == HolderType.USER ? CommandPermission.USER_SHOW_TRACKS : CommandPermission.GROUP_SHOW_TRACKS, Predicates.alwaysFalse());
public HolderShowTracks(HolderType type) {
super(CommandSpec.HOLDER_SHOWTRACKS, "showtracks", type == HolderType.USER ? CommandPermission.USER_SHOW_TRACKS : CommandPermission.GROUP_SHOW_TRACKS, Predicates.alwaysFalse());
}
@Override
@ -73,7 +72,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T
return CommandResult.LOADING_ERROR;
}
List<Map.Entry<Track, String>> lines = new ArrayList<>();
List<Map.Entry<Track, Component>> lines = new ArrayList<>();
if (target.getType() == HolderType.USER) {
// if the holder is a user, we want to query parent groups for tracks
@ -88,8 +87,14 @@ public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T
.filter(t -> t.containsGroup(groupName))
.collect(Collectors.toList());
for (Track t : tracks) {
lines.add(Maps.immutableEntry(t, MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node) + "\n" + MessageUtils.listToArrowSep(t.getGroups(), groupName)));
for (Track track : tracks) {
Component line = Component.text()
.append(Message.formatContextSetBracketed(node.getContexts(), Component.empty()))
.append(Component.newline())
.append(Message.formatTrackPath(track.getGroups(), groupName))
.build();
lines.add(Maps.immutableEntry(track, line));
}
}
} else {
@ -99,8 +104,8 @@ public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T
.filter(t -> t.containsGroup(groupName))
.collect(Collectors.toList());
for (Track t : tracks) {
lines.add(Maps.immutableEntry(t, MessageUtils.listToArrowSep(t.getGroups(), groupName)));
for (Track track : tracks) {
lines.add(Maps.immutableEntry(track, Message.formatTrackPath(track.getGroups(), groupName)));
}
}
@ -110,7 +115,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends ChildCommand<T
}
Message.LIST_TRACKS.send(sender, target.getFormattedDisplayName());
for (Map.Entry<Track, String> line : lines) {
for (Map.Entry<Track, Component> line : lines) {
Message.LIST_TRACKS_ENTRY.send(sender, line.getKey().getName(), line.getValue());
}
return CommandResult.SUCCESS;

View File

@ -29,26 +29,25 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.abstraction.GenericParentCommand;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
import java.util.Collections;
public class CommandParent<T extends PermissionHolder> extends GenericParentCommand<T> {
public CommandParent(LocaleManager locale, HolderType type) {
super(CommandSpec.PARENT.localize(locale), "Parent", type, ImmutableList.<GenericChildCommand>builder()
.add(new ParentInfo(locale))
.add(new ParentSet(locale))
.add(new ParentAdd(locale))
.add(new ParentRemove(locale))
.add(new ParentSetTrack(locale))
.add(new ParentAddTemp(locale))
.add(new ParentRemoveTemp(locale))
.add(new ParentClear(locale))
.add(new ParentClearTrack(locale))
.addAll(type == HolderType.USER ? Collections.singleton(new UserSwitchPrimaryGroup(locale)) : Collections.emptySet())
public CommandParent(HolderType type) {
super(CommandSpec.PARENT, "Parent", type, ImmutableList.<GenericChildCommand>builder()
.add(new ParentInfo())
.add(new ParentSet())
.add(new ParentAdd())
.add(new ParentRemove())
.add(new ParentSetTrack())
.add(new ParentAddTemp())
.add(new ParentRemoveTemp())
.add(new ParentClear())
.add(new ParentClearTrack())
.addAll(type == HolderType.USER ? Collections.singleton(new UserSwitchPrimaryGroup()) : Collections.emptySet())
.build());
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.types.Inheritance;
@ -54,8 +52,8 @@ import net.luckperms.api.model.data.DataType;
import java.util.List;
public class ParentAdd extends GenericChildCommand {
public ParentAdd(LocaleManager locale) {
super(CommandSpec.PARENT_ADD.localize(locale), "add", CommandPermission.USER_PARENT_ADD, CommandPermission.GROUP_PARENT_ADD, Predicates.is(0));
public ParentAdd() {
super(CommandSpec.PARENT_ADD, "add", CommandPermission.USER_PARENT_ADD, CommandPermission.GROUP_PARENT_ADD, Predicates.is(0));
}
@Override
@ -84,7 +82,7 @@ public class ParentAdd extends GenericChildCommand {
DataMutateResult result = target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
if (result.wasSuccessful()) {
Message.SET_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.SET_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("parent", "add", group.getName(), context)
@ -93,7 +91,7 @@ public class ParentAdd extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,22 +31,19 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.storage.misc.DataConstraints;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.context.MutableContextSet;
@ -58,8 +55,8 @@ import java.time.Duration;
import java.util.List;
public class ParentAddTemp extends GenericChildCommand {
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));
public ParentAddTemp() {
super(CommandSpec.PARENT_ADD_TEMP, "addtemp", CommandPermission.USER_PARENT_ADD_TEMP, CommandPermission.GROUP_PARENT_ADD_TEMP, Predicates.inRange(0, 1));
}
@Override
@ -88,7 +85,7 @@ public class ParentAddTemp extends GenericChildCommand {
}
if (group.getName().equalsIgnoreCase(target.getObjectName())) {
Message.ALREADY_TEMP_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_TEMP_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), context);
return CommandResult.STATE_ERROR;
}
@ -96,7 +93,7 @@ public class ParentAddTemp extends GenericChildCommand {
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), duration, context);
LoggedAction.build().source(sender).target(target)
.description("parent", "addtemp", group.getName(), duration, context)
@ -105,7 +102,7 @@ public class ParentAddTemp extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_TEMP_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_TEMP_INHERITS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -51,8 +49,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class ParentClear extends GenericChildCommand {
public ParentClear(LocaleManager locale) {
super(CommandSpec.PARENT_CLEAR.localize(locale), "clear", CommandPermission.USER_PARENT_CLEAR, CommandPermission.GROUP_PARENT_CLEAR, Predicates.alwaysFalse());
public ParentClear() {
super(CommandSpec.PARENT_CLEAR, "clear", CommandPermission.USER_PARENT_CLEAR, CommandPermission.GROUP_PARENT_CLEAR, Predicates.alwaysFalse());
}
@Override
@ -78,11 +76,7 @@ public class ParentClear extends GenericChildCommand {
}
int changed = before - target.normalData().size();
if (changed == 1) {
Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.PARENT_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
Message.PARENT_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), context, changed);
LoggedAction.build().source(sender).target(target)
.description("parent", "clear", context)

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.Track;
@ -55,8 +53,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class ParentClearTrack extends GenericChildCommand {
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));
public ParentClearTrack() {
super(CommandSpec.PARENT_CLEAR_TRACK, "cleartrack", CommandPermission.USER_PARENT_CLEAR_TRACK, CommandPermission.GROUP_PARENT_CLEAR_TRACK, Predicates.is(0));
}
@Override
@ -100,12 +98,7 @@ public class ParentClearTrack extends GenericChildCommand {
}
int changed = before - target.normalData().size();
if (changed == 1) {
Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, target.getFormattedDisplayName(), track.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, target.getFormattedDisplayName(), track.getName(), context, changed);
LoggedAction.build().source(sender).target(target)
.description("parent", "cleartrack", track.getName(), context)

View File

@ -29,40 +29,29 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.SortMode;
import me.lucko.luckperms.common.command.utils.SortType;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
import me.lucko.luckperms.common.node.factory.NodeCommandFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Iterators;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.node.types.InheritanceNode;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
public class ParentInfo extends GenericChildCommand {
public ParentInfo(LocaleManager locale) {
super(CommandSpec.PARENT_INFO.localize(locale), "info", CommandPermission.USER_PARENT_INFO, CommandPermission.GROUP_PARENT_INFO, Predicates.notInRange(0, 2));
public ParentInfo() {
super(CommandSpec.PARENT_INFO, "info", CommandPermission.USER_PARENT_INFO, CommandPermission.GROUP_PARENT_INFO, Predicates.notInRange(0, 2));
}
@Override
@ -113,13 +102,11 @@ public class ParentInfo extends GenericChildCommand {
// send content
for (InheritanceNode node : content) {
String s = "&3> &a" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node);
if (node.hasExpiry()) {
s += "\n&2 expires in " + DurationFormatter.LONG.format(node.getExpiryDuration());
Message.PARENT_INFO_TEMPORARY_NODE_ENTRY.send(sender, node, target, label);
} else {
Message.PARENT_INFO_NODE_ENTRY.send(sender, node, target, label);
}
TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(target, label, node)).build();
sender.sendMessage(message);
}
return CommandResult.SUCCESS;
@ -134,22 +121,4 @@ public class ParentInfo extends GenericChildCommand {
// fallback to priority
return NodeWithContextComparator.reverse().compare(o1, o2);
};
private static Consumer<ComponentBuilder<? ,?>> makeFancy(PermissionHolder holder, String label, InheritanceNode node) {
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> &f" + node.getGroupName(),
" ",
"&7Click to remove this parent from " + holder.getPlainDisplayName()
), TextUtils.AMPERSAND_CHAR));
String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getPlainDisplayName();
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
String command = "/" + label + " " + NodeCommandFactory.undoCommand(node, id, holder.getType(), explicitGlobalContext);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
}

View File

@ -31,15 +31,13 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
@ -57,8 +55,8 @@ import net.luckperms.api.model.data.DataType;
import java.util.List;
public class ParentRemove extends GenericChildCommand {
public ParentRemove(LocaleManager locale) {
super(CommandSpec.PARENT_REMOVE.localize(locale), "remove", CommandPermission.USER_PARENT_REMOVE, CommandPermission.GROUP_PARENT_REMOVE, Predicates.is(0));
public ParentRemove() {
super(CommandSpec.PARENT_REMOVE, "remove", CommandPermission.USER_PARENT_REMOVE, CommandPermission.GROUP_PARENT_REMOVE, Predicates.is(0));
}
@Override
@ -95,7 +93,7 @@ public class ParentRemove extends GenericChildCommand {
DataMutateResult result = target.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).withContext(context).build());
if (result.wasSuccessful()) {
Message.UNSET_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.UNSET_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), groupName, context);
LoggedAction.build().source(sender).target(target)
.description("parent", "remove", groupName, context)
@ -108,7 +106,7 @@ public class ParentRemove extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_INHERIT.send(sender, target.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.DOES_NOT_INHERIT.send(sender, target.getFormattedDisplayName(), groupName, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,20 +31,17 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.storage.misc.DataConstraints;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.context.MutableContextSet;
@ -56,8 +53,8 @@ import java.time.Duration;
import java.util.List;
public class ParentRemoveTemp extends GenericChildCommand {
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));
public ParentRemoveTemp() {
super(CommandSpec.PARENT_REMOVE_TEMP, "removetemp", CommandPermission.USER_PARENT_REMOVE_TEMP, CommandPermission.GROUP_PARENT_REMOVE_TEMP, Predicates.is(0));
}
@Override
@ -85,19 +82,13 @@ public class ParentRemoveTemp extends GenericChildCommand {
Node mergedNode = result.getMergedNode();
//noinspection ConstantConditions
if (mergedNode != null) {
Message.UNSET_TEMP_INHERIT_SUBTRACT_SUCCESS.send(sender,
target.getFormattedDisplayName(),
groupName,
DurationFormatter.LONG.format(mergedNode.getExpiryDuration()),
MessageUtils.contextSetToString(plugin.getLocaleManager(), context),
DurationFormatter.LONG.format(duration)
);
Message.UNSET_TEMP_INHERIT_SUBTRACT_SUCCESS.send(sender, target.getFormattedDisplayName(), groupName, mergedNode.getExpiryDuration(), context, duration);
LoggedAction.build().source(sender).target(target)
.description("parent", "removetemp", groupName, duration, context)
.build().submit(plugin, sender);
} else {
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, target.getFormattedDisplayName(), groupName, context);
LoggedAction.build().source(sender).target(target)
.description("parent", "removetemp", groupName, context)
@ -107,7 +98,7 @@ public class ParentRemoveTemp extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_TEMP_INHERIT.send(sender, target.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.DOES_NOT_TEMP_INHERIT.send(sender, target.getFormattedDisplayName(), groupName, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
@ -56,8 +54,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class ParentSet extends GenericChildCommand {
public ParentSet(LocaleManager locale) {
super(CommandSpec.PARENT_SET.localize(locale), "set", CommandPermission.USER_PARENT_SET, CommandPermission.GROUP_PARENT_SET, Predicates.is(0));
public ParentSet() {
super(CommandSpec.PARENT_SET, "set", CommandPermission.USER_PARENT_SET, CommandPermission.GROUP_PARENT_SET, Predicates.is(0));
}
@Override
@ -89,7 +87,7 @@ public class ParentSet extends GenericChildCommand {
((User) target).getPrimaryGroup().setStoredValue(group.getName());
}
Message.SET_PARENT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.SET_PARENT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("parent", "set", group.getName(), context)

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.Track;
@ -55,8 +53,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class ParentSetTrack extends GenericChildCommand {
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));
public ParentSetTrack() {
super(CommandSpec.PARENT_SET_TRACK, "settrack", CommandPermission.USER_PARENT_SET_TRACK, CommandPermission.GROUP_PARENT_SET_TRACK, Predicates.inRange(0, 1));
}
@Override
@ -87,7 +85,7 @@ public class ParentSetTrack extends GenericChildCommand {
if (index > 0) {
List<String> trackGroups = track.getGroups();
if ((index - 1) >= trackGroups.size()) {
Message.DOES_NOT_EXIST.send(sender, index);
Message.DOES_NOT_EXIST.send(sender, String.valueOf(index));
return CommandResult.INVALID_ARGS;
}
groupName = track.getGroups().get(index - 1);
@ -117,7 +115,7 @@ public class ParentSetTrack extends GenericChildCommand {
target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
Message.SET_TRACK_PARENT_SUCCESS.send(sender, target.getFormattedDisplayName(), track.getName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.SET_TRACK_PARENT_SUCCESS.send(sender, target.getFormattedDisplayName(), track.getName(), group.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("parent", "settrack", track.getName(), groupName, context)

View File

@ -30,15 +30,14 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
@ -55,8 +54,8 @@ import net.luckperms.api.node.NodeEqualityPredicate;
import java.util.List;
public class UserSwitchPrimaryGroup extends GenericChildCommand {
public UserSwitchPrimaryGroup(LocaleManager locale) {
super(CommandSpec.USER_SWITCHPRIMARYGROUP.localize(locale), "switchprimarygroup", CommandPermission.USER_PARENT_SWITCHPRIMARYGROUP, null, Predicates.not(1));
public UserSwitchPrimaryGroup() {
super(CommandSpec.USER_SWITCHPRIMARYGROUP, "switchprimarygroup", CommandPermission.USER_PARENT_SWITCHPRIMARYGROUP, null, Predicates.not(1));
}
@Override

View File

@ -29,22 +29,21 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.abstraction.GenericParentCommand;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.PermissionHolder;
public class CommandPermission<T extends PermissionHolder> extends GenericParentCommand<T> {
public CommandPermission(LocaleManager locale, HolderType type) {
super(CommandSpec.PERMISSION.localize(locale), "Permission", type, ImmutableList.<GenericChildCommand>builder()
.add(new PermissionInfo(locale))
.add(new PermissionSet(locale))
.add(new PermissionUnset(locale))
.add(new PermissionSetTemp(locale))
.add(new PermissionUnsetTemp(locale))
.add(new PermissionCheck(locale))
.add(new PermissionCheckInherits(locale))
.add(new PermissionClear(locale))
public CommandPermission(HolderType type) {
super(CommandSpec.PERMISSION, "Permission", type, ImmutableList.<GenericChildCommand>builder()
.add(new PermissionInfo())
.add(new PermissionSet())
.add(new PermissionUnset())
.add(new PermissionSetTemp())
.add(new PermissionUnsetTemp())
.add(new PermissionCheck())
.add(new PermissionCheckInherits())
.add(new PermissionClear())
.build());
}
}

View File

@ -30,13 +30,11 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -51,8 +49,8 @@ import net.luckperms.api.util.Tristate;
import java.util.List;
public class PermissionCheck extends GenericChildCommand {
public PermissionCheck(LocaleManager locale) {
super(CommandSpec.PERMISSION_CHECK.localize(locale), "check", CommandPermission.USER_PERM_CHECK, CommandPermission.GROUP_PERM_CHECK, Predicates.is(0));
public PermissionCheck() {
super(CommandSpec.PERMISSION_CHECK, "check", CommandPermission.USER_PERM_CHECK, CommandPermission.GROUP_PERM_CHECK, Predicates.is(0));
}
@Override
@ -66,9 +64,7 @@ public class PermissionCheck extends GenericChildCommand {
MutableContextSet context = args.getContextOrDefault(1, plugin);
Tristate result = target.hasNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(node).withContext(context).build(), NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY);
String s = MessageUtils.formatTristate(result);
Message.CHECK_PERMISSION.send(sender, target.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.CHECK_PERMISSION.send(sender, target.getFormattedDisplayName(), node, result, context);
return CommandResult.SUCCESS;
}

View File

@ -30,13 +30,11 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
@ -52,8 +50,8 @@ import java.util.List;
import java.util.Optional;
public class PermissionCheckInherits extends GenericChildCommand {
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));
public PermissionCheckInherits() {
super(CommandSpec.PERMISSION_CHECK_INHERITS, "checkinherits", CommandPermission.USER_PERM_CHECK_INHERITS, CommandPermission.GROUP_PERM_CHECK_INHERITS, Predicates.is(0));
}
@Override
@ -76,8 +74,8 @@ public class PermissionCheckInherits extends GenericChildCommand {
location = "self";
}
String s = MessageUtils.formatTristate(match.map(n -> Tristate.of(n.getValue())).orElse(Tristate.UNDEFINED));
Message.CHECK_INHERITS_PERMISSION.send(sender, target.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context), location);
Tristate result = match.map(n -> Tristate.of(n.getValue())).orElse(Tristate.UNDEFINED);
Message.CHECK_INHERITS_PERMISSION.send(sender, target.getFormattedDisplayName(), node, result, context, location);
return CommandResult.SUCCESS;
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -51,8 +49,8 @@ import net.luckperms.api.node.NodeType;
import java.util.List;
public class PermissionClear extends GenericChildCommand {
public PermissionClear(LocaleManager locale) {
super(CommandSpec.PERMISSION_CLEAR.localize(locale), "clear", CommandPermission.USER_PERM_CLEAR, CommandPermission.GROUP_PERM_CLEAR, Predicates.alwaysFalse());
public PermissionClear() {
super(CommandSpec.PERMISSION_CLEAR, "clear", CommandPermission.USER_PERM_CLEAR, CommandPermission.GROUP_PERM_CLEAR, Predicates.alwaysFalse());
}
@Override
@ -75,11 +73,7 @@ public class PermissionClear extends GenericChildCommand {
target.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.PERMISSION::matches, false);
int changed = before - target.normalData().size();
if (changed == 1) {
Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
} else {
Message.PERMISSION_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
}
Message.PERMISSION_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), context, changed);
LoggedAction.build().source(sender).target(target)
.description("permission", "clear", context)

View File

@ -29,28 +29,18 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.SortMode;
import me.lucko.luckperms.common.command.utils.SortType;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
import me.lucko.luckperms.common.node.factory.NodeCommandFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Iterators;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
@ -58,11 +48,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
public class PermissionInfo extends GenericChildCommand {
public PermissionInfo(LocaleManager locale) {
super(CommandSpec.PERMISSION_INFO.localize(locale), "info", CommandPermission.USER_PERM_INFO, CommandPermission.GROUP_PERM_INFO, Predicates.notInRange(0, 2));
public PermissionInfo() {
super(CommandSpec.PERMISSION_INFO, "info", CommandPermission.USER_PERM_INFO, CommandPermission.GROUP_PERM_INFO, Predicates.notInRange(0, 2));
}
@Override
@ -113,13 +102,11 @@ public class PermissionInfo extends GenericChildCommand {
// send content
for (Node node : content) {
String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getKey() + (sender.isConsole() ? " &7(" + node.getValue() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node);
if (node.hasExpiry()) {
s += "\n&2- expires in " + DurationFormatter.LONG.format(node.getExpiryDuration());
Message.PERMISSION_INFO_TEMPORARY_NODE_ENTRY.send(sender, node, target, label);
} else {
Message.PERMISSION_INFO_NODE_ENTRY.send(sender, node, target, label);
}
TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(target, label, node)).build();
sender.sendMessage(message);
}
return CommandResult.SUCCESS;
@ -134,22 +121,4 @@ public class PermissionInfo extends GenericChildCommand {
// fallback to priority
return NodeWithContextComparator.reverse().compare(o1, o2);
};
private static Consumer<ComponentBuilder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"§3> " + (node.getValue() ? "§a" : "§c") + node.getKey(),
" ",
"§7Click to remove this node from " + holder.getPlainDisplayName()
), '§'));
String id = holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getPlainDisplayName();
boolean explicitGlobalContext = !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
String command = "/" + label + " " + NodeCommandFactory.undoCommand(node, id, holder.getType(), explicitGlobalContext);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -54,8 +52,8 @@ import net.luckperms.api.node.types.InheritanceNode;
import java.util.List;
public class PermissionSet extends GenericChildCommand {
public PermissionSet(LocaleManager locale) {
super(CommandSpec.PERMISSION_SET.localize(locale), "set", CommandPermission.USER_PERM_SET, CommandPermission.GROUP_PERM_SET, Predicates.is(0));
public PermissionSet() {
super(CommandSpec.PERMISSION_SET, "set", CommandPermission.USER_PERM_SET, CommandPermission.GROUP_PERM_SET, Predicates.is(0));
}
@Override
@ -88,7 +86,7 @@ public class PermissionSet extends GenericChildCommand {
DataMutateResult result = target.setNode(DataType.NORMAL, builtNode, true);
if (result.wasSuccessful()) {
Message.SETPERMISSION_SUCCESS.send(sender, node, value, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.SETPERMISSION_SUCCESS.send(sender, node, value, target.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("permission", "set", node, value, context)
@ -97,7 +95,7 @@ public class PermissionSet extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HASPERMISSION.send(sender, target.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_HASPERMISSION.send(sender, target.getFormattedDisplayName(), node, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,20 +31,17 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.context.MutableContextSet;
@ -58,8 +55,8 @@ import java.time.Duration;
import java.util.List;
public class PermissionSetTemp extends GenericChildCommand {
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));
public PermissionSetTemp() {
super(CommandSpec.PERMISSION_SETTEMP, "settemp", CommandPermission.USER_PERM_SET_TEMP, CommandPermission.GROUP_PERM_SET_TEMP, Predicates.inRange(0, 2));
}
@Override
@ -95,7 +92,7 @@ public class PermissionSetTemp extends GenericChildCommand {
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, target.getFormattedDisplayName(), DurationFormatter.LONG.format(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, target.getFormattedDisplayName(), duration, context);
LoggedAction.build().source(sender).target(target)
.description("permission", "settemp", node, value, duration, context)
@ -104,7 +101,7 @@ public class PermissionSetTemp extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, target.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, target.getFormattedDisplayName(), node, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -54,8 +52,8 @@ import net.luckperms.api.node.types.InheritanceNode;
import java.util.List;
public class PermissionUnset extends GenericChildCommand {
public PermissionUnset(LocaleManager locale) {
super(CommandSpec.PERMISSION_UNSET.localize(locale), "unset", CommandPermission.USER_PERM_UNSET, CommandPermission.GROUP_PERM_UNSET, Predicates.is(0));
public PermissionUnset() {
super(CommandSpec.PERMISSION_UNSET, "unset", CommandPermission.USER_PERM_UNSET, CommandPermission.GROUP_PERM_UNSET, Predicates.is(0));
}
@Override
@ -87,7 +85,7 @@ public class PermissionUnset extends GenericChildCommand {
DataMutateResult result = target.unsetNode(DataType.NORMAL, builtNode);
if (result.wasSuccessful()) {
Message.UNSETPERMISSION_SUCCESS.send(sender, node, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.UNSETPERMISSION_SUCCESS.send(sender, node, target.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("permission", "unset", node, context)
@ -96,7 +94,7 @@ public class PermissionUnset extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_HAVE_PERMISSION.send(sender, target.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.DOES_NOT_HAVE_PERMISSION.send(sender, target.getFormattedDisplayName(), node, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -31,19 +31,16 @@ import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.GenericChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.context.MutableContextSet;
@ -56,8 +53,8 @@ import java.time.Duration;
import java.util.List;
public class PermissionUnsetTemp extends GenericChildCommand {
public PermissionUnsetTemp(LocaleManager locale) {
super(CommandSpec.PERMISSION_UNSETTEMP.localize(locale), "unsettemp", CommandPermission.USER_PERM_UNSET_TEMP, CommandPermission.GROUP_PERM_UNSET_TEMP, Predicates.is(0));
public PermissionUnsetTemp() {
super(CommandSpec.PERMISSION_UNSETTEMP, "unsettemp", CommandPermission.USER_PERM_UNSET_TEMP, CommandPermission.GROUP_PERM_UNSET_TEMP, Predicates.is(0));
}
@Override
@ -93,20 +90,13 @@ public class PermissionUnsetTemp extends GenericChildCommand {
Node mergedNode = result.getMergedNode();
//noinspection ConstantConditions
if (mergedNode != null) {
Message.UNSET_TEMP_PERMISSION_SUBTRACT_SUCCESS.send(sender,
mergedNode.getKey(),
mergedNode.getValue(),
target.getFormattedDisplayName(),
DurationFormatter.LONG.format(mergedNode.getExpiryDuration()),
MessageUtils.contextSetToString(plugin.getLocaleManager(), context),
DurationFormatter.LONG.format(duration)
);
Message.UNSET_TEMP_PERMISSION_SUBTRACT_SUCCESS.send(sender, mergedNode.getKey(), mergedNode.getValue(), target.getFormattedDisplayName(), mergedNode.getExpiryDuration(), context, duration);
LoggedAction.build().source(sender).target(target)
.description("permission", "unsettemp", node, duration, context)
.build().submit(plugin, sender);
} else {
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, target.getFormattedDisplayName(), context);
LoggedAction.build().source(sender).target(target)
.description("permission", "unsettemp", node, context)
@ -116,7 +106,7 @@ public class PermissionUnsetTemp extends GenericChildCommand {
StorageAssistant.save(target, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, target.getFormattedDisplayName(), node, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, target.getFormattedDisplayName(), node, context);
return CommandResult.STATE_ERROR;
}
}

View File

@ -29,10 +29,9 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.storage.misc.DataConstraints;
@ -42,8 +41,8 @@ import net.luckperms.api.actionlog.Action;
import net.luckperms.api.event.cause.CreationCause;
public class CreateGroup extends SingleCommand {
public CreateGroup(LocaleManager locale) {
super(CommandSpec.CREATE_GROUP.localize(locale), "CreateGroup", CommandPermission.CREATE_GROUP, Predicates.not(1));
public CreateGroup() {
super(CommandSpec.CREATE_GROUP, "CreateGroup", CommandPermission.CREATE_GROUP, Predicates.not(1));
}
@Override

View File

@ -29,12 +29,11 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -47,8 +46,8 @@ import net.luckperms.api.event.cause.DeletionCause;
import java.util.List;
public class DeleteGroup extends SingleCommand {
public DeleteGroup(LocaleManager locale) {
super(CommandSpec.DELETE_GROUP.localize(locale), "DeleteGroup", CommandPermission.DELETE_GROUP, Predicates.not(1));
public DeleteGroup() {
super(CommandSpec.DELETE_GROUP, "DeleteGroup", CommandPermission.DELETE_GROUP, Predicates.not(1));
}
@Override

View File

@ -30,11 +30,10 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -45,8 +44,8 @@ import net.luckperms.api.event.cause.CreationCause;
import net.luckperms.api.model.data.DataType;
public class GroupClone extends ChildCommand<Group> {
public GroupClone(LocaleManager locale) {
super(CommandSpec.GROUP_CLONE.localize(locale), "clone", CommandPermission.GROUP_CLONE, Predicates.not(1));
public GroupClone() {
super(CommandSpec.GROUP_CLONE, "clone", CommandPermission.GROUP_CLONE, Predicates.not(1));
}
@Override

View File

@ -25,22 +25,17 @@
package me.lucko.luckperms.common.commands.group;
import com.google.common.collect.Maps;
import me.lucko.luckperms.common.cacheddata.type.MetaCache;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
@ -53,8 +48,8 @@ import java.util.Map;
import java.util.stream.Collectors;
public class GroupInfo extends ChildCommand<Group> {
public GroupInfo(LocaleManager locale) {
super(CommandSpec.GROUP_INFO.localize(locale), "info", CommandPermission.GROUP_INFO, Predicates.alwaysFalse());
public GroupInfo() {
super(CommandSpec.GROUP_INFO, "info", CommandPermission.GROUP_INFO, Predicates.alwaysFalse());
}
@Override
@ -64,11 +59,7 @@ public class GroupInfo extends ChildCommand<Group> {
return CommandResult.NO_PERMISSION;
}
Message.GROUP_INFO_GENERAL.send(sender,
target.getName(),
target.getPlainDisplayName(),
target.getWeight().isPresent() ? target.getWeight().getAsInt() : "None"
);
Message.GROUP_INFO_GENERAL.send(sender, target.getName(), target.getPlainDisplayName(), target.getWeight());
List<InheritanceNode> parents = target.normalData().inheritanceAsSortedSet().stream()
.filter(Node::getValue)
@ -83,41 +74,22 @@ public class GroupInfo extends ChildCommand<Group> {
if (!parents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (InheritanceNode node : parents) {
Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node));
Message.INFO_PARENT_NODE_ENTRY.send(sender, node);
}
}
if (!tempParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (InheritanceNode node : tempParents) {
Message.INFO_PARENT_ENTRY.send(sender, node.getGroupName(), MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node));
Message.INFO_PARENT_ENTRY_EXPIRY.send(sender, DurationFormatter.LONG.format(node.getExpiryDuration()));
Message.INFO_PARENT_TEMPORARY_NODE_ENTRY.send(sender, node);
}
}
QueryOptions queryOptions = plugin.getContextManager().getStaticQueryOptions();
String prefix = "&bNone";
String suffix = "&bNone";
String meta = "&bNone";
MetaCache data = target.getCachedData().getMetaData(queryOptions);
String prefixValue = data.getPrefix(MetaCheckEvent.Origin.INTERNAL);
if (prefixValue != null) {
prefix = "&f\"" + prefixValue + "&f\"";
}
String sussexValue = data.getSuffix(MetaCheckEvent.Origin.INTERNAL);
if (sussexValue != null) {
suffix = "&f\"" + sussexValue + "&f\"";
}
Map<String, List<String>> metaMap = data.getMeta(MetaCheckEvent.Origin.INTERNAL);
if (!metaMap.isEmpty()) {
meta = metaMap.entrySet().stream()
.flatMap(entry -> entry.getValue().stream().map(value -> Maps.immutableEntry(entry.getKey(), value)))
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
.collect(Collectors.joining(" "));
}
String prefix = data.getPrefix(MetaCheckEvent.Origin.INTERNAL);
String suffix = data.getSuffix(MetaCheckEvent.Origin.INTERNAL);
Map<String, List<String>> meta = data.getMeta(MetaCheckEvent.Origin.INTERNAL);
Message.GROUP_INFO_CONTEXTUAL_DATA.send(sender, prefix, suffix, meta);
return CommandResult.SUCCESS;

View File

@ -32,47 +32,36 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.node.comparator.NodeEntryComparator;
import me.lucko.luckperms.common.node.factory.NodeCommandFactory;
import me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher;
import me.lucko.luckperms.common.node.matcher.StandardNodeMatchers;
import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.storage.misc.NodeEntry;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Iterators;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.InheritanceNode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
public class GroupListMembers extends ChildCommand<Group> {
public GroupListMembers(LocaleManager locale) {
super(CommandSpec.GROUP_LISTMEMBERS.localize(locale), "listmembers", CommandPermission.GROUP_LIST_MEMBERS, Predicates.notInRange(0, 1));
public GroupListMembers() {
super(CommandSpec.GROUP_LISTMEMBERS, "listmembers", CommandPermission.GROUP_LIST_MEMBERS, Predicates.notInRange(0, 1));
}
@Override
@ -140,7 +129,7 @@ public class GroupListMembers extends ChildCommand<Group> {
return CommandResult.SUCCESS;
}
private static <T extends Comparable<T>> void sendResult(Sender sender, List<NodeEntry<T, InheritanceNode>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
private static <T extends Comparable<T>> void sendResult(Sender sender, List<NodeEntry<T, InheritanceNode>> results, Function<T, String> lookupFunction, Message.Args3<Integer, Integer, Integer> headerMessage, HolderType holderType, String label, int page) {
results = new ArrayList<>(results);
results.sort(NodeEntryComparator.normal());
@ -162,34 +151,7 @@ public class GroupListMembers extends ChildCommand<Group> {
headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, NodeEntry<T, InheritanceNode>> ent : mappedContent) {
String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().getNode()) + MessageUtils.getAppendableNodeContextString(sender.getPlugin().getLocaleManager(), ent.getValue().getNode());
TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue(), sender.getPlugin())).build();
sender.sendMessage(message);
Message.SEARCH_INHERITS_NODE_ENTRY.send(sender, ent.getValue().getNode(), ent.getKey(), holderType, label, sender.getPlugin());
}
}
private static String getNodeExpiryString(Node node) {
if (!node.hasExpiry()) {
return "";
}
return " &8(&7expires in " + DurationFormatter.LONG.format(node.getExpiryDuration()) + "&8)";
}
private static Consumer<ComponentBuilder<? ,?>> makeFancy(String holderName, HolderType holderType, String label, NodeEntry<?, ?> perm, LuckPermsPlugin plugin) {
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> &b" + ((InheritanceNode) perm.getNode()).getGroupName(),
" ",
"&7Click to remove this parent from " + holderName
), TextUtils.AMPERSAND_CHAR));
boolean explicitGlobalContext = !plugin.getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
String command = "/" + label + " " + NodeCommandFactory.undoCommand(perm.getNode(), holderName, holderType, explicitGlobalContext);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
}

View File

@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.command.abstraction.Command;
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.commands.generic.meta.CommandMeta;
import me.lucko.luckperms.common.commands.generic.other.HolderClear;
@ -37,8 +38,6 @@ import me.lucko.luckperms.common.commands.generic.other.HolderEditor;
import me.lucko.luckperms.common.commands.generic.other.HolderShowTracks;
import me.lucko.luckperms.common.commands.generic.parent.CommandParent;
import me.lucko.luckperms.common.commands.generic.permission.CommandPermission;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -60,20 +59,20 @@ public class GroupParentCommand extends ParentCommand<Group, String> {
.expireAfterAccess(1, TimeUnit.HOURS)
.build(key -> new ReentrantLock());
public GroupParentCommand(LocaleManager locale) {
super(CommandSpec.GROUP.localize(locale), "Group", Type.TAKES_ARGUMENT_FOR_TARGET, ImmutableList.<Command<Group>>builder()
.add(new GroupInfo(locale))
.add(new CommandPermission<>(locale, HolderType.GROUP))
.add(new CommandParent<>(locale, HolderType.GROUP))
.add(new CommandMeta<>(locale, HolderType.GROUP))
.add(new HolderEditor<>(locale, HolderType.GROUP))
.add(new GroupListMembers(locale))
.add(new GroupSetWeight(locale))
.add(new GroupSetDisplayName(locale))
.add(new HolderShowTracks<>(locale, HolderType.GROUP))
.add(new HolderClear<>(locale, HolderType.GROUP))
.add(new GroupRename(locale))
.add(new GroupClone(locale))
public GroupParentCommand() {
super(CommandSpec.GROUP, "Group", Type.TAKES_ARGUMENT_FOR_TARGET, ImmutableList.<Command<Group>>builder()
.add(new GroupInfo())
.add(new CommandPermission<>(HolderType.GROUP))
.add(new CommandParent<>(HolderType.GROUP))
.add(new CommandMeta<>(HolderType.GROUP))
.add(new HolderEditor<>(HolderType.GROUP))
.add(new GroupListMembers())
.add(new GroupSetWeight())
.add(new GroupSetDisplayName())
.add(new HolderShowTracks<>(HolderType.GROUP))
.add(new HolderClear<>(HolderType.GROUP))
.add(new GroupRename())
.add(new GroupClone())
.build()
);
}

View File

@ -29,11 +29,10 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -45,8 +44,8 @@ import net.luckperms.api.event.cause.DeletionCause;
import net.luckperms.api.model.data.DataType;
public class GroupRename extends ChildCommand<Group> {
public GroupRename(LocaleManager locale) {
super(CommandSpec.GROUP_RENAME.localize(locale), "rename", CommandPermission.GROUP_RENAME, Predicates.not(1));
public GroupRename() {
super(CommandSpec.GROUP_RENAME, "rename", CommandPermission.GROUP_RENAME, Predicates.not(1));
}
@Override

View File

@ -31,14 +31,12 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.node.types.DisplayName;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -53,8 +51,8 @@ import net.luckperms.api.node.types.DisplayNameNode;
import java.util.List;
public class GroupSetDisplayName extends ChildCommand<Group> {
public GroupSetDisplayName(LocaleManager locale) {
super(CommandSpec.GROUP_SET_DISPLAY_NAME.localize(locale), "setdisplayname", CommandPermission.GROUP_SET_DISPLAY_NAME, Predicates.is(0));
public GroupSetDisplayName() {
super(CommandSpec.GROUP_SET_DISPLAY_NAME, "setdisplayname", CommandPermission.GROUP_SET_DISPLAY_NAME, Predicates.is(0));
}
@Override
@ -93,7 +91,7 @@ public class GroupSetDisplayName extends ChildCommand<Group> {
target.removeIf(DataType.NORMAL, context, NodeType.DISPLAY_NAME::matches, false);
if (name.equals(target.getName())) {
Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, target.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, target.getName(), context);
LoggedAction.build().source(sender).target(target)
.description("setdisplayname", name, context)
@ -105,7 +103,7 @@ public class GroupSetDisplayName extends ChildCommand<Group> {
target.setNode(DataType.NORMAL, DisplayName.builder(name).withContext(context).build(), true);
Message.GROUP_SET_DISPLAY_NAME.send(sender, name, target.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
Message.GROUP_SET_DISPLAY_NAME.send(sender, name, target.getName(), context);
LoggedAction.build().source(sender).target(target)
.description("setdisplayname", name, context)

View File

@ -31,11 +31,10 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.StorageAssistant;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.node.types.Weight;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -46,8 +45,8 @@ import net.luckperms.api.model.data.DataType;
import net.luckperms.api.node.NodeType;
public class GroupSetWeight extends ChildCommand<Group> {
public GroupSetWeight(LocaleManager locale) {
super(CommandSpec.GROUP_SETWEIGHT.localize(locale), "setweight", CommandPermission.GROUP_SET_WEIGHT, Predicates.not(1));
public GroupSetWeight() {
super(CommandSpec.GROUP_SETWEIGHT, "setweight", CommandPermission.GROUP_SET_WEIGHT, Predicates.not(1));
}
@Override

View File

@ -28,32 +28,24 @@ package me.lucko.luckperms.common.commands.group;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
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.util.Predicates;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.format.TextColor;
import java.util.List;
import java.util.stream.Collectors;
public class ListGroups extends SingleCommand {
public ListGroups(LocaleManager locale) {
super(CommandSpec.LIST_GROUPS.localize(locale), "ListGroups", CommandPermission.LIST_GROUPS, Predicates.alwaysFalse());
public ListGroups() {
super(CommandSpec.LIST_GROUPS, "ListGroups", CommandPermission.LIST_GROUPS, Predicates.alwaysFalse());
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
try {
plugin.getStorage().loadAllGroups().get();
} catch (Exception e) {
@ -70,27 +62,7 @@ public class ListGroups extends SingleCommand {
})
.forEach(group -> {
List<String> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(group)).map(Track::getName).collect(Collectors.toList());
TextComponent component;
if (tracks.isEmpty()) {
component = Message.GROUPS_LIST_ENTRY.asComponent(plugin.getLocaleManager(),
group.getFormattedDisplayName(),
group.getWeight().orElse(0)
);
} else {
component = Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asComponent(plugin.getLocaleManager(),
group.getFormattedDisplayName(),
group.getWeight().orElse(0),
MessageUtils.toCommaSep(tracks)
);
}
component = component.toBuilder().applyDeep(c -> {
c.clickEvent(ClickEvent.runCommand("/" + label + " group " + group.getName() + " info"));
c.hoverEvent(HoverEvent.showText(TextComponent.of("Click to view more info about " + group.getName() + ".").color(TextColor.GRAY)));
}).build();
sender.sendMessage(component);
Message.GROUPS_LIST_ENTRY.send(sender, group.getFormattedDisplayName(), group.getWeight().orElse(0), tracks);
});
return CommandResult.SUCCESS;

View File

@ -30,16 +30,14 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.storage.misc.DataConstraints;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Paginated;
import me.lucko.luckperms.common.util.Predicates;
@ -48,8 +46,8 @@ import java.util.List;
public class LogGroupHistory extends ChildCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogGroupHistory(LocaleManager locale) {
super(CommandSpec.LOG_GROUP_HISTORY.localize(locale), "grouphistory", CommandPermission.LOG_GROUP_HISTORY, Predicates.notInRange(1, 2));
public LogGroupHistory() {
super(CommandSpec.LOG_GROUP_HISTORY, "grouphistory", CommandPermission.LOG_GROUP_HISTORY, Predicates.notInRange(1, 2));
}
@Override
@ -91,14 +89,7 @@ public class LogGroupHistory extends ChildCommand<Log> {
Message.LOG_HISTORY_GROUP_HEADER.send(sender, name, page, maxPage);
for (Paginated.Entry<LoggedAction> e : entries) {
Message.LOG_ENTRY.send(sender,
e.position(),
DurationFormatter.CONCISE_LOW_ACCURACY.format(e.value().getDurationSince()),
e.value().getSourceFriendlyString(),
Character.toString(LoggedAction.getTypeCharacter(e.value().getTarget().getType())),
e.value().getTargetFriendlyString(),
e.value().getDescription()
);
Message.LOG_ENTRY.send(sender, e.position(), e.value());
}
return CommandResult.SUCCESS;

View File

@ -29,11 +29,10 @@ import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -49,8 +48,8 @@ import java.util.UUID;
public class LogNotify extends ChildCommand<Log> {
private static final String IGNORE_NODE = "luckperms.log.notify.ignoring";
public LogNotify(LocaleManager locale) {
super(CommandSpec.LOG_NOTIFY.localize(locale), "notify", CommandPermission.LOG_NOTIFY, Predicates.notInRange(0, 1));
public LogNotify() {
super(CommandSpec.LOG_NOTIFY, "notify", CommandPermission.LOG_NOTIFY, Predicates.notInRange(0, 1));
}
public static boolean isIgnoring(LuckPermsPlugin plugin, UUID uuid) {

View File

@ -30,9 +30,8 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.command.abstraction.Command;
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -42,14 +41,14 @@ import java.util.concurrent.locks.ReentrantLock;
public class LogParentCommand extends ParentCommand<Log, Void> {
private final ReentrantLock lock = new ReentrantLock();
public LogParentCommand(LocaleManager locale) {
super(CommandSpec.LOG.localize(locale), "Log", Type.NO_TARGET_ARGUMENT, ImmutableList.<Command<Log>>builder()
.add(new LogRecent(locale))
.add(new LogSearch(locale))
.add(new LogNotify(locale))
.add(new LogUserHistory(locale))
.add(new LogGroupHistory(locale))
.add(new LogTrackHistory(locale))
public LogParentCommand() {
super(CommandSpec.LOG, "Log", Type.NO_TARGET_ARGUMENT, ImmutableList.<Command<Log>>builder()
.add(new LogRecent())
.add(new LogSearch())
.add(new LogNotify())
.add(new LogUserHistory())
.add(new LogGroupHistory())
.add(new LogTrackHistory())
.build()
);
}

View File

@ -30,13 +30,11 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Paginated;
import me.lucko.luckperms.common.util.Predicates;
@ -46,8 +44,8 @@ import java.util.UUID;
public class LogRecent extends ChildCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogRecent(LocaleManager locale) {
super(CommandSpec.LOG_RECENT.localize(locale), "recent", CommandPermission.LOG_RECENT, Predicates.notInRange(0, 2));
public LogRecent() {
super(CommandSpec.LOG_RECENT, "recent", CommandPermission.LOG_RECENT, Predicates.notInRange(0, 2));
}
@Override
@ -103,14 +101,7 @@ public class LogRecent extends ChildCommand<Log> {
}
for (Paginated.Entry<LoggedAction> e : entries) {
Message.LOG_ENTRY.send(sender,
e.position(),
DurationFormatter.CONCISE_LOW_ACCURACY.format(e.value().getDurationSince()),
e.value().getSourceFriendlyString(),
Character.toString(LoggedAction.getTypeCharacter(e.value().getTarget().getType())),
e.value().getTargetFriendlyString(),
e.value().getDescription()
);
Message.LOG_ENTRY.send(sender, e.position(), e.value());
}
return CommandResult.SUCCESS;
}

View File

@ -30,13 +30,11 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Paginated;
import me.lucko.luckperms.common.util.Predicates;
@ -45,8 +43,8 @@ import java.util.List;
public class LogSearch extends ChildCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogSearch(LocaleManager locale) {
super(CommandSpec.LOG_SEARCH.localize(locale), "search", CommandPermission.LOG_SEARCH, Predicates.is(0));
public LogSearch() {
super(CommandSpec.LOG_SEARCH, "search", CommandPermission.LOG_SEARCH, Predicates.is(0));
}
@Override
@ -91,14 +89,7 @@ public class LogSearch extends ChildCommand<Log> {
Message.LOG_SEARCH_HEADER.send(sender, query, page, maxPage);
for (Paginated.Entry<LoggedAction> e : entries) {
Message.LOG_ENTRY.send(sender,
e.position(),
DurationFormatter.CONCISE_LOW_ACCURACY.format(e.value().getDurationSince()),
e.value().getSourceFriendlyString(),
Character.toString(LoggedAction.getTypeCharacter(e.value().getTarget().getType())),
e.value().getTargetFriendlyString(),
e.value().getDescription()
);
Message.LOG_ENTRY.send(sender, e.position(), e.value());
}
return CommandResult.SUCCESS;

View File

@ -30,16 +30,14 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.storage.misc.DataConstraints;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Paginated;
import me.lucko.luckperms.common.util.Predicates;
@ -48,8 +46,8 @@ import java.util.List;
public class LogTrackHistory extends ChildCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogTrackHistory(LocaleManager locale) {
super(CommandSpec.LOG_TRACK_HISTORY.localize(locale), "trackhistory", CommandPermission.LOG_TRACK_HISTORY, Predicates.notInRange(1, 2));
public LogTrackHistory() {
super(CommandSpec.LOG_TRACK_HISTORY, "trackhistory", CommandPermission.LOG_TRACK_HISTORY, Predicates.notInRange(1, 2));
}
@Override
@ -91,14 +89,7 @@ public class LogTrackHistory extends ChildCommand<Log> {
Message.LOG_HISTORY_TRACK_HEADER.send(sender, name, page, maxPage);
for (Paginated.Entry<LoggedAction> e : entries) {
Message.LOG_ENTRY.send(sender,
e.position(),
DurationFormatter.CONCISE_LOW_ACCURACY.format(e.value().getDurationSince()),
e.value().getSourceFriendlyString(),
Character.toString(LoggedAction.getTypeCharacter(e.value().getTarget().getType())),
e.value().getTargetFriendlyString(),
e.value().getDescription()
);
Message.LOG_ENTRY.send(sender, e.position(), e.value());
}
return CommandResult.SUCCESS;

View File

@ -30,13 +30,11 @@ import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Paginated;
import me.lucko.luckperms.common.util.Predicates;
@ -46,8 +44,8 @@ import java.util.UUID;
public class LogUserHistory extends ChildCommand<Log> {
private static final int ENTRIES_PER_PAGE = 10;
public LogUserHistory(LocaleManager locale) {
super(CommandSpec.LOG_USER_HISTORY.localize(locale), "userhistory", CommandPermission.LOG_USER_HISTORY, Predicates.notInRange(1, 2));
public LogUserHistory() {
super(CommandSpec.LOG_USER_HISTORY, "userhistory", CommandPermission.LOG_USER_HISTORY, Predicates.notInRange(1, 2));
}
@Override
@ -84,14 +82,7 @@ public class LogUserHistory extends ChildCommand<Log> {
Message.LOG_HISTORY_USER_HEADER.send(sender, name, page, maxPage);
for (Paginated.Entry<LoggedAction> e : entries) {
Message.LOG_ENTRY.send(sender,
e.position(),
DurationFormatter.CONCISE_LOW_ACCURACY.format(e.value().getDurationSince()),
e.value().getSourceFriendlyString(),
Character.toString(LoggedAction.getTypeCharacter(e.value().getTarget().getType())),
e.value().getTargetFriendlyString(),
e.value().getDescription()
);
Message.LOG_ENTRY.send(sender, e.position(), e.value());
}
return CommandResult.SUCCESS;

View File

@ -32,9 +32,8 @@ import me.lucko.luckperms.common.command.abstraction.ChildCommand;
import me.lucko.luckperms.common.command.abstraction.Command;
import me.lucko.luckperms.common.command.abstraction.ParentCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
@ -63,19 +62,19 @@ public class MigrationParentCommand extends ParentCommand<Object, Void> {
private List<Command<Object>> commands = null;
private boolean display = true;
public MigrationParentCommand(LocaleManager locale) {
super(CommandSpec.MIGRATION.localize(locale), "Migration", Type.NO_TARGET_ARGUMENT, null);
public MigrationParentCommand() {
super(CommandSpec.MIGRATION, "Migration", Type.NO_TARGET_ARGUMENT, null);
}
@Override
public synchronized @NonNull List<Command<Object>> getChildren() {
if (this.commands == null) {
this.commands = getAvailableCommands(getSpec().getLocaleManager());
this.commands = getAvailableCommands();
// Add dummy command to show in the list.
if (this.commands.isEmpty()) {
this.display = false;
this.commands.add(new ChildCommand<Object>(CommandSpec.MIGRATION_COMMAND.localize(getSpec().getLocaleManager()), "No available plugins to migrate from", CommandPermission.MIGRATION, Predicates.alwaysFalse()) {
this.commands.add(new ChildCommand<Object>(CommandSpec.MIGRATION_COMMAND, "No available plugins to migrate from", CommandPermission.MIGRATION, Predicates.alwaysFalse()) {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, ArgumentList args, String label) {
return CommandResult.SUCCESS;
@ -98,13 +97,13 @@ public class MigrationParentCommand extends ParentCommand<Object, Void> {
}
@SuppressWarnings("unchecked")
private static List<Command<Object>> getAvailableCommands(LocaleManager locale) {
private static List<Command<Object>> getAvailableCommands() {
List<Command<Object>> available = new ArrayList<>();
for (Map.Entry<String, String> plugin : PLUGINS.entrySet()) {
try {
Class.forName(plugin.getKey());
available.add((ChildCommand<Object>) Class.forName(plugin.getValue()).getConstructor(LocaleManager.class).newInstance(locale));
available.add((ChildCommand<Object>) Class.forName(plugin.getValue()).getConstructor().newInstance());
} catch (Throwable ignored) {}
}

View File

@ -30,11 +30,10 @@ import com.google.gson.JsonObject;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.http.UnsuccessfulRequestException;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
@ -43,8 +42,8 @@ import me.lucko.luckperms.common.webeditor.WebEditorResponse;
import java.io.IOException;
public class ApplyEditsCommand extends SingleCommand {
public ApplyEditsCommand(LocaleManager locale) {
super(CommandSpec.APPLY_EDITS.localize(locale), "ApplyEdits", CommandPermission.APPLY_EDITS, Predicates.notInRange(1, 2));
public ApplyEditsCommand() {
super(CommandSpec.APPLY_EDITS, "ApplyEdits", CommandPermission.APPLY_EDITS, Predicates.notInRange(1, 2));
}
@Override

View File

@ -41,11 +41,10 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.CommandException;
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentException;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.CaffeineFactory;
@ -57,8 +56,8 @@ import java.util.concurrent.TimeUnit;
public class BulkUpdateCommand extends SingleCommand {
private final Cache<String, BulkUpdate> pendingOperations = CaffeineFactory.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build();
public BulkUpdateCommand(LocaleManager locale) {
super(CommandSpec.BULK_UPDATE.localize(locale), "BulkUpdate", CommandPermission.BULK_UPDATE, Predicates.alwaysFalse());
public BulkUpdateCommand() {
super(CommandSpec.BULK_UPDATE, "BulkUpdate", CommandPermission.BULK_UPDATE, Predicates.alwaysFalse());
}
@Override

View File

@ -28,14 +28,12 @@ package me.lucko.luckperms.common.commands.misc;
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.spec.CommandSpec;
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.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -49,8 +47,8 @@ import java.util.List;
import java.util.UUID;
public class CheckCommand extends SingleCommand {
public CheckCommand(LocaleManager locale) {
super(CommandSpec.CHECK.localize(locale), "Check", CommandPermission.CHECK, Predicates.not(2));
public CheckCommand() {
super(CommandSpec.CHECK, "Check", CommandPermission.CHECK, Predicates.not(2));
}
@Override
@ -72,7 +70,7 @@ public class CheckCommand extends SingleCommand {
}
Tristate tristate = user.getCachedData().getPermissionData(user.getQueryOptions()).checkPermission(permission, PermissionCheckEvent.Origin.INTERNAL).result();
Message.CHECK_RESULT.send(sender, user.getFormattedDisplayName(), permission, MessageUtils.formatTristate(tristate));
Message.CHECK_RESULT.send(sender, user.getFormattedDisplayName(), permission, tristate);
return CommandResult.SUCCESS;
}

View File

@ -29,11 +29,10 @@ import me.lucko.luckperms.common.command.CommandResult;
import me.lucko.luckperms.common.command.abstraction.SingleCommand;
import me.lucko.luckperms.common.command.access.ArgumentPermissions;
import me.lucko.luckperms.common.command.access.CommandPermission;
import me.lucko.luckperms.common.command.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.Track;
@ -60,8 +59,8 @@ import java.util.UUID;
public class EditorCommand extends SingleCommand {
public static final int MAX_USERS = 1000;
public EditorCommand(LocaleManager locale) {
super(CommandSpec.EDITOR.localize(locale), "Editor", CommandPermission.EDITOR, Predicates.notInRange(0, 2));
public EditorCommand() {
super(CommandSpec.EDITOR, "Editor", CommandPermission.EDITOR, Predicates.notInRange(0, 2));
}
@Override

View File

@ -29,10 +29,9 @@ import me.lucko.luckperms.common.backup.Exporter;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
@ -45,8 +44,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class ExportCommand extends SingleCommand {
private final AtomicBoolean running = new AtomicBoolean(false);
public ExportCommand(LocaleManager locale) {
super(CommandSpec.EXPORT.localize(locale), "Export", CommandPermission.EXPORT, Predicates.notInRange(1, 2));
public ExportCommand() {
super(CommandSpec.EXPORT, "Export", CommandPermission.EXPORT, Predicates.notInRange(1, 2));
}
@Override
@ -78,20 +77,20 @@ public class ExportCommand extends SingleCommand {
}
if (Files.exists(path)) {
Message.LOG_EXPORT_ALREADY_EXISTS.send(sender, path.toString());
Message.EXPORT_FILE_ALREADY_EXISTS.send(sender, path.toString());
return CommandResult.INVALID_ARGS;
}
try {
Files.createFile(path);
} catch (IOException e) {
Message.LOG_EXPORT_FAILURE.send(sender);
Message.EXPORT_FILE_FAILURE.send(sender);
e.printStackTrace();
return CommandResult.FAILURE;
}
if (!Files.isWritable(path)) {
Message.LOG_EXPORT_NOT_WRITABLE.send(sender, path.toString());
Message.EXPORT_FILE_NOT_WRITABLE.send(sender, path.toString());
return CommandResult.FAILURE;
}

View File

@ -31,11 +31,10 @@ import me.lucko.luckperms.common.backup.Importer;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.http.UnsuccessfulRequestException;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
@ -53,8 +52,8 @@ import java.util.zip.GZIPInputStream;
public class ImportCommand extends SingleCommand {
private final AtomicBoolean running = new AtomicBoolean(false);
public ImportCommand(LocaleManager locale) {
super(CommandSpec.IMPORT.localize(locale), "Import", CommandPermission.IMPORT, Predicates.notInRange(1, 2));
public ImportCommand() {
super(CommandSpec.IMPORT, "Import", CommandPermission.IMPORT, Predicates.notInRange(1, 2));
}
@Override
@ -112,18 +111,18 @@ public class ImportCommand extends SingleCommand {
String code = args.get(0);
if (code.isEmpty()) {
Message.IMPORT_INVALID_CODE.send(sender, code);
Message.IMPORT_WEB_INVALID_CODE.send(sender, code);
return CommandResult.INVALID_ARGS;
}
try {
data = plugin.getBytebin().getJsonContent(code).getAsJsonObject();
} catch (UnsuccessfulRequestException e) {
Message.IMPORT_HTTP_REQUEST_FAILURE.send(sender, e.getResponse().code(), e.getResponse().message());
Message.HTTP_REQUEST_FAILURE.send(sender, e.getResponse().code(), e.getResponse().message());
return CommandResult.STATE_ERROR;
} catch (IOException e) {
new RuntimeException("Error reading data to bytebin", e).printStackTrace();
Message.IMPORT_HTTP_UNKNOWN_FAILURE.send(sender);
Message.HTTP_UNKNOWN_FAILURE.send(sender);
return CommandResult.STATE_ERROR;
}

View File

@ -28,81 +28,25 @@ package me.lucko.luckperms.common.commands.misc;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.messaging.InternalMessagingService;
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.extension.Extension;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
import java.util.Map;
public class InfoCommand extends SingleCommand {
public InfoCommand(LocaleManager locale) {
super(CommandSpec.INFO.localize(locale), "Info", CommandPermission.INFO, Predicates.alwaysFalse());
public InfoCommand() {
super(CommandSpec.INFO, "Info", CommandPermission.INFO, Predicates.alwaysFalse());
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
Map<String, String> storageMeta = plugin.getStorage().getMeta();
Message.INFO_HEADER.send(sender,
AbstractLuckPermsPlugin.getPluginName(),
plugin.getBootstrap().getVersion(),
plugin.getBootstrap().getType().getFriendlyName(),
plugin.getBootstrap().getServerBrand(),
plugin.getBootstrap().getServerVersion()
);
Message.INFO_STORAGE.send(sender, plugin.getStorage().getName());
for (Map.Entry<String, String> e : storageMeta.entrySet()) {
Message.INFO_STORAGE_META.send(sender, e.getKey(), formatValue(e.getValue()));
}
Collection<Extension> loadedExtensions = plugin.getExtensionManager().getLoadedExtensions();
if (!loadedExtensions.isEmpty()) {
Message.INFO_EXTENSIONS.send(sender);
for (Extension extension : loadedExtensions) {
Message.INFO_EXTENSION_ENTRY.send(sender, extension.getClass().getName());
}
}
ImmutableContextSet staticContext = plugin.getContextManager().getStaticContext();
Message.INFO_MIDDLE.send(sender,
plugin.getMessagingService().map(InternalMessagingService::getName).orElse("None"),
staticContext.isEmpty() ? "None" : MessageUtils.contextSetToString(plugin.getLocaleManager(), staticContext),
plugin.getBootstrap().getPlayerCount(),
plugin.getConnectionListener().getUniqueConnections().size(),
DurationFormatter.CONCISE_LOW_ACCURACY.format(Duration.between(plugin.getBootstrap().getStartupTime(), Instant.now())),
plugin.getUserManager().getAll().size(),
plugin.getGroupManager().getAll().size(),
plugin.getTrackManager().getAll().size()
);
Message.INFO.send(sender, plugin, storageMeta);
return CommandResult.SUCCESS;
}
private static String formatValue(String value) {
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
return MessageUtils.formatBoolean(Boolean.parseBoolean(value));
}
try {
int i = Integer.parseInt(value);
return "&a" + i;
} catch (NumberFormatException ignored) {}
return "&f" + value;
}
}

View File

@ -28,10 +28,9 @@ package me.lucko.luckperms.common.commands.misc;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.messaging.InternalMessagingService;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -40,8 +39,8 @@ import me.lucko.luckperms.common.util.Predicates;
import java.util.Optional;
public class NetworkSyncCommand extends SingleCommand {
public NetworkSyncCommand(LocaleManager locale) {
super(CommandSpec.NETWORK_SYNC.localize(locale), "NetworkSync", CommandPermission.SYNC, Predicates.alwaysFalse());
public NetworkSyncCommand() {
super(CommandSpec.NETWORK_SYNC, "NetworkSync", CommandPermission.SYNC, Predicates.alwaysFalse());
}
@Override

View File

@ -28,17 +28,16 @@ package me.lucko.luckperms.common.commands.misc;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
public class ReloadConfigCommand extends SingleCommand {
public ReloadConfigCommand(LocaleManager locale) {
super(CommandSpec.RELOAD_CONFIG.localize(locale), "ReloadConfig", CommandPermission.RELOAD_CONFIG, Predicates.alwaysFalse());
public ReloadConfigCommand() {
super(CommandSpec.RELOAD_CONFIG, "ReloadConfig", CommandPermission.RELOAD_CONFIG, Predicates.alwaysFalse());
}
@Override

View File

@ -34,44 +34,34 @@ import me.lucko.luckperms.common.cache.LoadingMap;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.tabcomplete.TabCompletions;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.command.utils.MessageUtils;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.HolderType;
import me.lucko.luckperms.common.node.comparator.NodeEntryComparator;
import me.lucko.luckperms.common.node.factory.NodeCommandFactory;
import me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher;
import me.lucko.luckperms.common.node.matcher.StandardNodeMatchers;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.storage.misc.NodeEntry;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Iterators;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.node.Node;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
public class SearchCommand extends SingleCommand {
public SearchCommand(LocaleManager locale) {
super(CommandSpec.SEARCH.localize(locale), "Search", CommandPermission.SEARCH, Predicates.notInRange(1, 3));
public SearchCommand() {
super(CommandSpec.SEARCH, "Search", CommandPermission.SEARCH, Predicates.notInRange(1, 3));
}
@Override
@ -85,7 +75,7 @@ public class SearchCommand extends SingleCommand {
ConstraintNodeMatcher<Node> matcher = StandardNodeMatchers.of(Constraint.of(comparison, args.get(1)));
int page = args.getIntOrDefault(2, 1);
Message.SEARCH_SEARCHING.send(sender, matcher);
Message.SEARCH_SEARCHING.send(sender, matcher.toString());
List<NodeEntry<UUID, Node>> matchedUsers = plugin.getStorage().searchUserNodes(matcher).join();
List<NodeEntry<String, Node>> matchedGroups = plugin.getStorage().searchGroupNodes(matcher).join();
@ -128,7 +118,7 @@ public class SearchCommand extends SingleCommand {
.complete(args);
}
private static <T extends Comparable<T>> void sendResult(Sender sender, List<NodeEntry<T, Node>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page, Comparison comparison) {
private static <T extends Comparable<T>> void sendResult(Sender sender, List<NodeEntry<T, Node>> results, Function<T, String> lookupFunction, Message.Args3<Integer, Integer, Integer> headerMessage, HolderType holderType, String label, int page, Comparison comparison) {
results = new ArrayList<>(results);
results.sort(NodeEntryComparator.normal());
@ -150,40 +140,7 @@ public class SearchCommand extends SingleCommand {
headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, NodeEntry<T, Node>> ent : mappedContent) {
// only show the permission in the results if the comparison isn't equals
String permission = "";
if (comparison != StandardComparison.EQUAL) {
permission = "&7 - (" + ent.getValue().getNode().getKey() + ")";
}
String s = "&3> &b" + ent.getKey() + permission + "&7 - " + (ent.getValue().getNode().getValue() ? "&a" : "&c") + ent.getValue().getNode().getValue() + getNodeExpiryString(ent.getValue().getNode()) + MessageUtils.getAppendableNodeContextString(sender.getPlugin().getLocaleManager(), ent.getValue().getNode());
TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue(), sender.getPlugin())).build();
sender.sendMessage(message);
Message.SEARCH_NODE_ENTRY.send(sender, comparison != StandardComparison.EQUAL, ent.getValue().getNode(), ent.getKey(), holderType, label, sender.getPlugin());
}
}
private static String getNodeExpiryString(Node node) {
if (!node.hasExpiry()) {
return "";
}
return " &8(&7expires in " + DurationFormatter.LONG.format(node.getExpiryDuration()) + "&8)";
}
private static Consumer<ComponentBuilder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, NodeEntry<?, ?> perm, LuckPermsPlugin plugin) {
HoverEvent hoverEvent = HoverEvent.showText(TextUtils.fromLegacy(TextUtils.joinNewline(
"&3> " + (perm.getNode().getValue() ? "&a" : "&c") + perm.getNode().getKey(),
" ",
"&7Click to remove this node from " + holderName
), TextUtils.AMPERSAND_CHAR));
boolean explicitGlobalContext = !plugin.getConfiguration().getContextsFile().getDefaultContexts().isEmpty();
String command = "/" + label + " " + NodeCommandFactory.undoCommand(perm.getNode(), holderName, holderType, explicitGlobalContext);
ClickEvent clickEvent = ClickEvent.suggestCommand(command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
}

View File

@ -28,17 +28,16 @@ package me.lucko.luckperms.common.commands.misc;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
public class SyncCommand extends SingleCommand {
public SyncCommand(LocaleManager locale) {
super(CommandSpec.SYNC.localize(locale), "Sync", CommandPermission.SYNC, Predicates.alwaysFalse());
public SyncCommand() {
super(CommandSpec.SYNC, "Sync", CommandPermission.SYNC, Predicates.alwaysFalse());
}
@Override

View File

@ -29,12 +29,11 @@ import me.lucko.luckperms.common.cacheddata.type.PermissionCache;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.http.UnsuccessfulRequestException;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -42,18 +41,12 @@ import me.lucko.luckperms.common.treeview.TreeView;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.Uuids;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.format.TextColor;
import java.io.IOException;
import java.util.UUID;
public class TreeCommand extends SingleCommand {
public TreeCommand(LocaleManager locale) {
super(CommandSpec.TREE.localize(locale), "Tree", CommandPermission.TREE, Predicates.alwaysFalse());
public TreeCommand() {
super(CommandSpec.TREE, "Tree", CommandPermission.TREE, Predicates.alwaysFalse());
}
@Override
@ -107,15 +100,7 @@ public class TreeCommand extends SingleCommand {
}
String url = plugin.getConfiguration().get(ConfigKeys.TREE_VIEWER_URL_PATTERN) + id;
Message.TREE_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA)
.clickEvent(ClickEvent.openUrl(url))
.hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the tree view.").color(TextColor.GRAY)))
.build();
sender.sendMessage(message);
Message.TREE_URL.send(sender, url);
return CommandResult.SUCCESS;
}
}

View File

@ -28,14 +28,13 @@ package me.lucko.luckperms.common.commands.misc;
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.spec.CommandSpec;
import me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier;
import me.lucko.luckperms.common.command.tabcomplete.TabCompleter;
import me.lucko.luckperms.common.command.utils.ArgumentList;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.http.UnsuccessfulRequestException;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
@ -44,19 +43,13 @@ import me.lucko.luckperms.common.verbose.VerboseFilter;
import me.lucko.luckperms.common.verbose.VerboseHandler;
import me.lucko.luckperms.common.verbose.VerboseListener;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.format.TextColor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class VerboseCommand extends SingleCommand {
public VerboseCommand(LocaleManager locale) {
super(CommandSpec.VERBOSE.localize(locale), "Verbose", CommandPermission.VERBOSE, Predicates.is(0));
public VerboseCommand() {
super(CommandSpec.VERBOSE, "Verbose", CommandPermission.VERBOSE, Predicates.is(0));
}
@Override
@ -173,15 +166,7 @@ public class VerboseCommand extends SingleCommand {
}
String url = plugin.getConfiguration().get(ConfigKeys.VERBOSE_VIEWER_URL_PATTERN) + id;
Message.VERBOSE_RESULTS_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA)
.clickEvent(ClickEvent.openUrl(url))
.hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the results page.").color(TextColor.GRAY)))
.build();
sender.sendMessage(message);
Message.VERBOSE_RESULTS_URL.send(sender, url);
return CommandResult.SUCCESS;
}
} else {

Some files were not shown because too many files have changed in this diff Show More