Ajout fichier de config

This commit is contained in:
M4TH1EU 2019-07-16 11:28:29 +02:00
parent 7557a909ea
commit 2f463737d5
8 changed files with 268 additions and 61 deletions

205
.gitignore vendored
View File

@ -1,22 +1,195 @@
# eclipse
bin
*.launch
.settings
# Created by https://www.gitignore.io/api/java,eclipse,intellij,forgegradle
# Edit at https://www.gitignore.io/?templates=java,eclipse,intellij,forgegradle
### Eclipse ###
.metadata
.classpath
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
### Eclipse Patch ###
# Eclipse Core
.project
# idea
out
*.ipr
# JDT-specific (Eclipse Java Development Tools)
.classpath
# Annotation Processing
.apt_generated
.sts4-cache/
### ForgeGradle ###
# Minecraft client/server files
run/**
run/
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**
.idea/**/
.idea/*
.idea/*/
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
*.iml
.idea
# gradle
build
.gradle
# IntelliJ
out/
# other
eclipse
run
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/sonarlint
### Java ###
# Compiled class file
*.class
build/**
classes/**
classes/**/
classes/*/
classes/*
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# End of https://www.gitignore.io/api/java,eclipse,intellij,forgegradle

View File

@ -11,11 +11,12 @@ 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.0"
group = "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "modid"
version = "1.1"
group = "ch.m4th1eu.richpresence" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "richpresence"
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
sourceCompatibility = targetCompatibility = '1.8' // Need
// this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}

View File

@ -1,9 +1,8 @@
package ch.m4th1eu.richpresence;
import ch.m4th1eu.richpresence.events.AdvancedStatusEvent;
import ch.m4th1eu.richpresence.events.EventPresence;
import ch.m4th1eu.richpresence.events.Events;
import ch.m4th1eu.richpresence.proxy.CommonProxy;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod;
@ -11,26 +10,35 @@ 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 net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.logging.log4j.Logger;
/**
* @author M4TH1EU_#0001
*/
@Mod(modid = Main.MODID, name = Main.NAME, version = Main.VERSION)
public class Main {
public static final String MODID = "richpresence";
public static final String NAME = "Discord Rich Presence";
public static final String VERSION = "1.0.0";
public EventPresence rpcClient;
public static final String VERSION = "1.1";
@SidedProxy(clientSide = "ch.m4th1eu.richpresence.proxy.ClientProxy", serverSide = "ch.m4th1eu.richpresence.proxy.CommonProxy")
public static CommonProxy proxy;
public static String applicationId;
/**
* Variables pour la config
*/
public static String applicationId, largeimage, largeimagetext;
public static boolean advancedstatus;
private static Logger logger;
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());
@ -39,7 +47,11 @@ public class Main {
Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
try {
cfg.load();
applicationId = cfg.getString("applicationId", "", "applicationId", "this is a comment");
applicationId = cfg.getString("applicationID", "DiscordRichPresence", "ex: 491941559181246465", "Ici mettez le client id de votre application (https://bit.ly/2Lu1CC3).");
largeimage = cfg.getString("largeimage", "DiscordRichPresence", "logo", "Ici mettez le nom de votre image (celle dans RichPresence -> Art Assets). (sans le .png)");
largeimagetext = cfg.getString("largeimagetext", "DiscordRichPresence", "Mon serveur !", "Ici mettez le texte qui s'affichera quand vous passerez la souris sur l'image.");
advancedstatus = cfg.getBoolean("advancedstatus", "DiscordRichPresence", true, "Ici laissez \"true\" si vous voulez un status avancé sinon mettez \"false\".");
} catch (Exception ex) {
event.getModLog().error("Failed to load configuration");
@ -52,10 +64,6 @@ public class Main {
}
public Main() {
MinecraftForge.EVENT_BUS.register(new Events());
}
@EventHandler
public void init(FMLInitializationEvent event) {
@ -63,8 +71,12 @@ public class Main {
rpcClient = new EventPresence();
proxy.rpcinit();
proxy.rpcupdate("Dans le menu.", null);
if (Main.advancedstatus) {
proxy.rpcupdate("Dans le menu.", null);
} else {
proxy.rpcupdate("", null);
}
}

View File

@ -7,27 +7,36 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
/**
* @author M4TH1EU_#0001
*/
@Mod.EventBusSubscriber
public class Events {
public class AdvancedStatusEvent {
@SubscribeEvent
public void onServerJoin(FMLNetworkEvent.ClientConnectedToServerEvent event) {
Main.proxy.rpcupdate("En jeu.", null);
if (Main.advancedstatus) {
Main.proxy.rpcupdate("En jeu.", null);
}
}
@SubscribeEvent
public void onQuitServer(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
Main.proxy.rpcupdate("Dans le menu.", null);
if (Main.advancedstatus) {
Main.proxy.rpcupdate("Dans le menu principal.", null);
}
}
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
if (event.getGui() instanceof GuiIngameMenu) {
Main.proxy.rpcupdate("Dans le menu.", null);
}
if (Main.advancedstatus) {
if (event.getGui() instanceof GuiIngameMenu) {
Main.proxy.rpcupdate("Dans le menu pause.", null);
}
System.out.println(event.getGui());
System.out.println(event.getGui());
}
}

View File

@ -1,16 +1,20 @@
package ch.m4th1eu.richpresence.events;
import ch.m4th1eu.richpresence.Main;
import net.arikia.dev.drpc.DiscordEventHandlers;
import net.arikia.dev.drpc.DiscordRPC;
import net.arikia.dev.drpc.DiscordRichPresence;
/**
* @author M4TH1EU_#0001
*/
public class EventPresence {
private static Thread callbackRunner;
public synchronized static final void init() {
DiscordEventHandlers handlers = new DiscordEventHandlers();
DiscordRPC.discordInitialize("BOT CLIENT ID", handlers, true, null);
DiscordRPC.discordInitialize(Main.applicationId, handlers, true, null);
if (EventPresence.callbackRunner == null) {
(EventPresence.callbackRunner = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
@ -23,13 +27,13 @@ public class EventPresence {
return;
}, "RPC-Callback-Handler")).start();
}
System.out.println("EventPresence has been started.");
Main.logger.info("EventPresence has been started.");
}
public static final void updatePresence(String details, String action) {
DiscordRichPresence presence = new DiscordRichPresence();
presence.largeImageKey = "image";
presence.largeImageText = "TEXT";
presence.largeImageKey = Main.largeimage;
presence.largeImageText = Main.largeimagetext;
if (details != null) {
presence.details = details;

View File

@ -5,6 +5,9 @@ import net.minecraftforge.common.MinecraftForge;
import java.io.File;
/**
* @author M4TH1EU_#0001
*/
public class ClientProxy extends CommonProxy {
@Override

View File

@ -2,6 +2,9 @@ package ch.m4th1eu.richpresence.proxy;
import java.io.File;
/**
* @author M4TH1EU_#0001
*/
public class CommonProxy {
public void preInit(File configFile) {

View File

@ -1,16 +1,18 @@
[
{
"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": []
}
{
"modid": "richpresence",
"name": "Discord Rich Presence Mod",
"description": "Un mod pour ajouter un Rich Presence personnalisé",
"version": "${version}",
"mcversion": "1.12.2",
"url": "https://mathieubroillet.ch/",
"updateUrl": "",
"authorList": [
"M4TH1EU_"
],
"credits": "RPC Lib author(s)",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]