Fichier de config déplacé dans le mod et fixage de bugs.
This commit is contained in:
parent
3a70986336
commit
21a77c799a
12
build.gradle
12
build.gradle
@ -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.3"
|
||||
group = "ch.m4th1eu.richpresence" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "richpresence"
|
||||
|
||||
@ -24,7 +24,7 @@ compileJava {
|
||||
minecraft {
|
||||
version = "1.12.2-14.23.5.2768"
|
||||
runDir = "run"
|
||||
|
||||
|
||||
// the mappings can be changed at any time, and must be in the following format.
|
||||
// snapshot_YYYYMMDD snapshot are built nightly.
|
||||
// stable_# stables are built at the discretion of the MCP team.
|
||||
@ -39,7 +39,7 @@ dependencies {
|
||||
// or you may define them like so..
|
||||
//compile "some.group:artifact:version:classifier"
|
||||
//compile "some.group:artifact:version"
|
||||
|
||||
|
||||
// real examples
|
||||
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
|
||||
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
|
||||
@ -66,11 +66,11 @@ processResources {
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
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
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude '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.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;
|
||||
@ -17,6 +16,7 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* @author M4TH1EU_#0001
|
||||
@ -25,7 +25,7 @@ import java.io.UnsupportedEncodingException;
|
||||
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.3";
|
||||
|
||||
@Mod.Instance(Main.MODID)
|
||||
public static Main instance;
|
||||
@ -49,7 +49,13 @@ public class Main {
|
||||
|
||||
//Configuration
|
||||
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) {
|
||||
try {
|
||||
@ -106,16 +112,20 @@ public class Main {
|
||||
MinecraftForge.EVENT_BUS.register(instance);
|
||||
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");
|
||||
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();
|
||||
rpcClient = new EventPresence();
|
||||
|
||||
|
||||
proxy.rpcinit();
|
||||
|
||||
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 java.io.*;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
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
|
||||
*/
|
||||
@ -33,10 +47,6 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Nathanael
|
||||
*/
|
||||
public static String readTextFromURL(String url) throws IOException {
|
||||
URL urlObject;
|
||||
URLConnection uc;
|
||||
@ -61,8 +71,13 @@ public class Utils {
|
||||
/**
|
||||
* @author M4TH1EU_
|
||||
*/
|
||||
public static String replaceArgsString(String variable) {
|
||||
File config_file = new File(Minecraft.getMinecraft().mcDataDir, "\\config\\" + Main.MODID + ".json");
|
||||
public String replaceArgsString(String variable) {
|
||||
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));
|
||||
|
||||
String serverip = config.getString("server-ip");
|
||||
@ -78,9 +93,9 @@ public class Utils {
|
||||
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");
|
||||
@ -89,25 +104,25 @@ public class Utils {
|
||||
|
||||
switch (id) {
|
||||
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;
|
||||
case 1:
|
||||
Main.proxy.rpcupdate(Utils.replaceArgsString(onJoinServer.getString("message")), null, false);
|
||||
Main.proxy.rpcupdate(replaceArgsString(onJoinServer.getString("message")), null, false);
|
||||
break;
|
||||
case 2:
|
||||
Main.proxy.rpcupdate(Utils.replaceArgsString(onQuitServer.getString("message")), null, false);
|
||||
Main.proxy.rpcupdate(replaceArgsString(onQuitServer.getString("message")), null, false);
|
||||
break;
|
||||
case 3:
|
||||
Main.proxy.rpcupdate(Utils.replaceArgsString(inPauseMenu.getString("message")), null, false);
|
||||
Main.proxy.rpcupdate(replaceArgsString(inPauseMenu.getString("message")), null, false);
|
||||
break;
|
||||
case 4:
|
||||
Main.proxy.rpcupdate(Utils.replaceArgsString(inMainMenu.getString("message")), null, false);
|
||||
Main.proxy.rpcupdate(replaceArgsString(inMainMenu.getString("message")), null, false);
|
||||
break;
|
||||
case 5:
|
||||
Main.proxy.rpcupdate(Utils.replaceArgsString(inInventory.getString("message")), null, false);
|
||||
Main.proxy.rpcupdate(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(config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer").getString("message")), null, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1,9 +1,7 @@
|
||||
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;
|
||||
@ -13,6 +11,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* @author M4TH1EU_#0001
|
||||
@ -20,15 +19,23 @@ import java.io.File;
|
||||
@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));
|
||||
JSONObject config = null;
|
||||
|
||||
{
|
||||
try {
|
||||
config = new JSONObject(Utils.readFileToString(new File(getClass().getResource("/config/richpresence.json").toURI())));
|
||||
} catch (
|
||||
URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onJoinServer(FMLNetworkEvent.ClientConnectedToServerEvent event) {
|
||||
JSONObject onJoinServer = config.getJSONObject("advanced-status-custom").getJSONObject("onJoinServer");
|
||||
|
||||
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");
|
||||
|
||||
if (onQuitServer.getBoolean("enable")) {
|
||||
Utils.updateStatus(1);
|
||||
Utils.instance.updateStatus(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,25 +57,25 @@ public class AdvancedStatusEvent {
|
||||
|
||||
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);
|
||||
Utils.instance.updateStatus(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class EventPresence {
|
||||
|
||||
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()) {
|
||||
@ -27,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;
|
||||
|
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