From 70c24ef8109637250f474de69530482c752a7f1c Mon Sep 17 00:00:00 2001 From: yusshu Date: Sat, 7 Oct 2023 13:37:55 -0500 Subject: [PATCH 01/10] feat(api): introduce ResourcePack API --- .../kyori/adventure/audience/Audience.java | 11 +++ .../audience/ForwardingAudience.java | 11 +++ .../adventure/resourcepack/ResourcePack.java | 99 +++++++++++++++++++ .../resourcepack/ResourcePackImpl.java | 98 ++++++++++++++++++ .../adventure/resourcepack/package-info.java | 27 +++++ 5 files changed, 246 insertions(+) create mode 100644 api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java create mode 100644 api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java create mode 100644 api/src/main/java/net/kyori/adventure/resourcepack/package-info.java 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 3911b9837..f3647bde0 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -36,6 +36,7 @@ import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointered; +import net.kyori.adventure.resourcepack.ResourcePack; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; @@ -700,4 +701,14 @@ default void openBook(final Book.@NotNull Builder book) { */ default void openBook(final @NotNull Book book) { } + + /** + * Sends a resource pack to this audience. + * + * @param resourcePack the resource pack + * @see ResourcePack + * @since 4.15.0 + */ + default void sendResourcePack(final @NotNull ResourcePack resourcePack) { + } } 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 8ba613519..5fcacfa66 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -38,6 +38,7 @@ import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.pointer.Pointers; +import net.kyori.adventure.resourcepack.ResourcePack; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; @@ -199,6 +200,11 @@ default void openBook(final @NotNull Book book) { for (final Audience audience : this.audiences()) audience.openBook(book); } + @Override + default void sendResourcePack(final @NotNull ResourcePack resourcePack) { + for (final Audience audience : this.audiences()) audience.sendResourcePack(resourcePack); + } + /** * An audience that forwards everything to a single other audience. * @@ -361,5 +367,10 @@ default void stopSound(final @NotNull SoundStop stop) { default void openBook(final @NotNull Book book) { this.audience().openBook(book); } + + @Override + default void sendResourcePack(final @NotNull ResourcePack resourcePack) { + this.audience().sendResourcePack(resourcePack); + } } } diff --git a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java b/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java new file mode 100644 index 000000000..23267df54 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java @@ -0,0 +1,99 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2023 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.resourcepack; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import net.kyori.examination.Examinable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a resource pack that can be sent to players. + * + * @see Audience#sendResourcePack(ResourcePack) + * @since 4.15.0 + */ +public interface ResourcePack extends Examinable { + /** + * Creates a resource pack. + * + * @param url the url + * @param hash the sha-1 hash + * @param required whether this resource pack is required or not + * @return the resource pack + * @since 4.15.0 + */ + static @NotNull ResourcePack resourcePack(final @NotNull String url, final @NotNull String hash, final boolean required) { + return resourcePack(url, hash, required, null); + } + + /** + * Creates a resource pack. + * + * @param url the url + * @param hash the sha-1 hash + * @param required whether this resource pack is required or not + * @param prompt the prompt + * @return the resource pack + * @since 4.15.0 + */ + static @NotNull ResourcePack resourcePack(final @NotNull String url, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { + return new ResourcePackImpl(url, hash, required, prompt); + } + + /** + * Gets the url. + * + * @return the url + * @since 4.15.0 + */ + @NotNull String url(); + + /** + * Gets the hash. + * + * @return the hash + * @since 4.15.0 + */ + @NotNull String hash(); + + /** + * Gets whether this resource pack is required + * or not. + * + * @return True if this resource pack is required, + * false otherwise + * @since 4.15.0 + */ + boolean required(); + + /** + * Gets the prompt. + * + * @return the prompt + * @since 4.15.0 + */ + @Nullable Component prompt(); +} diff --git a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java b/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java new file mode 100644 index 000000000..4c4c13b45 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java @@ -0,0 +1,98 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2023 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.resourcepack; + +import net.kyori.adventure.text.Component; +import net.kyori.examination.ExaminableProperty; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; +import java.util.stream.Stream; + +import static java.util.Objects.requireNonNull; + +final class ResourcePackImpl implements ResourcePack { + private final String url; + private final String hash; + private final boolean required; + private final Component prompt; + + ResourcePackImpl(final @NotNull String url, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { + this.url = requireNonNull(url, "url"); + this.hash = requireNonNull(hash, "hash"); + this.required = required; + this.prompt = prompt; + } + + @Override + public @NotNull String url() { + return this.url; + } + + @Override + public @NotNull String hash() { + return this.hash; + } + + @Override + public boolean required() { + return this.required; + } + + @Override + public @Nullable Component prompt() { + return this.prompt; + } + + @Override + public @NotNull Stream examinableProperties() { + return Stream.of( + ExaminableProperty.of("url", this.url), + ExaminableProperty.of("hash", this.hash), + ExaminableProperty.of("required", this.required), + ExaminableProperty.of("prompt", this.prompt) + ); + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (!(o instanceof ResourcePackImpl)) return false; + final ResourcePackImpl that = (ResourcePackImpl) o; + return this.required == that.required + && this.url.equals(that.url) + && this.hash.equals(that.hash) + && Objects.equals(this.prompt, that.prompt); + } + + @Override + public int hashCode() { + int result = this.url.hashCode(); + result = 31 * result + this.hash.hashCode(); + result = 31 * result + (this.required ? 1 : 0); + result = 31 * result + (this.prompt != null ? this.prompt.hashCode() : 0); + return result; + } +} diff --git a/api/src/main/java/net/kyori/adventure/resourcepack/package-info.java b/api/src/main/java/net/kyori/adventure/resourcepack/package-info.java new file mode 100644 index 000000000..af74d6e74 --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/resourcepack/package-info.java @@ -0,0 +1,27 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 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. + */ +/** + * Data for controlling resource packs + */ +package net.kyori.adventure.resourcepack; From 85bf6c7607c359b1b8195c555052cd3c218ee04f Mon Sep 17 00:00:00 2001 From: yusshu Date: Sun, 8 Oct 2023 00:03:14 -0500 Subject: [PATCH 02/10] refactor: use URI instead of String to specify resource pack location --- .../adventure/resourcepack/ResourcePack.java | 20 ++++++++++--------- .../resourcepack/ResourcePackImpl.java | 17 ++++++++-------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java b/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java index 23267df54..2b12f0d51 100644 --- a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java +++ b/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java @@ -29,6 +29,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.net.URI; + /** * Represents a resource pack that can be sent to players. * @@ -39,37 +41,37 @@ public interface ResourcePack extends Examinable { /** * Creates a resource pack. * - * @param url the url + * @param uri the uri * @param hash the sha-1 hash * @param required whether this resource pack is required or not * @return the resource pack * @since 4.15.0 */ - static @NotNull ResourcePack resourcePack(final @NotNull String url, final @NotNull String hash, final boolean required) { - return resourcePack(url, hash, required, null); + static @NotNull ResourcePack resourcePack(final @NotNull URI uri, final @NotNull String hash, final boolean required) { + return resourcePack(uri, hash, required, null); } /** * Creates a resource pack. * - * @param url the url + * @param uri the uri * @param hash the sha-1 hash * @param required whether this resource pack is required or not * @param prompt the prompt * @return the resource pack * @since 4.15.0 */ - static @NotNull ResourcePack resourcePack(final @NotNull String url, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { - return new ResourcePackImpl(url, hash, required, prompt); + static @NotNull ResourcePack resourcePack(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { + return new ResourcePackImpl(uri, hash, required, prompt); } /** - * Gets the url. + * Gets the uri. * - * @return the url + * @return the uri * @since 4.15.0 */ - @NotNull String url(); + @NotNull URI uri(); /** * Gets the hash. diff --git a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java b/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java index 4c4c13b45..e25cf4d66 100644 --- a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java +++ b/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java @@ -28,27 +28,28 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.net.URI; import java.util.Objects; import java.util.stream.Stream; import static java.util.Objects.requireNonNull; final class ResourcePackImpl implements ResourcePack { - private final String url; + private final URI uri; private final String hash; private final boolean required; private final Component prompt; - ResourcePackImpl(final @NotNull String url, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { - this.url = requireNonNull(url, "url"); + ResourcePackImpl(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { + this.uri = requireNonNull(uri, "uri"); this.hash = requireNonNull(hash, "hash"); this.required = required; this.prompt = prompt; } @Override - public @NotNull String url() { - return this.url; + public @NotNull URI uri() { + return this.uri; } @Override @@ -69,7 +70,7 @@ public boolean required() { @Override public @NotNull Stream examinableProperties() { return Stream.of( - ExaminableProperty.of("url", this.url), + ExaminableProperty.of("uri", this.uri), ExaminableProperty.of("hash", this.hash), ExaminableProperty.of("required", this.required), ExaminableProperty.of("prompt", this.prompt) @@ -82,14 +83,14 @@ public boolean equals(final Object o) { if (!(o instanceof ResourcePackImpl)) return false; final ResourcePackImpl that = (ResourcePackImpl) o; return this.required == that.required - && this.url.equals(that.url) + && this.uri.equals(that.uri) && this.hash.equals(that.hash) && Objects.equals(this.prompt, that.prompt); } @Override public int hashCode() { - int result = this.url.hashCode(); + int result = this.uri.hashCode(); result = 31 * result + this.hash.hashCode(); result = 31 * result + (this.required ? 1 : 0); result = 31 * result + (this.prompt != null ? this.prompt.hashCode() : 0); From 04c6727eaf7669497599bb5337d55303c8e749b5 Mon Sep 17 00:00:00 2001 From: yusshu Date: Sun, 8 Oct 2023 00:07:57 -0500 Subject: [PATCH 03/10] refactor: rename 'resourcepack' package to 'resource', implement ResourcePack#toString --- .../net/kyori/adventure/audience/Audience.java | 2 +- .../adventure/audience/ForwardingAudience.java | 2 +- .../{resourcepack => resource}/ResourcePack.java | 2 +- .../ResourcePackImpl.java | 16 +++++++++++----- .../{resourcepack => resource}/package-info.java | 4 ++-- 5 files changed, 16 insertions(+), 10 deletions(-) rename api/src/main/java/net/kyori/adventure/{resourcepack => resource}/ResourcePack.java (95%) rename api/src/main/java/net/kyori/adventure/{resourcepack => resource}/ResourcePackImpl.java (86%) rename api/src/main/java/net/kyori/adventure/{resourcepack => resource}/package-info.java (91%) 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 f3647bde0..d11c750d1 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -36,7 +36,7 @@ import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointered; -import net.kyori.adventure.resourcepack.ResourcePack; +import net.kyori.adventure.resource.ResourcePack; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; 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 5fcacfa66..5299fb728 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -38,7 +38,7 @@ import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.pointer.Pointers; -import net.kyori.adventure.resourcepack.ResourcePack; +import net.kyori.adventure.resource.ResourcePack; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; diff --git a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java similarity index 95% rename from api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java rename to api/src/main/java/net/kyori/adventure/resource/ResourcePack.java index 2b12f0d51..5c8678284 100644 --- a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePack.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.adventure.resourcepack; +package net.kyori.adventure.resource; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; diff --git a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java similarity index 86% rename from api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java rename to api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java index e25cf4d66..e364f3485 100644 --- a/api/src/main/java/net/kyori/adventure/resourcepack/ResourcePackImpl.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java @@ -21,8 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.adventure.resourcepack; +package net.kyori.adventure.resource; +import net.kyori.adventure.internal.Internals; import net.kyori.adventure.text.Component; import net.kyori.examination.ExaminableProperty; import org.jetbrains.annotations.NotNull; @@ -78,10 +79,15 @@ public boolean required() { } @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (!(o instanceof ResourcePackImpl)) return false; - final ResourcePackImpl that = (ResourcePackImpl) o; + public String toString() { + return Internals.toString(this); + } + + @Override + public boolean equals(final @Nullable Object other) { + if (this == other) return true; + if (!(other instanceof ResourcePackImpl)) return false; + final ResourcePackImpl that = (ResourcePackImpl) other; return this.required == that.required && this.uri.equals(that.uri) && this.hash.equals(that.hash) diff --git a/api/src/main/java/net/kyori/adventure/resourcepack/package-info.java b/api/src/main/java/net/kyori/adventure/resource/package-info.java similarity index 91% rename from api/src/main/java/net/kyori/adventure/resourcepack/package-info.java rename to api/src/main/java/net/kyori/adventure/resource/package-info.java index af74d6e74..7e01fcac8 100644 --- a/api/src/main/java/net/kyori/adventure/resourcepack/package-info.java +++ b/api/src/main/java/net/kyori/adventure/resource/package-info.java @@ -22,6 +22,6 @@ * SOFTWARE. */ /** - * Data for controlling resource packs + * Data for controlling resource packs. */ -package net.kyori.adventure.resourcepack; +package net.kyori.adventure.resource; From 3b539d79585574483a0cc01e7633c02f84061d32 Mon Sep 17 00:00:00 2001 From: yusshu Date: Sun, 8 Oct 2023 00:24:57 -0500 Subject: [PATCH 04/10] feat: add ResourcePack.Builder api --- .../adventure/resource/ResourcePack.java | 86 ++++++++++++++++++- .../adventure/resource/ResourcePackImpl.java | 39 +++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java index 5c8678284..7ced8fed9 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java @@ -24,8 +24,11 @@ package net.kyori.adventure.resource; import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.builder.AbstractBuilder; import net.kyori.adventure.text.Component; +import net.kyori.adventure.util.Buildable; import net.kyori.examination.Examinable; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,7 +40,7 @@ * @see Audience#sendResourcePack(ResourcePack) * @since 4.15.0 */ -public interface ResourcePack extends Examinable { +public interface ResourcePack extends Buildable, Examinable { /** * Creates a resource pack. * @@ -65,6 +68,16 @@ public interface ResourcePack extends Examinable { return new ResourcePackImpl(uri, hash, required, prompt); } + /** + * Create a new builder that will create a {@link ResourcePack}. + * + * @return a builder + * @since 4.15.0 + */ + static @NotNull Builder builder() { + return new ResourcePackImpl.BuilderImpl(); + } + /** * Gets the uri. * @@ -98,4 +111,75 @@ public interface ResourcePack extends Examinable { * @since 4.15.0 */ @Nullable Component prompt(); + + /** + * Create a new builder initialized with the attributes of this resource pack. + * + * @return the builder + * @since 4.15.0 + */ + @Override + default @NotNull Builder toBuilder() { + return builder() + .uri(this.uri()) + .hash(this.hash()) + .required(this.required()) + .prompt(this.prompt()); + } + + /** + * A builder for resource packs. + * + * @since 4.15.0 + */ + interface Builder extends AbstractBuilder, Buildable.Builder { + /** + * Sets the uri. + * + * @param uri the uri + * @return this builder + * @since 4.15.0 + */ + @Contract("_ -> this") + @NotNull Builder uri(final @NotNull URI uri); + + /** + * Sets the hash. + * + * @param hash the hash + * @return this builder + * @since 4.15.0 + */ + @Contract("_ -> this") + @NotNull Builder hash(final @NotNull String hash); + + /** + * Sets whether this resource pack is required or not. + * + * @param required whether this resource pack is required or not + * @return this builder + * @since 4.15.0 + */ + @Contract("_ -> this") + @NotNull Builder required(final boolean required); + + /** + * Sets the prompt. + * + * @param prompt the prompt + * @return this builder + * @since 4.15.0 + */ + @Contract("_ -> this") + @NotNull Builder prompt(final @Nullable Component prompt); + + /** + * Builds. + * + * @return a new resource pack + * @since 4.15.0 + */ + @Override + @NotNull ResourcePack build(); + } } diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java index e364f3485..add01a888 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java @@ -102,4 +102,43 @@ public int hashCode() { result = 31 * result + (this.prompt != null ? this.prompt.hashCode() : 0); return result; } + + static final class BuilderImpl implements Builder { + private URI uri; + private String hash; + private boolean required; + private Component prompt; + + BuilderImpl() { + } + + @Override + public @NotNull Builder uri(final @NotNull URI uri) { + this.uri = requireNonNull(uri, "uri"); + return this; + } + + @Override + public @NotNull Builder hash(final @NotNull String hash) { + this.hash = requireNonNull(hash, "hash"); + return this; + } + + @Override + public @NotNull Builder required(final boolean required) { + this.required = required; + return this; + } + + @Override + public @NotNull Builder prompt(final @Nullable Component prompt) { + this.prompt = prompt; + return this; + } + + @Override + public @NotNull ResourcePack build() { + return new ResourcePackImpl(this.uri, this.hash, this.required, this.prompt); + } + } } From ac8d809b1939f3649f3eb48abfa423ecb6b08910 Mon Sep 17 00:00:00 2001 From: yusshu Date: Sun, 8 Oct 2023 00:27:12 -0500 Subject: [PATCH 05/10] feat: add Audience#sendResourcePack overload that accepts ResourcePack.Builder --- .../java/net/kyori/adventure/audience/Audience.java | 12 ++++++++++++ .../net/kyori/adventure/audience/EmptyAudience.java | 5 +++++ 2 files changed, 17 insertions(+) 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 d11c750d1..1707e34a6 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -702,6 +702,18 @@ default void openBook(final Book.@NotNull Builder book) { default void openBook(final @NotNull Book book) { } + /** + * Sends a resource pack to this audience. + * + * @param resourcePack the resource pack + * @see ResourcePack + * @since 4.15.0 + */ + @ForwardingAudienceOverrideNotRequired + default void sendResourcePack(final ResourcePack.@NotNull Builder resourcePack) { + this.sendResourcePack(resourcePack.build()); + } + /** * Sends a resource pack to this audience. * 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 0c95a1c9f..a888cfc49 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -33,6 +33,7 @@ import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointer; +import net.kyori.adventure.resource.ResourcePack; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; import org.jetbrains.annotations.Contract; @@ -118,6 +119,10 @@ public void sendPlayerListHeaderAndFooter(final @NotNull ComponentLike header, f public void openBook(final Book.@NotNull Builder book) { } + @Override + public void sendResourcePack(final ResourcePack.@NotNull Builder resourcePack) { + } + @Override public boolean equals(final Object that) { return this == that; From ac470bc7ea479348fa647a4576536eb967dc823f Mon Sep 17 00:00:00 2001 From: yusshu Date: Sun, 8 Oct 2023 14:54:38 -0500 Subject: [PATCH 06/10] refactor: remove Buildable usages from ResourcePack --- .../java/net/kyori/adventure/resource/ResourcePack.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java index 7ced8fed9..b7a53d2cb 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java @@ -26,7 +26,6 @@ import net.kyori.adventure.audience.Audience; import net.kyori.adventure.builder.AbstractBuilder; import net.kyori.adventure.text.Component; -import net.kyori.adventure.util.Buildable; import net.kyori.examination.Examinable; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -40,7 +39,7 @@ * @see Audience#sendResourcePack(ResourcePack) * @since 4.15.0 */ -public interface ResourcePack extends Buildable, Examinable { +public interface ResourcePack extends Examinable { /** * Creates a resource pack. * @@ -118,7 +117,6 @@ public interface ResourcePack extends Buildable, Buildable.Builder { + interface Builder extends AbstractBuilder { /** * Sets the uri. * From e266644210ffc403c7cd0d16123c619e49416a1e Mon Sep 17 00:00:00 2001 From: yusshu Date: Sun, 8 Oct 2023 15:23:05 -0500 Subject: [PATCH 07/10] refactor: rename ResourcePack to ResourcePackRequest --- .../kyori/adventure/audience/Audience.java | 20 +++---- .../adventure/audience/EmptyAudience.java | 4 +- .../audience/ForwardingAudience.java | 10 ++-- ...urcePack.java => ResourcePackRequest.java} | 52 +++++++++---------- ...Impl.java => ResourcePackRequestImpl.java} | 12 ++--- 5 files changed, 49 insertions(+), 49 deletions(-) rename api/src/main/java/net/kyori/adventure/resource/{ResourcePack.java => ResourcePackRequest.java} (67%) rename api/src/main/java/net/kyori/adventure/resource/{ResourcePackImpl.java => ResourcePackRequestImpl.java} (86%) 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 1707e34a6..73ef1d910 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -36,7 +36,7 @@ import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointered; -import net.kyori.adventure.resource.ResourcePack; +import net.kyori.adventure.resource.ResourcePackRequest; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; @@ -703,24 +703,24 @@ default void openBook(final @NotNull Book book) { } /** - * Sends a resource pack to this audience. + * Sends a resource pack request to this audience. * - * @param resourcePack the resource pack - * @see ResourcePack + * @param resourcePackRequest the resource pack request + * @see ResourcePackRequest * @since 4.15.0 */ @ForwardingAudienceOverrideNotRequired - default void sendResourcePack(final ResourcePack.@NotNull Builder resourcePack) { - this.sendResourcePack(resourcePack.build()); + default void sendResourcePackRequest(final ResourcePackRequest.@NotNull Builder resourcePackRequest) { + this.sendResourcePackRequest(resourcePackRequest.build()); } /** - * Sends a resource pack to this audience. + * Sends a resource pack request to this audience. * - * @param resourcePack the resource pack - * @see ResourcePack + * @param resourcePackRequest the resource pack request + * @see ResourcePackRequest * @since 4.15.0 */ - default void sendResourcePack(final @NotNull ResourcePack resourcePack) { + default void sendResourcePackRequest(final @NotNull ResourcePackRequest resourcePackRequest) { } } 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 a888cfc49..1280d6857 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -33,7 +33,7 @@ import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointer; -import net.kyori.adventure.resource.ResourcePack; +import net.kyori.adventure.resource.ResourcePackRequest; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; import org.jetbrains.annotations.Contract; @@ -120,7 +120,7 @@ public void openBook(final Book.@NotNull Builder book) { } @Override - public void sendResourcePack(final ResourcePack.@NotNull Builder resourcePack) { + public void sendResourcePackRequest(final ResourcePackRequest.@NotNull Builder resourcePackRequest) { } @Override 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 5299fb728..98f291a1b 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -38,7 +38,7 @@ import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.pointer.Pointers; -import net.kyori.adventure.resource.ResourcePack; +import net.kyori.adventure.resource.ResourcePackRequest; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; @@ -201,8 +201,8 @@ default void openBook(final @NotNull Book book) { } @Override - default void sendResourcePack(final @NotNull ResourcePack resourcePack) { - for (final Audience audience : this.audiences()) audience.sendResourcePack(resourcePack); + default void sendResourcePackRequest(final @NotNull ResourcePackRequest resourcePackRequest) { + for (final Audience audience : this.audiences()) audience.sendResourcePackRequest(resourcePackRequest); } /** @@ -369,8 +369,8 @@ default void openBook(final @NotNull Book book) { } @Override - default void sendResourcePack(final @NotNull ResourcePack resourcePack) { - this.audience().sendResourcePack(resourcePack); + default void sendResourcePackRequest(final @NotNull ResourcePackRequest resourcePackRequest) { + this.audience().sendResourcePackRequest(resourcePackRequest); } } } diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java similarity index 67% rename from api/src/main/java/net/kyori/adventure/resource/ResourcePack.java rename to api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java index b7a53d2cb..995b8addf 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePack.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java @@ -34,47 +34,47 @@ import java.net.URI; /** - * Represents a resource pack that can be sent to players. + * Represents a resource pack request that can be sent to players. * - * @see Audience#sendResourcePack(ResourcePack) + * @see Audience#sendResourcePackRequest(ResourcePackRequest) * @since 4.15.0 */ -public interface ResourcePack extends Examinable { +public interface ResourcePackRequest extends Examinable { /** - * Creates a resource pack. + * Creates a resource pack request. * * @param uri the uri * @param hash the sha-1 hash - * @param required whether this resource pack is required or not - * @return the resource pack + * @param required whether the resource pack is required or not + * @return the resource pack request * @since 4.15.0 */ - static @NotNull ResourcePack resourcePack(final @NotNull URI uri, final @NotNull String hash, final boolean required) { - return resourcePack(uri, hash, required, null); + static @NotNull ResourcePackRequest resourcePackRequest(final @NotNull URI uri, final @NotNull String hash, final boolean required) { + return resourcePackRequest(uri, hash, required, null); } /** - * Creates a resource pack. + * Creates a resource pack request. * * @param uri the uri * @param hash the sha-1 hash - * @param required whether this resource pack is required or not + * @param required whether the resource pack is required or not * @param prompt the prompt - * @return the resource pack + * @return the resource pack request * @since 4.15.0 */ - static @NotNull ResourcePack resourcePack(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { - return new ResourcePackImpl(uri, hash, required, prompt); + static @NotNull ResourcePackRequest resourcePackRequest(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { + return new ResourcePackRequestImpl(uri, hash, required, prompt); } /** - * Create a new builder that will create a {@link ResourcePack}. + * Create a new builder that will create a {@link ResourcePackRequest}. * * @return a builder * @since 4.15.0 */ - static @NotNull Builder builder() { - return new ResourcePackImpl.BuilderImpl(); + static @NotNull Builder resourcePackRequest() { + return new ResourcePackRequestImpl.BuilderImpl(); } /** @@ -94,10 +94,10 @@ public interface ResourcePack extends Examinable { @NotNull String hash(); /** - * Gets whether this resource pack is required + * Gets whether the resource pack is required * or not. * - * @return True if this resource pack is required, + * @return True if the resource pack is required, * false otherwise * @since 4.15.0 */ @@ -112,13 +112,13 @@ public interface ResourcePack extends Examinable { @Nullable Component prompt(); /** - * Create a new builder initialized with the attributes of this resource pack. + * Create a new builder initialized with the attributes of this resource pack request. * * @return the builder * @since 4.15.0 */ default @NotNull Builder toBuilder() { - return builder() + return resourcePackRequest() .uri(this.uri()) .hash(this.hash()) .required(this.required()) @@ -126,11 +126,11 @@ public interface ResourcePack extends Examinable { } /** - * A builder for resource packs. + * A builder for resource pack requests. * * @since 4.15.0 */ - interface Builder extends AbstractBuilder { + interface Builder extends AbstractBuilder { /** * Sets the uri. * @@ -152,9 +152,9 @@ interface Builder extends AbstractBuilder { @NotNull Builder hash(final @NotNull String hash); /** - * Sets whether this resource pack is required or not. + * Sets whether the resource pack is required or not. * - * @param required whether this resource pack is required or not + * @param required whether the resource pack is required or not * @return this builder * @since 4.15.0 */ @@ -174,10 +174,10 @@ interface Builder extends AbstractBuilder { /** * Builds. * - * @return a new resource pack + * @return a new resource pack request * @since 4.15.0 */ @Override - @NotNull ResourcePack build(); + @NotNull ResourcePackRequest build(); } } diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestImpl.java similarity index 86% rename from api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java rename to api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestImpl.java index add01a888..f5e4d9eee 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePackImpl.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestImpl.java @@ -35,13 +35,13 @@ import static java.util.Objects.requireNonNull; -final class ResourcePackImpl implements ResourcePack { +final class ResourcePackRequestImpl implements ResourcePackRequest { private final URI uri; private final String hash; private final boolean required; private final Component prompt; - ResourcePackImpl(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { + ResourcePackRequestImpl(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { this.uri = requireNonNull(uri, "uri"); this.hash = requireNonNull(hash, "hash"); this.required = required; @@ -86,8 +86,8 @@ public String toString() { @Override public boolean equals(final @Nullable Object other) { if (this == other) return true; - if (!(other instanceof ResourcePackImpl)) return false; - final ResourcePackImpl that = (ResourcePackImpl) other; + if (!(other instanceof ResourcePackRequestImpl)) return false; + final ResourcePackRequestImpl that = (ResourcePackRequestImpl) other; return this.required == that.required && this.uri.equals(that.uri) && this.hash.equals(that.hash) @@ -137,8 +137,8 @@ static final class BuilderImpl implements Builder { } @Override - public @NotNull ResourcePack build() { - return new ResourcePackImpl(this.uri, this.hash, this.required, this.prompt); + public @NotNull ResourcePackRequest build() { + return new ResourcePackRequestImpl(this.uri, this.hash, this.required, this.prompt); } } } From 4d161c3056de61ef0669aa5823ca5de4f11f4a30 Mon Sep 17 00:00:00 2001 From: yusshu Date: Sun, 8 Oct 2023 18:03:09 -0500 Subject: [PATCH 08/10] refactor: rename Audience#sendResourcePackRequest to Audience#sendResourcePack --- .../main/java/net/kyori/adventure/audience/Audience.java | 6 +++--- .../java/net/kyori/adventure/audience/EmptyAudience.java | 2 +- .../net/kyori/adventure/audience/ForwardingAudience.java | 8 ++++---- .../net/kyori/adventure/resource/ResourcePackRequest.java | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) 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 73ef1d910..513791db4 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -710,8 +710,8 @@ default void openBook(final @NotNull Book book) { * @since 4.15.0 */ @ForwardingAudienceOverrideNotRequired - default void sendResourcePackRequest(final ResourcePackRequest.@NotNull Builder resourcePackRequest) { - this.sendResourcePackRequest(resourcePackRequest.build()); + default void sendResourcePack(final ResourcePackRequest.@NotNull Builder resourcePackRequest) { + this.sendResourcePack(resourcePackRequest.build()); } /** @@ -721,6 +721,6 @@ default void sendResourcePackRequest(final ResourcePackRequest.@NotNull Builder * @see ResourcePackRequest * @since 4.15.0 */ - default void sendResourcePackRequest(final @NotNull ResourcePackRequest resourcePackRequest) { + default void sendResourcePack(final @NotNull ResourcePackRequest resourcePackRequest) { } } 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 1280d6857..205edf370 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -120,7 +120,7 @@ public void openBook(final Book.@NotNull Builder book) { } @Override - public void sendResourcePackRequest(final ResourcePackRequest.@NotNull Builder resourcePackRequest) { + public void sendResourcePack(final ResourcePackRequest.@NotNull Builder resourcePackRequest) { } @Override 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 98f291a1b..4c1cfecc9 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -201,8 +201,8 @@ default void openBook(final @NotNull Book book) { } @Override - default void sendResourcePackRequest(final @NotNull ResourcePackRequest resourcePackRequest) { - for (final Audience audience : this.audiences()) audience.sendResourcePackRequest(resourcePackRequest); + default void sendResourcePack(final @NotNull ResourcePackRequest resourcePackRequest) { + for (final Audience audience : this.audiences()) audience.sendResourcePack(resourcePackRequest); } /** @@ -369,8 +369,8 @@ default void openBook(final @NotNull Book book) { } @Override - default void sendResourcePackRequest(final @NotNull ResourcePackRequest resourcePackRequest) { - this.audience().sendResourcePackRequest(resourcePackRequest); + default void sendResourcePack(final @NotNull ResourcePackRequest resourcePackRequest) { + this.audience().sendResourcePack(resourcePackRequest); } } } diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java index 995b8addf..a0915cbf5 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java @@ -36,7 +36,7 @@ /** * Represents a resource pack request that can be sent to players. * - * @see Audience#sendResourcePackRequest(ResourcePackRequest) + * @see Audience#sendResourcePack(ResourcePackRequest) * @since 4.15.0 */ public interface ResourcePackRequest extends Examinable { From 2e6cdac6811d6b0b13ffb2542ee0a7b5f1b6f8b1 Mon Sep 17 00:00:00 2001 From: yusshu Date: Sun, 8 Oct 2023 18:19:15 -0500 Subject: [PATCH 09/10] codestyle: fix styling issues --- .../resource/ResourcePackRequest.java | 365 +++++++++--------- .../resource/ResourcePackRequestImpl.java | 287 +++++++------- .../adventure/resource/package-info.java | 54 +-- 3 files changed, 352 insertions(+), 354 deletions(-) diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java index a0915cbf5..35c1c393e 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java @@ -1,183 +1,182 @@ -/* - * This file is part of adventure, licensed under the MIT License. - * - * Copyright (c) 2017-2023 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.resource; - -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.builder.AbstractBuilder; -import net.kyori.adventure.text.Component; -import net.kyori.examination.Examinable; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.net.URI; - -/** - * Represents a resource pack request that can be sent to players. - * - * @see Audience#sendResourcePack(ResourcePackRequest) - * @since 4.15.0 - */ -public interface ResourcePackRequest extends Examinable { - /** - * Creates a resource pack request. - * - * @param uri the uri - * @param hash the sha-1 hash - * @param required whether the resource pack is required or not - * @return the resource pack request - * @since 4.15.0 - */ - static @NotNull ResourcePackRequest resourcePackRequest(final @NotNull URI uri, final @NotNull String hash, final boolean required) { - return resourcePackRequest(uri, hash, required, null); - } - - /** - * Creates a resource pack request. - * - * @param uri the uri - * @param hash the sha-1 hash - * @param required whether the resource pack is required or not - * @param prompt the prompt - * @return the resource pack request - * @since 4.15.0 - */ - static @NotNull ResourcePackRequest resourcePackRequest(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { - return new ResourcePackRequestImpl(uri, hash, required, prompt); - } - - /** - * Create a new builder that will create a {@link ResourcePackRequest}. - * - * @return a builder - * @since 4.15.0 - */ - static @NotNull Builder resourcePackRequest() { - return new ResourcePackRequestImpl.BuilderImpl(); - } - - /** - * Gets the uri. - * - * @return the uri - * @since 4.15.0 - */ - @NotNull URI uri(); - - /** - * Gets the hash. - * - * @return the hash - * @since 4.15.0 - */ - @NotNull String hash(); - - /** - * Gets whether the resource pack is required - * or not. - * - * @return True if the resource pack is required, - * false otherwise - * @since 4.15.0 - */ - boolean required(); - - /** - * Gets the prompt. - * - * @return the prompt - * @since 4.15.0 - */ - @Nullable Component prompt(); - - /** - * Create a new builder initialized with the attributes of this resource pack request. - * - * @return the builder - * @since 4.15.0 - */ - default @NotNull Builder toBuilder() { - return resourcePackRequest() - .uri(this.uri()) - .hash(this.hash()) - .required(this.required()) - .prompt(this.prompt()); - } - - /** - * A builder for resource pack requests. - * - * @since 4.15.0 - */ - interface Builder extends AbstractBuilder { - /** - * Sets the uri. - * - * @param uri the uri - * @return this builder - * @since 4.15.0 - */ - @Contract("_ -> this") - @NotNull Builder uri(final @NotNull URI uri); - - /** - * Sets the hash. - * - * @param hash the hash - * @return this builder - * @since 4.15.0 - */ - @Contract("_ -> this") - @NotNull Builder hash(final @NotNull String hash); - - /** - * Sets whether the resource pack is required or not. - * - * @param required whether the resource pack is required or not - * @return this builder - * @since 4.15.0 - */ - @Contract("_ -> this") - @NotNull Builder required(final boolean required); - - /** - * Sets the prompt. - * - * @param prompt the prompt - * @return this builder - * @since 4.15.0 - */ - @Contract("_ -> this") - @NotNull Builder prompt(final @Nullable Component prompt); - - /** - * Builds. - * - * @return a new resource pack request - * @since 4.15.0 - */ - @Override - @NotNull ResourcePackRequest build(); - } -} +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2023 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.resource; + +import java.net.URI; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.builder.AbstractBuilder; +import net.kyori.adventure.text.Component; +import net.kyori.examination.Examinable; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a resource pack request that can be sent to players. + * + * @see Audience#sendResourcePack(ResourcePackRequest) + * @since 4.15.0 + */ +public interface ResourcePackRequest extends Examinable { + /** + * Creates a resource pack request. + * + * @param uri the uri + * @param hash the sha-1 hash + * @param required whether the resource pack is required or not + * @return the resource pack request + * @since 4.15.0 + */ + static @NotNull ResourcePackRequest resourcePackRequest(final @NotNull URI uri, final @NotNull String hash, final boolean required) { + return resourcePackRequest(uri, hash, required, null); + } + + /** + * Creates a resource pack request. + * + * @param uri the uri + * @param hash the sha-1 hash + * @param required whether the resource pack is required or not + * @param prompt the prompt + * @return the resource pack request + * @since 4.15.0 + */ + static @NotNull ResourcePackRequest resourcePackRequest(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { + return new ResourcePackRequestImpl(uri, hash, required, prompt); + } + + /** + * Create a new builder that will create a {@link ResourcePackRequest}. + * + * @return a builder + * @since 4.15.0 + */ + static @NotNull Builder resourcePackRequest() { + return new ResourcePackRequestImpl.BuilderImpl(); + } + + /** + * Gets the uri. + * + * @return the uri + * @since 4.15.0 + */ + @NotNull URI uri(); + + /** + * Gets the hash. + * + * @return the hash + * @since 4.15.0 + */ + @NotNull String hash(); + + /** + * Gets whether the resource pack is required + * or not. + * + * @return True if the resource pack is required, + * false otherwise + * @since 4.15.0 + */ + boolean required(); + + /** + * Gets the prompt. + * + * @return the prompt + * @since 4.15.0 + */ + @Nullable Component prompt(); + + /** + * Create a new builder initialized with the attributes of this resource pack request. + * + * @return the builder + * @since 4.15.0 + */ + default @NotNull Builder toBuilder() { + return resourcePackRequest() + .uri(this.uri()) + .hash(this.hash()) + .required(this.required()) + .prompt(this.prompt()); + } + + /** + * A builder for resource pack requests. + * + * @since 4.15.0 + */ + interface Builder extends AbstractBuilder { + /** + * Sets the uri. + * + * @param uri the uri + * @return this builder + * @since 4.15.0 + */ + @Contract("_ -> this") + @NotNull Builder uri(final @NotNull URI uri); + + /** + * Sets the hash. + * + * @param hash the hash + * @return this builder + * @since 4.15.0 + */ + @Contract("_ -> this") + @NotNull Builder hash(final @NotNull String hash); + + /** + * Sets whether the resource pack is required or not. + * + * @param required whether the resource pack is required or not + * @return this builder + * @since 4.15.0 + */ + @Contract("_ -> this") + @NotNull Builder required(final boolean required); + + /** + * Sets the prompt. + * + * @param prompt the prompt + * @return this builder + * @since 4.15.0 + */ + @Contract("_ -> this") + @NotNull Builder prompt(final @Nullable Component prompt); + + /** + * Builds. + * + * @return a new resource pack request + * @since 4.15.0 + */ + @Override + @NotNull ResourcePackRequest build(); + } +} diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestImpl.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestImpl.java index f5e4d9eee..c3b186f7f 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestImpl.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestImpl.java @@ -1,144 +1,143 @@ -/* - * This file is part of adventure, licensed under the MIT License. - * - * Copyright (c) 2017-2023 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.resource; - -import net.kyori.adventure.internal.Internals; -import net.kyori.adventure.text.Component; -import net.kyori.examination.ExaminableProperty; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.net.URI; -import java.util.Objects; -import java.util.stream.Stream; - -import static java.util.Objects.requireNonNull; - -final class ResourcePackRequestImpl implements ResourcePackRequest { - private final URI uri; - private final String hash; - private final boolean required; - private final Component prompt; - - ResourcePackRequestImpl(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { - this.uri = requireNonNull(uri, "uri"); - this.hash = requireNonNull(hash, "hash"); - this.required = required; - this.prompt = prompt; - } - - @Override - public @NotNull URI uri() { - return this.uri; - } - - @Override - public @NotNull String hash() { - return this.hash; - } - - @Override - public boolean required() { - return this.required; - } - - @Override - public @Nullable Component prompt() { - return this.prompt; - } - - @Override - public @NotNull Stream examinableProperties() { - return Stream.of( - ExaminableProperty.of("uri", this.uri), - ExaminableProperty.of("hash", this.hash), - ExaminableProperty.of("required", this.required), - ExaminableProperty.of("prompt", this.prompt) - ); - } - - @Override - public String toString() { - return Internals.toString(this); - } - - @Override - public boolean equals(final @Nullable Object other) { - if (this == other) return true; - if (!(other instanceof ResourcePackRequestImpl)) return false; - final ResourcePackRequestImpl that = (ResourcePackRequestImpl) other; - return this.required == that.required - && this.uri.equals(that.uri) - && this.hash.equals(that.hash) - && Objects.equals(this.prompt, that.prompt); - } - - @Override - public int hashCode() { - int result = this.uri.hashCode(); - result = 31 * result + this.hash.hashCode(); - result = 31 * result + (this.required ? 1 : 0); - result = 31 * result + (this.prompt != null ? this.prompt.hashCode() : 0); - return result; - } - - static final class BuilderImpl implements Builder { - private URI uri; - private String hash; - private boolean required; - private Component prompt; - - BuilderImpl() { - } - - @Override - public @NotNull Builder uri(final @NotNull URI uri) { - this.uri = requireNonNull(uri, "uri"); - return this; - } - - @Override - public @NotNull Builder hash(final @NotNull String hash) { - this.hash = requireNonNull(hash, "hash"); - return this; - } - - @Override - public @NotNull Builder required(final boolean required) { - this.required = required; - return this; - } - - @Override - public @NotNull Builder prompt(final @Nullable Component prompt) { - this.prompt = prompt; - return this; - } - - @Override - public @NotNull ResourcePackRequest build() { - return new ResourcePackRequestImpl(this.uri, this.hash, this.required, this.prompt); - } - } -} +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2023 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.resource; + +import java.net.URI; +import java.util.Objects; +import java.util.stream.Stream; +import net.kyori.adventure.internal.Internals; +import net.kyori.adventure.text.Component; +import net.kyori.examination.ExaminableProperty; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static java.util.Objects.requireNonNull; + +final class ResourcePackRequestImpl implements ResourcePackRequest { + private final URI uri; + private final String hash; + private final boolean required; + private final Component prompt; + + ResourcePackRequestImpl(final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) { + this.uri = requireNonNull(uri, "uri"); + this.hash = requireNonNull(hash, "hash"); + this.required = required; + this.prompt = prompt; + } + + @Override + public @NotNull URI uri() { + return this.uri; + } + + @Override + public @NotNull String hash() { + return this.hash; + } + + @Override + public boolean required() { + return this.required; + } + + @Override + public @Nullable Component prompt() { + return this.prompt; + } + + @Override + public @NotNull Stream examinableProperties() { + return Stream.of( + ExaminableProperty.of("uri", this.uri), + ExaminableProperty.of("hash", this.hash), + ExaminableProperty.of("required", this.required), + ExaminableProperty.of("prompt", this.prompt) + ); + } + + @Override + public String toString() { + return Internals.toString(this); + } + + @Override + public boolean equals(final @Nullable Object other) { + if (this == other) return true; + if (!(other instanceof ResourcePackRequestImpl)) return false; + final ResourcePackRequestImpl that = (ResourcePackRequestImpl) other; + return this.required == that.required + && this.uri.equals(that.uri) + && this.hash.equals(that.hash) + && Objects.equals(this.prompt, that.prompt); + } + + @Override + public int hashCode() { + int result = this.uri.hashCode(); + result = 31 * result + this.hash.hashCode(); + result = 31 * result + (this.required ? 1 : 0); + result = 31 * result + (this.prompt != null ? this.prompt.hashCode() : 0); + return result; + } + + static final class BuilderImpl implements Builder { + private URI uri; + private String hash; + private boolean required; + private Component prompt; + + BuilderImpl() { + } + + @Override + public @NotNull Builder uri(final @NotNull URI uri) { + this.uri = requireNonNull(uri, "uri"); + return this; + } + + @Override + public @NotNull Builder hash(final @NotNull String hash) { + this.hash = requireNonNull(hash, "hash"); + return this; + } + + @Override + public @NotNull Builder required(final boolean required) { + this.required = required; + return this; + } + + @Override + public @NotNull Builder prompt(final @Nullable Component prompt) { + this.prompt = prompt; + return this; + } + + @Override + public @NotNull ResourcePackRequest build() { + return new ResourcePackRequestImpl(this.uri, this.hash, this.required, this.prompt); + } + } +} diff --git a/api/src/main/java/net/kyori/adventure/resource/package-info.java b/api/src/main/java/net/kyori/adventure/resource/package-info.java index 7e01fcac8..12d8d3083 100644 --- a/api/src/main/java/net/kyori/adventure/resource/package-info.java +++ b/api/src/main/java/net/kyori/adventure/resource/package-info.java @@ -1,27 +1,27 @@ -/* - * This file is part of adventure, licensed under the MIT License. - * - * Copyright (c) 2017-2022 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. - */ -/** - * Data for controlling resource packs. - */ -package net.kyori.adventure.resource; +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 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. + */ +/** + * Data for controlling resource packs. + */ +package net.kyori.adventure.resource; From 98b9f5fe343fde4c6a51f5d32c60dbab28d777ff Mon Sep 17 00:00:00 2001 From: Riley Park Date: Tue, 10 Oct 2023 01:37:46 -0700 Subject: [PATCH 10/10] feat(api): add ResourcePackRequestLike --- .../kyori/adventure/audience/Audience.java | 15 ++++--- .../adventure/audience/EmptyAudience.java | 4 +- .../audience/ForwardingAudience.java | 8 ++-- .../resource/ResourcePackRequest.java | 24 +++++------ .../resource/ResourcePackRequestLike.java | 41 +++++++++++++++++++ 5 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestLike.java 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 513791db4..3c54022b6 100644 --- a/api/src/main/java/net/kyori/adventure/audience/Audience.java +++ b/api/src/main/java/net/kyori/adventure/audience/Audience.java @@ -37,6 +37,7 @@ import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointered; import net.kyori.adventure.resource.ResourcePackRequest; +import net.kyori.adventure.resource.ResourcePackRequestLike; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; @@ -702,25 +703,29 @@ default void openBook(final Book.@NotNull Builder book) { default void openBook(final @NotNull Book book) { } + // ------------------------ + // ---- Resource Packs ---- + // ------------------------ + /** * Sends a resource pack request to this audience. * - * @param resourcePackRequest the resource pack request + * @param request the resource pack request * @see ResourcePackRequest * @since 4.15.0 */ @ForwardingAudienceOverrideNotRequired - default void sendResourcePack(final ResourcePackRequest.@NotNull Builder resourcePackRequest) { - this.sendResourcePack(resourcePackRequest.build()); + default void sendResourcePack(final @NotNull ResourcePackRequestLike request) { + this.sendResourcePack(request.asResourcePackRequest()); } /** * Sends a resource pack request to this audience. * - * @param resourcePackRequest the resource pack request + * @param request the resource pack request * @see ResourcePackRequest * @since 4.15.0 */ - default void sendResourcePack(final @NotNull ResourcePackRequest resourcePackRequest) { + default void sendResourcePack(final @NotNull ResourcePackRequest request) { } } 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 205edf370..6822ec5d4 100644 --- a/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/EmptyAudience.java @@ -33,7 +33,7 @@ import net.kyori.adventure.identity.Identity; import net.kyori.adventure.inventory.Book; import net.kyori.adventure.pointer.Pointer; -import net.kyori.adventure.resource.ResourcePackRequest; +import net.kyori.adventure.resource.ResourcePackRequestLike; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; import org.jetbrains.annotations.Contract; @@ -120,7 +120,7 @@ public void openBook(final Book.@NotNull Builder book) { } @Override - public void sendResourcePack(final ResourcePackRequest.@NotNull Builder resourcePackRequest) { + public void sendResourcePack(final @NotNull ResourcePackRequestLike request) { } @Override 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 4c1cfecc9..472b04d4f 100644 --- a/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java +++ b/api/src/main/java/net/kyori/adventure/audience/ForwardingAudience.java @@ -201,8 +201,8 @@ default void openBook(final @NotNull Book book) { } @Override - default void sendResourcePack(final @NotNull ResourcePackRequest resourcePackRequest) { - for (final Audience audience : this.audiences()) audience.sendResourcePack(resourcePackRequest); + default void sendResourcePack(final @NotNull ResourcePackRequest request) { + for (final Audience audience : this.audiences()) audience.sendResourcePack(request); } /** @@ -369,8 +369,8 @@ default void openBook(final @NotNull Book book) { } @Override - default void sendResourcePack(final @NotNull ResourcePackRequest resourcePackRequest) { - this.audience().sendResourcePack(resourcePackRequest); + default void sendResourcePack(final @NotNull ResourcePackRequest request) { + this.audience().sendResourcePack(request); } } } diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java index 35c1c393e..a77f657f3 100644 --- a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequest.java @@ -38,7 +38,7 @@ * @see Audience#sendResourcePack(ResourcePackRequest) * @since 4.15.0 */ -public interface ResourcePackRequest extends Examinable { +public interface ResourcePackRequest extends Examinable, ResourcePackRequestLike { /** * Creates a resource pack request. * @@ -110,18 +110,9 @@ public interface ResourcePackRequest extends Examinable { */ @Nullable Component prompt(); - /** - * Create a new builder initialized with the attributes of this resource pack request. - * - * @return the builder - * @since 4.15.0 - */ - default @NotNull Builder toBuilder() { - return resourcePackRequest() - .uri(this.uri()) - .hash(this.hash()) - .required(this.required()) - .prompt(this.prompt()); + @Override + default @NotNull ResourcePackRequest asResourcePackRequest() { + return this; } /** @@ -129,7 +120,7 @@ public interface ResourcePackRequest extends Examinable { * * @since 4.15.0 */ - interface Builder extends AbstractBuilder { + interface Builder extends AbstractBuilder, ResourcePackRequestLike { /** * Sets the uri. * @@ -178,5 +169,10 @@ interface Builder extends AbstractBuilder { */ @Override @NotNull ResourcePackRequest build(); + + @Override + default @NotNull ResourcePackRequest asResourcePackRequest() { + return this.build(); + } } } diff --git a/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestLike.java b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestLike.java new file mode 100644 index 000000000..d246c50de --- /dev/null +++ b/api/src/main/java/net/kyori/adventure/resource/ResourcePackRequestLike.java @@ -0,0 +1,41 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2023 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.resource; + +import org.jetbrains.annotations.NotNull; + +/** + * Something that can be represented as a {@link ResourcePackRequest}. + * + * @since 4.15.0 + */ +public interface ResourcePackRequestLike { + /** + * Gets a {@link ResourcePackRequest} representation. + * + * @return a component + * @since 4.15.0 + */ + @NotNull ResourcePackRequest asResourcePackRequest(); +}