Skip to content

Commit

Permalink
feat(api): Introduce ResourcePackRequestLike
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Dec 10, 2023
1 parent dd280f9 commit 29abee2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
27 changes: 27 additions & 0 deletions api/src/main/java/net/kyori/adventure/audience/Audience.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.kyori.adventure.resource.ResourcePackInfo;
import net.kyori.adventure.resource.ResourcePackInfoLike;
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 @@ -725,6 +726,20 @@ default void sendResourcePacks(final @NotNull ResourcePackInfoLike first, final
this.sendResourcePacks(ResourcePackRequest.addingRequest(first, others));
}

/**
* Sends a request to apply resource packs to this audience.
*
* <p>Multiple resource packs are only supported since 1.20.3. On older versions, all requests behave as if {@link ResourcePackRequest#replace()} is set to {@code true}.</p>
*
* @param request the resource pack request
* @see ResourcePackInfo
* @since 4.15.0
*/
@ForwardingAudienceOverrideNotRequired
default void sendResourcePacks(final @NotNull ResourcePackRequestLike request) {
this.sendResourcePacks(request.asResourcePackRequest());
}

/**
* Sends a request to apply resource packs to this audience.
*
Expand All @@ -737,6 +752,18 @@ default void sendResourcePacks(final @NotNull ResourcePackInfoLike first, final
default void sendResourcePacks(final @NotNull ResourcePackRequest request) {
}

/**
* Clear resource packs with the IDs used in the provided requests if they are present.
*
* @param request the request used to originally apply the packs
* @since 4.15.0
* @sinceMinecraft 1.20.3
*/
@ForwardingAudienceOverrideNotRequired
default void removeResourcePacks(final @NotNull ResourcePackRequestLike request) {
this.removeResourcePacks(request.asResourcePackRequest());
}

/**
* Clear resource packs with the IDs used in the provided requests if they are present.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @since 4.15.0
*/
public interface ResourcePackRequest extends Examinable {
public interface ResourcePackRequest extends Examinable, ResourcePackRequestLike {
/**
* Create a basic request to apply the provided resource packs.
*
Expand Down Expand Up @@ -125,12 +125,17 @@ public interface ResourcePackRequest extends Examinable {
*/
@NotNull ResourcePackRequest replace(final boolean replace);

@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 {
/**
* Set the resource packs to apply.
*
Expand Down Expand Up @@ -167,5 +172,10 @@ interface Builder extends AbstractBuilder<ResourcePackRequest> {
* @since 4.15.0
*/
@NotNull Builder replace(final boolean replace);

@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 {
/**
* Get the pack request representation.
*
* @return the pack request representation of this object
* @since 4.15.0
*/
@NotNull ResourcePackRequest asResourcePackRequest();
}

0 comments on commit 29abee2

Please sign in to comment.