From 59b29a075e0abe4e9aeca393975a1cfbead35ee9 Mon Sep 17 00:00:00 2001
From: FivePB
Date: Sat, 5 Jun 2021 16:07:24 +0200
Subject: [PATCH] Improve new Resource-pack API
---
.../java/com/velocitypowered/api/proxy/Player.java | 11 +++++++----
.../com/velocitypowered/api/proxy/ProxyServer.java | 10 ++++++----
.../api/proxy/player/ResourcePackInfo.java | 2 +-
.../proxy/connection/client/ConnectedPlayer.java | 3 +--
4 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java
index d22f0caf2..51d966044 100644
--- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java
+++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java
@@ -238,6 +238,8 @@ public interface Player extends CommandSource, Identified, InboundConnection,
* Queues and sends a new Resource-pack offer to the player.
* To monitor the status of the sent resource pack, subscribe to
* {@link PlayerResourcePackStatusEvent}.
+ * To create a {@link ResourcePackInfo} use the
+ * {@link ProxyServer#createResourcePackBuilder(String)} builder.
*
* @param packInfo the resource-pack in question
*/
@@ -247,16 +249,17 @@ public interface Player extends CommandSource, Identified, InboundConnection,
* Gets the {@link ResourcePackInfo} of the currently applied
* resource-pack or null if none.
*
- * @return the applied resource pack
+ * @return the applied resource pack or null if none.
*/
@Nullable
ResourcePackInfo getAppliedResourcePack();
/**
- * Gets the {@link ResourcePackInfo} of the currently accepted
- * and currently downloading resource-pack or null if none.
+ * Gets the {@link ResourcePackInfo} of the resource pack
+ * the user is currently downloading or is currently
+ * prompted to install or null if none.
*
- * @return the pending resource pack
+ * @return the pending resource pack or null if none
*/
@Nullable
ResourcePackInfo getPendingResourcePack();
diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java
index bd3430a13..6f2e518f6 100644
--- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java
+++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java
@@ -225,14 +225,16 @@ public interface ProxyServer extends Audience {
*
* Note: The resource-pack location should always:
* - Use HTTPS with a valid certificate.
- * - Be in a crawler-accessible location. Having it behind Cloudflare or Cloudfront
- * may cause issues in downloading.
- * - Be in location with appropriate bandwidth so the download does not time out or fail.
+ * - Be in a crawler-accessible location. Having it behind Cloudflare or other DoS/Bot/crawler
+ * protection may cause issues in downloading.
+ * - Be on a web-server with enough bandwidth and reliable connection
+ * so the download does not time out or fail.
*
* Do also make sure that the resource pack is in the correct format for the version
* of the client. It is also highly recommended to always provide the resource-pack SHA-1 hash
* of the resource pack with {@link ResourcePackInfo.Builder#setHash(byte[])}
- * whenever possible to save bandwidth.
+ * whenever possible to save bandwidth. If a hash is present the client will first check
+ * if it already has a resource pack by that hash cached.
*
* @param url The url where the resource pack can be found
* @return a ResourcePackInfo builder
diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/ResourcePackInfo.java b/api/src/main/java/com/velocitypowered/api/proxy/player/ResourcePackInfo.java
index 067dd26ba..4643dd422 100644
--- a/api/src/main/java/com/velocitypowered/api/proxy/player/ResourcePackInfo.java
+++ b/api/src/main/java/com/velocitypowered/api/proxy/player/ResourcePackInfo.java
@@ -113,7 +113,7 @@ public interface ResourcePackInfo {
*/
DOWNSTREAM_SERVER,
/**
- * The player declined to download the resource pack.
+ * The resource-pack originated from a plugin on this proxy.
*/
PLUGIN_ON_PROXY
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java
index 459a7ea26..26ba80c24 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java
@@ -1000,9 +1000,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
}
if (!peek) {
- CompletableFuture.supplyAsync(() -> {
+ connection.eventLoop().execute(() -> {
tickResourcePackQueue();
- return true;
});
}