This commit is contained in:
moehreag 2024-06-15 13:17:51 +02:00
parent e352bb835f
commit e222633c13
18 changed files with 451 additions and 451 deletions

View file

@ -3,8 +3,8 @@ package dev.frogmc.frogloader.api.mod;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType; import java.lang.invoke.MethodType;
import java.util.Map;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -116,9 +116,9 @@ public final class ModExtensions {
} }
}; };
if (value instanceof String s){ if (value instanceof String s) {
c.accept(s); c.accept(s);
} else if (value instanceof Collection l){ } else if (value instanceof Collection l) {
((Collection<String>) l).forEach(c); ((Collection<String>) l).forEach(c);
} }
} }

View file

@ -79,6 +79,7 @@ public interface ModProperties {
/** /**
* Get this mod's paths * Get this mod's paths
*
* @return Where this mod is loaded from * @return Where this mod is loaded from
*/ */
Collection<Path> paths(); Collection<Path> paths();

View file

@ -1,10 +1,10 @@
package dev.frogmc.frogloader.api.plugin; package dev.frogmc.frogloader.api.plugin;
import dev.frogmc.frogloader.api.mod.ModProperties;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
import dev.frogmc.frogloader.api.mod.ModProperties;
public interface FrogModProvider { public interface FrogModProvider {
String id(); String id();
@ -20,7 +20,8 @@ public interface FrogModProvider {
return false; return false;
} }
default void initMods(Collection<ModProperties> mods) {}; default void initMods(Collection<ModProperties> mods) {
}
default ModProperties loadMod(Path path) { default ModProperties loadMod(Path path) {
return null; return null;

View file

@ -2,7 +2,6 @@ package dev.frogmc.frogloader.api.plugin;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import dev.frogmc.frogloader.api.FrogLoader; import dev.frogmc.frogloader.api.FrogLoader;
import dev.frogmc.frogloader.api.mod.ModProperties; import dev.frogmc.frogloader.api.mod.ModProperties;

View file

@ -1,22 +1,5 @@
package dev.frogmc.frogloader.impl; package dev.frogmc.frogloader.impl;
import com.google.gson.Gson;
import dev.frogmc.frogloader.api.FrogLoader;
import dev.frogmc.frogloader.api.env.Env;
import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.api.plugin.FrogGamePlugin;
import dev.frogmc.frogloader.api.plugin.FrogModProvider;
import dev.frogmc.frogloader.api.plugin.FrogPlugin;
import dev.frogmc.frogloader.impl.gui.LoaderGui;
import dev.frogmc.frogloader.impl.launch.MixinClassLoader;
import dev.frogmc.frogloader.impl.mod.ModUtil;
import dev.frogmc.frogloader.impl.util.CrashReportGenerator;
import dev.frogmc.frogloader.impl.util.SystemProperties;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.MixinEnvironment;
import java.io.IOException; import java.io.IOException;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
@ -27,6 +10,22 @@ import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.google.gson.Gson;
import dev.frogmc.frogloader.api.FrogLoader;
import dev.frogmc.frogloader.api.env.Env;
import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.api.plugin.FrogGamePlugin;
import dev.frogmc.frogloader.api.plugin.FrogModProvider;
import dev.frogmc.frogloader.impl.gui.LoaderGui;
import dev.frogmc.frogloader.impl.launch.MixinClassLoader;
import dev.frogmc.frogloader.impl.mod.ModUtil;
import dev.frogmc.frogloader.impl.util.CrashReportGenerator;
import dev.frogmc.frogloader.impl.util.SystemProperties;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.MixinEnvironment;
public class FrogLoaderImpl implements FrogLoader { public class FrogLoaderImpl implements FrogLoader {
public static final String MOD_FILE_EXTENSION = ".frogmod"; public static final String MOD_FILE_EXTENSION = ".frogmod";
private static final boolean DEV_ENV = Boolean.getBoolean(SystemProperties.DEVELOPMENT); private static final boolean DEV_ENV = Boolean.getBoolean(SystemProperties.DEVELOPMENT);
@ -57,7 +56,7 @@ public class FrogLoaderImpl implements FrogLoader {
private final Gson gson = new Gson(); private final Gson gson = new Gson();
// Map<Provider ID, Map<Mod ID, ModProperties>> // Map<Provider ID, Map<Mod ID, ModProperties>>
private Map<String, Map<String, ModProperties>> mods = new HashMap<>(); private final Map<String, Map<String, ModProperties>> mods = new HashMap<>();
// private Map<String, ModProperties> mods; // private Map<String, ModProperties> mods;
private Collection<String> modIds = new ArrayList<>(); private Collection<String> modIds = new ArrayList<>();

View file

@ -76,7 +76,7 @@ public class LoaderGui extends JFrame {
public static void execUnfulfilledDep(Path reportPath, ModDependencyResolver.UnfulfilledDependencyException ex, boolean keepRunning) { public static void execUnfulfilledDep(Path reportPath, ModDependencyResolver.UnfulfilledDependencyException ex, boolean keepRunning) {
exec(gui -> { exec(gui -> {
int count = ex.getDependencies().size(); int count = ex.getDependencies().size();
gui.setHeader("Found " + count + " problem"+(count > 1 ? "s" : "")); gui.setHeader("Found " + count + " problem" + (count > 1 ? "s" : ""));
gui.addTab("Info", new UnfulfilledDepPage(ex)); gui.addTab("Info", new UnfulfilledDepPage(ex));
addReport(gui, reportPath); addReport(gui, reportPath);
}, keepRunning); }, keepRunning);
@ -85,7 +85,7 @@ public class LoaderGui extends JFrame {
public static void execBreakingDep(Path reportPath, ModDependencyResolver.BreakingModException ex, boolean keepRunning) { public static void execBreakingDep(Path reportPath, ModDependencyResolver.BreakingModException ex, boolean keepRunning) {
exec(gui -> { exec(gui -> {
int count = ex.getBreaks().size(); int count = ex.getBreaks().size();
gui.setHeader("Found " + count + " problem"+(count > 1 ? "s" : "")); gui.setHeader("Found " + count + " problem" + (count > 1 ? "s" : ""));
gui.addTab("Info", new BreakingDepPage(ex)); gui.addTab("Info", new BreakingDepPage(ex));
addReport(gui, reportPath); addReport(gui, reportPath);
}, keepRunning); }, keepRunning);

View file

@ -1,14 +1,14 @@
package dev.frogmc.frogloader.impl.gui.component; package dev.frogmc.frogloader.impl.gui.component;
import dev.frogmc.frogloader.impl.mod.ModDependencyResolver;
import org.jetbrains.annotations.Nullable;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.basic.BasicBorders; import javax.swing.plaf.basic.BasicBorders;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.net.URL; import java.net.URL;
import dev.frogmc.frogloader.impl.mod.ModDependencyResolver;
import org.jetbrains.annotations.Nullable;
public class DependencyErrorEntry extends JPanel { public class DependencyErrorEntry extends JPanel {
private final JPanel actions; private final JPanel actions;

View file

@ -1,12 +1,12 @@
package dev.frogmc.frogloader.impl.gui.page; package dev.frogmc.frogloader.impl.gui.page;
import dev.frogmc.frogloader.impl.gui.component.DependencyErrorEntry;
import dev.frogmc.frogloader.impl.mod.ModDependencyResolver;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.util.Objects; import java.util.Objects;
import dev.frogmc.frogloader.impl.gui.component.DependencyErrorEntry;
import dev.frogmc.frogloader.impl.mod.ModDependencyResolver;
public class BreakingDepPage extends JScrollPane { public class BreakingDepPage extends JScrollPane {
public BreakingDepPage(ModDependencyResolver.BreakingModException ex) { public BreakingDepPage(ModDependencyResolver.BreakingModException ex) {

View file

@ -1,15 +1,15 @@
package dev.frogmc.frogloader.impl.gui.page; package dev.frogmc.frogloader.impl.gui.page;
import dev.frogmc.frogloader.impl.gui.component.DependencyErrorEntry;
import dev.frogmc.frogloader.impl.mod.ModDependencyResolver;
import dev.frogmc.frogloader.impl.util.PlatformUtil;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Objects; import java.util.Objects;
import dev.frogmc.frogloader.impl.gui.component.DependencyErrorEntry;
import dev.frogmc.frogloader.impl.mod.ModDependencyResolver;
import dev.frogmc.frogloader.impl.util.PlatformUtil;
public class UnfulfilledDepPage extends JScrollPane { public class UnfulfilledDepPage extends JScrollPane {
public UnfulfilledDepPage(ModDependencyResolver.UnfulfilledDependencyException ex) { public UnfulfilledDepPage(ModDependencyResolver.UnfulfilledDependencyException ex) {

View file

@ -58,15 +58,15 @@ public class FrogLauncher {
new FrogLauncher(args, env); new FrogLauncher(args, env);
} }
public void putProperty(IPropertyKey key, Object value){ public void putProperty(IPropertyKey key, Object value) {
globalProperties.put(key, value); globalProperties.put(key, value);
} }
public Object getProperty(IPropertyKey key){ public Object getProperty(IPropertyKey key) {
return globalProperties.get(key); return globalProperties.get(key);
} }
public Object getProperty(IPropertyKey key, Object defaultValue){ public Object getProperty(IPropertyKey key, Object defaultValue) {
return globalProperties.getOrDefault(key, defaultValue); return globalProperties.getOrDefault(key, defaultValue);
} }
} }

View file

@ -14,15 +14,15 @@ public class FrogGlobalPropertyService implements IGlobalPropertyService {
} }
@Override @Override
public boolean equals(Object other){ public boolean equals(Object other) {
if (other instanceof IPropertyKey k){ if (other instanceof IPropertyKey k) {
return name.equals(k.toString()); return name.equals(k.toString());
} }
return false; return false;
} }
@Override @Override
public int hashCode(){ public int hashCode() {
return name.hashCode(); return name.hashCode();
} }
}; };

View file

@ -6,7 +6,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.google.common.collect.*; import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import dev.frogmc.frogloader.api.mod.ModDependencies; import dev.frogmc.frogloader.api.mod.ModDependencies;
import dev.frogmc.frogloader.api.mod.ModProperties; import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.api.mod.SemVer; import dev.frogmc.frogloader.api.mod.SemVer;

View file

@ -49,8 +49,8 @@ public class ModPropertiesReader {
CommentedConfig props = PARSER.parse(in); CommentedConfig props = PARSER.parse(in);
String url = in.toString(); String url = in.toString();
Path source = Path.of(url.substring(url.lastIndexOf(":")+1).split("!")[0]).toAbsolutePath(); Path source = Path.of(url.substring(url.lastIndexOf(":") + 1).split("!")[0]).toAbsolutePath();
if (!source.getFileName().toString().endsWith(".jar")){ if (!source.getFileName().toString().endsWith(".jar")) {
source = source.getParent(); source = source.getParent();
} else { } else {
// TODO will this result in a memory leak? // TODO will this result in a memory leak?

View file

@ -1,5 +1,12 @@
package dev.frogmc.frogloader.impl.plugin.game.minecraft; package dev.frogmc.frogloader.impl.plugin.game.minecraft;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.nio.file.*;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import dev.frogmc.frogloader.api.FrogLoader; import dev.frogmc.frogloader.api.FrogLoader;
import dev.frogmc.frogloader.api.plugin.FrogGamePlugin; import dev.frogmc.frogloader.api.plugin.FrogGamePlugin;
@ -9,13 +16,6 @@ import dev.frogmc.thyroxine.Thyroxine;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.nio.file.*;
public class MinecraftGamePlugin implements FrogGamePlugin { public class MinecraftGamePlugin implements FrogGamePlugin {
protected final String[] MINECRAFT_CLASSES = new String[]{ protected final String[] MINECRAFT_CLASSES = new String[]{
@ -39,7 +39,7 @@ public class MinecraftGamePlugin implements FrogGamePlugin {
foundMainClass = n.substring(0, n.length() - 6).replace("/", "."); foundMainClass = n.substring(0, n.length() - 6).replace("/", ".");
try { try {
version = FrogLoaderImpl.getInstance().getGson().fromJson(Files.readString(fs.getPath("version.json")), JsonObject.class).get("id").getAsString(); version = FrogLoaderImpl.getInstance().getGson().fromJson(Files.readString(fs.getPath("version.json")), JsonObject.class).get("id").getAsString();
} catch (Exception e){ } catch (Exception e) {
version = FrogLoaderImpl.getInstance().getArgument("version"); version = FrogLoaderImpl.getInstance().getArgument("version");
} }
return true; return true;

View file

@ -1,18 +1,17 @@
package dev.frogmc.frogloader.impl.plugin.mod; package dev.frogmc.frogloader.impl.plugin.mod;
import dev.frogmc.frogloader.api.FrogLoader;
import dev.frogmc.frogloader.api.extensions.PreLaunchExtension;
import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.api.plugin.FrogModProvider;
import dev.frogmc.frogloader.impl.mod.ModPropertiesReader;
import org.slf4j.Logger;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileSystem; import java.nio.file.FileSystem;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
import dev.frogmc.frogloader.api.extensions.PreLaunchExtension;
import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.api.plugin.FrogModProvider;
import dev.frogmc.frogloader.impl.mod.ModPropertiesReader;
import org.slf4j.Logger;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class FrogmodModProvider implements FrogModProvider { public class FrogmodModProvider implements FrogModProvider {
@ -31,7 +30,7 @@ public class FrogmodModProvider implements FrogModProvider {
@Override @Override
public boolean isFileApplicable(Path path) { public boolean isFileApplicable(Path path) {
if (!path.toString().endsWith(".frogmod")) { if (!path.toString().endsWith(".frogmod")) {
LOGGER.info("File {} is not a frogmod file", path.toString()); LOGGER.info("File {} is not a frogmod file", path);
return false; return false;
} }
try (FileSystem fs = FileSystems.newFileSystem(path)) { try (FileSystem fs = FileSystems.newFileSystem(path)) {