From 92c20769c767cf1c80adae8244bcd4c570b59827 Mon Sep 17 00:00:00 2001 From: LOOHP Date: Thu, 13 Aug 2020 15:18:05 +0800 Subject: [PATCH] Fixes legacy bungeecord api problems with other plugins --- pom.xml | 2 +- .../interactivechat/InteractiveChat.java | 13 ++-- .../Utils/ChatComponentUtils.java | 60 +++++++------------ 3 files changed, 26 insertions(+), 49 deletions(-) diff --git a/pom.xml b/pom.xml index ec735a85..e8e330de 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 InteractiveChat InteractiveChat - 2.6.10 + 2.6.11 src diff --git a/src/com/loohp/interactivechat/InteractiveChat.java b/src/com/loohp/interactivechat/InteractiveChat.java index 779c0114..458de5a6 100644 --- a/src/com/loohp/interactivechat/InteractiveChat.java +++ b/src/com/loohp/interactivechat/InteractiveChat.java @@ -33,13 +33,14 @@ import com.loohp.interactivechat.ObjectHolders.ICPlaceholder; import com.loohp.interactivechat.ObjectHolders.MentionPair; import com.loohp.interactivechat.Updater.Updater; -import com.loohp.interactivechat.Utils.ChatComponentUtils; import com.loohp.interactivechat.Utils.ItemNBTUtils; import com.loohp.interactivechat.Utils.MCVersion; import com.loohp.interactivechat.Utils.MaterialUtils; import com.loohp.interactivechat.Utils.PotionUtils; import com.loohp.interactivechat.Utils.RarityUtils; +import net.md_5.bungee.api.chat.TextComponent; + public class InteractiveChat extends JavaPlugin { public static Plugin plugin = null; @@ -216,16 +217,12 @@ public void onEnable() { ClientSettingPackets.clientSettingsListener(); try { - Class.forName("net.md_5.bungee.api.chat.hover.content.Content"); + new TextComponent("Legacy Bungeecord Chat API Test").getHoverEvent().getContents(); legacyChatAPI = false; - } catch (ClassNotFoundException e) { + } catch (Exception | NoSuchMethodError e) { legacyChatAPI = true; - }; - - if (legacyChatAPI) { - ChatComponentUtils.setupLegacy(); Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[InteractiveChat] Legacy Bungeecord Chat API detected, using legacy methods..."); - } + }; getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[InteractiveChat] InteractiveChat has been Enabled!"); diff --git a/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java b/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java index 688585a6..d5e1456f 100644 --- a/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java +++ b/src/com/loohp/interactivechat/Utils/ChatComponentUtils.java @@ -1,8 +1,5 @@ package com.loohp.interactivechat.Utils; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; @@ -31,23 +28,11 @@ public class ChatComponentUtils { - private static Class chatHoverEventClass; - private static MethodHandle hoverEventGetValueMethod; - private static Pattern fontFormating = Pattern.compile("(?=(? contents1 = hover1.getContents(); @@ -259,18 +242,15 @@ public static boolean areEventsSimilar(BaseComponent base1, BaseComponent base2) return clickSim && hoverSim; } + @SuppressWarnings("deprecation") public static BaseComponent removeHoverEventColor(BaseComponent baseComponent) { if (baseComponent.getHoverEvent() != null) { if (InteractiveChat.legacyChatAPI) { - try { - for (BaseComponent each : (BaseComponent[]) hoverEventGetValueMethod.invoke(baseComponent.getHoverEvent())) { - each.setColor(ChatColor.WHITE); - if (each instanceof TextComponent) { - ((TextComponent) each).setText(ChatColor.stripColor(((TextComponent) each).getText())); - } + for (BaseComponent each : baseComponent.getHoverEvent().getValue()) { + each.setColor(ChatColor.WHITE); + if (each instanceof TextComponent) { + ((TextComponent) each).setText(ChatColor.stripColor(((TextComponent) each).getText())); } - } catch (Throwable e) { - e.printStackTrace(); } } else { int j = 0;