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();
|
||||
|
|
|
@ -3,13 +3,13 @@ package dev.frogmc.frogloader.api.plugin;
|
|||
import dev.frogmc.frogloader.api.FrogLoader;
|
||||
|
||||
public interface FrogGamePlugin {
|
||||
default void run() {
|
||||
}
|
||||
default void run() {
|
||||
}
|
||||
|
||||
default boolean isApplicable() {
|
||||
return false;
|
||||
}
|
||||
default boolean isApplicable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void init(FrogLoader loader) throws Exception {
|
||||
}
|
||||
default void init(FrogLoader loader) throws Exception {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,29 @@
|
|||
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();
|
||||
String id();
|
||||
|
||||
default String loadDirectory() {
|
||||
return "mods";
|
||||
}
|
||||
default String loadDirectory() {
|
||||
return "mods";
|
||||
}
|
||||
|
||||
default boolean isApplicable() {
|
||||
return false;
|
||||
}
|
||||
default boolean isApplicable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isFileApplicable(Path path) {
|
||||
return false;
|
||||
}
|
||||
default boolean isFileApplicable(Path path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void initMods(Collection<ModProperties> mods) {};
|
||||
default void initMods(Collection<ModProperties> mods) {
|
||||
}
|
||||
|
||||
default ModProperties loadMod(Path path) {
|
||||
return null;
|
||||
}
|
||||
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,145 +10,161 @@ 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);
|
||||
@Getter
|
||||
private static FrogLoaderImpl instance;
|
||||
@Getter
|
||||
private final String[] args;
|
||||
@Getter
|
||||
private final Env env;
|
||||
private final Logger LOGGER = LoggerFactory.getLogger("FrogLoader");
|
||||
public static final String MOD_FILE_EXTENSION = ".frogmod";
|
||||
private static final boolean DEV_ENV = Boolean.getBoolean(SystemProperties.DEVELOPMENT);
|
||||
@Getter
|
||||
private static FrogLoaderImpl instance;
|
||||
@Getter
|
||||
private final String[] args;
|
||||
@Getter
|
||||
private final Env env;
|
||||
private final Logger LOGGER = LoggerFactory.getLogger("FrogLoader");
|
||||
|
||||
// @Getter
|
||||
// private final List<FrogPlugin> plugins = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private final Collection<FrogGamePlugin> gamePlugins = new ArrayList<>();
|
||||
@Getter
|
||||
private final Collection<FrogGamePlugin> gamePlugins = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private final Collection<FrogModProvider> modProviders = new ArrayList<>();
|
||||
@Getter
|
||||
private final Collection<FrogModProvider> modProviders = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private final Path gameDir, configDir, modsDir;
|
||||
@Getter
|
||||
private final Path gameDir, configDir, modsDir;
|
||||
|
||||
@Getter
|
||||
private final MixinClassLoader classloader;
|
||||
@Getter
|
||||
private final MixinClassLoader classloader;
|
||||
|
||||
@Getter
|
||||
private final Gson gson = new Gson();
|
||||
@Getter
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
// Map<Provider ID, Map<Mod ID, ModProperties>>
|
||||
private Map<String, Map<String, ModProperties>> mods = new HashMap<>();
|
||||
// private Map<String, ModProperties> mods;
|
||||
private Collection<String> modIds = new ArrayList<>();
|
||||
// Map<Provider ID, Map<Mod ID, ModProperties>>
|
||||
private final Map<String, Map<String, ModProperties>> mods = new HashMap<>();
|
||||
// private Map<String, ModProperties> mods;
|
||||
private Collection<String> modIds = new ArrayList<>();
|
||||
|
||||
|
||||
private FrogLoaderImpl(String[] args, Env env) {
|
||||
instance = this;
|
||||
this.classloader = (MixinClassLoader) this.getClass().getClassLoader();
|
||||
this.args = args;
|
||||
this.env = env;
|
||||
private FrogLoaderImpl(String[] args, Env env) {
|
||||
instance = this;
|
||||
this.classloader = (MixinClassLoader) this.getClass().getClassLoader();
|
||||
this.args = args;
|
||||
this.env = env;
|
||||
|
||||
gameDir = Paths.get(getArgumentOrElse("gameDir", "."));
|
||||
configDir = gameDir.resolve("config");
|
||||
modsDir = gameDir.resolve("mods");
|
||||
gameDir = Paths.get(getArgumentOrElse("gameDir", "."));
|
||||
configDir = gameDir.resolve("config");
|
||||
modsDir = gameDir.resolve("mods");
|
||||
|
||||
try {
|
||||
Files.createDirectories(gameDir);
|
||||
Files.createDirectories(configDir);
|
||||
Files.createDirectories(modsDir);
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Failed to create essential directories ", e);
|
||||
}
|
||||
try {
|
||||
Files.createDirectories(gameDir);
|
||||
Files.createDirectories(configDir);
|
||||
Files.createDirectories(modsDir);
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Failed to create essential directories ", e);
|
||||
}
|
||||
|
||||
try {
|
||||
discoverGamePlugins();
|
||||
discoverModProviders();
|
||||
advanceMixinState();
|
||||
modIds = collectModIds();
|
||||
LOGGER.info(ModUtil.getModList(getMods()));
|
||||
LOGGER.info("Launching...");
|
||||
gamePlugins.forEach(FrogGamePlugin::run);
|
||||
modProviders.forEach(m -> m.initMods(mods.get(m.id()).values()));
|
||||
} catch (Throwable t) {
|
||||
LoaderGui.execReport(CrashReportGenerator.writeReport(t, getMods()), false);
|
||||
}
|
||||
}
|
||||
try {
|
||||
discoverGamePlugins();
|
||||
discoverModProviders();
|
||||
advanceMixinState();
|
||||
modIds = collectModIds();
|
||||
LOGGER.info(ModUtil.getModList(getMods()));
|
||||
LOGGER.info("Launching...");
|
||||
gamePlugins.forEach(FrogGamePlugin::run);
|
||||
modProviders.forEach(m -> m.initMods(mods.get(m.id()).values()));
|
||||
} catch (Throwable t) {
|
||||
LoaderGui.execReport(CrashReportGenerator.writeReport(t, getMods()), false);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void run(String[] args, Env env) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("Loader was started multiple times!");
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
public static void run(String[] args, Env env) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("Loader was started multiple times!");
|
||||
}
|
||||
|
||||
new FrogLoaderImpl(args, env);
|
||||
}
|
||||
new FrogLoaderImpl(args, env);
|
||||
}
|
||||
|
||||
private void advanceMixinState() {
|
||||
try {
|
||||
MethodHandle m = MethodHandles.privateLookupIn(MixinEnvironment.class, MethodHandles.lookup()).findStatic(MixinEnvironment.class, "gotoPhase", MethodType.methodType(void.class, MixinEnvironment.Phase.class));
|
||||
m.invoke(MixinEnvironment.Phase.INIT);
|
||||
m.invoke(MixinEnvironment.Phase.DEFAULT);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
private void advanceMixinState() {
|
||||
try {
|
||||
MethodHandle m = MethodHandles.privateLookupIn(MixinEnvironment.class, MethodHandles.lookup()).findStatic(MixinEnvironment.class, "gotoPhase", MethodType.methodType(void.class, MixinEnvironment.Phase.class));
|
||||
m.invoke(MixinEnvironment.Phase.INIT);
|
||||
m.invoke(MixinEnvironment.Phase.DEFAULT);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void discoverModProviders() {
|
||||
LOGGER.info("Discovering mod providers...");
|
||||
ServiceLoader<FrogModProvider> loader = ServiceLoader.load(FrogModProvider.class);
|
||||
loader.stream().map(ServiceLoader.Provider::get).forEach(p -> LOGGER.info("Found mod provider: " + p.getClass().getName()));
|
||||
FrogModProvider[] applicableProviders = ServiceLoader.load(FrogModProvider.class).stream().map(ServiceLoader.Provider::get).filter(FrogModProvider::isApplicable).toArray(FrogModProvider[]::new);
|
||||
private void discoverModProviders() {
|
||||
LOGGER.info("Discovering mod providers...");
|
||||
ServiceLoader<FrogModProvider> loader = ServiceLoader.load(FrogModProvider.class);
|
||||
loader.stream().map(ServiceLoader.Provider::get).forEach(p -> LOGGER.info("Found mod provider: " + p.getClass().getName()));
|
||||
FrogModProvider[] applicableProviders = ServiceLoader.load(FrogModProvider.class).stream().map(ServiceLoader.Provider::get).filter(FrogModProvider::isApplicable).toArray(FrogModProvider[]::new);
|
||||
|
||||
for (FrogModProvider plugin : applicableProviders) {
|
||||
try {
|
||||
LOGGER.info("Initialising mod provider: " + plugin.id());
|
||||
Map<String, ModProperties> modsFromProvider = new HashMap<>();
|
||||
Collection<Path> paths = Discovery.find(gameDir.resolve(plugin.loadDirectory()), p -> false, plugin::isFileApplicable);
|
||||
paths.forEach(p -> {
|
||||
LOGGER.info("Loading mod: " + p);
|
||||
try {
|
||||
ModProperties mod = plugin.loadMod(p);
|
||||
modsFromProvider.put(mod.id(), mod);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Error during mod initialisation: ", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
LOGGER.info("Loaded " + modsFromProvider.size() + " mods from provider: " + plugin.id());
|
||||
mods.put(plugin.id(), modsFromProvider);
|
||||
modIds.addAll(modsFromProvider.keySet());
|
||||
modProviders.add(plugin);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Error during plugin initialisation: ", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (FrogModProvider plugin : applicableProviders) {
|
||||
try {
|
||||
LOGGER.info("Initialising mod provider: " + plugin.id());
|
||||
Map<String, ModProperties> modsFromProvider = new HashMap<>();
|
||||
Collection<Path> paths = Discovery.find(gameDir.resolve(plugin.loadDirectory()), p -> false, plugin::isFileApplicable);
|
||||
paths.forEach(p -> {
|
||||
LOGGER.info("Loading mod: " + p);
|
||||
try {
|
||||
ModProperties mod = plugin.loadMod(p);
|
||||
modsFromProvider.put(mod.id(), mod);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Error during mod initialisation: ", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
LOGGER.info("Loaded " + modsFromProvider.size() + " mods from provider: " + plugin.id());
|
||||
mods.put(plugin.id(), modsFromProvider);
|
||||
modIds.addAll(modsFromProvider.keySet());
|
||||
modProviders.add(plugin);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Error during plugin initialisation: ", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void discoverGamePlugins() {
|
||||
LOGGER.info("Discovering game plugins...");
|
||||
ServiceLoader<FrogGamePlugin> loader = ServiceLoader.load(FrogGamePlugin.class);
|
||||
loader.stream().map(ServiceLoader.Provider::get).forEach(p -> LOGGER.info("Found game plugin: " + p.getClass().getName()));
|
||||
FrogGamePlugin[] applicablePlugins = ServiceLoader.load(FrogGamePlugin.class).stream().map(ServiceLoader.Provider::get).filter(FrogGamePlugin::isApplicable).toArray(FrogGamePlugin[]::new);
|
||||
if (applicablePlugins.length > 1) {
|
||||
throw new IllegalStateException("Multiple applicable game plugins found!");
|
||||
} else if (applicablePlugins.length == 0) {
|
||||
throw new IllegalStateException("No applicable game plugin found!");
|
||||
}
|
||||
private void discoverGamePlugins() {
|
||||
LOGGER.info("Discovering game plugins...");
|
||||
ServiceLoader<FrogGamePlugin> loader = ServiceLoader.load(FrogGamePlugin.class);
|
||||
loader.stream().map(ServiceLoader.Provider::get).forEach(p -> LOGGER.info("Found game plugin: " + p.getClass().getName()));
|
||||
FrogGamePlugin[] applicablePlugins = ServiceLoader.load(FrogGamePlugin.class).stream().map(ServiceLoader.Provider::get).filter(FrogGamePlugin::isApplicable).toArray(FrogGamePlugin[]::new);
|
||||
if (applicablePlugins.length > 1) {
|
||||
throw new IllegalStateException("Multiple applicable game plugins found!");
|
||||
} else if (applicablePlugins.length == 0) {
|
||||
throw new IllegalStateException("No applicable game plugin found!");
|
||||
}
|
||||
|
||||
for (FrogGamePlugin plugin : applicablePlugins) {
|
||||
try {
|
||||
plugin.init(this);
|
||||
gamePlugins.add(plugin);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Error during plugin initialisation: ", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (FrogGamePlugin plugin : applicablePlugins) {
|
||||
try {
|
||||
plugin.init(this);
|
||||
gamePlugins.add(plugin);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Error during plugin initialisation: ", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*private void discoverPlugins() {
|
||||
|
@ -186,48 +185,48 @@ public class FrogLoaderImpl implements FrogLoader {
|
|||
}
|
||||
}*/
|
||||
|
||||
public String getArgument(String name) {
|
||||
for (int i = 0; i < args.length - 1; i += 2) {
|
||||
if (args[i].equals("--" + name)) {
|
||||
return args[i + 1];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public String getArgument(String name) {
|
||||
for (int i = 0; i < args.length - 1; i += 2) {
|
||||
if (args[i].equals("--" + name)) {
|
||||
return args[i + 1];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getArgumentOrElse(String name, String other) {
|
||||
String res = getArgument(name);
|
||||
if (res.isEmpty()) {
|
||||
return other;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public String getArgumentOrElse(String name, String other) {
|
||||
String res = getArgument(name);
|
||||
if (res.isEmpty()) {
|
||||
return other;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDevelopment() {
|
||||
return DEV_ENV;
|
||||
}
|
||||
@Override
|
||||
public boolean isDevelopment() {
|
||||
return DEV_ENV;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModLoaded(String id) {
|
||||
return modIds.contains(id);
|
||||
}
|
||||
@Override
|
||||
public boolean isModLoaded(String id) {
|
||||
return modIds.contains(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ModProperties> getModProperties(String id) {
|
||||
return mods.values().stream().flatMap(m -> m.values().stream()).filter(m -> m.id().equals(id)).findFirst();
|
||||
}
|
||||
@Override
|
||||
public Optional<ModProperties> getModProperties(String id) {
|
||||
return mods.values().stream().flatMap(m -> m.values().stream()).filter(m -> m.id().equals(id)).findFirst();
|
||||
}
|
||||
|
||||
/*private Map<String, ModProperties> collectMods() {
|
||||
return plugins.stream().map(FrogPlugin::getMods).flatMap(Collection::stream).collect(Collectors.toMap(ModProperties::id, m -> m));
|
||||
}*/
|
||||
|
||||
private Collection<String> collectModIds() {
|
||||
return mods.values().stream().flatMap(m -> m.keySet().stream()).collect(Collectors.toSet());
|
||||
}
|
||||
private Collection<String> collectModIds() {
|
||||
return mods.values().stream().flatMap(m -> m.keySet().stream()).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ModProperties> getMods() {
|
||||
return mods.values().stream().map(Map::values).flatMap(Collection::stream).collect(Collectors.toSet());
|
||||
}
|
||||
@Override
|
||||
public Collection<ModProperties> getMods() {
|
||||
return mods.values().stream().map(Map::values).flatMap(Collection::stream).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,50 +1,50 @@
|
|||
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;
|
||||
private final JPanel actions;
|
||||
|
||||
public DependencyErrorEntry(String description, ModDependencyResolver.VersionRange range, Color background, @Nullable String icon) {
|
||||
super(new BorderLayout());
|
||||
public DependencyErrorEntry(String description, ModDependencyResolver.VersionRange range, Color background, @Nullable String icon) {
|
||||
super(new BorderLayout());
|
||||
|
||||
setBorder(BasicBorders.getInternalFrameBorder());
|
||||
setBorder(BasicBorders.getInternalFrameBorder());
|
||||
|
||||
Box text = Box.createVerticalBox();
|
||||
text.setBorder(BorderFactory.createEmptyBorder());
|
||||
Box text = Box.createVerticalBox();
|
||||
text.setBorder(BorderFactory.createEmptyBorder());
|
||||
|
||||
JTextPane desc = new JTextPane();
|
||||
desc.setContentType("text/html");
|
||||
desc.setEditable(false);
|
||||
desc.setBackground(background);
|
||||
desc.setText("<html>" + description.replace("<", "<").replace("\n", "<br>") + "</html>");
|
||||
text.add(desc);
|
||||
JTextPane desc = new JTextPane();
|
||||
desc.setContentType("text/html");
|
||||
desc.setEditable(false);
|
||||
desc.setBackground(background);
|
||||
desc.setText("<html>" + description.replace("<", "<").replace("\n", "<br>") + "</html>");
|
||||
text.add(desc);
|
||||
|
||||
add(text, BorderLayout.NORTH);
|
||||
add(text, BorderLayout.NORTH);
|
||||
|
||||
this.actions = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
add(this.actions, BorderLayout.SOUTH);
|
||||
this.actions = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
add(this.actions, BorderLayout.SOUTH);
|
||||
|
||||
if (icon != null) {
|
||||
URL location = getClass().getResource(icon);
|
||||
if (icon != null) {
|
||||
URL location = getClass().getResource(icon);
|
||||
|
||||
if (location != null)
|
||||
add(new JLabel(new ImageIcon(location)), BorderLayout.WEST);
|
||||
}
|
||||
}
|
||||
if (location != null)
|
||||
add(new JLabel(new ImageIcon(location)), BorderLayout.WEST);
|
||||
}
|
||||
}
|
||||
|
||||
public void addAction(String label, ActionListener listener) {
|
||||
var button = new JButton(label);
|
||||
button.addActionListener(listener);
|
||||
this.actions.add(button);
|
||||
}
|
||||
public void addAction(String label, ActionListener listener) {
|
||||
var button = new JButton(label);
|
||||
button.addActionListener(listener);
|
||||
this.actions.add(button);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
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) {
|
||||
getHorizontalScrollBar().setUnitIncrement(16);
|
||||
public BreakingDepPage(ModDependencyResolver.BreakingModException ex) {
|
||||
getHorizontalScrollBar().setUnitIncrement(16);
|
||||
getVerticalScrollBar().setUnitIncrement(16);
|
||||
|
||||
Box list = Box.createVerticalBox();
|
||||
|
||||
ex.getBreaks().forEach(entry -> {
|
||||
String description =
|
||||
"""
|
||||
Mod %s (%s) breaks with mod %s (%s) for versions matching range: %s (present: %s)
|
||||
Suggested Solution: Install %s of Mod %s (%s)
|
||||
""";
|
||||
ex.getBreaks().forEach(entry -> {
|
||||
String description =
|
||||
"""
|
||||
Mod %s (%s) breaks with mod %s (%s) for versions matching range: %s (present: %s)
|
||||
Suggested Solution: Install %s of Mod %s (%s)
|
||||
""";
|
||||
|
||||
description = description.formatted(
|
||||
entry.source().id(),
|
||||
entry.source().name(),
|
||||
entry.broken().id(),
|
||||
entry.broken().name(),
|
||||
entry.range().toString(" or "),
|
||||
entry.broken().version(),
|
||||
entry.range()
|
||||
.maxCompatible()
|
||||
.or(entry.range()::minCompatible)
|
||||
.map(Objects::toString)
|
||||
.map(s -> "0.0.0".equals(s) ? "any version" : "version " + s)
|
||||
.orElse("<unknown>"),
|
||||
entry.broken().id(),
|
||||
entry.broken().name()
|
||||
entry.source().id(),
|
||||
entry.source().name(),
|
||||
entry.broken().id(),
|
||||
entry.broken().name(),
|
||||
entry.range().toString(" or "),
|
||||
entry.broken().version(),
|
||||
entry.range()
|
||||
.maxCompatible()
|
||||
.or(entry.range()::minCompatible)
|
||||
.map(Objects::toString)
|
||||
.map(s -> "0.0.0".equals(s) ? "any version" : "version " + s)
|
||||
.orElse("<unknown>"),
|
||||
entry.broken().id(),
|
||||
entry.broken().name()
|
||||
);
|
||||
|
||||
DependencyErrorEntry result = new DependencyErrorEntry(
|
||||
description,
|
||||
entry.range(),
|
||||
list.getBackground(),
|
||||
entry.source().icon()
|
||||
description,
|
||||
entry.range(),
|
||||
list.getBackground(),
|
||||
entry.source().icon()
|
||||
);
|
||||
list.add(result);
|
||||
});
|
||||
setViewportView(list);
|
||||
list.add(result);
|
||||
});
|
||||
setViewportView(list);
|
||||
SwingUtilities.invokeLater(() -> getViewport().setViewPosition(new Point()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,24 +11,24 @@ import java.nio.file.Path;
|
|||
|
||||
public class ReportPage extends JScrollPane {
|
||||
|
||||
public ReportPage(Path reportPath) {
|
||||
getHorizontalScrollBar().setUnitIncrement(16);
|
||||
getVerticalScrollBar().setUnitIncrement(16);
|
||||
public ReportPage(Path reportPath) {
|
||||
getHorizontalScrollBar().setUnitIncrement(16);
|
||||
getVerticalScrollBar().setUnitIncrement(16);
|
||||
|
||||
JTextArea text = new JTextArea();
|
||||
text.setEditable(false);
|
||||
text.setTabSize(2);
|
||||
try {
|
||||
text.setText(Files.readString(reportPath, StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter printer = new PrintWriter(writer);
|
||||
printer.printf("Could not load contents of %s:%n", reportPath);
|
||||
e.printStackTrace(printer);
|
||||
}
|
||||
text.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));
|
||||
setViewportView(text);
|
||||
SwingUtilities.invokeLater(() -> getViewport().setViewPosition(new Point(0, 0)));
|
||||
}
|
||||
JTextArea text = new JTextArea();
|
||||
text.setEditable(false);
|
||||
text.setTabSize(2);
|
||||
try {
|
||||
text.setText(Files.readString(reportPath, StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter printer = new PrintWriter(writer);
|
||||
printer.printf("Could not load contents of %s:%n", reportPath);
|
||||
e.printStackTrace(printer);
|
||||
}
|
||||
text.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));
|
||||
setViewportView(text);
|
||||
SwingUtilities.invokeLater(() -> getViewport().setViewPosition(new Point(0, 0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
@ -39,13 +39,13 @@ public class UnfulfilledDepPage extends JScrollPane {
|
|||
}
|
||||
description.append("\nSuggested Solution: Install ")
|
||||
.append(
|
||||
entry
|
||||
.range()
|
||||
.maxCompatible()
|
||||
.or(entry.range()::minCompatible)
|
||||
.map(Objects::toString)
|
||||
.map(s -> "0.0.0".equals(s) ? "any version" : "version " + s)
|
||||
.orElse("<unknown>")
|
||||
entry
|
||||
.range()
|
||||
.maxCompatible()
|
||||
.or(entry.range()::minCompatible)
|
||||
.map(Objects::toString)
|
||||
.map(s -> "0.0.0".equals(s) ? "any version" : "version " + s)
|
||||
.orElse("<unknown>")
|
||||
)
|
||||
.append(" of ");
|
||||
if (entry.dependencyName() != null) {
|
||||
|
@ -55,10 +55,10 @@ public class UnfulfilledDepPage extends JScrollPane {
|
|||
}
|
||||
|
||||
DependencyErrorEntry result = new DependencyErrorEntry(
|
||||
description.toString(),
|
||||
entry.range(),
|
||||
list.getBackground(),
|
||||
entry.source().icon()
|
||||
description.toString(),
|
||||
entry.range(),
|
||||
list.getBackground(),
|
||||
entry.source().icon()
|
||||
);
|
||||
|
||||
if (entry.link() != null) {
|
||||
|
|
|
@ -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?
|
||||
|
@ -96,7 +96,7 @@ public class ModPropertiesReader {
|
|||
if (version == null || version.isEmpty())
|
||||
badProperties.add("frog.mod.version");
|
||||
else {
|
||||
try {
|
||||
try {
|
||||
semVer = SemVerImpl.parse(version);
|
||||
} catch (SemVerParseException e) {
|
||||
badProperties.add("frog.mod.version");
|
||||
|
@ -186,11 +186,11 @@ public class ModPropertiesReader {
|
|||
|
||||
public InvalidModPropertiesException(String id, Collection<Path> sources, Collection<String> invalid) {
|
||||
super(
|
||||
"Invalid properties for %s (%s) - invalid or missing values for: %s".formatted(
|
||||
Objects.requireNonNullElse(id, "<unknown>"),
|
||||
sources.stream().map(Path::toString).collect(Collectors.joining(", ")),
|
||||
String.join(", ", invalid)
|
||||
)
|
||||
"Invalid properties for %s (%s) - invalid or missing values for: %s".formatted(
|
||||
Objects.requireNonNullElse(id, "<unknown>"),
|
||||
sources.stream().map(Path::toString).collect(Collectors.joining(", ")),
|
||||
String.join(", ", invalid)
|
||||
)
|
||||
);
|
||||
this.invalid = invalid;
|
||||
}
|
||||
|
|
|
@ -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,113 +16,106 @@ 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[]{
|
||||
"net/minecraft/client/main/Main.class",
|
||||
"net/minecraft/client/MinecraftApplet.class",
|
||||
"net/minecraft/server/Main.class"
|
||||
};
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("Plugin/Minecraft");
|
||||
protected Path gamePath;
|
||||
protected String foundMainClass;
|
||||
private String version;
|
||||
protected final String[] MINECRAFT_CLASSES = new String[]{
|
||||
"net/minecraft/client/main/Main.class",
|
||||
"net/minecraft/client/MinecraftApplet.class",
|
||||
"net/minecraft/server/Main.class"
|
||||
};
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("Plugin/Minecraft");
|
||||
protected Path gamePath;
|
||||
protected String foundMainClass;
|
||||
private String version;
|
||||
|
||||
protected boolean checkLocation(Path jar) {
|
||||
if (!Files.exists(jar) || Files.isDirectory(jar)) {
|
||||
return false;
|
||||
}
|
||||
try (FileSystem fs = FileSystems.newFileSystem(jar)) {
|
||||
for (String n : MINECRAFT_CLASSES) {
|
||||
if (Files.exists(fs.getPath(n)) && n.contains(FrogLoaderImpl.getInstance().getEnv().getIdentifier())) {
|
||||
LOGGER.info("Found game: {}", jar);
|
||||
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){
|
||||
version = FrogLoaderImpl.getInstance().getArgument("version");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected boolean checkLocation(Path jar) {
|
||||
if (!Files.exists(jar) || Files.isDirectory(jar)) {
|
||||
return false;
|
||||
}
|
||||
try (FileSystem fs = FileSystems.newFileSystem(jar)) {
|
||||
for (String n : MINECRAFT_CLASSES) {
|
||||
if (Files.exists(fs.getPath(n)) && n.contains(FrogLoaderImpl.getInstance().getEnv().getIdentifier())) {
|
||||
LOGGER.info("Found game: {}", jar);
|
||||
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) {
|
||||
version = FrogLoaderImpl.getInstance().getArgument("version");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected Path findGame() {
|
||||
LOGGER.info("Locating game..");
|
||||
String jar = System.getProperty(SystemProperties.MINECRAFT_GAME_JAR);
|
||||
if (jar != null) {
|
||||
Path p = Paths.get(jar);
|
||||
if (checkLocation(p)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
protected Path findGame() {
|
||||
LOGGER.info("Locating game..");
|
||||
String jar = System.getProperty(SystemProperties.MINECRAFT_GAME_JAR);
|
||||
if (jar != null) {
|
||||
Path p = Paths.get(jar);
|
||||
if (checkLocation(p)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : System.getProperty("java.class.path", "").split(File.pathSeparator)) {
|
||||
Path p = Paths.get(s);
|
||||
if (checkLocation(p)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
LOGGER.warn("Could not locate game!");
|
||||
return null;
|
||||
}
|
||||
for (String s : System.getProperty("java.class.path", "").split(File.pathSeparator)) {
|
||||
Path p = Paths.get(s);
|
||||
if (checkLocation(p)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
LOGGER.warn("Could not locate game!");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable() {
|
||||
gamePath = findGame();
|
||||
return gamePath != null;
|
||||
}
|
||||
@Override
|
||||
public boolean isApplicable() {
|
||||
gamePath = findGame();
|
||||
return gamePath != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (foundMainClass != null) {
|
||||
LOGGER.info("Launching main class: {}", foundMainClass);
|
||||
Class<?> mainClass = Class.forName(foundMainClass);
|
||||
MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
|
||||
main.invoke((Object) FrogLoaderImpl.getInstance().getArgs());
|
||||
} else {
|
||||
LOGGER.warn("Failed to locate main class!");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (foundMainClass != null) {
|
||||
LOGGER.info("Launching main class: {}", foundMainClass);
|
||||
Class<?> mainClass = Class.forName(foundMainClass);
|
||||
MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
|
||||
main.invoke((Object) FrogLoaderImpl.getInstance().getArgs());
|
||||
} else {
|
||||
LOGGER.warn("Failed to locate main class!");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FrogLoader loader) throws Exception {
|
||||
if (gamePath == null) {
|
||||
throw new IllegalStateException("Game not found!");
|
||||
}
|
||||
Path remappedGamePath = loader.getGameDir().resolve(".frogmc/remappedJars").resolve(version).resolve("game-" + version + "-remapped.jar");
|
||||
@Override
|
||||
public void init(FrogLoader loader) throws Exception {
|
||||
if (gamePath == null) {
|
||||
throw new IllegalStateException("Game not found!");
|
||||
}
|
||||
Path remappedGamePath = loader.getGameDir().resolve(".frogmc/remappedJars").resolve(version).resolve("game-" + version + "-remapped.jar");
|
||||
|
||||
if (!Files.exists(remappedGamePath.getParent())) {
|
||||
try {
|
||||
Files.createDirectories(remappedGamePath.getParent());
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Failed to create directory", e);
|
||||
}
|
||||
}
|
||||
if (!Files.exists(remappedGamePath.getParent())) {
|
||||
try {
|
||||
Files.createDirectories(remappedGamePath.getParent());
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Failed to create directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!loader.isDevelopment()) {
|
||||
if (!Files.exists(remappedGamePath)) {
|
||||
Thyroxine.run(version, gamePath, remappedGamePath, true, false);
|
||||
}
|
||||
}
|
||||
if (!loader.isDevelopment()) {
|
||||
if (!Files.exists(remappedGamePath)) {
|
||||
Thyroxine.run(version, gamePath, remappedGamePath, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
var runtimePath = loader.isDevelopment() ? gamePath : remappedGamePath;
|
||||
FrogLoaderImpl.getInstance().getClassloader().addURL(runtimePath.toUri().toURL());
|
||||
}
|
||||
var runtimePath = loader.isDevelopment() ? gamePath : remappedGamePath;
|
||||
FrogLoaderImpl.getInstance().getClassloader().addURL(runtimePath.toUri().toURL());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,62 +1,61 @@
|
|||
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 {
|
||||
|
||||
Logger LOGGER = org.slf4j.LoggerFactory.getLogger("FrogModProvider");
|
||||
Logger LOGGER = org.slf4j.LoggerFactory.getLogger("FrogModProvider");
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "frogloader:frogmod";
|
||||
}
|
||||
@Override
|
||||
public String id() {
|
||||
return "frogloader:frogmod";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isApplicable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFileApplicable(Path path) {
|
||||
if (!path.toString().endsWith(".frogmod")) {
|
||||
LOGGER.info("File {} is not a frogmod file", path.toString());
|
||||
return false;
|
||||
}
|
||||
try (FileSystem fs = FileSystems.newFileSystem(path)) {
|
||||
return fs.getPath("frog.mod.toml").toFile().exists();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error while checking file {}", path, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean isFileApplicable(Path path) {
|
||||
if (!path.toString().endsWith(".frogmod")) {
|
||||
LOGGER.info("File {} is not a frogmod file", path);
|
||||
return false;
|
||||
}
|
||||
try (FileSystem fs = FileSystems.newFileSystem(path)) {
|
||||
return fs.getPath("frog.mod.toml").toFile().exists();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error while checking file {}", path, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModProperties loadMod(Path path) {
|
||||
try (FileSystem fs = FileSystems.newFileSystem(path)) {
|
||||
ModProperties prop = ModPropertiesReader.readFile(fs.getPath("frog.mod.toml").toUri().toURL()).orElseThrow(IOException::new);
|
||||
@Override
|
||||
public ModProperties loadMod(Path path) {
|
||||
try (FileSystem fs = FileSystems.newFileSystem(path)) {
|
||||
ModProperties prop = ModPropertiesReader.readFile(fs.getPath("frog.mod.toml").toUri().toURL()).orElseThrow(IOException::new);
|
||||
// prop.extensions().runIfPresent(PreLaunchExtension.ID, PreLaunchExtension.class, PreLaunchExtension::onPreLaunch);
|
||||
return prop;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return prop;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initMods(Collection<ModProperties> mods) {
|
||||
mods.forEach(mod -> {
|
||||
mod.extensions().runIfPresent(PreLaunchExtension.ID, PreLaunchExtension.class, PreLaunchExtension::onPreLaunch);
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void initMods(Collection<ModProperties> mods) {
|
||||
mods.forEach(mod -> {
|
||||
mod.extensions().runIfPresent(PreLaunchExtension.ID, PreLaunchExtension.class, PreLaunchExtension::onPreLaunch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ public class PlatformUtil {
|
|||
ProcessBuilder builder = new ProcessBuilder("bash", "-c", "wl-copy < " + path);
|
||||
builder.start();
|
||||
} else {
|
||||
String data = Files.readString(path, StandardCharsets.UTF_8);
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(data), null);
|
||||
String data = Files.readString(path, StandardCharsets.UTF_8);
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(data), null);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Failed to copy contents of {}:", path, e);
|
||||
|
|
Loading…
Reference in a new issue