local s = peripheral.wrap("top")

local whitelist = {"oddstr13", "lordgt55", "thosaa955"}

local function checkOpen()
  local open = false

  for _,v in pairs(s.getPlayerNames()) do
    for _,p in pairs(whitelist) do
      if v == p then
        local player = s.getPlayerData(v)
        if player then
          local x = player.position.x
          local z = player.position.z
          if -2 > x and x > -3 then
            if -0.31 < z and z < 1.31 then
              print(p, ": ", x, ",", z)
              open = true
            end
          end
        end
      end
    end
  end
  
  rs.setOutput("right", not open)
end

while true do
  checkOpen()
  sleep(0.05)
end
