diff options
author | number Zero <silverunicorn2011@yandex.ru> | 2016-07-08 22:59:51 +0300 |
---|---|---|
committer | Jeija <norrepli@gmail.com> | 2016-07-09 11:01:27 +0200 |
commit | f9f7600017967672ec28ecf139d9d520d64fcef0 (patch) | |
tree | b71b54e7b09bafd008a5f59ec0cda63c5a659ed1 | |
parent | 40487a65f47cd42595417ab434a9b5a97a496a3e (diff) | |
download | mesecons-f9f7600017967672ec28ecf139d9d520d64fcef0.tar mesecons-f9f7600017967672ec28ecf139d9d520d64fcef0.tar.gz mesecons-f9f7600017967672ec28ecf139d9d520d64fcef0.tar.bz2 mesecons-f9f7600017967672ec28ecf139d9d520d64fcef0.tar.xz mesecons-f9f7600017967672ec28ecf139d9d520d64fcef0.zip |
Command block server crash fixed
Before that, command block would crash the server if activated when no
players are online
-rw-r--r-- | mesecons_commandblock/init.lua | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/mesecons_commandblock/init.lua b/mesecons_commandblock/init.lua index b1a0c6f..6cd0027 100644 --- a/mesecons_commandblock/init.lua +++ b/mesecons_commandblock/init.lua @@ -93,9 +93,22 @@ local function receive_fields(pos, formname, fields, sender) end local function resolve_commands(commands, pos) + local players = minetest.get_connected_players() + + -- No players online: remove all commands containing + -- @nearest, @farthest and @random + if #players == 0 then + commands = commands:gsub("[^\r\n]+", function (line) + if line:find("@nearest") then return "" end + if line:find("@farthest") then return "" end + if line:find("@random") then return "" end + return line + end) + return commands + end + local nearest, farthest = nil, nil local min_distance, max_distance = math.huge, -1 - local players = minetest.get_connected_players() for index, player in pairs(players) do local distance = vector.distance(pos, player:getpos()) if distance < min_distance then |