From b50530b4e7c5f072fd1bf90236e843385343b626 Mon Sep 17 00:00:00 2001 From: KrystilizeNevaDies <57762380+KrystilizeNevaDies@users.noreply.github.com> Date: Fri, 6 Nov 2020 00:36:45 +1000 Subject: [PATCH] Fix rgb byte overflow Fix rgb byte overflow: Changed from concatenation and logic to bitwise ops --- .../java/net/minestom/server/chat/ChatColor.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/minestom/server/chat/ChatColor.java b/src/main/java/net/minestom/server/chat/ChatColor.java index 73435bec4..a43e16f8f 100644 --- a/src/main/java/net/minestom/server/chat/ChatColor.java +++ b/src/main/java/net/minestom/server/chat/ChatColor.java @@ -263,19 +263,9 @@ public class ChatColor { code = codeName; } else { // RGB color - String redH = Integer.toHexString(red); - if (redH.length() == 1) - redH = "0" + redH; + int color = (red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF; - String greenH = Integer.toHexString(green); - if (greenH.length() == 1) - greenH = "0" + greenH; - - String blueH = Integer.toHexString(blue); - if (blueH.length() == 1) - blueH = "0" + blueH; - - code = redH + greenH + blueH; + code = "#"+Integer.toHexString(color); } return header + code + footer;