Refresh the state

This commit is contained in:
Mathieu 2020-04-28 20:57:15 +02:00
parent bf0b510cf0
commit 2b489d3bf5
10 changed files with 19 additions and 4 deletions

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.5"
version = "1.6"
group = "ch.m4th1eu.richpresence" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "richpresence"

View File

@ -1,5 +1,6 @@
#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
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View File

@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets;
public class Utils {
public static final Utils instance = new Utils();
public static int status = 0;
public static String readTextFromURL(String url) throws IOException {
URL urlObject;
@ -45,8 +46,11 @@ public class Utils {
try {
variable = variable.replaceAll("%player-name%", Minecraft.getMinecraft().getSession().getUsername());
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-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) {
}
@ -56,6 +60,8 @@ public class Utils {
public void updateStatus(int id) {
Thread t = new Thread(() -> {
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");
@ -88,6 +94,7 @@ public class Utils {
private String getState(JSONObject jsonObject) {
String state = replaceArgsString(Main.config_object.getString("state"));
System.out.println(state);
if (jsonObject.getBoolean("showState")) {
return state;

View File

@ -9,6 +9,7 @@ import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraftforge.client.event.GuiOpenEvent;
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;
/**
@ -17,6 +18,12 @@ import net.minecraftforge.fml.common.network.FMLNetworkEvent;
@Mod.EventBusSubscriber
public class AdvancedStatusEvent {
@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) {