Replace custom update system with forge update checker
This commit is contained in:
@@ -35,6 +35,7 @@ import java.util.Queue;
|
|||||||
|
|
||||||
@Mod(modid = ReplayMod.MOD_ID,
|
@Mod(modid = ReplayMod.MOD_ID,
|
||||||
useMetadata = true,
|
useMetadata = true,
|
||||||
|
updateJSON = "https://raw.githubusercontent.com/ReplayMod/ReplayMod/master/versions.json",
|
||||||
guiFactory = "com.replaymod.core.gui.GuiFactory")
|
guiFactory = "com.replaymod.core.gui.GuiFactory")
|
||||||
public class ReplayMod {
|
public class ReplayMod {
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ public class ReplayModExtras {
|
|||||||
FullBrightness.class,
|
FullBrightness.class,
|
||||||
HotkeyButtons.class,
|
HotkeyButtons.class,
|
||||||
LocalizationExtra.class,
|
LocalizationExtra.class,
|
||||||
OpenEyeExtra.class,
|
OpenEyeExtra.class
|
||||||
VersionChecker.class
|
|
||||||
);
|
);
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
package com.replaymod.extras;
|
|
||||||
|
|
||||||
import com.replaymod.core.ReplayMod;
|
|
||||||
import com.replaymod.online.ReplayModOnline;
|
|
||||||
import net.minecraft.client.gui.Gui;
|
|
||||||
import net.minecraft.client.gui.GuiMainMenu;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class VersionChecker implements Extra {
|
|
||||||
@Mod.Instance(ReplayModOnline.MOD_ID)
|
|
||||||
private static ReplayModOnline module;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(ReplayMod mod) throws Exception {
|
|
||||||
final String currentVersion = mod.getVersion();
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
boolean upToDate = module.getApiClient().isVersionUpToDate(currentVersion);
|
|
||||||
if (!upToDate) {
|
|
||||||
MinecraftForge.EVENT_BUS.register(VersionChecker.this);
|
|
||||||
}
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, "ReplayMod-VersionChecker").start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
|
|
||||||
if (!(event.gui instanceof GuiMainMenu)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int width = Math.max(100, event.gui.width / 2 - 100 - 10);
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") List<String> lines =
|
|
||||||
event.gui.mc.fontRendererObj.listFormattedStringToWidth(I18n.format("replaymod.gui.outdated"), width);
|
|
||||||
|
|
||||||
int maxLineWidth = 0;
|
|
||||||
for(String line : lines) {
|
|
||||||
int lineWidth = event.gui.mc.fontRendererObj.getStringWidth(line);
|
|
||||||
if(lineWidth > maxLineWidth) {
|
|
||||||
maxLineWidth = lineWidth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Gui.drawRect(2, 77, 5 + maxLineWidth + 3, 80 + (lines.size() * 10), 0x80FF0000);
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for(String line : lines) {
|
|
||||||
event.gui.mc.fontRendererObj.drawStringWithShadow(line, 5, 80 + (i * 10), Color.WHITE.getRGB());
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user