13
0
geforkt von Mirrors/Velocity

Move #getPermissionChecker

Dieser Commit ist enthalten in:
lexikiq 2021-06-12 12:52:35 -04:00
Ursprung 72408d5bd8
Commit e798f0d906
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: AE6C11E94FDBB116
2 geänderte Dateien mit 23 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -8,15 +8,12 @@
package com.velocitypowered.api.command; package com.velocitypowered.api.command;
import com.velocitypowered.api.permission.PermissionSubject; import com.velocitypowered.api.permission.PermissionSubject;
import com.velocitypowered.api.permission.Tristate;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.MessageType; import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.permission.PermissionChecker;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
import net.kyori.adventure.util.TriState;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
/** /**
@ -39,24 +36,4 @@ public interface CommandSource extends Audience, PermissionSubject {
@NonNull MessageType type) { @NonNull MessageType type) {
this.sendMessage(LegacyText3ComponentSerializer.get().serialize(message)); this.sendMessage(LegacyText3ComponentSerializer.get().serialize(message));
} }
/**
* Gets the permission checker for the invoker.
*
* @return invoker's permission checker
*/
default PermissionChecker getPermissionChecker() {
return permission -> {
final Tristate state = getPermissionValue(permission);
if (state == Tristate.TRUE) {
return TriState.TRUE;
} else if (state == Tristate.UNDEFINED) {
return TriState.NOT_SET;
} else if (state == Tristate.FALSE) {
return TriState.FALSE;
} else {
throw new IllegalArgumentException();
}
};
}
} }

Datei anzeigen

@ -7,6 +7,9 @@
package com.velocitypowered.api.permission; package com.velocitypowered.api.permission;
import net.kyori.adventure.permission.PermissionChecker;
import net.kyori.adventure.util.TriState;
/** /**
* Represents a object that has a set of queryable permissions. * Represents a object that has a set of queryable permissions.
*/ */
@ -29,4 +32,24 @@ public interface PermissionSubject {
* @return the value the permission is set to * @return the value the permission is set to
*/ */
Tristate getPermissionValue(String permission); Tristate getPermissionValue(String permission);
/**
* Gets the permission checker for the subject.
*
* @return subject's permission checker
*/
default PermissionChecker getPermissionChecker() {
return permission -> {
final Tristate state = getPermissionValue(permission);
if (state == Tristate.TRUE) {
return TriState.TRUE;
} else if (state == Tristate.UNDEFINED) {
return TriState.NOT_SET;
} else if (state == Tristate.FALSE) {
return TriState.FALSE;
} else {
throw new IllegalArgumentException();
}
};
}
} }