Repository navigation
bukkit: add GameMode.SPECTATOR for mods that provide the game type - #210
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Mods like Et Futurum Requiem backport spectator mode by registering a
GameTypewith id 3, and on plain Forge/gamemode 3and the F3+F4 switcher work. On Crucible they don't:/gamemodewith Bukkit'sGameModeCommand, which only knows survival/creative/adventure./gamemode 3and/gamemode spectatorsilently set the player to survival.GameMode.SPECTATORdirectly, so they fail withNoSuchFieldErroron Crucible.Player#getGameMode()returnsnull.Adding the constant at runtime with
EnumHelperis not enough: it updatesvalues()/valueOf(), but a plugin compiled withGameMode.SPECTATORreads a static field, and that only exists if the constant is declared in the class.Change
GameModegets a realSPECTATOR(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.getByIDfalls back to survival for unknown ids).CraftPlayer#setGameModerefuses an unavailable mode. The player keeps their current game mode, no event fires, and the console gets a warning that explains why./gamemodeacceptsspectator/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 againstspigot-api 1.12.2, and a headless 1.7.10 client in each scenario, starting from survival:GameMode.SPECTATOR/switchon itplayer.setGameMode(GameMode.SPECTATOR)gamemode spectator <player>/gamemode spConsole warning when no mod provides it:
Side effect:
GameMode.values()now always listsSPECTATOR, as on every 1.8+ server. Selecting it without a mod is refused as above.