diff options
author | syeyoung <cyong06@naver.com> | 2021-03-06 16:36:59 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-03-06 16:36:59 +0900 |
commit | 778909720ab8bb99afb48d57a9da07ab20a6f4ce (patch) | |
tree | d68aacd31e4b5c263ae194f6897b4e3d6f986e26 /src/main | |
parent | ccdcb508b1b7b5fcc212efc39466434631118e87 (diff) | |
download | Skyblock-Dungeons-Guide-778909720ab8bb99afb48d57a9da07ab20a6f4ce.tar.gz Skyblock-Dungeons-Guide-778909720ab8bb99afb48d57a9da07ab20a6f4ce.tar.bz2 Skyblock-Dungeons-Guide-778909720ab8bb99afb48d57a9da07ab20a6f4ce.zip |
pog
Diffstat (limited to 'src/main')
10 files changed, 378 insertions, 50 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java index 641522a6..0d11a8f2 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java @@ -3,6 +3,8 @@ package kr.syeyoung.dungeonsguide; import kr.syeyoung.dungeonsguide.events.SkyblockJoinedEvent; import kr.syeyoung.dungeonsguide.events.SkyblockLeftEvent; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.party.PartyInviteViewer; +import kr.syeyoung.dungeonsguide.party.PartyJoinRequest; import kr.syeyoung.dungeonsguide.party.PartyManager; import kr.syeyoung.dungeonsguide.stomp.StompHeader; import kr.syeyoung.dungeonsguide.stomp.StompPayload; @@ -14,8 +16,9 @@ import org.json.JSONObject; import java.io.*; import java.net.URL; +import java.time.Instant; -public class RichPresenceManager implements JoinRequestCallback, JoinGameCallback, ErroredCallback, DisconnectedCallback, Runnable { +public class RichPresenceManager implements Runnable { public static RichPresenceManager INSTANCE = new RichPresenceManager(); public RichPresenceManager() { @@ -30,11 +33,23 @@ public class RichPresenceManager implements JoinRequestCallback, JoinGameCallbac public void apply(DiscordUser user) { updatePresence(); } - }) - .setJoinRequestEventHandler(this) - .setJoinGameEventHandler(this) - .setErroredEventHandler(this) - .setDisconnectedEventHandler(this).build(), true); + }).setJoinRequestEventHandler(request -> { + PartyJoinRequest partyJoinRequest = new PartyJoinRequest(); + partyJoinRequest.setDiscordUser(request); + partyJoinRequest.setTime(Instant.now()); + + PartyInviteViewer.INSTANCE.joinRequests.add(partyJoinRequest); + }).setJoinGameEventHandler(joinSecret -> { + e.getDungeonsGuide().getStompConnection().send(new StompPayload().method(StompHeader.SEND) + .header("destination", "/app/party.askedtojoin") + .payload(new JSONObject().put("token", joinSecret).toString())); + }).setErroredEventHandler((errorCode, message) -> { + System.out.println("ERROR! "+errorCode+ " - "+message); + setup(); + }).setDisconnectedEventHandler((errorCode, message) -> { + System.out.println("ERROR! "+errorCode+ " - "+message); + setup(); + }).build(), true); } private SkyblockStatus skyblockStatus = e.getDungeonsGuide().getSkyblockStatus(); @@ -75,27 +90,6 @@ public class RichPresenceManager implements JoinRequestCallback, JoinGameCallbac @SubscribeEvent public void tick(TickEvent.ClientTickEvent clientTickEvent) { } - - @Override - public void apply(int errorCode, String message) { - System.out.println("ERROR! "+errorCode+ " - "+message); - setup(); - } - - @Override - public void apply(String joinSecret) { - System.out.println("OK JOINNNNNNNNNNNNNNNNNN "+joinSecret); - e.getDungeonsGuide().getStompConnection().send(new StompPayload().method(StompHeader.SEND) - .header("destination", "/app/party.askedtojoin") - .payload(new JSONObject().put("token", joinSecret).toString())); - } - - @Override - public void apply(DiscordUser user) { - System.out.println(user.username+" wants to join"); - DiscordRPC.discordRespond(user.userId, DiscordRPC.DiscordReply.YES); - } - @Override public void run() { while(true) { @@ -105,6 +99,7 @@ public class RichPresenceManager implements JoinRequestCallback, JoinGameCallbac lastLoc = skyblockStatus.getDungeonName()+""; } updatePresence(); + Thread.sleep(1000L); } catch (Exception e) {e.printStackTrace();} } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/e.java b/src/main/java/kr/syeyoung/dungeonsguide/e.java index 478ea8b5..a8d76c49 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/e.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/e.java @@ -8,6 +8,7 @@ import kr.syeyoung.dungeonsguide.eventlistener.FeatureListener; import kr.syeyoung.dungeonsguide.eventlistener.PacketListener; import kr.syeyoung.dungeonsguide.events.StompConnectedEvent; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.party.PartyInviteViewer; import kr.syeyoung.dungeonsguide.party.PartyManager; import kr.syeyoung.dungeonsguide.stomp.CloseListener; import kr.syeyoung.dungeonsguide.stomp.StompClient; @@ -97,6 +98,7 @@ public class e implements c, CloseListener { RichPresenceManager.INSTANCE.setup(); MinecraftForge.EVENT_BUS.register(RichPresenceManager.INSTANCE); MinecraftForge.EVENT_BUS.register(PartyManager.INSTANCE); + MinecraftForge.EVENT_BUS.register(PartyInviteViewer.INSTANCE); AhUtils.registerTimer(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java index 4cb4f429..a4e853de 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java @@ -106,6 +106,7 @@ public class DungeonListener { } catch (Throwable e2) {e2.printStackTrace();} } + boolean wasOnHypixel = false; @SubscribeEvent public void onTick(TickEvent.ClientTickEvent ev) throws Throwable { try { @@ -153,6 +154,11 @@ public class DungeonListener { boolean isOnSkyblock = skyblockStatus.isOnSkyblock(); skyblockStatus.updateStatus(); + if (!wasOnHypixel && skyblockStatus.isOnHypixel()) { + MinecraftForge.EVENT_BUS.post(new HypixelJoinedEvent()); + } + wasOnHypixel = skyblockStatus.isOnHypixel(); + if (isOnSkyblock && !skyblockStatus.isOnSkyblock()) { MinecraftForge.EVENT_BUS.post(new SkyblockLeftEvent()); } else if (!isOnSkyblock && skyblockStatus.isOnSkyblock()) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/events/HypixelJoinedEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/events/HypixelJoinedEvent.java new file mode 100644 index 00000000..25e13c4b --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/events/HypixelJoinedEvent.java @@ -0,0 +1,6 @@ +package kr.syeyoung.dungeonsguide.events; + +import net.minecraftforge.fml.common.eventhandler.Event; + +public class HypixelJoinedEvent extends Event { +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/LoadedImage.java b/src/main/java/kr/syeyoung/dungeonsguide/party/LoadedImage.java new file mode 100644 index 00000000..be9ecf6f --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/LoadedImage.java @@ -0,0 +1,22 @@ +package kr.syeyoung.dungeonsguide.party; + + +import lombok.Data; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.util.ResourceLocation; + +import java.awt.image.BufferedImage; + +@Data +public class LoadedImage { + private String url; + private BufferedImage image; + private DynamicTexture previewTexture; + private ResourceLocation resourceLocation; + + public void buildGLThings() { + previewTexture = new DynamicTexture(image); + resourceLocation = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("dgurl/"+url, previewTexture); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java new file mode 100644 index 00000000..efaa471f --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java @@ -0,0 +1,249 @@ +package kr.syeyoung.dungeonsguide.party; + +import kr.syeyoung.dungeonsguide.SkyblockStatus; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiGuiLocationConfig; +import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.features.AbstractFeature; +import kr.syeyoung.dungeonsguide.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.features.GuiFeature; +import kr.syeyoung.dungeonsguide.features.listener.ScreenRenderListener; +import net.arikia.dev.drpc.DiscordRPC; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.input.Mouse; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.net.URL; +import java.util.*; +import java.util.concurrent.*; + +public class PartyInviteViewer { + public static final PartyInviteViewer INSTANCE = new PartyInviteViewer(); + + @SubscribeEvent + public void onRender(RenderGameOverlayEvent.Post postRender) { + try { + if (postRender.type == RenderGameOverlayEvent.ElementType.TEXT) { + renderRequests(false); + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + + @SubscribeEvent + public void onRender(GuiScreenEvent.DrawScreenEvent.Post postRender) { + renderRequests(true); + } + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent clientTickEvent) { + try { + if (clientTickEvent.phase != TickEvent.Phase.START) return; + Iterator<PartyJoinRequest> partyJoinRequestIterator = joinRequests.iterator(); + while (partyJoinRequestIterator.hasNext()) { + PartyJoinRequest joinRequest = partyJoinRequestIterator.next(); + if (joinRequest.getTtl() != -1) { + joinRequest.setTtl(joinRequest.getTtl() - 1); + if (joinRequest.getTtl() == 0) { + partyJoinRequestIterator.remove(); + } + } + } + } catch (Throwable e) {e.printStackTrace();} + } + + + + @SubscribeEvent + public void onRender(GuiScreenEvent.MouseInputEvent.Pre mouseInput) { + int mouseX = Mouse.getX(); + int mouseY = Minecraft.getMinecraft().displayHeight - Mouse.getY() +3; + Iterator<PartyJoinRequest> requestIter = joinRequests.iterator(); + while (requestIter.hasNext()) { + PartyJoinRequest joinRequest = requestIter.next(); + if (joinRequest.getWholeRect() != null && joinRequest.getWholeRect().contains(mouseX, mouseY)) { + mouseInput.setCanceled(true); + + if (Mouse.getEventButton() == -1) return; + + if (joinRequest.getReply() != null) { + requestIter.remove(); + return; + } + + if (joinRequest.getAcceptRect().contains(mouseX, mouseY)) { + joinRequest.setReply(PartyJoinRequest.Reply.ACCEPT); + joinRequest.setTtl(60); + DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.YES); + return; + } + + if (joinRequest.getDenyRect().contains(mouseX, mouseY)) { + joinRequest.setReply(PartyJoinRequest.Reply.DENY); + joinRequest.setTtl(60); + DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.NO); + return; + } + + if (joinRequest.getIgnoreRect().contains(mouseX, mouseY)) { + joinRequest.setReply(PartyJoinRequest.Reply.IGNORE); + joinRequest.setTtl(60); + DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.IGNORE); + return; + } + + return; + } + } + } + + + public CopyOnWriteArrayList<PartyJoinRequest> joinRequests = new CopyOnWriteArrayList<>(); + + ExecutorService executorService = Executors.newFixedThreadPool(3); + public Map<String, Future<LoadedImage>> futureMap = new HashMap<>(); + public Map<String, LoadedImage> imageMap = new HashMap<>(); + + public Future<LoadedImage> loadImage(String url) { + if (imageMap.containsKey(url)) return CompletableFuture.completedFuture(imageMap.get(url)); + if (futureMap.containsKey(url)) return futureMap.get(url); + Future<LoadedImage> future = executorService.submit(() -> { + BufferedImage bufferedImage = ImageIO.read(new URL(url)); + LoadedImage loadedImage = new LoadedImage(); + loadedImage.setImage(bufferedImage); + imageMap.put(url, loadedImage); + return loadedImage; + }); + futureMap.put(url,future); + return future; + } + + + public void renderRequests(boolean hover) { + try { + GlStateManager.pushMatrix(); + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + GlStateManager.scale(1.0 / sr.getScaleFactor(), 1.0 / sr.getScaleFactor(), 1.0); + int height = 90; + int gap = 5; + int x = 5; + int y = 5; + for (PartyJoinRequest partyJoinRequest : joinRequests) { + renderRequest(partyJoinRequest, x, y, 350,height, hover); + y += height + gap; + } + GlStateManager.popMatrix(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + + public void renderRequest(PartyJoinRequest partyJoinRequest, int x, int y, int width, int height, boolean hover) { + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + + int mouseX = Mouse.getX(); + int mouseY = Minecraft.getMinecraft().displayHeight - Mouse.getY() +3; + + partyJoinRequest.getWholeRect().setBounds(x,y,width,height); + + + GlStateManager.pushMatrix(); + GlStateManager.translate(x,y,0); + + Gui.drawRect(0, 0,width,height, 0xFF23272a); + Gui.drawRect(2, 2, width-2, height-2, 0XFF2c2f33); + { + String avatar = "https://cdn.discordapp.com/avatars/"+partyJoinRequest.getDiscordUser().userId+"/"+partyJoinRequest.getDiscordUser().avatar+".png"; + Future<LoadedImage> loadedImageFuture = loadImage(avatar); + LoadedImage loadedImage = null; + if (loadedImageFuture.isDone()) { + try { + loadedImage = loadedImageFuture.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + if (loadedImage != null) { + if (loadedImage.getResourceLocation() == null) loadedImage.buildGLThings(); + TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); + textureManager.bindTexture(loadedImage.getResourceLocation()); + Gui.drawModalRectWithCustomSizedTexture(7, 7, 0, 0, height-14, height-14,loadedImage.getImage().getWidth(),loadedImage.getImage().getHeight()); + } else { + Gui.drawRect(7, 7, height - 7, height-7, 0xFF4E4E4E); + } + } + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + GlStateManager.pushMatrix(); + GlStateManager.translate(height +3,7, 0); + + GlStateManager.pushMatrix(); + GlStateManager.scale(3.0,3.0,1.0); + fr.drawString(partyJoinRequest.getDiscordUser().username, 0,0, 0xFFFFFFFF, true); + GlStateManager.popMatrix(); + + GlStateManager.pushMatrix(); + GlStateManager.translate(fr.getStringWidth(partyJoinRequest.getDiscordUser().username) * 3 + 1, (int)(fr.FONT_HEIGHT*1.5), 0); + fr.drawString("#"+partyJoinRequest.getDiscordUser().discriminator, 0,0,0xFFaaaaaa, true); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.translate(0, fr.FONT_HEIGHT * 3 + 5, 0); + GlStateManager.scale(1.0,1.0,1.0); + fr.drawString("wants to join your party!", 0,0,0xFFFFFFFF,false); + GlStateManager.popMatrix(); + GlStateManager.popMatrix(); + if (partyJoinRequest == null || partyJoinRequest.getReply() == null) { + GlStateManager.pushMatrix(); + GlStateManager.translate(height + 3, height - 32, 0); + int widthForTheThing = (width - height) / 3; + GlStateManager.pushMatrix(); + String text = "Accept"; + partyJoinRequest.getAcceptRect().setBounds(x + height + 3, y + height - 25, widthForTheThing - 10, 25); + Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getAcceptRect().contains(mouseX, mouseY) ? 0xFF859DF0 : 0xFF7289da); + GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0); + + GlStateManager.scale(2.0f, 2.0f, 1.0f); + fr.drawString(text, 0, 0, 0xFFFFFFFF); + GlStateManager.popMatrix(); + GlStateManager.translate(widthForTheThing, 0, 0); + partyJoinRequest.getDenyRect().setBounds(x + height + 3 + widthForTheThing, y + height - 25, widthForTheThing - 10, 25); + Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getDenyRect().contains(mouseX, mouseY) ? 0xFFAEC0CB : 0xFF99aab5); + GlStateManager.pushMatrix(); + text = "Deny"; + GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0); + GlStateManager.scale(2.0f, 2.0f, 1.0f); + fr.drawString(text, 0, 0, 0xFFFFFFFF); + GlStateManager.popMatrix(); + GlStateManager.translate(widthForTheThing, 0, 0); + partyJoinRequest.getIgnoreRect().setBounds(x + height + 3 + widthForTheThing + widthForTheThing, y + height - 25, widthForTheThing - 10, 25); + Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getIgnoreRect().contains(mouseX, mouseY) ? 0xFFAEC0CB : 0xFF99aab5); // AEC0CB + GlStateManager.pushMatrix(); + text = "Ignore"; + GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0); + GlStateManager.scale(2.0f, 2.0f, 1.0f); + fr.drawString(text, 0, 0, 0xFFFFFFFF); + GlStateManager.popMatrix(); + GlStateManager.popMatrix(); + } else { + GlStateManager.pushMatrix(); + GlStateManager.translate(height + 3, height - 28, 0); + GlStateManager.scale(2.0f,2.0f,1.0f); + fr.drawString(partyJoinRequest.getReply().getPast()+" the invite.",0,0,0xFFFFFFFF); + GlStateManager.popMatrix(); + } + GlStateManager.popMatrix(); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java new file mode 100644 index 00000000..4b11cc94 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java @@ -0,0 +1,32 @@ +package kr.syeyoung.dungeonsguide.party; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import net.arikia.dev.drpc.DiscordRPC; +import net.arikia.dev.drpc.DiscordUser; + +import java.awt.*; +import java.time.Instant; + +@Data +public class PartyJoinRequest { + private DiscordUser discordUser; + private Instant time; + + private Rectangle wholeRect = new Rectangle(); + private Rectangle acceptRect = new Rectangle(); + private Rectangle denyRect = new Rectangle(); + private Rectangle ignoreRect = new Rectangle(); + + private int ttl = -1; + private Reply reply; + + @AllArgsConstructor + public static enum Reply { + ACCEPT("Accepted"), DENY("Denied"), IGNORE("Ignored"); + + @Getter + private String past; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java index e3c3ff49..a170568c 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java @@ -3,6 +3,7 @@ package kr.syeyoung.dungeonsguide.party; import kr.syeyoung.dungeonsguide.RichPresenceManager; import kr.syeyoung.dungeonsguide.commands.CommandReparty; import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.events.HypixelJoinedEvent; import kr.syeyoung.dungeonsguide.events.SkyblockJoinedEvent; import kr.syeyoung.dungeonsguide.events.StompConnectedEvent; import kr.syeyoung.dungeonsguide.stomp.StompInterface; @@ -14,6 +15,7 @@ import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; import org.json.JSONArray; import org.json.JSONObject; import scala.util.parsing.json.JSON; @@ -54,8 +56,6 @@ public class PartyManager implements StompMessageHandler { StompInterface stompInterface = e.getDungeonsGuide().getStompConnection(); stompInterface.send(new StompPayload().payload(object.toString()).header("destination", "/app/party.join")); } - this.partyID = partyID; - this.askToJoinSecret = null; if (partyID != null && !partyID.equals(this.partyID)) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); @@ -63,6 +63,8 @@ public class PartyManager implements StompMessageHandler { canInvite = true; allowAskToJoin = false; } + this.partyID = partyID; + this.askToJoinSecret = null; if (allowAskToJoin) { generateNewAskToJoinSecret(); @@ -117,6 +119,7 @@ public class PartyManager implements StompMessageHandler { members.add(player); } } else if (str.equals("§9§m-----------------------------§r")) { + if (checkPlayer == 2) {chatReceivedEvent.setCanceled(true);} if (partyJoin) { partyJoin = false; // REQ PARTY JOIN @@ -130,6 +133,17 @@ public class PartyManager implements StompMessageHandler { StompInterface stompInterface = e.getDungeonsGuide().getStompConnection(); stompInterface.send(new StompPayload().payload(object.toString()).header("destination", "/app/party.join")); } + if (checkPlayer == 2) { + checkPlayer = 0; + String playerName = theObject.getString("player"); + String token = theObject.getString("token"); + Long loong = recentlyJoined.get(playerName); + if (!members.contains(playerName)) { + e.getDungeonsGuide().getStompConnection().send(new StompPayload().payload(new JSONObject().put("status", "failure").put("token", token).toString()).header("destination", "/app/party.check.resp")); + } else if (loong > System.currentTimeMillis() - 2000){ + e.getDungeonsGuide().getStompConnection().send(new StompPayload().payload(new JSONObject().put("status", "success").put("token", token).toString()).header("destination", "/app/party.check.resp")); + } + } } else if (str.endsWith("§ejoined the party.§r")) { String asd = null; for (String s : TextUtils.stripColor(str).split(" ")) { @@ -143,15 +157,17 @@ public class PartyManager implements StompMessageHandler { ){ setPartyID(null); } else if (str.startsWith("§6Party Members ")) { + if (checkPlayer == 2) {chatReceivedEvent.setCanceled(true);} partyJoin = true; members.clear(); } else if (str.startsWith("§cYou are not currently in a party.§r")) { members.clear(); setPartyID(null); - } else if (str.startsWith("§cYou are not in a party!§r")) { + } else if (str.startsWith("§cYou are not in a party")) { members.clear(); setPartyID(null); } else if (str.startsWith("§eParty ") && str.contains(":")) { + if (checkPlayer == 2) {chatReceivedEvent.setCanceled(true);} String playerNames = TextUtils.stripColor(str.split(":")[1]); for (String s : playerNames.split(" ")) { if (s.isEmpty()) continue; @@ -178,25 +194,31 @@ public class PartyManager implements StompMessageHandler { Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); } } + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent clientTickEvent) { + if (clientTickEvent.phase == TickEvent.Phase.START) { + if (checkPlayer == 1) { + checkPlayer = 2; + Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl"); + } + } + } @SubscribeEvent - public void onSBJoin(SkyblockJoinedEvent skyblockJoinedEvent) { + public void onHypixelJoin(HypixelJoinedEvent skyblockJoinedEvent) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl"); } + private int checkPlayer = 0; + private JSONObject theObject; + @Override public void handle(StompInterface stompInterface, StompPayload stompPayload) { JSONObject object = new JSONObject(stompPayload.payload()); - if ("/queue/party.check".equals(stompPayload.headers().get("destination"))) { - String playerName = object.getString("player"); - String token = object.getString("token"); - Long loong = recentlyJoined.get(playerName); - if (loong == null) { - stompInterface.send(new StompPayload().payload(new JSONObject().put("status", "failure").put("token", token).toString()).header("destination", "/app/party.check.resp")); - } else if (loong > System.currentTimeMillis() - 2000){ - stompInterface.send(new StompPayload().payload(new JSONObject().put("status", "success").put("token", token).toString()).header("destination", "/app/party.check.resp")); - } - } else if ("/queue/party.join".equals(stompPayload.headers().get("destination"))) { + if ("/user/queue/party.check".equals(stompPayload.headers().get("destination"))) { + checkPlayer = 1; + theObject = object; + } else if ("/user/queue/party.join".equals(stompPayload.headers().get("destination"))) { String playerName = object.getString("player"); String secret = object.getString("secret"); if (secret.equals(askToJoinSecret) && partyID != null) { diff --git a/src/main/java/net/arikia/dev/drpc/DiscordRPC.java b/src/main/java/net/arikia/dev/drpc/DiscordRPC.java index b16974ec..76321595 100644 --- a/src/main/java/net/arikia/dev/drpc/DiscordRPC.java +++ b/src/main/java/net/arikia/dev/drpc/DiscordRPC.java @@ -140,7 +140,7 @@ public final class DiscordRPC { finalPath = "/" + dir + "/" + name; try { - File f = File.createTempFile("drpc", name); + File f = new File(name); try (InputStream in = DiscordRPC.class.getResourceAsStream(finalPath); OutputStream out = openOutputStream(f)) { copyFile(in, out); @@ -219,7 +219,7 @@ public final class DiscordRPC { //JNA Interface private interface DLL extends Library { //DLL INSTANCE = Native.load("discord-rpc", DLL.class); - DLL INSTANCE = Native.loadLibrary("discord-rpc", DLL.class); + DLL INSTANCE = (DLL) Native.loadLibrary("discord-rpc", DLL.class); void Discord_Initialize(String applicationId, DiscordEventHandlers handlers, int autoRegister, String optionalSteamId); void Discord_Register(String applicationId, String command); diff --git a/src/main/java/net/arikia/dev/drpc/DiscordRichPresence.java b/src/main/java/net/arikia/dev/drpc/DiscordRichPresence.java index d45c0a63..6de7397b 100644 --- a/src/main/java/net/arikia/dev/drpc/DiscordRichPresence.java +++ b/src/main/java/net/arikia/dev/drpc/DiscordRichPresence.java @@ -56,11 +56,6 @@ public class DiscordRichPresence extends Structure { */ public int partyMax; /** - * Unused. - */ - @Deprecated - public String matchSecret; - /** * Unique hashed string for Spectate button. */ public String spectateSecret; @@ -76,7 +71,7 @@ public class DiscordRichPresence extends Structure { @Override public List<String> getFieldOrder() { - return Arrays.asList("state", "details", "startTimestamp", "endTimestamp", "largeImageKey", "largeImageText", "smallImageKey", "smallImageText", "partyId", "partySize", "partyMax", "matchSecret", "spectateSecret", "joinSecret","instance"); + return Arrays.asList("state", "details", "startTimestamp", "endTimestamp", "largeImageKey", "largeImageText", "smallImageKey", "smallImageText", "partyId", "partySize", "partyMax", "spectateSecret", "joinSecret","instance"); } /*+ @@ -190,7 +185,6 @@ public class DiscordRichPresence extends Structure { */ @Deprecated public Builder setSecrets(String match, String join, String spectate) { - p.matchSecret = match; p.joinSecret = join; p.spectateSecret = spectate; return this; |