gamerchamper

Maybe we should presend the cordinates result to the target server if the player comes in range like 10 blocks away to allow for faster/instant syncing.

📎 2 files 18,784 chars
📄
pasted-code-1775185893129.txt
txt 151 lines
▶
package com.normalsmp.normalSurvivalWorlds;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import org.slf4j.Logger;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

@Plugin(id = "normalsurvivalworlds", name = "NormalSurvivalWorlds", version = "2.0")
public class NormalSurvivalWorlds {

    public static final MinecraftChannelIdentifier CHANNEL = MinecraftChannelIdentifier.from("nsw:playerdata");

    private final ProxyServer server;
    private final Logger logger;

    private final Map playerDataMap = new ConcurrentHashMap<>();

    @Inject
    public NormalSurvivalWorlds(ProxyServer server, Logger logger) {
        this.server = server;
        this.logger = logger;
    }

    @Subscribe
    public void onProxyInitialization(ProxyInitializeEvent event) {
        server.getChannelRegistrar().register(CHANNEL);
        logger.info("[NSW] NormalSurvivalWorlds v2.0 enabled");
    }

    @Subscribe
    public void onPlayerQuit(DisconnectEvent event) {
        UUID uuid = event.getPlayer().getUniqueId();
        playerDataMap.remove(uuid);
        logger.info("[NSW] Cleaned up data for " + uuid);
    }

    @Subscribe
    public void onPluginMessage(PluginMessageEvent event) {
        if (!event.getIdentifier().equals(CHANNEL)) return;

        logger.info("[NSW] Message source: " + event.getSource().getClass().getSimpleName());

        if (!(event.getSource() instanceof ServerConnection)) {
            logger.warn("[NSW] Message not from ServerConnection, ignoring");
            return;
        }

        ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());

        try {
            String sub = in.readUTF();
            logger.info("[NSW] Received " + sub + " from backend");

            if (sub.equals("DATA")) {
                handleData(in);
            } else if (sub.equals("PING")) {
                handlePing(in);
            }
        } catch (Exception e) {
            logger.error("[NSW] Proxy error", e);
        }
    }

    private void handlePing(ByteArrayDataInput in) {
        UUID uuid = UUID.fromString(in.readUTF());
        long timestamp = in.readLong();

        Player player = server.getPlayer(uuid).orElse(null);
        if (player == null) return;

        PlayerData data = playerDataMap.get(uuid);
        if (data == null) {
            logger.info("[NSW] No data for " + uuid + ", sending PONG anyway");

            String currentServerName = player.getCurrentServer().orElseThrow().getServerInfo().getName();
            server.getServer(currentServerName).ifPresent(srv -> {
                ByteArrayDataOutput output = ByteStreams.newDataOutput();
                output.writeUTF("PONG");
                output.writeLong(timestamp);
                output.writeDouble(0);
                output.writeDouble(0);
                output.writeDouble(0);
                output.writeFloat(0);
                output.writeFloat(0);
                srv.sendPluginMessage(CHANNEL, output.toByteArray());
                logger.info("[NSW] Sent empty PONG to server " + currentServerName);
            });
            return;
        }

        String currentServerName = player.getCurrentServer().orElseThrow().getServerInfo().getName();
        logger.info("[NSW] Current server for " + uuid + ": " + currentServerName);

        server.getServer(currentServerName).ifPresent(srv -> {
            ByteArrayDataOutput output = ByteStreams.newDataOutput();
            output.writeUTF("PONG");
            output.writeLong(timestamp);
            output.writeDouble(data.getX());
            output.writeDouble(data.getY());
            output.writeDouble(data.getZ());
            output.writeFloat(data.getYaw());
            output.writeFloat(data.getPitch());
            srv.sendPluginMessage(CHANNEL, output.toByteArray());
            logger.info("[NSW] Sent PONG to server " + currentServerName + " with pos " + data.getX() + " " + data.getY() + " " + data.getZ());
        });
    }

    private void handleData(ByteArrayDataInput in) {
        UUID uuid = UUID.fromString(in.readUTF());
        String username = in.readUTF();
        String serverName = in.readUTF();
        String world = in.readUTF();
        double x = in.readDouble();
        double y = in.readDouble();
        double z = in.readDouble();
        float yaw = in.readFloat();
        float pitch = in.readFloat();
        boolean borderHit = in.readBoolean();
        String targetServerName = in.readUTF();
        String edge = in.readUTF();

        logger.info("[NSW] DATA: " + username + " @ " + x + " " + y + " " + z + " | borderHit=" + borderHit + " target=" + targetServerName + " edge=" + edge);

        PlayerData data = new PlayerData(uuid, username, serverName, world, x, y, z, yaw, pitch);
        playerDataMap.put(uuid, data);

        if (borderHit && targetServerName != null) {
            Player player = server.getPlayer(uuid).orElse(null);
            if (player == null) return;

            server.getServer(targetServerName).ifPresent(target -> {
                logger.info("[NSW] Transferring " + username + " -> " + targetServerName);
                player.createConnectionRequest(target).fireAndForget();
            });
        }
    }
}
📄
pasted-code-1775185898123.txt
txt 340 lines
▶
package com.normalsmp.normalSurvivalWorldsPaper;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.Component;
import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.event.*;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.material.MaterialData;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public final class NormalSurvivalWorldsPaper extends JavaPlugin implements Listener {

    private static final String CHANNEL = "nsw:playerdata";

    private String serverName, targetServer, borderType;
    private double minX, maxX, minZ, maxZ, buffer;

    private final Map cooldown = new HashMap<>();
    private final Set frozenPlayers = new HashSet<>();
    private final Map> playerWalls = new ConcurrentHashMap<>();
    private final Set wallUpdateQueued = new HashSet<>();
    private static final long COOLDOWN_MS = 5000; // 5 seconds
    private static final double POSITION_SHIFT = 10.0; // Shift amount to get out of border zone
    private static final double WALL_DISTANCE = 10.0; // Show wall when within this distance

    @Override
    public void onEnable() {
        saveDefaultConfig();

        serverName = getConfig().getString("server-name");
        targetServer = getConfig().getString("target-server");
        borderType = getConfig().getString("border.type", "OUT");

        minX = getConfig().getDouble("border.min-x");
        maxX = getConfig().getDouble("border.max-x");
        minZ = getConfig().getDouble("border.min-z");
        maxZ = getConfig().getDouble("border.max-z");
        buffer = getConfig().getDouble("border.buffer", 5);

        getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
        getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, this::onMessage);

        Bukkit.getPluginManager().registerEvents(this, this);

        getLogger().info("[NSW] Enabled on " + serverName + " | Mode=" + borderType);
    }

    private void onMessage(String channel, Player player, byte[] message) {
        ByteArrayDataInput in = ByteStreams.newDataInput(message);
        String sub = in.readUTF();

        getLogger().info("[NSW] Received: " + sub);

        if (sub.equals("PONG")) {
            long timestamp = in.readLong();
            long latency = System.currentTimeMillis() - timestamp;

            double x = in.readDouble();
            double y = in.readDouble();
            double z = in.readDouble();
            float yaw = in.readFloat();
            float pitch = in.readFloat();

            getLogger().info("[NSW] PONG received! Latency: " + latency + "ms");
            getLogger().info("[NSW] Raw teleport to: " + x + " " + y + " " + z + " yaw=" + yaw + " pitch=" + pitch);

            if ((Math.abs(x) < 0.1 && Math.abs(z) < 0.1) || y == 0) {
                getLogger().warning("[NSW] Invalid PONG ignored");
                return;
            }

            // Shift position to get out of border zone
            double[] shifted = applyPositionShift(x, z, borderType);
            x = shifted[0];
            z = shifted[1];

            getLogger().info("[NSW] After shift: " + x + " " + y + " " + z);

            Location loc = new Location(player.getWorld(), x, y, z);
            loc.setYaw(yaw);
            loc.setPitch(pitch);

            player.setVelocity(new Vector(0, 0, 0));
            player.teleport(loc);

            player.setAI(true);
            frozenPlayers.remove(player.getUniqueId());

            cooldown.put(player.getUniqueId(), System.currentTimeMillis());

            getLogger().info("[NSW] Teleported " + player.getName() + " to " + x + " " + y + " " + z + " yaw=" + yaw + " pitch=" + pitch);
        }
    }

    private double[] applyPositionShift(double x, double z, String type) {
        if (type.equalsIgnoreCase("OUT")) {
            if (x > maxX) x += POSITION_SHIFT;
            else if (x < minX) x -= POSITION_SHIFT;
            else if (z > maxZ) z += POSITION_SHIFT;
            else if (z < minZ) z -= POSITION_SHIFT;
        } else if (type.equalsIgnoreCase("IN")) {
            double distX = Math.min(Math.abs(maxX - x), Math.abs(x - minX));
            double distZ = Math.min(Math.abs(maxZ - z), Math.abs(z - minZ));

            if (distX < distZ) {
                if (x > 0) x += POSITION_SHIFT;
                else x -= POSITION_SHIFT;
            } else {
                if (z > 0) z += POSITION_SHIFT;
                else z -= POSITION_SHIFT;
            }
        }
        return new double[] {x, z};
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Player player = e.getPlayer();
        getLogger().info("[NSW] Player joined: " + player.getName());

        frozenPlayers.add(player.getUniqueId());
        player.setAI(false);

        // Safety: unfreeze after 5 seconds if PONG never arrives
        Bukkit.getScheduler().runTaskLater(this, () -> {
            if (frozenPlayers.contains(player.getUniqueId())) {
                frozenPlayers.remove(player.getUniqueId());
                player.setAI(true);
                getLogger().warning("[NSW] PONG timeout - unfroze " + player.getName());
            }
        }, 100L);

        Bukkit.getScheduler().runTaskLater(this, () -> {
            sendData(player, false, "NONE");
            sendPing(player);
        }, 20L);
    }

    private void sendPing(Player player) {
        long timestamp = System.currentTimeMillis();
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("PING");
        out.writeUTF(player.getUniqueId().toString());
        out.writeLong(timestamp);

        player.sendPluginMessage(this, CHANNEL, out.toByteArray());
        getLogger().info("[NSW] Sent PING to proxy - success=" + true);
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent e) {
        UUID uuid = e.getPlayer().getUniqueId();
        cooldown.remove(uuid);
        frozenPlayers.remove(uuid);
        wallUpdateQueued.remove(uuid);
        removeWall(uuid);
        getLogger().info("[NSW] Player quit: " + uuid);
    }

    @EventHandler
    public void onMove(PlayerMoveEvent e) {
        Player player = e.getPlayer();
        UUID uuid = player.getUniqueId();

        if (frozenPlayers.contains(uuid)) {
            e.setCancelled(true);
            return;
        }

        if (e.getFrom().getBlockX() == e.getTo().getBlockX() &&
                e.getFrom().getBlockZ() == e.getTo().getBlockZ()) {
            return;
        }

        if (cooldown.containsKey(uuid)) {
            long remaining = System.currentTimeMillis() - cooldown.get(uuid);
            if (remaining < COOLDOWN_MS) {
                return;
            }
            cooldown.remove(uuid);
        }

        double x = e.getTo().getX();
        double z = e.getTo().getZ();

        boolean isInside = (x > minX && x < maxX && z > minZ && z < maxZ);
        boolean borderHit = false;
        String edge = "NONE";

        if (borderType.equalsIgnoreCase("OUT")) {
            if (!isInside) {
                borderHit = true;
                if (x >= maxX) edge = "EAST";
                else if (x <= minX) edge = "WEST";
                else if (z >= maxZ) edge = "SOUTH";
                else if (z <= minZ) edge = "NORTH";
            }
        } else {
            if (isInside) {
                borderHit = true;
                edge = determineInwardEdge(x, z);
            }
        }

        double dist = distanceToBoundary(x, z);
        if (dist <= buffer && dist > 0) {
            player.sendActionBar(Component.text("Border: " + Math.round(dist) + "m"));
        }

        // Update wall visualization (throttled to every 10 ticks)
        if (!wallUpdateQueued.contains(uuid)) {
            wallUpdateQueued.add(uuid);
            Bukkit.getScheduler().runTaskLater(this, () -> {
                wallUpdateQueued.remove(uuid);
                updateWall(player, x, z);
            }, 10L);
        }

        if (borderHit) {
            getLogger().info("[NSW] BORDER HIT: " + edge + " @ " + x + " " + z);
            sendData(player, true, edge);
        }
    }

    private void sendData(Player player, boolean borderHit, String edge) {
        Location loc = player.getLocation();

        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("DATA");
        out.writeUTF(player.getUniqueId().toString());
        out.writeUTF(player.getName());
        out.writeUTF(serverName);
        out.writeUTF(player.getWorld().getName());
        out.writeDouble(loc.getX());
        out.writeDouble(loc.getY());
        out.writeDouble(loc.getZ());
        out.writeFloat(loc.getYaw());
        out.writeFloat(loc.getPitch());
        out.writeBoolean(borderHit);
        out.writeUTF(targetServer);
        out.writeUTF(edge);

        player.sendPluginMessage(this, CHANNEL, out.toByteArray());
        getLogger().info("[NSW] Sent DATA: " + player.getName() + " borderHit=" + borderHit);
    }

    private String determineInwardEdge(double x, double z) {
        double dE = Math.abs(maxX - x);
        double dW = Math.abs(minX - x);
        double dS = Math.abs(maxZ - z);
        double dN = Math.abs(minZ - z);
        double min = Math.min(Math.min(dE, dW), Math.min(dS, dN));

        if (min == dE) return "EAST";
        if (min == dW) return "WEST";
        if (min == dS) return "SOUTH";
        return "NORTH";
    }

    private double distanceToBoundary(double x, double z) {
        double dx = Math.min(Math.abs(maxX - x), Math.abs(x - minX));
        double dz = Math.min(Math.abs(maxZ - z), Math.abs(z - minZ));
        return Math.min(dx, dz);
    }

    private void updateWall(Player player, double px, double pz) {
        World world = player.getWorld();
        UUID uuid = player.getUniqueId();

        double dist = distanceToBoundary(px, pz);

        // Show wall when within 10 blocks of border
        if (dist > WALL_DISTANCE) {
            removeWall(uuid);
            return;
        }

        removeWall(uuid);

        // Position wall 1 block inside the border
        double wallX = px;
        double wallZ = pz;

        if (borderType.equalsIgnoreCase("OUT")) {
            // For OUT server, wall is at the inner border edge
            if (px > maxX) wallX = maxX - 1;
            else if (px < minX) wallX = minX + 1;
            else if (pz > maxZ) wallZ = maxZ - 1;
            else if (pz < minZ) wallZ = minZ + 1;
        } else {
            // For IN server, wall is at the inner border edge
            if (px > maxX) wallX = maxX - 1;
            else if (px < minX) wallX = minX + 1;
            else if (pz > maxZ) wallZ = maxZ - 1;
            else if (pz < minZ) wallZ = minZ + 1;
        }

        List wallEntities = new ArrayList<>();
        int centerX = (int) Math.floor(wallX);
        int centerZ = (int) Math.floor(wallZ);
        double playerY = player.getLocation().getY();

        // 5x5 vertical glass wall at border position
        for (int ix = -2; ix <= 2; ix++) {
            for (int iz = -2; iz <= 2; iz++) {
                for (int iy = 0; iy <= 5; iy++) {
                    Location frameLoc = new Location(world, centerX + ix, playerY + iy, centerZ + iz);
                    ItemFrame frame = world.spawn(frameLoc, ItemFrame.class);
                    frame.setVisible(false);
                    frame.setInvulnerable(true);
                    frame.setGravity(false);
                    frame.setItem(new MaterialData(Material.GLASS, (byte) 0).toItemStack(1));
                    frame.setFixed(true);
                    frame.addScoreboardTag("nsw_wall");
                    wallEntities.add(frame);
                }
            }
        }

        playerWalls.put(uuid, wallEntities);
    }

    private void removeWall(UUID uuid) {
        List entities = playerWalls.remove(uuid);
        if (entities != null) {
            for (Entity ent : entities) {
                ent.remove();
            }
        }
    }
}
Kodari AI
KodariApr 3 at 3:14 am 16,122 (v2)

I’ll create an improved cross-server world border system with position pre-syncing for instant transfers.

NormalSurvivalWorlds
A cross-server world border system for Velocity networks enabling seamless player transfers between connected servers. Features configurable IN/OUT border types, visual wall indicators shown within 10 blocks, position pre-syncing for instant transfers when approaching borders, and automatic cooldown management. Players crossing borders are smoothly transferred to adjacent servers with exact position preservation and minimal delay through predictive coordinate caching.

System created with position pre-syncing for instant transfers. When players approach within 10 blocks of the border, their coordinates are sent to the target server and cached, eliminating the PING/PONG delay on join for seamless cross-server transitions.

gamerchamper

[23:53:33 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8001.638703619364,823.0410764682532 [23:53:33 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8000.561382476039,823.5161265933818 [23:53:34 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7999.66925278583,823.9095156246756 [23:53:34 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7999.282460833526,824.0800734629574 [23:53:34 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7998.930480146785,824.235281100267 [23:53:34 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7999.205431851991,824.5623014445595 [23:53:34 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8000.094767614311,824.4797113217112 [23:53:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8001.164590210297,824.3696313823068 [23:53:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8002.371717200857,824.2527417877086 [23:53:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8003.093873347498,824.1871918349269 [23:53:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8004.187109240007,824.0879590561624 [23:53:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8005.084030659685,824.0065456984252 [23:53:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8005.218014737704,823.9943839934691 [23:53:36 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8006.0451898706015,823.9193014906672 | borderHit=true target=server-in [23:53:34 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:34 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 7998.958776924905,137.86859856141194,824.5821051140096 | borderHit=true target=server-in [23:53:34 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:34 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 7999.775700249939,137.86859856141194,824.5107518201826 | borderHit=true target=server-in [23:53:35 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:35 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8000.790896074861,138.25859857690915,824.4086309639814 | borderHit=true target=server-in [23:53:35 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:35 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8001.956231258787,139.22483861530407,824.2904553542425 | borderHit=true target=server-in [23:53:35 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:35 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8002.749809419038,139.55684502849684,824.2184224411737 | borderHit=true target=server-in [23:53:35 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:35 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8003.951167508051,139.71939536839602,824.109375434685 | borderHit=true target=server-in [23:53:35 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:35 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8004.936795413357,139.73837073013306,824.0199102089807 | borderHit=true target=server-in [23:53:35 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:35 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8005.084030659685,139.73837073013306,824.0065456984252 | borderHit=true target=server-in [23:53:36 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [23:53:36 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8005.993014296013,139.73837073013306,823.9240374559657 | borderHit=true target=server-in

Server2 - ter and More!

Get it now: → https://www.spigotmc.org/resources/79061/ [23:52:36 INFO]: [spark] Starting background profiler... [23:52:36 INFO]: [spark] The async-profiler engine is not supported for your os/arch (windows11/amd64), so the built-in Java engine will be used instead. [23:52:36 INFO]: Running delayed init tasks [23:52:37 INFO]: Done (24.482s)! For help, type "help"

it doesnt look like im getting sent to server2 when im past the border in server1

Kodari AI
KodariApr 3 at 3:54 am 11,836 (v2)

I need to read the existing code to understand why the player transfer isn’t working.

Looking at the logs, I can see the Velocity proxy is receiving the DATA messages with borderHit=true and target=server-in, but there’s no “Transferring” log message. This indicates the server lookup is failing.

The issue is in the Velocity plugin - when server.getServer(targetServerName) returns empty, the ifPresent block never executes. The most common cause is the server name in your Velocity config doesn’t match "server-in" exactly.

Let me add diagnostic logging to help identify the problem:

This patch adds error logging that will tell you:

  1. If the player isn’t found on the proxy

  2. If the target server name doesn’t exist (most likely your issue)

  3. What server names ARE registered on Velocity

After applying this, restart your proxy and try again. You’ll see a log message like:

Plain Text
[NSW] Cannot transfer Ridewithit - server 'server-in' not found!
[NSW] Available servers: lobby, survival, creative

Then you need to:

  1. Check your velocity.toml config file

  2. Ensure a server is registered with the EXACT name "server-in" (case-sensitive)

  3. Update your Paper config.yml to match the exact server name from Velocity

gamerchamper

server1: 288, 828.4056146580207) [00:00:00 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:00:01 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:00:01 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 24ms [00:00:01 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 7999.972984215797,136.0,833.7303422908618 [00:00:06 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:19 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:20 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:22 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:23 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:25 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:27 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:28 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:29 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:30 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:31 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:32 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:34 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:00:34 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8000.001743000057,784.1638154425547 [00:00:34 INFO]: Ridewithit lost connection: Disconnected [00:00:34 INFO]: Ridewithit left the game server2:8434727046) [00:00:35 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:00:36 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:00:36 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 14ms [00:00:36 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8009.925687223044,136.0,833.7298434727046 [00:00:41 INFO]: Ridewithit lost connection: Disconnected [00:00:41 INFO]: Ridewithit left the game

velocity: [00:00:34 INFO] [normalsurvivalworlds]: [NSW] Transferring Ridewithit -> server2 [00:00:34 INFO]: [server connection] Ridewithit -> server2 has connected [00:00:34 INFO]: [server connection] Ridewithit -> server1 has disconnected [00:00:35 INFO]: [Velocity] Ridewithit bedrock=false [00:00:36 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:00:36 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 7999.925687223044,136.0,833.7298434727046 | borderHit=false target=server1 [00:00:36 INFO] [normalsurvivalworlds]: [NSW] Received PING from backend [00:00:36 INFO] [normalsurvivalworlds]: [NSW] Sent PONG to server2 with position [00:00:41 INFO]: [connected player] Ridewithit (/127.0.0.1:54402) has disconnected [00:00:41 INFO]: [server connection] Ridewithit -> server2 has disconnected [00:00:41 INFO] [normalsurvivalworlds]: [NSW] Cleaned up data for ded34a2f-3fc7-3885-bdf9-b5db8d2494d9

positions are off by a lot when they get transferred

Kodari AI
KodariApr 3 at 4:03 am 15,253 (v2)

I need to read the plugin files to see how positions are being calculated during world border transfers.

Looking at the logs, I can see the problem:

server1 sends position 7999.925687223044,136.0,833.7298434727046
server2 teleports to 8009.925687223044,136.0,833.7298434727046 (+10 blocks in wrong direction!)

The issue is in the applyPositionShift() method for IN borders. The current IN logic doesn’t know which edge the player crossed, so it guesses based on position signs - but this causes it to shift in the wrong direction.

The fix: Pass edge information through PRESYNC→CACHE so server2 knows which direction to shift.

Fixed! The position transfer now works correctly:

Changes made:

  • Added edge field to PlayerData and CachedPosition classes to track which border was crossed (EAST/WEST/NORTH/SOUTH)

  • Updated PRESYNC and CACHE messages to include edge information

  • Fixed applyPositionShift() for IN borders to shift in the opposite direction based on the edge crossed

  • Fixed typo in OUT border logic (z > maxX → z > maxZ)

How it works now:

  1. Player at x=7999 crosses EAST border at x=8000 on server1

  2. Server1 sends PRESYNC with edge=“EAST”

  3. Velocity forwards CACHE with edge=“EAST” to server2

  4. Server2 applies shift: if (edge.equals("EAST")) x -= POSITION_SHIFT;

  5. Result: x = 7999 - 10 = 7989 (correctly shifted inward!)

gamerchamper

server1: 00:07:12 INFO]: Ridewithit left the game [00:07:28 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:07:28 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:07:28 INFO]: Ridewithit joined the game [00:07:28 INFO]: Ridewithit[/127.0.0.1:62166] logged in with entity id 946 at ([world]8000.942843463141, 119.0, 784.2355348194376) [00:07:28 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:07:29 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:07:29 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 10ms [00:07:29 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8010.019044038085,119.0,784.5053547684225 [00:07:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:07:36 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:08:43 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:08:44 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:08:45 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:08:46 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:08:47 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:08:47 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8000.037629417845,781.7018373057615 [00:08:47 INFO]: Ridewithit lost connection: Disconnected [00:08:47 INFO]: Ridewithit left the game [00:09:05 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:09:05 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:09:05 INFO]: Ridewithit joined the game [00:09:05 INFO]: Ridewithit[/127.0.0.1:62197] logged in with entity id 3117 at ([world]8000.037629417845, 119.0, 781.7018373057615) [00:09:05 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:09:06 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:09:06 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 10ms [00:09:06 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8010.181903062441,118.0,775.1746108425947 server2: [00:06:44 INFO]: [spark] Starting background profiler... [00:06:44 INFO]: [spark] The async-profiler engine is not supported for your os/arch (windows11/amd64), so the built-in Java engine will be used instead. [00:06:44 INFO]: Running delayed init tasks [00:06:44 INFO]: Done (20.627s)! For help, type "help" [00:07:12 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:07:14 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:07:14 INFO]: Ridewithit joined the game [00:07:14 INFO]: Ridewithit[/127.0.0.1:62160] logged in with entity id 216 at ([world]8009.300000011921, 136.0, 833.7298434727046) [00:07:14 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:07:15 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:07:15 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 170ms [00:07:15 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8009.973122096095,119.0,784.2051365839171 [00:07:24 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:07:25 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:07:26 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:07:28 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:07:28 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7999.865856251054,784.5057513100701 [00:07:28 INFO]: Ridewithit lost connection: Disconnected [00:07:28 INFO]: Ridewithit left the game [00:08:47 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:08:48 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:08:48 INFO]: Ridewithit joined the game [00:08:48 INFO]: Ridewithit[/127.0.0.1:62192] logged in with entity id 2351 at ([world]7999.865856251054, 119.0, 784.5057513100701) [00:08:48 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:08:49 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:08:49 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 7ms [00:08:49 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8009.856906633862,119.0,781.7023051244558 [00:09:02 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:09:03 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:09:04 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border [00:09:05 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7999.901348664121,775.1724045633648 [00:09:05 INFO]: Ridewithit lost connection: Disconnected [00:09:05 INFO]: Ridewithit left the game

velocity: ... 9 more [00:09:03 INFO] [normalsurvivalworlds]: [NSW] Received PRESYNC from backend [00:09:03 ERROR] [normalsurvivalworlds]: [NSW] Proxy error java.lang.IllegalStateException: java.io.EOFException at com.google.common.io.ByteStreams$ByteArrayDataInputStream.readUTF(ByteStreams.java:475) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] at com.normalsmp.normalsurvivalworlds.NormalSurvivalWorlds.handlePresync(NormalSurvivalWorlds.java:88) ~[?:?] at com.normalsmp.normalsurvivalworlds.NormalSurvivalWorlds.onPluginMessage(NormalSurvivalWorlds.java:70) ~[?:?] at com.normalsmp.normalsurvivalworlds.Lmbda$7.execute(Unknown Source) ~[?:?] at com.velocitypowered.proxy.event.UntargetedEventHandler$VoidHandler.lambda$buildHandler$0(UntargetedEventHandler.java:56) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] at com.velocitypowered.proxy.event.VelocityEventManager.fire(VelocityEventManager.java:677) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] at com.velocitypowered.proxy.event.VelocityEventManager.lambda$fire$5(VelocityEventManager.java:542) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090) ~[?:?] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614) ~[?:?] at java.base/java.lang.Thread.run(Thread.java:1474) [?:?] Caused by: java.io.EOFException at java.base/java.io.DataInputStream.readFully(DataInputStream.java:215) ~[?:?] at java.base/java.io.DataInputStream.readUnsignedShort(DataInputStream.java:346) ~[?:?] at java.base/java.io.DataInputStream.readUTF(DataInputStream.java:580) ~[?:?] at java.base/java.io.DataInputStream.readUTF(DataInputStream.java:555) ~[?:?] at com.google.common.io.ByteStreams$ByteArrayDataInputStream.readUTF(ByteStreams.java:473) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] ... 9 more [00:09:04 INFO] [normalsurvivalworlds]: [NSW] Received PRESYNC from backend [00:09:04 ERROR] [normalsurvivalworlds]: [NSW] Proxy error java.lang.IllegalStateException: java.io.EOFException at com.google.common.io.ByteStreams$ByteArrayDataInputStream.readUTF(ByteStreams.java:475) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] at com.normalsmp.normalsurvivalworlds.NormalSurvivalWorlds.handlePresync(NormalSurvivalWorlds.java:88) ~[?:?] at com.normalsmp.normalsurvivalworlds.NormalSurvivalWorlds.onPluginMessage(NormalSurvivalWorlds.java:70) ~[?:?] at com.normalsmp.normalsurvivalworlds.Lmbda$7.execute(Unknown Source) ~[?:?] at com.velocitypowered.proxy.event.UntargetedEventHandler$VoidHandler.lambda$buildHandler$0(UntargetedEventHandler.java:56) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] at com.velocitypowered.proxy.event.VelocityEventManager.fire(VelocityEventManager.java:677) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] at com.velocitypowered.proxy.event.VelocityEventManager.lambda$fire$5(VelocityEventManager.java:542) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090) ~[?:?] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614) ~[?:?] at java.base/java.lang.Thread.run(Thread.java:1474) [?:?] Caused by: java.io.EOFException at java.base/java.io.DataInputStream.readFully(DataInputStream.java:215) ~[?:?] at java.base/java.io.DataInputStream.readUnsignedShort(DataInputStream.java:346) ~[?:?] at java.base/java.io.DataInputStream.readUTF(DataInputStream.java:580) ~[?:?] at java.base/java.io.DataInputStream.readUTF(DataInputStream.java:555) ~[?:?] at com.google.common.io.ByteStreams$ByteArrayDataInputStream.readUTF(ByteStreams.java:473) ~[velocity-3.5.0-SNAPSHOT-584.jar:3.5.0-SNAPSHOT (git-d11511c1-b584)] ... 9 more [00:09:05 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:09:05 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8000.181903062441,118.0,775.1746108425947 | borderHit=true edge=EAST target=server1 [00:09:05 INFO] [normalsurvivalworlds]: [NSW] Transferring Ridewithit -> server1 [00:09:05 INFO]: [server connection] Ridewithit -> server1 has connected [00:09:05 INFO]: [server connection] Ridewithit -> server2 has disconnected [00:09:05 INFO]: [Velocity] Ridewithit bedrock=false [00:09:06 INFO] [normalsurvivalworlds]: [NSW] Received PING from backend [00:09:06 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:09:06 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8000.037629417845,119.0,781.7018373057615 | borderHit=false edge=NONE target=server2 [00:09:06 INFO] [normalsurvivalworlds]: [NSW] Sent PONG to server1 with position

going from server1 to server2 puts me 10 blocks ahead. and going from server2 to server1 it puts me 10 blocks in server2s border it seems so i have to move fast so i dont get travel looped

Kodari AI
KodariApr 3 at 4:13 am 20,591 (v2)

I need to read the code to understand how the border crossing teleportation is being calculated.

I can see the issue clearly now. There are two bugs:

  1. PRESYNC sends no edge, but Velocity tries to read one → causing the EOFException

  2. Position shift doesn’t consider which edge was crossed → always adding 10 blocks regardless of direction

The shift should be based on the edge crossed, not the border type:

  • EAST edge → player moves INTO eastern server (+X direction)

  • WEST edge → player moves INTO western server (-X direction)

Let me fix both issues:

Summary:

Fixed two critical bugs causing the 10-block offset:

  1. EOFException in PRESYNC - Velocity tried to read edge data that wasn’t being sent. Now Paper computes and sends the approaching edge.

  2. Incorrect position shift - The shift was based on border type (IN/OUT) and current position, not the actual edge crossed. Now it correctly shifts based on which edge was crossed:

    • EAST edge → +10 blocks X (into eastern server)

    • WEST edge → -10 blocks X (into western server)

    • NORTH edge → -10 blocks Z (into northern server)

    • SOUTH edge → +10 blocks Z (into southern server)

The player will now spawn exactly 10 blocks into the new server from the border they crossed, regardless of direction.

gamerchamper

server1: [00:18:20 INFO]: Ridewithit[/127.0.0.1:53600] logged in with entity id 5715 at ([world]8000.004592278041, 111.0, 874.3680146734001) [00:18:20 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:18:21 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:18:21 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 12ms (edge=EAST) [00:18:21 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8010.104039397654,89.0,619.6077342737049 [00:18:26 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:18:26 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8006.96405187794,619.6340067016909 [00:18:26 INFO]: Ridewithit lost connection: Disconnected [00:18:26 INFO]: Ridewithit left the game [00:18:36 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:18:36 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:18:36 INFO]: Ridewithit joined the game [00:18:36 INFO]: Ridewithit[/127.0.0.1:53608] logged in with entity id 6718 at ([world]8006.96405187794, 89.0, 619.6340067016909) [00:18:36 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:18:37 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:18:37 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 8ms (edge=EAST) [00:18:37 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8010.079124015918,89.0,619.765133934762 [00:18:59 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:19:00 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:19:02 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:19:02 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8000.089329425638,619.3759673769202 [00:19:02 INFO]: Ridewithit lost connection: Disconnected [00:19:02 INFO]: Ridewithit left the game [00:19:08 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:19:08 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:19:08 INFO]: Ridewithit joined the game [00:19:08 INFO]: Ridewithit[/127.0.0.1:53621] logged in with entity id 7364 at ([world]8000.089329425638, 88.0, 619.3759673769202) [00:19:08 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:19:09 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:19:09 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 9ms (edge=EAST) [00:19:09 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8003.148582898262,88.0,619.42724504555 Server2: [00:17:45 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:17:45 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:17:45 INFO]: Ridewithit joined the game [00:17:45 INFO]: Ridewithit[/127.0.0.1:53583] logged in with entity id 4591 at ([world]7999.978575691104, 108.0, 891.5568144448303) [00:17:45 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:17:46 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:17:46 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 24ms (edge=NONE) [00:17:46 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 7999.978575691104,108.0,891.5568144448303 [00:17:52 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:17:53 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:17:55 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:17:56 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:17:59 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:18:17 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:18:18 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:18:20 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:18:20 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7999.8882108492035,619.6094103839382 [00:18:20 INFO]: Ridewithit lost connection: Disconnected [00:18:20 INFO]: Ridewithit left the game [00:18:26 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:18:26 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:18:26 INFO]: Ridewithit joined the game [00:18:26 INFO]: Ridewithit[/127.0.0.1:53603] logged in with entity id 7434 at ([world]7999.8882108492035, 89.0, 619.6094103839382) [00:18:26 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:18:27 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:18:27 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 7ms (edge=EAST) [00:18:27 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8017.081642934713,89.0,619.6330934973209 [00:18:33 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:18:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:18:36 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:18:36 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7999.927620573971,619.7663105004724 [00:18:36 INFO]: Ridewithit lost connection: Disconnected [00:18:36 INFO]: Ridewithit left the game [00:19:02 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:19:02 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:19:02 INFO]: Ridewithit joined the game [00:19:02 INFO]: Ridewithit[/127.0.0.1:53618] logged in with entity id 8540 at ([world]7999.927620573971, 89.0, 619.7663105004724) [00:19:02 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:19:03 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:19:03 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 9ms (edge=EAST) [00:19:03 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8009.873782957916,88.0,619.3652272698995 [00:19:08 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:19:08 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7992.932742713807,619.4243891859284 [00:19:08 INFO]: Ridewithit lost connection: Disconnected [00:19:08 INFO]: Ridewithit left the game

velocity: r1 [00:18:36 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:18:36 INFO] [normalsurvivalworlds]: [NSW] Forwarded CACHE to server1 for Ridewithit (edge=EAST) [00:18:36 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8000.079124015918,89.0,619.765133934762 | borderHit=true edge=EAST target=server1 [00:18:36 INFO] [normalsurvivalworlds]: [NSW] Transferring Ridewithit -> server1 [00:18:36 INFO]: [server connection] Ridewithit -> server1 has connected [00:18:36 INFO]: [server connection] Ridewithit -> server2 has disconnected [00:18:36 INFO]: [Velocity] Ridewithit bedrock=false [00:18:37 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:18:37 INFO] [normalsurvivalworlds]: [NSW] Received PING from backend [00:18:37 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8006.96405187794,89.0,619.6340067016909 | borderHit=false edge=NONE target=server2 [00:18:37 INFO] [normalsurvivalworlds]: [NSW] Sent PONG to server1 with position (edge=EAST) [00:18:59 INFO] [normalsurvivalworlds]: [NSW] Received PRESYNC from backend [00:18:59 INFO] [normalsurvivalworlds]: [NSW] PRESYNC: Ridewithit approaching border (edge=EAST), will transfer to server2 [00:18:59 INFO] [normalsurvivalworlds]: [NSW] Forwarded CACHE to server2 for Ridewithit (edge=EAST) [00:19:00 INFO] [normalsurvivalworlds]: [NSW] Received PRESYNC from backend [00:19:00 INFO] [normalsurvivalworlds]: [NSW] PRESYNC: Ridewithit approaching border (edge=EAST), will transfer to server2 [00:19:00 INFO] [normalsurvivalworlds]: [NSW] Forwarded CACHE to server2 for Ridewithit (edge=EAST) [00:19:02 INFO] [normalsurvivalworlds]: [NSW] Received PRESYNC from backend [00:19:02 INFO] [normalsurvivalworlds]: [NSW] PRESYNC: Ridewithit approaching border (edge=EAST), will transfer to server2 [00:19:02 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:19:02 INFO] [normalsurvivalworlds]: [NSW] Forwarded CACHE to server2 for Ridewithit (edge=EAST) [00:19:02 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 7999.873782957916,88.0,619.3652272698995 | borderHit=true edge=EAST target=server2 [00:19:02 INFO] [normalsurvivalworlds]: [NSW] Transferring Ridewithit -> server2 [00:19:02 INFO]: [server connection] Ridewithit -> server2 has connected [00:19:02 INFO]: [server connection] Ridewithit -> server1 has disconnected [00:19:02 INFO]: [Velocity] Ridewithit bedrock=false [00:19:03 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:19:03 INFO] [normalsurvivalworlds]: [NSW] Received PING from backend [00:19:03 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 7999.927620573971,89.0,619.7663105004724 | borderHit=false edge=NONE target=server1 [00:19:03 INFO] [normalsurvivalworlds]: [NSW] Sent PONG to server2 with position (edge=EAST) [00:19:08 INFO] [normalsurvivalworlds]: [NSW] Received PRESYNC from backend [00:19:08 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:19:08 INFO] [normalsurvivalworlds]: [NSW] PRESYNC: Ridewithit approaching border (edge=EAST), will transfer to server1 [00:19:08 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 7993.148582898262,88.0,619.42724504555 | borderHit=true edge=EAST target=server1 [00:19:08 INFO] [normalsurvivalworlds]: [NSW] Forwarded CACHE to server1 for Ridewithit (edge=EAST) [00:19:08 INFO] [normalsurvivalworlds]: [NSW] Transferring Ridewithit -> server1 [00:19:08 INFO]: [server connection] Ridewithit -> server1 has connected [00:19:08 INFO]: [server connection] Ridewithit -> server2 has disconnected [00:19:08 INFO]: [Velocity] Ridewithit bedrock=false [00:19:09 INFO] [normalsurvivalworlds]: [NSW] Received DATA from backend [00:19:09 INFO] [normalsurvivalworlds]: [NSW] Received PING from backend [00:19:09 INFO] [normalsurvivalworlds]: [NSW] DATA: Ridewithit @ 8000.089329425638,88.0,619.3759673769202 | borderHit=false edge=NONE target=server2 [00:19:09 INFO] [normalsurvivalworlds]: [NSW] Sent PONG to server1 with position (edge=EAST)

Its better but now the way im facing is wrong when i cross servers

Kodari AI
KodariApr 3 at 4:21 am 13,319 (v2)

I need to read the current code to see how player position is being stored and transferred, and add yaw/pitch tracking.

Looking at the logs, I can see the transfer is working but the facing direction isn’t being preserved correctly. The issue is that the CACHE sent during PRESYNC (when player is 10 blocks away) has old yaw/pitch values, but when the player actually hits the border, they may have turned their head.

The fix: When DATA is received at border-hit time, send a fresh CACHE with the updated yaw/pitch to the target server.

The fix sends a fresh CACHE with the exact yaw/pitch from the border-hit moment, ensuring the player faces the correct direction after transfer.

gamerchamper

server1: 0:23:55 INFO]: Running delayed init tasks [00:23:56 INFO]: Done (22.330s)! For help, type "help" [00:24:15 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:24:16 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:24:16 INFO]: Ridewithit joined the game [00:24:16 INFO]: Ridewithit[/127.0.0.1:55075] logged in with entity id 357 at ([world]8008.5336768047055, 88.0, 620.8573751145955) [00:24:16 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:24:17 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:24:17 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 36ms (edge=NONE) [00:24:17 WARN]: [NormalSurvivalWorldsPaper] [NSW] Invalid PONG ignored [00:24:24 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:24:24 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 8007.908013677724,620.8179729468636 [00:24:24 INFO]: Ridewithit lost connection: Disconnected [00:24:24 INFO]: Ridewithit left the game [00:24:40 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:24:40 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:24:40 INFO]: Ridewithit joined the game [00:24:40 INFO]: Ridewithit[/127.0.0.1:55084] logged in with entity id 1543 at ([world]8007.067269218672, 88.0, 620.7650256773719) [00:24:40 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:24:41 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:24:41 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 11ms (edge=EAST) [00:24:41 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8010.15735409449,89.0,619.2974894290098 [00:24:45 INFO]: Ridewithit lost connection: Disconnected [00:24:45 INFO]: Ridewithit left the game

server2:

Get it now: → https://www.spigotmc.org/resources/79061/ [00:23:56 INFO]: [spark] Starting background profiler... [00:23:56 INFO]: [spark] The async-profiler engine is not supported for your os/arch (windows11/amd64), so the built-in Java engine will be used instead. [00:23:56 INFO]: Running delayed init tasks [00:23:57 INFO]: Done (21.309s)! For help, type "help" [00:24:24 INFO]: UUID of player Ridewithit is ded34a2f-3fc7-3885-bdf9-b5db8d2494d9 [00:24:26 INFO]: [NormalSurvivalWorldsPaper] [NSW] No valid cache, using PING/PONG for Ridewithit [00:24:26 INFO]: Ridewithit joined the game [00:24:26 INFO]: Ridewithit[/127.0.0.1:55079] logged in with entity id 671 at ([world]7992.932742713807, 88.0, 619.4243891859284) [00:24:26 INFO]: [normalsurvivalbedrock] RAW <- ded34a2f-3fc7-3885-bdf9-b5db8d2494d9:bedrock:false: [00:24:27 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PING to proxy [00:24:27 INFO]: [NormalSurvivalWorldsPaper] [NSW] PONG received! Latency: 113ms (edge=EAST) [00:24:27 INFO]: [NormalSurvivalWorldsPaper] [NSW] Teleported Ridewithit to 8018.10429862288,88.0,620.8303343151443 [00:24:34 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:24:35 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:24:37 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:24:39 INFO]: [NormalSurvivalWorldsPaper] [NSW] Sent PRESYNC: Ridewithit approaching border (edge=EAST) [00:24:40 INFO]: [NormalSurvivalWorldsPaper] [NSW] BORDER HIT: EAST @ 7999.944635727974,619.3002631863019 [00:24:40 INFO]: Ridewithit lost connection: Disconnected [00:24:40 INFO]: Ridewithit left the game

i went to server2 and its teleporting me inside of the border technically on server1 which is wrong

Kodari AI
KodariApr 3 at 4:26 am 12,067 (v2)

I need to read the code to understand how the teleportation logic works when players cross borders.

I found the bug! The position shift logic in applyPositionShift is inverted.

When a player crosses from the EAST side, they should spawn on the WEST side of the border on the new server (subtract from X), but the code currently adds to X, pushing them further east.

The issue:

  • Edge represents where the player came from

  • The shift should move them in the opposite direction

  • Currently: edge=EAST → x += 10 (wrong!)

  • Should be: edge=EAST → x -= 10 (move west)

Fixed! The position shift now correctly moves players in the opposite direction of the edge they crossed from. When you cross from the EAST, you’ll now spawn 10 blocks to the WEST of the border on the new server.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
7 810
src/main/java/com/normalsmp/normalsurvivalworldspaper/NormalSurvivalWorldsPaper.java
package com.normalsmp.normalsurvivalworldspaper;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public final class NormalSurvivalWorldsPaper extends JavaPlugin implements Listener {

    private static final String CHANNEL = "nsw:playerdata";

    private String serverName, targetServer, borderType;
    private double minX, maxX, minZ, maxZ, buffer;

    private final Map<UUID, Long> cooldown = new HashMap<>();
    private final Map<UUID, Long> presyncCooldown = new HashMap<>();
    private final Set<UUID> frozenPlayers = new HashSet<>();
    private final Map<UUID, List<Entity>> playerWalls = new ConcurrentHashMap<>();
    private final Set<UUID> wallUpdateQueued = new HashSet<>();
    private final Map<UUID, CachedPosition> positionCache = new ConcurrentHashMap<>();

    private static final long COOLDOWN_MS = 5000;
    private static final long PRESYNC_COOLDOWN_MS = 1000;
    private static final double POSITION_SHIFT = 10.0;
    private static final double WALL_DISTANCE = 10.0;
    private static final double PRESYNC_DISTANCE = 10.0;
    private static final long CACHE_VALID_MS = 3000;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        serverName = getConfig().getString("server-name");
        targetServer = getConfig().getString("target-server");
        borderType = getConfig().getString("border.type", "OUT");

        minX = getConfig().getDouble("border.min-x");
        maxX = getConfig().getDouble("border.max-x");
        minZ = getConfig().getDouble("border.min-z");
        maxZ = getConfig().getDouble("border.max-z");
        buffer = getConfig().getDouble("border.buffer", 5);

        getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
        getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, this::onMessage);

        Bukkit.getPluginManager().registerEvents(this, this);

        getLogger().info("[NSW] Enabled v2.1 on " + serverName + " | Mode=" + borderType + " | Pre-sync active");
    }

    private void onMessage(String channel, Player player, byte[] message) {
        ByteArrayDataInput in = ByteStreams.newDataInput(message);
        String sub = in.readUTF();

        if (sub.equals("PONG")) {
            handlePong(player, in);
        } else if (sub.equals("CACHE")) {
            handleCache(in);
        }
    }

    private void handleCache(ByteArrayDataInput in) {
        UUID uuid = UUID.fromString(in.readUTF());
        String username = in.readUTF();
        double x = in.readDouble();
        double y = in.readDouble();
        double z = in.readDouble();
        float yaw = in.readFloat();
        float pitch = in.readFloat();
        String edge = in.readUTF();
        long timestamp = in.readLong();

        CachedPosition cached = new CachedPosition(x, y, z, yaw, pitch, edge, timestamp);
        positionCache.put(uuid, cached);

        getLogger().info("[NSW] Cached position for " + username + " at " + x + "," + y + "," + z + " (edge=" + edge + ")");
    }

    private void handlePong(Player player, ByteArrayDataInput in) {
        long timestamp = in.readLong();
        long latency = System.currentTimeMillis() - timestamp;

        double x = in.readDouble();
        double y = in.readDouble();
        double z = in.readDouble();
        float yaw = in.readFloat();
        float pitch = in.readFloat();
        String edge = in.readUTF();

        getLogger().info("[NSW] PONG received! Latency: " + latency + "ms (edge=" + edge + ")");

        if ((Math.abs(x) < 0.1 && Math.abs(z) < 0.1) || y == 0) {
            getLogger().warning("[NSW] Invalid PONG ignored");
            frozenPlayers.remove(player.getUniqueId());
            player.setAI(true);
            return;
        }

        double[] shifted = applyPositionShift(x, z, edge);
        x = shifted[0];
        z = shifted[1];

        Location loc = new Location(player.getWorld(), x, y, z);
        loc.setYaw(yaw);
        loc.setPitch(pitch);

        player.setVelocity(new Vector(0, 0, 0));
        player.teleport(loc);
        player.setAI(true);

        frozenPlayers.remove(player.getUniqueId());
        cooldown.put(player.getUniqueId(), System.currentTimeMillis());

        getLogger().info("[NSW] Teleported " + player.getName() + " to " + x + "," + y + "," + z);
    }

    private double[] applyPositionShift(double x, double z, String edge) {
        if (edge == null || edge.equals("NONE")) {
            return new double[] {x, z};
        }

        switch (edge.toUpperCase()) {
            case "EAST":
                x -= POSITION_SHIFT;
                break;
            case "WEST":
                x += POSITION_SHIFT;
                break;
            case "SOUTH":
                z -= POSITION_SHIFT;
                break;
            case "NORTH":
                z += POSITION_SHIFT;
                break;
        }

        return new double[] {x, z};
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Player player = e.getPlayer();
        UUID uuid = player.getUniqueId();

        CachedPosition cached = positionCache.remove(uuid);
        if (cached != null && !cached.isStale(CACHE_VALID_MS)) {
            getLogger().info("[NSW] Using cached position for " + player.getName() + " (edge=" + cached.getEdge() + ")");

            double x = cached.getX();
            double z = cached.getZ();
            double[] shifted = applyPositionShift(x, z, cached.getEdge());
            double shiftedX = shifted[0];
            double shiftedZ = shifted[1];

            Location loc = new Location(player.getWorld(), shiftedX, cached.getY(), shiftedZ);
            loc.setYaw(cached.getYaw());
            loc.setPitch(cached.getPitch());

            Bukkit.getScheduler().runTaskLater(this, () -> {
                player.setVelocity(new Vector(0, 0, 0));
                player.teleport(loc);
                cooldown.put(uuid, System.currentTimeMillis());
                getLogger().info("[NSW] Instant teleport via cache: " + shiftedX + "," + cached.getY() + "," + shiftedZ);
            }, 5L);

            return;
        }

        getLogger().info("[NSW] No valid cache, using PING/PONG for " + player.getName());

        frozenPlayers.add(uuid);
        player.setAI(false);

        Bukkit.getScheduler().runTaskLater(this, () -> {
            if (frozenPlayers.contains(uuid)) {
                frozenPlayers.remove(uuid);
                player.setAI(true);
                getLogger().warning("[NSW] PONG timeout - unfroze " + player.getName());
            }
        }, 100L);

        Bukkit.getScheduler().runTaskLater(this, () -> {