mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-28 20:17:55 +01:00
Another Vault fix & cleanup User / Group classes
This commit is contained in:
parent
63b9be9845
commit
2d8083bf18
@ -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
|
||||
|
@ -548,17 +548,6 @@ public abstract class PermissionHolder {
|
||||
return getPermissions(false).stream().filter(Node::isTemporary).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Map<Map.Entry<String, Boolean>, Long> getTemporaryNodesLegacy() {
|
||||
Map<Map.Entry<String, Boolean>, 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<String> 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<String> 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<String> 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<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups, List<String> possibleNodes) {
|
||||
Map<String, String> context = new HashMap<>();
|
||||
|
@ -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<String> {
|
||||
@ -73,7 +69,7 @@ public class Group extends PermissionHolder implements Identifiable<String> {
|
||||
* @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<String> {
|
||||
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<String> {
|
||||
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<String> {
|
||||
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<String> {
|
||||
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<String> {
|
||||
* @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<String> {
|
||||
* @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<String> {
|
||||
* @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<String> {
|
||||
* @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<String> {
|
||||
* @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<String> {
|
||||
* @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<String> {
|
||||
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<String> 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<String> 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<String> 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<String> 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());
|
||||
}
|
||||
}
|
||||
|
@ -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<UUID
|
||||
* @return true if the user is a member of the group
|
||||
*/
|
||||
public boolean isInGroup(Group group) {
|
||||
return isInGroup(group, "global");
|
||||
return hasPermission("group." + group.getName(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,10 +131,6 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
*/
|
||||
public void addGroup(Group group, String server) throws 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));
|
||||
}
|
||||
@ -150,10 +143,6 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
*/
|
||||
public void addGroup(Group group, String server, String world) throws 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 +166,6 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
*/
|
||||
public void addGroup(Group group, String server, long expireAt) throws 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));
|
||||
}
|
||||
@ -194,10 +179,6 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
*/
|
||||
public void addGroup(Group group, String server, String world, long expireAt) throws 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));
|
||||
}
|
||||
@ -208,7 +189,7 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
public void removeGroup(Group group) throws ObjectLacksException {
|
||||
removeGroup(group, "global");
|
||||
unsetPermission("group." + group.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,7 +199,7 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
public void removeGroup(Group group, boolean temporary) throws ObjectLacksException {
|
||||
removeGroup(group, "global", temporary);
|
||||
unsetPermission("group." + group.getName(), temporary);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,10 +209,6 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
public void removeGroup(Group group, String server) throws ObjectLacksException {
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
unsetPermission("group." + group.getName(), server);
|
||||
}
|
||||
|
||||
@ -243,10 +220,6 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
public void removeGroup(Group group, String server, String world) throws ObjectLacksException {
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
unsetPermission("group." + group.getName(), server, world);
|
||||
}
|
||||
|
||||
@ -258,10 +231,6 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
public void removeGroup(Group group, String server, boolean temporary) throws ObjectLacksException {
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
unsetPermission("group." + group.getName(), server, temporary);
|
||||
}
|
||||
|
||||
@ -274,10 +243,6 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
public void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException {
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
unsetPermission("group." + group.getName(), server, world, temporary);
|
||||
}
|
||||
|
||||
@ -288,49 +253,4 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
getNodes().clear();
|
||||
getPlugin().getUserManager().giveDefaultIfNeeded(this, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link List} of all of the groups the user is a member of, on all servers
|
||||
* @return a {@link List} of group names
|
||||
*/
|
||||
public List<String> 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<String> 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<String> 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<String> 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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user