diff --git a/bungee/src/main/java/me/lucko/luckperms/BungeeConfig.java b/bungee/src/main/java/me/lucko/luckperms/BungeeConfig.java index 7651df7b..791b9cab 100644 --- a/bungee/src/main/java/me/lucko/luckperms/BungeeConfig.java +++ b/bungee/src/main/java/me/lucko/luckperms/BungeeConfig.java @@ -31,6 +31,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.util.HashMap; import java.util.Map; class BungeeConfig extends AbstractConfiguration { @@ -80,6 +81,16 @@ class BungeeConfig extends AbstractConfiguration { @Override protected Map getMap(String path, Map def) { - return configuration.get(path, def); + Map map = new HashMap<>(); + Configuration section = configuration.getSection(path); + if (section == null) { + return def; + } + + for (String key : section.getKeys()) { + map.put(key, section.getString(key)); + } + + return map; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/Util.java b/common/src/main/java/me/lucko/luckperms/commands/Util.java index 2c2a73b5..5b019705 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/Util.java +++ b/common/src/main/java/me/lucko/luckperms/commands/Util.java @@ -181,6 +181,64 @@ public class Util { return sb.toString(); } + public static String permGroupsToString(SortedSet nodes) { + StringBuilder sb = new StringBuilder(); + for (Node node : nodes) { + if (!node.isGroupNode()) { + continue; + } + + if (node.isTemporary()) { + continue; + } + + sb.append("&a-> &b").append(node.getGroupName()); + if (node.isServerSpecific()) { + sb.append(" &7(&f").append(node.getServer().get()).append("&7)"); + } + if (node.isWorldSpecific()) { + sb.append(" &7(&f").append(node.getWorld().get()).append("&7)"); + } + sb.append("\n"); + } + + if (sb.length() == 0) { + return "&6None"; + } + + return sb.toString(); + } + + public static String tempGroupsToString(SortedSet nodes) { + StringBuilder sb = new StringBuilder(); + + for (Node node : nodes) { + if (!node.isGroupNode()) { + continue; + } + + if (!node.isTemporary()) { + continue; + } + + sb.append("&a-> &b").append(node.getGroupName()); + if (node.isServerSpecific()) { + sb.append(" &7(&f").append(node.getServer().get()).append("&7)"); + } + if (node.isWorldSpecific()) { + sb.append(" &7(&f").append(node.getWorld().get()).append("&7)"); + } + + sb.append("&6 - expires in ").append(DateUtil.formatDateDiff(node.getExpiryUnixTime())).append("\n"); + } + + if (sb.length() == 0) { + return "&6None"; + } + + return sb.toString(); + } + public static UUID parseUuid(String s) { try { return UUID.fromString(s); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java index f1d79e84..3859a446 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java @@ -39,6 +39,7 @@ public class GroupMainCommand extends MainCommand { super("Group", "/%s group ", 2, ImmutableList.>builder() .add(new GroupInfo()) .add(new GroupListNodes()) + .add(new GroupListParents()) .add(new GroupHasPerm()) .add(new GroupInheritsPerm()) .add(new GroupSetPermission()) diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfo.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfo.java index e0b0fc43..d707b8f5 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfo.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfo.java @@ -48,7 +48,6 @@ public class GroupInfo extends SubCommand { label, group.getName() ); - // TODO show inheritances return CommandResult.SUCCESS; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupListParents.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupListParents.java new file mode 100644 index 00000000..354b2ea2 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupListParents.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.commands.group.subcommands; + +import me.lucko.luckperms.LuckPermsPlugin; +import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.constants.Message; +import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.groups.Group; + +import java.util.List; + +public class GroupListParents extends SubCommand { + public GroupListParents() { + super("listparents", "Lists the groups that this group inherits from", "/%s group listparents", + Permission.GROUP_LISTPARENTS, Predicate.alwaysFalse()); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { + Message.LISTPARENTS.send(sender, group.getDisplayName(), Util.permGroupsToString(group.getPermissions(false))); + Message.LISTPARENTS_TEMP.send(sender, group.getDisplayName(), Util.tempGroupsToString(group.getPermissions(false))); + return CommandResult.SUCCESS; + } +} + diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java index 08e3e217..a105a938 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java @@ -42,6 +42,7 @@ public class UserMainCommand extends MainCommand { .add(new UserInfo()) .add(new UserGetUUID()) .add(new UserListNodes()) + .add(new UserListGroups()) .add(new UserHasPerm()) .add(new UserInheritsPerm()) .add(new UserSetPermission()) diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfo.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfo.java index 96cd9058..ec4735b4 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfo.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfo.java @@ -23,7 +23,10 @@ package me.lucko.luckperms.commands.user.subcommands; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.CommandResult; +import me.lucko.luckperms.commands.Predicate; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.users.User; @@ -41,7 +44,6 @@ public class UserInfo extends SubCommand { user.getName(), user.getUuid(), plugin.getPlayerStatus(user.getUuid()), - Util.listToCommaSep(user.getGroupNames()), // TODO move this to own command user.getPrimaryGroup(), user.getPermanentNodes().size(), user.getTemporaryNodes().size(), diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserListGroups.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserListGroups.java new file mode 100644 index 00000000..18207ae4 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserListGroups.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.commands.user.subcommands; + +import me.lucko.luckperms.LuckPermsPlugin; +import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.constants.Message; +import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.users.User; + +import java.util.List; + +public class UserListGroups extends SubCommand { + public UserListGroups() { + super("listgroups", "Lists the groups a user is in", "/%s user listgroups", + Permission.USER_LISTGROUPS, Predicate.alwaysFalse()); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) { + Message.LISTGROUPS.send(sender, user.getName(), Util.permGroupsToString(user.getPermissions(false))); + Message.LISTGROUPS_TEMP.send(sender, user.getName(), Util.tempGroupsToString(user.getPermissions(false))); + return CommandResult.SUCCESS; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/constants/Message.java b/common/src/main/java/me/lucko/luckperms/constants/Message.java index 31b73b19..de6a2752 100644 --- a/common/src/main/java/me/lucko/luckperms/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/constants/Message.java @@ -157,6 +157,10 @@ public enum Message { LISTNODES("&e%s's Nodes:" + "\n" + "%s", true), LISTNODES_TEMP("&e%s's Temporary Nodes:" + "\n" + "%s", true), + LISTPARENTS("&e%s's Parent Groups:" + "\n" + "%s", true), + LISTPARENTS_TEMP("&e%s's Temporary Parent Groups:" + "\n" + "%s", true), + LISTGROUPS("&e%s's Groups:" + "\n" + "%s", true), + LISTGROUPS_TEMP("&e%s's Temporary Groups:" + "\n" + "%s", true), SETPERMISSION_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a.", true), SETPERMISSION_SERVER_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a.", true), SETPERMISSION_SERVER_WORLD_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a, world &b%s&a.", true), @@ -217,7 +221,6 @@ public enum Message { PREFIX + "&d-> &eUser: &6%s" + "\n" + PREFIX + "&d-> &eUUID: &6%s" + "\n" + PREFIX + "&d-> &eStatus: %s" + "\n" + - PREFIX + "&d-> &eGroups: &6%s" + "\n" + PREFIX + "&d-> &ePrimary Group: &6%s" + "\n" + PREFIX + "&d-> &ePermissions: &6%s" + "\n" + PREFIX + "&d-> &eTemporary Permissions: &6%s" + "\n" + diff --git a/common/src/main/java/me/lucko/luckperms/constants/Permission.java b/common/src/main/java/me/lucko/luckperms/constants/Permission.java index cb72a936..b632c9c9 100644 --- a/common/src/main/java/me/lucko/luckperms/constants/Permission.java +++ b/common/src/main/java/me/lucko/luckperms/constants/Permission.java @@ -47,6 +47,7 @@ public enum Permission { USER_INFO("info", "user"), USER_GETUUID("getuuid", "user"), USER_LISTNODES("listnodes", "user"), + USER_LISTGROUPS("listgroups", "user"), USER_HASPERMISSION("haspermission", "user"), USER_INHERITSPERMISSION("inheritspermission", "user"), USER_SETPERMISSION("setpermission", "user"), @@ -75,6 +76,7 @@ public enum Permission { GROUP_INFO("info", "group"), GROUP_LISTNODES("listnodes", "group"), + GROUP_LISTPARENTS("listparents", "group"), GROUP_HASPERMISSION("haspermission", "group"), GROUP_INHERITSPERMISSION("inheritspermission", "group"), GROUP_SETPERMISSION("setpermission", "group"),