Skip to content

Commit

Permalink
Forge Update Checker
Browse files Browse the repository at this point in the history
  • Loading branch information
LotuxPunk committed Oct 16, 2018
1 parent e288a43 commit 95b717b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/vandendaelen/handles/Handles.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
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 net.minecraftforge.fml.common.gameevent.PlayerEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(modid = Reference.MODID,name = Reference.MOD_NAME,version = Reference.VERSION.VERSION,dependencies = Reference.DEP)
@Mod(modid = Reference.MODID,name = Reference.MOD_NAME,version = Reference.VERSION.VERSION,dependencies = Reference.DEP, updateJSON = Reference.UPDATE_JSON)
public class Handles {
public static final Logger LOGGER = LogManager.getLogger(Reference.MOD_NAME);

Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/vandendaelen/handles/event/CommonEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.vandendaelen.handles.event;

import com.vandendaelen.handles.utils.Reference;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;

@Mod.EventBusSubscriber(modid = Reference.MODID)
public class CommonEvent {
@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent e){
EntityPlayer player = e.player;
if (!player.world.isRemote){
ForgeVersion.CheckResult version = ForgeVersion.getResult(Loader.instance().activeModContainer());
if (version.status == ForgeVersion.Status.OUTDATED){
TextComponentString url = new TextComponentString(TextFormatting.DARK_AQUA + TextFormatting.BOLD.toString() + "UPDATE");
url.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://minecraft.curseforge.com/projects/handles"));
url.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Open link")));

player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + "[Handles] : ").appendSibling(url));
String changes = String.valueOf(version.changes).replace("{" + version.target + "=", "").replace("}", "");
player.sendMessage(new TextComponentString(TextFormatting.DARK_AQUA + "Changelog: " + TextFormatting.AQUA + changes));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Reference {
public static final String DEP = "after:tardis, computercraft; required-after:forge@[14.23.4.2768,)";
public static final String CLIENT_PROXY_CLASS = "com.vandendaelen.handles.proxy.ClientProxy";
public static final String SERVER_PROXY_CLASS = "com.vandendaelen.handles.proxy.ServerProxy";
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/LotuxPunk/Handles/master/update.json";


public static class VERSION{
Expand Down
11 changes: 11 additions & 0 deletions update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://minecraft.curseforge.com/projects/k9-mod",
"promos": {
"1.12.2-latest": "1.12.2-1.1.2.0",
"1.12.2-recommended": "1.12.2-1.1.2.0"
},
"1.12.2": {
"1.12.2-1.1.1.1": "First release, fix crash at launch",
"1.12.2-1.1.2.0": "New methods, Forge Update Checker"
}
}

0 comments on commit 95b717b

Please sign in to comment.