utility.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function serveressentials.get_short_stack_desc(stack)
  2. local def = minetest.registered_items[stack:get_name()]
  3. local meta = stack:get_meta()
  4. local description = meta:get_string("description")
  5. if description ~= "" then
  6. return utility.get_short_desc(description):trim()
  7. elseif def and def.description then
  8. return utility.get_short_desc(def.description):trim()
  9. end
  10. end
  11. -- Get the number of seconds until the next schedualed reset of the Outback.
  12. -- This is also used by the calendar item.
  13. function serveressentials.get_outback_timeout()
  14. local meta = serveressentials.modstorage
  15. local stime = meta:get_string("outback_reset_time")
  16. -- If timestamp is missing, then initialize it to the current time.
  17. if not stime or stime == "" then
  18. stime = tostring(os.time())
  19. meta:set_string("outback_reset_time", stime)
  20. end
  21. local time = tonumber(stime) -- Time of last reset (or initialization).
  22. local days = serveressentials.reset_timeout
  23. local timeout = 60 * 60 * 24 * days
  24. local now = os.time() -- Current time.
  25. local later = time + timeout -- Time of next reset.
  26. return (later - now)
  27. end
  28. function serveressentials.get_midfeld_timeout()
  29. local meta = serveressentials.modstorage
  30. local stime = meta:get_string("midfeld_reset_time")
  31. -- If timestamp is missing, then initialize it to the current time.
  32. if not stime or stime == "" then
  33. stime = tostring(os.time())
  34. meta:set_string("midfeld_reset_time", stime)
  35. end
  36. local time = tonumber(stime) -- Time of last reset (or initialization).
  37. local days = serveressentials.midfeld_reset_timeout
  38. local timeout = 60 * 60 * 24 * days
  39. local now = os.time() -- Current time.
  40. local later = time + timeout -- Time of next reset.
  41. return (later - now)
  42. end