Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local json = require "/json"
- local monitor = peripheral.find("monitor", function (n, o) return o.isColor() end)
- if not monitor then error "add color monitor pls thanks" end
- monitor.setTextScale(.5)
- local oldTerm = term.current()
- term.redirect(monitor)
- term.clear()
- local size = {term.getSize()}
- local fields = { "player", "dimension", "x", "y", "z", "health" }
- local function round(n)
- if n ~= nil then return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
- else return 0 end
- end
- local function doRepeat(input, amount)
- local orig = input
- for i = 1, amount do
- input = input..orig
- end
- return input
- end
- local function render(text, length)
- text = tostring(text)
- local textLen = text:len()
- if textLen == length then
- return text
- elseif textLen < length then
- return text..doRepeat(" ", length - textLen)
- end
- end
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- local width = round(size[1] / #fields)
- for i = 1, #fields do
- term.write(render(fields[i], width))
- end
- local function draw(data)
- for i = 2, size[2] do
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, i)
- term.write(doRepeat(" ", size[1]))
- end
- for i = 1, #data do
- term.setCursorPos(1, i + 1)
- local plr = data[i]
- if i % 2 == 1 then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.black)
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- term.write(render(plr.name, width))
- term.write(render(plr.world, width))
- term.write(render(round(plr.x), width))
- term.write(render(round(plr.y), width))
- term.write(render(round(plr.z), width))
- term.write(render(round(plr.health), width))
- term.setBackgroundColor(colors.black)
- end
- end
- while true do
- local r = http.get("https://dynmap.switchcraft.pw/up/world/world/"..os.epoch "utc")
- local plrs = json.decode(r.readAll()).players
- r.close()
- draw(plrs)
- sleep(5)
- end
Add Comment
Please, Sign In to add comment