diff --git a/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java index f18821ab..2570c1d3 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java @@ -1,6 +1,7 @@ package com.fibermc.essentialcommands.commands; import java.util.Random; +import java.util.concurrent.CompletableFuture; import com.fibermc.essentialcommands.EssentialCommands; import com.fibermc.essentialcommands.ManagerLocator; @@ -19,6 +20,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Material; import net.minecraft.command.CommandException; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -78,15 +80,14 @@ public int run(CommandContext context) throws CommandSyntax playerData.setTimeUsedRtp(curServerTickTime); } - new Thread("RTP Location Calculator Thread") { - public void run() { - try { - exec(context.getSource(), world); - } catch (CommandSyntaxException e) { - e.printStackTrace(); - } + CompletableFuture.runAsync(() -> { + try { + exec(context.getSource(), world); + } catch (CommandSyntaxException e) { + e.printStackTrace(); } - }.start(); + }); + return 1; } @@ -156,11 +157,11 @@ private static int exec(ServerPlayerEntity player, ServerWorld world, MinecraftL } // Teleport the player - PlayerTeleporter.requestTeleport( + world.getServer().executeSync(() -> PlayerTeleporter.requestTeleport( player, new MinecraftLocation(world.getRegistryKey(), new_x, new_y, new_z, 0, 0), ecText.getText("cmd.rtp.location_name") - ); + )); return 1; }