Skip to content

Commit

Permalink
log total rtp time as well, include safety check in validate time
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Paul-R committed Mar 18, 2023
1 parent fc9eda6 commit b106cd1
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ public int run(CommandContext<ServerCommandSource> 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();
}
Expand Down Expand Up @@ -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",
Expand All @@ -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);
}

Expand Down

0 comments on commit b106cd1

Please sign in to comment.