add back list capabilities to ModExtensionsImpl.runIfPresent
Some checks failed
Publish to snapshot maven / build (push) Failing after 1m15s
Some checks failed
Publish to snapshot maven / build (push) Failing after 1m15s
- format
This commit is contained in:
parent
cea4e8ea01
commit
3f53df3f83
|
@ -7,6 +7,7 @@ public class ModExtensionResolutionException extends Exception {
|
|||
|
||||
/**
|
||||
* Instantiate this exception
|
||||
*
|
||||
* @param message A message describing this exception
|
||||
*/
|
||||
public ModExtensionResolutionException(String message) {
|
||||
|
@ -15,6 +16,7 @@ public class ModExtensionResolutionException extends Exception {
|
|||
|
||||
/**
|
||||
* Instantiate this exception
|
||||
*
|
||||
* @param cause The cause of this exception
|
||||
*/
|
||||
public ModExtensionResolutionException(Throwable cause) {
|
||||
|
@ -23,6 +25,7 @@ public class ModExtensionResolutionException extends Exception {
|
|||
|
||||
/**
|
||||
* Instantiate this exception
|
||||
*
|
||||
* @param message A message describing this exception
|
||||
* @param cause The cause of this exception
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
/**
|
||||
* Represents dependencies declared by a mod at runtime.
|
||||
*
|
||||
* @see ModProperties
|
||||
* @see ModExtensions
|
||||
*/
|
||||
|
@ -30,7 +31,7 @@ public interface ModDependencies {
|
|||
/**
|
||||
* Dependency types to distinguish their variants.
|
||||
*/
|
||||
public enum Type {
|
||||
enum Type {
|
||||
/**
|
||||
* Depend on another mod
|
||||
*/
|
||||
|
|
|
@ -25,7 +25,6 @@ public interface ModExtensions {
|
|||
* @param modId The mod ID this extension is stored under
|
||||
* @param key The extension name to query
|
||||
* @param <T> The type of the value of this extension
|
||||
*
|
||||
* @return The value of the extension, or null
|
||||
*/
|
||||
<T> T get(String modId, String key);
|
||||
|
@ -37,7 +36,6 @@ public interface ModExtensions {
|
|||
* @param key The extension name to query
|
||||
* @param defaultValue A default value
|
||||
* @param <T> The type of the value of this extension
|
||||
*
|
||||
* @return The value of the extension, or the default value if it isn't present
|
||||
*/
|
||||
<T> T getOrDefault(String modId, String key, T defaultValue);
|
||||
|
@ -67,7 +65,6 @@ public interface ModExtensions {
|
|||
* @param type The class type of the extension (The class the extension class is extending/implementing)
|
||||
* @param action The action to run on the newly retrieved instance of the provided class
|
||||
* @param <T> The type of the class
|
||||
*
|
||||
* @throws ModExtensionResolutionException If the reference could not be resolved
|
||||
*/
|
||||
<T> void runIfPresent(String modId, String key, Class<T> type, Consumer<T> action) throws ModExtensionResolutionException;
|
||||
|
|
|
@ -4,9 +4,8 @@ import java.nio.file.Path;
|
|||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import dev.frogmc.frogloader.impl.mod.ModDependenciesImpl;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A mod's properties. This class represents a mod at runtime.
|
||||
|
|
|
@ -7,8 +7,9 @@ import org.jetbrains.annotations.NotNull;
|
|||
/**
|
||||
* A plugin responsible for loading a game.
|
||||
* Only one of these may be loaded at a time.
|
||||
* @see FrogLoader
|
||||
*
|
||||
* @see ModProvider
|
||||
* @see FrogLoader
|
||||
*/
|
||||
public interface GamePlugin {
|
||||
/**
|
||||
|
@ -21,6 +22,7 @@ public interface GamePlugin {
|
|||
/**
|
||||
* Whether this plugin is applicable to be loaded in the current environment.
|
||||
* Only one plugin may be applicable at a time.
|
||||
*
|
||||
* @return Whether this plugin is applicable to be loaded
|
||||
*/
|
||||
default boolean isApplicable() {
|
||||
|
@ -29,6 +31,7 @@ public interface GamePlugin {
|
|||
|
||||
/**
|
||||
* Initialize this plugin.
|
||||
*
|
||||
* @param loader The loader currently loading this plugin
|
||||
* @throws Exception If an exception occurs during initialization. It will be handled by the loader.
|
||||
*/
|
||||
|
@ -37,6 +40,7 @@ public interface GamePlugin {
|
|||
|
||||
/**
|
||||
* Queries the version of the game of this plugin.
|
||||
*
|
||||
* @return The version of the game loaded by this plugin
|
||||
*/
|
||||
@NotNull
|
||||
|
@ -44,6 +48,7 @@ public interface GamePlugin {
|
|||
|
||||
/**
|
||||
* Get the mod embodying the game loaded by this plugin.
|
||||
*
|
||||
* @return A mod for the currently loaded game. May be null if no such mod shall be added.
|
||||
*/
|
||||
default ModProperties getGameMod() {
|
||||
|
|
|
@ -6,11 +6,12 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
import dev.frogmc.frogloader.api.FrogLoader;
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
|
||||
/**
|
||||
* A provider for mods to be loaded.
|
||||
*
|
||||
* @see FrogLoader
|
||||
* @see GamePlugin
|
||||
* @see ModProperties
|
||||
|
@ -19,12 +20,14 @@ public interface ModProvider {
|
|||
|
||||
/**
|
||||
* Get the ID of this provider. Mods will be stored separated by their provider ID.
|
||||
*
|
||||
* @return The ID of this provider
|
||||
*/
|
||||
String id();
|
||||
|
||||
/**
|
||||
* The directory to search in for mods. This will be resolved relative to the game directory.
|
||||
*
|
||||
* @return The name of the mods directory, relative to the game directory
|
||||
*/
|
||||
default String loadDirectory() {
|
||||
|
@ -33,6 +36,7 @@ public interface ModProvider {
|
|||
|
||||
/**
|
||||
* Whether this provider is applicable to load in the current environment.
|
||||
*
|
||||
* @return Whether this provider is applicable to load
|
||||
*/
|
||||
default boolean isApplicable() {
|
||||
|
@ -41,6 +45,7 @@ public interface ModProvider {
|
|||
|
||||
/**
|
||||
* Whether a mod file is valid to be loaded by this provider.
|
||||
*
|
||||
* @param path The path to validate
|
||||
* @return Whether this path is valid to be loaded by this provider
|
||||
* @see #isDirectoryApplicable(Path)
|
||||
|
@ -53,6 +58,7 @@ public interface ModProvider {
|
|||
/**
|
||||
* Whether a directory (inside the path declared by this provider's mod directory) is valid to be queried for mods
|
||||
* to be loaded by this provider.
|
||||
*
|
||||
* @param path The directory to be validated
|
||||
* @return Whether this directory should be traversed further
|
||||
* @see #loadDirectory()
|
||||
|
@ -64,6 +70,7 @@ public interface ModProvider {
|
|||
|
||||
/**
|
||||
* This method will be invoked just before the game is launched. It may be used for a pre-launch entrypoint for mods.
|
||||
*
|
||||
* @param mods The mods loaded by this provider
|
||||
* @throws Exception If an exception occurs during pre-launch. It will be handled by the loader.
|
||||
*/
|
||||
|
|
|
@ -59,20 +59,6 @@ public class LoaderGui extends JFrame {
|
|||
add(this.actions, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
public void setHeader(String text) {
|
||||
this.header.setText(text);
|
||||
}
|
||||
|
||||
public void addTab(String name, Component component) {
|
||||
this.tabbedPane.add(name, component);
|
||||
}
|
||||
|
||||
public void addAction(String label, ActionListener listener) {
|
||||
var button = new JButton(label);
|
||||
button.addActionListener(listener);
|
||||
this.actions.add(button, this.actions.getComponentCount() - 2);
|
||||
}
|
||||
|
||||
public static void execUnfulfilledDep(Path reportPath, ModDependencyResolver.UnfulfilledDependencyException ex, boolean keepRunning) {
|
||||
exec(gui -> {
|
||||
int count = ex.getDependencies().size();
|
||||
|
@ -135,4 +121,18 @@ public class LoaderGui extends JFrame {
|
|||
System.exit(0);
|
||||
}
|
||||
|
||||
public void setHeader(String text) {
|
||||
this.header.setText(text);
|
||||
}
|
||||
|
||||
public void addTab(String name, Component component) {
|
||||
this.tabbedPane.add(name, component);
|
||||
}
|
||||
|
||||
public void addAction(String label, ActionListener listener) {
|
||||
var button = new JButton(label);
|
||||
button.addActionListener(listener);
|
||||
this.actions.add(button, this.actions.getComponentCount() - 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,13 +17,11 @@ import org.spongepowered.asm.service.IPropertyKey;
|
|||
public class FrogLauncher {
|
||||
|
||||
public static final int ASM_VERSION = Opcodes.ASM9;
|
||||
private static final Map<IPropertyKey, Object> globalProperties = new HashMap<>();
|
||||
@Getter
|
||||
private static FrogLauncher instance;
|
||||
@Getter
|
||||
private final MixinClassLoader targetClassLoader;
|
||||
|
||||
private static final Map<IPropertyKey, Object> globalProperties = new HashMap<>();
|
||||
|
||||
@Getter
|
||||
private final Env env;
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@ public interface AsmTransformer {
|
|||
AccessWidener::processClass
|
||||
);
|
||||
|
||||
ClassVisitor transform(ClassReader reader, ClassVisitor cv, String name);
|
||||
|
||||
static byte[] transform(byte[] clazz, String name) {
|
||||
ClassReader reader = new ClassReader(clazz);
|
||||
ClassWriter writer = new ClassWriter(0);
|
||||
|
@ -28,4 +26,6 @@ public interface AsmTransformer {
|
|||
reader.accept(cv, 0);
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
ClassVisitor transform(ClassReader reader, ClassVisitor cv, String name);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package dev.frogmc.frogloader.impl.mod;
|
|||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import dev.frogmc.frogloader.api.mod.ModExtensions;
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
import dev.frogmc.frogloader.impl.SemVerParseException;
|
||||
|
||||
|
|
|
@ -4,19 +4,14 @@ import java.lang.invoke.MethodHandle;
|
|||
import java.lang.invoke.MethodHandleProxies;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import dev.frogmc.frogloader.api.exception.ModExtensionResolutionException;
|
||||
import dev.frogmc.frogloader.api.mod.ModExtensions;
|
||||
|
@ -55,14 +50,23 @@ public class ModExtensionsImpl implements ModExtensions {
|
|||
action.accept((T) value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> void runIfPresent(String modId, String key, Class<T> type, Consumer<T> action)
|
||||
throws ModExtensionResolutionException {
|
||||
String s = get(modId, key);
|
||||
Object o = get(modId, key);
|
||||
|
||||
if (s == null)
|
||||
if (o == null)
|
||||
return;
|
||||
|
||||
List<String> items = new ArrayList<>();
|
||||
if (o instanceof String) {
|
||||
items.add((String) o);
|
||||
} else if (o instanceof Collection<?>) {
|
||||
items.addAll((Collection<? extends String>) o);
|
||||
}
|
||||
|
||||
for (String s : items) {
|
||||
T object;
|
||||
if (s.contains("::")) {
|
||||
String[] parts = s.split("::", 2);
|
||||
|
@ -94,6 +98,7 @@ public class ModExtensionsImpl implements ModExtensions {
|
|||
action.accept(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object handleReference(Class<?> owner, Class<?> type, String name)
|
||||
throws ModExtensionResolutionException, IllegalAccessException {
|
||||
|
|
|
@ -8,16 +8,13 @@ import java.nio.file.FileSystems;
|
|||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import com.electronwill.nightconfig.core.file.FileNotFoundAction;
|
||||
import com.electronwill.nightconfig.toml.TomlParser;
|
||||
|
||||
import dev.frogmc.frogloader.api.mod.ModDependencies;
|
||||
import dev.frogmc.frogloader.api.mod.ModExtensions;
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
import dev.frogmc.frogloader.api.mod.SemVer;
|
||||
import dev.frogmc.frogloader.impl.SemVerParseException;
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.util.stream.Collectors;
|
|||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.frogmc.frogloader.api.FrogLoader;
|
||||
import dev.frogmc.frogloader.api.mod.ModExtensions;
|
||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||
import dev.frogmc.frogloader.api.plugin.GamePlugin;
|
||||
import dev.frogmc.frogloader.impl.FrogLoaderImpl;
|
||||
|
@ -37,12 +36,12 @@ public class MinecraftGamePlugin implements GamePlugin {
|
|||
|
||||
protected static final String CALAMUS_META_URL = "https://meta.ornithemc.net/v3/versions/gen2/intermediary/%s";
|
||||
protected static final String CALAMUS_MAVEN_URL = "https://maven.ornithemc.net/releases/%s";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("Plugin/Minecraft");
|
||||
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;
|
||||
|
@ -144,7 +143,8 @@ public class MinecraftGamePlugin implements GamePlugin {
|
|||
try {
|
||||
mappings = MojmapProvider.get(version, remappedGamePath.resolveSibling("client-" + version + ".txt"))
|
||||
.flattenData().reverse();
|
||||
} catch (NullPointerException e) { // NPE is only thrown if the mappings for this version can't be found
|
||||
} catch (
|
||||
NullPointerException e) { // NPE is only thrown if the mappings for this version can't be found
|
||||
LOGGER.info("Mojmap is not available for version {}, using ornithe's calamus as a fallback!", version);
|
||||
Path file = remappedGamePath.resolveSibling("calamus-" + version + ".tiny");
|
||||
if (!Files.exists(file)) {
|
||||
|
|
Loading…
Reference in a new issue