// 目标切换事件
NativeEvents.onEvent($LivingChangeTargetEvent, event => {
    if (!event.getEntity().getLevel().isClientSide()) {
        let player = event.getNewTarget()
        if (player && player.isPlayer()) {
            let effects = get_armor_effects(player)
            effects.forEach(effect => {
                let effectname = effect.name
                if (!effectname) return
                // 查找对应的策略并执行
                let strategy = armor_target_change_strategies[effectname] || armor_target_change_strategies.default;
                strategy(event, player, effect.level, effectname, effect.efficiency);
            })
        }
    }
})
const armor_target_change_strategies = {
    // 遗忘者
    'forgotten': function (event, player, effectLevel, effectname, efficiency) {
        let time = player.persistentData.getInt(effectname) ?? 0
        let CD = Math.abs(player.age - time)
        if (CD < 20 * 60 * 2) return

        event.setCanceled(true);
    },
    'default': function (event, player, effectLevel, effectname, efficiency) {
        return;
    }
};