mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-19 09:27:43 +01:00
Fix right click sign editor color codes
This commit is contained in:
44
patches/server/0005-Add-component-util.patch
Normal file
44
patches/server/0005-Add-component-util.patch
Normal file
@@ -0,0 +1,44 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
||||
Date: Sat, 15 Aug 2020 03:49:33 -0500
|
||||
Subject: [PATCH] Add component util
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/pl3x/purpur/ComponentUtil.java b/src/main/java/net/pl3x/purpur/ComponentUtil.java
|
||||
new file mode 100644
|
||||
index 000000000..3f7bc68d1
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/ComponentUtil.java
|
||||
@@ -0,0 +1,32 @@
|
||||
+package net.pl3x.purpur;
|
||||
+
|
||||
+import net.md_5.bungee.api.chat.BaseComponent;
|
||||
+import net.md_5.bungee.api.chat.TextComponent;
|
||||
+import net.md_5.bungee.chat.ComponentSerializer;
|
||||
+import net.minecraft.server.IChatBaseComponent;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class ComponentUtil {
|
||||
+ public static String fromComponent(IChatBaseComponent component) {
|
||||
+ String json = "";
|
||||
+ try {
|
||||
+ int chop;
|
||||
+ List<IChatBaseComponent> siblings = component.getSiblings();
|
||||
+ if (siblings.size() > 0) chop = siblings.get(0).getChatModifier().getColor() == null ? 4 : 2;
|
||||
+ else chop = component.getChatModifier().getColor() == null ? 2 : 0;
|
||||
+ json = IChatBaseComponent.ChatSerializer.componentToJson(component);
|
||||
+ BaseComponent[] parsed = ComponentSerializer.parse(json);
|
||||
+ return TextComponent.toLegacyText(parsed).substring(chop);
|
||||
+ } catch (Exception e) {
|
||||
+ MinecraftServer.LOGGER.warn("There was a problem processing a chat component!");
|
||||
+ MinecraftServer.LOGGER.warn("We have fallen back to legacy colorless string to prevent real errors");
|
||||
+ MinecraftServer.LOGGER.warn("Please report this to Purpur!");
|
||||
+ MinecraftServer.LOGGER.warn("JSON: " + json);
|
||||
+ MinecraftServer.LOGGER.warn("The following error describes what went wrong:");
|
||||
+ e.printStackTrace();
|
||||
+ return component.getString();
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
Reference in New Issue
Block a user