diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java index 67d6e2bc2..55be88c53 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java @@ -34,8 +34,6 @@ import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.model.HolderType; import me.lucko.luckperms.common.model.PermissionHolder; -import net.luckperms.api.node.ChatMetaType; - public class CommandMeta extends GenericParentCommand { public CommandMeta(LocaleManager locale, HolderType type) { super(CommandSpec.META.localize(locale), "Meta", type, ImmutableList.builder() @@ -44,18 +42,18 @@ public class CommandMeta extends GenericParentComman .add(new MetaUnset(locale)) .add(new MetaSetTemp(locale)) .add(new MetaUnsetTemp(locale)) - .add(new MetaAddChatMeta(locale, ChatMetaType.PREFIX)) - .add(new MetaAddChatMeta(locale, ChatMetaType.SUFFIX)) - .add(new MetaSetChatMeta(locale, ChatMetaType.PREFIX)) - .add(new MetaSetChatMeta(locale, ChatMetaType.SUFFIX)) - .add(new MetaRemoveChatMeta(locale, ChatMetaType.PREFIX)) - .add(new MetaRemoveChatMeta(locale, ChatMetaType.SUFFIX)) - .add(new MetaAddTempChatMeta(locale, ChatMetaType.PREFIX)) - .add(new MetaAddTempChatMeta(locale, ChatMetaType.SUFFIX)) - .add(new MetaSetTempChatMeta(locale, ChatMetaType.PREFIX)) - .add(new MetaSetTempChatMeta(locale, ChatMetaType.SUFFIX)) - .add(new MetaRemoveTempChatMeta(locale, ChatMetaType.PREFIX)) - .add(new MetaRemoveTempChatMeta(locale, ChatMetaType.SUFFIX)) + .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)) .build()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java index f5477995b..d59e9e477 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java @@ -38,6 +38,7 @@ 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.model.PermissionHolder; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -55,16 +56,31 @@ import net.luckperms.api.node.ChatMetaType; import java.util.List; public class MetaAddChatMeta extends GenericChildCommand { + + public static MetaAddChatMeta forPrefix(LocaleManager locale) { + return new MetaAddChatMeta( + ChatMetaType.PREFIX, + CommandSpec.META_ADDPREFIX.localize(locale), + "addprefix", + CommandPermission.USER_META_ADD_PREFIX, + CommandPermission.GROUP_META_ADD_PREFIX + ); + } + + public static MetaAddChatMeta forSuffix(LocaleManager locale) { + return new MetaAddChatMeta( + ChatMetaType.SUFFIX, + CommandSpec.META_ADDSUFFIX.localize(locale), + "addsuffix", + CommandPermission.USER_META_ADD_SUFFIX, + CommandPermission.GROUP_META_ADD_SUFFIX + ); + } + private final ChatMetaType type; - public MetaAddChatMeta(LocaleManager locale, ChatMetaType type) { - super( - type == ChatMetaType.PREFIX ? CommandSpec.META_ADDPREFIX.localize(locale) : CommandSpec.META_ADDSUFFIX.localize(locale), - "add" + type.name().toLowerCase(), - type == ChatMetaType.PREFIX ? CommandPermission.USER_META_ADD_PREFIX : CommandPermission.USER_META_ADD_SUFFIX, - type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_ADD_PREFIX : CommandPermission.GROUP_META_ADD_SUFFIX, - Predicates.inRange(0, 1) - ); + private MetaAddChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) { + super(spec, name, userPermission, groupPermission, Predicates.inRange(0, 1)); this.type = type; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java index 578761353..3a2edd8e2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java @@ -39,6 +39,7 @@ 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.model.PermissionHolder; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -59,16 +60,31 @@ import java.time.Duration; import java.util.List; public class MetaAddTempChatMeta extends GenericChildCommand { + + public static MetaAddTempChatMeta forPrefix(LocaleManager locale) { + return new MetaAddTempChatMeta( + ChatMetaType.PREFIX, + CommandSpec.META_ADDTEMP_PREFIX.localize(locale), + "addtempprefix", + CommandPermission.USER_META_ADD_TEMP_PREFIX, + CommandPermission.GROUP_META_ADD_TEMP_PREFIX + ); + } + + public static MetaAddTempChatMeta forSuffix(LocaleManager locale) { + return new MetaAddTempChatMeta( + ChatMetaType.SUFFIX, + CommandSpec.META_ADDTEMP_SUFFIX.localize(locale), + "addtempsuffix", + CommandPermission.USER_META_ADD_TEMP_SUFFIX, + CommandPermission.GROUP_META_ADD_TEMP_SUFFIX + ); + } + private final ChatMetaType type; - public MetaAddTempChatMeta(LocaleManager locale, ChatMetaType type) { - super( - type == ChatMetaType.PREFIX ? CommandSpec.META_ADDTEMP_PREFIX.localize(locale) : CommandSpec.META_ADDTEMP_SUFFIX.localize(locale), - "addtemp" + type.name().toLowerCase(), - type == ChatMetaType.PREFIX ? CommandPermission.USER_META_ADD_TEMP_PREFIX : CommandPermission.USER_META_ADD_TEMP_SUFFIX, - type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_ADD_TEMP_PREFIX : CommandPermission.GROUP_META_ADD_TEMP_SUFFIX, - Predicates.inRange(0, 2) - ); + private MetaAddTempChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) { + super(spec, name, userPermission, groupPermission, Predicates.inRange(0, 2)); this.type = type; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java index 5d5379ed2..804db26b9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java @@ -68,11 +68,6 @@ import java.util.TreeSet; import java.util.function.Consumer; public class MetaInfo extends GenericChildCommand { - private static String processLocation(Node node, PermissionHolder holder) { - String location = node.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName(); - return location.equalsIgnoreCase(holder.getObjectName()) ? "self" : location; - } - public MetaInfo(LocaleManager locale) { super(CommandSpec.META_INFO.localize(locale), "info", CommandPermission.USER_META_INFO, CommandPermission.GROUP_META_INFO, Predicates.alwaysFalse()); } @@ -129,6 +124,11 @@ public class MetaInfo extends GenericChildCommand { 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 meta, Sender sender, PermissionHolder holder, String label) { for (MetaNode m : meta) { String location = processLocation(m, holder); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java index 6084651e3..099ecff22 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java @@ -38,6 +38,7 @@ 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.model.PermissionHolder; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -55,16 +56,31 @@ import net.luckperms.api.node.ChatMetaType; import java.util.List; public class MetaRemoveChatMeta extends GenericChildCommand { + + public static MetaRemoveChatMeta forPrefix(LocaleManager locale) { + return new MetaRemoveChatMeta( + ChatMetaType.PREFIX, + CommandSpec.META_REMOVEPREFIX.localize(locale), + "removeprefix", + CommandPermission.USER_META_REMOVE_PREFIX, + CommandPermission.GROUP_META_REMOVE_PREFIX + ); + } + + public static MetaRemoveChatMeta forSuffix(LocaleManager locale) { + return new MetaRemoveChatMeta( + ChatMetaType.SUFFIX, + CommandSpec.META_REMOVESUFFIX.localize(locale), + "removesuffix", + CommandPermission.USER_META_REMOVE_SUFFIX, + CommandPermission.GROUP_META_REMOVE_SUFFIX + ); + } + private final ChatMetaType type; - public MetaRemoveChatMeta(LocaleManager locale, ChatMetaType type) { - super( - type == ChatMetaType.PREFIX ? CommandSpec.META_REMOVEPREFIX.localize(locale) : CommandSpec.META_REMOVESUFFIX.localize(locale), - "remove" + type.name().toLowerCase(), - type == ChatMetaType.PREFIX ? CommandPermission.USER_META_REMOVE_PREFIX : CommandPermission.USER_META_REMOVE_SUFFIX, - type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_REMOVE_PREFIX : CommandPermission.GROUP_META_REMOVE_SUFFIX, - Predicates.is(0) - ); + private MetaRemoveChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) { + super(spec, name, userPermission, groupPermission, Predicates.is(0)); this.type = type; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java index b26ecbed0..70352fcbe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java @@ -38,6 +38,7 @@ 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.model.PermissionHolder; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -55,16 +56,31 @@ import net.luckperms.api.node.ChatMetaType; import java.util.List; public class MetaRemoveTempChatMeta extends GenericChildCommand { + + public static MetaRemoveTempChatMeta forPrefix(LocaleManager locale) { + return new MetaRemoveTempChatMeta( + ChatMetaType.PREFIX, + CommandSpec.META_REMOVETEMP_PREFIX.localize(locale), + "removetempprefix", + CommandPermission.USER_META_REMOVE_TEMP_PREFIX, + CommandPermission.GROUP_META_REMOVE_TEMP_PREFIX + ); + } + + public static MetaRemoveTempChatMeta forSuffix(LocaleManager locale) { + return new MetaRemoveTempChatMeta( + ChatMetaType.SUFFIX, + CommandSpec.META_REMOVETEMP_SUFFIX.localize(locale), + "removetempsuffix", + CommandPermission.USER_META_REMOVE_TEMP_SUFFIX, + CommandPermission.GROUP_META_REMOVE_TEMP_SUFFIX + ); + } + private final ChatMetaType type; - public MetaRemoveTempChatMeta(LocaleManager locale, ChatMetaType type) { - super( - type == ChatMetaType.PREFIX ? CommandSpec.META_REMOVETEMP_PREFIX.localize(locale) : CommandSpec.META_REMOVETEMP_SUFFIX.localize(locale), - "removetemp" + type.name().toLowerCase(), - type == ChatMetaType.PREFIX ? CommandPermission.USER_META_REMOVE_TEMP_PREFIX : CommandPermission.USER_META_REMOVE_TEMP_SUFFIX, - type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_REMOVE_TEMP_PREFIX : CommandPermission.GROUP_META_REMOVE_TEMP_SUFFIX, - Predicates.is(0) - ); + private MetaRemoveTempChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) { + super(spec, name, userPermission, groupPermission, Predicates.is(0)); this.type = type; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java index afbcbe18d..15668a8f8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java @@ -39,6 +39,7 @@ 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.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; @@ -59,16 +60,31 @@ import java.util.List; import java.util.OptionalInt; public class MetaSetChatMeta extends GenericChildCommand { + + public static MetaSetChatMeta forPrefix(LocaleManager locale) { + return new MetaSetChatMeta( + ChatMetaType.PREFIX, + CommandSpec.META_SETPREFIX.localize(locale), + "setprefix", + CommandPermission.USER_META_SET_PREFIX, + CommandPermission.GROUP_META_SET_PREFIX + ); + } + + public static MetaSetChatMeta forSuffix(LocaleManager locale) { + return new MetaSetChatMeta( + ChatMetaType.SUFFIX, + CommandSpec.META_SETSUFFIX.localize(locale), + "setsuffix", + CommandPermission.USER_META_SET_SUFFIX, + CommandPermission.GROUP_META_SET_SUFFIX + ); + } + private final ChatMetaType type; - public MetaSetChatMeta(LocaleManager locale, ChatMetaType type) { - super( - type == ChatMetaType.PREFIX ? CommandSpec.META_SETPREFIX.localize(locale) : CommandSpec.META_SETSUFFIX.localize(locale), - "set" + type.name().toLowerCase(), - type == ChatMetaType.PREFIX ? CommandPermission.USER_META_SET_PREFIX : CommandPermission.USER_META_SET_SUFFIX, - type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_SET_PREFIX : CommandPermission.GROUP_META_SET_SUFFIX, - Predicates.is(0) - ); + private MetaSetChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) { + super(spec, name, userPermission, groupPermission, Predicates.is(0)); this.type = type; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java index fc88c1fb3..daed8eab2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java @@ -40,6 +40,7 @@ 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.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; @@ -63,16 +64,31 @@ import java.util.List; import java.util.OptionalInt; public class MetaSetTempChatMeta extends GenericChildCommand { + + public static MetaSetTempChatMeta forPrefix(LocaleManager locale) { + return new MetaSetTempChatMeta( + ChatMetaType.PREFIX, + CommandSpec.META_SETTEMP_PREFIX.localize(locale), + "settempprefix", + CommandPermission.USER_META_SET_TEMP_PREFIX, + CommandPermission.GROUP_META_SET_TEMP_PREFIX + ); + } + + public static MetaSetTempChatMeta forSuffix(LocaleManager locale) { + return new MetaSetTempChatMeta( + ChatMetaType.SUFFIX, + CommandSpec.META_SETTEMP_SUFFIX.localize(locale), + "settempsuffix", + CommandPermission.USER_META_SET_TEMP_SUFFIX, + CommandPermission.GROUP_META_SET_TEMP_SUFFIX + ); + } + private final ChatMetaType type; - public MetaSetTempChatMeta(LocaleManager locale, ChatMetaType type) { - super( - type == ChatMetaType.PREFIX ? CommandSpec.META_SETTEMP_PREFIX.localize(locale) : CommandSpec.META_SETTEMP_SUFFIX.localize(locale), - "settemp" + type.name().toLowerCase(), - type == ChatMetaType.PREFIX ? CommandPermission.USER_META_SET_TEMP_PREFIX : CommandPermission.USER_META_SET_TEMP_SUFFIX, - type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_SET_TEMP_PREFIX : CommandPermission.GROUP_META_SET_TEMP_SUFFIX, - Predicates.inRange(0, 1) - ); + private MetaSetTempChatMeta(ChatMetaType type, LocalizedCommandSpec spec, String name, CommandPermission userPermission, CommandPermission groupPermission) { + super(spec, name, userPermission, groupPermission, Predicates.inRange(0, 1)); this.type = type; }