diff options
Diffstat (limited to 'src/main/java/kr/syeyoung')
5 files changed, 84 insertions, 58 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java index 969da396..7f02d69a 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java @@ -69,7 +69,13 @@ public class RichPresenceManager implements Runnable { callbacks = new IDiscordActivityEvents.ByReference(); callbacks.OnActivityInvite = (eventData, type, user, activity) -> { + PartyJoinRequest partyJoinRequest = new PartyJoinRequest(); + partyJoinRequest.setDiscordUser(user); + partyJoinRequest.setExpire(System.currentTimeMillis() + 30000); + partyJoinRequest.setInvite(true); + PartyInviteViewer.INSTANCE.joinRequests.add(partyJoinRequest); + System.out.println("Received Join Request from "+user.id.longValue()+" ("+partyJoinRequest.getUsername()+"#"+partyJoinRequest.getDiscriminator()+")"); }; callbacks.OnActivityJoin = (eventData, secret) -> {DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload().method(StompHeader.SEND) .header("destination", "/app/party.askedtojoin") @@ -105,8 +111,13 @@ public class RichPresenceManager implements Runnable { activityManager = iDiscordCore.GetActivityManager.getActivityManager(iDiscordCore); latestDiscordActivity = new DiscordActivity(); latestDiscordActivity.assets = new DiscordActivityAssets(); + latestDiscordActivity.secrets = new DiscordActivitySecrets(); + latestDiscordActivity.party = new DiscordActivityParty(); + latestDiscordActivity.party.discordActivityParty = new DiscordPartySize(); + latestDiscordActivity.timestamps = new DiscordActivityTimestamps(); GameSDK.writeString(latestDiscordActivity.assets.large_image, "mort"); GameSDK.writeString(latestDiscordActivity.assets.large_text, "mort"); + return true; } @@ -120,12 +131,16 @@ public class RichPresenceManager implements Runnable { }); } + public void accept(DiscordSnowflake userID) { + activityManager.AcceptInvite.acceptInvite(activityManager, userID, Pointer.NULL, (callbackData, result) -> { + System.out.println("Discord Returned "+result+" For Accepting invite from "+userID.longValue()+"L"); + }); + } public void updatePresence() { if (!skyblockStatus.isOnHypixel() || !FeatureRegistry.ADVANCED_RICHPRESENCE.isEnabled() || (!skyblockStatus.isOnSkyblock() && FeatureRegistry.ADVANCED_RICHPRESENCE.<Boolean>getParameter("disablenotskyblock").getValue())) { activityManager.ClearActivity.clearActivity(activityManager, Pointer.NULL, new NativeGameSDK.DiscordCallback() { @Override public void callback(Pointer callbackData, EDiscordResult result) { - System.out.println("Discord Returned "+result+" For Clearing RPC"); } }); } else { @@ -135,21 +150,13 @@ public class RichPresenceManager implements Runnable { GameSDK.writeString(latestDiscordActivity.state, name); - if (PartyManager.INSTANCE.getPartyID() != null) { - if (latestDiscordActivity.party == null) latestDiscordActivity.party = new DiscordActivityParty(); - GameSDK.writeString(latestDiscordActivity.party.id, PartyManager.INSTANCE.getPartyID()); - if (latestDiscordActivity.party.discordActivityParty == null) latestDiscordActivity.party.discordActivityParty = new DiscordPartySize(); + GameSDK.writeString(latestDiscordActivity.party.id, PartyManager.INSTANCE.getPartyID() == null ? "" : PartyManager.INSTANCE.getPartyID()); latestDiscordActivity.party.discordActivityParty.current_size = new Int32(PartyManager.INSTANCE.getMemberCount()); latestDiscordActivity.party.discordActivityParty.max_size = new Int32(PartyManager.INSTANCE.getMaxParty()); - } else { - latestDiscordActivity.party = null; - } - GameSDK.writeString(latestDiscordActivity.state, name); + if (skyblockStatus.getContext() != null) { DungeonContext dungeonContext = skyblockStatus.getContext(); long init = dungeonContext.getInit(); - if (latestDiscordActivity.timestamps == null) - latestDiscordActivity.timestamps = new DiscordActivityTimestamps(); latestDiscordActivity.timestamps.start = new DiscordTimestamp(init); if (dungeonContext.getBossfightProcessor() != null) { @@ -158,20 +165,17 @@ public class RichPresenceManager implements Runnable { GameSDK.writeString(latestDiscordActivity.details, "Clearing Rooms"); } } else { - latestDiscordActivity.timestamps = null; + latestDiscordActivity.timestamps.start = new DiscordTimestamp(0); GameSDK.writeString(latestDiscordActivity.details, "Dungeons Guide"); } if (PartyManager.INSTANCE.isAllowAskToJoin()) { - if (latestDiscordActivity.secrets == null) - latestDiscordActivity.secrets = new DiscordActivitySecrets(); GameSDK.writeString(latestDiscordActivity.secrets.join, PartyManager.INSTANCE.getAskToJoinSecret()); } else { - latestDiscordActivity.secrets = null; + GameSDK.writeString(latestDiscordActivity.secrets.join, ""); } activityManager.UpdateActivity.updateActivity(activityManager, latestDiscordActivity, Pointer.NULL, new NativeGameSDK.DiscordCallback() { @Override public void callback(Pointer callbackData, EDiscordResult result) { - System.out.println("Discord Returned "+result+" For Setting new RPC"); } }); } @@ -182,9 +186,9 @@ public class RichPresenceManager implements Runnable { setupSuccessful = setup(); if (!setupSuccessful) return; while(!Thread.interrupted()) { - iDiscordCore.RunCallbacks.runCallbacks(iDiscordCore); - updatePresence(); try { + iDiscordCore.RunCallbacks.runCallbacks(iDiscordCore); + updatePresence(); Thread.sleep(300L); } catch (Exception e) {e.printStackTrace();} } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java index 87cd6862..d2960b2a 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java @@ -39,6 +39,7 @@ import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.features.impl.party.playerpreview.FeatureViewPlayerOnJoin; import kr.syeyoung.dungeonsguide.features.impl.party.api.ApiFetchur; +import kr.syeyoung.dungeonsguide.party.PartyInviteViewer; import kr.syeyoung.dungeonsguide.party.PartyManager; import kr.syeyoung.dungeonsguide.roomedit.EditingContext; import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonRoomEdit; @@ -395,6 +396,8 @@ public class CommandDungeonsGuide extends CommandBase { cosmeticsManager.requestCosmeticsList(); cosmeticsManager.requestActiveCosmetics(); StaticResourceCache.INSTANCE.purgeCache(); + PartyInviteViewer.INSTANCE.imageMap.clear(); + PartyInviteViewer.INSTANCE.futureMap.clear(); sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully purged API Cache!")); } else if (args[0].equals("pbroadcast")) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java b/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java index 0f591f22..ee4dd1f8 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java @@ -83,11 +83,12 @@ public class GameSDK { public static void writeString(byte[] bts, String str) { System.arraycopy(str.getBytes(), 0, bts, 0, str.getBytes().length); + bts[str.getBytes().length] = 0; } public static String readString(byte[] bts) { int i; for (i = 0; i < bts.length && bts[i] != 0; i++); - byte[] asdasd = new byte[i+1]; + byte[] asdasd = new byte[i]; System.arraycopy(bts, 0, asdasd, 0, i); return new String(asdasd); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java index 8588fca1..8dbdf2bb 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java @@ -39,6 +39,7 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; import javax.imageio.ImageIO; +import java.awt.*; import java.awt.image.BufferedImage; import java.net.HttpURLConnection; import java.net.URL; @@ -105,25 +106,40 @@ public class PartyInviteViewer { return; } - if (joinRequest.getAcceptRect().contains(mouseX, mouseY)) { - joinRequest.setReply(PartyJoinRequest.Reply.ACCEPT); - joinRequest.setTtl(60); - RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_Yes); - return; - } + if (!joinRequest.isInvite()) { + if (joinRequest.getAcceptRect().contains(mouseX, mouseY)) { + joinRequest.setReply(PartyJoinRequest.Reply.ACCEPT); + joinRequest.setTtl(60); + RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_Yes); + return; + } - if (joinRequest.getDenyRect().contains(mouseX, mouseY)) { - joinRequest.setReply(PartyJoinRequest.Reply.DENY); - joinRequest.setTtl(60); - RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_No); - return; - } + if (joinRequest.getDenyRect().contains(mouseX, mouseY)) { + joinRequest.setReply(PartyJoinRequest.Reply.DENY); + joinRequest.setTtl(60); + RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_No); + return; + } - if (joinRequest.getIgnoreRect().contains(mouseX, mouseY)) { - joinRequest.setReply(PartyJoinRequest.Reply.IGNORE); - joinRequest.setTtl(60); - RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_Ignore); - return; + if (joinRequest.getIgnoreRect().contains(mouseX, mouseY)) { + joinRequest.setReply(PartyJoinRequest.Reply.IGNORE); + joinRequest.setTtl(60); + RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_Ignore); + return; + } + } else { + if (joinRequest.getAcceptRect().contains(mouseX, mouseY)) { + joinRequest.setReply(PartyJoinRequest.Reply.ACCEPT); + joinRequest.setTtl(60); + RichPresenceManager.INSTANCE.accept(joinRequest.getDiscordUser().id); + return; + } + + if (joinRequest.getDenyRect().contains(mouseX, mouseY)) { + joinRequest.setReply(PartyJoinRequest.Reply.DENY); + joinRequest.setTtl(60); + return; + } } return; @@ -147,8 +163,12 @@ public class PartyInviteViewer { HttpURLConnection huc = (HttpURLConnection) urlObj.openConnection(); huc.addRequestProperty("User-Agent", "DungeonsGuideMod (dungeons.guide, 1.0)"); BufferedImage bufferedImage = ImageIO.read(huc.getInputStream()); + BufferedImage newImage = new BufferedImage(128,128, BufferedImage.TYPE_INT_RGB); + Graphics g = newImage.createGraphics(); + g.drawImage(bufferedImage, 0, 0, 128, 128, null); + g.dispose(); LoadedImage loadedImage = new LoadedImage(); - loadedImage.setImage(bufferedImage); + loadedImage.setImage(newImage); imageMap.put(url, loadedImage); return loadedImage; } catch (Exception e) { @@ -196,7 +216,7 @@ public class PartyInviteViewer { 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().id.longValue()+"/"+partyJoinRequest.getAvatar()+".png"; + String avatar = "https://cdn.discordapp.com/avatars/"+Long.toUnsignedString(partyJoinRequest.getDiscordUser().id.longValue())+"/"+partyJoinRequest.getAvatar()+"."+(partyJoinRequest.getAvatar().startsWith("a_") ? "gif":"png"); Future<LoadedImage> loadedImageFuture = loadImage(avatar); LoadedImage loadedImage = null; if (loadedImageFuture.isDone()) { @@ -211,19 +231,9 @@ public class PartyInviteViewer { TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); textureManager.bindTexture(loadedImage.getResourceLocation()); - - GlStateManager.disableLighting(); GlStateManager.color(1, 1, 1, 1.0F); - GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); - GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); - - Gui.drawModalRectWithCustomSizedTexture(7, 7, 0, 0, height-14, height-14,loadedImage.getImage().getWidth(),loadedImage.getImage().getHeight()); - - - GlStateManager.enableLighting(); - GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); - GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); + Gui.drawScaledCustomSizeModalRect(7, 7, 0, 0, loadedImage.getImage().getWidth(),loadedImage.getImage().getHeight(),height-14,height-14, loadedImage.getImage().getWidth(), loadedImage.getImage().getHeight()); } else { Gui.drawRect(7, 7, height - 7, height-7, 0xFF4E4E4E); } @@ -248,6 +258,9 @@ public class PartyInviteViewer { GlStateManager.pushMatrix(); GlStateManager.translate(0, fr.FONT_HEIGHT * 3 + 5, 0); GlStateManager.scale(1.0,1.0,1.0); + if (partyJoinRequest.isInvite()) + fr.drawString("§ewants to you to join their party! ("+(TextUtils.formatTime(partyJoinRequest.getExpire() - System.currentTimeMillis()))+")", 0,0,0xFFFFFFFF,false); + else fr.drawString("wants to join your party! ("+(TextUtils.formatTime(partyJoinRequest.getExpire() - System.currentTimeMillis()))+")", 0,0,0xFFFFFFFF,false); GlStateManager.popMatrix(); GlStateManager.popMatrix(); @@ -279,18 +292,21 @@ public class PartyInviteViewer { GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); fr.drawString(text, 0, 0, 0xFFFFFFFF); GlStateManager.popMatrix(); + if (!partyJoinRequest.isInvite()) { 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); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - fr.drawString(text, 0, 0, 0xFFFFFFFF); - GlStateManager.popMatrix(); + + 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); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + fr.drawString(text, 0, 0, 0xFFFFFFFF); + GlStateManager.popMatrix(); + } GlStateManager.popMatrix(); } else { GlStateManager.pushMatrix(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java index ac2b9561..a894ee4e 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java @@ -35,6 +35,7 @@ public class PartyJoinRequest { username = GameSDK.readString(discordUser.username); discriminator = GameSDK.readString(discordUser.discriminator); avatar = GameSDK.readString(discordUser.avatar); + System.out.println(username+"/"+discriminator+"/"+avatar); } private String username, discriminator, avatar; @@ -45,6 +46,7 @@ public class PartyJoinRequest { private Rectangle denyRect = new Rectangle(); private Rectangle ignoreRect = new Rectangle(); + private boolean isInvite; private int ttl = -1; private Reply reply; |