Fix adventure stuff
This commit is contained in:
		
							
								
								
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -73,9 +73,7 @@ | ||||
|                     <minimizeJar>true</minimizeJar> | ||||
|                     <artifactSet> | ||||
|                         <includes> | ||||
|                             <include>net.kyori:adventure-text-minimessage</include> | ||||
|                             <include>net.kyori:adventure-text-serializer-gson</include> | ||||
|                             <include>net.kyori:adventure-api</include> | ||||
|                             <include>net.kyori:*</include> | ||||
|                         </includes> | ||||
|                     </artifactSet> | ||||
|                     <relocations> | ||||
| @@ -100,7 +98,7 @@ | ||||
|         <asm.version>9.0</asm.version> | ||||
|         <lombok.version>1.18.16</lombok.version> | ||||
|         <protocollib.version>master-SNAPSHOT</protocollib.version> | ||||
|         <spigot.version>[1.16,]</spigot.version> | ||||
|         <spigot.version>[1.16,1.16.5]</spigot.version> | ||||
|         <junit.version>4.13.1</junit.version> | ||||
|         <paper-api.version>[1.16,]</paper-api.version> | ||||
|         <bungeecord-chat.version>1.12-SNAPSHOT</bungeecord-chat.version> | ||||
|   | ||||
| @@ -569,13 +569,8 @@ public class FlagWatcher { | ||||
|             } | ||||
|  | ||||
|             if (NmsVersion.v1_13.isSupported()) { | ||||
|                 Optional<WrappedChatComponent> optional; | ||||
|  | ||||
|                 if (DisguiseUtilities.hasAdventureTextSupport()) { | ||||
|                     optional = Optional.of(AdventureComponentConverter.fromComponent(DisguiseUtilities.getAdventureChat(name))); | ||||
|                 } else { | ||||
|                     optional = Optional.of(WrappedChatComponent.fromJson(ComponentSerializer.toString(DisguiseUtilities.getColoredChat(name)))); | ||||
|                 } | ||||
|                 Optional<WrappedChatComponent> optional = | ||||
|                         Optional.of(WrappedChatComponent.fromJson(DisguiseUtilities.serialize(DisguiseUtilities.getAdventureChat(name)))); | ||||
|  | ||||
|                 setData(MetaIndex.ENTITY_CUSTOM_NAME, optional); | ||||
|             } else { | ||||
|   | ||||
| @@ -39,7 +39,6 @@ import net.kyori.adventure.text.Component; | ||||
| import net.kyori.adventure.text.minimessage.MiniMessage; | ||||
| import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; | ||||
| import net.md_5.bungee.api.chat.BaseComponent; | ||||
| import net.md_5.bungee.api.chat.ClickEvent; | ||||
| import net.md_5.bungee.api.chat.TextComponent; | ||||
| import net.md_5.bungee.chat.ComponentSerializer; | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| @@ -219,29 +218,8 @@ public class DisguiseUtilities { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * This should return true every single time, except for when ProtocolLib isn't updated for AdventureComponentConverter | ||||
|      * | ||||
|      * The reason being is that we shade the adventure text library in the plugin | ||||
|      */ | ||||
|     public static boolean hasAdventureTextSupport() { | ||||
|         if (adventureTextSupport == null) { | ||||
|             try { | ||||
|                 adventureTextSupport = true; | ||||
|  | ||||
|                 // Force a test for support by actually trying to use it all | ||||
|                 BaseComponent[] test1 = ComponentSerializer.parse(GsonComponentSerializer.gson().serialize(getAdventureChat("<green>test"))); | ||||
|                 WrappedChatComponent test2 = AdventureComponentConverter.fromComponent(DisguiseUtilities.getAdventureChat("<green>test")); | ||||
|  | ||||
|                 if (test1 == null || test1.length == 0 || test2 == null) { | ||||
|                     adventureTextSupport = false; | ||||
|                 } | ||||
|             } catch (Throwable ex) { | ||||
|                 adventureTextSupport = false; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return adventureTextSupport; | ||||
|     public static String serialize(Component component) { | ||||
|         return GsonComponentSerializer.gson().serialize(component); | ||||
|     } | ||||
|  | ||||
|     public static void doSkinUUIDWarning(CommandSender sender) { | ||||
| @@ -2549,110 +2527,12 @@ public class DisguiseUtilities { | ||||
|         return MiniMessage.get().parse(message); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Modification of TextComponent.fromLegacyText | ||||
|      */ | ||||
|     public static BaseComponent[] getColoredChat(String message) { | ||||
|         if (message.isEmpty()) { | ||||
|             return new BaseComponent[0]; | ||||
|         } | ||||
|  | ||||
|         if (hasAdventureTextSupport()) { | ||||
|             return ComponentSerializer.parse(GsonComponentSerializer.gson().serialize(getAdventureChat(message))); | ||||
|         } | ||||
|  | ||||
|         ArrayList<BaseComponent> components = new ArrayList(); | ||||
|         StringBuilder builder = new StringBuilder(); | ||||
|         TextComponent component = new TextComponent(); | ||||
|         Matcher matcher = urlMatcher.matcher(message); | ||||
|  | ||||
|         for (int i = 0; i < message.length(); ++i) { | ||||
|             char c = message.charAt(i); | ||||
|             TextComponent old; | ||||
|  | ||||
|             if (c == ChatColor.COLOR_CHAR && i + 1 >= message.length()) { | ||||
|                 break; | ||||
|             } | ||||
|  | ||||
|             if (c == ChatColor.COLOR_CHAR || (NmsVersion.v1_16.isSupported() && c == '<' && i + 9 < message.length() && | ||||
|                     Pattern.matches("<#[0-9a-fA-F]{6}>", message.substring(i, i + 9)))) { | ||||
|                 i++; | ||||
|  | ||||
|                 net.md_5.bungee.api.ChatColor format; | ||||
|  | ||||
|                 if (c != ChatColor.COLOR_CHAR || (message.length() - i >= 7 && Pattern.matches("#[0-9a-fA-F]{6}", message.substring(i, i + 7)))) { | ||||
|                     format = net.md_5.bungee.api.ChatColor.of(message.substring(i, i + 7)); | ||||
|  | ||||
|                     i += c == '<' ? 7 : 8; | ||||
|                 } else { | ||||
|                     c = message.charAt(i); | ||||
|  | ||||
|                     if (c >= 'A' && c <= 'Z') { | ||||
|                         c = (char) (c + 32); | ||||
|                     } | ||||
|  | ||||
|                     format = net.md_5.bungee.api.ChatColor.getByChar(c); | ||||
|                 } | ||||
|  | ||||
|                 if (format != null) { | ||||
|                     if (builder.length() > 0) { | ||||
|                         old = component; | ||||
|                         component = new TextComponent(component); | ||||
|                         old.setText(builder.toString()); | ||||
|                         builder = new StringBuilder(); | ||||
|                         components.add(old); | ||||
|                     } | ||||
|  | ||||
|                     if (format == net.md_5.bungee.api.ChatColor.BOLD) { | ||||
|                         component.setBold(true); | ||||
|                     } else if (format == net.md_5.bungee.api.ChatColor.ITALIC) { | ||||
|                         component.setItalic(true); | ||||
|                     } else if (format == net.md_5.bungee.api.ChatColor.UNDERLINE) { | ||||
|                         component.setUnderlined(true); | ||||
|                     } else if (format == net.md_5.bungee.api.ChatColor.STRIKETHROUGH) { | ||||
|                         component.setStrikethrough(true); | ||||
|                     } else if (format == net.md_5.bungee.api.ChatColor.MAGIC) { | ||||
|                         component.setObfuscated(true); | ||||
|                     } else if (format == net.md_5.bungee.api.ChatColor.RESET) { | ||||
|                         component = new TextComponent(); | ||||
|                         component.setColor(net.md_5.bungee.api.ChatColor.WHITE); | ||||
|                     } else { | ||||
|                         component = new TextComponent(); | ||||
|                         component.setColor(format); | ||||
|                     } | ||||
|                 } | ||||
|             } else { | ||||
|                 int pos = message.indexOf(32, i); | ||||
|                 if (pos == -1) { | ||||
|                     pos = message.length(); | ||||
|                 } | ||||
|  | ||||
|                 if (matcher.region(i, pos).find()) { | ||||
|                     if (builder.length() > 0) { | ||||
|                         old = component; | ||||
|                         component = new TextComponent(component); | ||||
|                         old.setText(unquoteHex(builder.toString())); | ||||
|                         builder = new StringBuilder(); | ||||
|                         components.add(old); | ||||
|                     } | ||||
|  | ||||
|                     old = component; | ||||
|                     component = new TextComponent(component); | ||||
|                     String urlString = message.substring(i, pos); | ||||
|                     component.setText(unquoteHex(urlString)); | ||||
|                     component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, urlString.startsWith("http") ? urlString : "http://" + urlString)); | ||||
|                     components.add(component); | ||||
|                     i += pos - i - 1; | ||||
|                     component = old; | ||||
|                 } else { | ||||
|                     builder.append(c); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         component.setText(unquoteHex(builder.toString())); | ||||
|         components.add(component); | ||||
|         return components.toArray(new BaseComponent[0]); | ||||
|         return ComponentSerializer.parse(serialize(getAdventureChat(message))); | ||||
|     } | ||||
|  | ||||
|     public static void sendProtocolLibUpdateMessage(CommandSender p, String version, String requiredProtocolLib) { | ||||
|   | ||||
| @@ -297,12 +297,9 @@ public enum LibsMsg { | ||||
|     SELF_DISGUISE_HIDDEN("<green>Self disguise hidden as it's too tall.."); | ||||
|  | ||||
|     private final String string; | ||||
|     private final String useString; | ||||
|  | ||||
|     LibsMsg(String string) { | ||||
|         this.string = string; | ||||
|  | ||||
|         useString = DisguiseUtilities.hasAdventureTextSupport() ? string : getVanillaFormat(); | ||||
|     } | ||||
|  | ||||
|     public String getVanillaFormat() { | ||||
| @@ -319,10 +316,6 @@ public enum LibsMsg { | ||||
|         return string; | ||||
|     } | ||||
|  | ||||
|     public String getStringToUse() { | ||||
|         return useString; | ||||
|     } | ||||
|  | ||||
|     public BaseComponent[] getChat(Object... strings) { | ||||
|         String string = get(strings); | ||||
|  | ||||
|   | ||||
| @@ -138,19 +138,19 @@ public enum TranslateType { | ||||
|         save(null, message, comment); | ||||
|     } | ||||
|  | ||||
|     public void save(LibsMsg orig, String message, String comment) { | ||||
|         toDeDupe.put(StringEscapeUtils.escapeJava(message.replace("§", "&")), false); | ||||
|     public void save(LibsMsg orig, String rawMessage, String comment) { | ||||
|         toDeDupe.put(StringEscapeUtils.escapeJava(rawMessage.replace("§", "&")), false); | ||||
|  | ||||
|         if (translated.containsKey(message)) { | ||||
|         if (translated.containsKey(rawMessage)) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         String value = message; | ||||
|         String value = rawMessage; | ||||
|  | ||||
|         if (orig != null) { | ||||
|             String vanilla = orig.getVanillaFormat(); | ||||
|  | ||||
|             if (translated.containsKey(vanilla) && !vanilla.equals(message) && !translated.get(vanilla).equals(vanilla)) { | ||||
|             if (translated.containsKey(vanilla) && !vanilla.equals(rawMessage) && !translated.get(vanilla).equals(vanilla)) { | ||||
|                 value = translated.get(vanilla); | ||||
|  | ||||
|                 for (ChatColor color : ChatColor.values()) { | ||||
| @@ -159,7 +159,7 @@ public enum TranslateType { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         translated.put(message, value); | ||||
|         translated.put(rawMessage, value); | ||||
|  | ||||
|         try { | ||||
|             boolean exists = getFile().exists(); | ||||
| @@ -185,10 +185,10 @@ public enum TranslateType { | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             String sanitizedKey = StringEscapeUtils.escapeJava(message.replace("§", "&")); | ||||
|             String sanitized = StringEscapeUtils.escapeJava(value.replace("§", "&")); | ||||
|             String sanitizedKey = StringEscapeUtils.escapeJava(rawMessage.replace("§", "&")); | ||||
|             String sanitizedValue = StringEscapeUtils.escapeJava(value.replace("§", "&")); | ||||
|  | ||||
|             writer.write("\n" + (comment != null ? "# " + comment + "\n" : "") + "\"" + sanitizedKey + "\": \"" + sanitized + "\"\n"); | ||||
|             writer.write("\n" + (comment != null ? "# " + comment + "\n" : "") + "\"" + sanitizedKey + "\": \"" + sanitizedValue + "\"\n"); | ||||
|             written++; | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
| @@ -274,7 +274,7 @@ public enum TranslateType { | ||||
|     } | ||||
|  | ||||
|     public String get(LibsMsg msg) { | ||||
|         return get(msg.getStringToUse()); | ||||
|         return get(msg.getRaw()); | ||||
|     } | ||||
|  | ||||
|     public String get(String msg) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user