2022-07-20 13:18:57 +02:00
|
|
|
|
package fr.pandacube.lib.permissions;
|
2021-03-21 20:17:31 +01:00
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
2022-07-20 13:18:57 +02:00
|
|
|
|
import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedGroup;
|
|
|
|
|
import fr.pandacube.lib.permissions.SQLPermissions.EntityType;
|
2021-03-21 20:17:31 +01:00
|
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
|
/**
|
|
|
|
|
* Represents an group in the permission system.
|
|
|
|
|
*/
|
|
|
|
|
public final class PermGroup extends PermEntity {
|
2021-03-21 20:17:31 +01:00
|
|
|
|
/* package */ PermGroup(String name) {
|
|
|
|
|
super(name, EntityType.Group);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected CachedGroup getBackendEntity() {
|
|
|
|
|
return Permissions.backendReader.getCachedGroup(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return getInternalName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<PermGroup> getInheritances() {
|
|
|
|
|
return fromCachedGroups(getBackendEntity().inheritances);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getInheritancesString() {
|
|
|
|
|
return getBackendEntity().inheritances.stream()
|
|
|
|
|
.map(cg -> cg.name)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
2022-08-10 03:04:12 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tells if this group is a default group.
|
|
|
|
|
* A player inherits all default groups when they don’t explicitely inherit from at least one group.
|
|
|
|
|
* @return true if this group is a default group, false otherwise.
|
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
|
public boolean isDefault() {
|
|
|
|
|
return getBackendEntity().deflt;
|
|
|
|
|
}
|
2022-08-10 03:04:12 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets this group as a default group or not.
|
|
|
|
|
* All players that don’t explicitely inherit from at least one group will either start or stop implicitely
|
|
|
|
|
* inheriting from this group.
|
|
|
|
|
* @param deflt true to set this group as default, false to set is as not default.
|
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
|
public void setDefault(boolean deflt) {
|
|
|
|
|
Permissions.backendWriter.setGroupDefault(name, deflt);
|
|
|
|
|
}
|
2022-08-10 03:04:12 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Makes this group inherit the provided group.
|
|
|
|
|
* @param group the name of the group to inherit from.
|
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
|
public void addInheritance(String group) {
|
|
|
|
|
Permissions.backendWriter.addInheritance(name, type, group);
|
|
|
|
|
}
|
2022-08-10 03:04:12 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Makes this group inherit the provided group.
|
|
|
|
|
* @param group the group to inherit from.
|
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
|
public void addInheritance(PermGroup group) {
|
|
|
|
|
addInheritance(group.name);
|
|
|
|
|
}
|
2022-08-10 03:04:12 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Makes this group stop inheriting from the provided group.
|
|
|
|
|
* @param group the name of the group to stop inheriting from.
|
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
|
public void removeInheritance(String group) {
|
|
|
|
|
Permissions.backendWriter.removeInheritance(name, type, group);
|
|
|
|
|
}
|
2022-08-10 03:04:12 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Makes this group stop inheriting from the provided group.
|
|
|
|
|
* @param group the group to stop inheriting from.
|
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
|
public void removeInheritance(PermGroup group) {
|
|
|
|
|
removeInheritance(group.name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* package */ static List<PermGroup> fromCachedGroups(List<CachedGroup> in) {
|
|
|
|
|
return in.stream()
|
|
|
|
|
.map(cg -> Permissions.getGroup(cg.name))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
}
|