Skip to content

Commit

Permalink
Fix destination's velocity not applying
Browse files Browse the repository at this point in the history
  • Loading branch information
benwoo1110 committed Feb 23, 2025
1 parent 733a561 commit fe0be3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Service;

import org.mvplugins.multiverse.core.MultiverseCore;
import org.mvplugins.multiverse.core.destination.DestinationInstance;

/**
* Teleports entities safely and asynchronously. Provider for the {@link AsyncSafetyTeleporter}.
*/
@Service
public final class AsyncSafetyTeleporter {
@NotNull
private final MultiverseCore multiverseCore;
private final BlockSafety blockSafety;
private final TeleportQueue teleportQueue;
private final PluginManager pluginManager;

@Inject
AsyncSafetyTeleporter(
@NotNull MultiverseCore multiverseCore,
@NotNull BlockSafety blockSafety,
@NotNull TeleportQueue teleportQueue,
@NotNull PluginManager pluginManager) {
this.multiverseCore = multiverseCore;
this.blockSafety = blockSafety;
this.teleportQueue = teleportQueue;
this.pluginManager = pluginManager;
Expand All @@ -37,6 +42,7 @@ public final class AsyncSafetyTeleporter {
*/
public AsyncSafetyTeleporterAction to(@Nullable Location location) {
return new AsyncSafetyTeleporterAction(
multiverseCore,
blockSafety,
teleportQueue,
pluginManager,
Expand All @@ -52,6 +58,7 @@ public AsyncSafetyTeleporterAction to(@Nullable Location location) {
*/
public AsyncSafetyTeleporterAction to(@Nullable DestinationInstance<?, ?> destination) {
return new AsyncSafetyTeleporterAction(
multiverseCore,
blockSafety,
teleportQueue,
pluginManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import com.dumptruckman.minecraft.util.Logging;
import io.papermc.lib.PaperLib;
import io.vavr.control.Either;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mvplugins.multiverse.core.MultiverseCore;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.event.MVTeleportDestinationEvent;
import org.mvplugins.multiverse.core.utils.result.Async;
Expand All @@ -24,6 +26,8 @@
*/
public final class AsyncSafetyTeleporterAction {

@NotNull
private final MultiverseCore multiverseCore;
private final BlockSafety blockSafety;
private final TeleportQueue teleportQueue;
private final PluginManager pluginManager;
Expand All @@ -33,10 +37,12 @@ public final class AsyncSafetyTeleporterAction {
private @Nullable CommandSender teleporter = null;

AsyncSafetyTeleporterAction(
@NotNull MultiverseCore multiverseCore,
@NotNull BlockSafety blockSafety,
@NotNull TeleportQueue teleportQueue,
@NotNull PluginManager pluginManager,
@NotNull Either<Location, DestinationInstance<?, ?>> locationOrDestination) {
this.multiverseCore = multiverseCore;
this.blockSafety = blockSafety;
this.teleportQueue = teleportQueue;
this.pluginManager = pluginManager;
Expand Down Expand Up @@ -161,11 +167,18 @@ private AsyncAttempt<Void, TeleportFailureReason> doAsyncTeleport(
return Attempt.failure(TeleportFailureReason.TELEPORT_FAILED_EXCEPTION);
}).mapAttempt(success -> {
if (success) {
applyPostTeleportVelocity(teleportee);
Logging.finer("Teleported async %s to %s", teleportee.getName(), location);
return Attempt.success(null);
}
Logging.warning("Failed to async teleport %s to %s", teleportee.getName(), location);
return Attempt.failure(TeleportFailureReason.TELEPORT_FAILED);
});
}

private void applyPostTeleportVelocity(@NotNull Entity teleportee) {
locationOrDestination.peek(destination ->
destination.getVelocity(teleportee).peek(velocity ->
Bukkit.getScheduler().runTaskLater(multiverseCore, () -> teleportee.setVelocity(velocity), 1L)));
}
}

0 comments on commit fe0be3e

Please sign in to comment.