diff options
Diffstat (limited to 'src/main')
7 files changed, 49 insertions, 37 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java index c8c96940..4875029d 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java @@ -114,16 +114,12 @@ public class DungeonsGuide implements DGInterface, CloseListener { MinecraftForge.EVENT_BUS.register(commandDungeonsGuide); commandReparty = new CommandReparty(); - if (FeatureRegistry.ETC_REPARTY.isEnabled()) - ClientCommandHandler.instance.registerCommand(commandReparty); - MinecraftForge.EVENT_BUS.register(commandReparty); + MinecraftForge.EVENT_BUS.register(new FeatureListener()); MinecraftForge.EVENT_BUS.register(new PacketListener()); MinecraftForge.EVENT_BUS.register(new Keybinds()); - RichPresenceManager.INSTANCE.getLastSetupCode(); - MinecraftForge.EVENT_BUS.register(RichPresenceManager.INSTANCE); MinecraftForge.EVENT_BUS.register(PartyManager.INSTANCE); MinecraftForge.EVENT_BUS.register(StaticResourceCache.INSTANCE); @@ -155,6 +151,13 @@ public class DungeonsGuide implements DGInterface, CloseListener { } catch (IOException e) { e.printStackTrace(); } + + if (FeatureRegistry.ETC_REPARTY.isEnabled()) + ClientCommandHandler.instance.registerCommand(commandReparty); + if (FeatureRegistry.DISCORD_DONOTUSE.isEnabled()) + System.setProperty("dg.safe", "true"); + MinecraftForge.EVENT_BUS.register(RichPresenceManager.INSTANCE); + ProgressManager.pop(progressbar); } @Getter diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java index 7e27c584..08f01248 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java @@ -318,6 +318,10 @@ public class CommandDungeonsGuide extends CommandBase { // } // } } else if (args[0].equalsIgnoreCase("asktojoin") || args[0].equalsIgnoreCase("atj")) { + if (RichPresenceManager.INSTANCE.getLastSetupCode() == -9999) { + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §cDiscord GameSDK has been disabled, or it failed to load!")); + return; + } if (!PartyManager.INSTANCE.isCanInvite()) { sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §cYou don't have perms in the party to invite people!")); } else { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java index 55e2753b..0fac0dba 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java @@ -86,6 +86,7 @@ public class FeatureRegistry { }); public static final PartyInviteViewer DISCORD_ASKTOJOIN = register(new PartyInviteViewer()); public static final PlayingDGAlarm DISCORD_ONLINEALARM = register(new PlayingDGAlarm()); + public static final SimpleFeature DISCORD_DONOTUSE = register(new SimpleFeature("Discord", "Disable Native Library", "Disables usage of jna for discord rpc support.\nBreaks any discord related feature in the mod.\nRequires mod restart to get affected.\n\nThis feature is only for those whose minecraft crashes due to discord gamesdk crash.", "discord.rpc", false)); public static final SimpleFeature SOLVER_RIDDLE = register(new SimpleFeature("Solver.Any Floor", "Riddle", "Highlights the correct box after clicking on all 3 weirdos", "solver.riddle")); 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 b73a2024..23c8e253 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 @@ -25,6 +25,7 @@ import kr.syeyoung.dungeonsguide.features.impl.discord.invteTooltip.MTooltipInvi 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; import net.minecraft.client.Minecraft; @@ -40,6 +41,7 @@ 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; @@ -116,7 +118,11 @@ public class PanelPartyFinder extends MPanel { discordInvite = new MButton(); discordInvite.setText("Invite Discord Friends"); discordInvite.setOnActionPerformed(() -> { - if (PartyManager.INSTANCE.isAllowAskToJoin()) { + if (RichPresenceManager.INSTANCE.getLastSetupCode() == -9999) { + 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()) { MTooltipInvite mTooltipInvite = new MTooltipInvite(); mTooltipInvite.setScale( new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); mTooltipInvite.open(this); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java b/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java index ee4dd1f8..39885ab9 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gamesdk/GameSDK.java @@ -46,7 +46,7 @@ public class GameSDK { static { try { - extractLibrary(); + if (System.getProperty("dg.safe") == null) extractLibrary(); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java index 3ac637c9..fdeab870 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java @@ -114,10 +114,8 @@ public class PartyManager implements StompMessageHandler { this.partyID = partyID; this.askToJoinSecret = null; - if (allowAskToJoin) { + if (allowAskToJoin && RichPresenceManager.INSTANCE.getLastSetupCode() != -9999) { generateNewAskToJoinSecret(); - } else { - RichPresenceManager.INSTANCE.updatePresence(); } } @@ -137,7 +135,6 @@ public class PartyManager implements StompMessageHandler { StompInterface stompInterface = DungeonsGuide.getDungeonsGuide().getStompConnection(); stompInterface.send(new StompPayload().payload(new JSONObject().put("secret", askToJoinSecret).toString()).header("destination", "/app/party.setjoinsecret")); - RichPresenceManager.INSTANCE.updatePresence(); } private int partyJoin =0; @@ -284,7 +281,6 @@ public class PartyManager implements StompMessageHandler { canInvite = false; allowAskToJoin = false; askToJoinSecret = ""; - RichPresenceManager.INSTANCE.updatePresence(); } else if (str.equals("§cCouldn't find a player with that name!§r")) { canInvite = true; if (invitedDash > 0) invitedDash = 3; @@ -299,7 +295,6 @@ public class PartyManager implements StompMessageHandler { canInvite = false; allowAskToJoin = false; askToJoinSecret = ""; - RichPresenceManager.INSTANCE.updatePresence(); 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 diff --git a/src/main/java/kr/syeyoung/dungeonsguide/rpc/RichPresenceManager.java b/src/main/java/kr/syeyoung/dungeonsguide/rpc/RichPresenceManager.java index e19a6fad..598b3e49 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/rpc/RichPresenceManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/rpc/RichPresenceManager.java @@ -62,9 +62,12 @@ public class RichPresenceManager implements Runnable { @Getter private Map<Long, JDiscordRelation> relationMap = new HashMap<>(); + private boolean ready = false; + @Getter private int lastSetupCode = -99999; public int setup() { + ready = false; if (iDiscordCore != null) { iDiscordCore.Destroy.destroy(iDiscordCore); iDiscordCore = null; @@ -106,23 +109,27 @@ public class RichPresenceManager implements Runnable { relation_callbacks = new IDiscordRelationshipEvents.ByReference(); relation_callbacks.OnRefresh = (p) -> { - IDiscordRelationshipManager iDiscordRelationshipManager = iDiscordCore.GetRelationshipManager.getRelationshipManager(iDiscordCore); - iDiscordRelationshipManager.Filter.filter(iDiscordRelationshipManager, Pointer.NULL, (d, relation) -> true); - IntByReference intByReference = new IntByReference(); - iDiscordRelationshipManager.Count.count(iDiscordRelationshipManager, intByReference); - int count = intByReference.getValue(); - for (int i = 0; i < count; i++) { - DiscordRelationship discordRelationship = new DiscordRelationship(); - iDiscordRelationshipManager.GetAt.getAt(iDiscordRelationshipManager, new UInt32(i), discordRelationship); - - JDiscordRelation jDiscordRelation = JDiscordRelation.fromJNA(discordRelationship); - relationMap.put(jDiscordRelation.getDiscordUser().getId(), jDiscordRelation); - } + try { + ready = true; + IDiscordRelationshipManager iDiscordRelationshipManager = iDiscordCore.GetRelationshipManager.getRelationshipManager(iDiscordCore); + iDiscordRelationshipManager.Filter.filter(iDiscordRelationshipManager, Pointer.NULL, (d, relation) -> true); + IntByReference intByReference = new IntByReference(); + iDiscordRelationshipManager.Count.count(iDiscordRelationshipManager, intByReference); + int count = intByReference.getValue(); + relationMap.clear(); + for (int i = 0; i < count; i++) { + DiscordRelationship discordRelationship = new DiscordRelationship(); + iDiscordRelationshipManager.GetAt.getAt(iDiscordRelationshipManager, new UInt32(i), discordRelationship); + + JDiscordRelation jDiscordRelation = JDiscordRelation.fromJNA(discordRelationship); + relationMap.put(jDiscordRelation.getDiscordUser().getId(), jDiscordRelation); + } + } catch (Throwable e) {e.printStackTrace();} }; relation_callbacks.OnRelationshipUpdate = (p, rel) -> { - JDiscordRelation jDiscordRelation = JDiscordRelation.fromJNA(rel); - JDiscordRelation prev = relationMap.put(jDiscordRelation.getDiscordUser().getId(), jDiscordRelation); try { + JDiscordRelation jDiscordRelation = JDiscordRelation.fromJNA(rel); + JDiscordRelation prev = relationMap.put(jDiscordRelation.getDiscordUser().getId(), jDiscordRelation); MinecraftForge.EVENT_BUS.post(new DiscordUserUpdateEvent(prev, jDiscordRelation)); } catch (Throwable t) { t.printStackTrace(); @@ -157,22 +164,21 @@ public class RichPresenceManager implements Runnable { private final SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus(); public void respond(DiscordSnowflake userID, EDiscordActivityJoinRequestReply reply) { + if (activityManager == null) return; activityManager.SendRequestReply.sendRequestReply(activityManager, userID, reply, Pointer.NULL, (callbackData, result) -> { System.out.println("Discord Returned "+result+" For Replying "+reply+" To "+userID.longValue()+"L"); }); } public void accept(DiscordSnowflake userID) { + if (activityManager == null) return; 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.DISCORD_RICHPRESENCE.isEnabled() || (!skyblockStatus.isOnSkyblock() && FeatureRegistry.DISCORD_RICHPRESENCE.<Boolean>getParameter("disablenotskyblock").getValue())) { - activityManager.ClearActivity.clearActivity(activityManager, Pointer.NULL, new NativeGameSDK.DiscordCallback() { - @Override - public void callback(Pointer callbackData, EDiscordResult result) { - } + activityManager.ClearActivity.clearActivity(activityManager, Pointer.NULL, (callbackData, result) -> { }); } else { String name = skyblockStatus.getDungeonName() == null ? "" : skyblockStatus.getDungeonName(); @@ -212,10 +218,7 @@ public class RichPresenceManager implements Runnable { } else { GameSDK.writeString(latestDiscordActivity.secrets.join, ""); } - activityManager.UpdateActivity.updateActivity(activityManager, latestDiscordActivity, Pointer.NULL, new NativeGameSDK.DiscordCallback() { - @Override - public void callback(Pointer callbackData, EDiscordResult result) { - } + activityManager.UpdateActivity.updateActivity(activityManager, latestDiscordActivity, Pointer.NULL, (callbackData, result) -> { }); } } @@ -235,9 +238,9 @@ public class RichPresenceManager implements Runnable { counter = 0; } else { EDiscordResult eDiscordResult = iDiscordCore.RunCallbacks.runCallbacks(iDiscordCore); - if (eDiscordResult == EDiscordResult.DiscordResult_NotRunning) { + if (eDiscordResult != EDiscordResult.DiscordResult_Ok) { setup = true; - } else { + } else if (ready){ if (counter == 0) updatePresence(); if (++counter == 15) counter = 0; |