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

Move loading cdn entries to separate function

Dieser Commit ist enthalten in:
onebeastchris 2023-10-11 21:09:14 +02:00
Ursprung fd69b0c381
Commit c0227d3da1

Datei anzeigen

@ -100,34 +100,8 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
resourcePacks.add(skullResourcePack);
}
final Path cachedCdnPacksDirectory = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("cache").resolve("cdn-packs");
// Download CDN packs to get the pack uuid's
if (!Files.exists(cachedCdnPacksDirectory)) {
try {
Files.createDirectories(cachedCdnPacksDirectory);
} catch (IOException e) {
GeyserImpl.getInstance().getLogger().error("Could not create cached packs directory", e);
}
}
List<String> cdnPacks = GeyserImpl.getInstance().getConfig().getResourcePackUrls();
for (String url: cdnPacks) {
int packHash = url.hashCode();
Path cachedPath = cachedCdnPacksDirectory.resolve(packHash + ".zip");
WebUtils.downloadFile(url, cachedPath.toString());
ResourcePack cdnpack = readPack(cachedPath);
UUID uuid = cdnpack.manifest().header().uuid();
RESOURCE_PACK_CDN_ENTRIES.add(new ResourcePackCDNEntry(url, uuid));
try {
Files.delete(cachedPath);
} catch (IOException e) {
GeyserImpl.getInstance().getLogger().error("Could not delete cached pack", e);
}
}
// Load CDN entries
loadCdnEntries();
GeyserLoadResourcePacksEvent event = new GeyserLoadResourcePacksEvent(resourcePacks);
GeyserImpl.getInstance().eventBus().fire(event);
@ -200,4 +174,36 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<String, Reso
throw new IllegalArgumentException(GeyserLocale.getLocaleStringLog("geyser.resource_pack.broken", path.getFileName()), e);
}
}
public void loadCdnEntries() {
final Path cachedCdnPacksDirectory = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("cache").resolve("cdn-packs");
// Download CDN packs to get the pack uuid's
if (!Files.exists(cachedCdnPacksDirectory)) {
try {
Files.createDirectories(cachedCdnPacksDirectory);
} catch (IOException e) {
GeyserImpl.getInstance().getLogger().error("Could not create cached packs directory", e);
return;
}
}
List<String> cdnPacks = GeyserImpl.getInstance().getConfig().getResourcePackUrls();
for (String url: cdnPacks) {
int packHash = url.hashCode();
Path cachedPath = cachedCdnPacksDirectory.resolve(packHash + ".zip");
WebUtils.downloadFile(url, cachedPath.toString());
ResourcePack cdnpack = readPack(cachedPath);
UUID uuid = cdnpack.manifest().header().uuid();
RESOURCE_PACK_CDN_ENTRIES.add(new ResourcePackCDNEntry(url, uuid));
try {
Files.delete(cachedPath);
} catch (IOException e) {
GeyserImpl.getInstance().getLogger().error("Could not delete cached pack", e);
}
}
}
}