Skip to content

Commit

Permalink
Workarround adventure breaking translatable comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablete1234 committed Aug 21, 2023
1 parent d16cf73 commit 2a2f6d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/main/java/tc/oc/pgm/PGMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import tc.oc.pgm.tablist.MatchTabManager;
import tc.oc.pgm.util.FileUtils;
import tc.oc.pgm.util.bukkit.BukkitUtils;
import tc.oc.pgm.util.bukkit.ViaUtils;
import tc.oc.pgm.util.chunk.NullChunkGenerator;
import tc.oc.pgm.util.compatability.SportPaperListener;
import tc.oc.pgm.util.concurrent.BukkitExecutorService;
Expand Down Expand Up @@ -118,6 +119,8 @@ public void onEnable() {

// Sanity test PGM is running on a supported version before doing any work
NMSHacks.allocateEntityId();
// Fix before any audiences have the chance of creating
ViaUtils.removeViaChatFacet();

Permissions.registerAll();

Expand Down
20 changes: 20 additions & 0 deletions util/src/main/java/tc/oc/pgm/util/bukkit/ViaUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tc.oc.pgm.util.bukkit;

import com.viaversion.viaversion.api.Via;
import java.lang.reflect.Field;
import java.util.List;
import org.bukkit.entity.Player;

public class ViaUtils {
Expand Down Expand Up @@ -41,4 +43,22 @@ public static int getProtocolVersion(Player player) {
public static boolean isReady(Player player) {
return !enabled() || Via.getAPI().isInjected(player.getUniqueId());
}

/**
* Adventure has a ViaFacet$Chat class, which sends text using 1.16 format for support for hex
* codes. The issue is by doing that, it skips all translation layers from 1.8 to 1.16, including
* a needed rename for translated items to work. Removing this means hex colors would be
* restricted to the 16 colors even for 1.16 clients (pgm doesn't use them) but translations will
* be correct.
*/
public static void removeViaChatFacet() {
try {
Class<?> bukkitAudience = Class.forName("net.kyori.adventure.platform.bukkit.BukkitAudience");
Field f = bukkitAudience.getDeclaredField("CHAT");
f.setAccessible(true);
List<?> list = (List<?>) f.get(null);
list.removeIf(el -> el.getClass().getName().endsWith("ViaFacet$Chat"));
} catch (ReflectiveOperationException ignored) {
}
}
}

0 comments on commit 2a2f6d6

Please sign in to comment.