Skip to content

Commit

Permalink
Fix: publish to maven central
Browse files Browse the repository at this point in the history
  • Loading branch information
xfl03 committed Jan 31, 2023
1 parent ab494f8 commit fb8d5b8
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -2,7 +2,7 @@ plugins {
base
}

version = "3.0.1"
version = "3.0.2"

subprojects {
//Real subproject DSL is located at `buildSrc/src/main/kotlin/dev.3-3.jmccc.gradle.kts`
Expand Down
6 changes: 6 additions & 0 deletions buildSrc/src/main/kotlin/dev.3-3.jmccc.gradle.kts
@@ -1,6 +1,7 @@
plugins {
`java-library`
`maven-publish`
signing
}

dependencies {
Expand Down Expand Up @@ -40,6 +41,7 @@ publishing {
artifact(tasks["shadowJar"])
}
pom {
name.set(project.name)
description.set("JMCCC is a powerful open-source library for launching and downloading Minecraft.")
url.set("https://github.com/xfl03/JMCCC")
licenses {
Expand Down Expand Up @@ -119,4 +121,8 @@ publishing {
}
}
}
}

signing {
sign(publishing.publications["mavenJava"])
}
62 changes: 31 additions & 31 deletions jmccc-cli/src/main/java/jmccc/cli/Main.java
@@ -1,14 +1,16 @@
package jmccc.cli;

import jmccc.cli.download.CliDownloader;
import jmccc.cli.download.ModLoaderDownloader;
import jmccc.cli.download.SimpleDownloader;
import jmccc.cli.launch.SimpleLauncher;
import jmccc.cli.launch.CliLauncher;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.to2mbn.jmccc.option.MinecraftDirectory;
import org.to2mbn.jmccc.version.Version;

import java.util.concurrent.ExecutionException;

public class Main {

/**
Expand All @@ -25,49 +27,47 @@ public static void main(String... args) throws Exception {
String player = playerOption.value(options);
String dir = dirOption.value(options);
String version = versionOption.value(options);
if (version == null) {
version = "release";
}
MinecraftDirectory minecraftDirectory = new MinecraftDirectory(dir);

//Check special version
version = parseVersion(version);
System.out.println("Version: " + version);

//Download game if not exist
if (!minecraftDirectory.getVersionJson(version).exists()) {
Version v = CliDownloader.download(minecraftDirectory, version);
version = v.getVersion();
}

//Launch game
CliLauncher.launch(minecraftDirectory, version, player);
}

private static String parseVersion(String version) throws ExecutionException, InterruptedException {
if (version == null) {
version = "release";
}
switch (version) {
case "latest":
case "stable":
case "release":
version = SimpleDownloader.getLatestRelease();
break;
return CliDownloader.getLatestRelease();
case "snapshot":
version = SimpleDownloader.getLatestSnapshot();
break;
return CliDownloader.getLatestSnapshot();
case "forge":
version = ModLoaderDownloader.getLatestForge().getVersionName();
break;
return ModLoaderDownloader.getLatestForge().getVersionName();
case "liteloader":
version = ModLoaderDownloader.getLatestLiteLoader().getVersionName();
break;
return ModLoaderDownloader.getLatestLiteLoader().getVersionName();
case "fabric":
version = ModLoaderDownloader.getLatestFabric().getVersionName();
break;
return ModLoaderDownloader.getLatestFabric().getVersionName();
case "fabric-snapshot":
version = ModLoaderDownloader.getLatestFabricSnapshot().getVersionName();
break;
return ModLoaderDownloader.getLatestFabricSnapshot().getVersionName();
case "quilt":
version = ModLoaderDownloader.getLatestQuilt().getVersionName();
break;
return ModLoaderDownloader.getLatestQuilt().getVersionName();
case "quilt-snapshot":
version = ModLoaderDownloader.getLatestQuiltSnapshot().getVersionName();
break;
}
System.out.println("Version: " + version);

//Download game if not exist
if (!minecraftDirectory.getVersionJson(version).exists()) {
Version v = SimpleDownloader.download(minecraftDirectory, version);
version = v.getVersion();
return ModLoaderDownloader.getLatestQuiltSnapshot().getVersionName();
default:
return version;
}

//Launch game
SimpleLauncher.launch(minecraftDirectory, version, player);
}
}
Expand Up @@ -4,7 +4,7 @@
import org.to2mbn.jmccc.mcdownloader.download.concurrent.DownloadCallback;
import org.to2mbn.jmccc.mcdownloader.download.tasks.DownloadTask;

public class SimpleCallback<T> extends CallbackAdapter<T> {
public class CliCallback<T> extends CallbackAdapter<T> {
@Override
public void done(T result) {
String res = result.toString();
Expand Down Expand Up @@ -36,6 +36,6 @@ public void retry(Throwable e, int current, int max) {
@Override
public <R> DownloadCallback<R> taskStart(DownloadTask<R> task) {
System.out.println("Start: " + task.getURI());
return new SimpleCallback<R>();
return new CliCallback<R>();
}
}
Expand Up @@ -14,7 +14,7 @@

import java.util.concurrent.ExecutionException;

public class SimpleDownloader {
public class CliDownloader {
public static BmclApiProvider bmclApiProvider = new BmclApiProvider();
public static ForgeDownloadProvider forgeProvider = new ForgeDownloadProvider(bmclApiProvider);
public static LiteloaderDownloadProvider liteloaderProvider = new LiteloaderDownloadProvider(bmclApiProvider);
Expand All @@ -40,14 +40,14 @@ public static String getLatestSnapshot() throws ExecutionException, InterruptedE
}

public static Version download(MinecraftDirectory dir, String version) throws ExecutionException, InterruptedException {
return downloader.downloadIncrementally(dir, version, new SimpleCallback<>()).get();
return downloader.downloadIncrementally(dir, version, new CliCallback<>()).get();
}

public static void downloadLibrary(MinecraftDirectory dir, Library lib) throws ExecutionException, InterruptedException {
downloader.download(downloader.getProvider().library(dir, lib), new SimpleCallback<>()).get();
downloader.download(downloader.getProvider().library(dir, lib), new CliCallback<>()).get();
}

public static <T> T get(CombinedDownloadTask<T> task) throws ExecutionException, InterruptedException {
return SimpleDownloader.downloader.download(task, new SimpleCallback<>()).get();
return CliDownloader.downloader.download(task, new CliCallback<>()).get();
}
}
Expand Up @@ -8,27 +8,27 @@

public class ModLoaderDownloader {
public static ForgeVersion getLatestForge() throws ExecutionException, InterruptedException {
return SimpleDownloader.get(SimpleDownloader.forgeProvider.forgeVersionList()).getLatest();
return CliDownloader.get(CliDownloader.forgeProvider.forgeVersionList()).getLatest();
}

public static LiteloaderVersion getLatestLiteLoader() throws ExecutionException, InterruptedException {
return SimpleDownloader.get(SimpleDownloader.liteloaderProvider.liteloaderVersionList())
return CliDownloader.get(CliDownloader.liteloaderProvider.liteloaderVersionList())
.getSnapshot("1.12.2");
}

public static FabricVersion getLatestFabric() throws ExecutionException, InterruptedException {
return SimpleDownloader.get(SimpleDownloader.fabricProvider.fabricVersionList()).getLatestRelease();
return CliDownloader.get(CliDownloader.fabricProvider.fabricVersionList()).getLatestRelease();
}

public static FabricVersion getLatestFabricSnapshot() throws ExecutionException, InterruptedException {
return SimpleDownloader.get(SimpleDownloader.fabricProvider.fabricVersionList()).getLatestSnapshot();
return CliDownloader.get(CliDownloader.fabricProvider.fabricVersionList()).getLatestSnapshot();
}

public static FabricVersion getLatestQuilt() throws ExecutionException, InterruptedException {
return SimpleDownloader.get(SimpleDownloader.quiltProvider.fabricVersionList()).getLatestRelease();
return CliDownloader.get(CliDownloader.quiltProvider.fabricVersionList()).getLatestRelease();
}

public static FabricVersion getLatestQuiltSnapshot() throws ExecutionException, InterruptedException {
return SimpleDownloader.get(SimpleDownloader.quiltProvider.fabricVersionList()).getLatestSnapshot();
return CliDownloader.get(CliDownloader.quiltProvider.fabricVersionList()).getLatestSnapshot();
}
}
@@ -1,6 +1,6 @@
package jmccc.cli.launch;

import jmccc.cli.download.SimpleDownloader;
import jmccc.cli.download.CliDownloader;
import org.to2mbn.jmccc.auth.OfflineAuthenticator;
import org.to2mbn.jmccc.launch.Launcher;
import org.to2mbn.jmccc.launch.LauncherBuilder;
Expand All @@ -11,7 +11,7 @@
import org.to2mbn.jmccc.version.Library;


public class SimpleLauncher {
public class CliLauncher {

public static void launch(MinecraftDirectory dir, String targetVersion, String player) throws Exception {
Launcher launcher = LauncherBuilder.create().printDebugCommandline(true).build();
Expand All @@ -20,34 +20,15 @@ public static void launch(MinecraftDirectory dir, String targetVersion, String p
option.commandlineVariables().put("version_type", "JMCCC 3.0");
//Set memory to 2048MB
option.setMaxMemory(2048);
ProcessListener listener = new ExampleListener();
ProcessListener listener = new CliListener();
System.out.println("Launching version: " + targetVersion);
try {
launcher.launch(option, listener);
} catch (MissingDependenciesException e) {
for (Library lib : e.getMissingLibraries()) {
SimpleDownloader.downloadLibrary(dir, lib);
CliDownloader.downloadLibrary(dir, lib);
}
launcher.launch(option, listener);
}
}

private static class ExampleListener implements ProcessListener {

@Override
public void onLog(String log) {
System.out.println(log);
}

@Override
public void onErrorLog(String log) {
System.err.println(log);
}

@Override
public void onExit(int code) {
System.out.println("Game exited with " + code);
SimpleDownloader.downloader.shutdown();
System.exit(0);
}
}
}
24 changes: 24 additions & 0 deletions jmccc-cli/src/main/java/jmccc/cli/launch/CliListener.java
@@ -0,0 +1,24 @@
package jmccc.cli.launch;

import jmccc.cli.download.CliDownloader;
import org.to2mbn.jmccc.launch.ProcessListener;

public class CliListener implements ProcessListener {

@Override
public void onLog(String log) {
System.out.println(log);
}

@Override
public void onErrorLog(String log) {
System.err.println(log);
}

@Override
public void onExit(int code) {
System.out.println("Game exited with " + code);
CliDownloader.downloader.shutdown();
System.exit(0);
}
}
Expand Up @@ -91,7 +91,7 @@ private void runInstaller(Path installerJar) throws Exception {
Class<?> installer = cl.loadClass("net.minecraftforge.installer.SimpleInstaller");
Method main = installer.getMethod("main", String[].class);
//We have tweaked install server to install client
main.invoke(null, (Object) new String[]{"--installServer", mcdir.getAbsolutePath(),"--mirror",""});
main.invoke(null, (Object) new String[]{"--installServer", mcdir.getAbsolutePath()});
}
}
}

0 comments on commit fb8d5b8

Please sign in to comment.