3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 22:40:18 +01:00

Allow null content key

Dieser Commit ist enthalten in:
onebeastchris 2024-01-26 19:01:12 +01:00
Ursprung 4d99250b27
Commit 2e776c4561
5 geänderte Dateien mit 17 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -26,6 +26,7 @@
package org.geysermc.geyser.api.pack;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
import java.io.IOException;
@ -84,11 +85,11 @@ public abstract class PackCodec {
* Creates a new pack provider from the given url and content key.
*
* @param url the url to create the pack provider from
* @param contentKey the content key, leave empty if pack is not encrypted
* @param contentKey the content key, leave empty or null if pack is not encrypted
* @return the new pack provider
*/
@NonNull
public static PackCodec url(@NonNull String url, @NonNull String contentKey) {
public static PackCodec url(@NonNull String url, @Nullable String contentKey) {
return GeyserApi.api().provider(UrlPackCodec.class, url, contentKey);
}
}

Datei anzeigen

@ -34,10 +34,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
* Due to Bedrock limitations, the URL must:
* <ul>
* <li>be a direct download link to a .zip or .mcpack resource pack</li>
* <li>Use application type `application/zip` and set a correct content length</li>
* <li>use the application type `application/zip` and set a correct content length</li>
* </ul>
*
* 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.
* 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.
*/
public abstract class UrlPackCodec extends PackCodec {
@ -51,7 +51,8 @@ public abstract class UrlPackCodec extends PackCodec {
/**
* If the remote pack has an encryption key, it must be specified here.
* Otherwise, leave empty.
* This will return empty if none is specified.
*
* @return the encryption key of the resource pack
*/
@NonNull

Datei anzeigen

@ -27,6 +27,7 @@ package org.geysermc.geyser.pack.url;
import lombok.Getter;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.pack.ResourcePack;
import org.geysermc.geyser.api.pack.UrlPackCodec;
@ -47,9 +48,13 @@ public class GeyserUrlPackCodec extends UrlPackCodec {
this(url, "");
}
public GeyserUrlPackCodec(String url, String contentKey) throws IllegalArgumentException {
public GeyserUrlPackCodec(@NonNull String url, @Nullable String contentKey) throws IllegalArgumentException {
//noinspection ConstantValue - need to enforce
if (url == null) {
throw new IllegalArgumentException("Url cannot be nulL!");
}
this.url = url;
this.contentKey = contentKey;
this.contentKey = contentKey == null ? "" : contentKey;
}
@Override

Datei anzeigen

@ -155,7 +155,7 @@ public class WebUtils {
String cachedEtag = metadataLines.get(1);
long cachedLastModified = Long.parseLong(metadataLines.get(2));
if (cachedSize == size && cachedEtag.equals(con.getHeaderField("ETag")) && cachedLastModified == con.getLastModified()) {
if (cachedSize == size && cachedEtag.equals(con.getHeaderField("ETag")) && cachedLastModified == con.getLastModified() && !force) {
GeyserImpl.getInstance().getLogger().debug("Using cached pack for " + url);
return packLocation;
}
@ -168,7 +168,7 @@ public class WebUtils {
Files.copy(in, packLocation, StandardCopyOption.REPLACE_EXISTING);
if (Files.size(packLocation) != size) {
GeyserImpl.getInstance().getLogger().error("Downloaded pack has " + Files.size(packLocation) + " bytes, expected " + size + " bytes");
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));
Files.delete(packLocation);
return null;
}
@ -186,7 +186,6 @@ public class WebUtils {
GeyserImpl.getInstance().getLogger().error("Unable to reach URL: " + url + " (" + e.getMessage() + ")");
return null;
} catch (IOException e) {
e.printStackTrace(); // TODO yeeeeeeeet
throw new RuntimeException("Unable to download and save remote resource pack from: " + url + " (" + e.getMessage() + ")");
}
});

Datei anzeigen

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