Skip to content

Commit

Permalink
update installed message for everyone
Browse files Browse the repository at this point in the history
  • Loading branch information
Dams4K committed Jul 19, 2023
1 parent c69efde commit 4be1b6d
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 18 deletions.
1 change: 1 addition & 0 deletions build.10.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ targetCompatibility = 1.8

group = "fr.dams4k.cpsdisplay"
version = "mc1.10.2-${mod_version}"
archivesBaseName = "cpsdisplay"

minecraft {
version = "1.10.2-12.18.3.2511"
Expand Down
1 change: 1 addition & 0 deletions build.11.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ targetCompatibility = 1.8

group = "fr.dams4k.cpsdisplay"
version = "mc1.11.2-${mod_version}"
archivesBaseName = "cpsdisplay"

minecraft {
version = "1.11.2-13.20.1.2588"
Expand Down
1 change: 1 addition & 0 deletions build.8.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ targetCompatibility = 1.8

group = "fr.dams4k.cpsdisplay"
version = "mc1.8.9-${mod_version}"
archivesBaseName = "cpsdisplay"

minecraft {
version = "1.8.9-11.15.1.1722"
Expand Down
1 change: 1 addition & 0 deletions build.9.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ targetCompatibility = 1.8

group = "fr.dams4k.cpsdisplay"
version = "mc1.9.4-${mod_version}"
archivesBaseName = "cpsdisplay"

minecraft {
version = "1.9.4-12.17.0.2317-1.9.4"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public class VersionManagerConfig {
public static boolean patchUpdate = true;
public static boolean autoUpdate = true;

public static String latestVersion = "0.0.0";

private static Property majorUpdateProperty;
private static Property minorUpdateProperty;
private static Property patchUpdateProperty;
private static Property autoUpdateProperty;

private static Property latestVersionProperty;

public static void preInit() {
if (Launch.minecraftHome == null) {
Launch.minecraftHome = new File(".");
Expand All @@ -41,11 +45,16 @@ public static void loadConfig() {
minorUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "minor", minorUpdate);
patchUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "patch", patchUpdate);
autoUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "auto_update", autoUpdate);

latestVersionProperty = config.get(CATEGORY_VERSION_MANAGER, "latest_version", latestVersion);


majorUpdate = majorUpdateProperty.getBoolean();
minorUpdate = minorUpdateProperty.getBoolean();
patchUpdate = patchUpdateProperty.getBoolean();
autoUpdate = autoUpdateProperty.getBoolean();

latestVersion = latestVersionProperty.getString();
}

public static void saveConfig() {
Expand All @@ -54,6 +63,8 @@ public static void saveConfig() {
patchUpdateProperty.set(patchUpdate);
autoUpdateProperty.set(autoUpdate);

latestVersionProperty.set(latestVersion);

if (config.hasChanged()) {
config.save();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fr.dams4k.cpsdisplay.events;

import fr.dams4k.cpsdisplay.VersionManager;
import fr.dams4k.cpsdisplay.CPSDisplay;
import fr.dams4k.cpsdisplay.References;
import fr.dams4k.cpsdisplay.VersionChecker;
import fr.dams4k.cpsdisplay.VersionManager;
import fr.dams4k.cpsdisplay.config.VersionManagerConfig;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
Expand All @@ -19,11 +20,30 @@ public class VersionCheckerEvent {
@SubscribeEvent
public void onClientJoinWorld(EntityJoinWorldEvent event) {
if (event.getEntity() instanceof EntityPlayerSP) {
EntityPlayerSP player = (EntityPlayerSP) event.getEntity();

// Check if a new version has been installed
if (!VersionManagerConfig.latestVersion.equals(References.MOD_VERSION)) {
VersionManagerConfig.latestVersion = References.MOD_VERSION;
VersionManagerConfig.saveConfig();

ITextComponent modNameMessage = new TextComponentString(I18n.format("cpsdisplay.version.mod_name", new Object[0]));

String modInstalledString = I18n.format("cpsdisplay.version.installed", new Object[0]);
ITextComponent modInstalledMessage = new TextComponentString(modInstalledString.replace("{version}", References.MOD_VERSION));

ITextComponent message = new TextComponentString("");
message.appendSibling(modNameMessage);
message.appendText(" ");
message.appendSibling(modInstalledMessage);

player.addChatMessage(message);
}

// Check if a new version available
VersionManager versionManager = CPSDisplay.versionManager;
VersionChecker versionChecker = new VersionChecker(References.MOD_VERSION);
if (versionChecker.compareTo(versionManager.latestVersion) == VersionChecker.LOWER) {
EntityPlayerSP player = (EntityPlayerSP) event.getEntity();

// MOD NAME
ITextComponent modNameMessage = new TextComponentString(I18n.format("cpsdisplay.version.mod_name", new Object[0]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public class VersionManagerConfig {
public static boolean patchUpdate = true;
public static boolean autoUpdate = true;

public static String latestVersion = "0.0.0";

private static Property majorUpdateProperty;
private static Property minorUpdateProperty;
private static Property patchUpdateProperty;
private static Property autoUpdateProperty;

private static Property latestVersionProperty;

public static void preInit() {
if (Launch.minecraftHome == null) {
Launch.minecraftHome = new File(".");
Expand All @@ -41,11 +45,16 @@ public static void loadConfig() {
minorUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "minor", minorUpdate);
patchUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "patch", patchUpdate);
autoUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "auto_update", autoUpdate);

latestVersionProperty = config.get(CATEGORY_VERSION_MANAGER, "latest_version", latestVersion);


majorUpdate = majorUpdateProperty.getBoolean();
minorUpdate = minorUpdateProperty.getBoolean();
patchUpdate = patchUpdateProperty.getBoolean();
autoUpdate = autoUpdateProperty.getBoolean();

latestVersion = latestVersionProperty.getString();
}

public static void saveConfig() {
Expand All @@ -54,6 +63,8 @@ public static void saveConfig() {
patchUpdateProperty.set(patchUpdate);
autoUpdateProperty.set(autoUpdate);

latestVersionProperty.set(latestVersion);

if (config.hasChanged()) {
config.save();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fr.dams4k.cpsdisplay.events;

import fr.dams4k.cpsdisplay.VersionManager;
import fr.dams4k.cpsdisplay.CPSDisplay;
import fr.dams4k.cpsdisplay.References;
import fr.dams4k.cpsdisplay.VersionChecker;
import fr.dams4k.cpsdisplay.VersionManager;
import fr.dams4k.cpsdisplay.config.VersionManagerConfig;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
Expand All @@ -19,11 +20,30 @@ public class VersionCheckerEvent {
@SubscribeEvent
public void onClientJoinWorld(EntityJoinWorldEvent event) {
if (event.getEntity() instanceof EntityPlayerSP) {
EntityPlayerSP player = (EntityPlayerSP) event.getEntity();

// Check if a new version has been installed
if (!VersionManagerConfig.latestVersion.equals(References.MOD_VERSION)) {
VersionManagerConfig.latestVersion = References.MOD_VERSION;
VersionManagerConfig.saveConfig();

ITextComponent modNameMessage = new TextComponentString(I18n.format("cpsdisplay.version.mod_name", new Object[0]));

String modInstalledString = I18n.format("cpsdisplay.version.installed", new Object[0]);
ITextComponent modInstalledMessage = new TextComponentString(modInstalledString.replace("{version}", References.MOD_VERSION));

ITextComponent message = new TextComponentString("");
message.appendSibling(modNameMessage);
message.appendText(" ");
message.appendSibling(modInstalledMessage);

player.sendMessage(message);
}

// Check if a new version available
VersionManager versionManager = CPSDisplay.versionManager;
VersionChecker versionChecker = new VersionChecker(References.MOD_VERSION);
if (versionChecker.compareTo(versionManager.latestVersion) == VersionChecker.LOWER) {
EntityPlayerSP player = (EntityPlayerSP) event.getEntity();

// MOD NAME
ITextComponent modNameMessage = new TextComponentString(I18n.format("cpsdisplay.version.mod_name", new Object[0]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public class VersionManagerConfig {
public static boolean patchUpdate = true;
public static boolean autoUpdate = true;

public static String latestVersion = "0.0.0";

private static Property majorUpdateProperty;
private static Property minorUpdateProperty;
private static Property patchUpdateProperty;
private static Property autoUpdateProperty;

private static Property latestVersionProperty;

public static void preInit() {
if (Launch.minecraftHome == null) {
Launch.minecraftHome = new File(".");
Expand All @@ -41,11 +45,16 @@ public static void loadConfig() {
minorUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "minor", minorUpdate);
patchUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "patch", patchUpdate);
autoUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "auto_update", autoUpdate);

latestVersionProperty = config.get(CATEGORY_VERSION_MANAGER, "latest_version", latestVersion);


majorUpdate = majorUpdateProperty.getBoolean();
minorUpdate = minorUpdateProperty.getBoolean();
patchUpdate = patchUpdateProperty.getBoolean();
autoUpdate = autoUpdateProperty.getBoolean();

latestVersion = latestVersionProperty.getString();
}

public static void saveConfig() {
Expand All @@ -54,6 +63,8 @@ public static void saveConfig() {
patchUpdateProperty.set(patchUpdate);
autoUpdateProperty.set(autoUpdate);

latestVersionProperty.set(latestVersion);

if (config.hasChanged()) {
config.save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,46 @@
import fr.dams4k.cpsdisplay.References;
import fr.dams4k.cpsdisplay.VersionChecker;
import fr.dams4k.cpsdisplay.VersionManager;
import fr.dams4k.cpsdisplay.config.VersionManagerConfig;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.resources.I18n;
import net.minecraft.event.ClickEvent;
import net.minecraft.event.ClickEvent.Action;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class VersionCheckerEvent {
@SubscribeEvent
public void onClientJoinWorld(EntityJoinWorldEvent event) {
if (event.entity instanceof EntityPlayerSP) {
EntityPlayerSP player = (EntityPlayerSP) event.entity;

// Check if a new version has been installed
if (!VersionManagerConfig.latestVersion.equals(References.MOD_VERSION)) {
VersionManagerConfig.latestVersion = References.MOD_VERSION;
VersionManagerConfig.saveConfig();

IChatComponent modNameMessage = new ChatComponentText(I18n.format("cpsdisplay.version.mod_name", new Object[0]));

String modInstalledString = I18n.format("cpsdisplay.version.installed", new Object[0]);
IChatComponent modInstalledMessage = new ChatComponentText(modInstalledString.replace("{version}", References.MOD_VERSION));

IChatComponent message = new ChatComponentText("");
message.appendSibling(modNameMessage);
message.appendText(" ");
message.appendSibling(modInstalledMessage);

player.addChatMessage(message);
}

// Check if a new version available
VersionManager versionManager = CPSDisplay.versionManager;
VersionChecker versionChecker = new VersionChecker(References.MOD_VERSION);
if (versionChecker.compareTo(versionManager.latestVersion) == VersionChecker.LOWER) {
EntityPlayerSP player = (EntityPlayerSP) event.entity;

// MOD NAME
IChatComponent modNameMessage = new ChatComponentText(
I18n.format("cpsdisplay.version.mod_name", new Object[0]));
Expand All @@ -48,6 +69,7 @@ public void onClientJoinWorld(EntityJoinWorldEvent event) {

player.addChatMessage(message);
}
MinecraftForge.EVENT_BUS.unregister(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public class VersionManagerConfig {
public static boolean patchUpdate = true;
public static boolean autoUpdate = true;

public static String latestVersion = "0.0.0";

private static Property majorUpdateProperty;
private static Property minorUpdateProperty;
private static Property patchUpdateProperty;
private static Property autoUpdateProperty;

private static Property latestVersionProperty;

public static void preInit() {
if (Launch.minecraftHome == null) {
Launch.minecraftHome = new File(".");
Expand All @@ -41,11 +45,16 @@ public static void loadConfig() {
minorUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "minor", minorUpdate);
patchUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "patch", patchUpdate);
autoUpdateProperty = config.get(CATEGORY_VERSION_MANAGER, "auto_update", autoUpdate);

latestVersionProperty = config.get(CATEGORY_VERSION_MANAGER, "latest_version", latestVersion);


majorUpdate = majorUpdateProperty.getBoolean();
minorUpdate = minorUpdateProperty.getBoolean();
patchUpdate = patchUpdateProperty.getBoolean();
autoUpdate = autoUpdateProperty.getBoolean();

latestVersion = latestVersionProperty.getString();
}

public static void saveConfig() {
Expand All @@ -54,6 +63,8 @@ public static void saveConfig() {
patchUpdateProperty.set(patchUpdate);
autoUpdateProperty.set(autoUpdate);

latestVersionProperty.set(latestVersion);

if (config.hasChanged()) {
config.save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.dams4k.cpsdisplay.References;
import fr.dams4k.cpsdisplay.VersionChecker;
import fr.dams4k.cpsdisplay.VersionManager;
import fr.dams4k.cpsdisplay.config.VersionManagerConfig;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
Expand All @@ -19,11 +20,30 @@ public class VersionCheckerEvent {
@SubscribeEvent
public void onClientJoinWorld(EntityJoinWorldEvent event) {
if (event.getEntity() instanceof EntityPlayerSP) {
EntityPlayerSP player = (EntityPlayerSP) event.getEntity();

// Check if a new version has been installed
if (!VersionManagerConfig.latestVersion.equals(References.MOD_VERSION)) {
VersionManagerConfig.latestVersion = References.MOD_VERSION;
VersionManagerConfig.saveConfig();

ITextComponent modNameMessage = new TextComponentString(I18n.format("cpsdisplay.version.mod_name", new Object[0]));

String modInstalledString = I18n.format("cpsdisplay.version.installed", new Object[0]);
ITextComponent modInstalledMessage = new TextComponentString(modInstalledString.replace("{version}", References.MOD_VERSION));

ITextComponent message = new TextComponentString("");
message.appendSibling(modNameMessage);
message.appendText(" ");
message.appendSibling(modInstalledMessage);

player.addChatMessage(message);
}

// Check if a new version available
VersionManager versionManager = CPSDisplay.versionManager;
VersionChecker versionChecker = new VersionChecker(References.MOD_VERSION);
if (versionChecker.compareTo(versionManager.latestVersion) == VersionChecker.LOWER) {
EntityPlayerSP player = (EntityPlayerSP) event.getEntity();

// MOD NAME
ITextComponent modNameMessage = new TextComponentString(I18n.format("cpsdisplay.version.mod_name", new Object[0]));

Expand Down
Loading

0 comments on commit 4be1b6d

Please sign in to comment.