aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-19 20:57:07 +0200
committerGitHub <noreply@github.com>2024-04-19 20:57:07 +0200
commit40309bc8acb7afb37bbc99d7a758c24ffd962b4c (patch)
treecfabc8d261d820ea63921bead05e20feb67f4a4f /src/main/java
parentf3b6288fed75eacede95627282cb9bfec73f0c9e (diff)
downloadskyhanni-40309bc8acb7afb37bbc99d7a758c24ffd962b4c.tar.gz
skyhanni-40309bc8acb7afb37bbc99d7a758c24ffd962b4c.tar.bz2
skyhanni-40309bc8acb7afb37bbc99d7a758c24ffd962b4c.zip
Backend: Add unimined build system (#1456)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java91
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt13
2 files changed, 4 insertions, 100 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java b/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java
index 1f1b0e1fe..eb4009ce5 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java
@@ -4,24 +4,13 @@ import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import java.util.stream.Stream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
public class SkyhanniMixinPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
-
}
@Override
@@ -31,7 +20,7 @@ public class SkyhanniMixinPlugin implements IMixinConfigPlugin {
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
- return false;
+ return true;
}
@Override
@@ -39,85 +28,9 @@ public class SkyhanniMixinPlugin implements IMixinConfigPlugin {
}
- public URL baseUrl(URL classUrl) {
- String string = classUrl.toString();
- if (classUrl.getProtocol().equals("jar")) {
- try {
- return new URL(string.substring(4).split("!")[0]);
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
- if (string.endsWith(".class")) {
- try {
- return new URL(string.replace("\\", "/")
- .replace(getClass().getCanonicalName().replace(".", "/") + ".class", ""));
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
- return classUrl;
- }
-
- String mixinBasePackage = "at.hannibal2.skyhanni.mixins.transformers.";
- String mixinBaseDir = mixinBasePackage.replace(".", "/");
-
- List<String> mixins = null;
-
- public void tryAddMixinClass(String className) {
- String norm = (className.endsWith(".class") ? className.substring(0, className.length() - ".class".length()) : className)
- .replace("\\", "/")
- .replace("/", ".");
- if (norm.startsWith(mixinBasePackage) && !norm.endsWith(".")) {
- mixins.add(norm.substring(mixinBasePackage.length()));
- }
- }
-
- public void walkDir(Path file) {
- System.out.println("Trying to find mixins from directory");
- try (Stream<Path> classes = Files.walk(file.resolve(mixinBaseDir))) {
- classes.map(it -> file.relativize(it).toString())
- .forEach(this::tryAddMixinClass);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
@Override
public List<String> getMixins() {
- if (mixins != null) return mixins;
- System.out.println("Trying to discover mixins");
- mixins = new ArrayList<>();
- URL classUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
- System.out.println("Found classes at " + classUrl);
- Path file;
- try {
- file = Paths.get(baseUrl(classUrl).toURI());
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
- System.out.println("Base directory found at " + file);
- if (Files.isDirectory(file)) {
- walkDir(file);
- } else {
- walkJar(file);
- }
- System.out.println("Found mixins: " + mixins);
-
- return mixins;
- }
-
- private void walkJar(Path file) {
- System.out.println("Trying to find mixins from jar file");
- try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(file))) {
- ZipEntry next;
- while ((next = zis.getNextEntry()) != null) {
- tryAddMixinClass(next.getName());
- zis.closeEntry();
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ return new ArrayList<>();
}
@Override
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
index 4022b382c..5de464872 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
@@ -11,9 +11,10 @@ import org.apache.logging.log4j.core.Filter
import org.apache.logging.log4j.core.LogEvent
import org.apache.logging.log4j.core.Logger
import org.apache.logging.log4j.core.LoggerContext
+import org.apache.logging.log4j.core.filter.AbstractFilter
import org.apache.logging.log4j.message.Message
-class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter {
+class MinecraftConsoleFilter(private val loggerConfigName: String) : AbstractFilter(Filter.Result.ACCEPT, Filter.Result.DENY) {
private val config get() = SkyHanniMod.feature.dev.minecraftConsoles
private val filterConfig get() = config.consoleFilter
@@ -35,8 +36,6 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter {
}
}
- // prevents error sending on every shutdown
- fun stop() {}
override fun filter(event: LogEvent?): Filter.Result {
if (event == null) return Filter.Result.ACCEPT
@@ -205,14 +204,6 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter {
}
}
- override fun getOnMismatch(): Filter.Result {
- return Filter.Result.DENY
- }
-
- override fun getOnMatch(): Filter.Result {
- return Filter.Result.ACCEPT
- }
-
override fun filter(
logger: Logger?,
level: Level?,