From 1fb09e8f404f91a79ebc8a7105cd5b3f77f3650b Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 25 Sep 2020 20:14:35 +0200 Subject: [PATCH] wip modding (2) --- doc/Modding.md | 2 +- .../minosoft/modding/loading/LoadingInfo.java | 33 +++++++ .../modding/loading/LoadingPriorities.java | 22 +++++ .../modding/{ => loading}/MinosoftMod.java | 2 +- .../minosoft/modding/loading/ModInfo.java | 87 +++++++++++++++++++ .../modding/{ => loading}/ModPhases.java | 2 +- .../java/de/bixilon/minosoft/util/Util.java | 13 ++- 7 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/modding/loading/LoadingInfo.java create mode 100644 src/main/java/de/bixilon/minosoft/modding/loading/LoadingPriorities.java rename src/main/java/de/bixilon/minosoft/modding/{ => loading}/MinosoftMod.java (95%) create mode 100644 src/main/java/de/bixilon/minosoft/modding/loading/ModInfo.java rename src/main/java/de/bixilon/minosoft/modding/{ => loading}/ModPhases.java (95%) diff --git a/doc/Modding.md b/doc/Modding.md index 21625724c..83d3740e3 100644 --- a/doc/Modding.md +++ b/doc/Modding.md @@ -45,7 +45,7 @@ In your jar file (the mod) must be a file called `mod.json`. - `versionName`, `authors`, `name` is the classic implementation of metadata. Can be anything, will be displayed in the mod list. **Required** - `identifier` is the prefix of items (for Minecraft it is `minecraft`). Aka the thing before the `:`. **Required** - `mainClass` the Main class of your mod (self explaining). The main class needs to extent the abstract class `MinosoftMod`. **Required** - `loading` Loading attributes. **Optional** +- `loading` Loading attributes. **Optional** - `priority` should the mod be loaded at the beginning or at the end. Possible values are `LOWEST`, `LOW`, `NORMAL`, `HIGH`, `HIGHEST` **Optional** - `dependencies` Used if you need an other mod to work **Optional** - `hard` These mods are **needed** to work. If the loading fails, your mod is not getting loaded and an warning message is being displayed. **Optional** diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/LoadingInfo.java b/src/main/java/de/bixilon/minosoft/modding/loading/LoadingInfo.java new file mode 100644 index 000000000..0c100507e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/modding/loading/LoadingInfo.java @@ -0,0 +1,33 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.modding.loading; + +public class LoadingInfo { + LoadingPriorities loadingPriority; + + public LoadingInfo(LoadingPriorities loadingPriority) { + this.loadingPriority = loadingPriority; + } + + public LoadingInfo() { + } + + public LoadingPriorities getLoadingPriority() { + return loadingPriority; + } + + public void setLoadingPriority(LoadingPriorities loadingPriority) { + this.loadingPriority = loadingPriority; + } +} diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/LoadingPriorities.java b/src/main/java/de/bixilon/minosoft/modding/loading/LoadingPriorities.java new file mode 100644 index 000000000..79d38c2ec --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/modding/loading/LoadingPriorities.java @@ -0,0 +1,22 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.modding.loading; + +public enum LoadingPriorities { + LOWEST, + LOW, + NORMAL, + HIGH, + HIGHEST +} diff --git a/src/main/java/de/bixilon/minosoft/modding/MinosoftMod.java b/src/main/java/de/bixilon/minosoft/modding/loading/MinosoftMod.java similarity index 95% rename from src/main/java/de/bixilon/minosoft/modding/MinosoftMod.java rename to src/main/java/de/bixilon/minosoft/modding/loading/MinosoftMod.java index 005147ba9..8ff20a37c 100644 --- a/src/main/java/de/bixilon/minosoft/modding/MinosoftMod.java +++ b/src/main/java/de/bixilon/minosoft/modding/loading/MinosoftMod.java @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.modding; +package de.bixilon.minosoft.modding.loading; interface MinosoftModInterface { boolean start(ModPhases phase); diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/ModInfo.java b/src/main/java/de/bixilon/minosoft/modding/loading/ModInfo.java new file mode 100644 index 000000000..c7f68176c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/modding/loading/ModInfo.java @@ -0,0 +1,87 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.modding.loading; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import de.bixilon.minosoft.util.Util; + +import java.util.UUID; + +public class ModInfo { + final UUID uuid; + final int versionId; + final String versionName; + final String name; + final String[] authors; + final String identifier; + final String mainClass; + LoadingInfo info; + + public ModInfo(JsonObject json) { + this.uuid = Util.uuidFromString(json.get("uuid").getAsString()); + this.versionId = json.get("versionId").getAsInt(); + this.versionName = json.get("versionName").getAsString(); + this.name = json.get("name").getAsString(); + JsonArray authors = json.get("authors").getAsJsonArray(); + this.authors = new String[authors.size()]; + int i = 0; + for (JsonElement authorElement : authors) { + this.authors[i] = authorElement.getAsString(); + i++; + } + this.identifier = json.get("identifier").getAsString(); + this.mainClass = json.get("mainClass").getAsString(); + if (json.has("loading")) { + JsonObject loading = json.getAsJsonObject("loading"); + this.info = new LoadingInfo(); + if (loading.has("priority")) { + this.info.setLoadingPriority(LoadingPriorities.valueOf(loading.get("priority").getAsString())); + } + } + } + + public UUID getUUID() { + return uuid; + } + + public int getVersionId() { + return versionId; + } + + public String getVersionName() { + return versionName; + } + + public String getName() { + return name; + } + + public String[] getAuthors() { + return authors; + } + + public String getIdentifier() { + return identifier; + } + + public String getMainClass() { + return mainClass; + } + + public LoadingInfo getInfo() { + return info; + } +} diff --git a/src/main/java/de/bixilon/minosoft/modding/ModPhases.java b/src/main/java/de/bixilon/minosoft/modding/loading/ModPhases.java similarity index 95% rename from src/main/java/de/bixilon/minosoft/modding/ModPhases.java rename to src/main/java/de/bixilon/minosoft/modding/loading/ModPhases.java index f76000323..8fdbd8e28 100644 --- a/src/main/java/de/bixilon/minosoft/modding/ModPhases.java +++ b/src/main/java/de/bixilon/minosoft/modding/loading/ModPhases.java @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.modding; +package de.bixilon.minosoft.modding.loading; public enum ModPhases { BOOTING, diff --git a/src/main/java/de/bixilon/minosoft/util/Util.java b/src/main/java/de/bixilon/minosoft/util/Util.java index ace2428fb..1bad3221c 100644 --- a/src/main/java/de/bixilon/minosoft/util/Util.java +++ b/src/main/java/de/bixilon/minosoft/util/Util.java @@ -28,10 +28,7 @@ import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.UUID; import java.util.regex.Pattern; -import java.util.zip.DataFormatException; -import java.util.zip.Deflater; -import java.util.zip.GZIPInputStream; -import java.util.zip.Inflater; +import java.util.zip.*; public final class Util { public static final Pattern UUID_FIX = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); // thanks https://www.spigotmc.org/threads/free-code-easily-convert-between-trimmed-and-full-uuids.165615 @@ -159,6 +156,14 @@ public final class Util { return stringBuilder.toString(); } + public static String readFileFromZip(String fileName, ZipFile zipFile) throws IOException { + return readFile(new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipFile.getEntry(fileName)))), false); + } + + public static JsonObject readJsonFromZip(String fileName, ZipFile zipFile) throws IOException { + return JsonParser.parseString(readFileFromZip(fileName, zipFile)).getAsJsonObject(); + } + public static String readFile(File file) throws IOException { return readFile(new BufferedReader(new FileReader(file)), true); }