Lukkit
Search…
Examples
This method hooks into the BlockBreakEvent event and sends a message to the player who broke the block.
1
plugin.registerEvent("BlockBreakEvent", function(e)
2
e:getPlayer():sendMessage("You broke a block")
3
end)
Copied!
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.
1
-- Imports
2
material = import("$.Material")
3
color = newInstance("#.wrappers.ChatColorWrapper", {plugin.getPlugin()})
4
5
-- An inspect command with an event to tell what a block is
6
inspecters = {}
7
8
-- Add the command
9
local inspectCommand = plugin.addCommand({name="inspect"}, function(cmd)
10
local sender = cmd.getSender()
11
-- Make sure it's a player sending the command
12
if not cmd.isPlayerSender() then
13
sender:sendMessage(color.DARK_RED:toString() .. "Only players can run this command!")
14
return
15
end
16
-- Go through every inspector and check if any equals this players uuid
17
for k,v in pairs(inspecters) do
18
if v == sender:getUniqueId() then
19
-- Remove them from inspectors and tell them
20
table.remove(inspecters, k)
21
sender:sendMessage(color.YELLOW .. "You are no longer an inspector")
22
return
23
end
24
end
25
-- Else, add them and tell them
26
table.insert(inspecters, sender:getUniqueId())
27
sender:sendMessage(color.YELLOW .. "You are now an inspector")
28
end)
29
30
-- Add the event
31
plugin.registerEvent("BlockBreakEvent", function(e)
32
-- Go through every inspector and check if any equals this players uuid
33
for _,v in pairs(inspecters) do
34
if v == e:getPlayer():getUniqueId() then
35
-- Tell them the block
36
e:getPlayer():sendMessage(color.AQUA .. "That is " .. color.GOLD .. e:getBlock():getType():name())
37
e:setCancelled(true)
38
break
39
end
40
end
41
end)
Copied!
Last modified 3yr ago
Copy link