Events
This section describes the events that can be hooked through Context.Events.
Events
onTick
onChat
onDisconnected
onGameJoined
onSpawned
onWorldReload
onHealthUpdate
onDeath
onStartedStarving
onBlockChanged
onChunkLoaded
onPlayerMoved
onInventoryChanged
onSprintingChanged
onExplosion
onEntityEffectAdded
onObjectSpawned
onEntityVelocity
onPlayerUpdate
onExperienceChanged
onResourcePackReceived
onEntityAttached
Usage
You will generally be Registering tasks in the Start method of the task class. You will also generally want to unregister them in Stop method, otherwise the plugin may not stop execution.
/* We assume that this is in an ITask class and the
class is registered using 'RegisterTask' in the PluginCore class.
*/
public override async Task Start() {
Context.Events.onChat += OnChat;
}
public override async Task Stop() {
// The plugin has been stopped, therefore we should
// unregister all the events.
Context.Events.onChat -= OnChat;
}
private void OnChat(IBotContext context, IChat message, byte position) {
Console.WriteLine($"Bot '{context.Player.GetUsername()}' " +
$"received the message '{message.GetText()}'");
}
Events
onTick
Called each client tick, which is around 50ms. ITickListener uses this.
event IPlayerDelegates.PlayerDelegate onTick;
onChat
Called when the bot receives a chat message from the server. This also includes middle of the screen titles and above the hotbar messages. The type of message (chat, screen, above hotbar) can be determined by the position variable.
event IPlayerDelegates.OnChatDelegate onChat;
onDisconnected
Called once the bot is disconnected from the server.
event IPlayerDelegates.PlayerReasonDelegate onDisconnected;
onGameJoined
Called once the player joins the game. It is important to note that this will most likely run only if the plugin is enabled before the bot is started.
event IPlayerDelegates.OnGameJoinedDelegate onGameJoined;
onSpawned
Called once the player spawns into the game. This usually signifies that the bot's entity has been spawned by the server and is visible by other players.
event IPlayerDelegates.OnSpawnedDelegate onSpawned;
onHealthUpdate
Called once the bot's health or hunger is updated by the server. It is important to note that this is also for hunger changes as well, while the name suggest that it's only for health updates.
event IPlayerDelegates.OnHealthUpdateDelegate onHealthUpdate;
onDeath
Called when the bot's health drops to 0, which signifies that it has died.
event IPlayerDelegates.OnDeathDelegate onDeath;
onStartedStarving
Called when the bot starts starving, which is when it reaches 0 food.
event IPlayerDelegates.OnStartedStartvingDelegate onStartedStarving;
onBlockChange
Called once a block in the world changes.
event IPlayerDelegates.OnBlockChangedDelegate onBlockChanged;
onChunkLoaded
Called once a chunk is loaded/reloaded.
event IPlayerDelegates.OnBlockChangedDelegate onBlockChanged;
onPlayerMoved
Called once this bot is moved by the server. This will not be triggered when the bot moves it self.
event IPlayerDelegates.OnPlayerMovedDelegate onPlayerMoved;
onInventoryChanged
Called once an slot gets set or updated. This will also usually trigger when a new container is opened, as the server updates each slot of the container window.
event IPlayerDelegates.OnInventoryChangedDelegate onInventoryChanged;
onSprintChanged
Called once the bot's sprint state gets updated.
event IPlayerDelegates.OnPlayerSprintUpdateDelegate onSprintingChanged;
onWorldReload
Called once the world is fully reloaded, which is generally when respawning or teleporting.
event IPlayerDelegates.PlayerDelegate onWorldReload;
onEntityAttached
Called when the server sends an entity attached packet (e.g.: player sits in a minecart). Note: This is only supported for 1.8.*
event IPlayerDelegates.OnEntityAttached onEntityAttached;
OnResourcePackReceived
Called when the server sends a resource pack URL and hash to the client.
event IPlayerDelegates.OnResourcePackReceived onResourcePackReceived
onExperienceChanged
Called when the server updates the bot's experience
event IPlayerDelegates.OnExperienceChanged onExperienceChanged
onPlayerUpdate
Called before the player update, allows you to cancel all physics.
event IPlayerDelegates.OnPlayerUpdate onPlayerUpdate;
onEntityVelocity
Called once the server set's an entities velocity,
event IPlayerDelegates.OnEntityVelocity onEntityVelocity;
onObjectSpawned
Called once an object spawns.
event IPlayerDelegates.OnObjectSpawned onObjectSpawned;
onEntityEffectAdded
Called once an Entity receives an effect.
event IPlayerDelegates.OnEntityEffect onEntityEffectAdded;
onExplosion
Called once an explosion occurs.
event IPlayerDelegates.OnExplosionDelegate onExplosion;
Last updated