Separate plugin types #10
|
@ -3,8 +3,8 @@ package dev.frogmc.frogloader.api.mod;
|
|||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
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);
|
||||
} else if (value instanceof Collection l){
|
||||
} else if (value instanceof Collection l) {
|
||||
((Collection<String>) l).forEach(c);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ public interface ModProperties {
|
|||
|
||||
/**
|
||||
* Get this mod's paths
|
||||
*
|
||||
* @return Where this mod is loaded from
|
||||
*/
|
||||
Collection<Path> paths();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package dev.frogmc.frogloader.api.plugin;
|
||||
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
|
||||
public interface FrogModProvider {
|
||||
String id();
|
||||
|
||||
|
@ -20,7 +20,8 @@ public interface FrogModProvider {
|
|||
return false;
|
||||
}
|
||||
|
||||
default void initMods(Collection<ModProperties> mods) {};
|
||||
default void initMods(Collection<ModProperties> mods) {
|
||||
}
|
||||
|
||||
default ModProperties loadMod(Path path) {
|
||||
return null;
|
||||
|
|
|
@ -2,7 +2,6 @@ package dev.frogmc.frogloader.api.plugin;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import dev.frogmc.frogloader.api.FrogLoader;
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
|
|
|
@ -1,22 +1,5 @@
|
|||
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.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
@ -27,6 +10,22 @@ import java.nio.file.Paths;
|
|||
import java.util.*;
|
||||
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 static final String MOD_FILE_EXTENSION = ".frogmod";
|
||||
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();
|
||||
|
||||
// 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 Collection<String> modIds = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public class LoaderGui extends JFrame {
|
|||
public static void execUnfulfilledDep(Path reportPath, ModDependencyResolver.UnfulfilledDependencyException ex, boolean keepRunning) {
|
||||
exec(gui -> {
|
||||
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));
|
||||
addReport(gui, reportPath);
|
||||
}, keepRunning);
|
||||
|
@ -85,7 +85,7 @@ public class LoaderGui extends JFrame {
|
|||
public static void execBreakingDep(Path reportPath, ModDependencyResolver.BreakingModException ex, boolean keepRunning) {
|
||||
exec(gui -> {
|
||||
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));
|
||||
addReport(gui, reportPath);
|
||||
}, keepRunning);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
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.plaf.basic.BasicBorders;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.URL;
|
||||
|
||||
import dev.frogmc.frogloader.impl.mod.ModDependencyResolver;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DependencyErrorEntry extends JPanel {
|
||||
|
||||
private final JPanel actions;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
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 java.awt.*;
|
||||
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 BreakingDepPage(ModDependencyResolver.BreakingModException ex) {
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
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 java.awt.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
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 UnfulfilledDepPage(ModDependencyResolver.UnfulfilledDependencyException ex) {
|
||||
|
|
|
@ -58,15 +58,15 @@ public class FrogLauncher {
|
|||
new FrogLauncher(args, env);
|
||||
}
|
||||
|
||||
public void putProperty(IPropertyKey key, Object value){
|
||||
public void putProperty(IPropertyKey key, Object value) {
|
||||
globalProperties.put(key, value);
|
||||
}
|
||||
|
||||
public Object getProperty(IPropertyKey key){
|
||||
public Object getProperty(IPropertyKey key) {
|
||||
return globalProperties.get(key);
|
||||
}
|
||||
|
||||
public Object getProperty(IPropertyKey key, Object defaultValue){
|
||||
public Object getProperty(IPropertyKey key, Object defaultValue) {
|
||||
return globalProperties.getOrDefault(key, defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,15 @@ public class FrogGlobalPropertyService implements IGlobalPropertyService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other){
|
||||
if (other instanceof IPropertyKey k){
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof IPropertyKey k) {
|
||||
return name.equals(k.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,7 +6,8 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
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.ModProperties;
|
||||
import dev.frogmc.frogloader.api.mod.SemVer;
|
||||
|
|
|
@ -49,8 +49,8 @@ public class ModPropertiesReader {
|
|||
CommentedConfig props = PARSER.parse(in);
|
||||
|
||||
String url = in.toString();
|
||||
Path source = Path.of(url.substring(url.lastIndexOf(":")+1).split("!")[0]).toAbsolutePath();
|
||||
if (!source.getFileName().toString().endsWith(".jar")){
|
||||
Path source = Path.of(url.substring(url.lastIndexOf(":") + 1).split("!")[0]).toAbsolutePath();
|
||||
if (!source.getFileName().toString().endsWith(".jar")) {
|
||||
source = source.getParent();
|
||||
} else {
|
||||
// TODO will this result in a memory leak?
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
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 dev.frogmc.frogloader.api.FrogLoader;
|
||||
import dev.frogmc.frogloader.api.plugin.FrogGamePlugin;
|
||||
|
@ -9,13 +16,6 @@ import dev.frogmc.thyroxine.Thyroxine;
|
|||
import org.slf4j.Logger;
|
||||
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 {
|
||||
|
||||
protected final String[] MINECRAFT_CLASSES = new String[]{
|
||||
|
@ -39,7 +39,7 @@ public class MinecraftGamePlugin implements FrogGamePlugin {
|
|||
foundMainClass = n.substring(0, n.length() - 6).replace("/", ".");
|
||||
try {
|
||||
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");
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
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.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
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")
|
||||
public class FrogmodModProvider implements FrogModProvider {
|
||||
|
||||
|
@ -31,7 +30,7 @@ public class FrogmodModProvider implements FrogModProvider {
|
|||
@Override
|
||||
public boolean isFileApplicable(Path path) {
|
||||
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;
|
||||
}
|
||||
try (FileSystem fs = FileSystems.newFileSystem(path)) {
|
||||
|
|
Loading…
Reference in a new issue