#GameTest, JS: What's the best and easiest method for checking for the owner of the server?

1 messages · Page 1 of 1 (latest)

glass sonnet
#

i dont think there is a builtin way to get the owner of a realm

#

you could use dynamic properties and make it so when the first person that is an operator joins, it asks if you are the realm owner then saves their name to a dynamic property on the world and never asks again

#

made an example

import { Player, system, world } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";

async function showOwnerConfirmationForm(player: Player): Promise<void> {
    const form = new MessageFormData();
    form.title("Confirmation");
    form.body("Are you the owner of this realm?");
    form.button1("yes");
    form.button2("no");
    const result = await form.show(player);
    if (result.canceled) {
        system.runTimeout(() => showOwnerConfirmationForm(player), 20);
        return;
    }
    if (result.selection === 0) {
        world.setDynamicProperty("owner_name", player.name);
    }
}

world.afterEvents.playerSpawn.subscribe(async function (event) {
    if (world.getDynamicProperty("owner_name") !== undefined) return;
    if (!event.player.isOp()) return;
    showOwnerConfirmationForm(event.player);
});
#

it is possible that someone lies and they say that they are the owner before the actual owner joins for the first time