Coder Social home page Coder Social logo

discord-rpc-java's Introduction

Discord RPC Java

This is the Java implementation of the Discord RPC C++ SDK that can be found in Discord RPC repository

Usage

Include this library with Maven with the following:

<dependency>
    <groupId>com.github.psnrigner</groupId>
    <artifactId>discord-rpc-java</artifactId>
    <version>1.0.4</version>
</dependency>

Or for Gradle:

compile "com.github.psnrigner:discord-rpc-java:1.0.4"

Look in examples package for samples.

Notes

This project is using Java 8. It can be easily converted to older languages, but staying on an updated version of Java is still better.

If i receive too many requests, i can change it to use Java 7 or lower.

TODOs

All what needs to be done / fixed is in issues, i would appreciate some help on some of these, especially OSX support.

Feel free to add your name in a CONTRIBUTORS.md file.

discord-rpc-java's People

Contributors

rigner avatar sirywell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

discord-rpc-java's Issues

Not sending data(no presence info transfered)

Data stays in the presenceQueue...
image

Because
image connection is not correctly established.
Code on startup

try{
      discordRpc = new DiscordRpc();
      discordRpc.init(clientProperties.getDiscordConfig().getApplicationId(), discordEventHandler, true, null);
      timer.schedule(new TimerTask() {
        @Override
        public void run() {
          discordRpc.runCallbacks();
        }
      }, initialDelayForCallback, periodForCallBack);
    }catch (Exception e){
      //TODO: report to bugsnap
      log.error("Error in discord init",e);
    }

Code to set presence

  public void updatePlayedGameTo(Game game){
    try {
      DiscordRichPresence discordRichPresence = new DiscordRichPresence();
      discordRichPresence.setState(getDiscordState(game));
      discordRichPresence.setDetails(MessageFormat.format("Game {0}",game.getTitle()));
      discordRichPresence.setStartTimestamp((game.getStartTime()==null?System.currentTimeMillis():game.getStartTime().toEpochMilli())/1000);
      discordRichPresence.setPartyId(String.valueOf(game.getId()));
      discordRichPresence.setPartySize(game.getNumPlayers());
      discordRichPresence.setPartyMax(game.getMaxPlayers());
      if(game.getStatus()==GameStatus.CLOSED){
        discordRichPresence.setEndTimestamp(Instant.now().toEpochMilli()/1000);
      }
      discordRichPresence.setInstance(false);

      discordRpc.updatePresence(discordRichPresence);
    }catch (Exception e){
      //TODO: report to bugsnap
      log.error("Error reporting game status to discord",e);
    }
  }

Rich Presence not updating when state and details not set

Hi !

Calling DiscordRpc.updatePresence(DiscordRichPresence) on a presence that has neither details nor state has no effect. Indeed, if these properties are not set (or empty) then Discord is not updated.

Since Discord's developer documentation seems to indicate that all fields are optional when updating a presence, I assume that it is a bug related to this implementation.

I can reproduce the bug by taking the example SimpleGame.java and commenting one of the lines that set the details or the state (on lines 91, 92).

Does someone have an idea about how to resolve this issue ? I'm on Windows, by the way.

More testing and add unit tests

Actually linux and OSX and not tested (because of personal issues, i'll be able to test on ubuntu really soon)

Also need to add unit tests where possible.

Rich Presence not updating

Hey there,
I tried to implement the api in my game, it worked but it didnt update the stuff. As example, when the game starts, the details should be 'Main Menu'. So far everything is fine. But when I now join the queue, it should update the details to 'in Queue', but that doesnt work. It just doesnt update. Then I took your example code, but the same issue. It isnt updating the text. Do you have any clue why?

NullPointerException Error

java.lang.NullPointerException: Initializing game
at com.google.gson.JsonPrimitive.isPrimitiveOrString(JsonPrimitive.java:278)
at com.google.gson.JsonPrimitive.setValue(JsonPrimitive.java:100)
at com.google.gson.JsonPrimitive.(JsonPrimitive.java:65)
at com.github.psnrigner.DiscordRichPresence.toJson(DiscordRichPresence.java:364)
at com.github.psnrigner.DiscordRpc.updatePresence(DiscordRpc.java:201)
at me.cubxity.mods.minecord.Minecord.updatePresence(Minecord.java:67)
at me.cubxity.mods.minecord.PresenceManager.update(PresenceManager.java:73)
at me.cubxity.mods.minecord.Minecord.postInit(Minecord.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)

Failed to create directory '/home/user/.local'

When running discordRpc.init() the following exception is thrown

Exception in thread "main" java.lang.RuntimeException: Failed to create directory '/home/koenn/.local'
	at com.github.psnrigner.discordrpcjava.impl.BaseConnectionUnix.register(BaseConnectionUnix.java:188)
	at com.github.psnrigner.discordrpcjava.DiscordRpc.register(DiscordRpc.java:294)
	at com.github.psnrigner.discordrpcjava.DiscordRpc.init(DiscordRpc.java:130)

The directory /home/koenn/.local already exists, so it does not have to be created.

Issues with type values on Json arrays in Json, errored

There's an issue with the Json system. When looking at this. The DiscordRichPresence I have set to PartySize=0, when it's going to encode the data to Json. It errors and the return type for getPartySize() is an int. While JsonArray expect the "Number" type or class.

[17:03:51] [Thread-16/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: java.lang.NoSuchMethodError: com.google.gson.JsonArray.add(Ljava/lang/Number;)V [17:03:51] [Thread-16/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: at com.github.psnrigner.discordrpcjava.DiscordRichPresence.toJson(DiscordRichPresence.java:413) [17:03:51] [Thread-16/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: at com.github.psnrigner.discordrpcjava.DiscordRpc.updatePresence(DiscordRpc.java:201) [17:03:51] [Thread-16/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: at se.techlabz.mc.discord.rpc.utils.DiscordHook.lambda$updatePresence$1(DiscordHook.java:79) [17:03:51] [Thread-16/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: at java.lang.Thread.run(Thread.java:748)

Shutdown application correctly

Hey, when closing your example apps, the game state stays the same. I didn't figured out until now how to remove the rich presence state. Should it automatically change?

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.