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.
version = "1.2"
version = "1.6"
group = "ch.m4th1eu.richpresence" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "richpresence"
@ -68,7 +68,7 @@ processResources {
include 'mcmod.info'
// 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

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
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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
# 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" "$@"

14
gradlew.bat vendored
View File

@ -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

View File

@ -4,16 +4,19 @@ import ch.m4th1eu.json.JSONObject;
import ch.m4th1eu.richpresence.events.AdvancedStatusEvent;
import ch.m4th1eu.richpresence.events.EventPresence;
import ch.m4th1eu.richpresence.proxy.CommonProxy;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.commons.io.IOUtils;
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
@ -22,7 +25,11 @@ import java.io.*;
public class Main {
public static final String MODID = "richpresence";
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")
public static CommonProxy proxy;
@ -30,103 +37,56 @@ public class Main {
* Variables pour la config
*/
public static String applicationId, largeimage, largeimagetext;
public static String config_file_text = "";
public static JSONObject config_object;
public static Logger logger;
public EventPresence rpcClient;
public Main() {
MinecraftForge.EVENT_BUS.register(new AdvancedStatusEvent());
}
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
proxy.preInit(event.getSuggestedConfigurationFile());
//Configuration
event.getModConfigurationDirectory().mkdir();
File config_file = new File(event.getModConfigurationDirectory(), "\\" + Main.MODID + ".json");
if (!config_file.exists()) {
try {
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();
}
InputStream in = getClass().getResourceAsStream("/config/richpresence.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
try {
config_file_text = IOUtils.toString(reader);
config_object = new JSONObject(config_file_text);
reader.close();
} catch (IOException e) {
e.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();
}
if (config_file_text != null || config_file_text.length() < 10) {
event.getModLog().warn("Impossible de charger la configuration du mod : " + Main.MODID);
}
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
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();
rpcClient = new EventPresence();
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 {
proxy.rpcupdate("", null, false);
}

View File

@ -2,41 +2,20 @@ package ch.m4th1eu.richpresence;
import ch.m4th1eu.json.JSONObject;
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.URLConnection;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
public class Utils {
/**
* @author Nathanaël#4314
*/
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";
}
}
public static final Utils instance = new Utils();
public static int status = 0;
/**
* @author Nathanael
*/
public static String readTextFromURL(String url) throws IOException {
URL urlObject;
URLConnection uc;
@ -49,7 +28,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) {
@ -61,53 +40,49 @@ public class Utils {
/**
* @author M4TH1EU_
*/
public static String replaceArgsString(String variable) {
File config_file = new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json");
JSONObject config = new JSONObject(Utils.readFileToString(config_file));
String serverip = config.getString("server-ip");
String serverport = config.getString("server-port");
public String replaceArgsString(String variable) {
String serverip = Main.config_object.getString("server-ip");
String serverport = Main.config_object.getString("server-port");
try {
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-max-slot%", readTextFromURL("https://minecraft-api.com/api/ping/maxplayer.php?ip=" + serverip + "&port=" + serverport));
} catch (Exception e) {
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));
System.out.println(readTextFromURL("https://api.serveurs-minecraft.com/api.php?Joueurs_En_Ligne_Ping&ip=" + serverip + "&port=" + serverport));
} catch (Exception ignored) {
}
return variable;
}
public static void updateStatus(int id) {
public void updateStatus(int id) {
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");
JSONObject onJoinServer = config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
JSONObject inPauseMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inPauseMenu");
JSONObject inMainMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu");
JSONObject inInventory = config.getJSONObject("advanced-status-custom").getJSONObject("inInventory");
status = id;
JSONObject onQuitServer = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer");
JSONObject onJoinServer = Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
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) {
case 0:
Main.proxy.rpcupdate(Utils.replaceArgsString(config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getString("message")), null, false);
break;
case 1:
Main.proxy.rpcupdate(Utils.replaceArgsString(onJoinServer.getString("message")), null, false);
Main.proxy.rpcupdate(replaceArgsString(onJoinServer.getString("message")), getState(onJoinServer), false);
break;
case 2:
Main.proxy.rpcupdate(Utils.replaceArgsString(onQuitServer.getString("message")), null, false);
Main.proxy.rpcupdate(replaceArgsString(onQuitServer.getString("message")), getState(onQuitServer), false);
break;
case 3:
Main.proxy.rpcupdate(Utils.replaceArgsString(inPauseMenu.getString("message")), null, false);
Main.proxy.rpcupdate(replaceArgsString(inPauseMenu.getString("message")), getState(inPauseMenu), false);
break;
case 4:
Main.proxy.rpcupdate(Utils.replaceArgsString(inMainMenu.getString("message")), null, false);
Main.proxy.rpcupdate(replaceArgsString(inMainMenu.getString("message")), getState(inMainMenu), false);
break;
case 5:
Main.proxy.rpcupdate(Utils.replaceArgsString(inInventory.getString("message")), null, false);
break;
case 6:
Main.proxy.rpcupdate(Utils.replaceArgsString(config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getString("message")), null, false);
Main.proxy.rpcupdate(replaceArgsString(inInventory.getString("message")), getState(inInventory), false);
break;
default:
break;
@ -115,8 +90,17 @@ public class Utils {
});
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.richpresence.Main;
import ch.m4th1eu.richpresence.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import java.io.File;
/**
* @author M4TH1EU_#0001
*/
@Mod.EventBusSubscriber
public class AdvancedStatusEvent {
File config_file = new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json");
JSONObject config = new JSONObject(Utils.readFileToString(config_file));
@SubscribeEvent
public void onTickEvent(TickEvent.WorldTickEvent event) {
if (event.world.getTotalWorldTime() % 1024 == 0) {
Utils.instance.updateStatus(Utils.status);
}
}
@SubscribeEvent
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")) {
Utils.updateStatus(1);
Utils.instance.updateStatus(1);
}
}
@SubscribeEvent
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")) {
Utils.updateStatus(1);
Utils.instance.updateStatus(2);
}
}
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
JSONObject inPauseMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inPauseMenu");
JSONObject inMainMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu");
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");
if (inPauseMenu.getBoolean("enable")) {
if (event.getGui() instanceof GuiIngameMenu) {
Utils.updateStatus(3);
Utils.instance.updateStatus(3);
}
}
if (inMainMenu.getBoolean("enable")) {
if (event.getGui() instanceof GuiMainMenu) {
Utils.updateStatus(4);
Utils.instance.updateStatus(4);
}
}
if (inInventory.getBoolean("enable")) {
if (event.getGui() instanceof GuiInventory) {
Utils.updateStatus(5);
Utils.instance.updateStatus(5);
}
}
if (event.getGui() == null) {
if (config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getBoolean("enable")) {
Utils.updateStatus(6);
if (Main.config_object.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getBoolean("enable")) {
Utils.instance.updateStatus(1);
}
}
}

View File

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