diff --git a/.checkstyle/suppressions.xml b/.checkstyle/suppressions.xml index 38dd9113de..cf97465109 100644 --- a/.checkstyle/suppressions.xml +++ b/.checkstyle/suppressions.xml @@ -1,6 +1,9 @@ + + + diff --git a/api/src/main/java/net/kyori/adventure/Adventure.java b/api/src/main/java/net/kyori/adventure/Adventure.java new file mode 100644 index 0000000000..e8085aab8c --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/Adventure.java @@ -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() { + } +} diff --git a/api/src/main/java/net/kyori/adventure/audience/Audience.java b/api/src/main/java/net/kyori/adventure/audience/Audience.java index f74164a614..fa08858c2a 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -26,14 +26,15 @@ import java.util.Arrays; import java.util.stream.Collector; import net.kyori.adventure.bossbar.BossBar; +import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; +import net.kyori.adventure.pointer.Pointered; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.title.Title; -import net.kyori.adventure.identity.Identified; import org.checkerframework.checker.nullness.qual.NonNull; /** @@ -77,7 +78,7 @@ * @see ForwardingAudience * @since 4.0.0 */ -public interface Audience { +public interface Audience extends Pointered { /** * Gets an audience that does nothing. * diff --git a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java index 8f87a7a614..acba43dc2a 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -23,15 +23,34 @@ */ package net.kyori.adventure.audience; +import java.util.Optional; +import java.util.function.Supplier; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; +import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.identity.Identified; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.PolyNull; final class EmptyAudience implements Audience { static final EmptyAudience INSTANCE = new EmptyAudience(); + @Override + public @NonNull Optional get(final @NonNull Pointer pointer) { + return Optional.empty(); + } + + @Override + public @PolyNull T getOrDefault(final @NonNull Pointer pointer, final @PolyNull T defaultValue) { + return defaultValue; + } + + @Override + public @PolyNull T getOrDefaultFrom(final @NonNull Pointer pointer, final @NonNull Supplier defaultValue) { + return defaultValue.get(); + } + @Override public void sendMessage(final @NonNull ComponentLike message) { } diff --git a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java index c94a80b4b6..00db3ae909 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -24,6 +24,9 @@ package net.kyori.adventure.audience; import java.util.Collections; +import java.util.Optional; +import java.util.function.Supplier; +import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; @@ -33,6 +36,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.title.Title; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.PolyNull; import org.jetbrains.annotations.ApiStatus; /** @@ -55,6 +59,21 @@ public interface ForwardingAudience extends Audience { @ApiStatus.OverrideOnly @NonNull Iterable audiences(); + @Override + default @NonNull Optional get(final @NonNull Pointer pointer) { + return Optional.empty(); // unsupported + } + + @Override + default @PolyNull T getOrDefault(final @NonNull Pointer pointer, final @PolyNull T defaultValue) { + return defaultValue; // unsupported + } + + @Override + default @PolyNull T getOrDefaultFrom(final @NonNull Pointer pointer, final @NonNull Supplier defaultValue) { + return defaultValue.get(); // unsupported + } + @Override default void sendMessage(final @NonNull Identified source, final @NonNull Component message, final @NonNull MessageType type) { for(final Audience audience : this.audiences()) audience.sendMessage(source, message, type); @@ -157,6 +176,11 @@ interface Single extends ForwardingAudience { return Collections.singleton(this.audience()); } + @Override + default @NonNull Optional get(final @NonNull Pointer pointer) { + return this.audience().get(pointer); + } + @Override default void sendMessage(final @NonNull Identified source, final @NonNull Component message, final @NonNull MessageType type) { this.audience().sendMessage(source, message, type); diff --git a/api/src/main/java/net/kyori/adventure/identity/Identity.java b/api/src/main/java/net/kyori/adventure/identity/Identity.java index 8170a9f7ed..d1484e2c24 100644 --- a/api/src/main/java/net/kyori/adventure/identity/Identity.java +++ b/api/src/main/java/net/kyori/adventure/identity/Identity.java @@ -25,6 +25,10 @@ import java.util.UUID; import java.util.stream.Stream; +import net.kyori.adventure.Adventure; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.pointer.Pointer; +import net.kyori.adventure.text.Component; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; import org.checkerframework.checker.nullness.qual.NonNull; @@ -37,6 +41,25 @@ * @sinceMinecraft 1.16 */ public interface Identity extends Examinable { + /** + * A pointer to a name. + * + * @since 4.8.0 + */ + Pointer NAME = Pointer.pointer(String.class, Key.key(Adventure.NAMESPACE, "name")); + /** + * A pointer to a {@link UUID}. + * + * @since 4.8.0 + */ + Pointer UUID = Pointer.pointer(UUID.class, Key.key(Adventure.NAMESPACE, "uuid")); + /** + * A pointer to a display name. + * + * @since 4.8.0 + */ + Pointer DISPLAY_NAME = Pointer.pointer(Component.class, Key.key(Adventure.NAMESPACE, "display_name")); + /** * Gets the {@code null} identity. * diff --git a/api/src/main/java/net/kyori/adventure/permission/PermissionChecker.java b/api/src/main/java/net/kyori/adventure/permission/PermissionChecker.java new file mode 100644 index 0000000000..d8422ca873 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/permission/PermissionChecker.java @@ -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 { + /** + * A pointer to a permission predicate. + * + * @since 4.8.0 + */ + Pointer 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; + } +} diff --git a/api/src/main/java/net/kyori/adventure/permission/PermissionCheckers.java b/api/src/main/java/net/kyori/adventure/permission/PermissionCheckers.java new file mode 100644 index 0000000000..608b2fa306 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/permission/PermissionCheckers.java @@ -0,0 +1,51 @@ +/* + * 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; + +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 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 + ")"; + } + } +} diff --git a/api/src/main/java/net/kyori/adventure/pointer/Pointer.java b/api/src/main/java/net/kyori/adventure/pointer/Pointer.java new file mode 100644 index 0000000000..a12ef55fe1 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/pointer/Pointer.java @@ -0,0 +1,75 @@ +/* + * 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.pointer; + +import java.util.stream.Stream; +import net.kyori.adventure.key.Key; +import net.kyori.examination.Examinable; +import net.kyori.examination.ExaminableProperty; +import org.checkerframework.checker.nullness.qual.NonNull; + +/** + * A pointer to a resource. + * + * @param the value type + * @since 4.8.0 + */ +public interface Pointer extends Examinable { + /** + * Creates a pointer. + * + * @param type the value type + * @param key the key + * @param the value type + * @return the pointer + * @since 4.8.0 + */ + static @NonNull Pointer pointer(final @NonNull Class type, final @NonNull Key key) { + return new PointerImpl<>(type, key); + } + + /** + * Gets the value type. + * + * @return the value type + * @since 4.8.0 + */ + @NonNull Class type(); + + /** + * Gets the key. + * + * @return the key + * @since 4.8.0 + */ + @NonNull Key key(); + + @Override + default @NonNull Stream examinableProperties() { + return Stream.of( + ExaminableProperty.of("type", this.type()), + ExaminableProperty.of("key", this.key()) + ); + } +} diff --git a/api/src/main/java/net/kyori/adventure/pointer/PointerImpl.java b/api/src/main/java/net/kyori/adventure/pointer/PointerImpl.java new file mode 100644 index 0000000000..9729dd953c --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/pointer/PointerImpl.java @@ -0,0 +1,69 @@ +/* + * 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.pointer; + +import net.kyori.adventure.key.Key; +import net.kyori.examination.string.StringExaminer; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +final class PointerImpl implements Pointer { + private final Class type; + private final Key key; + + PointerImpl(final Class type, final Key key) { + this.type = type; + this.key = key; + } + + @Override + public @NonNull Class type() { + return this.type; + } + + @Override + public @NonNull Key key() { + return this.key; + } + + @Override + public String toString() { + return this.examine(StringExaminer.simpleEscaping()); + } + + @Override + public boolean equals(final @Nullable Object other) { + if(this == other) return true; + if(other == null || this.getClass() != other.getClass()) return false; + final PointerImpl that = (PointerImpl) other; + return this.type.equals(that.type) && this.key.equals(that.key); + } + + @Override + public int hashCode() { + int result = this.type.hashCode(); + result = (31 * result) + this.key.hashCode(); + return result; + } +} diff --git a/api/src/main/java/net/kyori/adventure/pointer/Pointered.java b/api/src/main/java/net/kyori/adventure/pointer/Pointered.java new file mode 100644 index 0000000000..505917269d --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/pointer/Pointered.java @@ -0,0 +1,80 @@ +/* + * 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.pointer; + +import java.util.Optional; +import java.util.function.Supplier; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.PolyNull; + +/** + * Something that can retrieve values based on a given {@link Pointer}. + * + * @since 4.8.0 + */ +public interface Pointered { + /** + * Gets the value of {@code pointer}. + * + * @param pointer the pointer + * @param the type + * @return the value + * @since 4.8.0 + */ + default @NonNull Optional get(final @NonNull Pointer pointer) { + return Optional.empty(); + } + + /** + * Gets the value of {@code pointer}. + * + *

If this {@code Audience} is unable to provide a value for {@code pointer}, {@code defaultValue} will be returned.

+ * + * @param pointer the pointer + * @param defaultValue the default value + * @param the type + * @return the value + * @since 4.8.0 + */ + @SuppressWarnings("checkstyle:MethodName") + default @PolyNull T getOrDefault(final @NonNull Pointer pointer, final @PolyNull T defaultValue) { + return this.get(pointer).orElse(defaultValue); + } + + /** + * Gets the value of {@code pointer}. + * + *

If this {@code Audience} is unable to provide a value for {@code pointer}, the value supplied by {@code defaultValue} will be returned.

+ * + * @param pointer the pointer + * @param defaultValue the default value supplier + * @param the type + * @return the value + * @since 4.8.0 + */ + @SuppressWarnings("checkstyle:MethodName") + default @PolyNull T getOrDefaultFrom(final @NonNull Pointer pointer, final @NonNull Supplier defaultValue) { + return this.get(pointer).orElseGet(defaultValue); + } +} diff --git a/api/src/main/java/net/kyori/adventure/util/TriState.java b/api/src/main/java/net/kyori/adventure/util/TriState.java new file mode 100644 index 0000000000..8b9176c88f --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/util/TriState.java @@ -0,0 +1,50 @@ +/* + * 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.util; + +/** + * Similar to a {@code boolean} but with three states. + * + * @since 4.8.0 + */ +public enum TriState { + /** + * State describing the absence of a value. + * + * @since 4.8.0 + */ + NOT_SET, + /** + * State describing a {@code false} value. + * + * @since 4.8.0 + */ + FALSE, + /** + * State describing a {@code true} value. + * + * @since 4.8.0 + */ + TRUE; +} diff --git a/api/src/test/java/net/kyori/adventure/audience/AudienceTest.java b/api/src/test/java/net/kyori/adventure/audience/AudienceTest.java index fbdb0b9b18..3903ba0da1 100644 --- a/api/src/test/java/net/kyori/adventure/audience/AudienceTest.java +++ b/api/src/test/java/net/kyori/adventure/audience/AudienceTest.java @@ -24,10 +24,15 @@ package net.kyori.adventure.audience; import com.google.common.testing.EqualsTester; +import java.util.Optional; +import java.util.UUID; import java.util.stream.Stream; +import net.kyori.adventure.identity.Identity; import org.junit.jupiter.api.Test; import static com.google.common.truth.Truth.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -52,6 +57,24 @@ void testOf_many() { assertThat(((ForwardingAudience) ma).audiences()).containsExactly(a0, a1).inOrder(); } + @Test + void testGet() { + assertEquals(Optional.empty(), Audience.empty().get(Identity.UUID)); + } + + @Test + void testGetOrDefault() { + final UUID uuid = UUID.randomUUID(); + assertNull(Audience.empty().getOrDefault(Identity.UUID, null)); + assertEquals(uuid, Audience.empty().getOrDefault(Identity.UUID, uuid)); + } + + @Test + void testGetOrDefaultFrom() { + final UUID uuid = UUID.randomUUID(); + assertEquals(uuid, Audience.empty().getOrDefaultFrom(Identity.UUID, () -> uuid)); + } + @Test void testEquality() { new EqualsTester()