Improve /lp listgroups output - closes #368

This commit is contained in:
Luck 2017-07-10 10:09:29 +01:00
parent 1bb1f5ebb3
commit 7a6c0ab154
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 59 additions and 20 deletions

View File

@ -57,6 +57,16 @@ search-showing-users: "&bShowing user entries:"
search-showing-groups: "&bShowing group entries:"
search-showing-users-with-page: "&bShowing user entries: {0}"
search-showing-groups-with-page: "&bShowing group entries: {0}"
apply-edits-invalid-code: "&aInvalid code. &7({0})"
apply-edits-unable-to-read: "&aUnable to read data using the given code. &7({0})"
apply-edits-no-target: "&aUnable to parse the target of the edit. Please supply it as an extra argument."
apply-edits-target-group-not-exists: "&aTarget group &b{0}&a does not exist."
apply-edits-target-user-not-uuid: "&aTarget user &b{0}&a is not a valid uuid."
apply-edits-target-user-unable-to-load: "&aUnable to load target user &b{0}&a."
apply-edits-target-unknown: "&aInvalid target. &7({0})"
apply-edits-success: "&aSuccessfully applied &b{0}&a nodes to &b{1}&a."
editor-upload-failure: "&cUnable to upload permission data to the editor."
editor-url: "&aEditor URL:"
check-result: "&aPermission check result on user &b{0}&a for permission &b{1}&a: &f{2}"
create-success: "&b{0}&a was successfully created."
delete-success: "&b{0}&a was successfully deleted."
@ -116,21 +126,18 @@ info: >
create-group-error: "There was an error whilst creating the group."
delete-group-error: "There was an error whilst deleting the group."
delete-group-error-default: "You cannot delete the default group."
groups-list: "&aGroups: {0}"
groups-list: "&aGroups: &7(name, weight, tracks)"
groups-list-entry: "&f- &3{0} &7- &b{1}"
groups-list-entry-with-tracks: "&f- &3{0} &7- &b{1} &7- [&3{2}&7]"
create-track-error: "There was an error whilst creating the track."
delete-track-error: "There was an error whilst deleting the track."
tracks-list: "&aTracks: {0}"
listnodes: "&b{0}'s Nodes:"
listnodes-with-page: "&b{0}'s Nodes: {1}"
listnodes-temp: >
&b{0}'s Temporary Nodes:\n
{1}
listparents: >
&b{0}'s Parent Groups:\n
{1}
listparents-temp: >
&b{0}'s Temporary Parent Groups:\n
{1}
listnodes-temp: "&b{0}'s Temporary Nodes:"
listnodes-temp-with-page: "&b{0}'s Temporary Nodes: {1}"
listparents: "&b{0}'s Parent Groups:"
listparents-temp: "&b{0}'s Temporary Parent Groups:"
list-tracks: >
&b{0}'s Tracks:\n
{1}

View File

@ -29,14 +29,21 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
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.core.model.Group;
import me.lucko.luckperms.common.core.model.Track;
import me.lucko.luckperms.common.locale.CommandSpec;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates;
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.List;
import java.util.stream.Collectors;
@ -52,14 +59,37 @@ public class ListGroups extends SingleCommand {
return CommandResult.LOADING_ERROR;
}
Message.GROUPS_LIST.send(
sender,
Util.toCommaSep(plugin.getGroupManager().getAll().values().stream()
.map(Group::getDisplayName)
.sorted()
.collect(Collectors.toList())
)
);
Message.GROUPS_LIST.send(sender);
plugin.getGroupManager().getAll().values().stream()
.sorted((o1, o2) -> {
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
})
.forEach(group -> {
List<String> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(group)).map(Track::getName).collect(Collectors.toList());
Component component;
if (tracks.isEmpty()) {
component = ComponentSerializer.parseFromLegacy(Message.GROUPS_LIST_ENTRY.asString(plugin.getLocaleManager(),
group.getDisplayName(),
group.getWeight().orElse(0)
), Constants.COLOR_CHAR);
} else {
component = ComponentSerializer.parseFromLegacy(Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asString(plugin.getLocaleManager(),
group.getDisplayName(),
group.getWeight().orElse(0),
Util.toCommaSep(tracks)
), Constants.COLOR_CHAR);
}
component.applyRecursively(c -> {
c.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + label + " group " + group.getName() + " info"));
c.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to view more info about " + group.getName() + ".").color('7')));
});
sender.sendMessage(component);
});
return CommandResult.SUCCESS;
}
}

View File

@ -205,7 +205,9 @@ public enum Message {
CREATE_GROUP_ERROR("There was an error whilst creating the group.", true),
DELETE_GROUP_ERROR("There was an error whilst deleting the group.", true),
DELETE_GROUP_ERROR_DEFAULT("You cannot delete the default group.", true),
GROUPS_LIST("&aGroups: {0}", true),
GROUPS_LIST("&aGroups: &7(name, weight, tracks)", true),
GROUPS_LIST_ENTRY("&f- &3{0} &7- &b{1}", true),
GROUPS_LIST_ENTRY_WITH_TRACKS("&f- &3{0} &7- &b{1} &7- [&3{2}&7]", true),
CREATE_TRACK_ERROR("There was an error whilst creating the track.", true),
DELETE_TRACK_ERROR("There was an error whilst deleting the track.", true),