import { World, Commands } from "mojang-minecraft"; //import in the world

let prefix = '!hide-name'; //prefix command
let prefix2 = '!show-name'; //prefix2 command

World.events.beforeChat.subscribe((test) => {
  let msg = test.message;
  
  if (msg.startsWith(prefix)) {

    test.cancel = true;
    Commands.run(`execute @a[name="${test.sender.nameTag}"] ~ ~ ~ event entity @a[name="${test.sender.nameTag}"] minecraft:remove_name`, World.getDimension("overworld"))
  }
  else if (msg.startsWith(prefix2)) {

    test.cancel = true;
    Commands.run(`execute @a[name="${test.sender.nameTag}"] ~ ~ ~ event entity @a[name="${test.sender.nameTag}"] minecraft:add_name`, World.getDimension("overworld"))
  }
});