const NetworkEvents = Java.loadClass("dev.latvian.kubejs.network.NetworkEvents")

const holdingPlayers = new java.util.HashSet()

NetworkEvents.receive(event => {
  if (event.getName() !== "ninjago:key_event") return

  const player = event.getPlayer()
  const action = event.getData().getString("action")

  if (action === "down") holdingPlayers.add(player)
  else if (action === "up") {
    holdingPlayers.remove(player)
    Server.runCommand(`/function ninjago:key_up`)
  }
})

ServerEvents.tick(event => {
  for (const player of holdingPlayers) {
    Server.runCommand(`/function ninjago:key_down`)
  }
})
