mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-29 11:41:45 +01:00
Improve user info command
This commit is contained in:
parent
84bc4217de
commit
a3e6628e11
@ -35,7 +35,6 @@ import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
|
|||||||
import net.luckperms.api.model.data.DataMutateResult;
|
import net.luckperms.api.model.data.DataMutateResult;
|
||||||
import net.luckperms.api.model.data.DataType;
|
import net.luckperms.api.model.data.DataType;
|
||||||
import net.luckperms.api.node.NodeEqualityPredicate;
|
import net.luckperms.api.node.NodeEqualityPredicate;
|
||||||
import net.luckperms.api.query.QueryOptions;
|
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
@ -72,10 +71,7 @@ public class ApiUser extends ApiPermissionHolder implements net.luckperms.api.mo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull String getPrimaryGroup() {
|
public @NonNull String getPrimaryGroup() {
|
||||||
QueryOptions queryOptions = this.handle.getPlugin().getQueryOptionsForUser(this.handle)
|
String value = this.handle.getCachedData().getMetaData(this.handle.getQueryOptions()).getPrimaryGroup(MetaCheckEvent.Origin.LUCKPERMS_API);
|
||||||
.orElseGet(() -> this.handle.getPlugin().getContextManager().getStaticQueryOptions());
|
|
||||||
|
|
||||||
String value = this.handle.getCachedData().getMetaData(queryOptions).getPrimaryGroup(MetaCheckEvent.Origin.LUCKPERMS_API);
|
|
||||||
Objects.requireNonNull(value, "value"); // assert nonnull
|
Objects.requireNonNull(value, "value"); // assert nonnull
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class CheckCommand extends SingleCommand {
|
|||||||
return CommandResult.STATE_ERROR;
|
return CommandResult.STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tristate tristate = user.getCachedData().getPermissionData(plugin.getQueryOptionsForUser(user).orElse(plugin.getContextManager().getStaticQueryOptions())).checkPermission(permission, PermissionCheckEvent.Origin.INTERNAL).result();
|
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, MessageUtils.formatTristate(tristate));
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class TreeCommand extends SingleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Message.TREE_UPLOAD_START.send(sender);
|
Message.TREE_UPLOAD_START.send(sender);
|
||||||
PermissionCache permissionData = user == null ? null : user.getCachedData().getPermissionData(plugin.getQueryOptionsForUser(user).orElse(plugin.getContextManager().getStaticQueryOptions()));
|
PermissionCache permissionData = user == null ? null : user.getCachedData().getPermissionData(user.getQueryOptions());
|
||||||
|
|
||||||
String id;
|
String id;
|
||||||
try {
|
try {
|
||||||
|
@ -50,7 +50,6 @@ import net.luckperms.api.query.QueryOptions;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class UserInfo extends ChildCommand<User> {
|
public class UserInfo extends ChildCommand<User> {
|
||||||
@ -65,19 +64,12 @@ public class UserInfo extends ChildCommand<User> {
|
|||||||
return CommandResult.NO_PERMISSION;
|
return CommandResult.NO_PERMISSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<QueryOptions> queryOptions = plugin.getQueryOptionsForUser(user);
|
|
||||||
|
|
||||||
Message status = plugin.getBootstrap().isPlayerOnline(user.getUniqueId()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
|
Message status = plugin.getBootstrap().isPlayerOnline(user.getUniqueId()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
|
||||||
|
|
||||||
String primaryGroup = user.getCachedData().getMetaData(queryOptions.orElseGet(() -> plugin.getContextManager().getStaticQueryOptions()))
|
|
||||||
.getPrimaryGroup(MetaCheckEvent.Origin.INTERNAL);
|
|
||||||
|
|
||||||
Message.USER_INFO_GENERAL.send(sender,
|
Message.USER_INFO_GENERAL.send(sender,
|
||||||
user.getUsername().orElse("Unknown"),
|
user.getUsername().orElse("Unknown"),
|
||||||
user.getUniqueId(),
|
user.getUniqueId(),
|
||||||
user.getUniqueId().version() == 4 ? "&2mojang" : "&8offline",
|
user.getUniqueId().version() == 4 ? "&2mojang" : "&8offline",
|
||||||
status.asString(plugin.getLocaleManager()),
|
status.asString(plugin.getLocaleManager())
|
||||||
primaryGroup
|
|
||||||
);
|
);
|
||||||
|
|
||||||
List<InheritanceNode> parents = user.normalData().inheritanceAsSortedSet().stream()
|
List<InheritanceNode> parents = user.normalData().inheritanceAsSortedSet().stream()
|
||||||
@ -105,20 +97,27 @@ public class UserInfo extends ChildCommand<User> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QueryOptions queryOptions = plugin.getQueryOptionsForUser(user).orElse(null);
|
||||||
|
boolean active = true;
|
||||||
|
|
||||||
|
if (queryOptions == null) {
|
||||||
|
active = false;
|
||||||
|
queryOptions = plugin.getContextManager().getStaticQueryOptions();
|
||||||
|
}
|
||||||
|
|
||||||
String context = "&bNone";
|
String context = "&bNone";
|
||||||
String prefix = "&bNone";
|
String prefix = "&bNone";
|
||||||
String suffix = "&bNone";
|
String suffix = "&bNone";
|
||||||
String meta = "&bNone";
|
String meta = "&bNone";
|
||||||
|
|
||||||
if (queryOptions.isPresent()) {
|
ContextSet contextSet = queryOptions.context();
|
||||||
ContextSet contextSet = queryOptions.get().context();
|
|
||||||
if (!contextSet.isEmpty()) {
|
if (!contextSet.isEmpty()) {
|
||||||
context = contextSet.toSet().stream()
|
context = contextSet.toSet().stream()
|
||||||
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
|
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
|
||||||
.collect(Collectors.joining(" "));
|
.collect(Collectors.joining(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
MetaCache data = user.getCachedData().getMetaData(queryOptions.get());
|
MetaCache data = user.getCachedData().getMetaData(queryOptions);
|
||||||
String prefixValue = data.getPrefix(MetaCheckEvent.Origin.INTERNAL);
|
String prefixValue = data.getPrefix(MetaCheckEvent.Origin.INTERNAL);
|
||||||
if (prefixValue != null) {
|
if (prefixValue != null) {
|
||||||
prefix = "&f\"" + prefixValue + "&f\"";
|
prefix = "&f\"" + prefixValue + "&f\"";
|
||||||
@ -127,6 +126,7 @@ public class UserInfo extends ChildCommand<User> {
|
|||||||
if (sussexValue != null) {
|
if (sussexValue != null) {
|
||||||
suffix = "&f\"" + sussexValue + "&f\"";
|
suffix = "&f\"" + sussexValue + "&f\"";
|
||||||
}
|
}
|
||||||
|
String primaryGroup = user.getCachedData().getMetaData(queryOptions).getPrimaryGroup(MetaCheckEvent.Origin.INTERNAL);
|
||||||
|
|
||||||
Map<String, List<String>> metaMap = data.getMeta(MetaCheckEvent.Origin.INTERNAL);
|
Map<String, List<String>> metaMap = data.getMeta(MetaCheckEvent.Origin.INTERNAL);
|
||||||
if (!metaMap.isEmpty()) {
|
if (!metaMap.isEmpty()) {
|
||||||
@ -135,9 +135,8 @@ public class UserInfo extends ChildCommand<User> {
|
|||||||
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
|
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
|
||||||
.collect(Collectors.joining(" "));
|
.collect(Collectors.joining(" "));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Message.USER_INFO_DATA.send(sender, MessageUtils.formatBoolean(queryOptions != null), context, prefix, suffix, meta);
|
Message.USER_INFO_DATA.send(sender, active ? "&2active player" : "&8server", context, prefix, suffix, primaryGroup, meta);
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,28 +211,28 @@ public enum Message {
|
|||||||
"{PREFIX}&f- &3Platform: &f{}" + "\n" +
|
"{PREFIX}&f- &3Platform: &f{}" + "\n" +
|
||||||
"{PREFIX}&f- &3Server Brand: &f{}" + "\n" +
|
"{PREFIX}&f- &3Server Brand: &f{}" + "\n" +
|
||||||
"{PREFIX}&f- &3Server Version:" + "\n" +
|
"{PREFIX}&f- &3Server Version:" + "\n" +
|
||||||
"{PREFIX}&f- {}",
|
"{PREFIX} &f{}",
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
|
|
||||||
INFO_STORAGE(
|
INFO_STORAGE(
|
||||||
"{PREFIX}&f- &bStorage:" + "\n" +
|
"{PREFIX}&f- &bStorage:" + "\n" +
|
||||||
"{PREFIX}&f- &3Type: &f{}",
|
"{PREFIX} &3Type: &f{}",
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
|
|
||||||
INFO_STORAGE_META("&f- &3{}: {}", true),
|
INFO_STORAGE_META(" &3{}: {}", true),
|
||||||
|
|
||||||
INFO_EXTENSIONS("{PREFIX}&f- &bExtensions:", true),
|
INFO_EXTENSIONS("{PREFIX}&f- &bExtensions:", true),
|
||||||
INFO_EXTENSION_ENTRY("&f- &3{}", true),
|
INFO_EXTENSION_ENTRY(" &3{}", true),
|
||||||
|
|
||||||
INFO_MIDDLE(
|
INFO_MIDDLE(
|
||||||
"{PREFIX}&f- &bMessaging: &f{}" + "\n" +
|
"{PREFIX}&f- &bMessaging: &f{}" + "\n" +
|
||||||
"{PREFIX}&f- &bInstance:" + "\n" +
|
"{PREFIX}&f- &bInstance:" + "\n" +
|
||||||
"{PREFIX}&f- &3Static contexts: &f{}" + "\n" +
|
"{PREFIX} &3Static contexts: &f{}" + "\n" +
|
||||||
"{PREFIX}&f- &3Online Players: &a{} &7(&a{}&7 unique)" + "\n" +
|
"{PREFIX} &3Online Players: &a{} &7(&a{}&7 unique)" + "\n" +
|
||||||
"{PREFIX}&f- &3Uptime: &7{}" + "\n" +
|
"{PREFIX} &3Uptime: &7{}" + "\n" +
|
||||||
"{PREFIX}&f- &3Local Data: &a{} &7users, &a{} &7groups, &a{} &7tracks",
|
"{PREFIX} &3Local Data: &a{} &7users, &a{} &7groups, &a{} &7tracks",
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -355,26 +355,27 @@ public enum Message {
|
|||||||
|
|
||||||
USER_INFO_GENERAL(
|
USER_INFO_GENERAL(
|
||||||
"{PREFIX}&b&l> &bUser Info: &f{}" + "\n" +
|
"{PREFIX}&b&l> &bUser Info: &f{}" + "\n" +
|
||||||
"{PREFIX}&f- &3UUID: &f{} &7(type: {}&7)" + "\n" +
|
"{PREFIX}&f- &3UUID: &f{}" + "\n" +
|
||||||
"{PREFIX}&f- &3Status: {}" + "\n" +
|
"{PREFIX}&f &7(type: {}&7)" + "\n" +
|
||||||
"{PREFIX}&f- &3Primary Group: &f{}",
|
"{PREFIX}&f- &3Status: {}",
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
|
|
||||||
USER_INFO_DATA(
|
USER_INFO_DATA(
|
||||||
"{PREFIX}&f- &aContextual Data:" + "\n" +
|
"{PREFIX}&f- &aContextual Data:" + "\n" +
|
||||||
"{PREFIX}&f- &3Has contextual data: {}" + "\n" +
|
"{PREFIX} &3Type: {}" + "\n" +
|
||||||
"{PREFIX}&f- &3Applicable contexts: {}" + "\n" +
|
"{PREFIX} &3Contexts: {}" + "\n" +
|
||||||
"{PREFIX}&f- &3Prefix: {}" + "\n" +
|
"{PREFIX} &3Prefix: {}" + "\n" +
|
||||||
"{PREFIX}&f- &3Suffix: {}" + "\n" +
|
"{PREFIX} &3Suffix: {}" + "\n" +
|
||||||
"{PREFIX}&f- &3Meta: {}",
|
"{PREFIX} &3Primary Group: &f{}" + "\n" +
|
||||||
|
"{PREFIX} &3Meta: {}",
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
|
|
||||||
INFO_PARENT_HEADER("&f- &aParent Groups:", true),
|
INFO_PARENT_HEADER("&f- &aParent Groups:", true),
|
||||||
INFO_TEMP_PARENT_HEADER("&f- &aTemporary Parent Groups:", true),
|
INFO_TEMP_PARENT_HEADER("&f- &aTemporary Parent Groups:", true),
|
||||||
INFO_PARENT_ENTRY("&f- &3> &f{}{}", true),
|
INFO_PARENT_ENTRY(" &3> &f{}{}", true),
|
||||||
INFO_PARENT_ENTRY_EXPIRY("&f- &2- expires in {}", true),
|
INFO_PARENT_ENTRY_EXPIRY(" &2- expires in {}", true),
|
||||||
USER_REMOVEGROUP_ERROR_PRIMARY("&aYou cannot remove a user from their primary group.", true),
|
USER_REMOVEGROUP_ERROR_PRIMARY("&aYou cannot remove a user from their primary group.", true),
|
||||||
USER_PRIMARYGROUP_SUCCESS("&b{}&a's primary group was set to &b{}&a.", true),
|
USER_PRIMARYGROUP_SUCCESS("&b{}&a's primary group was set to &b{}&a.", true),
|
||||||
USER_PRIMARYGROUP_WARN_OPTION("&aWarning: The primary group calculation method being used by this server &7({}) &amay not reflect this change.", true),
|
USER_PRIMARYGROUP_WARN_OPTION("&aWarning: The primary group calculation method being used by this server &7({}) &amay not reflect this change.", true),
|
||||||
|
Loading…
Reference in New Issue
Block a user