> For the complete documentation index, see [llms.txt](https://docs.lukkit.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lukkit.net/events/examples.md).

# Examples

This method hooks into the `BlockBreakEvent` event and sends a message to the player who broke the block.

```lua
plugin.registerEvent("BlockBreakEvent", function(e)
    e:getPlayer():sendMessage("You broke a block")
end)
```

This next example allows the player to execute the command `/inspect` in order to be placed into a table. Once placed in this table, the player will not be able to break blocks and instead will receive information on the block that was broken. The same command can be run again to disable this feature.

```lua
-- Imports
material = import("$.Material")
color = newInstance("#.wrappers.ChatColorWrapper", {plugin.getPlugin()})

-- An inspect command with an event to tell what a block is
inspecters = {}

-- Add the command
local inspectCommand = plugin.addCommand({name="inspect"}, function(cmd)
    local sender = cmd.getSender()
    -- Make sure it's a player sending the command
    if not cmd.isPlayerSender() then
        sender:sendMessage(color.DARK_RED:toString() .. "Only players can run this command!")
        return
    end
    -- Go through every inspector and check if any equals this players uuid
    for k,v in pairs(inspecters) do
      if v == sender:getUniqueId() then
            -- Remove them from inspectors and tell them
            table.remove(inspecters, k)
            sender:sendMessage(color.YELLOW .. "You are no longer an inspector")
            return
        end
    end
    -- Else, add them and tell them
    table.insert(inspecters, sender:getUniqueId())
    sender:sendMessage(color.YELLOW .. "You are now an inspector")
end)

-- Add the event
plugin.registerEvent("BlockBreakEvent", function(e)
    -- Go through every inspector and check if any equals this players uuid
    for _,v in pairs(inspecters) do
      if v == e:getPlayer():getUniqueId() then
            -- Tell them the block
            e:getPlayer():sendMessage(color.AQUA .. "That is " .. color.GOLD .. e:getBlock():getType():name())
            e:setCancelled(true)
            break
      end
    end
end)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.lukkit.net/events/examples.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
