From 5c424c1da7fb71652b3449cca3331457716737c5 Mon Sep 17 00:00:00 2001 From: lexikiq Date: Sat, 12 Jun 2021 20:01:42 -0400 Subject: [PATCH] Move TriState converter --- .../api/permission/PermissionSubject.java | 13 +------------ .../velocitypowered/api/permission/Tristate.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) 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 2f1c036c9..b117f7385 100644 --- a/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java +++ b/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java @@ -39,17 +39,6 @@ public interface PermissionSubject { * @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(); - } - }; + return permission -> getPermissionValue(permission).toAdventureTriState(); } } diff --git a/api/src/main/java/com/velocitypowered/api/permission/Tristate.java b/api/src/main/java/com/velocitypowered/api/permission/Tristate.java index 70653eef6..cdb82c184 100644 --- a/api/src/main/java/com/velocitypowered/api/permission/Tristate.java +++ b/api/src/main/java/com/velocitypowered/api/permission/Tristate.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.permission; +import net.kyori.adventure.util.TriState; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -81,4 +82,16 @@ public enum Tristate { public boolean asBoolean() { return this.booleanValue; } + + public TriState toAdventureTriState() { + if (this == Tristate.TRUE) { + return TriState.TRUE; + } else if (this == Tristate.UNDEFINED) { + return TriState.NOT_SET; + } else if (this == Tristate.FALSE) { + return TriState.FALSE; + } else { + throw new IllegalArgumentException(); + } + } }