Skip to content

Commit 2e776c4

Browse files
committed
Allow null content key
1 parent 4d99250 commit 2e776c4

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

api/src/main/java/org/geysermc/geyser/api/pack/PackCodec.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package org.geysermc.geyser.api.pack;
2727

2828
import org.checkerframework.checker.nullness.qual.NonNull;
29+
import org.checkerframework.checker.nullness.qual.Nullable;
2930
import org.geysermc.geyser.api.GeyserApi;
3031

3132
import java.io.IOException;
@@ -84,11 +85,11 @@ public static PackCodec path(@NonNull Path path) {
8485
* Creates a new pack provider from the given url and content key.
8586
*
8687
* @param url the url to create the pack provider from
87-
* @param contentKey the content key, leave empty if pack is not encrypted
88+
* @param contentKey the content key, leave empty or null if pack is not encrypted
8889
* @return the new pack provider
8990
*/
9091
@NonNull
91-
public static PackCodec url(@NonNull String url, @NonNull String contentKey) {
92+
public static PackCodec url(@NonNull String url, @Nullable String contentKey) {
9293
return GeyserApi.api().provider(UrlPackCodec.class, url, contentKey);
9394
}
9495
}

api/src/main/java/org/geysermc/geyser/api/pack/UrlPackCodec.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
* Due to Bedrock limitations, the URL must:
3535
* <ul>
3636
* <li>be a direct download link to a .zip or .mcpack resource pack</li>
37-
* <li>Use application type `application/zip` and set a correct content length</li>
37+
* <li>use the application type `application/zip` and set a correct content length</li>
3838
* </ul>
3939
*
40-
* Additionally, the ResourcePack must be zipped in a folder enclosing the resource pack, instead of the resource pack being at the root of the zip.
40+
* Additionally, the resource pack must be zipped in a folder enclosing the resource pack, instead of the resource pack being at the root of the zip.
4141
*/
4242
public abstract class UrlPackCodec extends PackCodec {
4343

@@ -51,7 +51,8 @@ public abstract class UrlPackCodec extends PackCodec {
5151

5252
/**
5353
* If the remote pack has an encryption key, it must be specified here.
54-
* Otherwise, leave empty.
54+
* This will return empty if none is specified.
55+
*
5556
* @return the encryption key of the resource pack
5657
*/
5758
@NonNull

core/src/main/java/org/geysermc/geyser/pack/url/GeyserUrlPackCodec.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import lombok.Getter;
2929
import org.checkerframework.checker.nullness.qual.NonNull;
30+
import org.checkerframework.checker.nullness.qual.Nullable;
3031
import org.geysermc.geyser.GeyserImpl;
3132
import org.geysermc.geyser.api.pack.ResourcePack;
3233
import org.geysermc.geyser.api.pack.UrlPackCodec;
@@ -47,9 +48,13 @@ public GeyserUrlPackCodec(String url) throws IllegalArgumentException {
4748
this(url, "");
4849
}
4950

50-
public GeyserUrlPackCodec(String url, String contentKey) throws IllegalArgumentException {
51+
public GeyserUrlPackCodec(@NonNull String url, @Nullable String contentKey) throws IllegalArgumentException {
52+
//noinspection ConstantValue - need to enforce
53+
if (url == null) {
54+
throw new IllegalArgumentException("Url cannot be nulL!");
55+
}
5156
this.url = url;
52-
this.contentKey = contentKey;
57+
this.contentKey = contentKey == null ? "" : contentKey;
5358
}
5459

5560
@Override

core/src/main/java/org/geysermc/geyser/util/WebUtils.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static void downloadFile(String reqURL, String fileLocation) {
155155
String cachedEtag = metadataLines.get(1);
156156
long cachedLastModified = Long.parseLong(metadataLines.get(2));
157157

158-
if (cachedSize == size && cachedEtag.equals(con.getHeaderField("ETag")) && cachedLastModified == con.getLastModified()) {
158+
if (cachedSize == size && cachedEtag.equals(con.getHeaderField("ETag")) && cachedLastModified == con.getLastModified() && !force) {
159159
GeyserImpl.getInstance().getLogger().debug("Using cached pack for " + url);
160160
return packLocation;
161161
}
@@ -168,7 +168,7 @@ public static void downloadFile(String reqURL, String fileLocation) {
168168
Files.copy(in, packLocation, StandardCopyOption.REPLACE_EXISTING);
169169

170170
if (Files.size(packLocation) != size) {
171-
GeyserImpl.getInstance().getLogger().error("Downloaded pack has " + Files.size(packLocation) + " bytes, expected " + size + " bytes");
171+
GeyserImpl.getInstance().getLogger().error(String.format("Size mismatch with resource pack at url: %s. Downloaded pack has %s bytes, expected %s bytes!", url, Files.size(packLocation), size));
172172
Files.delete(packLocation);
173173
return null;
174174
}
@@ -186,7 +186,6 @@ public static void downloadFile(String reqURL, String fileLocation) {
186186
GeyserImpl.getInstance().getLogger().error("Unable to reach URL: " + url + " (" + e.getMessage() + ")");
187187
return null;
188188
} catch (IOException e) {
189-
e.printStackTrace(); // TODO yeeeeeeeet
190189
throw new RuntimeException("Unable to download and save remote resource pack from: " + url + " (" + e.getMessage() + ")");
191190
}
192191
});

core/src/main/resources/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ force-resource-packs: true
178178
# A list of links to send to the client to download resource packs from.
179179
# These must be direct links to the resource pack, not a link to a page containing the resource pack.
180180
# If you enter a link here, Geyser will download the resource pack once to check if it's in a valid format.
181+
# See https://wiki.geysermc.org/geyser/packs for more info.
181182
resource-pack-urls:
182183
# Example: GeyserOptionalPack
183184
- "https://ci.opencollab.dev/job/GeyserMC/job/GeyserOptionalPack/job/master/lastSuccessfulBuild/artifact/GeyserOptionalPack.mcpack"

0 commit comments

Comments
 (0)