mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
fix: dismount before changing servers, close #555
This commit is contained in:
5 files changed
+61
-5
No files matched your search
@@ -34,6 +34,7 @@ import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -106,6 +107,23 @@ public class BukkitUser extends OnlineUser {
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> dismount() {
|
||||
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
((BukkitHuskHomes) plugin).getScheduler().entitySpecificScheduler(player).run(
|
||||
() -> {
|
||||
player.leaveVehicle();
|
||||
player.eject();
|
||||
future.complete(null);
|
||||
},
|
||||
() -> {
|
||||
plugin.log(Level.WARNING, "User offline when dismounting: " + player.getName());
|
||||
future.complete(null);
|
||||
}
|
||||
);
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportLocally(@NotNull Location location, boolean async) throws TeleportationException {
|
||||
// Ensure the world exists
|
||||
|
||||
@@ -98,12 +98,14 @@ public class PluginMessageBroker extends Broker {
|
||||
|
||||
@Override
|
||||
public void changeServer(@NotNull OnlineUser user, @NotNull String server) {
|
||||
final ByteArrayDataOutput outputStream = ByteStreams.newDataOutput();
|
||||
user.dismount().thenRun(() -> {
|
||||
final ByteArrayDataOutput outputStream = ByteStreams.newDataOutput();
|
||||
|
||||
outputStream.writeUTF("Connect");
|
||||
outputStream.writeUTF(server);
|
||||
outputStream.writeUTF("Connect");
|
||||
outputStream.writeUTF(server);
|
||||
|
||||
user.sendPluginMessage(BUNGEE_CHANNEL_ID, outputStream.toByteArray());
|
||||
user.sendPluginMessage(BUNGEE_CHANNEL_ID, outputStream.toByteArray());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.intellij.lang.annotations.Subst;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* A cross-platform representation of a logged-in {@link User}.
|
||||
@@ -180,6 +181,13 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
|
||||
return plugin.getAudience(getUuid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismount the player, readying them for teleportation.
|
||||
*
|
||||
* @return a {@link CompletableFuture} that completes when the player has dismounted
|
||||
*/
|
||||
public abstract CompletableFuture<Void> dismount();
|
||||
|
||||
/**
|
||||
* Teleport a player to the specified local {@link Location}.
|
||||
*
|
||||
|
||||
@@ -23,6 +23,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -39,6 +40,7 @@ import net.william278.huskhomes.teleport.TeleportationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class FabricUser extends OnlineUser {
|
||||
|
||||
@@ -122,6 +124,17 @@ public class FabricUser extends OnlineUser {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> dismount() {
|
||||
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
plugin.runSync(() -> {
|
||||
player.stopRiding();
|
||||
player.getPassengerList().forEach(Entity::stopRiding);
|
||||
future.complete(null);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportLocally(@NotNull Location location, boolean async) throws TeleportationException {
|
||||
final MinecraftServer server = player.getServer();
|
||||
@@ -129,7 +142,9 @@ public class FabricUser extends OnlineUser {
|
||||
throw new TeleportationException(TeleportationException.Type.ILLEGAL_TARGET_COORDINATES, plugin);
|
||||
}
|
||||
|
||||
player.dismountVehicle();
|
||||
player.stopRiding();
|
||||
player.getPassengerList().forEach(Entity::stopRiding);
|
||||
|
||||
FabricDimensions.teleport(
|
||||
player,
|
||||
server.getWorld(server.getWorldRegistryKeys().stream()
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.spongepowered.api.world.server.ServerLocation;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SpongeUser extends OnlineUser {
|
||||
|
||||
@@ -104,6 +105,17 @@ public class SpongeUser extends OnlineUser {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> dismount() {
|
||||
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
plugin.runSync(() -> {
|
||||
player.vehicle().ifPresent(vehicle -> vehicle.get().passengers().remove(player));
|
||||
player.passengers().forEach(passenger -> player.passengers().remove(passenger));
|
||||
future.complete(null);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportLocally(@NotNull Location location, boolean async) {
|
||||
plugin.runSync(() -> {
|
||||
@@ -112,6 +124,7 @@ public class SpongeUser extends OnlineUser {
|
||||
return;
|
||||
}
|
||||
player.vehicle().ifPresent(vehicle -> vehicle.get().passengers().remove(player));
|
||||
player.passengers().forEach(passenger -> player.passengers().remove(passenger));
|
||||
player.setLocation(serverLocation.get());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user