@@ -318,7 +318,7 @@ core.register_chatcommand("teleport", {
318
318
teleportee :setpos (p )
319
319
return true , " Teleporting to " .. core .pos_to_string (p )
320
320
end
321
-
321
+
322
322
local teleportee = nil
323
323
local p = nil
324
324
local target_name = nil
@@ -355,7 +355,7 @@ core.register_chatcommand("teleport", {
355
355
return true , " Teleporting " .. teleportee_name
356
356
.. " to " .. core .pos_to_string (p )
357
357
end
358
-
358
+
359
359
local teleportee = nil
360
360
local p = nil
361
361
local teleportee_name = nil
@@ -377,7 +377,7 @@ core.register_chatcommand("teleport", {
377
377
.. " to " .. target_name
378
378
.. " at " .. core .pos_to_string (p )
379
379
end
380
-
380
+
381
381
return false , ' Invalid parameters ("' .. param
382
382
.. ' ") or player not found (see /help teleport)'
383
383
end ,
@@ -679,19 +679,41 @@ core.register_chatcommand("status", {
679
679
})
680
680
681
681
core .register_chatcommand (" time" , {
682
- params = " <0...24000>" ,
682
+ params = " <0..23>:<0..59> | <0. .24000>" ,
683
683
description = " set time of day" ,
684
- privs = {settime = true },
684
+ privs = {},
685
685
func = function (name , param )
686
686
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 )
695
717
return true , " Time of day changed."
696
718
end ,
697
719
})
@@ -808,4 +830,4 @@ core.register_chatcommand("last-login", {
808
830
end
809
831
return false , " Last login time is unknown"
810
832
end ,
811
- })
833
+ })
0 commit comments