-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: Add the ability to query an Audience for a value based on a Poin…
…ter key
- Loading branch information
Showing
14 changed files
with
620 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2021 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package net.kyori.adventure; | ||
|
||
import net.kyori.adventure.key.Key; | ||
|
||
/** | ||
* We're going on an Adventure! | ||
* | ||
* @since 4.8.0 | ||
*/ | ||
public final class Adventure { | ||
/** | ||
* The namespace. | ||
* | ||
* @see Key | ||
* @since 4.8.0 | ||
*/ | ||
public static final String NAMESPACE = "adventure"; | ||
|
||
private Adventure() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
api/src/main/java/net/kyori/adventure/permission/PermissionChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2021 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package net.kyori.adventure.permission; | ||
|
||
import java.util.function.Predicate; | ||
import net.kyori.adventure.Adventure; | ||
import net.kyori.adventure.key.Key; | ||
import net.kyori.adventure.pointer.Pointer; | ||
import net.kyori.adventure.util.TriState; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
/** | ||
* Something that has permissions. | ||
* | ||
* @since 4.8.0 | ||
*/ | ||
public interface PermissionChecker extends Predicate<String> { | ||
/** | ||
* A pointer to a permission predicate. | ||
* | ||
* @since 4.8.0 | ||
*/ | ||
Pointer<PermissionChecker> POINTER = Pointer.pointer(PermissionChecker.class, Key.key(Adventure.NAMESPACE, "permission")); | ||
|
||
/** | ||
* Creates a {@link PermissionChecker} that always returns {@code state}. | ||
* | ||
* @param state the state | ||
* @return a {@link PermissionChecker} | ||
* @since 4.8.0 | ||
*/ | ||
static @NonNull PermissionChecker always(final TriState state) { | ||
if(state == TriState.TRUE) return PermissionCheckers.TRUE; | ||
if(state == TriState.FALSE) return PermissionCheckers.FALSE; | ||
return PermissionCheckers.NOT_SET; | ||
} | ||
|
||
/** | ||
* Checks if something has a permission. | ||
* | ||
* @param permission the permission | ||
* @return a tri-state result | ||
* @since 4.8.0 | ||
*/ | ||
@NonNull TriState value(final String permission); | ||
|
||
@Override | ||
default boolean test(final String permission) { | ||
return this.value(permission) == TriState.TRUE; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
api/src/main/java/net/kyori/adventure/permission/PermissionCheckers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2021 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package net.kyori.adventure.permission; | ||
|
||
import net.kyori.adventure.util.TriState; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
final class PermissionCheckers { | ||
static final PermissionChecker NOT_SET = new Always(TriState.NOT_SET); | ||
static final PermissionChecker FALSE = new Always(TriState.FALSE); | ||
static final PermissionChecker TRUE = new Always(TriState.TRUE); | ||
|
||
private PermissionCheckers() { | ||
} | ||
|
||
private static final class Always implements PermissionChecker { | ||
private final TriState value; | ||
|
||
private Always(final TriState value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public @NonNull TriState value(final String permission) { | ||
return this.value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return PermissionChecker.class.getSimpleName() + ".always(" + this.value + ")"; | ||
} | ||
|
||
@Override | ||
public boolean equals(final @Nullable Object other) { | ||
if(this == other) return true; | ||
if(other == null || this.getClass() != other.getClass()) return false; | ||
final Always always = (Always) other; | ||
return this.value == always.value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return this.value.hashCode(); | ||
} | ||
} | ||
} |
Oops, something went wrong.