diff options
author | bowser0000 <bowser0000@gmail.com> | 2021-04-29 21:44:00 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2021-04-29 21:44:00 -0400 |
commit | 4e6be104aaa579abc06fff0613eb2dec991a7487 (patch) | |
tree | 585bae8d8c76947c5a77ef4c856c17391784f2ec /src/main/java/me/Danker/features | |
parent | 1d0cfd9f652990c396d6c58be61797c792fba8a2 (diff) | |
download | SkyblockMod-4e6be104aaa579abc06fff0613eb2dec991a7487.tar.gz SkyblockMod-4e6be104aaa579abc06fff0613eb2dec991a7487.tar.bz2 SkyblockMod-4e6be104aaa579abc06fff0613eb2dec991a7487.zip |
Auto update trivia and three man solutions
Diffstat (limited to 'src/main/java/me/Danker/features')
-rw-r--r-- | src/main/java/me/Danker/features/puzzlesolvers/ThreeManSolver.java | 71 | ||||
-rw-r--r-- | src/main/java/me/Danker/features/puzzlesolvers/TriviaSolver.java | 99 |
2 files changed, 119 insertions, 51 deletions
diff --git a/src/main/java/me/Danker/features/puzzlesolvers/ThreeManSolver.java b/src/main/java/me/Danker/features/puzzlesolvers/ThreeManSolver.java index 8f7de95..500c8eb 100644 --- a/src/main/java/me/Danker/features/puzzlesolvers/ThreeManSolver.java +++ b/src/main/java/me/Danker/features/puzzlesolvers/ThreeManSolver.java @@ -1,5 +1,6 @@ package me.Danker.features.puzzlesolvers; +import com.google.gson.JsonArray; import me.Danker.DankersSkyblockMod; import me.Danker.commands.ToggleCommand; import me.Danker.utils.Utils; @@ -16,6 +17,7 @@ import java.util.List; public class ThreeManSolver { + // Hard coded solutions if api call fails static String[] riddleSolutions = {"The reward is not in my chest!", "At least one of them is lying, and the reward is not in", "My chest doesn't have the reward. We are all telling the truth", "My chest has the reward and I'm telling the truth", "The reward isn't in any of our chests", "Both of them are telling the truth."}; @@ -33,33 +35,22 @@ public class ThreeManSolver { if (!Utils.inDungeons) return; if (ToggleCommand.threeManToggled && message.contains("[NPC]")) { - for (String solution : riddleSolutions) { - if (message.contains(solution)) { - Minecraft mc = Minecraft.getMinecraft(); - String npcName = message.substring(message.indexOf("]") + 2, message.indexOf(":")); - mc.thePlayer.addChatMessage(new ChatComponentText(DankersSkyblockMod.ANSWER_COLOUR + EnumChatFormatting.BOLD + StringUtils.stripControlCodes(npcName) + DankersSkyblockMod.MAIN_COLOUR + " has the blessing.")); - if (riddleChest == null) { - List<Entity> entities = mc.theWorld.getLoadedEntityList(); - for (Entity entity : entities) { - if (entity == null || !entity.hasCustomName()) continue; - if (entity.getCustomNameTag().contains(npcName)) { - BlockPos npcLocation = new BlockPos(entity.posX, 69, entity.posZ); - if (mc.theWorld.getBlockState(npcLocation.north()).getBlock() == Blocks.chest) { - riddleChest = npcLocation.north(); - } else if (mc.theWorld.getBlockState(npcLocation.east()).getBlock() == Blocks.chest) { - riddleChest = npcLocation.east(); - } else if (mc.theWorld.getBlockState(npcLocation.south()).getBlock() == Blocks.chest) { - riddleChest = npcLocation.south(); - } else if (mc.theWorld.getBlockState(npcLocation.west()).getBlock() == Blocks.chest) { - riddleChest = npcLocation.west(); - } else { - System.out.print("Could not find correct riddle chest."); - } - break; - } - } + if (DankersSkyblockMod.data != null && DankersSkyblockMod.data.has("threeman")) { + JsonArray riddleSolutions = DankersSkyblockMod.data.get("threeman").getAsJsonArray(); + + for (int i = 0; i < riddleSolutions.size(); i++) { + String solution = riddleSolutions.get(i).getAsString(); + if (message.contains(solution)) { + answer(message); + break; + } + } + } else { + for (String solution : riddleSolutions) { + if (message.contains(solution)) { + answer(message); + break; } - break; } } } @@ -72,4 +63,32 @@ public class ThreeManSolver { } } + public static void answer(String message) { + Minecraft mc = Minecraft.getMinecraft(); + String npcName = message.substring(message.indexOf("]") + 2, message.indexOf(":")); + mc.thePlayer.addChatMessage(new ChatComponentText(DankersSkyblockMod.ANSWER_COLOUR + EnumChatFormatting.BOLD + StringUtils.stripControlCodes(npcName) + DankersSkyblockMod.MAIN_COLOUR + " has the blessing.")); + + if (riddleChest == null) { + List<Entity> entities = mc.theWorld.getLoadedEntityList(); + for (Entity entity : entities) { + if (entity == null || !entity.hasCustomName()) continue; + if (entity.getCustomNameTag().contains(npcName)) { + BlockPos npcLocation = new BlockPos(entity.posX, 69, entity.posZ); + if (mc.theWorld.getBlockState(npcLocation.north()).getBlock() == Blocks.chest) { + riddleChest = npcLocation.north(); + } else if (mc.theWorld.getBlockState(npcLocation.east()).getBlock() == Blocks.chest) { + riddleChest = npcLocation.east(); + } else if (mc.theWorld.getBlockState(npcLocation.south()).getBlock() == Blocks.chest) { + riddleChest = npcLocation.south(); + } else if (mc.theWorld.getBlockState(npcLocation.west()).getBlock() == Blocks.chest) { + riddleChest = npcLocation.west(); + } else { + System.out.print("Could not find correct riddle chest."); + } + break; + } + } + } + } + } diff --git a/src/main/java/me/Danker/features/puzzlesolvers/TriviaSolver.java b/src/main/java/me/Danker/features/puzzlesolvers/TriviaSolver.java index 9adc555..dd2c23e 100644 --- a/src/main/java/me/Danker/features/puzzlesolvers/TriviaSolver.java +++ b/src/main/java/me/Danker/features/puzzlesolvers/TriviaSolver.java @@ -1,5 +1,9 @@ package me.Danker.features.puzzlesolvers; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import me.Danker.DankersSkyblockMod; import me.Danker.commands.ToggleCommand; import me.Danker.utils.Utils; import net.minecraft.util.ChatComponentText; @@ -9,16 +13,21 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class TriviaSolver { static Map<String, String[]> triviaSolutions = new HashMap<>(); static String[] triviaAnswers = null; + static JsonArray triviaAnswersJson = null; public static String TRIVIA_WRONG_ANSWER_COLOUR; public static void init() { + // Hard coded solutions if api call fails triviaSolutions.put("What is the status of The Watcher?", new String[]{"Stalker"}); triviaSolutions.put("What is the status of Bonzo?", new String[]{"New Necromancer"}); triviaSolutions.put("What is the status of Scarf?", new String[]{"Apprentice Necromancer"}); @@ -30,11 +39,10 @@ public class TriviaSolver { triviaSolutions.put("What is the status of Goldor?", new String[]{"Wither Soldier"}); triviaSolutions.put("What is the status of Storm?", new String[]{"Elementalist"}); triviaSolutions.put("What is the status of Necron?", new String[]{"Wither Lord"}); - triviaSolutions.put("How many total Fairy Souls are there?", new String[]{"222 Fairy Souls"}); + triviaSolutions.put("How many total Fairy Souls are there?", new String[]{"227 Fairy Souls"}); triviaSolutions.put("How many Fairy Souls are there in Spider's Den?", new String[]{"19 Fairy Souls"}); triviaSolutions.put("How many Fairy Souls are there in The End?", new String[]{"12 Fairy Souls"}); - triviaSolutions.put("How many Fairy Souls are there in The Barn?", new String[]{"7 Fairy Souls"}); - triviaSolutions.put("How many Fairy Souls are there in Mushroom Desert?", new String[]{"8 Fairy Souls"}); + triviaSolutions.put("How many Fairy Souls are there in The Farming Islands?", new String[]{"20 Fairy Souls"}); triviaSolutions.put("How many Fairy Souls are there in Blazing Fortress?", new String[]{"19 Fairy Souls"}); triviaSolutions.put("How many Fairy Souls are there in The Park?", new String[]{"11 Fairy Souls"}); triviaSolutions.put("How many Fairy Souls are there in Jerry's Workshop?", new String[]{"5 Fairy Souls"}); @@ -65,35 +73,76 @@ public class TriviaSolver { if (event.type == 2) return; if (ToggleCommand.oruoToggled) { - if (message.contains("What SkyBlock year is it?")) { - double currentTime = System.currentTimeMillis() /1000L; + if (DankersSkyblockMod.data != null && DankersSkyblockMod.data.has("trivia")) { + if (message.contains("What SkyBlock year is it?")) { + double currentTime = System.currentTimeMillis() / 1000L; - double diff = Math.floor(currentTime - 1560276000); + double diff = Math.floor(currentTime - 1560276000); - int year = (int) (diff / 446400 + 1); - triviaAnswers = new String[]{"Year " + year}; - } else { - for (String question : triviaSolutions.keySet()) { - if (message.contains(question)) { - triviaAnswers = triviaSolutions.get(question); - break; + int year = (int) (diff / 446400 + 1); + triviaAnswersJson = new JsonArray(); + triviaAnswersJson.add(new JsonPrimitive("Year " + year)); + } else { + JsonObject triviaSolutions = DankersSkyblockMod.data.get("trivia").getAsJsonObject(); + + List<String> triviaSolutionsList = triviaSolutions.entrySet().stream() + .map(Map.Entry::getKey) + .collect(Collectors.toCollection(ArrayList::new)); + for (String question : triviaSolutionsList) { + if (message.contains(question)) { + triviaAnswersJson = triviaSolutions.get(question).getAsJsonArray(); + break; + } } } - } - // Set wrong answers to red and remove click events - if (triviaAnswers != null && (message.contains("ⓐ") || message.contains("ⓑ") || message.contains("ⓒ"))) { - boolean isSolution = false; - for (String solution : triviaAnswers) { - if (message.contains(solution)) { - isSolution = true; - break; + // Set wrong answers to red and remove click events + if (triviaAnswersJson != null && (message.contains("ⓐ") || message.contains("ⓑ") || message.contains("ⓒ"))) { + boolean isSolution = false; + for (int i = 0; i < triviaAnswersJson.size(); i++) { + String solution = triviaAnswersJson.get(i).getAsString(); + if (message.contains(solution)) { + isSolution = true; + break; + } + } + if (!isSolution) { + char letter = message.charAt(5); + String option = message.substring(6); + event.message = new ChatComponentText(" " + EnumChatFormatting.GOLD + letter + TRIVIA_WRONG_ANSWER_COLOUR + option); + } + } + } else { + if (message.contains("What SkyBlock year is it?")) { + double currentTime = System.currentTimeMillis() / 1000L; + + double diff = Math.floor(currentTime - 1560276000); + + int year = (int) (diff / 446400 + 1); + triviaAnswers = new String[]{"Year " + year}; + } else { + for (String question : triviaSolutions.keySet()) { + if (message.contains(question)) { + triviaAnswers = triviaSolutions.get(question); + break; + } } } - if (!isSolution) { - char letter = message.charAt(5); - String option = message.substring(6); - event.message = new ChatComponentText(" " + EnumChatFormatting.GOLD + letter + TRIVIA_WRONG_ANSWER_COLOUR + option); + + // Set wrong answers to red and remove click events + if (triviaAnswers != null && (message.contains("ⓐ") || message.contains("ⓑ") || message.contains("ⓒ"))) { + boolean isSolution = false; + for (String solution : triviaAnswers) { + if (message.contains(solution)) { + isSolution = true; + break; + } + } + if (!isSolution) { + char letter = message.charAt(5); + String option = message.substring(6); + event.message = new ChatComponentText(" " + EnumChatFormatting.GOLD + letter + TRIVIA_WRONG_ANSWER_COLOUR + option); + } } } } |