From 7bdb944ea83a2255dadaa5f2624b7faa02553d98 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 30 Jul 2022 22:40:11 +0200 Subject: moved all of api logic into api class --- .../notenoughupdates/NotEnoughUpdates.java | 1 - .../miscgui/minionhelper/MinionHelperManager.java | 40 ++++++------------- .../miscgui/minionhelper/MinionHelperOverlay.java | 6 +-- .../MinionHelperRequirementsManager.java | 13 +++--- .../loaders/MinionHelperApiLoader.java | 46 +++++++++++++++------- .../loaders/MinionHelperChatLoader.java | 2 +- 6 files changed, 54 insertions(+), 54 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 357760cf..366ad24c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -298,7 +298,6 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(MinionHelperRepoLoader.getInstance()); MinecraftForge.EVENT_BUS.register(MinionHelperInventoryLoader.getInstance()); - MinecraftForge.EVENT_BUS.register(MinionHelperApiLoader.getInstance()); MinecraftForge.EVENT_BUS.register(MinionHelperOverlay.getInstance()); MinecraftForge.EVENT_BUS.register(MinionHelperTooltips.getInstance()); MinecraftForge.EVENT_BUS.register(MinionHelperManager.getInstance()); 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 84eedd98..27c7240e 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 @@ -36,11 +36,10 @@ import java.util.Map; public class MinionHelperManager { private static MinionHelperManager instance = null; private final Map minions = new HashMap<>(); - private ApiData apiData = null; - private boolean shouldNotifyNoCollectionApi = false; private final MinionHelperPriceCalculation priceCalculation = new MinionHelperPriceCalculation(this); private final MinionHelperRequirementsManager requirementsManager = new MinionHelperRequirementsManager(this); + private final MinionHelperApiLoader api = new MinionHelperApiLoader(this); public static MinionHelperManager getInstance() { if (instance == null) { @@ -51,6 +50,7 @@ public class MinionHelperManager { private MinionHelperManager() { MinecraftForge.EVENT_BUS.register(priceCalculation); + MinecraftForge.EVENT_BUS.register(api); } public boolean inCraftedMinionsInventory() { @@ -68,7 +68,7 @@ public class MinionHelperManager { public boolean isReadyToUse() { return MinionHelperRepoLoader.getInstance().isRepoReadyToUse() && - MinionHelperApiLoader.getInstance().isApiReadyToUse(); + api.isApiReadyToUse(); } public Minion getMinionById(String internalName) { @@ -104,22 +104,6 @@ public class MinionHelperManager { return text.toUpperCase().replace(" ", "_"); } - public void setApiData(ApiData apiData) { - this.apiData = apiData; - } - - public boolean isCollectionApiDisabled() { - return apiData != null && apiData.isCollectionApiDisabled(); - } - - public void setShouldNotifyNoCollectionApi(boolean shouldNotifyNoCollectionApi) { - this.shouldNotifyNoCollectionApi = shouldNotifyNoCollectionApi; - } - - public boolean isShouldNotifyNoCollectionApi() { - return shouldNotifyNoCollectionApi; - } - public void handleCommand(String[] args) { if (args.length == 2) { String parameter = args[1]; @@ -134,13 +118,13 @@ public class MinionHelperManager { return; } if (parameter.equals("reloadapi")) { - apiData = null; - MinionHelperApiLoader.getInstance().setDirty(); + api.resetData(); + api.setDirty(); Utils.addChatMessage("api reload requested"); return; } if (parameter.equals("clearapi")) { - apiData = null; + api.resetData(); Utils.addChatMessage("api data cleared"); return; } @@ -173,22 +157,18 @@ public class MinionHelperManager { minion.setCrafted(false); minion.setMeetRequirements(false); } - apiData = null; - MinionHelperApiLoader.getInstance().onProfileSwitch(); + api.onProfileSwitch(); } public MinionHelperPriceCalculation getPriceCalculation() { return priceCalculation; } - public ApiData getApiData() { - return apiData; - } - public void reloadData() { requirementsManager.reloadRequirements(); + ApiData apiData = api.getApiData(); if (apiData != null) { for (String minion : apiData.getCraftedMinions()) { getMinionById(minion).setCrafted(true); @@ -199,4 +179,8 @@ public class MinionHelperManager { public MinionHelperRequirementsManager getRequirementsManager() { return requirementsManager; } + + public MinionHelperApiLoader getApi() { + return api; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlay.java index c521ab40..330d94c2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperOverlay.java @@ -88,7 +88,7 @@ public class MinionHelperOverlay { if (!manager.inCraftedMinionsInventory()) return; if (!manager.isReadyToUse()) return; - if (manager.isShouldNotifyNoCollectionApi()) { + if (manager.getApi().isNotifyNoCollectionApi()) { NotificationHandler.displayNotification(Lists.newArrayList( "", "§cCollection API is disabled!", @@ -96,7 +96,7 @@ public class MinionHelperOverlay { "§cdo not meet the collection requirements!" ), false, true); //TODO add tutorial how to enable collection api - manager.setShouldNotifyNoCollectionApi(false); + manager.getApi().setNotifyNoCollectionApi(false); } LinkedHashMap renderMap = getRenderMap(); @@ -197,7 +197,7 @@ public class MinionHelperOverlay { for (MinionRequirement requirement : requirements) { //TODO maybe change the §7 color String color = manager.getRequirementsManager().meetRequirement(minion, requirement) ? "§a" : "§7"; - if (requirement instanceof CollectionRequirement && manager.isCollectionApiDisabled()) { + if (requirement instanceof CollectionRequirement && manager.getApi().isCollectionApiDisabled()) { color = "§cAPI DISABLED! §7"; } lines.add(" §8- " + color + requirement.printDescription()); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperRequirementsManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperRequirementsManager.java index ae2e6b22..4dc1f578 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperRequirementsManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/MinionHelperRequirementsManager.java @@ -63,17 +63,18 @@ public class MinionHelperRequirementsManager { } public boolean meetRequirement(Minion minion, MinionRequirement requirement) { - if (manager.getApiData() == null) return false; + ApiData apiData = manager.getApi().getApiData(); + if (apiData == null) return false; if (requirement instanceof CollectionRequirement) { - if (manager.getApiData().isCollectionApiDisabled()) return true; + if (apiData.isCollectionApiDisabled()) return true; CollectionRequirement collectionRequirement = (CollectionRequirement) requirement; String collection = collectionRequirement.getCollection(); String internalName = manager.formatInternalName(collection); int need = collectionRequirement.getLevel(); - Map highestCollectionTier = manager.getApiData().getHighestCollectionTier(); + Map highestCollectionTier = apiData.getHighestCollectionTier(); if (highestCollectionTier.containsKey(internalName)) { int has = highestCollectionTier.get(internalName); @@ -84,7 +85,7 @@ public class MinionHelperRequirementsManager { SlayerRequirement slayerRequirement = (SlayerRequirement) requirement; String slayer = slayerRequirement.getSlayer(); int need = slayerRequirement.getLevel(); - Map slayerTiers = manager.getApiData().getSlayerTiers(); + Map slayerTiers = apiData.getSlayerTiers(); if (slayerTiers.containsKey(slayer)) { return slayerTiers.get(slayer) >= need; } @@ -94,9 +95,9 @@ public class MinionHelperRequirementsManager { int need = reputationRequirement.getReputation(); String reputationType = reputationRequirement.getReputationType(); if (reputationType.equals("BARBARIAN")) { - return manager.getApiData().getBarbariansReputation() >= need; + return apiData.getBarbariansReputation() >= need; } else if (reputationType.equals("MAGE")) { - return manager.getApiData().getMagesReputation() >= need; + return apiData.getMagesReputation() >= need; } else { Utils.addChatMessage("§c[NEU] Minion Helper: Unknown reputation type: '" + reputationType + "'"); return false; 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 16fc61a5..9ec89eeb 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 @@ -23,7 +23,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.core.util.MiscUtils; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.ApiData; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; @@ -45,19 +44,17 @@ import java.util.List; import java.util.Map; public class MinionHelperApiLoader { - private static MinionHelperApiLoader instance = null; - private final MinionHelperManager manager = MinionHelperManager.getInstance(); + private final MinionHelperManager manager; private boolean dirty = true; private int ticks = 0; private boolean collectionApiEnabled = true; private boolean ignoreWorldSwitches = false; private boolean apiReadyToUse = false; + private ApiData apiData = null; + private boolean notifyNoCollectionApi = false; - public static MinionHelperApiLoader getInstance() { - if (instance == null) { - instance = new MinionHelperApiLoader(); - } - return instance; + public MinionHelperApiLoader(MinionHelperManager manager) { + this.manager = manager; } @SubscribeEvent @@ -117,7 +114,7 @@ public class MinionHelperApiLoader { } } - private List loadMinionData(JsonObject members) { + private List loadCraftedMinionsData(JsonObject members) { List craftedMinions = new ArrayList<>(); for (Map.Entry entry : members.entrySet()) { JsonObject value = entry.getValue().getAsJsonObject(); @@ -171,7 +168,7 @@ public class MinionHelperApiLoader { collectionApiEnabled = true; } else { if (collectionApiEnabled) { - manager.setShouldNotifyNoCollectionApi(true); + notifyNoCollectionApi = true; } collectionApiEnabled = false; } @@ -210,16 +207,14 @@ public class MinionHelperApiLoader { } } - List craftedMinions = loadMinionData(members); - - manager.setApiData(new ApiData( + apiData = new ApiData( highestCollectionTier, slayerTier, magesReputation, barbariansReputation, !collectionApiEnabled, - craftedMinions - )); + loadCraftedMinionsData(members) + ); manager.reloadData(); apiReadyToUse = true; @@ -236,6 +231,7 @@ public class MinionHelperApiLoader { } public void onProfileSwitch() { + apiData = null; setDirty(); ignoreWorldSwitches = false; collectionApiEnabled = true; @@ -244,4 +240,24 @@ public class MinionHelperApiLoader { public boolean isApiReadyToUse() { return apiReadyToUse; } + + public ApiData getApiData() { + return apiData; + } + + public boolean isCollectionApiDisabled() { + return apiData != null && apiData.isCollectionApiDisabled(); + } + + public void resetData() { + apiData = null; + } + + public void setNotifyNoCollectionApi(boolean notifyNoCollectionApi) { + this.notifyNoCollectionApi = notifyNoCollectionApi; + } + + public boolean isNotifyNoCollectionApi() { + return notifyNoCollectionApi; + } } 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 6d6b3bda..ed379354 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 @@ -65,7 +65,7 @@ public class MinionHelperChatLoader { } if (message.startsWith("§r§7Switching to profile ")) { - MinionHelperApiLoader.getInstance().prepareProfileSwitch(); + manager.getApi().prepareProfileSwitch(); } } catch (Exception e) { -- cgit