mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-10-31 07:51:05 +01:00
Make 'meta info' and 'parent info' clickable (#311)
This commit is contained in:
parent
d23b29aeb1
commit
b12ce943f7
@ -35,6 +35,7 @@ import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
|||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
@ -45,6 +46,10 @@ import me.lucko.luckperms.common.locale.Message;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -80,7 +85,13 @@ public class MetaAddChatMeta extends SharedSubCommand {
|
|||||||
|
|
||||||
DataMutateResult result = holder.setPermission(NodeFactory.makeChatMetaNode(type, priority, meta).withExtraContext(context).build());
|
DataMutateResult result = holder.setPermission(NodeFactory.makeChatMetaNode(type, priority, meta).withExtraContext(context).build());
|
||||||
if (result.asBoolean()) {
|
if (result.asBoolean()) {
|
||||||
Message.ADD_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, Util.contextSetToString(context));
|
Component component = ComponentSerializer.parseFromLegacy(Message.ADD_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, Util.contextSetToString(context)), Constants.COLOR_CHAR);
|
||||||
|
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(
|
||||||
|
"¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta,
|
||||||
|
'¥'
|
||||||
|
));
|
||||||
|
component.applyRecursively(c -> c.hoverEvent(event));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
|
||||||
LogEntry.build().actor(sender).acted(holder)
|
LogEntry.build().actor(sender).acted(holder)
|
||||||
.action("meta add" + type.name().toLowerCase() + " " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
.action("meta add" + type.name().toLowerCase() + " " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
||||||
|
@ -37,6 +37,7 @@ import me.lucko.luckperms.common.commands.sender.Sender;
|
|||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.TemporaryModifier;
|
import me.lucko.luckperms.common.core.TemporaryModifier;
|
||||||
@ -49,6 +50,10 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|||||||
import me.lucko.luckperms.common.utils.DateUtil;
|
import me.lucko.luckperms.common.utils.DateUtil;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -90,7 +95,13 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
|
|||||||
if (ret.getKey().asBoolean()) {
|
if (ret.getKey().asBoolean()) {
|
||||||
duration = ret.getValue().getExpiryUnixTime();
|
duration = ret.getValue().getExpiryUnixTime();
|
||||||
|
|
||||||
Message.ADD_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, DateUtil.formatDateDiff(duration), Util.contextSetToString(context));
|
Component component = ComponentSerializer.parseFromLegacy(Message.ADD_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, DateUtil.formatDateDiff(duration), Util.contextSetToString(context)), Constants.COLOR_CHAR);
|
||||||
|
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(
|
||||||
|
"¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta,
|
||||||
|
'¥'
|
||||||
|
));
|
||||||
|
component.applyRecursively(c -> c.hoverEvent(event));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
|
||||||
LogEntry.build().actor(sender).acted(holder)
|
LogEntry.build().actor(sender).acted(holder)
|
||||||
.action("meta addtemp" + type.name().toLowerCase() + " " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
.action("meta addtemp" + type.name().toLowerCase() + " " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.commands.impl.generic.meta;
|
package me.lucko.luckperms.common.commands.impl.generic.meta;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.ChatMetaType;
|
||||||
import me.lucko.luckperms.api.LocalizedNode;
|
import me.lucko.luckperms.api.LocalizedNode;
|
||||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
@ -33,31 +36,37 @@ import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
|||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.MetaComparator;
|
import me.lucko.luckperms.common.commands.utils.MetaComparator;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
|
import me.lucko.luckperms.common.core.model.Group;
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.Message;
|
import me.lucko.luckperms.common.locale.Message;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.TextUtils;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.event.ClickEvent;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class MetaInfo extends SharedSubCommand {
|
public class MetaInfo extends SharedSubCommand {
|
||||||
private static String processLocation(LocalizedNode node, PermissionHolder holder) {
|
private static String processLocation(LocalizedNode node, PermissionHolder holder) {
|
||||||
return node.getLocation().equalsIgnoreCase(holder.getObjectName()) ? "self" : node.getLocation();
|
return node.getLocation().equalsIgnoreCase(holder.getObjectName()) ? "self" : node.getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatMetaValue(String val) {
|
|
||||||
return val.replace("&", "{color char}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetaInfo(LocaleManager locale) {
|
public MetaInfo(LocaleManager locale) {
|
||||||
super(CommandSpec.META_INFO.spec(locale), "info", Permission.USER_META_INFO, Permission.GROUP_META_INFO, Predicates.alwaysFalse());
|
super(CommandSpec.META_INFO.spec(locale), "info", Permission.USER_META_INFO, Permission.GROUP_META_INFO, Predicates.alwaysFalse());
|
||||||
}
|
}
|
||||||
@ -80,9 +89,9 @@ public class MetaInfo extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.isPrefix()) {
|
if (node.isPrefix()) {
|
||||||
prefixes.add(new AbstractMap.SimpleEntry<>(node.getPrefix().getKey(), node));
|
prefixes.add(Maps.immutableEntry(node.getPrefix().getKey(), node));
|
||||||
} else if (node.isSuffix()) {
|
} else if (node.isSuffix()) {
|
||||||
suffixes.add(new AbstractMap.SimpleEntry<>(node.getSuffix().getKey(), node));
|
suffixes.add(Maps.immutableEntry(node.getSuffix().getKey(), node));
|
||||||
} else if (node.isMeta()) {
|
} else if (node.isMeta()) {
|
||||||
meta.add(node);
|
meta.add(node);
|
||||||
}
|
}
|
||||||
@ -92,47 +101,113 @@ public class MetaInfo extends SharedSubCommand {
|
|||||||
Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
|
Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
|
||||||
} else {
|
} else {
|
||||||
Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName());
|
Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName());
|
||||||
for (Map.Entry<Integer, LocalizedNode> e : prefixes) {
|
sendChatMetaMessage(ChatMetaType.PREFIX, prefixes, sender, holder, label);
|
||||||
String location = processLocation(e.getValue(), holder);
|
|
||||||
if (e.getValue().isServerSpecific() || e.getValue().isWorldSpecific() || !e.getValue().getContexts().isEmpty()) {
|
|
||||||
String context = Util.getAppendableNodeContextString(e.getValue());
|
|
||||||
Message.CHAT_META_ENTRY_WITH_CONTEXT.send(sender, e.getKey(), e.getValue().getPrefix().getValue(), location, context);
|
|
||||||
} else {
|
|
||||||
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue().getPrefix().getValue(), location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suffixes.isEmpty()) {
|
if (suffixes.isEmpty()) {
|
||||||
Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName());
|
Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName());
|
||||||
} else {
|
} else {
|
||||||
Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName());
|
Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName());
|
||||||
for (Map.Entry<Integer, LocalizedNode> e : suffixes) {
|
sendChatMetaMessage(ChatMetaType.SUFFIX, suffixes, sender, holder, label);
|
||||||
String location = processLocation(e.getValue(), holder);
|
|
||||||
if (e.getValue().hasSpecificContext()) {
|
|
||||||
String context = Util.getAppendableNodeContextString(e.getValue());
|
|
||||||
Message.CHAT_META_ENTRY_WITH_CONTEXT.send(sender, e.getKey(), e.getValue().getSuffix().getValue(), location, context);
|
|
||||||
} else {
|
|
||||||
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue().getSuffix().getValue(), location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.isEmpty()) {
|
if (meta.isEmpty()) {
|
||||||
Message.META_NONE.send(sender, holder.getFriendlyName());
|
Message.META_NONE.send(sender, holder.getFriendlyName());
|
||||||
} else {
|
} else {
|
||||||
Message.META_HEADER.send(sender, holder.getFriendlyName());
|
Message.META_HEADER.send(sender, holder.getFriendlyName());
|
||||||
for (LocalizedNode m : meta) {
|
sendMetaMessage(meta, sender, holder, label);
|
||||||
String location = processLocation(m, holder);
|
|
||||||
if (m.hasSpecificContext()) {
|
|
||||||
String context = Util.getAppendableNodeContextString(m);
|
|
||||||
Message.META_ENTRY_WITH_CONTEXT.send(sender, m.getMeta().getKey(), m.getMeta().getValue(), location, context);
|
|
||||||
} else {
|
|
||||||
Message.META_ENTRY.send(sender, m.getMeta().getKey(), formatMetaValue(m.getMeta().getValue()), location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void sendMetaMessage(Set<LocalizedNode> meta, Sender sender, PermissionHolder holder, String label) {
|
||||||
|
for (LocalizedNode m : meta) {
|
||||||
|
String location = processLocation(m, holder);
|
||||||
|
if (m.hasSpecificContext()) {
|
||||||
|
String context = Util.getAppendableNodeContextString(m);
|
||||||
|
Component component = ComponentSerializer.parseFromLegacy(Message.META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context), Constants.COLOR_CHAR);
|
||||||
|
component.applyRecursively(makeFancy(holder, label, m));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
} else {
|
||||||
|
Component component = ComponentSerializer.parseFromLegacy(Message.META_ENTRY.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location), Constants.COLOR_CHAR);
|
||||||
|
component.applyRecursively(makeFancy(holder, label, m));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendChatMetaMessage(ChatMetaType type, SortedSet<Map.Entry<Integer, LocalizedNode>> meta, Sender sender, PermissionHolder holder, String label) {
|
||||||
|
for (Map.Entry<Integer, LocalizedNode> e : meta) {
|
||||||
|
String location = processLocation(e.getValue(), holder);
|
||||||
|
if (e.getValue().hasSpecificContext()) {
|
||||||
|
String context = Util.getAppendableNodeContextString(e.getValue());
|
||||||
|
Component component = ComponentSerializer.parseFromLegacy(Message.CHAT_META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), e.getKey(), e.getValue().getPrefix().getValue(), location, context), Constants.COLOR_CHAR);
|
||||||
|
component.applyRecursively(makeFancy(type, holder, label, e.getValue()));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
} else {
|
||||||
|
Component component = ComponentSerializer.parseFromLegacy(Message.CHAT_META_ENTRY.asString(sender.getPlatform().getLocaleManager(), e.getKey(), e.getValue().getPrefix().getValue(), location), Constants.COLOR_CHAR);
|
||||||
|
component.applyRecursively(makeFancy(type, holder, label, e.getValue()));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Consumer<Component> makeFancy(ChatMetaType type, PermissionHolder holder, String label, LocalizedNode node) {
|
||||||
|
if (!node.getLocation().equals(holder.getObjectName())) {
|
||||||
|
// inherited.
|
||||||
|
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
|
||||||
|
if (group != null) {
|
||||||
|
holder = group;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
|
||||||
|
"¥3> ¥a" + type.getEntry(node).getKey() + " ¥7- ¥r" + type.getEntry(node).getValue(),
|
||||||
|
" ",
|
||||||
|
"¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFriendlyName()
|
||||||
|
), '¥'));
|
||||||
|
|
||||||
|
boolean group = !(holder instanceof User);
|
||||||
|
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group)
|
||||||
|
.replace("/luckperms", "/" + label)
|
||||||
|
.replace("permission set", "permission unset")
|
||||||
|
.replace("parent add", "parent remove")
|
||||||
|
.replace(" true", "")
|
||||||
|
.replace(" false", "");
|
||||||
|
|
||||||
|
return component -> {
|
||||||
|
component.hoverEvent(hoverEvent);
|
||||||
|
component.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Consumer<Component> makeFancy(PermissionHolder holder, String label, LocalizedNode node) {
|
||||||
|
if (!node.getLocation().equals(holder.getObjectName())) {
|
||||||
|
// inherited.
|
||||||
|
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
|
||||||
|
if (group != null) {
|
||||||
|
holder = group;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
|
||||||
|
"¥3> ¥r" + node.getMeta().getKey() + " ¥7- ¥r" + node.getMeta().getValue(),
|
||||||
|
" ",
|
||||||
|
"¥7Click to remove this meta pair from " + holder.getFriendlyName()
|
||||||
|
), '¥'));
|
||||||
|
|
||||||
|
boolean group = !(holder instanceof User);
|
||||||
|
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group)
|
||||||
|
.replace("/luckperms", "/" + label)
|
||||||
|
.replace("permission set", "permission unset")
|
||||||
|
.replace("parent add", "parent remove")
|
||||||
|
.replace(" true", "")
|
||||||
|
.replace(" false", "");
|
||||||
|
|
||||||
|
return component -> {
|
||||||
|
component.hoverEvent(hoverEvent);
|
||||||
|
component.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
|||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
@ -45,6 +46,10 @@ import me.lucko.luckperms.common.locale.Message;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -94,7 +99,13 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
|
|||||||
DataMutateResult result = holder.unsetPermission(NodeFactory.makeChatMetaNode(type, priority, meta).withExtraContext(context).build());
|
DataMutateResult result = holder.unsetPermission(NodeFactory.makeChatMetaNode(type, priority, meta).withExtraContext(context).build());
|
||||||
|
|
||||||
if (result.asBoolean()) {
|
if (result.asBoolean()) {
|
||||||
Message.REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, Util.contextSetToString(context));
|
Component component = ComponentSerializer.parseFromLegacy(Message.REMOVE_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, Util.contextSetToString(context)), Constants.COLOR_CHAR);
|
||||||
|
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(
|
||||||
|
"¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta,
|
||||||
|
'¥'
|
||||||
|
));
|
||||||
|
component.applyRecursively(c -> c.hoverEvent(event));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
|
||||||
LogEntry.build().actor(sender).acted(holder)
|
LogEntry.build().actor(sender).acted(holder)
|
||||||
.action("meta remove" + type.name().toLowerCase() + " " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
.action("meta remove" + type.name().toLowerCase() + " " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
||||||
|
@ -35,6 +35,7 @@ import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
|||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
@ -45,6 +46,10 @@ import me.lucko.luckperms.common.locale.Message;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -94,7 +99,13 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
|
|||||||
DataMutateResult result = holder.unsetPermission(NodeFactory.makeChatMetaNode(type, priority, meta).setExpiry(10L).withExtraContext(context).build());
|
DataMutateResult result = holder.unsetPermission(NodeFactory.makeChatMetaNode(type, priority, meta).setExpiry(10L).withExtraContext(context).build());
|
||||||
|
|
||||||
if (result.asBoolean()) {
|
if (result.asBoolean()) {
|
||||||
Message.REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, Util.contextSetToString(context));
|
Component component = ComponentSerializer.parseFromLegacy(Message.REMOVE_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, Util.contextSetToString(context)), Constants.COLOR_CHAR);
|
||||||
|
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(
|
||||||
|
"¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta,
|
||||||
|
'¥'
|
||||||
|
));
|
||||||
|
component.applyRecursively(c -> c.hoverEvent(event));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
|
||||||
LogEntry.build().actor(sender).acted(holder)
|
LogEntry.build().actor(sender).acted(holder)
|
||||||
.action("meta removetemp" + type.name().toLowerCase() + " " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
.action("meta removetemp" + type.name().toLowerCase() + " " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
||||||
|
@ -34,6 +34,7 @@ import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
|||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
@ -43,6 +44,11 @@ import me.lucko.luckperms.common.locale.LocaleManager;
|
|||||||
import me.lucko.luckperms.common.locale.Message;
|
import me.lucko.luckperms.common.locale.Message;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.TextUtils;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -83,7 +89,13 @@ public class MetaSet extends SharedSubCommand {
|
|||||||
holder.clearMetaKeys(key, context, false);
|
holder.clearMetaKeys(key, context, false);
|
||||||
holder.setPermission(n);
|
holder.setPermission(n);
|
||||||
|
|
||||||
Message.SET_META_SUCCESS.send(sender, key, value, holder.getFriendlyName(), Util.contextSetToString(context));
|
Component component = ComponentSerializer.parseFromLegacy(Message.SET_META_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), Util.contextSetToString(context)), Constants.COLOR_CHAR);
|
||||||
|
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(
|
||||||
|
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value),
|
||||||
|
'¥'
|
||||||
|
));
|
||||||
|
component.applyRecursively(c -> c.hoverEvent(event));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
|
||||||
LogEntry.build().actor(sender).acted(holder)
|
LogEntry.build().actor(sender).acted(holder)
|
||||||
.action("meta set " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
.action("meta set " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
||||||
|
@ -35,6 +35,7 @@ import me.lucko.luckperms.common.commands.sender.Sender;
|
|||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.TemporaryModifier;
|
import me.lucko.luckperms.common.core.TemporaryModifier;
|
||||||
@ -46,6 +47,11 @@ import me.lucko.luckperms.common.locale.Message;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.DateUtil;
|
import me.lucko.luckperms.common.utils.DateUtil;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.TextUtils;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -88,7 +94,13 @@ public class MetaSetTemp extends SharedSubCommand {
|
|||||||
holder.clearMetaKeys(key, context, true);
|
holder.clearMetaKeys(key, context, true);
|
||||||
duration = holder.setPermission(n, modifier).getValue().getExpiryUnixTime();
|
duration = holder.setPermission(n, modifier).getValue().getExpiryUnixTime();
|
||||||
|
|
||||||
Message.SET_META_TEMP_SUCCESS.send(sender, key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration), Util.contextSetToString(context));
|
Component component = ComponentSerializer.parseFromLegacy(Message.SET_META_TEMP_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration), Util.contextSetToString(context)), Constants.COLOR_CHAR);
|
||||||
|
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(
|
||||||
|
TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value),
|
||||||
|
'¥'
|
||||||
|
));
|
||||||
|
component.applyRecursively(c -> c.hoverEvent(event));
|
||||||
|
sender.sendMessage(component);
|
||||||
|
|
||||||
LogEntry.build().actor(sender).acted(holder)
|
LogEntry.build().actor(sender).acted(holder)
|
||||||
.action("meta settemp " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
.action("meta settemp " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
|
||||||
|
@ -33,17 +33,29 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.Message;
|
import me.lucko.luckperms.common.locale.Message;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.DateUtil;
|
import me.lucko.luckperms.common.utils.DateUtil;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.TextUtils;
|
||||||
|
|
||||||
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.TextComponent;
|
||||||
|
import net.kyori.text.event.ClickEvent;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class ParentInfo extends SharedSubCommand {
|
public class ParentInfo extends SharedSubCommand {
|
||||||
public ParentInfo(LocaleManager locale) {
|
public ParentInfo(LocaleManager locale) {
|
||||||
@ -57,38 +69,75 @@ public class ParentInfo extends SharedSubCommand {
|
|||||||
return CommandResult.NO_PERMISSION;
|
return CommandResult.NO_PERMISSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
Message.LISTPARENTS.send(sender, holder.getFriendlyName(), permGroupsToString(holder.mergePermissionsToSortedSet()));
|
Component ent = permGroupsToMessage(holder.mergePermissionsToSortedSet(), holder, label);
|
||||||
Message.LISTPARENTS_TEMP.send(sender, holder.getFriendlyName(), tempGroupsToString(holder.mergePermissionsToSortedSet()));
|
Message.LISTNODES.send(sender, holder.getFriendlyName());
|
||||||
|
sender.sendMessage(ent);
|
||||||
|
|
||||||
|
Component tempEnt = tempGroupsToMessage(holder.mergePermissionsToSortedSet(), holder, label);
|
||||||
|
Message.LISTNODES_TEMP.send(sender, holder.getFriendlyName());
|
||||||
|
sender.sendMessage(tempEnt);
|
||||||
|
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String permGroupsToString(SortedSet<LocalizedNode> nodes) {
|
private static Component permGroupsToMessage(SortedSet<LocalizedNode> nodes, PermissionHolder holder, String label) {
|
||||||
StringBuilder sb = new StringBuilder();
|
List<Node> page = new ArrayList<>();
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
if (!node.isGroupNode()) continue;
|
if (!node.isGroupNode()) continue;
|
||||||
if (node.isTemporary()) continue;
|
if (node.isTemporary()) continue;
|
||||||
|
page.add(node);
|
||||||
sb.append("&3> &f")
|
|
||||||
.append(node.getGroupName())
|
|
||||||
.append(Util.getAppendableNodeContextString(node))
|
|
||||||
.append("\n");
|
|
||||||
}
|
}
|
||||||
return sb.length() == 0 ? "&3None" : sb.toString();
|
|
||||||
|
if (page.isEmpty()) {
|
||||||
|
return new TextComponent("None").color('3');
|
||||||
|
}
|
||||||
|
|
||||||
|
TextComponent message = new TextComponent("");
|
||||||
|
for (Node node : page) {
|
||||||
|
String s = "&3> &a" + node.getGroupName() + Util.getAppendableNodeContextString(node) + "\n";
|
||||||
|
message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(holder, label, node)));
|
||||||
|
}
|
||||||
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String tempGroupsToString(SortedSet<LocalizedNode> nodes) {
|
private static Component tempGroupsToMessage(SortedSet<LocalizedNode> nodes, PermissionHolder holder, String label) {
|
||||||
StringBuilder sb = new StringBuilder();
|
List<Node> page = new ArrayList<>();
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
if (!node.isGroupNode()) continue;
|
if (!node.isGroupNode()) continue;
|
||||||
if (!node.isTemporary()) continue;
|
if (node.isPermanent()) continue;
|
||||||
|
page.add(node);
|
||||||
sb.append("&3> &f")
|
|
||||||
.append(node.getGroupName())
|
|
||||||
.append(Util.getAppendableNodeContextString(node))
|
|
||||||
.append("\n&2- expires in ")
|
|
||||||
.append(DateUtil.formatDateDiff(node.getExpiryUnixTime()))
|
|
||||||
.append("\n");
|
|
||||||
}
|
}
|
||||||
return sb.length() == 0 ? "&3None" : sb.toString();
|
|
||||||
|
if (page.isEmpty()) {
|
||||||
|
return new TextComponent("None").color('3');
|
||||||
|
}
|
||||||
|
|
||||||
|
TextComponent message = new TextComponent("");
|
||||||
|
for (Node node : page) {
|
||||||
|
String s = "&3> &a" + node.getPermission() + Util.getAppendableNodeContextString(node) + "\n&2- expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()) + "\n";
|
||||||
|
message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(holder, label, node)));
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Consumer<Component> makeFancy(PermissionHolder holder, String label, Node node) {
|
||||||
|
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
|
||||||
|
"&3> &f" + node.getGroupName(),
|
||||||
|
" ",
|
||||||
|
"&7Click to remove this parent from " + holder.getFriendlyName()
|
||||||
|
), Constants.FORMAT_CHAR));
|
||||||
|
|
||||||
|
boolean group = !(holder instanceof User);
|
||||||
|
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group)
|
||||||
|
.replace("/luckperms", "/" + label)
|
||||||
|
.replace("permission set", "permission unset")
|
||||||
|
.replace("parent add", "parent remove")
|
||||||
|
.replace(" true", "")
|
||||||
|
.replace(" false", "");
|
||||||
|
|
||||||
|
return component -> {
|
||||||
|
component.hoverEvent(hoverEvent);
|
||||||
|
component.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,36 +86,34 @@ public class PermissionInfo extends SharedSubCommand {
|
|||||||
filter = args.get(1);
|
filter = args.get(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.getUuid().equals(Constants.CONSOLE_UUID)) {
|
int page = ArgumentUtils.handleIntOrElse(0, args, 1);
|
||||||
Message.LISTNODES.send(sender, holder.getFriendlyName());
|
|
||||||
sender.sendMessage(Util.color(permNodesToString(filter, holder.mergePermissionsToSortedSet())));
|
|
||||||
} else {
|
|
||||||
int page = ArgumentUtils.handleIntOrElse(0, args, 1);
|
|
||||||
|
|
||||||
Map.Entry<Component, String> ent = permNodesToMessage(filter, holder.mergePermissionsToSortedSet(), holder, label, page);
|
Map.Entry<Component, String> ent = nodesToMessage(false, filter, holder.mergePermissionsToSortedSet(), holder, label, page, sender.isConsole());
|
||||||
if (ent.getValue() != null) {
|
if (ent.getValue() != null) {
|
||||||
Message.LISTNODES_WITH_PAGE.send(sender, holder.getFriendlyName(), ent.getValue());
|
Message.LISTNODES_WITH_PAGE.send(sender, holder.getFriendlyName(), ent.getValue());
|
||||||
sender.sendMessage(ent.getKey());
|
sender.sendMessage(ent.getKey());
|
||||||
} else {
|
} else {
|
||||||
Message.LISTNODES.send(sender, holder.getFriendlyName());
|
Message.LISTNODES.send(sender, holder.getFriendlyName());
|
||||||
sender.sendMessage(ent.getKey());
|
sender.sendMessage(ent.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map.Entry<Component, String> tempEnt = nodesToMessage(true, filter, holder.mergePermissionsToSortedSet(), holder, label, page, sender.isConsole());
|
||||||
|
if (tempEnt.getValue() != null) {
|
||||||
|
Message.LISTNODES_TEMP_WITH_PAGE.send(sender, holder.getFriendlyName(), tempEnt.getValue());
|
||||||
|
sender.sendMessage(tempEnt.getKey());
|
||||||
|
} else {
|
||||||
|
Message.LISTNODES_TEMP.send(sender, holder.getFriendlyName());
|
||||||
|
sender.sendMessage(tempEnt.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
Message.LISTNODES_TEMP.send(sender, holder.getFriendlyName(), tempNodesToString(filter, holder.mergePermissionsToSortedSet()));
|
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map.Entry<Component, String> permNodesToMessage(String filter, SortedSet<LocalizedNode> nodes, PermissionHolder holder, String label, int pageNumber) {
|
private static Map.Entry<Component, String> nodesToMessage(boolean temp, String filter, SortedSet<LocalizedNode> nodes, PermissionHolder holder, String label, int pageNumber, boolean console) {
|
||||||
List<Node> l = new ArrayList<>();
|
List<Node> l = new ArrayList<>();
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
if (filter != null && !node.getPermission().startsWith(filter)) {
|
if (filter != null && !node.getPermission().startsWith(filter)) continue;
|
||||||
continue;
|
if (temp != node.isTemporary()) continue;
|
||||||
}
|
|
||||||
if (node.isTemporary()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
l.add(node);
|
l.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +132,7 @@ public class PermissionInfo extends SharedSubCommand {
|
|||||||
List<Node> page = pages.get(index);
|
List<Node> page = pages.get(index);
|
||||||
|
|
||||||
TextComponent message = new TextComponent("");
|
TextComponent message = new TextComponent("");
|
||||||
String title = "&7(showing page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + nodes.size() + "&7 entries";
|
String title = "&7(showing page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + l.size() + "&7 entries";
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
title += " - filtered by &f\"" + filter + "\"&7)";
|
title += " - filtered by &f\"" + filter + "\"&7)";
|
||||||
} else {
|
} else {
|
||||||
@ -142,7 +140,11 @@ public class PermissionInfo extends SharedSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Node node : page) {
|
for (Node node : page) {
|
||||||
String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission() + Util.getAppendableNodeContextString(node) + "\n";
|
String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission() + (console ? " &7(" + node.getValue() + "&7)" : "") + Util.getAppendableNodeContextString(node) + "\n";
|
||||||
|
if (temp) {
|
||||||
|
s += "&2- expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()) + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(holder, label, node)));
|
message.append(ComponentSerializer.parseFromLegacy(s, Constants.FORMAT_CHAR).applyRecursively(makeFancy(holder, label, node)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,10 +153,10 @@ public class PermissionInfo extends SharedSubCommand {
|
|||||||
|
|
||||||
private static Consumer<Component> makeFancy(PermissionHolder holder, String label, Node node) {
|
private static Consumer<Component> makeFancy(PermissionHolder holder, String label, Node node) {
|
||||||
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
|
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentSerializer.parseFromLegacy(TextUtils.joinNewline(
|
||||||
"&3> " + (node.getValue() ? "&a" : "&c") + node.getPermission(),
|
"¥3> " + (node.getValue() ? "¥a" : "¥c") + node.getPermission(),
|
||||||
" ",
|
" ",
|
||||||
"&7Click to remove this node from " + holder.getFriendlyName()
|
"¥7Click to remove this node from " + holder.getFriendlyName()
|
||||||
), Constants.FORMAT_CHAR));
|
), '¥'));
|
||||||
|
|
||||||
boolean group = !(holder instanceof User);
|
boolean group = !(holder instanceof User);
|
||||||
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group)
|
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group)
|
||||||
@ -169,45 +171,4 @@ public class PermissionInfo extends SharedSubCommand {
|
|||||||
component.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
component.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String permNodesToString(String filter, SortedSet<LocalizedNode> nodes) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (Node node : nodes) {
|
|
||||||
if (filter != null && !node.getPermission().startsWith(filter)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (node.isTemporary()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append("&3> ")
|
|
||||||
.append(node.getValue() ? "&a" : "&c")
|
|
||||||
.append(node.getPermission())
|
|
||||||
.append(" ").append("&7(").append(node.getValue()).append("&7)")
|
|
||||||
.append(Util.getAppendableNodeContextString(node))
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
return sb.length() == 0 ? "&3None" : sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String tempNodesToString(String filter, SortedSet<LocalizedNode> nodes) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (Node node : nodes) {
|
|
||||||
if (filter != null && !node.getPermission().startsWith(filter)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!node.isTemporary()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append("&3> ")
|
|
||||||
.append(node.getValue() ? "&a" : "&c")
|
|
||||||
.append(node.getPermission())
|
|
||||||
.append(Util.getAppendableNodeContextString(node))
|
|
||||||
.append("\n&2- expires in ")
|
|
||||||
.append(DateUtil.formatDateDiff(node.getExpiryUnixTime()))
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
return sb.length() == 0 ? "&3None" : sb.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -213,9 +213,10 @@ public enum Message {
|
|||||||
|
|
||||||
LISTNODES("&b{0}'s Nodes:", true),
|
LISTNODES("&b{0}'s Nodes:", true),
|
||||||
LISTNODES_WITH_PAGE("&b{0}'s Nodes: {1}", true),
|
LISTNODES_WITH_PAGE("&b{0}'s Nodes: {1}", true),
|
||||||
LISTNODES_TEMP("&b{0}'s Temporary Nodes:" + "\n" + "{1}", true),
|
LISTNODES_TEMP("&b{0}'s Temporary Nodes:", true),
|
||||||
LISTPARENTS("&b{0}'s Parent Groups:" + "\n" + "{1}", true),
|
LISTNODES_TEMP_WITH_PAGE("&b{0}'s Temporary Nodes: {1}", true),
|
||||||
LISTPARENTS_TEMP("&b{0}'s Temporary Parent Groups:" + "\n" + "{1}", true),
|
LISTPARENTS("&b{0}'s Parent Groups:", true),
|
||||||
|
LISTPARENTS_TEMP("&b{0}'s Temporary Parent Groups:", true),
|
||||||
LIST_TRACKS("&b{0}'s Tracks:" + "\n" + "{1}", true),
|
LIST_TRACKS("&b{0}'s Tracks:" + "\n" + "{1}", true),
|
||||||
LIST_TRACKS_EMPTY("{0} is not on any tracks.", true),
|
LIST_TRACKS_EMPTY("{0} is not on any tracks.", true),
|
||||||
|
|
||||||
@ -419,10 +420,15 @@ public enum Message {
|
|||||||
IMPORT_END_ERROR_CONTENT("&b(Import) &b-> &c{0}", true),
|
IMPORT_END_ERROR_CONTENT("&b(Import) &b-> &c{0}", true),
|
||||||
IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", true);
|
IMPORT_END_ERROR_FOOTER("&b(Import) &7<------------------------------------------>", true);
|
||||||
|
|
||||||
|
public static final Object SKIP_ELEMENT = new Object();
|
||||||
|
|
||||||
private static String format(String s, Object... objects) {
|
private static String format(String s, Object... objects) {
|
||||||
for (int i = 0; i < objects.length; i++) {
|
for (int i = 0; i < objects.length; i++) {
|
||||||
Object o = objects[i];
|
Object o = objects[i];
|
||||||
s = s.replace("{" + i + "}", String.valueOf(o));
|
|
||||||
|
if (o != SKIP_ELEMENT) {
|
||||||
|
s = s.replace("{" + i + "}", String.valueOf(o));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -448,6 +454,10 @@ public enum Message {
|
|||||||
s = message;
|
s = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s.startsWith("&")) {
|
||||||
|
prefix = prefix.substring(0, prefix.length() - 2);
|
||||||
|
}
|
||||||
|
|
||||||
s = format(s.replace("{PREFIX}", prefix).replace("\\n", "\n"), objects);
|
s = format(s.replace("{PREFIX}", prefix).replace("\\n", "\n"), objects);
|
||||||
return Util.color(showPrefix ? prefix + s : s);
|
return Util.color(showPrefix ? prefix + s : s);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user