2021-03-27 14:27:22 +00:00
|
|
|
-- Licensed under the MIT license, written by appgurueu.
|
|
|
|
local players = {}
|
|
|
|
local blocks_per_second = 5
|
2021-03-28 19:45:49 +00:00
|
|
|
local resend_notification_seconds = 10
|
|
|
|
-- Bootstrap 4 "warning" color
|
|
|
|
local warning_color = 0xFFC107
|
2021-03-27 14:27:22 +00:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
-- player has to wait after join before they can place a node
|
|
|
|
players[player:get_player_name()] = {
|
2021-03-28 19:45:49 +00:00
|
|
|
last_notification_sent = -math.huge
|
2021-03-27 14:27:22 +00:00
|
|
|
}
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
players[player:get_player_name()] = nil
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_placenode(function(pos, _newnode, placer, oldnode, _itemstack, pointed_thing)
|
2021-03-28 19:45:49 +00:00
|
|
|
local name = placer:get_player_name()
|
2021-03-27 14:27:22 +00:00
|
|
|
if not ItemStack(minetest.get_node(pointed_thing.under).name):get_definition().pointable then
|
2021-03-28 19:45:49 +00:00
|
|
|
-- This should happen rarely
|
|
|
|
hud_event.new(name, {
|
|
|
|
name = "place_limit:unpointable",
|
|
|
|
color = warning_color,
|
|
|
|
value = "Block not pointable (dug/replaced)!",
|
|
|
|
})
|
2021-03-27 14:27:22 +00:00
|
|
|
minetest.set_node(pos, oldnode)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
local time = minetest.get_us_time()
|
2021-03-28 19:45:49 +00:00
|
|
|
local placements = players[name]
|
|
|
|
for i = #placements, 1, -1 do
|
|
|
|
if time - placements[i] > 1e6 then
|
|
|
|
placements[i] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #placements >= blocks_per_second then
|
|
|
|
if (time - placements.last_notification_sent) / 1e6 >= resend_notification_seconds then
|
|
|
|
hud_event.new(name, {
|
|
|
|
name = "place_limit:speed",
|
|
|
|
color = warning_color,
|
|
|
|
value = "Placing too fast!",
|
|
|
|
})
|
|
|
|
placements.last_notification_sent = time
|
2021-03-27 14:27:22 +00:00
|
|
|
end
|
|
|
|
minetest.set_node(pos, oldnode)
|
|
|
|
return true
|
|
|
|
end
|
2021-03-28 19:45:49 +00:00
|
|
|
table.insert(placements, 1, time)
|
2021-03-27 14:27:22 +00:00
|
|
|
end)
|