import { world } from '@minecraft/server';

class PlayerSetting {
    constructor(defaultValue, key) {
        this.defaultValue = defaultValue;
        this.key = key;
    }
    getValue(player) {
        const dynamicProperty = player.getDynamicProperty(this.key);
        if (dynamicProperty === undefined) {
            return this.defaultValue;
        }
        return dynamicProperty;
    }
    initDefault(player) {
        if (player.getDynamicPropertyIds().includes(this.key)) {
            return;
        }
        player.setDynamicProperty(this.key, this.defaultValue);
    }
    setValue(player, value) {
        player.setDynamicProperty(this.key, value);
    }
}
class WorldSetting {
    constructor(defaultValue, key) {
        this.defaultValue = defaultValue;
        this.key = key;
    }
    getValue() {
        const dynamicProperty = world.getDynamicProperty(this.key);
        if (dynamicProperty === undefined) {
            return this.defaultValue;
        }
        return dynamicProperty;
    }
    initDefault() {
        if (world.getDynamicPropertyIds().includes(this.key)) {
            return;
        }
        world.setDynamicProperty(this.key, this.defaultValue);
    }
    setValue(value) {
        world.setDynamicProperty(this.key, value);
    }
}

export { PlayerSetting, WorldSetting };
