From e798f0d906d083422364a3899c1fe4e5f260f7c2 Mon Sep 17 00:00:00 2001 From: lexikiq Date: Sat, 12 Jun 2021 12:52:35 -0400 Subject: [PATCH] Move #getPermissionChecker --- .../api/command/CommandSource.java | 23 ------------------- .../api/permission/PermissionSubject.java | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandSource.java b/api/src/main/java/com/velocitypowered/api/command/CommandSource.java index 31392f538..c37105075 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandSource.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandSource.java @@ -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(); - } - }; - } } diff --git a/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java b/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java index ec7171e9f..2f1c036c9 100644 --- a/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java +++ b/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java @@ -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(); + } + }; + } }