Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d647eaa

Browse files
LymkwiShadowNinja
authored andcommittedMay 16, 2015
Added hour:minute format to time command
* The time command now accepts parameters in the form <hour>:<minute>, and if invoked with no parameters returns the current time in said format.
1 parent c297a75 commit d647eaa

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed
 

Diff for: ‎builtin/game/chatcommands.lua

+36-14
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ core.register_chatcommand("teleport", {
318318
teleportee:setpos(p)
319319
return true, "Teleporting to "..core.pos_to_string(p)
320320
end
321-
321+
322322
local teleportee = nil
323323
local p = nil
324324
local target_name = nil
@@ -355,7 +355,7 @@ core.register_chatcommand("teleport", {
355355
return true, "Teleporting " .. teleportee_name
356356
.. " to " .. core.pos_to_string(p)
357357
end
358-
358+
359359
local teleportee = nil
360360
local p = nil
361361
local teleportee_name = nil
@@ -377,7 +377,7 @@ core.register_chatcommand("teleport", {
377377
.. " to " .. target_name
378378
.. " at " .. core.pos_to_string(p)
379379
end
380-
380+
381381
return false, 'Invalid parameters ("' .. param
382382
.. '") or player not found (see /help teleport)'
383383
end,
@@ -679,19 +679,41 @@ core.register_chatcommand("status", {
679679
})
680680

681681
core.register_chatcommand("time", {
682-
params = "<0...24000>",
682+
params = "<0..23>:<0..59> | <0..24000>",
683683
description = "set time of day",
684-
privs = {settime=true},
684+
privs = {},
685685
func = function(name, param)
686686
if param == "" then
687-
return false, "Missing time."
688-
end
689-
local newtime = tonumber(param)
690-
if newtime == nil then
691-
return false, "Invalid time."
692-
end
693-
core.set_timeofday((newtime % 24000) / 24000)
694-
core.log("action", name .. " sets time " .. newtime)
687+
local current_time = math.floor(core.get_timeofday() * 1440)
688+
local minutes = current_time % 60
689+
local hour = (current_time - minutes) / 60
690+
return true, ("Current time is %2d:%02d"):format(hour , minutes)
691+
end
692+
local player_privs = minetest.get_player_privs(name)
693+
if not player_privs.settime then
694+
return false, "You don't have permission to run this command " ..
695+
"(missing privilege : settime)."
696+
end
697+
local hour, minutes = param:match("^(%d+):(%d+)$")
698+
if not hour then
699+
local new_time = tonumber(param)
700+
if not new_time then
701+
return false, "Invalid time."
702+
end
703+
-- Backward compatibility.
704+
core.set_timeofday((new_time % 24000) / 24000)
705+
core.log("action", name .. " sets time to " .. new_time)
706+
return true, "Time of day changed."
707+
end
708+
hour = tonumber(hour)
709+
minutes = tonumber(minutes)
710+
if hour < 0 or hour > 23 then
711+
return false, "Invalid hour (must be between 0 and 23 inclusive)."
712+
elseif minutes < 0 or minutes > 59 then
713+
return false, "Invalid minute (must be between 0 and 59 inclusive)."
714+
end
715+
core.set_timeofday((hour * 60 + minutes) / 1440)
716+
core.log("action", name .. " sets time to " .. hour .. ":" .. minutes)
695717
return true, "Time of day changed."
696718
end,
697719
})
@@ -808,4 +830,4 @@ core.register_chatcommand("last-login", {
808830
end
809831
return false, "Last login time is unknown"
810832
end,
811-
})
833+
})

0 commit comments

Comments
 (0)
Please sign in to comment.