Skip to content

Commit

Permalink
feat(api): add ResourcePackRequestLike
Browse files Browse the repository at this point in the history
  • Loading branch information
kashike committed Oct 10, 2023
1 parent 2e6cdac commit 98b9f5f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 25 deletions.
15 changes: 10 additions & 5 deletions api/src/main/java/net/kyori/adventure/audience/Audience.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -110,26 +110,17 @@ 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;
}

/**
* A builder for resource pack requests.
*
* @since 4.15.0
*/
interface Builder extends AbstractBuilder<ResourcePackRequest> {
interface Builder extends AbstractBuilder<ResourcePackRequest>, ResourcePackRequestLike {
/**
* Sets the uri.
*
Expand Down Expand Up @@ -178,5 +169,10 @@ interface Builder extends AbstractBuilder<ResourcePackRequest> {
*/
@Override
@NotNull ResourcePackRequest build();

@Override
default @NotNull ResourcePackRequest asResourcePackRequest() {
return this.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 98b9f5f

Please sign in to comment.