diff options
Diffstat (limited to 'mod/src/main/java/kr/syeyoung')
-rw-r--r-- | mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java | 841 | ||||
-rwxr-xr-x | mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoomInfoRegistry.java | 19 |
2 files changed, 517 insertions, 343 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java index 9b0c8af7..c49b6264 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java @@ -51,6 +51,7 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraft.util.Tuple; import net.minecraftforge.common.MinecraftForge; @@ -78,396 +79,554 @@ public class CommandDgDebug extends CommandBase { return "dgdebug"; } + //List of subcommands for tab support + private static final String[] SUBCOMMANDS = { + "scoreboard", + "scoreboardclean", + "tablist", + "mockdungeonstart", + "saverooms", + "loadrooms", + "reloadah", + "brand", + "pathfind", + "process", + "check", + "reloaddungeon", + "partyid", + "loc", + "saverun", + "requeststaticresource", + "createfakeroom", + "closecontext", + "dumpsettings", + "readmap", + "testgui", + "clearprofile" + }; + + @Override + public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { + if (args.length == 1) { + return CommandBase.getListOfStringsMatchingLastWord(args, SUBCOMMANDS); + } + return Collections.emptyList(); + } + @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length == 0) return; - String arg = args[0].toLowerCase(); + if (args.length == 0) { + return; + } + switch (args[0].toLowerCase()) { //Case Insensitive + case "scoreboard": + scoreboardCommand(); + break; + case "scoreboardclean": + scoreboardCleanCommand(); + break; + case "tablist": + tabListCommand(); + break; + case "mockdungeonstart": + mockDungeonStartCommand(args); + break; + case "saverooms": + saveRoomsCommand(); + break; + case "loadrooms": + loadRoomsCommand(); + break; + case "reloadah": + reloadAHCommand(); + break; + case "brand": + brandCommand(); + break; + case "pathfind": + pathfindCommand(args); + break; + case "process": + processCommand1(); + break; + case "check": + checkCommand(); + break; + case "reloaddungeon": + reloadDungeonCommand(); + break; + case "partyid": + partyIdCommand(); + break; + case "loc": + locCommand(); + break; + case "saverun": + saveRunCommand(); + break; + case "requeststaticresource": + requestStaticResource(args); + break; + case "createfakeroom": // load schematic + createFakeRoomCommand(); + break; + case "closecontext": + closeContextCommand(); + break; + case "dumpsettings": + dumpSettingsCommand(); + break; + case "readmap": + readMapCommand(args); + break; + case "testgui": + testGuiCommand(); + break; + case "clearprofile": + clearProfileCommand(); + break; + default: + ChatTransmitter.addToQueue(new ChatComponentText("ain't gonna find much anything here")); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §e/dg loadrooms §7-§f Reloads dungeon roomdata.")); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §e/dg brand §7-§f View server brand.")); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §e/dg info §7-§f View Current DG User info.")); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §e/dg saverun §7-§f Save run to be sent to developer.")); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §e/dg saverooms §7-§f Saves usergenerated dungeon roomdata.")); + break; + } + } - if ("scoreboard".equals(arg)) { - for (Score score : ScoreboardManager.INSTANCE.getSidebarObjective().getScores()) { - ChatTransmitter.addToQueue("LINE: " + score.getVisibleName()+": "+score.getScore()); - } - } else if ("scoreboardclean".equals(arg)) { - for (Score score : ScoreboardManager.INSTANCE.getSidebarObjective().getScores()) { - ChatTransmitter.addToQueue("LINE: " + score.getJustTeam()+": "+score.getScore()); - } - }else if ("tablist".equals(arg)) { - for (TabListEntry entry : TabList.INSTANCE.getTabListEntries()) { - ChatTransmitter.addToQueue(entry.getFormatted()+" "+entry.getEffectiveName()+"("+entry.getPing()+")" + entry.getGameMode()); - } - ChatTransmitter.addToQueue("VS"); - } else if ("mockdungeonstart".equals(arg)) { - if (!Minecraft.getMinecraft().isSingleplayer()) { - ChatTransmitter.addToQueue("This only works in singlepayer", false); - return; + @Override + public int getRequiredPermissionLevel() { + return 0; + } + + //BEGIN COMMANDS FROM ARGS[0] + + private void scoreboardCommand() { + for (Score score : ScoreboardManager.INSTANCE.getSidebarObjective().getScores()) { + ChatTransmitter.addToQueue("LINE: " + score.getVisibleName() + ": " + score.getScore()); + } + } + + private void scoreboardCleanCommand() { + for (Score score : ScoreboardManager.INSTANCE.getSidebarObjective().getScores()) { + ChatTransmitter.addToQueue("LINE: " + score.getJustTeam() + ": " + score.getScore()); + } + } + + private void tabListCommand() { + for (TabListEntry entry : TabList.INSTANCE.getTabListEntries()) { + ChatTransmitter.addToQueue(entry.getFormatted() + " " + entry.getEffectiveName() + "(" + entry.getPing() + ")" + entry.getGamemode()); + } + ChatTransmitter.addToQueue("VS"); + } + + private void mockDungeonStartCommand(String[] args) { + if (!Minecraft.getMinecraft().isSingleplayer()) { + ChatTransmitter.addToQueue("This only works in singlepauer", false); + return; + } + + if (args.length == 2) { + int time = Integer.parseInt(args[1]); + ChatTransmitter.addToQueue("§r§aDungeon starts in " + time + " seconds.§r", false); + return; + } + + + (new Thread(DungeonsGuide.THREAD_GROUP, () -> { + try { + ChatTransmitter.addToQueue("§r§aDungeon starts in 15 seconds.§r", false); + Thread.sleep(6000); + ChatTransmitter.addToQueue("§r§aDungeon starts in 10 seconds.§r", false); + Thread.sleep(700); + ChatTransmitter.addToQueue("§r§aDungeon starts in 5 seconds.§r", false); + Thread.sleep(1000); + ChatTransmitter.addToQueue("§r§aDungeon starts in 4 seconds.§r", false); + Thread.sleep(1000); + ChatTransmitter.addToQueue("§r§aDungeon starts in 3 seconds.§r", false); + Thread.sleep(1000); + ChatTransmitter.addToQueue("§r§aDungeon starts in 2 seconds.§r", false); + Thread.sleep(1000); + ChatTransmitter.addToQueue("§r§aDungeon starts in 1 seconds.§r", false); + } catch (InterruptedException ignored) { } + })).start(); + } + + private void saveRoomsCommand() { + DungeonRoomInfoRegistry.saveAll(Main.getConfigDir()); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully saved user generated roomdata")); + } + + private void loadRoomsCommand() { + try { + DungeonRoomInfoRegistry.loadAll(Main.getConfigDir()); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully loaded roomdatas")); + return; + } catch (BadPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | + NoSuchAlgorithmException | IOException | IllegalBlockSizeException | + NoSuchPaddingException e) { + e.printStackTrace(); + } + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §cAn error has occurred while loading roomdata")); + } + + private void reloadAHCommand() { + try { + AhUtils.loadAuctions(); + } catch (CertificateException | NoSuchAlgorithmException | InvalidKeyException | + InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | + KeyStoreException | IllegalBlockSizeException | KeyManagementException e) { + e.printStackTrace(); + } + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §fReloaded Ah data")); + } + + private void brandCommand() { + String serverBrand = Minecraft.getMinecraft().thePlayer.getClientBrand(); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §e" + serverBrand)); + } - if (args.length == 2) { - int time = Integer.parseInt(args[1]); - ChatTransmitter.addToQueue("§r§aDungeon starts in " + time + " seconds.§r", false); + private void pathfindCommand(String[] args) { + try { + DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + if (thePlayer == null) { return; } + if (context.getBossfightProcessor() != null) { + context.getBossfightProcessor().tick(); + } + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); + grp.pathfind("COMMAND", args[1], args[2], FeatureRegistry.SECRET_LINE_PROPERTIES_GLOBAL.getRouteProperties()); + } catch (Throwable t) { + t.printStackTrace(); + } + } - (new Thread(DungeonsGuide.THREAD_GROUP, () -> { - try { - ChatTransmitter.addToQueue("§r§aDungeon starts in 15 seconds.§r", false); - Thread.sleep(6000); - ChatTransmitter.addToQueue("§r§aDungeon starts in 10 seconds.§r", false); - Thread.sleep(700); - ChatTransmitter.addToQueue("§r§aDungeon starts in 5 seconds.§r", false); - Thread.sleep(1000); - ChatTransmitter.addToQueue("§r§aDungeon starts in 4 seconds.§r", false); - Thread.sleep(1000); - ChatTransmitter.addToQueue("§r§aDungeon starts in 3 seconds.§r", false); - Thread.sleep(1000); - ChatTransmitter.addToQueue("§r§aDungeon starts in 2 seconds.§r", false); - Thread.sleep(1000); - ChatTransmitter.addToQueue("§r§aDungeon starts in 1 seconds.§r", false); - } catch (InterruptedException ignored) { - } - })).start(); - } else if ("saverooms".equals(arg)) { - DungeonRoomInfoRegistry.saveAll(Main.getConfigDir()); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully saved user generated room data")); - } else if ("loadrooms".equals(arg)) { - try { - DungeonRoomInfoRegistry.loadAll(Main.getConfigDir()); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully loaded room data")); - return; - } catch (BadPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | - NoSuchAlgorithmException | IOException | IllegalBlockSizeException | - NoSuchPaddingException e) { - e.printStackTrace(); + private void processCommand1() { + File fileRoot = Main.getConfigDir(); + File dir = new File(fileRoot, "processorinput"); + File outsecret = new File(fileRoot, "processoroutsecret"); + for (File f : dir.listFiles()) { + if (!f.getName().endsWith(".roomdata")) { + continue; } - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §cAn error has occurred while loading room data")); - } else if ("reloadah".equals(arg)) { try { - AhUtils.loadAuctions(); - } catch (CertificateException | NoSuchAlgorithmException | InvalidKeyException | - InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | - KeyStoreException | IllegalBlockSizeException | KeyManagementException e) { + InputStream fis = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(fis); + DungeonRoomInfo dri = (DungeonRoomInfo) ois.readObject(); + ois.close(); + fis.close(); + dri.setUserMade(false); + + FileOutputStream fos = new FileOutputStream(new File(outsecret, dri.getUuid().toString() + ".roomdata")); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(dri); + oos.flush(); + oos.close(); + } catch (Exception e) { e.printStackTrace(); } - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fReloaded AH data")); - } else if ("brand".equals(arg)) { - String serverBrand = Minecraft.getMinecraft().thePlayer.getClientBrand(); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e" + serverBrand)); + } + } - } else if ("pathfind".equals(arg)) { - try { - DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - if (thePlayer == null) return; - if (context.getBossfightProcessor() != null) context.getBossfightProcessor().tick(); - Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); - - DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); - GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); - grp.pathfind("COMMAND", args[1], args[2], FeatureRegistry.SECRET_LINE_PROPERTIES_GLOBAL.getRouteProperties()); - } catch (Throwable t) { - t.printStackTrace(); + private void checkCommand() { + File fileroot = Main.getConfigDir(); + for (File f : fileroot.listFiles()) { + if (!f.getName().endsWith(".roomdata")) { + continue; } - } else if ("process".equals(arg)) { - File fileRoot = Main.getConfigDir(); - File dir = new File(fileRoot, "processorinput"); - File outsecret = new File(fileRoot, "processoroutsecret"); - for (File f : dir.listFiles()) { - if (!f.getName().endsWith(".roomdata")) continue; - try { - InputStream fis = new FileInputStream(f); - ObjectInputStream ois = new ObjectInputStream(fis); - DungeonRoomInfo dri = (DungeonRoomInfo) ois.readObject(); - ois.close(); - fis.close(); - dri.setUserMade(false); - - FileOutputStream fos = new FileOutputStream(new File(outsecret, dri.getUuid().toString() + ".roomdata")); - ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(dri); - oos.flush(); - oos.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } else if ("check".equals(arg)) { - File fileroot = Main.getConfigDir(); - for (File f : fileroot.listFiles()) { - if (!f.getName().endsWith(".roomdata")) continue; - try { - InputStream fis = new FileInputStream(f); - ObjectInputStream ois = new ObjectInputStream(fis); - DungeonRoomInfo dri = (DungeonRoomInfo) ois.readObject(); - ois.close(); - fis.close(); - System.out.println("Starting at " + dri.getName() + " - " + dri.getUuid()); - for (Map.Entry<String, DungeonMechanic> value2 : dri.getMechanics().entrySet()) { - DungeonMechanic value = value2.getValue(); - if (value instanceof DungeonSecret && - (((DungeonSecret) value).getSecretType() == DungeonSecret.SecretType.BAT - || ((DungeonSecret) value).getSecretType() == DungeonSecret.SecretType.CHEST) - && ((DungeonSecret) value).getSecretPoint().getY() == 0) { - OffsetPoint offsetPoint = ((DungeonSecret) value).getSecretPoint(); - if (dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { + try { + InputStream fis = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(fis); + DungeonRoomInfo dri = (DungeonRoomInfo) ois.readObject(); + ois.close(); + fis.close(); + System.out.println("Starting at " + dri.getName() + " - " + dri.getUuid()); + for (Map.Entry<String, DungeonMechanic> value2 : dri.getMechanics().entrySet()) { + DungeonMechanic value = value2.getValue(); + if (value instanceof DungeonSecret && + (((DungeonSecret) value).getSecretType() == DungeonSecret.SecretType.BAT + || ((DungeonSecret) value).getSecretType() == DungeonSecret.SecretType.CHEST) + && ((DungeonSecret) value).getSecretPoint().getY() == 0) { + OffsetPoint offsetPoint = ((DungeonSecret) value).getSecretPoint(); + if (dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { + dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; + System.out.println("Fixing " + value2.getKey() + " - as secret " + ((DungeonSecret) value).getSecretType() + " - at " + ((DungeonSecret) value).getSecretPoint()); + } + } else if (value instanceof DungeonOnewayDoor) { + for (OffsetPoint offsetPoint : ((DungeonOnewayDoor) value).getSecretPoint().getOffsetPointList()) { + if (offsetPoint.getY() == 0 && dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; - System.out.println("Fixing " + value2.getKey() + " - as secret " + ((DungeonSecret) value).getSecretType() + " - at " + ((DungeonSecret) value).getSecretPoint()); + System.out.println("Fixing " + value2.getKey() + " - o-door - at " + offsetPoint); } - } else if (value instanceof DungeonOnewayDoor) { - for (OffsetPoint offsetPoint : ((DungeonOnewayDoor) value).getSecretPoint().getOffsetPointList()) { - if (offsetPoint.getY() == 0 && dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { - dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; - System.out.println("Fixing " + value2.getKey() + " - o-door - at " + offsetPoint); - } - } - } else if (value instanceof DungeonDoor) { - for (OffsetPoint offsetPoint : ((DungeonDoor) value).getSecretPoint().getOffsetPointList()) { - if (offsetPoint.getY() == 0 && dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { - dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; - System.out.println("Fixing " + value2.getKey() + " - door - at " + offsetPoint); - } + } + } else if (value instanceof DungeonDoor) { + for (OffsetPoint offsetPoint : ((DungeonDoor) value).getSecretPoint().getOffsetPointList()) { + if (offsetPoint.getY() == 0 && dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { + dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; + System.out.println("Fixing " + value2.getKey() + " - door - at " + offsetPoint); } - } else if (value instanceof DungeonBreakableWall) { - for (OffsetPoint offsetPoint : ((DungeonBreakableWall) value).getSecretPoint().getOffsetPointList()) { - if (offsetPoint.getY() == 0 && dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { - dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; - System.out.println("Fixing " + value2.getKey() + " - wall - at " + offsetPoint); - } + } + } else if (value instanceof DungeonBreakableWall) { + for (OffsetPoint offsetPoint : ((DungeonBreakableWall) value).getSecretPoint().getOffsetPointList()) { + if (offsetPoint.getY() == 0 && dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { + dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; + System.out.println("Fixing " + value2.getKey() + " - wall - at " + offsetPoint); } - } else if (value instanceof DungeonTomb) { - for (OffsetPoint offsetPoint : ((DungeonTomb) value).getSecretPoint().getOffsetPointList()) { - if (offsetPoint.getY() == 0 && dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { - dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; - System.out.println("Fixing " + value2.getKey() + " - crypt - at " + offsetPoint); - } + } + } else if (value instanceof DungeonTomb) { + for (OffsetPoint offsetPoint : ((DungeonTomb) value).getSecretPoint().getOffsetPointList()) { + if (offsetPoint.getY() == 0 && dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] != -1) { + dri.getBlocks()[offsetPoint.getZ()][offsetPoint.getX()] = -1; + System.out.println("Fixing " + value2.getKey() + " - crypt - at " + offsetPoint); } } } - FileOutputStream fos = new FileOutputStream(f); - ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(dri); - oos.flush(); - oos.close(); - } catch (Exception e) { - e.printStackTrace(); } + FileOutputStream fos = new FileOutputStream(f); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(dri); + oos.flush(); + oos.close(); + } catch (Exception e) { + e.printStackTrace(); } - } else if ("reloaddungeon".equals(arg)) { - try { - MinecraftForge.EVENT_BUS.post(new DungeonLeftEvent()); + } + } + + private void reloadDungeonCommand() { + try { + MinecraftForge.EVENT_BUS.post(new DungeonLeftEvent()); + + DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(null); + MapUtils.clearMap(); + } catch (Throwable t) { + t.printStackTrace(); + } + } - DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(null); - MapUtils.clearMap(); - } catch (Throwable t) { - t.printStackTrace(); + private void partyIdCommand() { + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §fInternal Party id: " + Optional.ofNullable(PartyManager.INSTANCE.getPartyContext()).map(PartyContext::getPartyID).orElse(null))); + } + + private void locCommand() { + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §fYou're in " + SkyblockStatus.locationName)); + } + + private void saveRunCommand() { + try { + File f = Main.getConfigDir(); + File runDir = new File(f, "dungeonruns"); + runDir.mkdirs(); + + File runFile = new File(runDir, UUID.randomUUID() + ".dgrun"); + + DungeonContext dungeonContext = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); + if (dungeonContext == null) { + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §cCouldn't find dungeon to save!")); + return; } - } else if ("partyid".equals(arg)) { - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fInternal Party id: " + Optional.ofNullable(PartyManager.INSTANCE.getPartyContext()).map(PartyContext::getPartyID).orElse(null))); - } else if ("loc".equals(arg)) { - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fYou're in " + SkyblockStatus.locationName)); - } else if ("saverun".equals(arg)) { - try { - File f = Main.getConfigDir(); - File runDir = new File(f, "dungeonruns"); - runDir.mkdirs(); + DungeonEventHolder dungeonEventHolder = new DungeonEventHolder(); + dungeonEventHolder.setDate(dungeonContext.getInit()); + dungeonEventHolder.setPlayers(dungeonContext.getPlayers()); + dungeonEventHolder.setEventDataList(dungeonContext.getRecorder().getEvents()); - File runFile = new File(runDir, UUID.randomUUID() + ".dgrun"); - DungeonContext dungeonContext = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - if (dungeonContext == null) { - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §cCouldn't find dungeon to save!")); - return; - } - DungeonEventHolder dungeonEventHolder = new DungeonEventHolder(); - dungeonEventHolder.setDate(dungeonContext.getInit()); - dungeonEventHolder.setPlayers(dungeonContext.getPlayers()); - dungeonEventHolder.setEventDataList(dungeonContext.getRecorder().getEvents()); + ObjectOutputStream oos = new ObjectOutputStream(Files.newOutputStream(runFile.toPath())); + oos.writeObject(dungeonEventHolder); + oos.flush(); + oos.close(); + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully saved dungeon run to " + runFile.getAbsolutePath())); + } catch (Exception e) { + ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §cAn error occured while writing rundata " + e.getMessage())); + e.printStackTrace(); + } + } + private void requestStaticResource(String[] args) { + UUID uid = UUID.fromString(args[1]); + StaticResourceCache.INSTANCE.getResource(uid).thenAccept(a -> { + ChatTransmitter.addToQueue(new ChatComponentText(a.getResourceID() + ": " + a.getValue() + ": " + a.isExists())); + }); + } - ObjectOutputStream oos = new ObjectOutputStream(Files.newOutputStream(runFile.toPath())); - oos.writeObject(dungeonEventHolder); - oos.flush(); - oos.close(); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully saved dungeon run to " + runFile.getAbsolutePath())); - } catch (Exception e) { - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §cAn error occurred while writing rundata " + e.getMessage())); + private void createFakeRoomCommand() { +/* File f = new File(Main.getConfigDir(), "schematics/new roonm-b2df250c-4af2-4201-963c-0ee1cb6bd3de-5efb1f0c-c05f-4064-bde7-cad0874fdf39.schematic"); + NBTTagCompound compound; + try { + compound = CompressedStreamTools.readCompressed(new FileInputStream(f)); + } catch (IOException e) { e.printStackTrace(); + return; } - } else if ("requeststaticresource".equals(arg)) { - UUID uid = UUID.fromString(args[1]); - StaticResourceCache.INSTANCE.getResource(uid).thenAccept(a -> { - sender.addChatMessage(new ChatComponentText(a.getResourceID() + ": " + a.getValue() + ": " + a.isExists())); - }); - } else if ("createfakeroom".equals(arg)) {// load schematic -// File f = new File(Main.getConfigDir(), "schematics/new roonm-b2df250c-4af2-4201-963c-0ee1cb6bd3de-5efb1f0c-c05f-4064-bde7-cad0874fdf39.schematic"); -// NBTTagCompound compound; -// try { -// compound = CompressedStreamTools.readCompressed(new FileInputStream(f)); -// } catch (IOException e) { -// e.printStackTrace(); -// return; -// } -// -// byte[] blocks = compound.getByteArray("Blocks"); -// byte[] meta = compound.getByteArray("Data"); -// for (int x = 0; x < compound.getShort("Width"); x++) { -// for (int y = 0; y < compound.getShort("Height"); y++) { -// for (int z = 0; z < compound.getShort("Length"); z++) { -// int index = x + (y * compound.getShort("Length") + z) * compound.getShort("Width"); -// BlockPos pos = new BlockPos(x, y, z); -// World w = MinecraftServer.getServer().getEntityWorld(); -// w.setBlockState(pos, Block.getBlockById(blocks[index] & 0xFF).getStateFromMeta(meta[index] & 0xFF), 2); -// } -// } -// } -// -// -// DungeonSpecificDataProviderRegistry.doorFinders.put(Pattern.compile("TEST DG"), new DungeonSpecificDataProvider() { -// @Override -// public BlockPos findDoor(World w, String dungeonName) { -// return new BlockPos(0, 0, 0); -// } -// -// @Override -// public Vector2d findDoorOffset(World w, String dungeonName) { -// return null; -// } -// -// @Override -// public BossfightProcessor createBossfightProcessor(World w, String dungeonName) { -// return null; -// } -// -// @Override -// public boolean isTrapSpawn(String dungeonName) { -// return false; -// } -// -// @Override -// public double secretPercentage(String dungeonName) { -// return 0; -// } -// -// @Override -// public int speedSecond(String dungeonName) { -// return 0; -// } -// }); -// DungeonContext.setDungeonName("TEST DG"); -// DungeonContext fakeContext = new DungeonContext(Minecraft.getMinecraft().theWorld); -// DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(fakeContext); -// DungeonsGuide.getDungeonsGuide().getSkyblockStatus().setForceIsOnDungeon(true); -// MapPlayerProcessor mapProcessor = fakeContext.getp(); -// mapProcessor.setUnitRoomDimension(new Dimension(16, 16)); -// mapProcessor.setBugged(false); -// mapProcessor.setDoorDimensions(new Dimension(4, 4)); -// mapProcessor.setTopLeftMapPoint(new Point(0, 0)); -// fakeContext.setDungeonMin(new BlockPos(0, 70, 0)); -// -// DungeonRoom dungeonRoom = new DungeonRoom(Arrays.asList(new Point(0, 0)), ShortUtils.topLeftifyInt((short) 1), (byte) 63, new BlockPos(0, 70, 0), new BlockPos(31, 70, 31), fakeContext, Collections.emptySet()); -// -// fakeContext.getDungeonRoomList().add(dungeonRoom); -// for (Point p : Arrays.asList(new Point(0, 0))) { -// fakeContext.getRoomMapper().put(p, dungeonRoom); -// } -// -// EditingContext.createEditingContext(dungeonRoom); -// EditingContext.getEditingContext().openGui(new GuiDungeonRoomEdit(dungeonRoom)); - } else if ("closecontext".equals(arg)) { - DungeonsGuide.getDungeonsGuide().getSkyblockStatus().setForceIsOnDungeon(false); - DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(null); - } else if ("dumpsettings".equals(arg)) { - NestedCategory nestedCategory = new NestedCategory("ROOT"); - for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) { - String category = abstractFeature.getCategory(); - NestedCategory currentRoot = nestedCategory; - for (String s : category.split("\\.")) { - NestedCategory finalCurrentRoot = currentRoot; - if (currentRoot.children().containsKey(s)) - currentRoot = currentRoot.children().get(s); - else { - currentRoot.child(currentRoot = new NestedCategory(finalCurrentRoot.categoryFull() + "." + s)); + byte[] blocks = compound.getByteArray("Blocks"); + byte[] meta = compound.getByteArray("Data"); + for (int x = 0; x < compound.getShort("Width"); x++) { + for (int y = 0; y < compound.getShort("Height"); y++) { + for (int z = 0; z < compound.getShort("Length"); z++) { + int index = x + (y * compound.getShort("Length") + z) * compound.getShort("Width"); + BlockPos pos = new BlockPos(x, y, z); + World w = MinecraftServer.getServer().getEntityWorld(); + w.setBlockState(pos, Block.getBlockById(blocks[index] & 0xFF).getStateFromMeta(meta[index] & 0xFF), 2); } } } - StringBuilder stringBuilder = new StringBuilder(); - StringBuilder stringBuilder2 = new StringBuilder(); - - Stack<Tuple<NestedCategory, Integer>> stak = new Stack<>(); - stak.push(new Tuple<>(nestedCategory, 0)); - Set<NestedCategory> discovered = new HashSet<>(); - while (!stak.isEmpty()) { - Tuple<NestedCategory, Integer> n = stak.pop(); - if (discovered.contains(n.getFirst())) continue; - discovered.add(n.getFirst()); - for (Map.Entry<String, NestedCategory> stringNestedCategoryEntry : n.getFirst().children().entrySet()) { - stak.push(new Tuple<>(stringNestedCategoryEntry.getValue(), n.getSecond() + 1)); + + DungeonSpecificDataProviderRegistry.doorFinders.put(Pattern.compile("TEST DG"), new DungeonSpecificDataProvider() { + @Override + public BlockPos findDoor(World w, String dungeonName) { + return new BlockPos(0, 0, 0); + } + + @Override + public Vector2d findDoorOffset(World w, String dungeonName) { + return null; + } + + @Override + public BossfightProcessor createBossfightProcessor(World w, String dungeonName) { + return null; } - if (n.getFirst().categoryFull().equals("ROOT")) continue; + @Override + public boolean isTrapSpawn(String dungeonName) { + return false; + } - String prefix = ""; - for (int i = 0; i < n.getSecond() - 1; i++) { - prefix += " "; + @Override + public double secretPercentage(String dungeonName) { + return 0; } - List<AbstractFeature> abstractFeatureList = FeatureRegistry.getFeaturesByCategory().getOrDefault(n.getFirst().categoryFull().substring(5), Collections.emptyList()); - stringBuilder.append(prefix).append("- C ").append(n.getFirst().categoryFull()).append("\n"); - stringBuilder2.append(n.getFirst().categoryFull()).append("\n"); - for (AbstractFeature abstractFeature : abstractFeatureList) { - stringBuilder.append(prefix).append(" - F ").append(abstractFeature.getName()).append(" / ").append(abstractFeature.getDescription().replace("\n", "$NEW_LINE$")).append("\n"); + @Override + public int speedSecond(String dungeonName) { + return 0; } + }); + DungeonContext.setDungeonName("TEST DG"); + DungeonContext fakeContext = new DungeonContext(Minecraft.getMinecraft().theWorld); + DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(fakeContext); + DungeonsGuide.getDungeonsGuide().getSkyblockStatus().setForceIsOnDungeon(true); + MapPlayerProcessor mapProcessor = fakeContext.getp(); + mapProcessor.setUnitRoomDimension(new Dimension(16, 16)); + mapProcessor.setBugged(false); + mapProcessor.setDoorDimensions(new Dimension(4, 4)); + mapProcessor.setTopLeftMapPoint(new Point(0, 0)); + fakeContext.setDungeonMin(new BlockPos(0, 70, 0)); + + DungeonRoom dungeonRoom = new DungeonRoom(Arrays.asList(new Point(0, 0)), ShortUtils.topLeftifyInt((short) 1), (byte) 63, new BlockPos(0, 70, 0), new BlockPos(31, 70, 31), fakeContext, Collections.emptySet()); + + fakeContext.getDungeonRoomList().add(dungeonRoom); + for (Point p : Arrays.asList(new Point(0, 0))) { + fakeContext.getRoomMapper().put(p, dungeonRoom); } - System.out.println(stringBuilder.toString()); - System.out.println(stringBuilder2.toString()); - } else if ("readmap".equals(arg)) { - try { - int fromX = Integer.parseInt(args[1]); - int fromY = Integer.parseInt(args[2]); - sender.addChatMessage(new ChatComponentText(MapUtils.readDigit(MapUtils.getColors(), fromX, fromY) + "-")); -// int cntY = Integer.parseInt(args[3]); -// int target = Integer.parseInt(args[4]); -// StringBuilder sb = new StringBuilder("{"); -// for (int y = fromY; y < fromY + cntY; y++) { -// int curr = 0; -// for (int x = fromX; x < fromX+8; x++) { -// byte clr = MapUtils.getMapColorAt(MapUtils.getColors(), x,y); -// if (clr == target) curr = (curr << 1) | 1; -// else curr <<= 1; -// } -// sb.append("0x").append(Integer.toHexString(curr).toUpperCase()); -// if (y != fromY + cntY - 1) sb.append(", "); -// } -// sb.append("}"); -// System.out.println("\n"+sb.toString()); - } catch (Exception e) { - e.printStackTrace(); + + EditingContext.createEditingContext(dungeonRoom); + EditingContext.getEditingContext().openGui(new GuiDungeonRoomEdit(dungeonRoom));*/ + } + + private void closeContextCommand() { + DungeonsGuide.getDungeonsGuide().getSkyblockStatus().setForceIsOnDungeon(false); + + DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(null); + } + + private void dumpSettingsCommand() { + NestedCategory nestedCategory = new NestedCategory("ROOT"); + for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) { + String category = abstractFeature.getCategory(); + NestedCategory currentRoot = nestedCategory; + for (String s : category.split("\\.")) { + NestedCategory finalCurrentRoot = currentRoot; + if (currentRoot.children().containsKey(s)) { + currentRoot = currentRoot.children().get(s); + } else { + currentRoot.child(currentRoot = new NestedCategory(finalCurrentRoot.categoryFull() + "." + s)); + } } - } else if ("testgui".equals(arg)) { - GuiScreenAdapter adapter = new GuiScreenAdapter(new TestView()); - new Thread(DungeonsGuide.THREAD_GROUP, () -> { - Minecraft.getMinecraft().addScheduledTask(() -> { - Minecraft.getMinecraft().displayGuiScreen(adapter); - }); - }).start(); - } else if ("clearprofile".equals(arg)) { - Minecraft.getMinecraft().mcProfiler.clearProfiling(); - } else { - sender.addChatMessage(new ChatComponentText("ain't gonna find much of anything here")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg loadrooms §7-§f Reloads dungeon roomdata.")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg brand §7-§f View server brand.")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg info §7-§f View Current DG User info.")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg saverun §7-§f Save run to be sent to developer.")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg saverooms §7-§f Saves user-generated dungeon roomdata.")); } + + StringBuilder stringBuilder = new StringBuilder(); + StringBuilder stringBuilder2 = new StringBuilder(); + + Stack<Tuple<NestedCategory, Integer>> stak = new Stack<>(); + stak.push(new Tuple<>(nestedCategory, 0)); + Set<NestedCategory> discovered = new HashSet<>(); + while (!stak.isEmpty()) { + Tuple<NestedCategory, Integer> n = stak.pop(); + if (discovered.contains(n.getFirst())) { + continue; + } + discovered.add(n.getFirst()); + for (Map.Entry<String, NestedCategory> stringNestedCategoryEntry : n.getFirst().children().entrySet()) { + stak.push(new Tuple<>(stringNestedCategoryEntry.getValue(), n.getSecond() + 1)); + } + + if (n.getFirst().categoryFull().equals("ROOT")) { + continue; + } + + String prefix = ""; + for (int i = 0; i < n.getSecond() - 1; i++) { + prefix += " "; + } + + List<AbstractFeature> abstractFeatureList = FeatureRegistry.getFeaturesByCategory().getOrDefault(n.getFirst().categoryFull().substring(5), Collections.emptyList()); + stringBuilder.append(prefix).append("- C ").append(n.getFirst().categoryFull()).append("\n"); + stringBuilder2.append(n.getFirst().categoryFull()).append("\n"); + for (AbstractFeature abstractFeature : abstractFeatureList) { + stringBuilder.append(prefix).append(" - F ").append(abstractFeature.getName()).append(" / ").append(abstractFeature.getDescription().replace("\n", "$NEW_LINE$")).append("\n"); + } + } + System.out.println(stringBuilder.toString()); + System.out.println(stringBuilder2.toString()); } + private void readMapCommand(String[] args) { + try { + int fromX = Integer.parseInt(args[1]); + int fromY = Integer.parseInt(args[2]); + ChatTransmitter.addToQueue(new ChatComponentText(MapUtils.readDigit(MapUtils.getColors(), fromX, fromY) + "-")); +/* int cntY = Integer.parseInt(args[3]); + int target = Integer.parseInt(args[4]); + StringBuilder sb = new StringBuilder("{"); + for (int y = fromY; y < fromY + cntY; y++) { + int curr = 0; + for (int x = fromX; x < fromX+8; x++) { + byte clr = MapUtils.getMapColorAt(MapUtils.getColors(), x,y); + if (clr == target) curr = (curr << 1) | 1; + else curr <<= 1; + } + sb.append("0x").append(Integer.toHexString(curr).toUpperCase()); + if (y != fromY + cntY - 1) sb.append(", "); + } + sb.append("}"); + System.out.println("\n"+sb.toString());*/ + } catch (Exception e) { + e.printStackTrace(); + } + } - @Override - public int getRequiredPermissionLevel() { - return 0; + private void testGuiCommand() { + GuiScreenAdapter adapter = new GuiScreenAdapter(new TestView()); + new Thread(DungeonsGuide.THREAD_GROUP, () -> { + Minecraft.getMinecraft().addScheduledTask(() -> { + Minecraft.getMinecraft().displayGuiScreen(adapter); + }); + }).start(); + } + + private void clearProfileCommand() { + Minecraft.getMinecraft().mcProfiler.clearProfiling(); } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoomInfoRegistry.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoomInfoRegistry.java index 45e019ff..11d16c42 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoomInfoRegistry.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoomInfoRegistry.java @@ -26,7 +26,7 @@ import lombok.Getter; import net.minecraft.client.Minecraft; import org.apache.commons.io.IOUtils; import org.jetbrains.annotations.NotNull; - +import net.minecraft.launchwrapper.Launch; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; @@ -37,7 +37,21 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.*; + + public class DungeonRoomInfoRegistry { + + /** + * DEV_USERS is used to check if the user is a dev user. + * You do not need to be in this list to use the commands if you are in a dev env. + * This lists whitelists users to allow them to use commands when not in a dev env. + */ + private static final List<String> DEV_USERS = + Arrays.asList( + "e686fe0aab804a71ac7011dc8c2b534c", //syeyoung + "a7d6b3f1842548e58acc9a38ab9b86f7" // whalker + ); + @Getter private static final List<DungeonRoomInfo> registered = new ArrayList<DungeonRoomInfo>(); private static final Map<Short, List<DungeonRoomInfo>> shapeMap = new HashMap<Short, List<DungeonRoomInfo>>(); @@ -98,7 +112,8 @@ public class DungeonRoomInfoRegistry { public static void saveAll(File dir) { dir.mkdirs(); - boolean isDev = Minecraft.getMinecraft().getSession().getPlayerID().replace("-","").equals("e686fe0aab804a71ac7011dc8c2b534c"); + //User is dev if they are in a dev environment or they are on the allowlist DEV_USERS + boolean isDev = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment") || DEV_USERS.contains(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-","")); StringBuilder nameIDString = new StringBuilder("name,uuid,processsor,secrets"); StringBuilder ids = new StringBuilder(); for (DungeonRoomInfo dungeonRoomInfo : registered) { |