geforkt von Mirrors/Velocity
Move #getPermissionChecker
Dieser Commit ist enthalten in:
Ursprung
72408d5bd8
Commit
e798f0d906
@ -8,15 +8,12 @@
|
||||
package com.velocitypowered.api.command;
|
||||
|
||||
import com.velocitypowered.api.permission.PermissionSubject;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.MessageType;
|
||||
import net.kyori.adventure.identity.Identified;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
@ -39,24 +36,4 @@ public interface CommandSource extends Audience, PermissionSubject {
|
||||
@NonNull MessageType type) {
|
||||
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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
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.
|
||||
*/
|
||||
@ -29,4 +32,24 @@ public interface PermissionSubject {
|
||||
* @return the value the permission is set to
|
||||
*/
|
||||
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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren