From c59b9009cd87ba4100887a772150fe9b754afa99 Mon Sep 17 00:00:00 2001 From: Maksim Date: Thu, 16 Apr 2020 21:00:57 +0200 Subject: [PATCH] Builtin: minor cleanup --- builtin/common/async_event.lua | 2 +- builtin/game/auth.lua | 2 +- builtin/game/chat.lua | 12 ++++++------ builtin/game/falling.lua | 4 ++-- builtin/game/hud.lua | 7 +++---- builtin/game/weather.lua | 14 ++++++++------ builtin/mainmenu/dlg_config_world.lua | 3 +-- builtin/mainmenu/dlg_create_world.lua | 1 - 8 files changed, 22 insertions(+), 23 deletions(-) diff --git a/builtin/common/async_event.lua b/builtin/common/async_event.lua index f2a70c46..8b92f82f 100644 --- a/builtin/common/async_event.lua +++ b/builtin/common/async_event.lua @@ -8,7 +8,7 @@ local function handle_job(jobid, serialized_retval) end if core.register_globalstep then - core.register_globalstep(function(dtime) + core.register_globalstep(function() for _, job in ipairs(core.get_finished_jobs()) do handle_job(job.jobid, job.retval) end diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index d6a0004d..081f9d9d 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -162,7 +162,7 @@ core.builtin_auth_handler = { end, } -core.register_on_prejoinplayer(function(name, ip) +core.register_on_prejoinplayer(function(name) if core.registered_auth_handler ~= nil then return -- Don't do anything if custom auth handler registered end diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua index 6727b70d..d67339b1 100644 --- a/builtin/game/chat.lua +++ b/builtin/game/chat.lua @@ -90,7 +90,7 @@ core.register_chatcommand("me", { core.register_chatcommand("admin", { description = "Show the name of the server owner", - func = function(name) + func = function() local admin = core.settings:get("name") if admin then return true, "The administrator of this server is " .. admin .. "." @@ -119,7 +119,7 @@ core.register_chatcommand("haspriv", { params = "", description = "Return list of all online players with privilege.", privs = {basic_privs = true}, - func = function(caller, param) + func = function(_, param) param = param:trim() if param == "" then return false, "Invalid parameters (see /help haspriv)" @@ -322,7 +322,7 @@ core.register_chatcommand("clearpassword", { core.register_chatcommand("auth_reload", { description = "Reload authentication data", privs = {server = true}, - func = function(name, param) + func = function() local done = core.auth_reload() return done, (done and "Done." or "Failed.") end @@ -356,7 +356,7 @@ core.register_chatcommand("remove_player", { core.register_chatcommand("auth_save", { description = "Write authentication data to disk", privs = {server = true}, - func = function(name, param) + func = function() local done = core.auth_save() return done, (done and "Authentication data successfully saved to disk." or "Failed to write the auth.txt file.") end @@ -472,7 +472,7 @@ core.register_chatcommand("set", { params = "([-n] ) | ", description = "Set or read server configuration setting", privs = {server = true}, - func = function(name, param) + func = function(_, param) local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)") if arg and arg == "-n" and setname and setvalue then core.settings:set(setname, setvalue) @@ -885,7 +885,7 @@ register_chatcommand_alias("settime", "time") core.register_chatcommand("days", { description = "Show day count since world creation", - func = function(name, param) + func = function() return true, "Current day is " .. core.get_day_count() end }) diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 794c5641..fda0a69b 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -286,8 +286,8 @@ function core.check_single_for_falling(p) local nc = core.get_node(pa) if core.get_item_group(nc.name, "attached_node2") ~= 0 then local connected - for i = 1, 4 do - local ptwo = vadd(pa, check_connected[i]) + for j = 1, 4 do + local ptwo = vadd(pa, check_connected[j]) local ntwo = core.get_node(ptwo) if core.registered_nodes[ntwo.name].walkable then connected = true diff --git a/builtin/game/hud.lua b/builtin/game/hud.lua index e3b79c32..c532c77a 100644 --- a/builtin/game/hud.lua +++ b/builtin/game/hud.lua @@ -115,7 +115,6 @@ function hud.remove_item(player, name) local elem = hud_id[i_name] - local i_name = player:get_player_name() .. "_" .. name if not elem then throw_error("Given HUD element " .. dump(name) .. " does not exist") return false @@ -155,11 +154,11 @@ core.register_on_joinplayer(function(player) end) core.register_on_leaveplayer(function(player) - local player = player:get_player_name() + local player_name = player:get_player_name() for name, _ in pairs(sb_bg) do - sb_bg[player .. "_" .. name] = nil + sb_bg[player_name .. "_" .. name] = nil end for name, _ in pairs(items) do - hud_id[player .. "_" .. name] = nil + hud_id[player_name .. "_" .. name] = nil end end) diff --git a/builtin/game/weather.lua b/builtin/game/weather.lua index c1fe42c7..853a40b2 100644 --- a/builtin/game/weather.lua +++ b/builtin/game/weather.lua @@ -35,12 +35,14 @@ weather = { } local file_name = core.get_worldpath() .. "/weather" -local file = io.open(file_name, "r") -if file ~= nil then - local saved_weather = core.deserialize(file:read("*a")) - io.close(file) - if type(saved_weather) == "table" then - weather = saved_weather +do + local file = io.open(file_name, "r") + if file ~= nil then + local saved_weather = core.deserialize(file:read("*a")) + io.close(file) + if type(saved_weather) == "table" then + weather = saved_weather + end end end diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 9fd6bb2a..6fdb72e2 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -159,7 +159,6 @@ local function handle_buttons(this, fields) local rawlist = this.data.list:get_raw_list() - local i,mod for _, mod in ipairs(rawlist) do if not mod.is_modpack and not mod.is_game_content then @@ -266,7 +265,7 @@ function create_configure_world_dlg(worldidx) return true end, { - worldpat h= dlg.data.worldspec.path, + worldpath = dlg.data.worldspec.path, gameid = dlg.data.worldspec.gameid } ) diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua index a04c9ce6..128f7072 100644 --- a/builtin/mainmenu/dlg_create_world.lua +++ b/builtin/mainmenu/dlg_create_world.lua @@ -20,7 +20,6 @@ local function create_world_formspec() local current_seed = core.formspec_escape(core.settings:get("fixed_map_seed")) or "" local current_mg = core.settings:get("mg_name") - local gameid = core.settings:get("menu_last_game") local mglist = "" local selindex = 1