diff --git a/bukkit/src/main/java/me/lucko/luckperms/api/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/api/vault/VaultPermissionHook.java index 5ff62053..e45faabf 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/api/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/api/vault/VaultPermissionHook.java @@ -199,7 +199,16 @@ public class VaultPermissionHook extends Permission { @Override public boolean playerInGroup(String world, @NonNull String player, @NonNull String group) { log("Checking if player " + player + " is in group: " + group + " on world " + world + ", server " + server); - return playerHas(world, player, "group." + group); + final User user = plugin.getUserManager().get(player); + if (user == null) return false; + + return user.getNodes().stream() + .filter(Node::isGroupNode) + .filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false)) + .filter(n -> n.shouldApplyOnWorld(world, true, false)) + .map(Node::getGroupName) + .filter(s -> s.equalsIgnoreCase(group)) + .findAny().isPresent(); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java index c0ce7f5d..e74608d1 100644 --- a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java @@ -548,17 +548,6 @@ public abstract class PermissionHolder { return getPermissions(false).stream().filter(Node::isTemporary).collect(Collectors.toSet()); } - @Deprecated - public Map, Long> getTemporaryNodesLegacy() { - Map, Long> m = new HashMap<>(); - - for (Node node : getTemporaryNodes()) { - m.put(new AbstractMap.SimpleEntry<>(node.getKey(), node.getValue()), node.getExpiryUnixTime()); - } - - return m; - } - /** * @return The permanent nodes held by the holder */ @@ -566,9 +555,49 @@ public abstract class PermissionHolder { return getPermissions(false).stream().filter(Node::isPermanent).collect(Collectors.toSet()); } + /** + * Get a {@link List} of all of the groups the group inherits, on all servers + * @return a {@link List} of group names + */ + public List getGroupNames() { + return getNodes().stream() + .filter(Node::isGroupNode) + .map(Node::getGroupName) + .collect(Collectors.toList()); + } + + /** + * Get a {@link List} of the groups the group inherits on a specific server + * @param server the server to check + * @param world the world to check + * @return a {@link List} of group names + */ + public List getLocalGroups(String server, String world) { + return getNodes().stream() + .filter(Node::isGroupNode) + .filter(n -> n.shouldApplyOnWorld(world, false, true)) + .filter(n -> n.shouldApplyOnServer(server, false, true)) + .map(Node::getGroupName) + .collect(Collectors.toList()); + } + + /** + * Get a {@link List} of the groups the group inherits on a specific server + * @param server the server to check + * @return a {@link List} of group names + */ + public List getLocalGroups(String server) { + return getNodes().stream() + .filter(Node::isGroupNode) + .filter(n -> n.shouldApplyOnServer(server, false, true)) + .map(Node::getGroupName) + .collect(Collectors.toList()); + } + /* * Don't use these methods, only here for compat reasons */ + @Deprecated public Map getLocalPermissions(String server, String world, List excludedGroups, List possibleNodes) { Map context = new HashMap<>(); diff --git a/common/src/main/java/me/lucko/luckperms/groups/Group.java b/common/src/main/java/me/lucko/luckperms/groups/Group.java index 8d4288f2..178811b6 100644 --- a/common/src/main/java/me/lucko/luckperms/groups/Group.java +++ b/common/src/main/java/me/lucko/luckperms/groups/Group.java @@ -26,7 +26,6 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.event.events.GroupAddEvent; import me.lucko.luckperms.api.implementation.internal.GroupLink; import me.lucko.luckperms.api.implementation.internal.PermissionHolderLink; @@ -35,9 +34,6 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.utils.Identifiable; -import java.util.List; -import java.util.stream.Collectors; - @ToString(of = {"name"}) @EqualsAndHashCode(of = {"name"}, callSuper = false) public class Group extends PermissionHolder implements Identifiable { @@ -73,7 +69,7 @@ public class Group extends PermissionHolder implements Identifiable { * @return true if the user is a member of the group */ public boolean inheritsGroup(Group group) { - return group.getName().equalsIgnoreCase(this.getName()) || inheritsGroup(group, "global"); + return group.getName().equalsIgnoreCase(this.getName()) || hasPermission("group." + group.getName(), true); } /** @@ -122,10 +118,6 @@ public class Group extends PermissionHolder implements Identifiable { throw new ObjectAlreadyHasException(); } - if (server == null) { - server = "global"; - } - setPermission("group." + group.getName(), true, server); getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), server, null, 0L)); } @@ -142,10 +134,6 @@ public class Group extends PermissionHolder implements Identifiable { throw new ObjectAlreadyHasException(); } - if (server == null) { - server = "global"; - } - setPermission("group." + group.getName(), true, server, world); getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), server, world, 0L)); } @@ -177,10 +165,6 @@ public class Group extends PermissionHolder implements Identifiable { throw new ObjectAlreadyHasException(); } - if (server == null) { - server = "global"; - } - setPermission("group." + group.getName(), true, server, expireAt); getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), server, null, expireAt)); } @@ -198,10 +182,6 @@ public class Group extends PermissionHolder implements Identifiable { throw new ObjectAlreadyHasException(); } - if (server == null) { - server = "global"; - } - setPermission("group." + group.getName(), true, server, world, expireAt); getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), server, world, expireAt)); } @@ -212,7 +192,7 @@ public class Group extends PermissionHolder implements Identifiable { * @throws ObjectLacksException if the group does not already inherit the group */ public void unsetInheritGroup(Group group) throws ObjectLacksException { - unsetInheritGroup(group, "global"); + unsetPermission("group." + group.getName()); } /** @@ -222,7 +202,7 @@ public class Group extends PermissionHolder implements Identifiable { * @throws ObjectLacksException if the group does not already inherit the group */ public void unsetInheritGroup(Group group, boolean temporary) throws ObjectLacksException { - unsetInheritGroup(group, "global", temporary); + unsetPermission("group." + group.getName(), temporary); } /** @@ -232,10 +212,6 @@ public class Group extends PermissionHolder implements Identifiable { * @throws ObjectLacksException if the group does not already inherit the group */ public void unsetInheritGroup(Group group, String server) throws ObjectLacksException { - if (server == null) { - server = "global"; - } - unsetPermission("group." + group.getName(), server); } @@ -247,10 +223,6 @@ public class Group extends PermissionHolder implements Identifiable { * @throws ObjectLacksException if the group does not already inherit the group */ public void unsetInheritGroup(Group group, String server, String world) throws ObjectLacksException { - if (server == null) { - server = "global"; - } - unsetPermission("group." + group.getName(), server, world); } @@ -262,10 +234,6 @@ public class Group extends PermissionHolder implements Identifiable { * @throws ObjectLacksException if the group does not already inherit the group */ public void unsetInheritGroup(Group group, String server, boolean temporary) throws ObjectLacksException { - if (server == null) { - server = "global"; - } - unsetPermission("group." + group.getName(), server, temporary); } @@ -278,10 +246,6 @@ public class Group extends PermissionHolder implements Identifiable { * @throws ObjectLacksException if the group does not already inherit the group */ public void unsetInheritGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException { - if (server == null) { - server = "global"; - } - unsetPermission("group." + group.getName(), server, world, temporary); } @@ -291,49 +255,4 @@ public class Group extends PermissionHolder implements Identifiable { public void clearNodes() { getNodes().clear(); } - - /** - * Get a {@link List} of all of the groups the group inherits, on all servers - * @return a {@link List} of group names - */ - public List getGroupNames() { - return getGroups(null, null, true); - } - - /** - * Get a {@link List} of the groups the group inherits on a specific server - * @param server the server to check - * @param world the world to check - * @return a {@link List} of group names - */ - public List getLocalGroups(String server, String world) { - return getGroups(server, world, false); - } - - /** - * Get a {@link List} of the groups the group inherits on a specific server - * @param server the server to check - * @return a {@link List} of group names - */ - public List getLocalGroups(String server) { - return getLocalGroups(server, null); - } - - /** - * Get a {@link List} of the groups the group inherits on a specific server with the option to include global - * groups or all groups - * @param server Which server to check on - * @param world Which world to check on - * @param includeGlobal Whether to include global groups - * @return a {@link List} of group names - */ - private List getGroups(String server, String world, boolean includeGlobal) { - // Call super #getPermissions method, and just sort through those - return getNodes().stream() - .filter(n -> n.shouldApplyOnWorld(world, includeGlobal, true)) - .filter(n -> n.shouldApplyOnServer(server, includeGlobal, true)) - .filter(Node::isGroupNode) - .map(Node::getGroupName) - .collect(Collectors.toList()); - } } diff --git a/common/src/main/java/me/lucko/luckperms/users/User.java b/common/src/main/java/me/lucko/luckperms/users/User.java index cf1416c7..689af3e6 100644 --- a/common/src/main/java/me/lucko/luckperms/users/User.java +++ b/common/src/main/java/me/lucko/luckperms/users/User.java @@ -27,7 +27,6 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.event.events.GroupAddEvent; import me.lucko.luckperms.api.implementation.internal.GroupLink; import me.lucko.luckperms.api.implementation.internal.PermissionHolderLink; @@ -37,9 +36,7 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.Identifiable; -import java.util.List; import java.util.UUID; -import java.util.stream.Collectors; @ToString(of = {"uuid"}) @EqualsAndHashCode(of = {"uuid"}, callSuper = false) @@ -93,7 +90,7 @@ public abstract class User extends PermissionHolder implements Identifiable getGroupNames() { - return getGroups(null, null, true); - } - - /** - * Get a {@link List} of the groups the user is a member of on a specific server - * @param server the server to check - * @param world the world to check - * @return a {@link List} of group names - */ - public List getLocalGroups(String server, String world) { - return getGroups(server, world, false); - } - - /** - * Get a {@link List} of the groups the user is a member of on a specific server - * @param server the server to check - * @return a {@link List} of group names - */ - public List getLocalGroups(String server) { - return getLocalGroups(server, null); - } - - /** - * Get a {@link List} of the groups the user is a member of on a specific server with the option to include global - * groups or all groups - * @param server Which server to check on - * @param world Which world to check on - * @param includeGlobal Whether to include global groups - * @return a {@link List} of group names - */ - public List getGroups(String server, String world, boolean includeGlobal) { - // Call super #getPermissions method, and just sort through those - return getNodes().stream() - .filter(n -> n.shouldApplyOnWorld(world, includeGlobal, true)) - .filter(n -> n.shouldApplyOnServer(server, includeGlobal, true)) - .filter(Node::isGroupNode) - .map(Node::getGroupName) - .collect(Collectors.toList()); - } }