From d239ae4d4748fc4867ab45a5cc7d42bfb5ac547c Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sat, 27 Nov 2021 23:19:16 +0900 Subject: - Deadlock on ApiFetchur (Waits until lilyweight data and lilyweight data fetcher waits for other tasks to finish) - New PartyManager - ChatProcessor now manages all automatic chat messages and msot chat parsing - PartyFinderSetting now contains option to leave party - Log StompPayload when debug enabled --- .../dungeonsguide/features/FeatureRegistry.java | 2 + .../features/impl/party/FeaturePartyList.java | 97 ++++++++++++++++++++++ .../features/impl/party/api/ApiFetchur.java | 29 +++---- .../impl/party/customgui/PanelPartyFinder.java | 5 +- .../party/customgui/PanelPartyFinderSettings.java | 17 +++- .../playerpreview/FeatureViewPlayerOnJoin.java | 37 ++++++--- 6 files changed, 151 insertions(+), 36 deletions(-) create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/FeaturePartyList.java (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java index f87456fa..edb429df 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java @@ -33,6 +33,7 @@ import kr.syeyoung.dungeonsguide.features.impl.dungeon.*; import kr.syeyoung.dungeonsguide.features.impl.etc.*; import kr.syeyoung.dungeonsguide.features.impl.etc.ability.FeatureAbilityCooldown; import kr.syeyoung.dungeonsguide.features.impl.party.APIKey; +import kr.syeyoung.dungeonsguide.features.impl.party.FeaturePartyList; import kr.syeyoung.dungeonsguide.features.impl.party.customgui.FeatureCustomPartyFinder; import kr.syeyoung.dungeonsguide.features.impl.party.playerpreview.FeatureViewPlayerOnJoin; import kr.syeyoung.dungeonsguide.features.impl.secret.*; @@ -161,6 +162,7 @@ public class FeatureRegistry { public static final APIKey PARTYKICKER_APIKEY = register(new APIKey()); public static final FeatureViewPlayerOnJoin PARTYKICKER_VIEWPLAYER = register(new FeatureViewPlayerOnJoin()); public static final FeatureCustomPartyFinder PARTYKICKER_CUSTOM = register(new FeatureCustomPartyFinder()); + public static final FeaturePartyList PARTY_LIST = register(new FeaturePartyList()); public static final FeatureTooltipDungeonStat ETC_DUNGEONSTAT = register(new FeatureTooltipDungeonStat()); public static final FeatureTooltipPrice ETC_PRICE = register(new FeatureTooltipPrice()); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/FeaturePartyList.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/FeaturePartyList.java new file mode 100644 index 00000000..0222b97b --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/FeaturePartyList.java @@ -0,0 +1,97 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.features.impl.party; + +import kr.syeyoung.dungeonsguide.chat.PartyContext; +import kr.syeyoung.dungeonsguide.chat.PartyManager; +import kr.syeyoung.dungeonsguide.config.types.AColor; +import kr.syeyoung.dungeonsguide.features.text.StyledText; +import kr.syeyoung.dungeonsguide.features.text.TextHUDFeature; +import kr.syeyoung.dungeonsguide.features.text.TextStyle; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class FeaturePartyList extends TextHUDFeature { + public FeaturePartyList() { + super("Party","Party List", "Party List as GUI", "party.list", false, getFontRenderer().getStringWidth("Watcher finished spawning all mobs!"), getFontRenderer().FONT_HEIGHT); + getStyles().add(new TextStyle("name", new AColor(0x00, 0xAA,0xAA,255), new AColor(0, 0,0,0), false)); + getStyles().add(new TextStyle("separator", new AColor(0x55, 0x55,0x55,255), new AColor(0, 0,0,0), false)); + getStyles().add(new TextStyle("player", new AColor(0x55, 0xFF,0xFF,255), new AColor(0, 0,0,0), false)); + getStyles().add(new TextStyle("allinvite", new AColor(0xAA,0xAA,0xAA,255), new AColor(0, 0,0,0), false)); + setEnabled(true); + } + + @Override + public boolean isHUDViewable() { + return PartyManager.INSTANCE.getPartyContext() != null; + } + + @Override + public java.util.List getUsedTextStyle() { + return Arrays.asList("name" ,"separator", "player", "allinvite"); + } + + private static final List dummyText = new ArrayList(); + static { + dummyText.add(new StyledText("\nLeader","name")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("syeyoung","player")); + dummyText.add(new StyledText("\nModerator","name")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("rioho, RaidShadowLegends, Tricked","player")); + dummyText.add(new StyledText("\nMember","name")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("Everyone","player")); + dummyText.add(new StyledText("\nAll invite Off","allinvite")); + } + + @Override + public List getDummyText() { + return dummyText; + } + + @Override + public boolean doesScaleWithHeight() { + return false; + } + + @Override + public List getText() { + PartyContext pc = PartyManager.INSTANCE.getPartyContext(); + List text= new ArrayList<>(); + text.add(new StyledText("\nLeader","name")); + text.add(new StyledText(": ","separator")); + text.add(new StyledText(pc.getPartyOwner()+"","player")); + text.add(new StyledText("\nModerator","name")); + text.add(new StyledText(": ","separator")); + text.add(new StyledText(pc.getPartyModerator() == null ? "????" : String.join(", ", pc.getPartyModerator()) + (pc.isModeratorComplete() ? "" : " ?"),"player")); + text.add(new StyledText("\nMember","name")); + text.add(new StyledText(": ","separator")); + text.add(new StyledText(pc.getPartyMember() == null ? "????" : String.join(", ", pc.getPartyMember()) + (pc.isMemberComplete() ? "" : " ?"),"player")); + if (pc.getAllInvite() != null && !pc.getAllInvite()) + text.add(new StyledText("\nAll invite Off","allinvite")); + else if (pc.getAllInvite() != null) + text.add(new StyledText("\nAll invite On","allinvite")); + else + text.add(new StyledText("\nAll invite Unknown","allinvite")); + return text; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/api/ApiFetchur.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/api/ApiFetchur.java index 046d9a8e..0d929697 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/api/ApiFetchur.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/api/ApiFetchur.java @@ -64,8 +64,12 @@ public class ApiFetchur { completableFutureMap3.clear(); completableFutureMap4.clear(); invalidKeys.clear(); - completableFutureMapLily= null; constants = null; + + ex.submit(ApiFetchur::getLilyWeightConstants); + } + static { + ex.submit(ApiFetchur::getLilyWeightConstants); } public static JsonObject getJson(String url) throws IOException { @@ -81,25 +85,16 @@ public class ApiFetchur { return gson.fromJson(new InputStreamReader(connection.getInputStream()), JsonArray.class); } - private static JsonObject constants; - private static CompletableFuture completableFutureMapLily; - public static CompletableFuture getLilyWeightConstants() { - if (constants != null) return CompletableFuture.completedFuture(constants); - if (completableFutureMapLily != null) return completableFutureMapLily; - CompletableFuture completableFuture = new CompletableFuture<>(); - completableFutureMapLily = completableFuture; - ex.submit(() -> { + private static volatile JsonObject constants; + public static JsonObject getLilyWeightConstants() { + if (constants != null) return constants; try { JsonObject jsonObject = getJson("https://raw.githubusercontent.com/Antonio32A/lilyweight/master/lib/constants.json"); constants = jsonObject; - completableFuture.complete(jsonObject); - completableFutureMapLily= null; } catch (Exception e) { - completableFuture.completeExceptionally(e); - completableFutureMapLily= null; + throw new RuntimeException(e); } - }); - return completableFuture; + return constants; } private static final Map>> completableFutureMap4 = new ConcurrentHashMap<>(); @@ -174,7 +169,7 @@ public class ApiFetchur { completableFutureMap.remove(uid); invalidKeys.add(apiKey); } else { - completableFuture.complete(Optional.empty()); + completableFuture.completeExceptionally(e); completableFutureMap.remove(uid); } e.printStackTrace(); @@ -497,7 +492,7 @@ public class ApiFetchur { } private static void calculateLilyWeight(PlayerProfile playerProfile, JsonObject playerData) throws ExecutionException, InterruptedException { - JsonObject constants = getLilyWeightConstants().get(); + JsonObject constants = getLilyWeightConstants(); double[] slayerXP = new double[4]; if (playerData.has("slayer_bosses")) { slayerXP[0] = getOrDefault(playerData.getAsJsonObject("slayer_bosses").getAsJsonObject("zombie"), "xp", 0); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/customgui/PanelPartyFinder.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/customgui/PanelPartyFinder.java index 23c8e253..eef360b2 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/customgui/PanelPartyFinder.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/customgui/PanelPartyFinder.java @@ -18,13 +18,13 @@ package kr.syeyoung.dungeonsguide.features.impl.party.customgui; +import kr.syeyoung.dungeonsguide.chat.PartyManager; import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfigV2; import kr.syeyoung.dungeonsguide.events.WindowUpdateEvent; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.features.impl.discord.invteTooltip.MTooltipInvite; import kr.syeyoung.dungeonsguide.gui.MPanel; import kr.syeyoung.dungeonsguide.gui.elements.*; -import kr.syeyoung.dungeonsguide.party.PartyManager; import kr.syeyoung.dungeonsguide.rpc.RichPresenceManager; import kr.syeyoung.dungeonsguide.utils.RenderUtils; import lombok.Getter; @@ -41,7 +41,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ChatComponentText; import java.awt.*; import java.util.HashMap; @@ -122,7 +121,7 @@ public class PanelPartyFinder extends MPanel { MModalMessage mTooltipInvite = new MModalMessage("Error", "Discord GameSDK has been disabled, or it failed to load", () -> {}); mTooltipInvite.setScale( new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); mTooltipInvite.open(this); - } else if (PartyManager.INSTANCE.isAllowAskToJoin()) { + } else if (PartyManager.INSTANCE.getAskToJoinSecret() != null) { MTooltipInvite mTooltipInvite = new MTooltipInvite(); mTooltipInvite.setScale( new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); mTooltipInvite.open(this); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/customgui/PanelPartyFinderSettings.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/customgui/PanelPartyFinderSettings.java index 8dad627c..46107ff8 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/customgui/PanelPartyFinderSettings.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/customgui/PanelPartyFinderSettings.java @@ -18,8 +18,10 @@ package kr.syeyoung.dungeonsguide.features.impl.party.customgui; +import kr.syeyoung.dungeonsguide.chat.ChatProcessor; +import kr.syeyoung.dungeonsguide.chat.PartyManager; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; -import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.features.impl.party.api.ApiFetchur; import kr.syeyoung.dungeonsguide.gui.elements.*; import kr.syeyoung.dungeonsguide.utils.TextUtils; import lombok.Getter; @@ -53,22 +55,27 @@ public class PanelPartyFinderSettings extends MPanelScaledGUI { boolean delistable = false; public void setDelistable(boolean delistable) { - createNew.setText(delistable ? "De-list" : "Create New"); this.delistable = delistable; + updateCreateNew(); + } + + public void updateCreateNew() { + createNew.setText((PartyManager.INSTANCE.getPartyContext() != null && !PartyManager.INSTANCE.isLeader()) ? "Leave Party" : (delistable ? "De-list" : "Create New")); } public PanelPartyFinderSettings(PanelPartyFinder panelPartyFinder) { this.panelPartyFinder = panelPartyFinder; - createNew.setText("Create New"); createNew.setOnActionPerformed(this::createNew); createNew.setBackground(0xFF00838F); createNew.setHover(0xFF00ACC1); createNew.setClicked(0xFF0097A7); add(createNew); + updateCreateNew(); refresh.setText("Refresh"); refresh.setOnActionPerformed(this::refresh); add(refresh); + settings.setText("Search Settings"); settings.setOnActionPerformed(this::settings); add(settings); @@ -142,6 +149,10 @@ public class PanelPartyFinderSettings extends MPanelScaledGUI { } private void createNew() { + if (PartyManager.INSTANCE.getPartyContext() != null && !PartyManager.INSTANCE.isLeader()) { + ChatProcessor.INSTANCE.addToChatQueue("/p leave ", () -> {}, true); + return; + } GuiChest chest = panelPartyFinder.getGuiCustomPartyFinder().getGuiChest(); if (delistable) Minecraft.getMinecraft().playerController.windowClick(chest.inventorySlots.windowId, 9*5+7, 0, 0, Minecraft.getMinecraft().thePlayer); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/playerpreview/FeatureViewPlayerOnJoin.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/playerpreview/FeatureViewPlayerOnJoin.java index 21fb5d04..ceca0022 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/playerpreview/FeatureViewPlayerOnJoin.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/playerpreview/FeatureViewPlayerOnJoin.java @@ -24,6 +24,8 @@ import io.github.moulberry.hychat.HyChat; import io.github.moulberry.hychat.chat.ChatManager; import io.github.moulberry.hychat.gui.GuiChatBox; import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.chat.ChatProcessor; +import kr.syeyoung.dungeonsguide.chat.PartyManager; import kr.syeyoung.dungeonsguide.config.guiconfig.ConfigPanelCreator; import kr.syeyoung.dungeonsguide.config.guiconfig.MFeatureEdit; import kr.syeyoung.dungeonsguide.config.guiconfig.MParameterEdit; @@ -38,7 +40,6 @@ import kr.syeyoung.dungeonsguide.features.listener.ChatListener; import kr.syeyoung.dungeonsguide.features.listener.GuiClickListener; import kr.syeyoung.dungeonsguide.features.listener.GuiPostRenderListener; import kr.syeyoung.dungeonsguide.gui.MPanel; -import kr.syeyoung.dungeonsguide.party.PartyManager; import kr.syeyoung.dungeonsguide.utils.TextUtils; import lombok.Getter; import lombok.Setter; @@ -416,10 +417,10 @@ public class FeatureViewPlayerOnJoin extends SimpleFeature implements GuiPostRen if (Mouse.getEventButton() != -1 && Mouse.isButtonDown(Mouse.getEventButton())) { if (new Rectangle(2, 195, 86, 23).contains(relX, relY)) { // invite - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite " + ApiFetchur.fetchNicknameAsync(playerProfile.getMemberUID()).get().orElse("-")); + ChatProcessor.INSTANCE.addToChatQueue("/p invite " + ApiFetchur.fetchNicknameAsync(playerProfile.getMemberUID()).get().orElse("-"), () -> {}, true); } else if (new Rectangle(2, 170, 86, 23).contains(relX, relY)) { // kick - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p kick " + ApiFetchur.fetchNicknameAsync(playerProfile.getMemberUID()).get().orElse("-")); + ChatProcessor.INSTANCE.addToChatQueue("/p kick " + ApiFetchur.fetchNicknameAsync(playerProfile.getMemberUID()).get().orElse("-"), () -> {}, true); } else if (new Rectangle(80,159,10,11).contains(relX, relY)) { drawInv = true; } @@ -456,21 +457,31 @@ public class FeatureViewPlayerOnJoin extends SimpleFeature implements GuiPostRen if (str.contains("§r§ejoined the dungeon group! (§r§b")) { String username = TextUtils.stripColor(str).split(" ")[3]; if (username.equalsIgnoreCase(Minecraft.getMinecraft().getSession().getUsername())) { - PartyManager.INSTANCE.getRunOnMembersReceived().add((e) -> { - for (String s : e) { - ApiFetchur.fetchUUIDAsync(s) - .thenAccept(a -> { - if (a == null) return; - ApiFetchur.fetchMostRecentProfileAsync(a.get(), FeatureRegistry.PARTYKICKER_APIKEY.getAPIKey()); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e"+s+"§f's Profile ").appendSibling(new ChatComponentText("§7view").setChatStyle(new ChatStyle().setChatHoverEvent(new FeatureViewPlayerOnJoin.HoverEventRenderPlayer(a.orElse(null)))))); - }); + PartyManager.INSTANCE.requestPartyList((context) -> { + if (context == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §cBugged Dungeon Party ")); + } else { + + for (String member : context.getPartyRawMembers()) { + ApiFetchur.fetchUUIDAsync(member) + .thenAccept((a) -> { + if (a == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e"+member+"§f's Profile §cCouldn't fetch uuid")); + } else { + ApiFetchur.fetchMostRecentProfileAsync(a.get(), FeatureRegistry.PARTYKICKER_APIKEY.getAPIKey()); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e"+member+"§f's Profile ").appendSibling(new ChatComponentText("§7view").setChatStyle(new ChatStyle().setChatHoverEvent(new FeatureViewPlayerOnJoin.HoverEventRenderPlayer(a.orElse(null)))))); + } + }); + } } }); - PartyManager.INSTANCE.requestPartyRetrieval(); } else { ApiFetchur.fetchUUIDAsync(username) .thenAccept(a -> { - if (a == null) return; + if (a == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e"+username+"§f's Profile §cCouldn't fetch uuid")); + return; + } ApiFetchur.fetchMostRecentProfileAsync(a.get(), FeatureRegistry.PARTYKICKER_APIKEY.getAPIKey()); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e"+username+"§f's Profile ").appendSibling(new ChatComponentText("§7view").setChatStyle(new ChatStyle().setChatHoverEvent(new FeatureViewPlayerOnJoin.HoverEventRenderPlayer(a.orElse(null)))))); }); -- cgit