import { world } from '@minecraft/server';
import { ActionFormData, ModalFormData, MessageFormData } from '@minecraft/server-ui';
const world = server.world;

let players = world.getAllPlayers();

function newPlayer(player) {
    let lastTick = undefined
    world.events.tick.subscribe(tick => {
        if (!lastTick || tick.currentTick - lastTick >= 100) {
            if (player.isSneaking) {
                player.runCommandAsync("say foo")

                lastTick = tick.currentTick
            }
        }
    })
}

players.forEach(newPlayer)
world.events.playerJoin.subscribe(newPlayer)

const form = new ui.ModalFormData()
form.title("Renamer")
form.textField("Rename nametag", "New Name", "")

world.events.beforeItemUse.subscribe(result => {
    if (result.item.typeId == "minecraft:name_tag") {
        form.show(result.source).then(onFulfilled => {

        })
    }
})