move things around for better organisation

This commit is contained in:
moehreag 2024-05-16 13:01:49 +02:00
parent 8a75f71ab4
commit 530797fcdb
13 changed files with 47 additions and 41 deletions

View file

@ -3,7 +3,7 @@ package io.github.moehreag.nonsense.loader.api;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import io.github.moehreag.nonsense.loader.impl.Env; import io.github.moehreag.nonsense.loader.api.env.Env;
import io.github.moehreag.nonsense.loader.impl.LoaderImpl; import io.github.moehreag.nonsense.loader.impl.LoaderImpl;
import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin; import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin;

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl; package io.github.moehreag.nonsense.loader.api.env;
import lombok.Getter; import lombok.Getter;

View file

@ -10,6 +10,8 @@ import java.nio.file.Paths;
import java.util.*; import java.util.*;
import io.github.moehreag.nonsense.loader.api.Loader; import io.github.moehreag.nonsense.loader.api.Loader;
import io.github.moehreag.nonsense.loader.api.env.Env;
import io.github.moehreag.nonsense.loader.impl.launch.MixinClassloader;
import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin; import io.github.moehreag.nonsense.loader.impl.plugin.NonsensePlugin;
import lombok.Getter; import lombok.Getter;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -84,24 +86,25 @@ public class LoaderImpl implements Loader {
}); });
LOGGER.info("Found plugins: \n{}", String.join("\t\n", classes)); LOGGER.info("Found plugins: \n{}", String.join("\t\n", classes));
classes.stream().map((String className) -> { for (Class<?> c : classes.stream().map((String className) -> {
try { try {
return classloader.findClass(className); return classloader.findClass(className);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// TODO error handling // TODO error handling
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}).filter(NonsensePlugin.class::isAssignableFrom).forEach(c -> { }).filter(NonsensePlugin.class::isAssignableFrom).toList()){
try { try {
MethodHandle ctor = MethodHandles.publicLookup().findConstructor(c, MethodType.methodType(void.class)); MethodHandle ctor = MethodHandles.publicLookup().findConstructor(c, MethodType.methodType(void.class));
NonsensePlugin plugin = (NonsensePlugin) ctor.invoke(); NonsensePlugin plugin = (NonsensePlugin) ctor.invoke();
plugins.add(plugin); plugins.add(plugin);
plugin.init(this); if (plugin.init(this)){
break;
}
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace();
LOGGER.error("Failed to instantiate plugin: ", e); LOGGER.error("Failed to instantiate plugin: ", e);
} }
}); }
} }
public String getArgument(String name){ public String getArgument(String name){

View file

@ -1,11 +0,0 @@
package io.github.moehreag.nonsense.loader.impl.client;
import io.github.moehreag.nonsense.loader.impl.Launcher;
import io.github.moehreag.nonsense.loader.impl.Env;
public class NonsenseClient {
public static void main(String[] args){
Launcher.run(args, Env.CLIENT);
}
}

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl; package io.github.moehreag.nonsense.loader.impl.launch;
import java.io.File; import java.io.File;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import io.github.moehreag.nonsense.loader.api.env.Env;
import io.github.moehreag.nonsense.loader.impl.mixin.NonsenseMixinService; import io.github.moehreag.nonsense.loader.impl.mixin.NonsenseMixinService;
import lombok.Getter; import lombok.Getter;
import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.launch.MixinBootstrap;

View file

@ -1,4 +1,4 @@
package io.github.moehreag.nonsense.loader.impl; package io.github.moehreag.nonsense.loader.impl.launch;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;

View file

@ -0,0 +1,11 @@
package io.github.moehreag.nonsense.loader.impl.launch.client;
import io.github.moehreag.nonsense.loader.impl.launch.Launcher;
import io.github.moehreag.nonsense.loader.api.env.Env;
public class NonsenseClient {
public static void main(String[] args){
Launcher.run(args, Env.CLIENT);
}
}

View file

@ -0,0 +1,11 @@
package io.github.moehreag.nonsense.loader.impl.launch.server;
import io.github.moehreag.nonsense.loader.impl.launch.Launcher;
import io.github.moehreag.nonsense.loader.api.env.Env;
public class NonsenseServer {
public static void main(String[] args){
Launcher.run(args, Env.SERVER);
}
}

View file

@ -1,6 +1,6 @@
package io.github.moehreag.nonsense.loader.impl.mixin; package io.github.moehreag.nonsense.loader.impl.mixin;
import io.github.moehreag.nonsense.loader.impl.Launcher; import io.github.moehreag.nonsense.loader.impl.launch.Launcher;
import org.spongepowered.asm.service.IGlobalPropertyService; import org.spongepowered.asm.service.IGlobalPropertyService;
import org.spongepowered.asm.service.IPropertyKey; import org.spongepowered.asm.service.IPropertyKey;

View file

@ -1,6 +1,6 @@
package io.github.moehreag.nonsense.loader.impl.mixin; package io.github.moehreag.nonsense.loader.impl.mixin;
import io.github.moehreag.nonsense.loader.impl.Launcher; import io.github.moehreag.nonsense.loader.impl.launch.Launcher;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.launch.platform.container.ContainerHandleVirtual; import org.spongepowered.asm.launch.platform.container.ContainerHandleVirtual;

View file

@ -8,7 +8,7 @@ public interface NonsensePlugin extends Runnable {
} }
default void init(LoaderImpl loader) { default boolean init(LoaderImpl loader) {
return false;
} }
} }

View file

@ -32,7 +32,13 @@ public class Minecraft implements NonsensePlugin {
private String foundMainClass; private String foundMainClass;
@Override @Override
public void init(LoaderImpl loader) { public boolean init(LoaderImpl loader) {
Path gameJar = findGame();
if (gameJar == null){
return false;
//throw new IllegalStateException("Could not find game jar!");
}
version = loader.getArgument("version"); version = loader.getArgument("version");
remappedGamePath = loader.getGameDir().resolve(".nonsense/remappedJars").resolve(version).resolve("game-"+version+"-remapped.jar"); remappedGamePath = loader.getGameDir().resolve(".nonsense/remappedJars").resolve(version).resolve("game-"+version+"-remapped.jar");
@ -57,10 +63,6 @@ public class Minecraft implements NonsensePlugin {
}).forEach(LoaderImpl.getInstance().getClassloader()::addURL); }).forEach(LoaderImpl.getInstance().getClassloader()::addURL);
LOGGER.info("Found {} mods", mods.size()); LOGGER.info("Found {} mods", mods.size());
Path gameJar = findGame();
if (gameJar == null){
throw new IllegalStateException("Could not find game jar!");
}
if (!Files.exists(remappedGamePath)){ if (!Files.exists(remappedGamePath)){
try { try {
@ -75,7 +77,7 @@ public class Minecraft implements NonsensePlugin {
} catch (Throwable e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return true;
} }
private Path findGame() { private Path findGame() {

View file

@ -1,11 +0,0 @@
package io.github.moehreag.nonsense.loader.impl.server;
import io.github.moehreag.nonsense.loader.impl.Launcher;
import io.github.moehreag.nonsense.loader.impl.Env;
public class NonsenseServer {
public static void main(String[] args){
Launcher.run(args, Env.SERVER);
}
}