Add configuration of custom Special Permissions
This commit is contained in:
parent
425527ddb2
commit
dcfafb92cb
@ -33,6 +33,14 @@ public class Permissions {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addSpecialPermissions(SpecialPermission... specialPermissions) {
|
||||||
|
checkInitialized();
|
||||||
|
if (specialPermissions == null)
|
||||||
|
return;
|
||||||
|
for (SpecialPermission sp : specialPermissions)
|
||||||
|
resolver.specialPermissions.add(sp);
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkInitialized() {
|
private static void checkInitialized() {
|
||||||
if (backendReader == null) {
|
if (backendReader == null) {
|
||||||
|
@ -386,6 +386,12 @@ public class PermissionsResolver {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* package */ List<SpecialPermission> specialPermissions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private PermResolutionNode resolveSelfPermission(CachedEntity entity, String permission, String server, String world) {
|
private PermResolutionNode resolveSelfPermission(CachedEntity entity, String permission, String server, String world) {
|
||||||
// special permissions
|
// special permissions
|
||||||
PermState result = PermState.UNDEFINED;
|
PermState result = PermState.UNDEFINED;
|
||||||
@ -396,38 +402,15 @@ public class PermissionsResolver {
|
|||||||
* Check for special permissions
|
* Check for special permissions
|
||||||
*/
|
*/
|
||||||
if (entity instanceof CachedPlayer) {
|
if (entity instanceof CachedPlayer) {
|
||||||
PermPlayer permP = new PermPlayer(((CachedPlayer) entity).playerId);
|
PermPlayer permP = Permissions.getPlayer(((CachedPlayer) entity).playerId);
|
||||||
ParsedSelfPermission specialPerm = null;
|
ParsedSelfPermission specialPerm = null;
|
||||||
if (permission.equals("pandacube.grade.isinstaff")) {
|
|
||||||
boolean res = permP.inheritsFromGroup("staff-base", true);
|
for (SpecialPermission spePerm : specialPermissions) {
|
||||||
specialPerm = new ParsedSelfPermission(permission, res, PermType.SPECIAL);
|
if (spePerm.match().match(permission)) {
|
||||||
conflict = "Special permission 'pandacube.grade.isinstaff' is deprecated. Use 'pandacube.inheritsfrom.<staffBaseGroup>' instead.";
|
boolean res = spePerm.tester().test(permP, permission, server, world);
|
||||||
}
|
specialPerm = new ParsedSelfPermission(permission, res, PermType.SPECIAL);
|
||||||
else if (permission.startsWith("pandacube.grade.")) {
|
break;
|
||||||
String group = permission.substring("pandacube.grade.".length());
|
}
|
||||||
boolean res = permP.inheritsFromGroup(group, false);
|
|
||||||
specialPerm = new ParsedSelfPermission(permission, res, PermType.SPECIAL);
|
|
||||||
conflict = "Special permission 'pandacube.grade.<groupName>' is deprecated. Use 'pandacube.ingroup.<groupName>' instead.";
|
|
||||||
}
|
|
||||||
else if (permission.startsWith("pandacube.ingroup.")) {
|
|
||||||
String group = permission.substring("pandacube.ingroup.".length());
|
|
||||||
boolean res = permP.inheritsFromGroup(group, false);
|
|
||||||
specialPerm = new ParsedSelfPermission(permission, res, PermType.SPECIAL);
|
|
||||||
}
|
|
||||||
else if (permission.startsWith("pandacube.inheritsfrom.")) {
|
|
||||||
String group = permission.substring("pandacube.inheritsfrom.".length());
|
|
||||||
boolean res = permP.inheritsFromGroup(group, true);
|
|
||||||
specialPerm = new ParsedSelfPermission(permission, res, PermType.SPECIAL);
|
|
||||||
}
|
|
||||||
else if (permission.startsWith("pandacube.inserver.")) {
|
|
||||||
String testedServer = permission.substring("pandacube.inserver.".length());
|
|
||||||
boolean res = testedServer.equals(server);
|
|
||||||
specialPerm = new ParsedSelfPermission(permission, res, PermType.SPECIAL);
|
|
||||||
}
|
|
||||||
else if (permission.startsWith("pandacube.inserverworld.")) {
|
|
||||||
String testedServerWorld = permission.substring("pandacube.inserverworld.".length());
|
|
||||||
boolean res = server != null && world != null && testedServerWorld.equals(server + "." + world);
|
|
||||||
specialPerm = new ParsedSelfPermission(permission, res, PermType.SPECIAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specialPerm != null) {
|
if (specialPerm != null) {
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package fr.pandacube.lib.core.permissions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a permission node that is based on an arbitrary player state.
|
||||||
|
*/
|
||||||
|
public record SpecialPermission(PermissionMatcher match, PermissionTester tester) {
|
||||||
|
|
||||||
|
public interface PermissionMatcher {
|
||||||
|
boolean match(String permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface PermissionTester {
|
||||||
|
boolean test(PermPlayer player, String permission, String server, String world);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,7 +33,7 @@ import fr.pandacube.lib.core.util.Log;
|
|||||||
public class PlayerFinder {
|
public class PlayerFinder {
|
||||||
|
|
||||||
private static Cache<UUID, String> playerLastKnownName = CacheBuilder.newBuilder()
|
private static Cache<UUID, String> playerLastKnownName = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(2, TimeUnit.MINUTES)
|
.expireAfterWrite(10, TimeUnit.MINUTES)
|
||||||
.maximumSize(1000)
|
.maximumSize(1000)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package fr.pandacube.lib.core.util;
|
package fr.pandacube.lib.core.util;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StringUtil {
|
public class StringUtil {
|
||||||
@ -33,23 +34,11 @@ public class StringUtil {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String repeat(String base, int count) {
|
|
||||||
int baseLength = base.length();
|
|
||||||
char[] baseChars = base.toCharArray();
|
|
||||||
char[] chars = new char[baseLength * count];
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
System.arraycopy(baseChars, 0, chars, i * baseLength, baseLength);
|
|
||||||
}
|
|
||||||
return new String(chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String repeat(char base, int count) {
|
public static String repeat(char base, int count) {
|
||||||
char[] chars = new char[count];
|
char[] chars = new char[count];
|
||||||
for (int i = 0; i < count; i++) {
|
Arrays.fill(chars, base);
|
||||||
chars[i] = base;
|
|
||||||
}
|
|
||||||
return new String(chars);
|
return new String(chars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ public class TimeUtil {
|
|||||||
int padding = leftPad - valueStr.length();
|
int padding = leftPad - valueStr.length();
|
||||||
if (padding <= 0)
|
if (padding <= 0)
|
||||||
return valueStr;
|
return valueStr;
|
||||||
return StringUtil.repeat("0", padding) + valueStr;
|
return "0".repeat(padding) + valueStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user