diff options
Diffstat (limited to 'src/main/java/kr')
7 files changed, 107 insertions, 17 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java index 2d25168f..bcbcbe0a 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java @@ -1,9 +1,6 @@ package kr.syeyoung.dungeonsguide; -import kr.syeyoung.dungeonsguide.commands.CommandEditRoom; -import kr.syeyoung.dungeonsguide.commands.CommandLoadData; -import kr.syeyoung.dungeonsguide.commands.CommandSaveData; -import kr.syeyoung.dungeonsguide.commands.CommandToggleDebug; +import kr.syeyoung.dungeonsguide.commands.*; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; import lombok.Getter; import net.minecraft.client.Minecraft; @@ -49,6 +46,7 @@ public class DungeonsGuide ClientCommandHandler.instance.registerCommand(new CommandLoadData()); ClientCommandHandler.instance.registerCommand(new CommandSaveData()); ClientCommandHandler.instance.registerCommand(new CommandToggleDebug()); + ClientCommandHandler.instance.registerCommand(new CommandWhatYearIsIt()); if (!configDir.exists()) { //noinspection ResultOfMethodCallIgnored diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandWhatYearIsIt.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandWhatYearIsIt.java new file mode 100644 index 00000000..d5da1c7f --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandWhatYearIsIt.java @@ -0,0 +1,40 @@ +package kr.syeyoung.dungeonsguide.commands; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import kr.syeyoung.dungeonsguide.utils.SkyblockUtils; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; + +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class CommandWhatYearIsIt extends CommandBase { + @Override + public String getCommandName() { + return "tellmeyear"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "tellmeyear"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + try { + + + + sender.addChatMessage(new ChatComponentText("Current year is "+ SkyblockUtils.getSkyblockYear())); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } + @Override + public int getRequiredPermissionLevel() { + return 0; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorCreeperSolver.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorCreeperSolver.java index 93f5e4e8..91b40112 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorCreeperSolver.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorCreeperSolver.java @@ -95,24 +95,21 @@ public class RoomProcessorCreeperSolver extends GeneralRoomProcessor { } - + private static final Color[] colors = new Color[] {Color.red, Color.orange, Color.green, Color.cyan, Color.blue, Color.pink, Color.yellow, Color.darkGray, Color.lightGray}; @Override public void drawWorld(float partialTicks) { super.drawWorld(partialTicks); World w = getDungeonRoom().getContext().getWorld(); - int index = 0; - for (BlockPos[] poset:poses) { - index ++; + for (int i = 0; i < poses.size(); i++) { + BlockPos[] poset = poses.get(i); + Color color = colors[i % colors.length]; + boolean oneIsConnected = false; if (w.getChunkFromBlockCoords(poset[0]).getBlock(poset[0]) != Blocks.sea_lantern && w.getChunkFromBlockCoords(poset[1]).getBlock(poset[1]) != Blocks.sea_lantern) { - continue; + oneIsConnected = true; } RenderUtils.drawLine(new Vec3(poset[0].getX() +0.5, poset[0].getY() +0.5, poset[0].getZ()+0.5), - new Vec3(poset[1].getX() +0.5, poset[1].getY() +0.5, poset[1].getZ()+0.5), new Color(index * 10,255,255,255), partialTicks, true); -//Re -// RenderUtils.highlightBlock(poset[0], new Color(0,255,255,50), partialTicks); -// RenderUtils.highlightBlock(poset[1], new Color(255,0,0,50), partialTicks); - // RenderUtils.drawLines(Arrays.asList(new BlockPos[] {poset[0], poset[1], poset[0]}), new Color(0,255,255,255), partialTicks); + new Vec3(poset[1].getX() +0.5, poset[1].getY() +0.5, poset[1].getZ()+0.5), oneIsConnected ? new Color(0,0,0,50) : color, partialTicks, true); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorTrivia.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorTrivia.java index 7e9d450d..05d236e1 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorTrivia.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorTrivia.java @@ -3,6 +3,7 @@ package kr.syeyoung.dungeonsguide.roomprocessor; import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import kr.syeyoung.dungeonsguide.utils.SkyblockUtils; import kr.syeyoung.dungeonsguide.utils.TextUtils; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; @@ -10,6 +11,7 @@ import net.minecraft.util.IChatComponent; import org.apache.commons.lang3.math.NumberUtils; import java.awt.*; +import java.io.IOException; import java.util.*; import java.util.List; import java.util.regex.Matcher; @@ -104,6 +106,7 @@ public class RoomProcessorTrivia extends GeneralRoomProcessor { } String correctAnswer; + private String getAnswer(String answerString) { Matcher matcher = anwerPattern.matcher(answerString.trim()); if (!matcher.matches()) return ""; @@ -112,12 +115,26 @@ public class RoomProcessorTrivia extends GeneralRoomProcessor { private String match(String question, String a, String b, String c) { String semi_answers = (String) getDungeonRoom().getDungeonRoomInfo().getProperties().get(question.toLowerCase().trim()); if (semi_answers == null) return null; + semi_answers = takeCareOfPlaceHolders(semi_answers); String[] answers = semi_answers.split(","); if (match(answers, a)) return "A"; if (match(answers, b)) return "B"; if (match(answers, c)) return "C"; return semi_answers; } + + private String takeCareOfPlaceHolders(String input) { + String str = input; + if (str.contains("$year")) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §fuses §eInventiveTalent§7(https://github.com/InventivetalentDev)§e's Skyblock Api §fto fetch current skyblock year!")); + try { + str = str.replace("$year", SkyblockUtils.getSkyblockYear()+""); + } catch (IOException e) { + str = str.replace("$year", "Couldn't determine current skyblock year :: "+e.getMessage()); + } + } + return str; + } private boolean match(String[] match, String match2) { for (String s : match) { if (NumberUtils.isNumber(s)) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/BoxPuzzleSolvingThread.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/BoxPuzzleSolvingThread.java index f4412419..8c63694b 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/BoxPuzzleSolvingThread.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/BoxPuzzleSolvingThread.java @@ -23,6 +23,7 @@ public class BoxPuzzleSolvingThread extends Thread { this.playerX = playerX; this.playerY = playerY; this.callback = onDone; + System.out.println("new solving thread"); } Route solution = null; @@ -33,8 +34,8 @@ public class BoxPuzzleSolvingThread extends Thread { public void run() { solved = false; solution = solve(data,playerX,playerY, 20); - callback.run(); solved = true; + callback.run(); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/RoomProcessorBoxSolver.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/RoomProcessorBoxSolver.java index 3b88de2d..e907671a 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/RoomProcessorBoxSolver.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/boxpuzzle/RoomProcessorBoxSolver.java @@ -25,7 +25,7 @@ import java.util.List; public class RoomProcessorBoxSolver extends GeneralRoomProcessor { - private BlockPos[][] poses = new BlockPos[6][7]; + private BlockPos[][] poses = new BlockPos[7][7]; private boolean bugged= true; private BoxPuzzleSolvingThread puzzleSolvingThread; @@ -92,7 +92,6 @@ public class RoomProcessorBoxSolver extends GeneralRoomProcessor { puzzleSolvingThread.start(); } if (calcReq) { - OffsetPointSet ops = (OffsetPointSet) getDungeonRoom().getDungeonRoomInfo().getProperties().get("board"); if (ops != null) { poses = new BlockPos[7][7]; @@ -105,6 +104,8 @@ public class RoomProcessorBoxSolver extends GeneralRoomProcessor { } calcDone = false; + if (puzzleSolvingThread != null) + puzzleSolvingThread.stop(); puzzleSolvingThread = new BoxPuzzleSolvingThread(currboard, 0, 6, new Runnable() { @Override public void run() { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/SkyblockUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/SkyblockUtils.java new file mode 100644 index 00000000..c8b87260 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/SkyblockUtils.java @@ -0,0 +1,36 @@ +package kr.syeyoung.dungeonsguide.utils; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import net.minecraft.util.ChatComponentText; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + +public class SkyblockUtils { + public static long getSkyblockYear() throws IOException { + URL url = new URL("https://hypixel-api.inventivetalent.org/api/skyblock/calendar"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("User-Agent", "DungeonsGuide/1.0"); + InputStreamReader inputStreamReader = new InputStreamReader(connection.getInputStream()); + JsonObject object = (JsonObject) new JsonParser().parse(inputStreamReader); + if (!object.get("success").getAsBoolean()) { + return -1; + } + long now = System.currentTimeMillis() / 1000; + + JsonObject real = object.getAsJsonObject("real"); + long secondsPerYear = real.get("SECONDS_PER_MONTH").getAsLong() * 12; + JsonObject lastLog = object.getAsJsonObject("lastLog"); + long lastTime = lastLog.get("time").getAsLong(); + long year = lastLog.get("year").getAsLong(); + + long passedTime = now - lastTime; + year += passedTime / secondsPerYear; + return year; + } +} |