aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-07-30 17:56:23 +0200
committerLorenz <lo.scherf@gmail.com>2022-07-30 17:56:23 +0200
commit7333b83660bcd27fda2e3b83dffa28f55c1a9558 (patch)
treea9a0c59cc77673dd0ad2e0361a3a1825c0f3d658 /src/main
parent75e07d9bbcd92ffd42f1bb901f9a8890582afa9f (diff)
downloadNotEnoughUpdates-7333b83660bcd27fda2e3b83dffa28f55c1a9558.tar.gz
NotEnoughUpdates-7333b83660bcd27fda2e3b83dffa28f55c1a9558.tar.bz2
NotEnoughUpdates-7333b83660bcd27fda2e3b83dffa28f55c1a9558.zip
add support for profile switching
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java18
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java27
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperRepoLoader.java1
5 files changed, 47 insertions, 11 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index cd0d08b5..3dd13d49 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -29,6 +29,7 @@ import io.github.moulberry.notenoughupdates.auction.APIManager;
import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent;
import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe;
import io.github.moulberry.notenoughupdates.miscgui.KatSitterOverlay;
+import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
import io.github.moulberry.notenoughupdates.recipes.CraftingOverlay;
import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe;
import io.github.moulberry.notenoughupdates.recipes.Ingredient;
@@ -158,6 +159,7 @@ public class NEUManager {
public void setCurrentProfile(String currentProfile) {
SBInfo.getInstance().currentProfile = currentProfile;
+ MinionHelperManager.getInstance().onProfileSwitch();
}
public String getCurrentProfile() {
@@ -207,7 +209,7 @@ public class NEUManager {
}
public CompletableFuture<Boolean> fetchRepository() {
- return CompletableFuture.<Boolean>supplyAsync(() -> {
+ return CompletableFuture.supplyAsync(() -> {
try {
JsonObject currentCommitJSON = getJsonFromFile(new File(configLocation, "currentCommit.json"));
@@ -1519,7 +1521,7 @@ public class NEUManager {
return NotEnoughUpdates.INSTANCE.manager
.fetchRepository()
.thenCompose(ignored -> NotEnoughUpdates.INSTANCE.manager.reloadRepository())
- .<List<String>>thenApply(ignored -> {
+ .thenApply(ignored -> {
String newCommitHash = NotEnoughUpdates.INSTANCE.manager.latestRepoCommit;
String newCommitShortHash = (newCommitHash == null ? "MISSING" : newCommitHash.substring(0, 7));
return Arrays.asList(
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java
index 0a6c4a99..20917103 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperManager.java
@@ -92,7 +92,8 @@ public class MinionHelperManager {
}
public boolean isReadyToUse() {
- return MinionHelperRepoLoader.getInstance().isRepoReadyToUse();
+ return MinionHelperRepoLoader.getInstance().isRepoReadyToUse() &&
+ MinionHelperApiLoader.getInstance().isApiReadyToUse();
}
public Minion getMinionById(String internalName) {
@@ -356,15 +357,26 @@ public class MinionHelperManager {
Utils.addChatMessage("");
}
- public List<Minion> getChilds(Minion minion) {
+ public List<Minion> getChildren(Minion minion) {
List<Minion> list = new ArrayList<>();
for (Minion other : minions.values()) {
if (minion == other.getParent()) {
list.add(other);
- list.addAll(getChilds(other));
+ list.addAll(getChildren(other));
break;
}
}
return list;
}
+
+ public void onProfileSwitch() {
+ //TODO check if the feature is enabled
+ for (Minion minion : minions.values()) {
+ minion.setCrafted(false);
+ minion.setMeetRequirements(false);
+ }
+ apiData = null;
+
+ MinionHelperApiLoader.getInstance().onProfileSwitch();
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
index 03c7e271..2f6b21f9 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
@@ -26,7 +26,6 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.ApiData;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
-import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperOverlay;
import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.SBInfo;
@@ -48,6 +47,8 @@ public class MinionHelperApiLoader {
private boolean dirty = true;
private int ticks = 0;
private boolean collectionApiEnabled = true;
+ private boolean ignoreWorldSwitches = false;
+ private boolean apiReadyToUse = false;
public static MinionHelperApiLoader getInstance() {
if (instance == null) {
@@ -58,7 +59,9 @@ public class MinionHelperApiLoader {
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
- dirty = true;
+ if (ignoreWorldSwitches) return;
+
+ setDirty();
}
@SubscribeEvent
@@ -192,10 +195,26 @@ public class MinionHelperApiLoader {
!collectionApiEnabled
));
manager.reloadRequirements();
- MinionHelperOverlay.getInstance().resetCache();
+ apiReadyToUse = true;
}
public void setDirty() {
- this.dirty = true;
+ dirty = true;
+ apiReadyToUse = false;
+ }
+
+ public void prepareProfileSwitch() {
+ ignoreWorldSwitches = true;
+ apiReadyToUse = false;
+ }
+
+ public void onProfileSwitch() {
+ setDirty();
+ ignoreWorldSwitches = false;
+ collectionApiEnabled = true;
+ }
+
+ public boolean isApiReadyToUse() {
+ return apiReadyToUse;
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java
index d4e0f3f4..6d6b3bda 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java
@@ -64,6 +64,10 @@ public class MinionHelperChatLoader {
MinionHelperOverlay.getInstance().resetCache();
}
+ if (message.startsWith("§r§7Switching to profile ")) {
+ MinionHelperApiLoader.getInstance().prepareProfileSwitch();
+ }
+
} catch (Exception e) {
Utils.addChatMessage(
"[NEU] §cMinion Helper failed reading the minion upgrade message. See the logs for more info!");
@@ -77,7 +81,7 @@ public class MinionHelperChatLoader {
if (!minion.doesMeetRequirements()) {
minion.setMeetRequirements(true);
- for (Minion child : manager.getChilds(minion)) {
+ for (Minion child : manager.getChildren(minion)) {
child.setMeetRequirements(true);
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperRepoLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperRepoLoader.java
index 7fecea6b..fca1bcb1 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperRepoLoader.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperRepoLoader.java
@@ -249,7 +249,6 @@ public class MinionHelperRepoLoader {
if (minion.getTier() != 1) break;
if (value.isEmpty()) break;
- //Requires: Red Sand I
String rawCollection = value.split(Pattern.quote(": "))[1];
String cleanCollection = StringUtils.removeLastWord(rawCollection, " ");
String rawTier = rawCollection.substring(cleanCollection.length() + 1);