Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 15:00:11 +01:00
Allow null content key
Dieser Commit ist enthalten in:
Ursprung
4d99250b27
Commit
2e776c4561
@ -26,6 +26,7 @@
|
|||||||
package org.geysermc.geyser.api.pack;
|
package org.geysermc.geyser.api.pack;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.geysermc.geyser.api.GeyserApi;
|
import org.geysermc.geyser.api.GeyserApi;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -84,11 +85,11 @@ public abstract class PackCodec {
|
|||||||
* Creates a new pack provider from the given url and content key.
|
* Creates a new pack provider from the given url and content key.
|
||||||
*
|
*
|
||||||
* @param url the url to create the pack provider from
|
* @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
|
* @return the new pack provider
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@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);
|
return GeyserApi.api().provider(UrlPackCodec.class, url, contentKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
* Due to Bedrock limitations, the URL must:
|
* Due to Bedrock limitations, the URL must:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>be a direct download link to a .zip or .mcpack resource pack</li>
|
* <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>
|
* </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 {
|
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.
|
* 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
|
* @return the encryption key of the resource pack
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -27,6 +27,7 @@ package org.geysermc.geyser.pack.url;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.api.pack.ResourcePack;
|
import org.geysermc.geyser.api.pack.ResourcePack;
|
||||||
import org.geysermc.geyser.api.pack.UrlPackCodec;
|
import org.geysermc.geyser.api.pack.UrlPackCodec;
|
||||||
@ -47,9 +48,13 @@ public class GeyserUrlPackCodec extends UrlPackCodec {
|
|||||||
this(url, "");
|
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.url = url;
|
||||||
this.contentKey = contentKey;
|
this.contentKey = contentKey == null ? "" : contentKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -155,7 +155,7 @@ public class WebUtils {
|
|||||||
String cachedEtag = metadataLines.get(1);
|
String cachedEtag = metadataLines.get(1);
|
||||||
long cachedLastModified = Long.parseLong(metadataLines.get(2));
|
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);
|
GeyserImpl.getInstance().getLogger().debug("Using cached pack for " + url);
|
||||||
return packLocation;
|
return packLocation;
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ public class WebUtils {
|
|||||||
Files.copy(in, packLocation, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(in, packLocation, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
if (Files.size(packLocation) != size) {
|
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);
|
Files.delete(packLocation);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -186,7 +186,6 @@ public class WebUtils {
|
|||||||
GeyserImpl.getInstance().getLogger().error("Unable to reach URL: " + url + " (" + e.getMessage() + ")");
|
GeyserImpl.getInstance().getLogger().error("Unable to reach URL: " + url + " (" + e.getMessage() + ")");
|
||||||
return null;
|
return null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace(); // TODO yeeeeeeeet
|
|
||||||
throw new RuntimeException("Unable to download and save remote resource pack from: " + url + " (" + e.getMessage() + ")");
|
throw new RuntimeException("Unable to download and save remote resource pack from: " + url + " (" + e.getMessage() + ")");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -178,6 +178,7 @@ force-resource-packs: true
|
|||||||
# A list of links to send to the client to download resource packs from.
|
# 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.
|
# 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.
|
# 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:
|
resource-pack-urls:
|
||||||
# Example: GeyserOptionalPack
|
# Example: GeyserOptionalPack
|
||||||
- "https://ci.opencollab.dev/job/GeyserMC/job/GeyserOptionalPack/job/master/lastSuccessfulBuild/artifact/GeyserOptionalPack.mcpack"
|
- "https://ci.opencollab.dev/job/GeyserMC/job/GeyserOptionalPack/job/master/lastSuccessfulBuild/artifact/GeyserOptionalPack.mcpack"
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren