1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/map_gen/Diggy/Feature/Antigrief.lua

58 lines
1.7 KiB
Lua
Raw Normal View History

-- dependencies
local Event = require 'utils.event'
local Global = require 'utils.global'
local CaveCollapse = require 'map_gen.Diggy.Feature.DiggyCaveCollapse'
local Game = require 'utils.game'
local Report = require 'features.report'
local format = string.format
-- this
local Antigrief = {}
2018-11-26 14:06:30 +02:00
local global_primitives = {}
local allowed_collapses_first_hour = 0
local player_collapses = {}
2018-11-26 14:06:30 +02:00
local jailed_players = {}
Global.register({
2018-11-26 14:06:30 +02:00
player_collapses = player_collapses,
jailed_players = jailed_players,
2018-11-27 01:48:51 +02:00
global_primitives = global_primitives,
}, function(tbl)
2018-11-26 14:06:30 +02:00
player_collapses = tbl.player_collapses
jailed_players = tbl.jailed_players
2018-11-27 01:48:51 +02:00
global_primitives = tbl.global_primitives
end)
2018-11-26 14:06:30 +02:00
global_primitives.autojail = false
global_primitives.last_collapse = 0
--[[--
Registers all event handlers.
]]
function Antigrief.register(config)
2018-11-26 14:06:30 +02:00
global_primitives.autojail = config.autojail
allowed_collapses_first_hour = config.allowed_collapses_first_hour
end
Event.add(CaveCollapse.events.on_collapse, function(event)
local player_index = event.player_index
2018-11-26 14:06:30 +02:00
if player_index and global_primitives.last_collapse ~= game.tick then
global_primitives.last_collapse = game.tick
local count = player_collapses[player_index] or 0
count = count + 1
player_collapses[player_index] = count
local player = Game.get_player_by_index(player_index)
2018-11-26 14:06:30 +02:00
if global_primitives.autojail and count > allowed_collapses_first_hour and player.online_time < 216000 and not jailed_players[player_index] then
Report.jail(player)
Report.report(nil, player, format('Caused %d collapses in the first hour', count))
2018-11-26 14:06:30 +02:00
jailed_players[player_index] = true
end
end
end)
return Antigrief