Skip to content

Commit

Permalink
feat: ResourcePackRequest now has a UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
kashike committed Nov 21, 2023
1 parent f9a739c commit 2b1b4cb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package net.kyori.adventure.resource;

import java.net.URI;
import java.util.UUID;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.builder.AbstractBuilder;
import net.kyori.adventure.text.Component;
Expand All @@ -42,28 +43,30 @@ public interface ResourcePackRequest extends Examinable, ResourcePackRequestLike
/**
* Creates a resource pack request.
*
* @param id the id
* @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);
static @NotNull ResourcePackRequest resourcePackRequest(final @NotNull UUID id, final @NotNull URI uri, final @NotNull String hash, final boolean required) {
return resourcePackRequest(id, uri, hash, required, null);
}

/**
* Creates a resource pack request.
*
* @param id the id
* @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);
static @NotNull ResourcePackRequest resourcePackRequest(final @NotNull UUID id, final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) {
return new ResourcePackRequestImpl(id, uri, hash, required, prompt);
}

/**
Expand All @@ -76,6 +79,14 @@ public interface ResourcePackRequest extends Examinable, ResourcePackRequestLike
return new ResourcePackRequestImpl.BuilderImpl();
}

/**
* Gets the id.
*
* @return the id
* @since 4.15.0
*/
@NotNull UUID id();

/**
* Gets the uri.
*
Expand Down Expand Up @@ -121,6 +132,16 @@ public interface ResourcePackRequest extends Examinable, ResourcePackRequestLike
* @since 4.15.0
*/
interface Builder extends AbstractBuilder<ResourcePackRequest>, ResourcePackRequestLike {
/**
* Sets the id.
*
* @param uri the id
* @return this builder
* @since 4.15.0
*/
@Contract("_ -> this")
@NotNull Builder id(final @NotNull UUID id);

/**
* Sets the uri.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.net.URI;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Stream;
import net.kyori.adventure.internal.Internals;
import net.kyori.adventure.text.Component;
Expand All @@ -35,18 +36,25 @@
import static java.util.Objects.requireNonNull;

final class ResourcePackRequestImpl implements ResourcePackRequest {
private final UUID id;
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) {
ResourcePackRequestImpl(final @NotNull UUID id, final @NotNull URI uri, final @NotNull String hash, final boolean required, final @Nullable Component prompt) {
this.id = requireNonNull(id, "id");
this.uri = requireNonNull(uri, "uri");
this.hash = requireNonNull(hash, "hash");
this.required = required;
this.prompt = prompt;
}

@Override
public @NotNull UUID id() {
return this.id;
}

@Override
public @NotNull URI uri() {
return this.uri;
Expand All @@ -70,6 +78,7 @@ public boolean required() {
@Override
public @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(
ExaminableProperty.of("id", this.id),
ExaminableProperty.of("uri", this.uri),
ExaminableProperty.of("hash", this.hash),
ExaminableProperty.of("required", this.required),
Expand All @@ -87,22 +96,25 @@ 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);
return this.id.equals(that.id) &&
this.uri.equals(that.uri) &&
this.hash.equals(that.hash) &&
this.required == that.required &&
Objects.equals(this.prompt, that.prompt);
}

@Override
public int hashCode() {
int result = this.uri.hashCode();
int result = this.id.hashCode();
result = 31 * 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 UUID id;
private URI uri;
private String hash;
private boolean required;
Expand All @@ -111,6 +123,12 @@ static final class BuilderImpl implements Builder {
BuilderImpl() {
}

@Override
public @NotNull Builder id(final @NotNull UUID id) {
this.id = requireNonNull(id, "id");
return this;
}

@Override
public @NotNull Builder uri(final @NotNull URI uri) {
this.uri = requireNonNull(uri, "uri");
Expand All @@ -137,7 +155,7 @@ static final class BuilderImpl implements Builder {

@Override
public @NotNull ResourcePackRequest build() {
return new ResourcePackRequestImpl(this.uri, this.hash, this.required, this.prompt);
return new ResourcePackRequestImpl(this.id, this.uri, this.hash, this.required, this.prompt);
}
}
}

0 comments on commit 2b1b4cb

Please sign in to comment.