mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Complete resource pack API
This commit is contained in:
parent
333cc0c4e1
commit
ecfabc25c7
2 changed files with 184 additions and 0 deletions
|
@ -2252,6 +2252,180 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
|
|||
void setResourcePack(@NotNull UUID uuid, @NotNull String url, byte @Nullable [] hash, net.kyori.adventure.text.@Nullable Component prompt, boolean force);
|
||||
// Paper end
|
||||
|
||||
// Paper start - more resource pack API
|
||||
/**
|
||||
* Request that the player's client download and switch resource packs.
|
||||
* <p>
|
||||
* The player's client will download the new resource pack asynchronously
|
||||
* in the background, and will automatically switch to it once the
|
||||
* download is complete. If the client has downloaded and cached the same
|
||||
* resource pack in the past, it will perform a quick timestamp check
|
||||
* over the network to determine if the resource pack has changed and
|
||||
* needs to be downloaded again. When this request is sent for the very
|
||||
* first time from a given server, the client will first display a
|
||||
* confirmation GUI to the player before proceeding with the download.
|
||||
* <p>
|
||||
* Notes:
|
||||
* <ul>
|
||||
* <li>Players can disable server resources on their client, in which
|
||||
* case this method will have no affect on them.
|
||||
* <li>To remove a resource pack you can use
|
||||
* {@link #removeResourcePacks(UUID, UUID...)} or {@link #clearResourcePacks()}.
|
||||
* </ul>
|
||||
*
|
||||
* @param url The URL from which the client will download the resource
|
||||
* pack. The string must contain only US-ASCII characters and should
|
||||
* be encoded as per RFC 1738.
|
||||
* @param hash A 40 character hexadecimal and lowercase SHA-1 digest of
|
||||
* the resource pack file.
|
||||
* @throws IllegalArgumentException Thrown if the URL is null.
|
||||
* @throws IllegalArgumentException Thrown if the URL is too long. The
|
||||
* length restriction is an implementation specific arbitrary value.
|
||||
*/
|
||||
default void setResourcePack(final @NotNull String url, final @NotNull String hash) {
|
||||
this.setResourcePack(url, hash, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player's client download and switch resource packs.
|
||||
* <p>
|
||||
* The player's client will download the new resource pack asynchronously
|
||||
* in the background, and will automatically switch to it once the
|
||||
* download is complete. If the client has downloaded and cached the same
|
||||
* resource pack in the past, it will perform a quick timestamp check
|
||||
* over the network to determine if the resource pack has changed and
|
||||
* needs to be downloaded again. When this request is sent for the very
|
||||
* first time from a given server, the client will first display a
|
||||
* confirmation GUI to the player before proceeding with the download.
|
||||
* <p>
|
||||
* Notes:
|
||||
* <ul>
|
||||
* <li>Players can disable server resources on their client, in which
|
||||
* case this method will have no affect on them.
|
||||
* <li>To remove a resource pack you can use
|
||||
* {@link #removeResourcePacks(UUID, UUID...)} or {@link #clearResourcePacks()}.
|
||||
* </ul>
|
||||
*
|
||||
* @param url The URL from which the client will download the resource
|
||||
* pack. The string must contain only US-ASCII characters and should
|
||||
* be encoded as per RFC 1738.
|
||||
* @param hash A 40 character hexadecimal and lowercase SHA-1 digest of
|
||||
* the resource pack file.
|
||||
* @param required Marks if the resource pack should be required by the client
|
||||
* @throws IllegalArgumentException Thrown if the URL is null.
|
||||
* @throws IllegalArgumentException Thrown if the URL is too long. The
|
||||
* length restriction is an implementation specific arbitrary value.
|
||||
*/
|
||||
default void setResourcePack(final @NotNull String url, final @NotNull String hash, final boolean required) {
|
||||
this.setResourcePack(url, hash, required, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player's client download and switch resource packs.
|
||||
* <p>
|
||||
* The player's client will download the new resource pack asynchronously
|
||||
* in the background, and will automatically switch to it once the
|
||||
* download is complete. If the client has downloaded and cached the same
|
||||
* resource pack in the past, it will perform a quick timestamp check
|
||||
* over the network to determine if the resource pack has changed and
|
||||
* needs to be downloaded again. When this request is sent for the very
|
||||
* first time from a given server, the client will first display a
|
||||
* confirmation GUI to the player before proceeding with the download.
|
||||
* <p>
|
||||
* Notes:
|
||||
* <ul>
|
||||
* <li>Players can disable server resources on their client, in which
|
||||
* case this method will have no affect on them.
|
||||
* <li>To remove a resource pack you can use
|
||||
* {@link #removeResourcePacks(UUID, UUID...)} or {@link #clearResourcePacks()}.
|
||||
* </ul>
|
||||
*
|
||||
* @param url The URL from which the client will download the resource
|
||||
* pack. The string must contain only US-ASCII characters and should
|
||||
* be encoded as per RFC 1738.
|
||||
* @param hash A 40 character hexadecimal and lowercase SHA-1 digest of
|
||||
* the resource pack file.
|
||||
* @param required Marks if the resource pack should be required by the client
|
||||
* @param resourcePackPrompt A Prompt to be displayed in the client request
|
||||
* @throws IllegalArgumentException Thrown if the URL is null.
|
||||
* @throws IllegalArgumentException Thrown if the URL is too long. The
|
||||
* length restriction is an implementation specific arbitrary value.
|
||||
*/
|
||||
default void setResourcePack(final @NotNull String url, final @NotNull String hash, final boolean required, final net.kyori.adventure.text.@Nullable Component resourcePackPrompt) {
|
||||
this.setResourcePack(UUID.nameUUIDFromBytes(url.getBytes(java.nio.charset.StandardCharsets.UTF_8)), url, hash, resourcePackPrompt, required);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that the player's client download and switch resource packs.
|
||||
* <p>
|
||||
* The player's client will download the new resource pack asynchronously
|
||||
* in the background, and will automatically switch to it once the
|
||||
* download is complete. If the client has downloaded and cached the same
|
||||
* resource pack in the past, it will perform a quick timestamp check
|
||||
* over the network to determine if the resource pack has changed and
|
||||
* needs to be downloaded again. When this request is sent for the very
|
||||
* first time from a given server, the client will first display a
|
||||
* confirmation GUI to the player before proceeding with the download.
|
||||
* <p>
|
||||
* Notes:
|
||||
* <ul>
|
||||
* <li>Players can disable server resources on their client, in which
|
||||
* case this method will have no affect on them.
|
||||
* <li>To remove a resource pack you can use
|
||||
* {@link #removeResourcePacks(UUID, UUID...)} or {@link #clearResourcePacks()}.
|
||||
* </ul>
|
||||
*
|
||||
* @param uuid Unique resource pack ID.
|
||||
* @param url The URL from which the client will download the resource
|
||||
* pack. The string must contain only US-ASCII characters and should
|
||||
* be encoded as per RFC 1738.
|
||||
* @param hash A 40 character hexadecimal and lowercase SHA-1 digest of
|
||||
* the resource pack file.
|
||||
* @param resourcePackPrompt A Prompt to be displayed in the client request
|
||||
* @param required Marks if the resource pack should be required by the client
|
||||
* @throws IllegalArgumentException Thrown if the URL is null.
|
||||
* @throws IllegalArgumentException Thrown if the URL is too long. The
|
||||
* length restriction is an implementation specific arbitrary value.
|
||||
*/
|
||||
default void setResourcePack(final @NotNull UUID uuid, final @NotNull String url, final @NotNull String hash, final net.kyori.adventure.text.@Nullable Component resourcePackPrompt, final boolean required) {
|
||||
this.sendResourcePacks(net.kyori.adventure.resource.ResourcePackRequest.resourcePackRequest()
|
||||
.required(required)
|
||||
.replace(true)
|
||||
.prompt(resourcePackPrompt)
|
||||
.packs(net.kyori.adventure.resource.ResourcePackInfo.resourcePackInfo(uuid, java.net.URI.create(url), hash))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the most recent resource pack status from the player.
|
||||
*
|
||||
* @return the most recent status or null
|
||||
*/
|
||||
org.bukkit.event.player.PlayerResourcePackStatusEvent.@Nullable Status getResourcePackStatus();
|
||||
|
||||
/**
|
||||
* Gets the most recent pack hash from the player.
|
||||
*
|
||||
* @return the most recent hash or null
|
||||
* @deprecated This is no longer sent from the client and will always be null
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.13.2")
|
||||
@org.jetbrains.annotations.Contract("-> null")
|
||||
default @Nullable String getResourcePackHash() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the last resource pack status from the player
|
||||
* was {@link org.bukkit.event.player.PlayerResourcePackStatusEvent.Status#SUCCESSFULLY_LOADED}.
|
||||
*
|
||||
* @return true if last status was successfully loaded
|
||||
*/
|
||||
default boolean hasResourcePack() {
|
||||
return this.getResourcePackStatus() == org.bukkit.event.player.PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED;
|
||||
}
|
||||
// Paper end - more resource pack API
|
||||
|
||||
/**
|
||||
* Request that the player's client download and include another resource pack.
|
||||
* <p>
|
||||
|
|
|
@ -21,6 +21,16 @@ public class PlayerResourcePackStatusEvent extends PlayerEvent {
|
|||
this.status = resourcePackStatus;
|
||||
}
|
||||
|
||||
// Paper start - add hash (not used anymore)
|
||||
/**
|
||||
* @deprecated Hash does not seem to ever be set
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public String getHash() {
|
||||
return null;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
* Gets the unique ID of this pack.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue