Giter Club home page Giter Club logo

Comments (11)

MinnDevelopment avatar MinnDevelopment commented on August 19, 2024

I don't see how this could be caused by either the discord-rpc SDK or this binding. I believe this is rather your application than this library or binding target.

from java-discord-rpc.

FireController1847 avatar FireController1847 commented on August 19, 2024

The issue is, I'm currently using this in Minecraft and I'm not sure how to prevent this issue. What happens is when a user leaves a server and then quits the game quickly, it sends the update on the menu load but that arrives AFTER the shutdown. If you could point me in the right direction, that'd be awesome.

from java-discord-rpc.

m-sterling avatar m-sterling commented on August 19, 2024

This kind of thing happens whenever you don't properly shut RPC down. If you exit your program before calling it (or before it finishes executing, since it seems like it takes a few seconds), you get the bug as described.

IMO I think the fact that the client can't self-update if the app is closed makes me think it's an issue with the SDK, as I don't really see a workaround to the user closing it too quickly.

from java-discord-rpc.

msciotti avatar msciotti commented on August 19, 2024

I'm having a bit of trouble understanding exactly the steps you're describing, but it sounds like what's happening is:

  1. Push Update_Presence() call
  2. Call Shutdown()
  3. Status disappears
  4. Status reappears

As mentioned via email, Discord determines status by the process ID of the program sending it presence updates. If you have Minecraft running and sending presence updates, and then call Shutdown() but don't close Minecraft, we still see the process id and think "Hey, they're still playing, keep showing whatever they sent us last".

Am I correct that the above steps are what you are describing?

from java-discord-rpc.

FireController1847 avatar FireController1847 commented on August 19, 2024

I believe the steps are correct but what you're describing doesn't sound correct, um..

Here's the steps that happens:

  1. User leaves a Minecraft server and returns to title screen, causing presence to update to "Main Menu"
    • Sends an Update_Presence()
  2. User quits the game before the Update_Presence() has finished sending
    • Sends a Shutdown() before Update_Presence() has finished
  3. The shutdown arrives before the Update_Presence(), causing the game to disappear (like you quit).
    • The Shutdown() arrives before the Update_Presence()
  4. The Update_Presence() arrives to Discord, returning the game to your profile.
    • The Update_Presence() arrives

In the end, Minecraft is actually closed, while the presence is still showing.

from java-discord-rpc.

m-sterling avatar m-sterling commented on August 19, 2024

So I did a bit of testing and found out that although the Minecraft modding library (Minecraft Forge) doesn't actually have an "on game shutdown" event, you can still achieve this by using Runtime#addShutdownHook. An example with the RPC library being instantiated as lib can be done as Runtime.getRuntime().addShutdownHook(new Thread(lib::Discord_Shutdown));.

from java-discord-rpc.

FireController1847 avatar FireController1847 commented on August 19, 2024

@kkirigaya That's exactly what I have and that is what causes the issue.

from java-discord-rpc.

FireController1847 avatar FireController1847 commented on August 19, 2024

Okay so for everyone participating in this thread, here's a video explaining exactly the issue I'm having.

Video Issue

And here's my presence file & the events that cause these to happen.

package com.firecontrol.minecraftdrp.RPC;

import com.firecontrol.minecraftdrp.MinecraftDRP;
import com.firecontrol.minecraftdrp.Reference;
import com.firecontrol.minecraftdrp.Handlers.RPCEventHandler;

import club.minnced.discord.rpc.DiscordEventHandlers;
import club.minnced.discord.rpc.DiscordRPC;
import club.minnced.discord.rpc.DiscordRichPresence;

public class RPCClient {

    private Thread callback;

    public void initialize() {
        DiscordEventHandlers handlers = new DiscordEventHandlers();

        handlers = RPCEventHandler.setupEvents(handlers);

        DiscordRPC.INSTANCE.Discord_Initialize(Reference.CLIENT_ID, handlers, true, null);

        if (callback == null) {
            callback = new Thread(() -> {
                while (!Thread.currentThread().isInterrupted()) {
                    DiscordRPC.INSTANCE.Discord_RunCallbacks();
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ignored) {
                    }
                }
            }, "RPC-Callback-Handler");

            callback.start();
        }

        MinecraftDRP.logger.info("Created new client.");

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                DiscordRPC.INSTANCE.Discord_Shutdown();
            }
        });
    }

    public void setPresence(DiscordRichPresence newPresence) {
        DiscordRPC.INSTANCE.Discord_UpdatePresence(newPresence);
    }

}

Here's the event.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void disconnectFromServerEvent(ClientDisconnectionFromServerEvent event) {
    Reference.serverPresence = null;
    DiscordRichPresence presence = new DiscordRichPresence();
    presence.state = "Main Menu";
    presence.largeImageKey = "crafting_large";
    presence.largeImageText = Display.getTitle();
    MinecraftDRP.DRPC.setPresence(presence);
}

from java-discord-rpc.

FireController1847 avatar FireController1847 commented on August 19, 2024

Okay so @kkirigaya and I have decided the simplest way to fix this would just be adding a "queue"-like system into the module that prevents multiple calls being sent at once.

from java-discord-rpc.

FireController1847 avatar FireController1847 commented on August 19, 2024

This looks very similar to discord/discord-rpc#61 and they're saying it's fixed. Is this similar or no?

from java-discord-rpc.

FireController1847 avatar FireController1847 commented on August 19, 2024

Closed via discord/discord-rpc#85

from java-discord-rpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.