Craftd:Events

Events
Events are the main way of acting with a craftd Server. Plugins work by registering to events and dispatching events.

An event callback has at least 1 parameter, which is the Server that the event was dispatched on, then other parameters are simply passed with some C magic. Remember to use only types that would work with a va_arg, this means use int/long even if a short/char is passed and use double instead of float, you can typecast them later, using smaller types would cause the data to be wrong. Pointers are always safe.

The event callback HAS to return true, if you return false the event chain is stopped, in this way your plugin can stop the chain of events.

You can also register to "Event.dispatch:before" and "Event.dispatch:after", these events are special events, and are called everytime an event is dispatched, other than the server a string parameter with the name of the event is passed, and a va_list. In this way you can inspect the event being called and abort it even before it's called, or act after an event as been called.

List of dispatched events
Remember that every event has as first parameter the Server, I won't list it in the event signatures because it is implied.


 * Event.dispatch:before (const char* event, va_list args): Called before every event is dispatched, if it returns false the event is stopped.
 * Event.dispatch:after (const char* event, va_list args): Called after every event is dispatched.


 * Player.connect (CDPlayer* player): Called when a client connects to the server, at this point it's added to the entities list but still hasn't an username
 * Player.login (CDPlayer* player, bool status): The client has tried to login, the status states if the login was succesful or not.
 * Player.process (CDPlayer* player, CDPacket* packet): Called when a Packet has been read from a Player and has been parsed.
 * Player.logout (CDPlayer* player, bool status): Called when a logged in Player disconnects.
 * Player.disconnect (CDPlayer* player, bool status): Called when a Player disconnect, status is true if the player disconnected on its own, false if disconnected because an error occurred.
 * Player.destroy (CDPlayer* player): Called when a Player object is destroyed


 * Mapgen.generateChunk (int x, int z, MCChunkData* data, CDString* seed): Callable to generate a chunk with the currently loaded map generator.