diff --git a/src/lib/clan/command.ts b/src/lib/clan/command.ts index 00193bd9..54f80a66 100644 --- a/src/lib/clan/command.ts +++ b/src/lib/clan/command.ts @@ -1,3 +1,6 @@ import { clanMenu } from './menu' -new Command('clan').setDescription('Клан').executes(ctx => clanMenu(ctx.player)[1]()) +new Command('clan') + .setDescription('Клан') + .setPermissions('member') + .executes(ctx => clanMenu(ctx.player)[1]()) diff --git a/src/lib/portals.ts b/src/lib/portals.ts index 97376eb6..f88fdc52 100644 --- a/src/lib/portals.ts +++ b/src/lib/portals.ts @@ -101,6 +101,7 @@ export class Portal { } teleport(player: Player) { + if (LockAction.locked(player, { tell: true })) return if (this.place) Portal.teleport(player, this.place) } } diff --git a/src/lib/sidebar.ts b/src/lib/sidebar.ts index c951a130..c5355c26 100644 --- a/src/lib/sidebar.ts +++ b/src/lib/sidebar.ts @@ -1,5 +1,6 @@ import { Player } from '@minecraft/server' import { util } from 'lib/util' +import { HealthIndicatorConfig } from 'modules/indicator/config' import { WeakPlayerSet } from './weak-player-storage' type Format = @@ -96,7 +97,7 @@ export class Sidebar { for (const [i, tip] of content.entries()) { if (i === 2) { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - player.onScreenDisplay.setActionBar(tip || '') + if (!HealthIndicatorConfig.lockDisplay.has(player)) player.onScreenDisplay.setActionBar(tip || '') } else { player.onScreenDisplay.setTip((i + 1) as 1 | 2 | 3 | 4 | 5, Sidebar.wrap(tip ?? '', options.maxWordCount)) } diff --git a/src/modules/indicator/health.ts b/src/modules/indicator/health.ts index 163a0539..963ed925 100644 --- a/src/modules/indicator/health.ts +++ b/src/modules/indicator/health.ts @@ -165,6 +165,7 @@ class HealthIndicator { private createHurtEntityRecord(entity: Entity) { let info = this.hurtEntities.get(entity.id) + console.log('INfo', { info }) if (!info) { const separated = !this.alwaysShows.includes(entity.typeId) const base = { diff --git a/src/modules/indicator/index.ts b/src/modules/indicator/index.ts index 227e4a19..bcba0a33 100644 --- a/src/modules/indicator/index.ts +++ b/src/modules/indicator/index.ts @@ -1,3 +1,3 @@ import './health' -// import "./pvp"; +import './pvp' import './test-damage' diff --git a/src/modules/indicator/player-name-tag.ts b/src/modules/indicator/player-name-tag.ts index db36cdff..9381c5c5 100644 --- a/src/modules/indicator/player-name-tag.ts +++ b/src/modules/indicator/player-name-tag.ts @@ -1,10 +1,9 @@ import { Entity, Player, system } from '@minecraft/server' -// import { isBuilding } from 'lib' -// import { getFullname } from 'lib/get-fullname' +import { isBuilding } from 'lib' +import { getFullname } from 'lib/get-fullname' export const PlayerNameTagModifiers: ((player: Player) => string | false)[] = [ - player => player.name, - // player => '\n' + getFullname(player, { role: isBuilding(player), name: false }), + player => getFullname(player, { role: isBuilding(player) }), ] system.runPlayerInterval(player => setNameTag(player, ''), 'player.nameTag modifiers', 40) diff --git a/src/modules/indicator/pvp.ts b/src/modules/indicator/pvp.ts index 5159c4e7..bdd0ed75 100644 --- a/src/modules/indicator/pvp.ts +++ b/src/modules/indicator/pvp.ts @@ -1,5 +1,5 @@ import { EntityDamageCause, EntityHurtAfterEvent, Player, system, world } from '@minecraft/server' -import { Settings } from 'lib' +import { LockAction, Settings } from 'lib' import { Core } from 'lib/extensions/core' import { HealthIndicatorConfig } from './config' @@ -8,12 +8,12 @@ import { HealthIndicatorConfig } from './config' const { lockDisplay } = HealthIndicatorConfig const options = Settings.world(...Settings.worldCommon, { - enabled: { + pvpEnabled: { value: true, description: 'Возможность входа в пвп режим (блокировка всех тп команд)§r', name: 'Включено', }, - cooldown: { value: 15, description: 'Время блокировки в секундах', name: 'Время' }, + pvpCooldown: { value: 15, description: 'Время блокировки в секундах', name: 'Время' }, }) const getPlayerSettings = Settings.player('PvP/PvE', 'pvp', { @@ -29,13 +29,13 @@ const getPlayerSettings = Settings.player('PvP/PvE', 'pvp', { }, }) +const pvpLockAction = new LockAction(p => p.scores.pvp > 0, 'Вы находитесь в режиме пвп') + system.runInterval( () => { - if (options.enabled) { - for (const player of world.getPlayers({ - scoreOptions: [{ objective: 'pvp' }], - })) { - player.scores.pvp-- + if (options.pvpEnabled) { + for (const player of world.getAllPlayers()) { + if (player.scores.pvp) player.scores.pvp-- } for (const [key, value] of lockDisplay.entries()) { @@ -51,18 +51,18 @@ system.runInterval( Core.afterEvents.worldLoad.subscribe(() => { system.runPlayerInterval( player => { - if (!options.enabled) return + if (!options.pvpEnabled) return const score = player.scores.pvp - if (HealthIndicatorConfig.disabled.includes(player.id) || score < 0) return + if (HealthIndicatorConfig.disabled.includes(player.id) || score <= 0) return const settings = getPlayerSettings(player) if (!settings.indicator) return - const q = score === options.cooldown || score === 0 + const q = score === options.pvpCooldown || score === 0 const g = (p: string) => (q ? `§4${p}` : '') - if (!lockDisplay.has(player.id)) player.onScreenDisplay.setActionBar(`${g('»')} §6PvP: ${score} ${g('«')}`) + player.onScreenDisplay.setActionBar(`${g('»')} §6PvP: ${score} ${g('«')}`) }, 'PVP player', 0, @@ -98,21 +98,20 @@ function onDamage(event: EntityHurtAfterEvent, fatal = false) { if ( !event.hurtEntity.typeId.startsWith('minecraft:') || - !options.enabled || + !options.pvpEnabled || HealthIndicatorConfig.disabled.includes(event.hurtEntity.id) ) return // Its player.chatClose - if (!damage.damagingEntity && event.hurtEntity instanceof Player && damage.cause === EntityDamageCause.entityAttack) - return + if (!damage.damagingEntity && event.hurtEntity.isPlayer() && damage.cause === EntityDamageCause.entityAttack) return const healthComponent = event.hurtEntity.getComponent('minecraft:health') if (!healthComponent) return const { currentValue: current, defaultValue: value } = healthComponent - if (damage.damagingEntity instanceof Player) { - damage.damagingEntity.scores.pvp = options.cooldown + if (damage.damagingEntity?.isPlayer()) { + damage.damagingEntity.scores.pvp = options.pvpCooldown damage.damagingEntity.scores.damageGive += event.damage if (fatal) damage.damagingEntity.scores.kills++ @@ -123,34 +122,31 @@ function onDamage(event: EntityHurtAfterEvent, fatal = false) { playHitSound(damage.damagingEntity, current, value) } - if (setting.indicator && fatal) { - // remove fatal ^ and uncomment code \/ - // if (!fatal) { - // damage.damagingEntity.onScreenDisplay.setActionBar( - // `§c-${data.damage}♥` - // ); - // } else { - // Kill - if (event.hurtEntity instanceof Player) { - // Player - damage.damagingEntity.onScreenDisplay.setActionBar( - `§gВы ${isBow ? 'застрелили' : 'убили'} §6${event.hurtEntity.name}`, - ) + if (setting.indicator) { + if (!fatal) { + // damage.damagingEntity.onScreenDisplay.setActionBar(`§c-${event.damage}♥`) } else { - // Entity - - const entityName = event.hurtEntity.typeId.replace('minecraft:', '') - damage.damagingEntity.onScreenDisplay.setActionBar({ - rawtext: [ - { text: '§6' }, - { - translate: `entity.${entityName}.name`, - }, - { text: isBow ? ' §gзастрелен' : ' §gубит' }, - ], - }) + // Kill + if (event.hurtEntity instanceof Player) { + // Player + damage.damagingEntity.onScreenDisplay.setActionBar( + `§gВы ${isBow ? 'застрелили' : 'убили'} §6${event.hurtEntity.name}`, + ) + } else { + // Entity + + const entityName = event.hurtEntity.typeId.replace('minecraft:', '') + damage.damagingEntity.onScreenDisplay.setActionBar({ + rawtext: [ + { text: '§6' }, + { + translate: `entity.${entityName}.name`, + }, + { text: isBow ? ' §gзастрелен' : ' §gубит' }, + ], + }) + } } - // } lockDisplay.set(damage.damagingEntity.id, 2) } @@ -158,9 +154,9 @@ function onDamage(event: EntityHurtAfterEvent, fatal = false) { if (event.hurtEntity instanceof Player) { // skip SimulatedPlayer because of error - if ('jump' in event.hurtEntity) return + // if ('jump' in event.hurtEntity) return - event.hurtEntity.scores.pvp = options.cooldown + event.hurtEntity.scores.pvp = options.pvpCooldown event.hurtEntity.scores.damageRecieve += event.damage if (fatal) event.hurtEntity.scores.deaths++ }