Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mixins #106

Merged
merged 18 commits into from Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -25,3 +25,9 @@ hs_err_pid*.log
/.archive
# secrets
**.secret

#ModLauncher
logs/*

#Built Jar
ExciteBot*.jar
32 changes: 30 additions & 2 deletions build.gradle
@@ -1,5 +1,6 @@
plugins {
id 'java-library'
id 'com.github.johnrengelman.shadow' version "6.1.0"
}

repositories {
Expand All @@ -11,6 +12,12 @@ repositories {
maven {
url "https://libraries.minecraft.net"
}
maven {
url "https://repo.spongepowered.org/maven/"
}
maven {
url "https://files.minecraftforge.net/maven/"
}
}

dependencies {
Expand All @@ -25,17 +32,38 @@ dependencies {
exclude module: 'opus-java'
}
implementation 'com.mojang:brigadier:1.0.17'

implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'

//mixin requirements:
implementation 'cpw.mods:modlauncher:8.0.9'
implementation 'cpw.mods:grossjava9hacks:1.1.+'
implementation 'org.spongepowered:mixin:0.8.3-SNAPSHOT'
implementation 'com.google.guava:guava:21.0'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.7'
implementation group: 'org.ow2.asm', name: 'asm', version: '7.2'
implementation group: 'org.ow2.asm', name: 'asm-util', version: '7.2'
}


shadowJar {
mergeServiceFiles()
}

jar {
int i = 0;
String classpathVar = configurations.compileClasspath.collect { " libs/" + (i++==0?String.format("%0\$-50s", it.getName()):String.format("%0\$-62s", it.getName())) }.join(" ");
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'com.gamebuster19901.excite.Main'
'Class-Path': classpathVar,
'MixinConfigs': 'mixins.json',
'Main-Class': 'cpw.mods.modlauncher.Launcher',
'Specification-Version': 8.0
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/gamebuster19901/excite/Main.java
Expand Up @@ -3,10 +3,13 @@
import java.io.File;
import java.io.IOError;
import java.io.IOException;

import java.sql.SQLException;
import java.sql.SQLNonTransientConnectionException;

import java.time.Duration;
import java.time.Instant;

import java.util.Scanner;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.logging.Level;
Expand All @@ -23,6 +26,7 @@
import com.gamebuster19901.excite.bot.user.UnknownDiscordUser;
import com.gamebuster19901.excite.util.StacktraceUtil;
import com.gamebuster19901.excite.util.ThreadService;

import com.mysql.cj.exceptions.CJCommunicationsException;
import com.mysql.cj.exceptions.ConnectionIsClosedException;
import com.mysql.cj.jdbc.exceptions.CommunicationsException;
Expand All @@ -47,7 +51,6 @@ public class Main {

@SuppressWarnings("rawtypes")
public static void main(String[] args) throws InterruptedException, ClassNotFoundException, IOException, SQLException {

if(args.length % 2 != 0) {
throw new IllegalArgumentException("Must be started with an even number of arguments!");
}
Expand Down
@@ -0,0 +1,46 @@
package com.gamebuster19901.excite.launch;

import java.io.File;
import java.io.IOError;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.concurrent.Callable;

import cpw.mods.gross.Java9ClassLoaderUtil;
import cpw.mods.modlauncher.api.ILaunchHandlerService;
import cpw.mods.modlauncher.api.ITransformingClassLoader;
import cpw.mods.modlauncher.api.ITransformingClassLoaderBuilder;

public class ExciteLauncherService implements ILaunchHandlerService {

public ExciteLauncherService() {

}

@Override
public String name() {
return "excitebot";
}

@Override
public void configureTransformationClassLoader(ITransformingClassLoaderBuilder builder) {
for (final URL url : Java9ClassLoaderUtil.getSystemClassPathURLs()) {
try {
builder.addTransformationPath(new File(url.toURI()).toPath());
} catch (Throwable t) {
throw new IOError(new Error("Could not start ExciteLauncher service!", t));
}
}
}

@Override
public Callable<Void> launchService(String[] arguments, ITransformingClassLoader launchClassLoader) {
return () -> {
Class<?> mainClass = launchClassLoader.getInstance().loadClass("com.gamebuster19901.excite.Main");
final Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.invoke(null, new Object[] {arguments});
return null;
};
}

}
@@ -0,0 +1,21 @@
package com.gamebuster19901.excite.launch;

import org.spongepowered.asm.launch.platform.container.ContainerHandleModLauncher;
import org.spongepowered.asm.service.modlauncher.MixinServiceModLauncher;

public class ExciteMixinServiceModLauncher extends MixinServiceModLauncher {

@Override
public ContainerHandleModLauncher getPrimaryContainer() {
return new ExciteHandleModLauncher(this.getName());
}

private static final class ExciteHandleModLauncher extends ContainerHandleModLauncher {

public ExciteHandleModLauncher(String name) {
super(name);
}

}

}
@@ -0,0 +1 @@
com.gamebuster19901.excite.launch.ExciteLauncherService
@@ -0,0 +1 @@
com.gamebuster19901.excite.launch.ExciteMixinServiceModLauncher
11 changes: 11 additions & 0 deletions src/main/resources/mixins.json
@@ -0,0 +1,11 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.gamebuster19901.excite.mixin",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixinPriority": 1,
"mixins": [

]
}