Fichier de config déplacé dans le mod et fixage de bugs.
This commit is contained in:
parent
3a70986336
commit
21a77c799a
@ -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.3"
|
||||||
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
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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": []
|
|
||||||
}
|
|
||||||
]
|
|
@ -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)."
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ 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;
|
||||||
@ -17,6 +16,7 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author M4TH1EU_#0001
|
* @author M4TH1EU_#0001
|
||||||
@ -25,7 +25,7 @@ import java.io.UnsupportedEncodingException;
|
|||||||
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.3";
|
||||||
|
|
||||||
@Mod.Instance(Main.MODID)
|
@Mod.Instance(Main.MODID)
|
||||||
public static Main instance;
|
public static Main instance;
|
||||||
@ -49,7 +49,13 @@ public class Main {
|
|||||||
|
|
||||||
//Configuration
|
//Configuration
|
||||||
event.getModConfigurationDirectory().mkdir();
|
event.getModConfigurationDirectory().mkdir();
|
||||||
File config_file = new File(event.getModConfigurationDirectory(), "\\" + Main.MODID + ".json");
|
|
||||||
|
File config_file = null;
|
||||||
|
try {
|
||||||
|
config_file = new File(getClass().getResource("/config/richpresence.json").toURI());
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
if (!config_file.exists() || config_file.length() < 10) {
|
if (!config_file.exists() || config_file.length() < 10) {
|
||||||
try {
|
try {
|
||||||
@ -106,16 +112,20 @@ public class Main {
|
|||||||
MinecraftForge.EVENT_BUS.register(instance);
|
MinecraftForge.EVENT_BUS.register(instance);
|
||||||
MinecraftForge.EVENT_BUS.register(new AdvancedStatusEvent());
|
MinecraftForge.EVENT_BUS.register(new AdvancedStatusEvent());
|
||||||
|
|
||||||
JSONObject config = new JSONObject(Utils.readFileToString(new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json")));
|
JSONObject config = null;
|
||||||
|
try {
|
||||||
|
config = new JSONObject(Utils.readFileToString(new File(getClass().getResource("/config/richpresence.json").toURI())));
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
applicationId = config.getJSONObject("application-settings").getString("applicationID");
|
applicationId = config.getJSONObject("application-settings").getString("applicationID");
|
||||||
largeimage = config.getJSONObject("application-settings").getString("large-image-name");
|
largeimage = config.getJSONObject("application-settings").getString("large-image-name");
|
||||||
largeimagetext = Utils.replaceArgsString(config.getJSONObject("application-settings").getString("large-image-text"));
|
largeimagetext = Utils.instance.replaceArgsString(config.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")) {
|
if (config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getBoolean("enable")) {
|
||||||
|
@ -4,12 +4,26 @@ import ch.m4th1eu.json.JSONObject;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
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.Charset;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
|
public static final Utils instance = new Utils();
|
||||||
|
|
||||||
|
private JSONObject config;
|
||||||
|
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
config = new JSONObject(Utils.readFileToString(new File(getClass().getResource("/config/richpresence.json").toURI())));
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nathanaël#4314
|
* @author Nathanaël#4314
|
||||||
*/
|
*/
|
||||||
@ -33,10 +47,6 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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;
|
||||||
@ -61,8 +71,13 @@ 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");
|
File config_file = null;
|
||||||
|
try {
|
||||||
|
config_file = new File(getClass().getResource("/config/richpresence.json").toURI());
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
JSONObject config = new JSONObject(Utils.readFileToString(config_file));
|
JSONObject config = new JSONObject(Utils.readFileToString(config_file));
|
||||||
|
|
||||||
String serverip = config.getString("server-ip");
|
String serverip = config.getString("server-ip");
|
||||||
@ -78,9 +93,9 @@ public class Utils {
|
|||||||
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");
|
JSONObject onQuitServer = config.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer");
|
||||||
JSONObject onJoinServer = config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
|
JSONObject onJoinServer = config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
|
||||||
JSONObject inPauseMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inPauseMenu");
|
JSONObject inPauseMenu = config.getJSONObject("advanced-status-custom").getJSONObject("inPauseMenu");
|
||||||
@ -89,25 +104,25 @@ public class Utils {
|
|||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 0:
|
case 0:
|
||||||
Main.proxy.rpcupdate(Utils.replaceArgsString(config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getString("message")), null, false);
|
Main.proxy.rpcupdate(replaceArgsString(config.getJSONObject("advanced-status-custom").getJSONObject("inMainMenu").getString("message")), null, false);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Main.proxy.rpcupdate(Utils.replaceArgsString(onJoinServer.getString("message")), null, false);
|
Main.proxy.rpcupdate(replaceArgsString(onJoinServer.getString("message")), null, false);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Main.proxy.rpcupdate(Utils.replaceArgsString(onQuitServer.getString("message")), null, false);
|
Main.proxy.rpcupdate(replaceArgsString(onQuitServer.getString("message")), null, false);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
Main.proxy.rpcupdate(Utils.replaceArgsString(inPauseMenu.getString("message")), null, false);
|
Main.proxy.rpcupdate(replaceArgsString(inPauseMenu.getString("message")), null, false);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
Main.proxy.rpcupdate(Utils.replaceArgsString(inMainMenu.getString("message")), null, false);
|
Main.proxy.rpcupdate(replaceArgsString(inMainMenu.getString("message")), null, false);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
Main.proxy.rpcupdate(Utils.replaceArgsString(inInventory.getString("message")), null, false);
|
Main.proxy.rpcupdate(replaceArgsString(inInventory.getString("message")), null, false);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
Main.proxy.rpcupdate(Utils.replaceArgsString(config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getString("message")), null, false);
|
Main.proxy.rpcupdate(replaceArgsString(config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getString("message")), null, false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package ch.m4th1eu.richpresence.events;
|
package ch.m4th1eu.richpresence.events;
|
||||||
|
|
||||||
import ch.m4th1eu.json.JSONObject;
|
import ch.m4th1eu.json.JSONObject;
|
||||||
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;
|
||||||
@ -13,6 +11,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|||||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author M4TH1EU_#0001
|
* @author M4TH1EU_#0001
|
||||||
@ -20,15 +19,23 @@ import java.io.File;
|
|||||||
@Mod.EventBusSubscriber
|
@Mod.EventBusSubscriber
|
||||||
public class AdvancedStatusEvent {
|
public class AdvancedStatusEvent {
|
||||||
|
|
||||||
File config_file = new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json");
|
JSONObject config = null;
|
||||||
JSONObject config = new JSONObject(Utils.readFileToString(config_file));
|
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
config = new JSONObject(Utils.readFileToString(new File(getClass().getResource("/config/richpresence.json").toURI())));
|
||||||
|
} catch (
|
||||||
|
URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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 = config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
|
||||||
|
|
||||||
if (onJoinServer.getBoolean("enable")) {
|
if (onJoinServer.getBoolean("enable")) {
|
||||||
Utils.updateStatus(1);
|
Utils.instance.updateStatus(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +44,7 @@ public class AdvancedStatusEvent {
|
|||||||
JSONObject onQuitServer = config.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer");
|
JSONObject onQuitServer = config.getJSONObject("advanced-status-custom").getJSONObject("onQuitServer");
|
||||||
|
|
||||||
if (onQuitServer.getBoolean("enable")) {
|
if (onQuitServer.getBoolean("enable")) {
|
||||||
Utils.updateStatus(1);
|
Utils.instance.updateStatus(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,25 +57,25 @@ public class AdvancedStatusEvent {
|
|||||||
|
|
||||||
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 (config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getBoolean("enable")) {
|
||||||
Utils.updateStatus(6);
|
Utils.instance.updateStatus(6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class EventPresence {
|
|||||||
|
|
||||||
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()) {
|
||||||
@ -27,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;
|
||||||
|
2
src/main/resources/config/richpresence.json
Normal file
2
src/main/resources/config/richpresence.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
Reference in New Issue
Block a user