Compare commits

...

7 Commits
1.2 ... master

Author SHA1 Message Date
Mathieu
2b489d3bf5 Refresh the state 2020-04-28 20:57:15 +02:00
Mathieu
bf0b510cf0 Upgraded gradlew and added custom state. 2020-04-28 20:19:04 +02:00
Mathieu
f7a52a982c Replaced dead api 2020-01-29 14:51:46 +01:00
M4TH1EU
af274c09f5 Mise à jour du numéro de version 2019-07-29 15:30:28 +02:00
M4TH1EU
726c4b0e67 Fixed : Crash lors de la récupération du fichier de config. 2019-07-29 15:23:44 +02:00
M4TH1EU
21a77c799a Fichier de config déplacé dans le mod et fixage de bugs. 2019-07-21 20:09:39 +02:00
M4TH1EU
3a70986336 Le fichier de config se créer bien + le temps ne se reset pas à chaque update. 2019-07-21 14:03:21 +02:00
26 changed files with 219 additions and 247 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,2 @@
#Tue Apr 28 20:17:19 CEST 2020
gradle.version=4.8.1

Binary file not shown.

View File

View File

@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
version = "1.2" version = "1.6"
group = "ch.m4th1eu.richpresence" // http://maven.apache.org/guides/mini/guide-naming-conventions.html group = "ch.m4th1eu.richpresence" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "richpresence" archivesBaseName = "richpresence"
@ -68,7 +68,7 @@ processResources {
include 'mcmod.info' include 'mcmod.info'
// replace version and mcversion // replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version expand 'version': project.version, 'mcversion': project.minecraft.version
} }
// copy everything else except the mcmod.info // copy everything else except the mcmod.info

View File

@ -1,16 +0,0 @@
[
{
"modid": "richpresence",
"name": "Discord Rich Presence Mod",
"description": "Un mod pour ajouter Rich Presence",
"version": "1.0",
"mcversion": "1.12.2",
"url": "https://mathieubroillet.ch/",
"updateUrl": "",
"authorList": ["M4TH1EU_"],
"credits": "RPC Lib author(s)",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]

View File

@ -1,7 +0,0 @@
{
"pack": {
"description": "examplemod resources",
"pack_format": 3,
"_comment": "A pack_format of 3 should be used starting with Minecraft 1.11. All resources, including language files, should be lowercase (eg: en_us.lang). A pack_format of 2 will load your mod resources with LegacyV2Adapter, which requires language files to have uppercase letters (eg: en_US.lang)."
}
}

Binary file not shown.

View File

@ -1,6 +1,6 @@
#Fri Jul 19 19:58:39 CEST 2019 #Tue Apr 28 20:22:31 CEST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip zipStoreBase=GRADLE_USER_HOME

110
gradlew vendored
View File

@ -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 # Attempt to set APP_HOME
# Resolve links: $0 may be a link # Resolve links: $0 may be a link
PRG="$0" PRG="$0"
@ -61,9 +20,49 @@ while [ -h "$PRG" ] ; do
fi fi
done done
SAVED="`pwd`" SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&- cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`" 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 CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@ -90,7 +89,7 @@ location of your Java installation."
fi fi
# Increase the maximum file descriptors if we can. # 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` MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@ -114,6 +113,7 @@ fi
if $cygwin ; then if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath # We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
@ -154,11 +154,19 @@ if $cygwin ; then
esac esac
fi fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules # Escape application args
function splitJvmOpts() { save () {
JVM_OPTS=("$@") for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
} }
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS APP_ARGS=$(save "$@")
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
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" "$@"

14
gradlew.bat vendored
View File

@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal 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 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% 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 @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail goto fail
:init :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 not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args :win9xME_args
@rem Slurp the command line arguments. @rem Slurp the command line arguments.
@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%* set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute :execute
@rem Setup the command line @rem Setup the command line

View File

@ -4,16 +4,19 @@ import ch.m4th1eu.json.JSONObject;
import ch.m4th1eu.richpresence.events.AdvancedStatusEvent; import ch.m4th1eu.richpresence.events.AdvancedStatusEvent;
import ch.m4th1eu.richpresence.events.EventPresence; import ch.m4th1eu.richpresence.events.EventPresence;
import ch.m4th1eu.richpresence.proxy.CommonProxy; import ch.m4th1eu.richpresence.proxy.CommonProxy;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/** /**
* @author M4TH1EU_#0001 * @author M4TH1EU_#0001
@ -22,7 +25,11 @@ import java.io.*;
public class Main { public class Main {
public static final String MODID = "richpresence"; public static final String MODID = "richpresence";
public static final String NAME = "Discord Rich Presence"; public static final String NAME = "Discord Rich Presence";
public static final String VERSION = "1.2"; public static final String VERSION = "1.5";
@Mod.Instance(Main.MODID)
public static Main instance;
@SidedProxy(clientSide = "ch.m4th1eu.richpresence.proxy.ClientProxy", serverSide = "ch.m4th1eu.richpresence.proxy.CommonProxy") @SidedProxy(clientSide = "ch.m4th1eu.richpresence.proxy.ClientProxy", serverSide = "ch.m4th1eu.richpresence.proxy.CommonProxy")
public static CommonProxy proxy; public static CommonProxy proxy;
@ -30,103 +37,56 @@ public class Main {
* Variables pour la config * Variables pour la config
*/ */
public static String applicationId, largeimage, largeimagetext; public static String applicationId, largeimage, largeimagetext;
public static String config_file_text = "";
public static JSONObject config_object;
public static Logger logger; public static Logger logger;
public EventPresence rpcClient; public EventPresence rpcClient;
public Main() {
MinecraftForge.EVENT_BUS.register(new AdvancedStatusEvent());
}
@EventHandler @EventHandler
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog(); logger = event.getModLog();
proxy.preInit(event.getSuggestedConfigurationFile()); proxy.preInit(event.getSuggestedConfigurationFile());
//Configuration //Configuration
event.getModConfigurationDirectory().mkdir(); event.getModConfigurationDirectory().mkdir();
File config_file = new File(event.getModConfigurationDirectory(), "\\" + Main.MODID + ".json");
if (!config_file.exists()) {
InputStream in = getClass().getResourceAsStream("/config/richpresence.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
try { try {
config_file_text = IOUtils.toString(reader);
config_object = new JSONObject(config_file_text);
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
if (config_file_text != null || config_file_text.length() < 10) {
event.getModLog().warn("Impossible de charger la configuration du mod : " + Main.MODID); event.getModLog().warn("Impossible de charger la configuration du mod : " + Main.MODID);
event.getModLog().warn("Création du fichier de configuration");
config_file.createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
} }
} }
if (config_file.length() < 10) {
try {
PrintWriter writer = new PrintWriter(config_file, "UTF-8");
writer.println("{\n" +
" \"_comment\": \"Variables disponibles :\",\n" +
" \"_comment2\": \"%player-name% - Nom du joueur.\",\n" +
" \"_comment3\": \"%server-connected-player% - Nombre de joueur connecté au serveur.\",\n" +
" \"_comment4\": \"%server-max-slot% - Nombre de slots du serveur\",\n" +
" \"server-ip\": \"mc.hypixel.net\",\n" +
" \"server-port\": \"25565\",\n" +
" \"application-settings\": {\n" +
" \"applicationID\": \"601875975533232158\",\n" +
" \"large-image-name\": \"discord_logo\",\n" +
" \"large-image-text\": \"En train de tester ce mod !\"\n" +
" },\n" +
" \"advanced-status-custom\": {\n" +
" \"onJoinServer\": {\n" +
" \"enable\": true,\n" +
" \"message\": \"En jeu.\"\n" +
" },\n" +
" \"onQuitServer\": {\n" +
" \"enable\": true,\n" +
" \"message\": \"Dans le menu principal.\"\n" +
" },\n" +
" \"inPauseMenu\": {\n" +
" \"enable\": true,\n" +
" \"message\": \"Dans le menu pause.\"\n" +
" },\n" +
" \"inMainMenu\": {\n" +
" \"enable\": true,\n" +
" \"message\": \"Dans le menu principal.\"\n" +
" },\n" +
" \"inInventory\": {\n" +
" \"enable\": false,\n" +
" \"message\": \"Dans l'inventaire.\"\n" +
" }\n" +
" }\n" +
"}");
writer.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
JSONObject config = new JSONObject(Utils.readFileToString(config_file));
applicationId = config.getJSONObject("application-settings").getString("applicationID");
largeimage = config.getJSONObject("application-settings").getString("large-image-name");
largeimagetext = Utils.replaceArgsString(config.getJSONObject("application-settings").getString("large-image-text"));
}
@EventHandler @EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
JSONObject config = new JSONObject(Utils.readFileToString(new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json"))); MinecraftForge.EVENT_BUS.register(instance);
MinecraftForge.EVENT_BUS.register(new AdvancedStatusEvent());
applicationId = config_object.getJSONObject("application-settings").getString("applicationID");
largeimage = config_object.getJSONObject("application-settings").getString("large-image-name");
largeimagetext = Utils.instance.replaceArgsString(config_object.getJSONObject("application-settings").getString("large-image-text"));
proxy.init(); proxy.init();
rpcClient = new EventPresence(); rpcClient = new EventPresence();
proxy.rpcinit(); proxy.rpcinit();
if (config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getBoolean("enable")) {
proxy.rpcupdate(config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getString("message"), null, false); if (config_object.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getBoolean("enable")) {
proxy.rpcupdate(config_object.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getString("message"), null, true);
} else { } else {
proxy.rpcupdate("", null, false); proxy.rpcupdate("", null, false);
} }

View File

@ -2,41 +2,20 @@ package ch.m4th1eu.richpresence;
import ch.m4th1eu.json.JSONObject; import ch.m4th1eu.json.JSONObject;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.network.INetHandler;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
public class Utils { public class Utils {
/** public static final Utils instance = new Utils();
* @author Nathanaël#4314 public static int status = 0;
*/
public static String readFileToString(final File file) {
try {
final BufferedReader reader = new BufferedReader(new FileReader(file));
final StringBuilder stringBuilder = new StringBuilder();
String line;
final String ls = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append(ls);
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
reader.close();
return stringBuilder.toString();
} catch (Exception e) {
e.printStackTrace();
return "ERROR";
}
}
/**
* @author Nathanael
*/
public static String readTextFromURL(String url) throws IOException { public static String readTextFromURL(String url) throws IOException {
URL urlObject; URL urlObject;
URLConnection uc; URLConnection uc;
@ -49,7 +28,7 @@ public class Utils {
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
uc.getInputStream(); uc.getInputStream();
InputStream is = 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; int ch;
while ((ch = in.read()) != -1) { while ((ch = in.read()) != -1) {
@ -61,53 +40,49 @@ public class Utils {
/** /**
* @author M4TH1EU_ * @author M4TH1EU_
*/ */
public static String replaceArgsString(String variable) { public String replaceArgsString(String variable) {
File config_file = new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json"); String serverip = Main.config_object.getString("server-ip");
JSONObject config = new JSONObject(Utils.readFileToString(config_file)); String serverport = Main.config_object.getString("server-port");
String serverip = config.getString("server-ip");
String serverport = config.getString("server-port");
try { try {
variable = variable.replaceAll("%player-name%", Minecraft.getMinecraft().getSession().getUsername()); variable = variable.replaceAll("%player-name%", Minecraft.getMinecraft().getSession().getUsername());
variable = variable.replaceAll("%server-connected-player%", readTextFromURL("https://minecraft-api.com/api/ping/playeronline.php?ip=" + serverip + "&port=" + serverport)); variable = variable.replaceAll("%server-connected-player%",
variable = variable.replaceAll("%server-max-slot%", readTextFromURL("https://minecraft-api.com/api/ping/maxplayer.php?ip=" + serverip + "&port=" + serverport)); readTextFromURL("https://api.serveurs-minecraft.com/api.php?Joueurs_En_Ligne_Ping&ip=" + serverip + "&port=" + serverport));
} catch (Exception e) { variable = variable.replaceAll("%server-max-slot%", readTextFromURL("https://api.serveurs-minecraft.com/api.php?Joueurs_Maximum_Ping&ip=" + serverip + "&port=" + serverport));
System.out.println(readTextFromURL("https://api.serveurs-minecraft.com/api.php?Joueurs_En_Ligne_Ping&ip=" + serverip + "&port=" + serverport));
} catch (Exception ignored) {
} }
return variable; return variable;
} }
public static void updateStatus(int id) { public void updateStatus(int id) {
Thread t = new Thread(() -> { Thread t = new Thread(() -> {
JSONObject config = new JSONObject(Utils.readFileToString(new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json")));
JSONObject onQuitServer = config.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer"); status = id;
JSONObject onJoinServer = config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
JSONObject inPauseMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inPauseMenu"); JSONObject onQuitServer = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer");
JSONObject inMainMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu"); JSONObject onJoinServer = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
JSONObject inInventory = config.getJSONObject("advanced-status-custom").getJSONObject("inInventory"); JSONObject inPauseMenu = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("inPauseMenu");
JSONObject inMainMenu = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu");
JSONObject inInventory = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("inInventory");
switch (id) { switch (id) {
case 0:
Main.proxy.rpcupdate(Utils.replaceArgsString(config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getString("message")), null, false);
break;
case 1: case 1:
Main.proxy.rpcupdate(Utils.replaceArgsString(onJoinServer.getString("message")), null, false); Main.proxy.rpcupdate(replaceArgsString(onJoinServer.getString("message")), getState(onJoinServer), false);
break; break;
case 2: case 2:
Main.proxy.rpcupdate(Utils.replaceArgsString(onQuitServer.getString("message")), null, false); Main.proxy.rpcupdate(replaceArgsString(onQuitServer.getString("message")), getState(onQuitServer), false);
break; break;
case 3: case 3:
Main.proxy.rpcupdate(Utils.replaceArgsString(inPauseMenu.getString("message")), null, false); Main.proxy.rpcupdate(replaceArgsString(inPauseMenu.getString("message")), getState(inPauseMenu), false);
break; break;
case 4: case 4:
Main.proxy.rpcupdate(Utils.replaceArgsString(inMainMenu.getString("message")), null, false); Main.proxy.rpcupdate(replaceArgsString(inMainMenu.getString("message")), getState(inMainMenu), false);
break; break;
case 5: case 5:
Main.proxy.rpcupdate(Utils.replaceArgsString(inInventory.getString("message")), null, false); Main.proxy.rpcupdate(replaceArgsString(inInventory.getString("message")), getState(inInventory), false);
break;
case 6:
Main.proxy.rpcupdate(Utils.replaceArgsString(config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getString("message")), null, false);
break; break;
default: default:
break; break;
@ -115,8 +90,17 @@ public class Utils {
}); });
t.start(); t.start();
}
private String getState(JSONObject jsonObject) {
String state = replaceArgsString(Main.config_object.getString("state"));
System.out.println(state);
if (jsonObject.getBoolean("showState")) {
return state;
}
return null;
} }
} }

View File

@ -3,74 +3,74 @@ package ch.m4th1eu.richpresence.events;
import ch.m4th1eu.json.JSONObject; import ch.m4th1eu.json.JSONObject;
import ch.m4th1eu.richpresence.Main; import ch.m4th1eu.richpresence.Main;
import ch.m4th1eu.richpresence.Utils; import ch.m4th1eu.richpresence.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiIngameMenu; import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent; import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import java.io.File;
/** /**
* @author M4TH1EU_#0001 * @author M4TH1EU_#0001
*/ */
@Mod.EventBusSubscriber @Mod.EventBusSubscriber
public class AdvancedStatusEvent { public class AdvancedStatusEvent {
File config_file = new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json"); @SubscribeEvent
JSONObject config = new JSONObject(Utils.readFileToString(config_file)); public void onTickEvent(TickEvent.WorldTickEvent event) {
if (event.world.getTotalWorldTime() % 1024 == 0) {
Utils.instance.updateStatus(Utils.status);
}
}
@SubscribeEvent @SubscribeEvent
public void onJoinServer(FMLNetworkEvent.ClientConnectedToServerEvent event) { public void onJoinServer(FMLNetworkEvent.ClientConnectedToServerEvent event) {
JSONObject onJoinServer = config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer"); JSONObject onJoinServer = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
if (onJoinServer.getBoolean("enable")) { if (onJoinServer.getBoolean("enable")) {
Utils.updateStatus(1); Utils.instance.updateStatus(1);
} }
} }
@SubscribeEvent @SubscribeEvent
public void onQuitServer(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) { public void onQuitServer(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
JSONObject onQuitServer = config.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer"); JSONObject onQuitServer = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer");
if (onQuitServer.getBoolean("enable")) { if (onQuitServer.getBoolean("enable")) {
Utils.updateStatus(1); Utils.instance.updateStatus(2);
} }
} }
@SubscribeEvent @SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) { public void onGuiOpen(GuiOpenEvent event) {
JSONObject inPauseMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inPauseMenu"); JSONObject inPauseMenu = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("inPauseMenu");
JSONObject inMainMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu"); JSONObject inMainMenu = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu");
JSONObject inInventory = config.getJSONObject("advanced-status-custom").getJSONObject("inInventory"); JSONObject inInventory = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("inInventory");
if (inPauseMenu.getBoolean("enable")) { if (inPauseMenu.getBoolean("enable")) {
if (event.getGui() instanceof GuiIngameMenu) { if (event.getGui() instanceof GuiIngameMenu) {
Utils.updateStatus(3); Utils.instance.updateStatus(3);
} }
} }
if (inMainMenu.getBoolean("enable")) { if (inMainMenu.getBoolean("enable")) {
if (event.getGui() instanceof GuiMainMenu) { if (event.getGui() instanceof GuiMainMenu) {
Utils.updateStatus(4); Utils.instance.updateStatus(4);
} }
} }
if (inInventory.getBoolean("enable")) { if (inInventory.getBoolean("enable")) {
if (event.getGui() instanceof GuiInventory) { if (event.getGui() instanceof GuiInventory) {
Utils.updateStatus(5); Utils.instance.updateStatus(5);
} }
} }
if (event.getGui() == null) { if (event.getGui() == null) {
if (config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getBoolean("enable")) { if (Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getBoolean("enable")) {
Utils.updateStatus(6); Utils.instance.updateStatus(1);
} }
} }
} }

View File

@ -10,11 +10,12 @@ import net.arikia.dev.drpc.DiscordRichPresence;
*/ */
public class EventPresence { public class EventPresence {
public static long oldTime;
private static Thread callbackRunner; private static Thread callbackRunner;
public synchronized static void init() { public synchronized static void init() {
DiscordEventHandlers handlers = new DiscordEventHandlers(); DiscordEventHandlers handlers = new DiscordEventHandlers();
DiscordRPC.discordInitialize(Main.applicationId, handlers, true, null); DiscordRPC.discordInitialize(Main.applicationId, handlers, true);
if (EventPresence.callbackRunner == null) { if (EventPresence.callbackRunner == null) {
(EventPresence.callbackRunner = new Thread(() -> { (EventPresence.callbackRunner = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) { while (!Thread.currentThread().isInterrupted()) {
@ -26,7 +27,7 @@ public class EventPresence {
Main.logger.info("EventPresence has been started."); Main.logger.info("EventPresence has been started.");
} }
public synchronized static void updatePresence(String details, String action, Boolean changeTime) { public static void updatePresence(String details, String action, Boolean changeTime) {
DiscordRichPresence presence = new DiscordRichPresence(); DiscordRichPresence presence = new DiscordRichPresence();
presence.largeImageKey = Main.largeimage; presence.largeImageKey = Main.largeimage;
presence.largeImageText = Main.largeimagetext; presence.largeImageText = Main.largeimagetext;
@ -35,8 +36,13 @@ public class EventPresence {
if (changeTime) { if (changeTime) {
presence.startTimestamp = System.currentTimeMillis() / 1000L; presence.startTimestamp = System.currentTimeMillis() / 1000L;
oldTime = presence.startTimestamp;
} else {
presence.startTimestamp = oldTime;
} }
} else if (action != null) { }
if (action != null) {
presence.state = action; presence.state = action;
} }
DiscordRPC.discordUpdatePresence(presence); DiscordRPC.discordUpdatePresence(presence);

View File

@ -0,0 +1,41 @@
{
"_comment": "Variables disponibles :",
"_comment2": "%player-name% - Nom du joueur.",
"_comment3": "%server-connected-player% - Nombre de joueur connecté au serveur.",
"_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",
"large-image-text": "En train de tester ce mod !"
},
"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."
}
}
}