diff --git a/.gradle/4.8.1/fileChanges/last-build.bin b/.gradle/4.8.1/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/4.8.1/fileChanges/last-build.bin differ diff --git a/.gradle/4.8.1/fileHashes/fileHashes.bin b/.gradle/4.8.1/fileHashes/fileHashes.bin new file mode 100644 index 0000000..41d6ebf Binary files /dev/null and b/.gradle/4.8.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/4.8.1/fileHashes/fileHashes.lock b/.gradle/4.8.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000..b348db9 Binary files /dev/null and b/.gradle/4.8.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/4.8.1/taskHistory/taskHistory.bin b/.gradle/4.8.1/taskHistory/taskHistory.bin new file mode 100644 index 0000000..0dfbde6 Binary files /dev/null and b/.gradle/4.8.1/taskHistory/taskHistory.bin differ diff --git a/.gradle/4.8.1/taskHistory/taskHistory.lock b/.gradle/4.8.1/taskHistory/taskHistory.lock new file mode 100644 index 0000000..2ff2923 Binary files /dev/null and b/.gradle/4.8.1/taskHistory/taskHistory.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..c9e16a7 Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..d71473c --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Tue Apr 28 20:17:19 CEST 2020 +gradle.version=4.8.1 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..8e6f517 Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/vcsWorkingDirs/gc.properties b/.gradle/vcsWorkingDirs/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 30d399d..758de96 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0ddf2cf..2d80b69 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jul 19 19:58:39 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip diff --git a/gradlew b/gradlew index 91a7e26..cccdd3d 100644 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,47 +6,6 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" @@ -61,9 +20,49 @@ while [ -h "$PRG" ] ; do fi done SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- +cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" -cd "$SAVED" >&- +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -90,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -114,6 +113,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 8a0b282..f955316 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/src/main/java/ch/m4th1eu/richpresence/Utils.java b/src/main/java/ch/m4th1eu/richpresence/Utils.java index f24042d..3891835 100644 --- a/src/main/java/ch/m4th1eu/richpresence/Utils.java +++ b/src/main/java/ch/m4th1eu/richpresence/Utils.java @@ -9,7 +9,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; public class Utils { @@ -27,7 +27,7 @@ public class Utils { "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); uc.getInputStream(); InputStream is = uc.getInputStream(); - BufferedReader in = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + BufferedReader in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); int ch; while ((ch = in.read()) != -1) { @@ -47,7 +47,7 @@ public class Utils { variable = variable.replaceAll("%player-name%", Minecraft.getMinecraft().getSession().getUsername()); variable = variable.replaceAll("%server-connected-player%", readTextFromURL("https://api.serveurs-minecraft.com/api.php?Joueurs_En_Ligne_Ping&ip=" + serverip + "&port=" + serverport)); variable = variable.replaceAll("%server-max-slot%", readTextFromURL("https://api.serveurs-minecraft.com/api.php?Joueurs_Maximum_Ping&ip=" + serverip + "&port=" + serverport)); - } catch (Exception e) { + } catch (Exception ignored) { } return variable; @@ -63,26 +63,20 @@ public class Utils { JSONObject inInventory = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("inInventory"); switch (id) { - case 0: - Main.proxy.rpcupdate(replaceArgsString(Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getString("message")), null, false); - break; case 1: - Main.proxy.rpcupdate(replaceArgsString(onJoinServer.getString("message")), null, false); + Main.proxy.rpcupdate(replaceArgsString(onJoinServer.getString("message")), getState(onJoinServer), false); break; case 2: - Main.proxy.rpcupdate(replaceArgsString(onQuitServer.getString("message")), null, false); + Main.proxy.rpcupdate(replaceArgsString(onQuitServer.getString("message")), getState(onQuitServer), false); break; case 3: - Main.proxy.rpcupdate(replaceArgsString(inPauseMenu.getString("message")), null, false); + Main.proxy.rpcupdate(replaceArgsString(inPauseMenu.getString("message")), getState(inPauseMenu), false); break; case 4: - Main.proxy.rpcupdate(replaceArgsString(inMainMenu.getString("message")), null, false); + Main.proxy.rpcupdate(replaceArgsString(inMainMenu.getString("message")), getState(inMainMenu), false); break; case 5: - Main.proxy.rpcupdate(replaceArgsString(inInventory.getString("message")), null, false); - break; - case 6: - Main.proxy.rpcupdate(replaceArgsString(Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getString("message")), null, false); + Main.proxy.rpcupdate(replaceArgsString(inInventory.getString("message")), getState(inInventory), false); break; default: break; @@ -90,8 +84,16 @@ public class Utils { }); t.start(); + } + private String getState(JSONObject jsonObject) { + String state = replaceArgsString(Main.config_object.getString("state")); + if (jsonObject.getBoolean("showState")) { + return state; + } + + return null; } } diff --git a/src/main/java/ch/m4th1eu/richpresence/events/AdvancedStatusEvent.java b/src/main/java/ch/m4th1eu/richpresence/events/AdvancedStatusEvent.java index 41ff4f8..134dd58 100644 --- a/src/main/java/ch/m4th1eu/richpresence/events/AdvancedStatusEvent.java +++ b/src/main/java/ch/m4th1eu/richpresence/events/AdvancedStatusEvent.java @@ -32,7 +32,7 @@ public class AdvancedStatusEvent { JSONObject onQuitServer = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer"); if (onQuitServer.getBoolean("enable")) { - Utils.instance.updateStatus(1); + Utils.instance.updateStatus(2); } } @@ -63,7 +63,7 @@ public class AdvancedStatusEvent { if (event.getGui() == null) { if (Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getBoolean("enable")) { - Utils.instance.updateStatus(6); + Utils.instance.updateStatus(1); } } } diff --git a/src/main/java/ch/m4th1eu/richpresence/events/EventPresence.java b/src/main/java/ch/m4th1eu/richpresence/events/EventPresence.java index 00b058c..4d82913 100644 --- a/src/main/java/ch/m4th1eu/richpresence/events/EventPresence.java +++ b/src/main/java/ch/m4th1eu/richpresence/events/EventPresence.java @@ -38,11 +38,11 @@ public class EventPresence { presence.startTimestamp = System.currentTimeMillis() / 1000L; oldTime = presence.startTimestamp; } else { - System.out.println(presence.startTimestamp); - System.out.println(oldTime); presence.startTimestamp = oldTime; } - } else if (action != null) { + } + + if (action != null) { presence.state = action; } DiscordRPC.discordUpdatePresence(presence); diff --git a/src/main/resources/config/richpresence.json b/src/main/resources/config/richpresence.json index 1ad96f3..219ab4f 100644 --- a/src/main/resources/config/richpresence.json +++ b/src/main/resources/config/richpresence.json @@ -5,6 +5,7 @@ "_comment4": "%server-max-slot% - Nombre de slots du serveur", "server-ip": "mc.hypixel.net", "server-port": "25565", + "state": "%server-connected-player%/%server-max-slot% joueurs connectés", "application-settings": { "applicationID": "601875975533232158", "large-image-name": "discord_logo", @@ -13,22 +14,27 @@ "advanced-status-custom": { "onJoinServer": { "enable": true, + "showState": true, "message": "En jeu." }, "onQuitServer": { "enable": true, + "showState": false, "message": "Dans le menu principal." }, "inPauseMenu": { "enable": true, + "showState": true, "message": "Dans le menu pause." }, "inMainMenu": { "enable": true, + "showState": false, "message": "Dans le menu principal." }, "inInventory": { "enable": false, + "showState": true, "message": "Dans l'inventaire." } }