diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-07-29 22:26:09 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-07-29 22:26:09 +0200 |
commit | 2b8c960c1a6a8fa6fca2d4e2ee7ec0f20492cb9e (patch) | |
tree | 0e692243cbef1d8b3d2daadfa7439f716eeb334a /src/main/java/io | |
parent | becaf5bf5b56fcf76c4934e2f1883b252fcb4194 (diff) | |
download | NotEnoughUpdates-2b8c960c1a6a8fa6fca2d4e2ee7ec0f20492cb9e.tar.gz NotEnoughUpdates-2b8c960c1a6a8fa6fca2d4e2ee7ec0f20492cb9e.tar.bz2 NotEnoughUpdates-2b8c960c1a6a8fa6fca2d4e2ee7ec0f20492cb9e.zip |
support for old or broken repo data
Diffstat (limited to 'src/main/java/io')
6 files changed, 134 insertions, 89 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index faed1984..307d0e7b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -55,7 +55,8 @@ public class DevTestCommand extends ClientCommandBase { "dediamondpro", "lulonaut", "craftyoldminer", - "eisengolem" + "eisengolem", + "hannibal2" ); private static final String[] DEV_FAIL_STRINGS = { @@ -150,7 +151,8 @@ public class DevTestCommand extends ClientCommandBase { return; } if (args.length == 1 && args[0].equalsIgnoreCase("dev")) { - NotEnoughUpdates.INSTANCE.config.hidden.dev = true; + NotEnoughUpdates.INSTANCE.config.hidden.dev = !NotEnoughUpdates.INSTANCE.config.hidden.dev; + Utils.addChatMessage("§e[NEU] Dev mode " + (NotEnoughUpdates.INSTANCE.config.hidden.dev ? "§aenabled": "§cdisabled")); return; } if (args.length == 1 && args[0].equalsIgnoreCase("saveconfig")) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java index 9cd1a08b..e4307efa 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java @@ -30,9 +30,10 @@ public class Minion { private final int tier; private String displayName; private MinionSource minionSource; - private boolean crafted = false; private Minion parent; private final List<MinionRequirement> requirements = new ArrayList<>(); + + private boolean crafted = false; private boolean meetRequirements = false; public Minion(String internalName, int tier) { 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 193b0675..788315c4 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 @@ -177,9 +177,15 @@ public class MinionHelperOverlay { lastHovered = minion; String displayName = minion.getDisplayName(); lines.add(displayName + " " + minion.getTier()); - for (MinionRequirement requirement : manager.getRequirements(minionSource.getMinion())) { - String color = manager.meetRequirement(minion, requirement) ? "§a" : "§c"; - lines.add(" " + color + "Requirement: §f" + requirement.printDescription()); + List<MinionRequirement> requirements = manager.getRequirements(minionSource.getMinion()); + if (!requirements.isEmpty()) { + for (MinionRequirement requirement : requirements) { + String color = manager.meetRequirement(minion, requirement) ? "§a" : "§c"; + lines.add(" " + color + "Requirement: §f" + requirement.printDescription()); + } + } else { + lines.add("§cCould not find any requirements!"); + lines.add("§cThis is "); } if (minionSource instanceof CraftingSource) { @@ -320,6 +326,12 @@ public class MinionHelperOverlay { Map<Minion, Long> sort = TrophyRewardOverlay.sortByValue(prices); for (Minion minion : sort.keySet()) { String displayName = minion.getDisplayName(); + if (displayName == null) { + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { + Utils.addChatMessage("§cDisplayname is null for " + minion.getInternalName()); + } + continue; + } displayName = displayName.replace(" Minion", ""); String format = manager.calculateUpgradeCostsFormat(minion.getMinionSource(), true); String requirementFormat = !minion.doesMeetRequirements() ? "§7§o" : ""; 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 4d73577a..40ec04b6 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 @@ -61,6 +61,7 @@ public class MinionHelperApiLoader { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { + if (Minecraft.getMinecraft().thePlayer == null) return; if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; ticks++; @@ -108,79 +109,71 @@ public class MinionHelperApiLoader { } private void readData(JsonObject player) { - try { - Map<String, Integer> highestCollectionTier = new HashMap<>(); - Map<String, Integer> slayerTier = new HashMap<>(); - int magesReputation = 0; - int barbariansReputation = 0; - - if (player.has("unlocked_coll_tiers")) { - for (JsonElement element : player.get("unlocked_coll_tiers").getAsJsonArray()) { - String text = element.getAsString(); - String[] split = text.split("_"); - int level = Integer.parseInt(split[split.length - 1]); - String name = StringUtils.removeLastWord(text, "_"); - - //Because skyblock is good in naming things - LinkedHashMap<String, ItemStack> collectionMap = ProfileViewer.getCollectionToCollectionDisplayMap(); - if (collectionMap.containsKey(name)) { - ItemStack itemStack = collectionMap.get(name); - String displayName = itemStack.getDisplayName(); - name = Utils.cleanColour(displayName); - name = manager.formatInternalName(name); - } else { - //Doing this since there is no space in the profile viewer gui for more entries in collectionToCollectionDisplayMap - if (name.equals("SAND:1")) name = "RED_SAND"; - if (name.equals("MYCEL")) name = "MYCELIUM"; - } - - level = Math.max(highestCollectionTier.getOrDefault(name, 0), level); - highestCollectionTier.put(name, level); + Map<String, Integer> highestCollectionTier = new HashMap<>(); + Map<String, Integer> slayerTier = new HashMap<>(); + int magesReputation = 0; + int barbariansReputation = 0; + + if (player.has("unlocked_coll_tiers")) { + for (JsonElement element : player.get("unlocked_coll_tiers").getAsJsonArray()) { + String text = element.getAsString(); + String[] split = text.split("_"); + int level = Integer.parseInt(split[split.length - 1]); + String name = StringUtils.removeLastWord(text, "_"); + + //Because skyblock is good in naming things + LinkedHashMap<String, ItemStack> collectionMap = ProfileViewer.getCollectionToCollectionDisplayMap(); + if (collectionMap.containsKey(name)) { + ItemStack itemStack = collectionMap.get(name); + String displayName = itemStack.getDisplayName(); + name = Utils.cleanColour(displayName); + name = manager.formatInternalName(name); + } else { + //Doing this since there is no space in the profile viewer gui for more entries in collectionToCollectionDisplayMap + if (name.equals("SAND:1")) name = "RED_SAND"; + if (name.equals("MYCEL")) name = "MYCELIUM"; } + + level = Math.max(highestCollectionTier.getOrDefault(name, 0), level); + highestCollectionTier.put(name, level); } + } - if (player.has("nether_island_player_data")) { - JsonObject netherData = player.getAsJsonObject("nether_island_player_data"); - if (netherData.has("mages_reputation")) { - magesReputation = netherData.get("mages_reputation").getAsInt(); - } - if (netherData.has("barbarians_reputation")) { - barbariansReputation = netherData.get("barbarians_reputation").getAsInt(); - } + if (player.has("nether_island_player_data")) { + JsonObject netherData = player.getAsJsonObject("nether_island_player_data"); + if (netherData.has("mages_reputation")) { + magesReputation = netherData.get("mages_reputation").getAsInt(); } + if (netherData.has("barbarians_reputation")) { + barbariansReputation = netherData.get("barbarians_reputation").getAsInt(); + } + } - JsonObject slayerLeveling = Constants.LEVELING.getAsJsonObject("slayer_xp"); - - if (player.has("slayer_bosses")) { - JsonObject slayerBosses = player.getAsJsonObject("slayer_bosses"); - for (Map.Entry<String, JsonElement> entry : slayerBosses.entrySet()) { - String name = entry.getKey(); - JsonObject slayerEntry = entry.getValue().getAsJsonObject(); - if (slayerEntry.has("xp")) { - long xp = slayerEntry.get("xp").getAsLong(); - - int tier = 0; - for (JsonElement element : slayerLeveling.getAsJsonArray(name)) { - int needForLevel = element.getAsInt(); - if (xp >= needForLevel) { - tier++; - } else { - break; - } + JsonObject slayerLeveling = Constants.LEVELING.getAsJsonObject("slayer_xp"); + + if (player.has("slayer_bosses")) { + JsonObject slayerBosses = player.getAsJsonObject("slayer_bosses"); + for (Map.Entry<String, JsonElement> entry : slayerBosses.entrySet()) { + String name = entry.getKey(); + JsonObject slayerEntry = entry.getValue().getAsJsonObject(); + if (slayerEntry.has("xp")) { + long xp = slayerEntry.get("xp").getAsLong(); + + int tier = 0; + for (JsonElement element : slayerLeveling.getAsJsonArray(name)) { + int needForLevel = element.getAsInt(); + if (xp >= needForLevel) { + tier++; + } else { + break; } - slayerTier.put(name, tier); } + slayerTier.put(name, tier); } } - - manager.setApiData(new ApiData(highestCollectionTier, slayerTier, magesReputation, barbariansReputation)); - - manager.reloadRequirements(); - - } catch (Throwable t) { - t.printStackTrace(); - Utils.addChatMessage("there was a mistake!"); - throw new RuntimeException("lul", t); } + + manager.setApiData(new ApiData(highestCollectionTier, slayerTier, magesReputation, barbariansReputation)); + manager.reloadRequirements(); } } 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 42c52416..1885eb68 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 @@ -36,6 +36,7 @@ import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CustomS import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.NpcSource; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -68,6 +69,7 @@ public class MinionHelperRepoLoader { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { + if (Minecraft.getMinecraft().thePlayer == null) return; if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; ticks++; @@ -79,8 +81,12 @@ public class MinionHelperRepoLoader { } } + boolean error = false; + void load() { //TODO load new from config entries and so? + error = false; + loadMinions(); loadNpcData(); @@ -88,21 +94,25 @@ public class MinionHelperRepoLoader { loadCustomSources(); checkMissingData(); + + if (error) { + Utils.showOutdatedRepoNotification(); + } } private void loadCustomSources() { - Map<String, String> customDescriptions = new HashMap<>(); + Map<String, String> customSource = new HashMap<>(); - customDescriptions.put("SNOW_GENERATOR_1", "Gifts"); + customSource.put("SNOW_GENERATOR_1", "Gifts"); - customDescriptions.put("FLOWER_GENERATOR_1", "Dark Auction"); + customSource.put("FLOWER_GENERATOR_1", "Dark Auction"); - customDescriptions.put("REVENANT_GENERATOR_1", "Revenant Slayer"); - customDescriptions.put("TARANTULA_GENERATOR_1", "Tarantula Slayer"); - customDescriptions.put("VOIDLING_GENERATOR_1", "Voidling Slayer"); - customDescriptions.put("INFERNO_GENERATOR_1", "Inferno Slayer"); + customSource.put("REVENANT_GENERATOR_1", "Zombie Slayer"); + customSource.put("TARANTULA_GENERATOR_1", "Spider Slayer"); + customSource.put("VOIDLING_GENERATOR_1", "Enderman Slayer"); + customSource.put("INFERNO_GENERATOR_1", "Blaze Slayer"); - for (Map.Entry<String, String> entry : customDescriptions.entrySet()) { + for (Map.Entry<String, String> entry : customSource.entrySet()) { String internalName = entry.getKey(); String description = entry.getValue(); Minion minion = manager.getMinionById(internalName); @@ -110,9 +120,10 @@ public class MinionHelperRepoLoader { minion.setMinionSource(new CustomSource(minion, description)); } - - manager.getMinionById("FLOWER_GENERATOR_1").getRequirements().add(new CustomRequirement("Buy Flower Minion 1 from Dark Auction")); - manager.getMinionById("SNOW_GENERATOR_1").getRequirements().add(new CustomRequirement("Gain Snow Minion 1 from opening gifts")); + manager.getMinionById("FLOWER_GENERATOR_1").getRequirements().add(new CustomRequirement( + "Buy Flower Minion 1 from Dark Auction")); + manager.getMinionById("SNOW_GENERATOR_1").getRequirements().add(new CustomRequirement( + "Gain Snow Minion 1 from opening gifts")); } @@ -165,13 +176,28 @@ public class MinionHelperRepoLoader { private void checkMissingData() { for (Minion minion : manager.getAllMinions().values()) { if (minion.getMinionSource() == null) { - Utils.addChatMessage("§7The Minion '" + minion.getInternalName() + " has no source!"); + error = true; + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { + Utils.addChatMessage("§c[NEU] The Minion '" + minion.getInternalName() + " has no source!"); + } } if (minion.getDisplayName() == null) { - Utils.addChatMessage("§cThe Minion '" + minion.getInternalName() + " has no display name!"); + error = true; + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { + Utils.addChatMessage("§c[NEU] The Minion '" + minion.getInternalName() + " has no display name!"); + } } if (manager.getRequirements(minion).isEmpty()) { - Utils.addChatMessage("§cThe Minion '" + minion.getInternalName() + " has no requirements!"); + error = true; + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { + Utils.addChatMessage("§c[NEU] The Minion '" + minion.getInternalName() + " has no requirements!"); + } + } + if (minion.getTier() > 1 && minion.getParent() == null) { + error = true; + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { + Utils.addChatMessage("§c[NEU] The Minion '" + minion.getInternalName() + " has parent!"); + } } } } @@ -235,9 +261,12 @@ public class MinionHelperRepoLoader { } } } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { - Utils.addChatMessage( - "§4Error §cwhile loading repo entry " + minion.getDisplayName() + " " + minion.getTier() + ": " + - e.getClass().getSimpleName() + ": " + e.getMessage()); + error = true; + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) { + Utils.addChatMessage( + "§c[NEU] Error in MinionHelperRepoLoader while loading repo entry " + minion.getDisplayName() + " " + minion.getTier() + ": " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } e.printStackTrace(); } } @@ -287,7 +316,10 @@ public class MinionHelperRepoLoader { boolean isParent = false; if (itemName.contains("_GENERATOR_")) { String minionInternalName = minion.getInternalName(); - boolean same = StringUtils.removeLastWord(itemName, "_").equals(StringUtils.removeLastWord(minionInternalName, "_")); + boolean same = StringUtils.removeLastWord(itemName, "_").equals(StringUtils.removeLastWord( + minionInternalName, + "_" + )); if (same) { parent = manager.getMinionById(itemName); if (parent == null) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 50782575..756c8d4c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -1977,6 +1977,11 @@ public class Utils { } public static void addChatMessage(String message) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message)); + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + if (thePlayer != null) { + thePlayer.addChatMessage(new ChatComponentText(message)); + } else { + System.out.println(message); + } } } |