Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
better auto updates
  • Loading branch information
valekatoz committed Feb 7, 2024
1 parent 473d4a8 commit b25a32a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod_name = Kore
mod_id = kore
version = 2.2.5
version_number = 22501
version_number = 22502
licensed = true
archiveBaseName = KoreClient
loom.platform=forge
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/net/kore/Kore.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Kore {

// Managers
public static LicenseManager licenseManager;
public static UpdateManager updateManager;
public static ModuleManager moduleManager;
public static ConfigManager configManager;
public static ThemeManager themeManager;
Expand Down Expand Up @@ -118,6 +119,8 @@ public static void start()
}

BlurUtils.registerListener();

updateManager = new UpdateManager();
}

public static void handleKey(int key)
Expand Down Expand Up @@ -152,17 +155,30 @@ public void postInit(FMLPostInitializationEvent event) {

@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (!licenseManager.hasConnected() && event.entity instanceof net.minecraft.client.entity.EntityPlayerSP) {
licenseManager.setConnected(true);

if(Boolean.parseBoolean(Kore.licensed)) {
if(licenseManager.isPremium()) {
sendMessageWithPrefix("You successfully authenticated to Kore (Premium)");
if(event.entity instanceof net.minecraft.client.entity.EntityPlayerSP) {
if (!licenseManager.hasConnected()) {
licenseManager.setConnected(true);

if(Boolean.parseBoolean(Kore.licensed)) {
if(licenseManager.isPremium()) {
sendMessageWithPrefix("You successfully authenticated to Kore (Premium)");
} else {
sendMessageWithPrefix("Looks like you are not premium. You should consider upgrading to premium for the best features.");
}
} else {
sendMessageWithPrefix("Looks like you are not premium. You should consider upgrading to premium for the best features.");
sendMessageWithPrefix("You are in the unlicensed version");
}
}

if(Kore.clientSettings.autoUpdate.isEnabled() && !updateManager.hasChecked()) {
updateManager.setChecked(true);

if (Boolean.parseBoolean(Kore.licensed)) {
if(updateManager.checkUpdate()) {
sendMessageWithPrefix("An update is available, restart your game to update.");
updateManager.update();
}
}
} else {
sendMessageWithPrefix("You are in the unlicensed version");
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/net/kore/commands/impl/KoreCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,34 @@ public KoreCommand()
public void execute(String[] args) throws Exception {
if (args.length > 2)
{
Kore.sendMessageWithPrefix(".kore <help/dev/disconnect>");
Kore.sendMessageWithPrefix(".kore <help/check/disconnect>");
return;
}

if(args.length > 1 && args[1].equals("help")) {
CommandManager.printHelp();
} else if(args.length > 1 && args[1].equals("dev")) {
// Dev test command
Kore.notificationManager.showNotification("This is a notification", 2000, Notification.NotificationType.INFO);
Kore.sendMessageWithPrefix("(&cDev&f) Notification executed");

} else if(args.length > 1 && args[1].equals("check")) {
if(Kore.updateManager.checkUpdate()) {
Kore.sendMessageWithPrefix("(&cUpdater&f) You are not running the latest version");
} else {
Kore.sendMessageWithPrefix("(&cUpdater&f) You are running the latest version");
}

} else if(args.length > 1 && args[1].equals("disconnect")) {
if(Kore.licenseManager.disconnect()) {
Kore.sendMessageWithPrefix("(&cDev&f) You successfully disconnected from Kore");
Kore.sendMessageWithPrefix("(&cLicense&f) You successfully disconnected from Kore");
} else {
Kore.sendMessageWithPrefix("(&cDev&f) You are in the unlicensed version.");
Kore.sendMessageWithPrefix("(&cLicense&f) You are in the unlicensed version.");
}

} else {
Kore.sendMessageWithPrefix("(&cDiscord&f) -> https://discord.com/invite/H4x6eFp9KR");
}
}

@Override
public String getDescription() {
return ".kore <help/dev/disconnect>";
return ".kore <help/update/disconnect>";
}
}
58 changes: 58 additions & 0 deletions src/main/java/net/kore/managers/UpdateManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.kore.managers;

import moe.nea.libautoupdate.CurrentVersion;
import moe.nea.libautoupdate.UpdateContext;
import moe.nea.libautoupdate.UpdateSource;
import moe.nea.libautoupdate.UpdateTarget;
import net.kore.Kore;

import java.util.concurrent.CompletableFuture;
import java.util.Base64;

public class UpdateManager {
private boolean checked = false;
private UpdateContext updateContext;
private boolean updateAvailable = false;
private String stream = "upstream";

public UpdateManager() {
// Auto Updater (Licensed only)
updateContext = new UpdateContext(
UpdateSource.gistSource("valekatoz","83a452dad0b31823d77f3b37e6a5ff3b"),
UpdateTarget.deleteAndSaveInTheSameFolder(Kore.class),
CurrentVersion.of(Integer.parseInt(Kore.VERSION_NUMBER)),
Base64.getEncoder().encodeToString(Kore.MOD_ID.getBytes())
);
updateContext.cleanup();
}

public void update() {
updateContext.checkUpdate(stream).thenCompose(it -> {
if(it.isUpdateAvailable()) {
updateAvailable = false;
}

return it.launchUpdate();
}).join();
}

public boolean checkUpdate() {
updateContext.checkUpdate(stream).thenCompose(it -> {
if(it.isUpdateAvailable()) {
updateAvailable = true;
}

return CompletableFuture.completedFuture(null);
}).join();

return updateAvailable;
}

public boolean hasChecked() {
return checked;
}

public void setChecked(boolean hasChecked) {
this.checked = hasChecked;
}
}
23 changes: 0 additions & 23 deletions src/main/java/net/kore/modules/ClientSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,6 @@ public ClientSettings() {
unlockerToggle = unlockerToggle();

this.addSettings(hideModules, debug, autoUpdate, richPresence, cosmeticsUnlocker);

// Auto Updater (Licensed only)

if(Boolean.parseBoolean(Kore.licensed) && this.autoUpdate.isEnabled()) {
String stream = "upstream";
UpdateContext updateContext = new UpdateContext(
UpdateSource.gistSource("valekatoz","83a452dad0b31823d77f3b37e6a5ff3b"),
UpdateTarget.deleteAndSaveInTheSameFolder(Kore.class),
CurrentVersion.of(Integer.parseInt(Kore.VERSION_NUMBER)),
Base64.getEncoder().encodeToString(Kore.MOD_ID.getBytes())
);
updateContext.cleanup();

System.out.println("Update cleaned");
System.out.println("Created update context: " + updateContext);

updateContext.checkUpdate(stream).thenCompose(it -> {
System.out.println("Checked for update on " + stream + ": " + it);
System.out.println("Can update: " + it.isUpdateAvailable());
return it.launchUpdate();
}).join();

}
}

@SubscribeEvent
Expand Down

0 comments on commit b25a32a

Please sign in to comment.