-
-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for manually supplying Bedrock resource packs (#1076)
* send resource packs A lot of this code is nukkit-credits in the classes * send resource packs A lot of this code is nukkit-credits in the classes * Remove unnecessary code/debugs * use separately generated hashes * Updated mappings and added .mcpack support * "packs" directory auto-create (#484) * "packs" directory auto-create * cleaned indentation in ResourcePack.java * Cleaned ResourcePack.java * Another cleanup I hate editor on github. * Yet another * Another indentation cleanup * Fix resource pack loading (cherry picked from commit f93b074) * Move back to internal sha256 hashing (cherry picked from commit 812a3d8) * Add resource pack loading back after merge * Add comments, config option and removed unused files * Fix packs folder location and cleanup code * Move to better options for the client * Fix typos in comments * Fix pack loading * Try to make it compile * Final touches? * Add Javadoc for MathUtils#constrain Co-authored-by: EOT3000 <[email protected]> Co-authored-by: Vesek <[email protected]> Co-authored-by: Heath123 <[email protected]> Co-authored-by: Camotoy <[email protected]>
- Loading branch information
1 parent
1a49e88
commit 99e72f3
Showing
10 changed files
with
372 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,4 +241,5 @@ config.yml | |
logs/ | ||
public-key.pem | ||
locales/ | ||
/cache/ | ||
/cache/ | ||
/packs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
connector/src/main/java/org/geysermc/connector/utils/ResourcePack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* @author GeyserMC | ||
* @link https://github.com/GeyserMC/Geyser | ||
*/ | ||
|
||
package org.geysermc.connector.utils; | ||
|
||
import org.geysermc.connector.GeyserConnector; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.zip.ZipFile; | ||
|
||
/** | ||
* This represents a resource pack and all the data relevant to it | ||
*/ | ||
public class ResourcePack { | ||
/** | ||
* The list of loaded resource packs | ||
*/ | ||
public static final Map<String, ResourcePack> PACKS = new HashMap<>(); | ||
|
||
/** | ||
* The size of each chunk to use when sending the resource packs to clients in bytes | ||
*/ | ||
public static final int CHUNK_SIZE = 102400; | ||
|
||
private byte[] sha256; | ||
private File file; | ||
private ResourcePackManifest manifest; | ||
private ResourcePackManifest.Version version; | ||
|
||
/** | ||
* Loop through the packs directory and locate valid resource pack files | ||
*/ | ||
public static void loadPacks() { | ||
File directory = GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("packs").toFile(); | ||
|
||
if (!directory.exists()) { | ||
directory.mkdir(); | ||
|
||
// As we just created the directory it will be empty | ||
return; | ||
} | ||
|
||
for (File file : directory.listFiles()) { | ||
if (file.getName().endsWith(".zip") || file.getName().endsWith(".mcpack")) { | ||
ResourcePack pack = new ResourcePack(); | ||
|
||
pack.sha256 = FileUtils.calculateSHA256(file); | ||
|
||
try { | ||
ZipFile zip = new ZipFile(file); | ||
|
||
zip.stream().forEach((x) -> { | ||
if (x.getName().contains("manifest.json")) { | ||
try { | ||
ResourcePackManifest manifest = FileUtils.loadJson(zip.getInputStream(x), ResourcePackManifest.class); | ||
|
||
pack.file = file; | ||
pack.manifest = manifest; | ||
pack.version = ResourcePackManifest.Version.fromArray(manifest.getHeader().getVersion()); | ||
|
||
PACKS.put(pack.getManifest().getHeader().getUuid().toString(), pack); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} catch (Exception e) { | ||
GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.resource_pack.broken", file.getName())); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public byte[] getSha256() { | ||
return sha256; | ||
} | ||
|
||
public File getFile() { | ||
return file; | ||
} | ||
|
||
public ResourcePackManifest getManifest() { | ||
return manifest; | ||
} | ||
|
||
public ResourcePackManifest.Version getVersion() { | ||
return version; | ||
} | ||
} |
Oops, something went wrong.