3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Shade relocated adventure without breaking native platform usage

Dieser Commit ist enthalten in:
KennyTV 2021-02-28 12:14:46 +01:00 committet von Nassim
Ursprung b84bc7668a
Commit ec188db247
7 geänderte Dateien mit 45 neuen und 24 gelöschten Zeilen

29
adventure/build.gradle.kts Normale Datei
Datei anzeigen

@ -0,0 +1,29 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
// Shade and relocate adventure in an extra module, so that common/the rest can directly depend on a
// relocated adventure without breaking native platform's adventure usage with project wide relocation
apply<ShadowPlugin>()
tasks {
withType<ShadowJar> {
relocate("net.kyori", "us.myles.viaversion.libs.kyori")
}
getByName("build") {
dependsOn(withType<ShadowJar>())
}
}
dependencies {
api("net.kyori", "adventure-api", Versions.adventure) {
exclude("org.checkerframework")
}
api("net.kyori", "adventure-text-serializer-gson", Versions.adventure) {
exclude("net.kyori", "adventure-api")
exclude("net.kyori", "adventure-bom")
exclude("com.google.code.gson", "gson")
}
api("net.kyori", "adventure-text-serializer-legacy", Versions.adventure) {
exclude("net.kyori", "adventure-api")
exclude("net.kyori", "adventure-bom")
}
}

Datei anzeigen

@ -33,7 +33,6 @@ private fun ShadowJar.configureRelocations() {
relocate("com.google.gson", "us.myles.viaversion.libs.gson") relocate("com.google.gson", "us.myles.viaversion.libs.gson")
relocate("com.github.steveice10.opennbt", "us.myles.viaversion.libs.opennbt") relocate("com.github.steveice10.opennbt", "us.myles.viaversion.libs.opennbt")
relocate("it.unimi.dsi.fastutil", "us.myles.viaversion.libs.fastutil") relocate("it.unimi.dsi.fastutil", "us.myles.viaversion.libs.fastutil")
relocate("net.kyori", "us.myles.viaversion.libs.kyori")
} }
private fun ShadowJar.configureExcludes() { private fun ShadowJar.configureExcludes() {

Datei anzeigen

@ -8,23 +8,11 @@ blossom {
} }
dependencies { dependencies {
api(project(":adventure", "shadow"))
api("it.unimi.dsi", "fastutil", Versions.fastUtil) api("it.unimi.dsi", "fastutil", Versions.fastUtil)
api("com.github.steveice10", "opennbt", Versions.openNBT) api("com.github.steveice10", "opennbt", Versions.openNBT)
api("com.google.code.gson", "gson", Versions.gson) api("com.google.code.gson", "gson", Versions.gson)
api("net.kyori", "adventure-api", Versions.adventure) {
exclude("org.checkerframework")
}
api("net.kyori", "adventure-text-serializer-gson", Versions.adventure) {
exclude("net.kyori", "adventure-api")
exclude("net.kyori", "adventure-bom")
exclude("com.google.code.gson", "gson")
}
api("net.kyori", "adventure-text-serializer-legacy", Versions.adventure) {
exclude("net.kyori", "adventure-api")
exclude("net.kyori", "adventure-bom")
}
compileOnlyApi("org.yaml", "snakeyaml", Versions.snakeYaml) compileOnlyApi("org.yaml", "snakeyaml", Versions.snakeYaml)
compileOnlyApi("io.netty", "netty-all", Versions.netty) compileOnlyApi("io.netty", "netty-all", Versions.netty)
compileOnlyApi("com.google.guava", "guava", Versions.guava) compileOnlyApi("com.google.guava", "guava", Versions.guava)

Datei anzeigen

@ -2,13 +2,13 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.rewriters.ComponentRewriter; import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ComponentRewriter1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ComponentRewriter1_13;
import us.myles.viaversion.libs.kyori.adventure.text.Component;
import us.myles.viaversion.libs.kyori.adventure.text.format.TextDecoration;
import us.myles.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import us.myles.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
public class ChatRewriter { public class ChatRewriter {
private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter1_13(); private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter1_13();
@ -18,6 +18,8 @@ public class ChatRewriter {
if (itemData) { if (itemData) {
builder.decoration(TextDecoration.ITALIC, false); builder.decoration(TextDecoration.ITALIC, false);
} }
// Not used for chat messages, so no need for url extraction
builder.append(LegacyComponentSerializer.legacySection().deserialize(message)); builder.append(LegacyComponentSerializer.legacySection().deserialize(message));
}); });
return GsonComponentSerializer.gson().serialize(component); return GsonComponentSerializer.gson().serialize(component);

Datei anzeigen

@ -1,5 +1,7 @@
rootProject.name = "viaversion-parent" rootProject.name = "viaversion-parent"
include("adventure")
setupViaSubproject("common") setupViaSubproject("common")
setupViaSubproject("bukkit") setupViaSubproject("bukkit")
setupViaSubproject("bukkit-legacy") setupViaSubproject("bukkit-legacy")

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.inject.Inject; import com.google.inject.Inject;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
import org.spongepowered.api.config.DefaultConfig; import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
@ -32,6 +31,7 @@ import us.myles.ViaVersion.sponge.platform.SpongeViaLoader;
import us.myles.ViaVersion.sponge.util.LoggerWrapper; import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import us.myles.ViaVersion.util.VersionInfo; import us.myles.ViaVersion.util.VersionInfo;
import us.myles.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -54,6 +54,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
@DefaultConfig(sharedRoot = false) @DefaultConfig(sharedRoot = false)
private File spongeConfig; private File spongeConfig;
public static final LegacyComponentSerializer COMPONENT_SERIALIZER = LegacyComponentSerializer.builder().character('§').extractUrls().build();
private final ViaConnectionManager connectionManager = new ViaConnectionManager(); private final ViaConnectionManager connectionManager = new ViaConnectionManager();
private final SpongeViaAPI api = new SpongeViaAPI(); private final SpongeViaAPI api = new SpongeViaAPI();
private SpongeViaConfig conf; private SpongeViaConfig conf;
@ -169,8 +170,8 @@ public class SpongePlugin implements ViaPlatform<Player> {
@Override @Override
public void sendMessage(UUID uuid, String message) { public void sendMessage(UUID uuid, String message) {
String serialized = LegacyComponentSerializer.legacySection().serialize(LegacyComponentSerializer.legacySection().deserialize(message)); String serialized = SpongePlugin.COMPONENT_SERIALIZER.serialize(SpongePlugin.COMPONENT_SERIALIZER.deserialize(message));
game.getServer().getPlayer(uuid).ifPresent(player -> player.sendMessage(TextSerializers.JSON.deserialize(serialized))); // Hacky way to fix links //TODO ?? game.getServer().getPlayer(uuid).ifPresent(player -> player.sendMessage(TextSerializers.JSON.deserialize(serialized))); // Hacky way to fix links
} }
@Override @Override

Datei anzeigen

@ -1,9 +1,9 @@
package us.myles.ViaVersion.sponge.commands; package us.myles.ViaVersion.sponge.commands;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.util.Identifiable; import org.spongepowered.api.util.Identifiable;
import us.myles.ViaVersion.SpongePlugin;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import java.util.UUID; import java.util.UUID;
@ -22,8 +22,8 @@ public class SpongeCommandSender implements ViaCommandSender {
@Override @Override
public void sendMessage(String msg) { public void sendMessage(String msg) {
String serialized = LegacyComponentSerializer.legacySection().serialize(LegacyComponentSerializer.legacySection().deserialize(msg)); String serialized = SpongePlugin.COMPONENT_SERIALIZER.serialize(SpongePlugin.COMPONENT_SERIALIZER.deserialize(msg));
source.sendMessage(TextSerializers.JSON.deserialize(serialized)); // Hacky way to fix links //TODO ?? source.sendMessage(TextSerializers.JSON.deserialize(serialized)); // Hacky way to fix links
} }
@Override @Override