Event Descriptions

In the follow section you will learn when each event is called, how it might be useful and how it is used in the example plugin.

Event Order

The following image displays the order in which each event is called. Note that TimeChangeEvent is called throughout, however the variables that change are the state & time it is called with.

Event Flow Chart

Events & Breakdowns

Note: Events have a minimum of a 1 tick delay before firing the next event.

  • LobbyStartEvent

Lobby Start Event is the very first even that is called - it is called as the server finishes initialising (usually just after the world is loaded). In the example plugin, it is used to display the "Waiting for x player(s)" message. The event changes the GameState from null or GameState.RESTARTING to GameState.LOBBY. This could be useful to display a "now in lobby" message, or, send a BungeeCord plugin message to display the lobby status on another server's sign. Note: This is only thrown once: After the "Done!" message appears when the server loads up. You can call this event, it will set the time back to full and the gamestate to Lobby.

  • LobbyAttemptEndEvent

Lobby Attempt End Event must be listened for in order to start the game. This event is used to determine if the ingame is to be started or not. LobbyAttemptEndEvent.startGame() is the method that must be called in order to start the game. If this method is not called, a LobbyRestartEvent is called and the lobby restarts. In the example plugin, this is used to check if there is a player ingame. If no player is ingame, the lobby restarts, but if there is one or more the game begins. In, for example, a Survival Games plugin this would be used to check if there are 12 players in the server, ready to play.

  • LobbyRestartEvent

Lobby Restart Event is called every time the lobby, as the name states, restarts. The event is called only if LobbyAttemptEndEvent.startGame() is not called. In the example plugin, this is used to display the "Lobby restarted!" message. The main uses of this would to notify players that the lobby has restarted, to tell the players how many more players are needed, etc. Note: After this event, LobbyStartEvent is NOT called.

  • LobbyEndEvent

LobbyEndEvent is called once the lobby has ended, and the ingame state is set to begin. This is called ONLY if LobbyAttemptEndEvent.startGame() is called. This is not used in the example plugin. The main uses of this event would be to teleport players into the arena, or initialise/setup anything needed.

  • IngameCountdownStartEvent

Ingame Countdown Start Event (what a mouthful!) is called directly after LobbyEndEvent, and changes the GameState from GameState.LOBBY to GameState.INGAME_COUNTDOWN. This is used to in the example plugin to for the "The first person to break a piece of wood wins!" message, give the players resistance, heal them, and teleport them. Primary uses for this would be to teleport players to the correct areas, send them messages, give starting loot, organise teams, send BungeeCord plugin messages to another server's sign to update the game status, etc.

  • IngameCountdownEndEvent

Ingame Countdown End Event is called as soon as the Countdown timer reaches zero. The example plugin uses this event to display a "Good luck!" message. Primary uses would be to remove barriers allowing players to move, fill chests/place loot, etc.

  • IngameStartEvent

Ingame Start Event is called directly after IngameCountdownEndEvent. This event changes the GameState from GameState.INGAME_COUNTDOWN to GameState.INGAME. The example plugin does not use this event. A typical use of this event would be to announce the game has begun.

  • IngameEndEvent

Ingame End Event is called once the ingame timer reaches zero. This is critical for ending the ingame phase! You can throw this event if the game ends prematurely! Call this event like you would any other, and the ingame will end and restarting will begin. The example plugin uses this to announce the winner. The primary uses of this would be to display who won, add the necessary points for victory/participation, etc.

  • RestartingStartEvent

Restarting Start Event is called directly after IngameEndEvent. This event changes the GameState from GameState.INGAME to GameState.RESTARTING. This event is used in the example plugin to clear players inventories, set them to Creative.

  • RestartEvent

Restart Event is the final event called before the plugin is, in essence, restarted. It is called when the restarting timer reaches zero. The plugin will not literally restart, but the GameState is set back from GameState.RESTARTING to GameState.LOBBY. The timer is also set to the specified length determined in the config.yml. A typical use of this event would be to send players back to the lobby, display a restarting message, etc.

  • TimeChangeEvent

This is the most critical event called by the plugin. This event is called every 20 game ticks (appx. 1/second) . As stated above, this is called all throughout the game. The methods attached to this are TimeChangeEvent.getTime() which returns the current seconds left in the timer, and TimeChangeEvent.getState(), which returns the current GameState. The example plugin uses this to display the "x seconds left" messages. A typical use of this would be to send time updates, messages, alerts, etc.


Comments

Posts Quoted:
Reply
Clear All Quotes