diff options
author | Keuin <[email protected]> | 2022-09-20 21:41:12 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-09-20 21:41:12 +0800 |
commit | e9dcb9f5f83afc994aeb19b5f987be82c2c5929b (patch) | |
tree | 35f73dcfd7da351a1cd5c1fbc939378d9b0c2e70 /src/main | |
parent | 8d52fd34955aeeef7ec968d222b3aca8ca8b1ea2 (diff) |
Fix permission api not compiling.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/me/lucko/fabric/api/permissions/v0/PermissionCheckEvent.java | 3 | ||||
-rw-r--r-- | src/main/java/me/lucko/fabric/api/permissions/v0/Permissions.java | 46 |
2 files changed, 28 insertions, 21 deletions
diff --git a/src/main/java/me/lucko/fabric/api/permissions/v0/PermissionCheckEvent.java b/src/main/java/me/lucko/fabric/api/permissions/v0/PermissionCheckEvent.java index 42b5b63..d6b74f4 100644 --- a/src/main/java/me/lucko/fabric/api/permissions/v0/PermissionCheckEvent.java +++ b/src/main/java/me/lucko/fabric/api/permissions/v0/PermissionCheckEvent.java @@ -28,8 +28,7 @@ package me.lucko.fabric.api.permissions.v0; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.util.TriState; -import net.minecraft.command.CommandSource; - +import net.minecraft.server.command.CommandSource; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/me/lucko/fabric/api/permissions/v0/Permissions.java b/src/main/java/me/lucko/fabric/api/permissions/v0/Permissions.java index 9fab02b..f4c06db 100644 --- a/src/main/java/me/lucko/fabric/api/permissions/v0/Permissions.java +++ b/src/main/java/me/lucko/fabric/api/permissions/v0/Permissions.java @@ -26,10 +26,9 @@ package me.lucko.fabric.api.permissions.v0; import net.fabricmc.fabric.api.util.TriState; -import net.minecraft.command.CommandSource; import net.minecraft.entity.Entity; +import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; - import org.jetbrains.annotations.NotNull; import java.util.Objects; @@ -43,7 +42,7 @@ public interface Permissions { /** * Gets the {@link TriState state} of a {@code permission} for the given source. * - * @param source the source + * @param source the source * @param permission the permission * @return the state of the permission */ @@ -57,45 +56,54 @@ public interface Permissions { * Performs a permission check, falling back to the {@code defaultValue} if the resultant * state is {@link TriState#DEFAULT}. * - * @param source the source to perform the check for - * @param permission the permission to check + * @param source the source to perform the check for + * @param permission the permission to check * @param defaultValue the default value to use if nothing has been set * @return the result of the permission check */ static boolean check(@NotNull CommandSource source, @NotNull String permission, boolean defaultValue) { - return getPermissionValue(source, permission).orElse(defaultValue); + TriState value = getPermissionValue(source, permission); + if (value == TriState.DEFAULT) { + return defaultValue; + } + return value == TriState.TRUE; } /** * Performs a permission check, falling back to requiring the {@code defaultRequiredLevel} * if the resultant state is {@link TriState#DEFAULT}. * - * @param source the source to perform the check for - * @param permission the permission to check + * @param source the source to perform the check for + * @param permission the permission to check * @param defaultRequiredLevel the required permission level to check for as a fallback * @return the result of the permission check */ static boolean check(@NotNull CommandSource source, @NotNull String permission, int defaultRequiredLevel) { - return getPermissionValue(source, permission).orElseGet(() -> source.hasPermissionLevel(defaultRequiredLevel)); + TriState value = getPermissionValue(source, permission); + if (value == TriState.DEFAULT) { + return source.hasPermissionLevel(defaultRequiredLevel); + } + return value == TriState.TRUE; } /** * Performs a permission check, falling back to {@code false} if the resultant state * is {@link TriState#DEFAULT}. * - * @param source the source to perform the check for + * @param source the source to perform the check for * @param permission the permission to check * @return the result of the permission check */ static boolean check(@NotNull CommandSource source, @NotNull String permission) { - return getPermissionValue(source, permission).orElse(false); + TriState value = getPermissionValue(source, permission); + return value == TriState.TRUE; } /** * Creates a predicate which returns the result of performing a permission check, * falling back to the {@code defaultValue} if the resultant state is {@link TriState#DEFAULT}. * - * @param permission the permission to check + * @param permission the permission to check * @param defaultValue the default value to use if nothing has been set * @return a predicate that will perform the permission check */ @@ -109,7 +117,7 @@ public interface Permissions { * falling back to requiring the {@code defaultRequiredLevel} if the resultant state is * {@link TriState#DEFAULT}. * - * @param permission the permission to check + * @param permission the permission to check * @param defaultRequiredLevel the required permission level to check for as a fallback * @return a predicate that will perform the permission check */ @@ -133,7 +141,7 @@ public interface Permissions { /** * Gets the {@link TriState state} of a {@code permission} for the given entity. * - * @param entity the entity + * @param entity the entity * @param permission the permission * @return the state of the permission */ @@ -146,8 +154,8 @@ public interface Permissions { * Performs a permission check, falling back to the {@code defaultValue} if the resultant * state is {@link TriState#DEFAULT}. * - * @param entity the entity to perform the check for - * @param permission the permission to check + * @param entity the entity to perform the check for + * @param permission the permission to check * @param defaultValue the default value to use if nothing has been set * @return the result of the permission check */ @@ -160,8 +168,8 @@ public interface Permissions { * Performs a permission check, falling back to requiring the {@code defaultRequiredLevel} * if the resultant state is {@link TriState#DEFAULT}. * - * @param entity the entity to perform the check for - * @param permission the permission to check + * @param entity the entity to perform the check for + * @param permission the permission to check * @param defaultRequiredLevel the required permission level to check for as a fallback * @return the result of the permission check */ @@ -174,7 +182,7 @@ public interface Permissions { * Performs a permission check, falling back to {@code false} if the resultant state * is {@link TriState#DEFAULT}. * - * @param entity the entity to perform the check for + * @param entity the entity to perform the check for * @param permission the permission to check * @return the result of the permission check */ |