diff --git a/CHANGELOG.md b/CHANGELOG.md index c0fc2f6..dbf6125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Added support for MultiMC json + +### Changed +- Changed InstallationModeOptions toString() to be prettier + ## [0.7.5] - 2019-10-16 ### Fixed diff --git a/src/main/java/io/github/ImpactDevelopment/installer/target/InstallationModeOptions.java b/src/main/java/io/github/ImpactDevelopment/installer/target/InstallationModeOptions.java index b01dd70..b2686ae 100644 --- a/src/main/java/io/github/ImpactDevelopment/installer/target/InstallationModeOptions.java +++ b/src/main/java/io/github/ImpactDevelopment/installer/target/InstallationModeOptions.java @@ -26,18 +26,18 @@ import io.github.ImpactDevelopment.installer.setting.InstallationConfig; import io.github.ImpactDevelopment.installer.target.targets.Forge; import io.github.ImpactDevelopment.installer.target.targets.ShowJSON; +import io.github.ImpactDevelopment.installer.target.targets.MultiMC; import io.github.ImpactDevelopment.installer.target.targets.Validate; import io.github.ImpactDevelopment.installer.target.targets.Vanilla; import java.util.function.Function; public enum InstallationModeOptions { - VANILLA(Vanilla::new, true), FORGE(Forge::new, true), VALIDATE(Validate::new, false), SHOWJSON(ShowJSON::new, true) { - @Override - public String toString() { - return "Show JSON"; - } - }; + VANILLA(Vanilla::new, true), + FORGE(Forge::new, true), + VALIDATE(Validate::new, false), + MULTIMC(MultiMC::new,true), + SHOWJSON(ShowJSON::new, true); InstallationModeOptions(Function mode, boolean showInGUI) { this.mode = mode; @@ -59,7 +59,20 @@ public boolean supports(ImpactVersion impact) { @Override public String toString() { // incredibly based code - String name = super.toString(); - return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); + // this is oof NGL :eyes: + switch (this) { + case VANILLA: + return "Vanilla"; + case SHOWJSON: + return "Show Vanilla JSON"; + case MULTIMC: + return "Show MultiMC JSON"; + case FORGE: + return "Forge"; + case VALIDATE: + return "Validate Vanilla version"; + default: + return "Unknown"; + } } } diff --git a/src/main/java/io/github/ImpactDevelopment/installer/target/targets/MultiMC.java b/src/main/java/io/github/ImpactDevelopment/installer/target/targets/MultiMC.java new file mode 100644 index 0000000..9352fec --- /dev/null +++ b/src/main/java/io/github/ImpactDevelopment/installer/target/targets/MultiMC.java @@ -0,0 +1,58 @@ +/* + * This file is part of Impact Installer. + * + * Copyright (C) 2019 ImpactDevelopment and contributors + * + * See the CONTRIBUTORS.md file for a list of copyright holders + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package io.github.ImpactDevelopment.installer.target.targets; + +import com.google.gson.JsonObject; +import io.github.ImpactDevelopment.installer.Installer; +import io.github.ImpactDevelopment.installer.setting.InstallationConfig; +import io.github.ImpactDevelopment.installer.target.InstallationMode; + +import javax.swing.*; + +public class MultiMC implements InstallationMode { + private final InstallationConfig config; + + public MultiMC(InstallationConfig config) { + this.config = config; + } + + @Override + public String apply() { + JsonObject toDisplay = new Vanilla(config).generateMultiMCJsonVersion(); + String data = Installer.gson.toJson(toDisplay); + if (Installer.args.noGUI) { + return data; + } + SwingUtilities.invokeLater(() -> { + JFrame frame = new JFrame(toDisplay.get("version").getAsString()); + JTextArea area = new JTextArea(); + area.setEditable(true); + area.append(data); + area.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + frame.getContentPane().add(new JScrollPane(area)); + frame.setSize(690, 420); + frame.setVisible(true); + }); + return "Here is the JSON for MultiMC " + toDisplay.get("version"); + } +} diff --git a/src/main/java/io/github/ImpactDevelopment/installer/target/targets/ShowJSON.java b/src/main/java/io/github/ImpactDevelopment/installer/target/targets/ShowJSON.java index bc5dd82..56acad9 100644 --- a/src/main/java/io/github/ImpactDevelopment/installer/target/targets/ShowJSON.java +++ b/src/main/java/io/github/ImpactDevelopment/installer/target/targets/ShowJSON.java @@ -38,7 +38,7 @@ public ShowJSON(InstallationConfig config) { @Override public String apply() { - JsonObject toDisplay = new Vanilla(config).generateJsonVersion(); + JsonObject toDisplay = new Vanilla(config).generateVanillaJsonVersion(); String data = Installer.gson.toJson(toDisplay); if (Installer.args.noGUI) { return data; @@ -53,6 +53,6 @@ public String apply() { frame.setSize(690, 420); frame.setVisible(true); }); - return "Here is the JSON for " + toDisplay.get("id"); + return "Here is the JSON for Vanilla " + toDisplay.get("id"); } } diff --git a/src/main/java/io/github/ImpactDevelopment/installer/target/targets/Vanilla.java b/src/main/java/io/github/ImpactDevelopment/installer/target/targets/Vanilla.java index 5c13145..3317e16 100644 --- a/src/main/java/io/github/ImpactDevelopment/installer/target/targets/Vanilla.java +++ b/src/main/java/io/github/ImpactDevelopment/installer/target/targets/Vanilla.java @@ -59,7 +59,7 @@ public Vanilla(InstallationConfig config) { this.id = version.mcVersion + "-" + version.name + "_" + version.version + prettifiedOptifineVersion().orElse(""); } - public JsonObject generateJsonVersion() { + public JsonObject generateVanillaJsonVersion() { JsonObject object = new JsonObject(); object.addProperty("id", id); object.addProperty("type", "release"); @@ -71,7 +71,23 @@ public JsonObject generateJsonVersion() { object.addProperty("minimumLauncherVersion", 0); object.addProperty("mainClass", "net.minecraft.launchwrapper.Launch"); populateArguments(object); - populateLibraries(object); + populateLibraries(object, false); + return object; + } + + public JsonObject generateMultiMCJsonVersion() { + JsonObject object = new JsonObject(); + JsonArray arrayTweakers = new JsonArray(); + arrayTweakers.add("clientapi.load.ClientTweaker"); + arrayTweakers.add("baritone.launch.BaritoneTweaker"); + object.addProperty("fileID", "me.zero.clarinet.Impact"); + object.addProperty("mainClass", "net.minecraft.launchwrapper.Launch"); + object.addProperty("mcVersion", version.mcVersion); + object.addProperty("name", "Impact " + version.version); + object.addProperty("order",10); + object.addProperty("version",id); + object.add("+tweakers", arrayTweakers); + populateLibraries(object, true); return object; } @@ -94,12 +110,16 @@ private void populateArguments(JsonObject object) { } } - private void populateLibraries(JsonObject object) { + private void populateLibraries(JsonObject object, boolean multimc) { JsonArray libraries = new JsonArray(); for (ILibrary lib : version.resolveLibraries(config)) { populateLib(lib, libraries); } - object.add("libraries", libraries); + if (multimc) { + object.add("+libraries", libraries); + } else { + object.add("libraries", libraries); + } populateOptifine(libraries); } @@ -197,7 +217,7 @@ private void installVersionJson() throws IOException { } } System.out.println("Writing to " + directory.resolve(id + ".json")); - Files.write(directory.resolve(id + ".json"), Installer.gson.toJson(generateJsonVersion()).getBytes(StandardCharsets.UTF_8)); + Files.write(directory.resolve(id + ".json"), Installer.gson.toJson(generateVanillaJsonVersion()).getBytes(StandardCharsets.UTF_8)); } private void installProfiles() throws IOException {