From 5534c9366b17b30a9c90722403acb58c5c09aa1b Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sat, 17 Jul 2021 23:53:01 +0900 Subject: Fix party manager to use cooldown Fix Cosmetics removing player's messages --- .../dungeonsguide/cosmetics/CosmeticsManager.java | 18 +++++---- .../chatreplacers/ChatReplacerViewProfile.java | 2 +- .../syeyoung/dungeonsguide/party/PartyManager.java | 47 +++++++++++++--------- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java index f208ac74..f6a9c3da 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java @@ -234,7 +234,7 @@ public class CosmeticsManager implements StompMessageHandler { requestPerms(); } @Getter @Setter - private static Set iChatReplacers = new HashSet<>(); + private static List iChatReplacers = new ArrayList<>(); static { iChatReplacers.add(new ChatReplacerViewProfile()); iChatReplacers.add(new ChatReplacerSocialOptions()); @@ -245,13 +245,17 @@ public class CosmeticsManager implements StompMessageHandler { @SubscribeEvent(priority = EventPriority.LOWEST) public void onChat(ClientChatReceivedEvent clientChatReceivedEvent) { - if (clientChatReceivedEvent.type == 2) return; - for (IChatReplacer iChatReplacer : iChatReplacers) { - if (iChatReplacer.isAcceptable(clientChatReceivedEvent)) { - System.out.println("Chosen "+iChatReplacer); - iChatReplacer.translate(clientChatReceivedEvent, this); - return; + try { + if (clientChatReceivedEvent.type == 2) return; + for (IChatReplacer iChatReplacer : iChatReplacers) { + if (iChatReplacer.isAcceptable(clientChatReceivedEvent)) { + iChatReplacer.translate(clientChatReceivedEvent, this); + return; + } } + } catch (Throwable t) { + System.out.println(clientChatReceivedEvent.message); + t.printStackTrace(); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java index abd399e3..51787951 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java @@ -35,7 +35,6 @@ import java.util.UUID; public class ChatReplacerViewProfile implements IChatReplacer { @Override public boolean isAcceptable(ClientChatReceivedEvent event) { - System.out.println(event.message); for (IChatComponent sibling : event.message.getSiblings()) { if (sibling.getChatStyle() != null && sibling.getChatStyle().getChatClickEvent() != null && sibling.getChatStyle().getChatClickEvent().getValue().startsWith("/viewprofile")) return true; } @@ -112,6 +111,7 @@ public class ChatReplacerViewProfile implements IChatReplacer { ChatComponentText newChatCompText = new ChatComponentText(building); newChatCompText.setChatStyle(sibling.getChatStyle()); replaceMents.add(new Tuple<>(sibling, newChatCompText)); + break; } } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java index feb3757a..a01f1658 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java @@ -31,6 +31,7 @@ import lombok.Getter; import lombok.Setter; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; +import net.minecraft.util.Tuple; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -40,6 +41,8 @@ import org.json.JSONObject; import java.security.SecureRandom; import java.util.*; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.SynchronousQueue; import java.util.function.Consumer; public class PartyManager implements StompMessageHandler { @@ -87,8 +90,7 @@ public class PartyManager implements StompMessageHandler { } if (partyID != null && !partyID.equals(this.partyID)) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); - invitedDash = 1; + sendChat.add(new Tuple<>("/p invite -", () -> {invitedDash = 1;})); } else { canInvite = true; allowAskToJoin = false; @@ -199,7 +201,7 @@ public class PartyManager implements StompMessageHandler { } else if (str.contains("§r§ejoined the dungeon group! (§r§b")) { String username = TextUtils.stripColor(str).split(" ")[3]; if (username.equalsIgnoreCase(Minecraft.getMinecraft().getSession().getUsername())) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl"); + sendChat.add(new Tuple<>("/pl", () -> {partyJoin = 1;})); partyJoin = 1; } else { members.add(username); @@ -282,8 +284,7 @@ public class PartyManager implements StompMessageHandler { allowAskToJoin = false; askToJoinSecret = ""; RichPresenceManager.INSTANCE.updatePresence(); - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); - invitedDash = 1; + sendChat.add(new Tuple<>("/p invite -", () -> {invitedDash = 1;})); } else if (str.endsWith("§r§eto Party Moderator§r")) { // §b[MVP§r§f+§r§b] apotato321§r§e has promoted §r§a[VIP§r§6+§r§a] syeyoung §r§eto Party Moderator§r String[] thetext = TextUtils.stripColor(str).split(" "); @@ -296,8 +297,7 @@ public class PartyManager implements StompMessageHandler { if (s.equals(Minecraft.getMinecraft().getSession().getUsername())) { canInvite = true; } else { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); - invitedDash = 1; + sendChat.add(new Tuple<>("/p invite -", () -> {invitedDash = 1;})); break; } } else { @@ -316,9 +316,7 @@ public class PartyManager implements StompMessageHandler { if (asd != null && Minecraft.getMinecraft().getSession().getUsername().equalsIgnoreCase(asd)) { canInvite = true; } else { - - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); - invitedDash = 1; + sendChat.add(new Tuple<>("/p invite -", () -> {invitedDash = 1;})); } } else if (str.endsWith("§eto Party Leader§r")) { // §a[VIP§r§6+§r§a] syeyoung§r§e has promoted §r§b[MVP§r§f+§r§b] apotato321 §r§eto Party Leader§r @@ -332,8 +330,7 @@ public class PartyManager implements StompMessageHandler { if (s.equals(Minecraft.getMinecraft().getSession().getUsername())) { canInvite = true; } else { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); - invitedDash = 1; + sendChat.add(new Tuple<>("/p invite -", () -> {invitedDash = 1;})); break; } } else { @@ -349,8 +346,7 @@ public class PartyManager implements StompMessageHandler { else if (s.equals("[")) continue; else if (seenThings == 2) { if (s.equals(Minecraft.getMinecraft().getSession().getUsername())) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); - invitedDash = 1; + sendChat.add(new Tuple<>("/p invite -", () -> {invitedDash = 1;})); canInvite = false; break; } @@ -364,22 +360,33 @@ public class PartyManager implements StompMessageHandler { } @SubscribeEvent public void onTick(TickEvent.ClientTickEvent clientTickEvent) { - if (clientTickEvent.phase == TickEvent.Phase.START) { + if (clientTickEvent.phase == TickEvent.Phase.START && Minecraft.getMinecraft().thePlayer != null && minimumNext < System.currentTimeMillis() ) { if (checkPlayer == 1) { - checkPlayer = 2; - Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl"); + checkPlayer = -1; + sendChat.add(new Tuple<>("/pl", () -> {checkPlayer = 2;})); + } + if (!sendChat.isEmpty()) { + Tuple tuple = sendChat.poll(); + Minecraft.getMinecraft().thePlayer.sendChatMessage(tuple.getFirst()); + if (tuple.getSecond() != null) + tuple.getSecond().run(); + minimumNext = System.currentTimeMillis()+ 200; + DungeonsGuide.sendDebugChat(new ChatComponentText("Sending "+tuple.getFirst()+" Secretly")); } + } } @SubscribeEvent public void onHypixelJoin(HypixelJoinedEvent skyblockJoinedEvent) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl"); - partyJoin = 1; + sendChat.add(new Tuple<>("/pl", () -> {partyJoin = 1;})); } private int checkPlayer = 0; private JSONObject theObject; + private long minimumNext = 0; + + public static Queue> sendChat = new ConcurrentLinkedQueue<>(); @Override public void handle(StompInterface stompInterface, StompPayload stompPayload) { @@ -391,7 +398,7 @@ public class PartyManager implements StompMessageHandler { String playerName = object.getString("player"); String secret = object.getString("secret"); if (secret.equals(askToJoinSecret) && partyID != null) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite "+playerName); + sendChat .add(new Tuple<>("/p invite "+playerName, null)); } } else if ("/user/queue/party.broadcast".equals(stompPayload.headers().get("destination"))) { try { -- cgit