diff --git a/MarriageMaster/src/at/pcgamingfreaks/MarriageMaster/Bukkit/Commands/HomeCommand.java b/MarriageMaster/src/at/pcgamingfreaks/MarriageMaster/Bukkit/Commands/HomeCommand.java index c14f990b..6e601855 100644 --- a/MarriageMaster/src/at/pcgamingfreaks/MarriageMaster/Bukkit/Commands/HomeCommand.java +++ b/MarriageMaster/src/at/pcgamingfreaks/MarriageMaster/Bukkit/Commands/HomeCommand.java @@ -257,7 +257,7 @@ public void doTheTP(MarriagePlayer player, Marriage marriage) player.send(messageNoHome); return; } - player.getPlayerOnline().teleport(marriage.getHome().getLocation()); + TpCommand.teleportAsync(player.getPlayerOnline(), marriage.getHome().getLocation()); player.send(messageTPed); } else diff --git a/MarriageMaster/src/at/pcgamingfreaks/MarriageMaster/Bukkit/Commands/TpCommand.java b/MarriageMaster/src/at/pcgamingfreaks/MarriageMaster/Bukkit/Commands/TpCommand.java index 559d6f38..89aab7b1 100644 --- a/MarriageMaster/src/at/pcgamingfreaks/MarriageMaster/Bukkit/Commands/TpCommand.java +++ b/MarriageMaster/src/at/pcgamingfreaks/MarriageMaster/Bukkit/Commands/TpCommand.java @@ -42,10 +42,13 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.concurrent.CompletableFuture; public class TpCommand extends MarryCommand { @@ -197,7 +200,7 @@ public void doTheTP(final @NotNull Player player, final @NotNull Player partner) } else { - player.teleport(loc); + teleportAsync(player, loc); messageTeleport.send(player); messageTeleportTo.send(partner); } @@ -213,6 +216,16 @@ public void doTheTP(final @NotNull Player player, final @NotNull Player partner) } } + public static CompletableFuture teleportAsync(Player player, Location location) { + try { + Method method = player.getClass().getMethod("teleportAsync", Location.class); + return (CompletableFuture) method.invoke(player, location); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + // paper's teleportAsync not found, fallback to bukkit's teleport + return CompletableFuture.completedFuture(player.teleport(location)); + } + } + @AllArgsConstructor private class TpToPartner implements DelayableTeleportAction {