Comment on page
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 |
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()}'");
}
Called each client tick, which is around 50ms. ITickListener uses this.
event IPlayerDelegates.PlayerDelegate onTick;
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;
Called once the bot is disconnected from the server.
event IPlayerDelegates.PlayerReasonDelegate onDisconnected;
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;
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;
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;
Called when the bot's health drops to 0, which signifies that it has died.
event IPlayerDelegates.OnDeathDelegate onDeath;
Called when the bot starts starving, which is when it reaches 0 food.
event IPlayerDelegates.OnStartedStartvingDelegate onStartedStarving;
Called once a block in the world changes.
event IPlayerDelegates.OnBlockChangedDelegate onBlockChanged;
Called once a chunk is loaded/reloaded.
event IPlayerDelegates.OnBlockChangedDelegate onBlockChanged;
Called once this bot is moved by the server. This will not be triggered when the bot moves it self.
event IPlayerDelegates.OnPlayerMovedDelegate onPlayerMoved;
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;
Called once the bot's sprint state gets updated.
event IPlayerDelegates.OnPlayerSprintUpdateDelegate onSprintingChanged;
Called once the world is fully reloaded, which is generally when respawning or teleporting.
event IPlayerDelegates.PlayerDelegate onWorldReload;
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;
Called when the server sends a resource pack URL and hash to the client.
event IPlayerDelegates.OnResourcePackReceived onResourcePackReceived
Called when the server updates the bot's experience
event IPlayerDelegates.OnExperienceChanged onExperienceChanged
Called before the player update, allows you to cancel all physics.
event IPlayerDelegates.OnPlayerUpdate onPlayerUpdate;
Called once the server set's an entities velocity,
event IPlayerDelegates.OnEntityVelocity onEntityVelocity;
Called once an object spawns.
event IPlayerDelegates.OnObjectSpawned onObjectSpawned;
Called once an Entity receives an effect.
event IPlayerDelegates.OnEntityEffect onEntityEffectAdded;
Called once an explosion occurs.
event IPlayerDelegates.OnExplosionDelegate onExplosion;
Last modified 4yr ago