Skip to content

bukkit: add GameMode.SPECTATOR for mods that provide the game type - #210

Merged
EverNife merged 1 commit into
CrucibleMC:stagingfrom
EverNife:fix/spectator-gamemode
Oct 13, 2026
Merged

EverNife merged 1 commit into
CrucibleMC:stagingfrom
EverNife:fix/spectator-gamemode

Conversation

@EverNife

Copy link
Copy Markdown
Member

Problem

Mods like Et Futurum Requiem backport spectator mode by registering a GameType with id 3, and on plain Forge /gamemode 3 and the F3+F4 switcher work. On Crucible they don't:

  • Crucible replaces vanilla /gamemode with Bukkit's GameModeCommand, which only knows survival/creative/adventure. /gamemode 3 and /gamemode spectator silently set the player to survival.
  • Plugins built against 1.8+ APIs reference GameMode.SPECTATOR directly, so they fail with NoSuchFieldError on Crucible.
  • If a mod puts a player in spectator by other means, Player#getGameMode() returns null.

Adding the constant at runtime with EnumHelper is not enough: it updates values()/valueOf(), but a plugin compiled with GameMode.SPECTATOR reads a static field, and that only exists if the constant is declared in the class.

Change

  • GameMode gets a real SPECTATOR(3) constant, so newer plugins link on every Crucible server.
  • CraftPlayer.isGameModeAvailable(GameMode) checks whether the server has a game type for the mode (GameType.getByID falls back to survival for unknown ids).
  • CraftPlayer#setGameMode refuses an unavailable mode. The player keeps their current game mode, no event fires, and the console gets a warning that explains why.
  • /gamemode accepts spectator/sp (and tab-completes it). When the mode is unavailable, it tells the sender so and suggests a mod that adds it.

Nothing is tied to a specific mod: any mod that registers game type 3 makes spectator available.

Testing

Crucible built from this branch (buildPackages, JDK 8), a probe plugin compiled against spigot-api 1.12.2, and a headless 1.7.10 client in each scenario, starting from survival:

Scenario Without a spectator mod With Et Futurum Requiem (master)
Plugin reads GameMode.SPECTATOR / switch on it OK OK
player.setGameMode(GameMode.SPECTATOR) stays SURVIVAL, console warning SPECTATOR on server and client
Console gamemode spectator <player> stays SURVIVAL, red message to sender SPECTATOR
Player runs /gamemode sp stays SURVIVAL, red message in player chat SPECTATOR

Console warning when no mod provides it:

Game mode of VanBot left unchanged at SURVIVAL: SPECTATOR is not available because no installed mod adds that game type. Install one that does, or pick another mode.

Side effect: GameMode.values() now always lists SPECTATOR, as on every 1.8+ server. Selecting it without a mod is refused as above.

Plugins built against 1.8+ APIs read GameMode.SPECTATOR directly. Tested
with Et Futurum Requiem; without such a mod the mode is refused and the
player keeps their current game mode.
@EverNife
EverNife merged commit 659427c into CrucibleMC:staging Oct 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant