| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | 
					
						
							|  |  |  | From: Aikar <aikar@aikar.co> | 
					
						
							|  |  |  | Date: Sun, 28 Jun 2020 19:08:41 -0400 | 
					
						
							|  |  |  | Subject: [PATCH] Improve Legacy Component serialization size | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Don't constantly send format: false for all formatting options when parent already | 
					
						
							|  |  |  | has it false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
 | 
					
						
							| 
									
										
										
										
											2024-06-13 16:45:27 +02:00
										 |  |  | index 5a9ddf71dc186c537a23083ac59434fb446a2140..70f207f016959402ff3cba9de924f906fea28110 100644
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  | --- a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
 | 
					
						
							|  |  |  | +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
 | 
					
						
							| 
									
										
										
										
											2024-06-13 16:45:27 +02:00
										 |  |  | @@ -48,6 +48,7 @@ public final class CraftChatMessage {
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  |          // Separate pattern with no group 3, new lines are part of previous string | 
					
						
							|  |  |  |          private static final Pattern INCREMENTAL_PATTERN_KEEP_NEWLINES = Pattern.compile("(" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + "[0-9a-fk-orx])|((?:(?:https?):\\/\\/)?(?:[-\\w_\\.]{2,}\\.[a-z]{2,4}.*?(?=[\\.\\?!,;:]?(?:[" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + " ]|$))))", Pattern.CASE_INSENSITIVE); | 
					
						
							|  |  |  |          // ChatColor.b does not explicitly reset, its more of empty | 
					
						
							| 
									
										
										
										
											2024-01-20 23:13:41 +01:00
										 |  |  | +        private static final Style EMPTY = Style.EMPTY.withItalic(false); // Paper - Improve Legacy Component serialization size
 | 
					
						
							| 
									
										
										
										
											2021-06-14 01:37:14 -07:00
										 |  |  |          private static final Style RESET = Style.EMPTY.withBold(false).withItalic(false).withUnderlined(false).withStrikethrough(false).withObfuscated(false); | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  |   | 
					
						
							|  |  |  |          private final List<Component> list = new ArrayList<Component>(); | 
					
						
							| 
									
										
										
										
											2024-06-13 16:45:27 +02:00
										 |  |  | @@ -69,6 +70,7 @@ public final class CraftChatMessage {
 | 
					
						
							| 
									
										
										
										
											2021-06-14 01:37:14 -07:00
										 |  |  |              Matcher matcher = (keepNewlines ? StringMessage.INCREMENTAL_PATTERN_KEEP_NEWLINES : StringMessage.INCREMENTAL_PATTERN).matcher(message); | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  |              String match = null; | 
					
						
							|  |  |  |              boolean needsAdd = false; | 
					
						
							| 
									
										
										
										
											2024-01-20 23:13:41 +01:00
										 |  |  | +            boolean hasReset = false; // Paper - Improve Legacy Component serialization size
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  |              while (matcher.find()) { | 
					
						
							|  |  |  |                  int groupId = 0; | 
					
						
							|  |  |  |                  while ((match = matcher.group(++groupId)) == null) { | 
					
						
							| 
									
										
										
										
											2024-06-13 16:45:27 +02:00
										 |  |  | @@ -114,7 +116,26 @@ public final class CraftChatMessage {
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  |                              throw new AssertionError("Unexpected message format"); | 
					
						
							|  |  |  |                          } | 
					
						
							|  |  |  |                      } else { // Color resets formatting | 
					
						
							| 
									
										
										
										
											2021-06-14 01:37:14 -07:00
										 |  |  | -                        this.modifier = StringMessage.RESET.withColor(format);
 | 
					
						
							| 
									
										
										
										
											2024-01-20 23:13:41 +01:00
										 |  |  | +                        // Paper start - Improve Legacy Component serialization size
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  | +                        Style previous = modifier;
 | 
					
						
							|  |  |  | +                        modifier = (!hasReset ? RESET : EMPTY).withColor(format);
 | 
					
						
							|  |  |  | +                        hasReset = true;
 | 
					
						
							|  |  |  | +                        if (previous.isBold()) {
 | 
					
						
							|  |  |  | +                            modifier = modifier.withBold(false);
 | 
					
						
							|  |  |  | +                        }
 | 
					
						
							|  |  |  | +                        if (previous.isItalic()) {
 | 
					
						
							|  |  |  | +                            modifier = modifier.withItalic(false);
 | 
					
						
							|  |  |  | +                        }
 | 
					
						
							|  |  |  | +                        if (previous.isObfuscated()) {
 | 
					
						
							| 
									
										
										
										
											2021-06-14 01:37:14 -07:00
										 |  |  | +                            modifier = modifier.withObfuscated(false);
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  | +                        }
 | 
					
						
							|  |  |  | +                        if (previous.isStrikethrough()) {
 | 
					
						
							| 
									
										
										
										
											2021-06-14 01:37:14 -07:00
										 |  |  | +                            modifier = modifier.withStrikethrough(false);
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  | +                        }
 | 
					
						
							|  |  |  | +                        if (previous.isUnderlined()) {
 | 
					
						
							| 
									
										
										
										
											2021-06-14 01:37:14 -07:00
										 |  |  | +                            modifier = modifier.withUnderlined(false);
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  | +                        }
 | 
					
						
							| 
									
										
										
										
											2024-01-20 23:13:41 +01:00
										 |  |  | +                        // Paper end - Improve Legacy Component serialization size
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:02:28 +02:00
										 |  |  |                      } | 
					
						
							|  |  |  |                      needsAdd = true; | 
					
						
							|  |  |  |                      break; |