Add logging, prepare for import/export system
This commit is contained in:
@@ -26,10 +26,11 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
import me.lucko.luckperms.utils.PermissionHolder;
|
||||
import me.lucko.luckperms.utils.Identifiable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -37,7 +38,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@ToString(of = {"name"})
|
||||
@EqualsAndHashCode(of = {"name"}, callSuper = false)
|
||||
public class Group extends PermissionHolder {
|
||||
public class Group extends PermissionHolder implements Identifiable<String> {
|
||||
|
||||
/**
|
||||
* The name of the group
|
||||
@@ -56,7 +57,7 @@ public class Group extends PermissionHolder {
|
||||
* @return true if the user is a member of the group
|
||||
*/
|
||||
public boolean inheritsGroup(Group group) {
|
||||
return inheritsGroup(group, "global");
|
||||
return group.getName().equalsIgnoreCase(this.getName()) || inheritsGroup(group, "global");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +67,7 @@ public class Group extends PermissionHolder {
|
||||
* @return true if the group inherits the group
|
||||
*/
|
||||
public boolean inheritsGroup(Group group, String server) {
|
||||
return hasPermission("group." + group.getName(), true, server);
|
||||
return group.getName().equalsIgnoreCase(this.getName()) || hasPermission("group." + group.getName(), true, server);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +78,7 @@ public class Group extends PermissionHolder {
|
||||
* @return true if the group inherits the group
|
||||
*/
|
||||
public boolean inheritsGroup(Group group, String server, String world) {
|
||||
return hasPermission("group." + group.getName(), true, server, world);
|
||||
return group.getName().equalsIgnoreCase(this.getName()) || hasPermission("group." + group.getName(), true, server, world);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +97,10 @@ public class Group extends PermissionHolder {
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
public void setInheritGroup(Group group, String server) throws ObjectAlreadyHasException {
|
||||
if (group.getName().equalsIgnoreCase(this.getName())) {
|
||||
throw new ObjectAlreadyHasException();
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
@@ -111,6 +116,10 @@ public class Group extends PermissionHolder {
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
public void setInheritGroup(Group group, String server, String world) throws ObjectAlreadyHasException {
|
||||
if (group.getName().equalsIgnoreCase(this.getName())) {
|
||||
throw new ObjectAlreadyHasException();
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
@@ -125,6 +134,10 @@ public class Group extends PermissionHolder {
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
public void setInheritGroup(Group group, long expireAt) throws ObjectAlreadyHasException {
|
||||
if (group.getName().equalsIgnoreCase(this.getName())) {
|
||||
throw new ObjectAlreadyHasException();
|
||||
}
|
||||
|
||||
setPermission("group." + group.getName(), true, expireAt);
|
||||
}
|
||||
|
||||
@@ -136,6 +149,10 @@ public class Group extends PermissionHolder {
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
public void setInheritGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException {
|
||||
if (group.getName().equalsIgnoreCase(this.getName())) {
|
||||
throw new ObjectAlreadyHasException();
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
@@ -152,6 +169,10 @@ public class Group extends PermissionHolder {
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
public void setInheritGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException {
|
||||
if (group.getName().equalsIgnoreCase(this.getName())) {
|
||||
throw new ObjectAlreadyHasException();
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
@@ -288,4 +309,9 @@ public class Group extends PermissionHolder {
|
||||
.map(s -> Patterns.DOT.split(s, 2)[1])
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,77 +22,17 @@
|
||||
|
||||
package me.lucko.luckperms.groups;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import me.lucko.luckperms.utils.AbstractManager;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class GroupManager {
|
||||
public class GroupManager extends AbstractManager<String, Group> {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
/**
|
||||
* A {@link Map} containing all loaded groups
|
||||
*/
|
||||
@Getter
|
||||
private final Map<String, Group> groups = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Get a group object by name
|
||||
* @param name The name to search by
|
||||
* @return a {@link Group} object if the group is loaded, returns null if the group is not loaded
|
||||
*/
|
||||
public Group getGroup(String name) {
|
||||
return groups.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a group to the loaded groups map
|
||||
* @param group The group to add
|
||||
*/
|
||||
public void setGroup(Group group) {
|
||||
groups.put(group.getName(), group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates (or sets if the group wasn't already loaded) a group in the groups map
|
||||
* @param group The group to update or set
|
||||
*/
|
||||
public void updateOrSetGroup(Group group) {
|
||||
if (!isLoaded(group.getName())) {
|
||||
// The group isn't already loaded
|
||||
groups.put(group.getName(), group);
|
||||
} else {
|
||||
groups.get(group.getName()).setNodes(group.getNodes());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a group is loaded or not
|
||||
* @param name The name of the group
|
||||
* @return true if the group is loaded
|
||||
*/
|
||||
public boolean isLoaded(String name) {
|
||||
return groups.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and unloads the group from the plugins internal storage
|
||||
* @param group The group to unload
|
||||
*/
|
||||
public void unloadGroup(Group group) {
|
||||
if (group != null) {
|
||||
groups.remove(group.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unloads all groups from the manager
|
||||
*/
|
||||
public void unloadAll() {
|
||||
groups.clear();
|
||||
@Override
|
||||
protected void copy(Group from, Group to) {
|
||||
to.setNodes(from.getNodes());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +40,8 @@ public class GroupManager {
|
||||
* @param name The name of the group
|
||||
* @return a new {@link Group} object
|
||||
*/
|
||||
public Group makeGroup(String name) {
|
||||
@Override
|
||||
public Group make(String name) {
|
||||
return new Group(name, plugin);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user