mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-14 22:55:30 +01:00
Add commands to view inherited groups
This commit is contained in:
parent
f48595b1ff
commit
df1e747861
@ -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<LPBungeePlugin> {
|
||||
@ -80,6 +81,16 @@ class BungeeConfig extends AbstractConfiguration<LPBungeePlugin> {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getMap(String path, Map<String, String> def) {
|
||||
return configuration.get(path, def);
|
||||
Map<String, String> 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;
|
||||
}
|
||||
}
|
||||
|
@ -181,6 +181,64 @@ public class Util {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String permGroupsToString(SortedSet<Node> 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<Node> 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);
|
||||
|
@ -39,6 +39,7 @@ public class GroupMainCommand extends MainCommand<Group> {
|
||||
super("Group", "/%s group <group>", 2, ImmutableList.<SubCommand<Group>>builder()
|
||||
.add(new GroupInfo())
|
||||
.add(new GroupListNodes())
|
||||
.add(new GroupListParents())
|
||||
.add(new GroupHasPerm())
|
||||
.add(new GroupInheritsPerm())
|
||||
.add(new GroupSetPermission())
|
||||
|
@ -48,7 +48,6 @@ public class GroupInfo extends SubCommand<Group> {
|
||||
label,
|
||||
group.getName()
|
||||
);
|
||||
// TODO show inheritances
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* 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<Group> {
|
||||
public GroupListParents() {
|
||||
super("listparents", "Lists the groups that this group inherits from", "/%s group <group> listparents",
|
||||
Permission.GROUP_LISTPARENTS, Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> 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;
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ public class UserMainCommand extends MainCommand<User> {
|
||||
.add(new UserInfo())
|
||||
.add(new UserGetUUID())
|
||||
.add(new UserListNodes())
|
||||
.add(new UserListGroups())
|
||||
.add(new UserHasPerm())
|
||||
.add(new UserInheritsPerm())
|
||||
.add(new UserSetPermission())
|
||||
|
@ -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> {
|
||||
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(),
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* 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<User> {
|
||||
public UserListGroups() {
|
||||
super("listgroups", "Lists the groups a user is in", "/%s user <user> listgroups",
|
||||
Permission.USER_LISTGROUPS, Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> 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;
|
||||
}
|
||||
}
|
@ -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" +
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user