Skip to content

Session policies

A SessionPolicy is a one-method function: given a ReconnectCtx, return a TargetLocation (or null for “don’t move them”). SessionPolicies is the core-module factory class for policies that don’t need arena code. Arena-aware variants — hub(), lobbyOfInstance(), gameOfInstance() — live in ArenaSessionPolicies.

  • You’re a command-driven mod with no arena dependency and want “rejoin where you left off”.
  • You want reconnecting players to land at the overworld respawn point by default.
  • You’re authoring your own custom policy and want to see the canonical shape.
package me.zlex.conduit.player;
@FunctionalInterface
public interface SessionPolicy {
@Nullable TargetLocation route(ReconnectCtx ctx);
}
public final class SessionPolicies {
public static SessionPolicy stayWherePlayerWas(); // returns null — vanilla rejoin
public static SessionPolicy overworldSpawn(); // route to overworld respawn point
}
public record TargetLocation(
ResourceKey<Level> dimension,
Vec3 pos,
float yaw,
float pitch,
@Nullable Consumer<ServerPlayer> postTeleport) {}
public record ReconnectCtx(
MinecraftServer server,
ServerPlayer player,
SessionRecord record) {}

Policies run on the server thread inside the join-event handler. Keep them cheap; defer heavy work to TargetLocation.postTeleport.

import me.zlex.conduit.player.PlayerSessionManager;
import me.zlex.conduit.player.SessionPolicies;
import me.zlex.conduit.player.SessionPolicy;
import me.zlex.conduit.player.TargetLocation;
import net.minecraft.world.phys.Vec3;
public final class BlockShuffleSessions {
/** Custom policy: route to the mod's overworld arena anchor. */
public static SessionPolicy arenaAnchor() {
return ctx -> {
var overworld = ctx.server().overworld();
return new TargetLocation(
overworld.dimension(),
new Vec3(128.5, 70, 128.5),
0f, 0f,
p -> p.heal(p.getMaxHealth()));
};
}
public static void register() {
// Command-driven mod: between rounds, just leave them wherever they were.
PlayerSessionManager.registerGame("my-game", SessionPolicies.stayWherePlayerWas());
// ...but in-game, snap them to the arena anchor.
PlayerSessionManager.setPhasePolicyOverride("my-game", "IN_GAME", arenaAnchor());
}
}
  • Returning null from a policy means “let vanilla put them wherever it would”.
  • postTeleport runs after SafeTeleport has fully relocated the player — use it for gamemode swaps, healing, inventory wipes.
  • A future expansion of overworldSpawn() may honour the player’s respawn config (bed / anchor); v1 only uses the world’s shared spawn.