Skip to content

Commit

Permalink
fix: nicknames and pvp
Browse files Browse the repository at this point in the history
  • Loading branch information
leaftail1880 committed Aug 28, 2024
1 parent 88cbe68 commit a6be0f4
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 52 deletions.
5 changes: 4 additions & 1 deletion src/lib/clan/command.ts
Original file line number Diff line number Diff line change
@@ -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]())
1 change: 1 addition & 0 deletions src/lib/portals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
3 changes: 2 additions & 1 deletion src/lib/sidebar.ts
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -96,7 +97,7 @@ export class Sidebar<E = any> {
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))
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/indicator/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/indicator/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import './health'
// import "./pvp";
import './pvp'
import './test-damage'
7 changes: 3 additions & 4 deletions src/modules/indicator/player-name-tag.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
86 changes: 41 additions & 45 deletions src/modules/indicator/pvp.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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', {
Expand All @@ -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()) {
Expand All @@ -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,
Expand Down Expand Up @@ -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++

Expand All @@ -123,44 +122,41 @@ 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)
}
}

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++
}
Expand Down

0 comments on commit a6be0f4

Please sign in to comment.