jakedacatman

Untitled

Jan 18th, 2020 (edited)
1,738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. local json = require "/json"
  2.  
  3. local monitor = peripheral.find("monitor", function (n, o) return o.isColor() end)
  4. if not monitor then error "add color monitor pls thanks" end
  5.  
  6. monitor.setTextScale(.5)
  7.  
  8. local oldTerm = term.current()
  9. term.redirect(monitor)
  10. term.clear()
  11. local size = {term.getSize()}
  12. local fields = { "player", "dimension", "x", "y", "z", "health" }
  13.  
  14. local function round(n)
  15. if n ~= nil then return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
  16. else return 0 end
  17. end
  18.  
  19. local function doRepeat(input, amount)
  20. local orig = input
  21. for i = 1, amount do
  22. input = input..orig
  23. end
  24. return input
  25. end
  26.  
  27. local function render(text, length)
  28. text = tostring(text)
  29.  
  30. local textLen = text:len()
  31.  
  32. if textLen == length then
  33. return text
  34. elseif textLen < length then
  35. return text..doRepeat(" ", length - textLen)
  36. end
  37. end
  38.  
  39. term.setCursorPos(1, 1)
  40. term.setBackgroundColor(colors.black)
  41. term.setTextColor(colors.white)
  42. local width = round(size[1] / #fields)
  43. for i = 1, #fields do
  44. term.write(render(fields[i], width))
  45. end
  46.  
  47. local function draw(data)
  48. for i = 2, size[2] do
  49. term.setBackgroundColor(colors.black)
  50. term.setCursorPos(1, i)
  51. term.write(doRepeat(" ", size[1]))
  52. end
  53. for i = 1, #data do
  54. term.setCursorPos(1, i + 1)
  55. local plr = data[i]
  56. if i % 2 == 1 then
  57. term.setBackgroundColor(colors.gray)
  58. term.setTextColor(colors.black)
  59. else
  60. term.setBackgroundColor(colors.black)
  61. term.setTextColor(colors.white)
  62. end
  63. term.write(render(plr.name, width))
  64. term.write(render(plr.world, width))
  65. term.write(render(round(plr.x), width))
  66. term.write(render(round(plr.y), width))
  67. term.write(render(round(plr.z), width))
  68. term.write(render(round(plr.health), width))
  69. term.setBackgroundColor(colors.black)
  70. end
  71. end
  72.  
  73. while true do
  74. local r = http.get("https://dynmap.switchcraft.pw/up/world/world/"..os.epoch "utc")
  75. local plrs = json.decode(r.readAll()).players
  76. r.close()
  77. draw(plrs)
  78. sleep(5)
  79. end
Add Comment
Please, Sign In to add comment