Spectator manager
SpectatorManager puts a player into a custom “spectator” state: adventure gamemode, creative flight, invisibility, and zero damage. Spectators see each other through a scoreboard team that has seeFriendlyInvisibles=true and collisionRule=NEVER, so they don’t block each other but stay visible to each other. The previous gamemode is remembered so release puts them back.
When to use it
Section titled “When to use it”- A player gets eliminated and you want them to keep watching the round.
- You want non-spectator players to ignore eliminated ones entirely (no collision, invisible).
- You want spectator abilities to survive a disconnect and re-apply on reconnect.
package me.zlex.conduit.spectator;
public final class SpectatorManager { public static final String TEAM_NAME = "conduit-spectators";
public static void init(); // call once from your ModInitializer
public static void makeSpectator(ServerPlayer player); public static void release(ServerPlayer player);
public static boolean isSpectating(UUID id); public static Set<UUID> getActiveSpectators();}State is in-memory only — if the server restarts mid-round, mods own the responsibility of re-promoting the right players.
Example
Section titled “Example”import me.zlex.conduit.spectator.SpectatorManager;import net.minecraft.server.level.ServerPlayer;
public final class MyElimination {
public static void eliminate(ServerPlayer p) { SpectatorManager.makeSpectator(p); p.sendSystemMessage(net.minecraft.network.chat.Component.literal( "You were eliminated. You'll spectate the rest of the round.")); }
public static void roundEnded(Collection<ServerPlayer> all) { for (ServerPlayer p : all) { if (SpectatorManager.isSpectating(p.getUUID())) { SpectatorManager.release(p); } } }}- Damage cancellation goes through Fabric’s
ALLOW_DAMAGEevent — spectators take zero damage from any source. - The
conduit-spectatorsscoreboard team is created at server start. Don’t reuse the team name for anything else. - Rejoining a spectating player re-pushes ability flags so client and server agree — gamemode and team membership persist through vanilla mechanisms.