Skip to content

Commit

Permalink
fix(bungee): use bungee's gson instance on adventure serializer
Browse files Browse the repository at this point in the history
Fixes #371
  • Loading branch information
diogotcorreia committed Dec 24, 2023
1 parent 9219770 commit 16a1f9e
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package com.rexcantor64.triton.bungeecord.utils;

import com.google.gson.Gson;
import com.rexcantor64.triton.Triton;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;

/**
* Utilities for {@link BaseComponent BaseComponents}.
*
* @since 4.0.0
*/
public class BaseComponentUtils {

static {
// I hate this
// https://github.com/KyoriPowered/adventure-platform/blob/36ab6311d9023a4f67d2db6a2e057d9ee3f8a8a7/platform-bungeecord/src/main/java/net/kyori/adventure/platform/bungeecord/BungeeAudiencesImpl.java#L63-L70
try {
final Field gsonField = ProxyServer.getInstance().getClass().getDeclaredField("gson");
gsonField.setAccessible(true);
final Gson gson = (Gson) gsonField.get(ProxyServer.getInstance());
BungeeComponentSerializer.inject(gson);
} catch (final Throwable error) {
Triton.get().getLogger().logError(error, "Failed to inject ProxyServer gson");
}
}

/**
* Convert {@link BaseComponent} to a {@link Component}.
*
Expand Down

0 comments on commit 16a1f9e

Please sign in to comment.