Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): Add removeResourcePack overload with Iterable #1036

Merged
merged 1 commit into from Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions api/src/main/java/net/kyori/adventure/audience/Audience.java
Expand Up @@ -23,7 +23,10 @@
*/
package net.kyori.adventure.audience;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -804,6 +807,38 @@ default void removeResourcePacks(final @NotNull ResourcePackInfoLike request, fi
this.removeResourcePacks(request.asResourcePackInfo().id(), otherReqs);
}

/**
* Clear resource packs with the provided ids if they are present.
*
* @param ids the ids of resource packs to remove
* @since 4.16.0
* @sinceMinecraft 1.20.3
*/
default void removeResourcePacks(final @NotNull Iterable<UUID> ids) {
// break these out to id + arrays
final Iterator<UUID> it = ids.iterator();
if (!it.hasNext()) return;

final UUID id = it.next();
final UUID[] others;
if (!it.hasNext()) {
others = new UUID[0];
} else if (ids instanceof Collection<?>) {
others = new UUID[((Collection<UUID>) ids).size() - 1];
for (int i = 0; i < others.length; i++) {
others[i] = it.next();
}
} else {
final List<UUID> othersList = new ArrayList<>();
while (it.hasNext()) {
othersList.add(it.next());
}
others = othersList.toArray(new UUID[0]);
}

this.removeResourcePacks(id, others);
}

/**
* Clear resource packs with the provided ids if they are present.
*
Expand Down
Expand Up @@ -206,6 +206,11 @@ default void sendResourcePacks(final @NotNull ResourcePackRequest request) {
for (final Audience audience : this.audiences()) audience.sendResourcePacks(request);
}

@Override
default void removeResourcePacks(final @NotNull Iterable<UUID> ids) {
for (final Audience audience : this.audiences()) audience.removeResourcePacks(ids);
}

@Override
default void removeResourcePacks(final @NotNull UUID id, final @NotNull UUID @NotNull ... others) {
for (final Audience audience : this.audiences()) audience.removeResourcePacks(id, others);
Expand Down Expand Up @@ -384,6 +389,11 @@ default void sendResourcePacks(final @NotNull ResourcePackRequest request) {
this.audience().sendResourcePacks(request.callback(Audiences.unwrapCallback(this, this.audience(), request.callback())));
}

@Override
default void removeResourcePacks(final @NotNull Iterable<UUID> ids) {
this.audience().removeResourcePacks(ids);
}

@Override
default void removeResourcePacks(final @NotNull UUID id, final @NotNull UUID @NotNull ... others) {
this.audience().removeResourcePacks(id, others);
Expand Down