From e6cf81f7fd2389d1fd4a3d312cdfa3308d09279c Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:27:31 +1100 Subject: Fix: Click for pv in chat (#1041) * fix pv in chat * change string name --- .../notenoughupdates/listener/ChatListener.java | 88 +++++++++++----------- 1 file changed, 42 insertions(+), 46 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index 16b8493f..22d360e5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -117,62 +117,58 @@ public class ChatListener { private IChatComponent replaceSocialControlsWithPV(IChatComponent chatComponent) { + if (NotEnoughUpdates.INSTANCE.config.misc.replaceSocialOptions1 == 0 || !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + return chatComponent; + } - if (NotEnoughUpdates.INSTANCE.config.misc.replaceSocialOptions1 > 0 && - NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && - ((!chatComponent.getSiblings().isEmpty() && chatComponent.getSiblings().get(0).getChatStyle() != null && - chatComponent.getSiblings().get(0).getChatStyle().getChatClickEvent() != null && - chatComponent.getSiblings().get(0).getChatStyle().getChatClickEvent().getAction() == ClickEvent.Action.RUN_COMMAND) || - // Party/global chat with levels off components are different from global chat with levels on, so need to check for them here - // Party/global without levels being 0 and global with levels being 1 - (!chatComponent.getSiblings().isEmpty() && chatComponent.getSiblings().size() > 1 && chatComponent.getSiblings().get(1).getChatStyle() != null && - chatComponent.getSiblings().get(1).getChatStyle().getChatClickEvent() != null && - chatComponent.getSiblings().get(1).getChatStyle().getChatClickEvent().getAction() == ClickEvent.Action.RUN_COMMAND))) { - - String startsWith = null; - List siblings = chatComponent.getSiblings(); - int chatComponentsCount = siblings.size()-2; - - if (!siblings.isEmpty() && siblings.get(0).getChatStyle() != null && siblings.get(0).getChatStyle().getChatClickEvent() != null && siblings.get(0).getChatStyle().getChatClickEvent().getValue().startsWith("/viewprofile")) { - startsWith = "/viewprofile"; - } else if (!siblings.isEmpty() && siblings.size() > 1 && siblings.get(1).getChatStyle() != null) { - - ClickEvent chatClickEvent = chatComponent.getSiblings().get(chatComponentsCount).getChatStyle().getChatClickEvent(); - if (chatClickEvent != null) { - if (chatClickEvent.getValue().startsWith("/socialoptions")) { - startsWith = "/socialoptions"; - } - } - } + List siblings = chatComponent.getSiblings(); + if (siblings.size() < 2) return chatComponent; + + IChatComponent targetedComponent = siblings.get(siblings.size() - 2); - if (startsWith != null) { - String username = startsWith.equals("/viewprofile") ? - Utils.getNameFromChatComponent(chatComponent) : - chatComponent.getSiblings().get(chatComponentsCount).getChatStyle().getChatClickEvent().getValue().substring(15); - username = username.replaceAll("[^a-zA-Z0-9_]", ""); + String chatClickCommand = getChatClickEvent(siblings.get(0)); - if (NotEnoughUpdates.INSTANCE.config.misc.replaceSocialOptions1 == 1) { + if (chatClickCommand == null) { + chatClickCommand = getChatClickEvent(targetedComponent); + } + if (chatClickCommand == null) return chatComponent; - ChatStyle pvClickStyle = getPVChatStyle(username); - chatComponent.getSiblings().get(chatComponentsCount).setChatStyle(pvClickStyle); - return chatComponent; - } else if (NotEnoughUpdates.INSTANCE.config.misc.replaceSocialOptions1 == 2) { + String username = chatClickCommand.equals("/viewprofile") ? + Utils.getNameFromChatComponent(chatComponent) : + targetedComponent.getChatStyle().getChatClickEvent().getValue().substring(15); + username = username.replaceAll("[^a-zA-Z0-9_]", ""); - ChatStyle ahClickStyle = Utils.createClickStyle( - ClickEvent.Action.RUN_COMMAND, - "/ah " + username, - "" + EnumChatFormatting.YELLOW + "Click to open " + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + - username + EnumChatFormatting.RESET + EnumChatFormatting.YELLOW + "'s /ah page" - ); + if (NotEnoughUpdates.INSTANCE.config.misc.replaceSocialOptions1 == 1) { - chatComponent.getSiblings().get(chatComponentsCount).setChatStyle(ahClickStyle); - return chatComponent; - } - } // wanted to add this for guild but guild uses uuid :sad: + ChatStyle pvClickStyle = getPVChatStyle(username); + targetedComponent.setChatStyle(pvClickStyle); + + return chatComponent; + } else if (NotEnoughUpdates.INSTANCE.config.misc.replaceSocialOptions1 == 2) { + + ChatStyle ahClickStyle = Utils.createClickStyle( + ClickEvent.Action.RUN_COMMAND, + "/ah " + username, + "" + EnumChatFormatting.YELLOW + "Click to open " + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + + username + EnumChatFormatting.RESET + EnumChatFormatting.YELLOW + "'s /ah page" + ); + + targetedComponent.setChatStyle(ahClickStyle); + return chatComponent; } return chatComponent; } + private String getChatClickEvent(IChatComponent sibling) { + if (sibling.getChatStyle() != null && sibling.getChatStyle().getChatClickEvent() != null) { + String clickEvent = sibling.getChatStyle().getChatClickEvent().getValue(); + + if (clickEvent.startsWith("/socialoptions")) return "/socialoptions"; + if (clickEvent.startsWith("/viewprofile")) return "/viewprofile"; + } + return null; + } + private static ChatStyle getPVChatStyle(String username) { username = username.replaceAll("[^a-zA-Z0-9_]", ""); return Utils.createClickStyle( -- cgit