forked from RepoMirrors/kami-blue
Merge pull request #667 from kami-blue/feature/updateChecker
Merge the update checker
This commit is contained in:
commit
65ff92c875
|
@ -9,6 +9,7 @@ CUR_BETA="$(cat ./scripts/curBeta)"
|
|||
sed -i "s/modVersion=.*/modVersion=${CUR_VER:1}$CUR_BETA/" gradle.properties
|
||||
sed -i "s/MODVER = \".*\";/MODVER = \"$CUR_VER$CUR_BETA\";/" src/main/java/me/zeroeightsix/kami/KamiMod.java
|
||||
sed -i "s/MODVERSMALL = \".*\";/MODVERSMALL = \"$CUR_VER$CUR_BETA\";/" src/main/java/me/zeroeightsix/kami/KamiMod.java
|
||||
sed -i "s/MODVERBROAD = \".*\";/MODVERBROAD = \"$CUR_VER\";/" src/main/java/me/zeroeightsix/kami/KamiMod.java
|
||||
sed -i "s/\"version\": \".*\",/\"version\": \"${CUR_VER:1}$CUR_BETA\",/" src/main/resources/mcmod.info
|
||||
|
||||
git reset
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.zeroeightsix.kami;
|
|||
import com.google.common.base.Converter;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import me.zero.alpine.EventBus;
|
||||
import me.zero.alpine.EventManager;
|
||||
|
@ -32,6 +33,7 @@ import net.minecraftforge.fml.common.Mod;
|
|||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
@ -40,6 +42,7 @@ import java.io.BufferedReader;
|
|||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
|
@ -51,19 +54,23 @@ import java.util.Optional;
|
|||
/**
|
||||
* Created by 086 on 7/11/2017.
|
||||
* Updated by S-B99 on 25/03/19
|
||||
* Updated by Dewy on 09/04/2020
|
||||
*/
|
||||
@Mod(
|
||||
modid = KamiMod.MODID,
|
||||
name = KamiMod.MODNAME,
|
||||
version = KamiMod.MODVER,
|
||||
updateJSON = KamiMod.UPDATE_JSON
|
||||
version = KamiMod.MODVER
|
||||
)
|
||||
public class KamiMod {
|
||||
|
||||
public static final String MODNAME = "KAMI Blue";
|
||||
public static final String MODID = "kamiblue";
|
||||
public static final String MODVER = "v1.1.2-beta";
|
||||
public static final String MODVERSMALL = "v1.1.2-beta";
|
||||
public static final String MODVER = "v1.1.2-beta"; // this is changed to v1.1.2-commit for debugging during travis releases
|
||||
public static final String MODVERSMALL = "v1.1.2-beta"; // shown to the user
|
||||
public static final String MODVERBROAD = "v1.1.1"; // used for update checking
|
||||
|
||||
public static final String MCVER = "1.12.2";
|
||||
|
||||
public static final String APP_ID = "638403216278683661";
|
||||
|
||||
static final String UPDATE_JSON = "https://raw.githubusercontent.com/kami-blue/assets/assets/assets/updateChecker.json";
|
||||
|
@ -72,9 +79,6 @@ public class KamiMod {
|
|||
public static final String GITHUB_LINK = "https://github.com/kami-blue/";
|
||||
public static final String WEBSITE_LINK = "https://blue.bella.wtf";
|
||||
|
||||
|
||||
// public static final String KAMI_HIRAGANA = "\u304B\u307F";
|
||||
// public static final String KAMI_KATAKANA = "\u30AB\u30DF";
|
||||
public static final String KAMI_KANJI = "\u30ab\u30df\u30d6\u30eb";
|
||||
public static final String KAMI_BLUE = "\u1d0b\u1d00\u1d0d\u026a \u0299\u029f\u1d1c\u1d07";
|
||||
public static final String KAMI_JAPANESE_ONTOP = "\u4e0a\u306b\u30ab\u30df\u30d6\u30eb\u30fc";
|
||||
|
@ -92,6 +96,10 @@ public class KamiMod {
|
|||
public static final EventBus EVENT_BUS = new EventManager();
|
||||
public static final ModuleManager MODULE_MANAGER = new ModuleManager();
|
||||
|
||||
public static String latest;
|
||||
public static boolean isLatest;
|
||||
public static boolean hasAskedToUpdate = false;
|
||||
|
||||
@Mod.Instance
|
||||
private static KamiMod INSTANCE;
|
||||
|
||||
|
@ -110,7 +118,9 @@ public class KamiMod {
|
|||
}).buildAndRegister("");
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) { }
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
updateCheck();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
|
@ -158,7 +168,6 @@ public class KamiMod {
|
|||
}
|
||||
}
|
||||
Display.setTitle(MODNAME + " " + KAMI_KANJI + " " + MODVERSMALL);
|
||||
// Display.setIcon(WindowIcon.ExtractByteBufferFromImagePath("kami.png"));
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
@ -302,4 +311,28 @@ public class KamiMod {
|
|||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public void updateCheck() {
|
||||
try {
|
||||
KamiMod.log.info("Attempting KAMI Blue update check...");
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
String latestVersion = parser.parse(IOUtils.toString(new URL(UPDATE_JSON))).getAsJsonObject().getAsJsonObject("promos").get(MCVER + "-latest").getAsString();
|
||||
|
||||
isLatest = latestVersion.equals(MODVERBROAD);
|
||||
latest = latestVersion;
|
||||
|
||||
if (!isLatest) {
|
||||
KamiMod.log.warn("You are running an outdated version of KAMI Blue.\nCurrent: " + MODVERBROAD + "\nLatest: " + latestVersion);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
KamiMod.log.info("Your KAMI Blue (" + MODVERBROAD + ") is up-to-date with the latest stable release.");
|
||||
} catch (IOException e) {
|
||||
KamiMod.log.error("Oes noes! An exception was thrown during the update check.");
|
||||
|
||||
KamiMod.log.error(e.getStackTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package me.zeroeightsix.kami.gui.mc;
|
||||
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
import me.zeroeightsix.kami.util.WebUtils;
|
||||
import net.minecraft.client.gui.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static me.zeroeightsix.kami.KamiMod.WEBSITE_LINK;
|
||||
|
||||
/**
|
||||
* Created by Dewy on 09/04/2020
|
||||
*/
|
||||
public class KamiGuiUpdateNotification extends GuiScreen {
|
||||
|
||||
private final String title;
|
||||
private final String message;
|
||||
private final int singleOrMulti;
|
||||
|
||||
public KamiGuiUpdateNotification(String title, String message, int singleOrMulti) {
|
||||
super();
|
||||
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
this.singleOrMulti = singleOrMulti;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, 200, "Download Latest (Recommended)"));
|
||||
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, 230, KamiMod.colour + "cUse Current Version"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawGradientRect(0, 0, this.width, this.height, -12574688, -11530224);
|
||||
|
||||
drawCenteredString(this.fontRenderer, this.title, this.width / 2, 80, 10260478);
|
||||
drawCenteredString(this.fontRenderer, this.message, this.width / 2, 110, 16777215);
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
|
||||
if (button.id == 0) {
|
||||
try {
|
||||
WebUtils.openWebLink(new URI(WEBSITE_LINK + "/download"));
|
||||
|
||||
if (singleOrMulti == 1) {
|
||||
mc.displayGuiScreen(new GuiWorldSelection(new GuiMainMenu()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mc.displayGuiScreen(new GuiMultiplayer(new GuiMainMenu())); // Multi
|
||||
} catch (URISyntaxException e) {
|
||||
KamiMod.log.error("Contact the KAMI Blue developers. Download link could not be parsed into URI reference form.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (singleOrMulti == 1) { // Single
|
||||
mc.displayGuiScreen(new GuiWorldSelection(new GuiMainMenu()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mc.displayGuiScreen(new GuiMultiplayer(new GuiMainMenu())); // Multi
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package me.zeroeightsix.kami.mixin.client;
|
||||
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
import me.zeroeightsix.kami.gui.mc.KamiGuiUpdateNotification;
|
||||
import me.zeroeightsix.kami.util.Wrapper;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Created by Dewy on 09/04/2020
|
||||
*/
|
||||
@Mixin(GuiMainMenu.class)
|
||||
public abstract class MixinGuiMainMenu {
|
||||
|
||||
@Inject(method = "actionPerformed", at = @At("HEAD"), cancellable = true)
|
||||
public void onActionPerformed(GuiButton btn, CallbackInfo callbackInfo) {
|
||||
if (!KamiMod.hasAskedToUpdate) {
|
||||
if (!KamiMod.isLatest) {
|
||||
if (btn.id == 1) {
|
||||
Wrapper.getMinecraft().displayGuiScreen(new KamiGuiUpdateNotification("KAMI Blue Update", "A newer release of KAMI Blue is available (" + KamiMod.latest + ").", btn.id));
|
||||
KamiMod.hasAskedToUpdate = true;
|
||||
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
|
||||
if (btn.id == 2) {
|
||||
Wrapper.getMinecraft().displayGuiScreen(new KamiGuiUpdateNotification("KAMI Blue Update", "A newer release of KAMI Blue is available (" + KamiMod.latest + ").", btn.id));
|
||||
KamiMod.hasAskedToUpdate = true;
|
||||
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package me.zeroeightsix.kami.util;
|
||||
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* Created by Dewy on 09/04/2020
|
||||
*/
|
||||
public class WebUtils {
|
||||
|
||||
public static void openWebLink(URI url) {
|
||||
try {
|
||||
Desktop.getDesktop().browse(url);
|
||||
} catch (IOException e) {
|
||||
KamiMod.log.error("Couldn't open link: " + url.toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
"MixinEntityRenderer",
|
||||
"MixinFrustum",
|
||||
"MixinGuiChat",
|
||||
"MixinGuiMainMenu",
|
||||
"MixinGuiNewChat",
|
||||
"MixinGuiPlayerTabOverlay",
|
||||
"MixinGuiScreen",
|
||||
|
|
Loading…
Reference in New Issue