Fix the common module being relocated due to adventure
Making a single distributable jar with adventure is fun
This commit is contained in:
parent
f5636c082e
commit
15e3ba306c
5 changed files with 47 additions and 12 deletions
|
|
@ -25,8 +25,4 @@ processResources {
|
|||
|
||||
shadowJar {
|
||||
relocate 'org.bstats', dependencyDir + '.bstats'
|
||||
relocate 'net.kyori.adventure', rootDependencyDir + '.adventure'
|
||||
relocate 'net.kyori.examination', rootDependencyDir + '.examination'
|
||||
relocate 'net.frankheijden.serverutils.common', dependencyDir + '.su.common'
|
||||
relocate 'net.kyori.adventure.text.minimessage', dependencyDir + '.adventure.text.minimessage'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,4 @@ processResources {
|
|||
|
||||
shadowJar {
|
||||
relocate 'org.bstats', dependencyDir + '.bstats'
|
||||
relocate 'net.kyori.adventure', rootDependencyDir + '.adventure'
|
||||
relocate 'net.kyori.examination', rootDependencyDir + '.examination'
|
||||
relocate 'net.kyori.adventure.text.minimessage', dependencyDir + '.adventure.text.minimessage'
|
||||
relocate 'net.frankheijden.serverutils.common', dependencyDir + '.su.common'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ dependencies {
|
|||
|
||||
shadowJar {
|
||||
relocate 'org.bstats', dependencyDir + '.bstats'
|
||||
relocate 'net.frankheijden.serverutils.common', dependencyDir + '.su.common'
|
||||
relocate 'net.kyori.adventure.text.minimessage', dependencyDir + '.adventure.text.minimessage'
|
||||
}
|
||||
|
||||
blossom {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,38 @@ package net.frankheijden.serverutils.velocity.entities;
|
|||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
public class VelocityAudience extends ServerUtilsAudience<CommandSource> {
|
||||
|
||||
private static final GsonComponentSerializer serializer = GsonComponentSerializer.gson();
|
||||
private static Object deserializer;
|
||||
private static MethodHandle deserializeMethodHandle;
|
||||
private static MethodHandle sendMessageMethodHandle;
|
||||
|
||||
static {
|
||||
try {
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
@SuppressWarnings("LineLength")
|
||||
Class<?> deserializerClass = Class.forName("net.frankheijden.serverutils.dependencies.impl.adventure.text.serializer.gson.GsonComponentSerializer");
|
||||
deserializer = deserializerClass.getDeclaredMethod("gson").invoke(null);
|
||||
deserializeMethodHandle = lookup.unreflect(deserializerClass.getMethod("deserialize", Object.class));
|
||||
|
||||
Class<?> componentClass = Class.forName(
|
||||
new String(new char[]{'n', 'e', 't'}) + ".kyori.adventure.text.Component" // relocate is smart
|
||||
);
|
||||
sendMessageMethodHandle = lookup.unreflect(CommandSource.class.getMethod("sendMessage", componentClass));
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected VelocityAudience(Audience audience, CommandSource source) {
|
||||
super(audience, source);
|
||||
}
|
||||
|
|
@ -20,4 +47,15 @@ public class VelocityAudience extends ServerUtilsAudience<CommandSource> {
|
|||
public boolean hasPermission(String permission) {
|
||||
return source.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Component component) {
|
||||
// Shading in adventure is fun when making a single distributable jar...
|
||||
String serializedString = serializer.serialize(component);
|
||||
try {
|
||||
sendMessageMethodHandle.invoke(source, deserializeMethodHandle.invoke(deserializer, serializedString));
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
build.gradle
11
build.gradle
|
|
@ -76,6 +76,10 @@ subprojects {
|
|||
relocate 'cloud.commandframework', dependencyDir + '.cloud'
|
||||
relocate 'me.lucko.commodore', dependencyDir + '.commodore'
|
||||
relocate 'io.leangen.geantyref', dependencyDir + '.typetoken'
|
||||
relocate 'net.kyori.adventure', dependencyDir + '.adventure'
|
||||
relocate 'net.kyori.examination', dependencyDir + '.examination'
|
||||
relocate 'net.kyori.adventure.text.minimessage', dependencyDir + '.adventure.text.minimessage'
|
||||
relocate 'dev.frankheijden.minecraftreflection', dependencyDir + '.minecraftreflection'
|
||||
}
|
||||
|
||||
shadowJar.dependsOn checkstyleMain, checkstyleTest, test
|
||||
|
|
@ -90,11 +94,14 @@ dependencies {
|
|||
implementation project(path: ':Bukkit', configuration: 'shadow')
|
||||
implementation project(path: ':Bungee', configuration: 'shadow')
|
||||
implementation project(path: ':Velocity', configuration: 'shadow')
|
||||
implementation("net.kyori:adventure-text-serializer-gson:${rootProject.adventureVersion}") {
|
||||
exclude group: 'net.kyori', module: 'adventure-api'
|
||||
exclude group: 'com.google.code.gson', module: 'gson'
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate 'org.apache.commons.codec', dependencyDir + '.codec'
|
||||
relocate 'dev.frankheijden.minecraftreflection', dependencyDir + '.minecraftreflection'
|
||||
relocate 'net.kyori.adventure.text.serializer.gson', dependencyDir + '.impl.adventure.text.serializer.gson'
|
||||
archiveFileName = "${archiveBaseName.orNull}-${archiveVersion.orNull}.${archiveExtension.orNull}"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue