From b106cd1ef8e66b498c61376aabe9f607a28c248a Mon Sep 17 00:00:00 2001 From: John Paul Rutigliano Date: Sat, 18 Mar 2023 11:26:03 -0400 Subject: [PATCH] log total rtp time as well, include safety check in validate time --- .../commands/RandomTeleportCommand.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java index b08e3f08..ec4cd034 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java @@ -82,7 +82,18 @@ public int run(CommandContext context) throws CommandSyntax new Thread("RTP Location Calculator Thread") { public void run() { try { - exec(context.getSource(), world); + { + Stopwatch timer = Stopwatch.createStarted(); + + exec(context.getSource(), world); + + var totalTime = timer.stop(); + EssentialCommands.LOGGER.info( + String.format( + "Total RTP Time: %s", + Text.literal(String.valueOf(totalTime)) + )); + } } catch (CommandSyntaxException e) { e.printStackTrace(); } @@ -140,9 +151,15 @@ private static int exec(ServerPlayerEntity player, ServerWorld world, Vec3i cent Chunk chunk = world.getChunk(targetXZ); + boolean isSafePosition; + { Stopwatch timer = Stopwatch.createStarted(); + new_y = getTop(chunk, new_x, new_z); + + isSafePosition = isSafePosition(chunk, new BlockPos(new_x, new_y - 2, new_z)); + EssentialCommands.LOGGER.info( ECText.getInstance().getText( "cmd.rtp.log.location_validate_time", @@ -152,7 +169,7 @@ private static int exec(ServerPlayerEntity player, ServerWorld world, Vec3i cent // This creates an infinite recursive call in the case where all positions on RTP circle are in water. // Addressed by adding timesRun limit. - if (!isSafePosition(chunk, new BlockPos(new_x, new_y - 2, new_z))) { + if (!isSafePosition) { return exec(player, world, center, timesRun + 1); }