@@ -2,8 +2,6 @@ import { Entity, Player, ScoreboardObjective, ScoreNames, world } from '@minecra
22import { expand } from 'lib/extensions/extend'
33import { capitalize } from 'lib/util'
44
5- type LushWayGameModes = 'anarchy'
6-
75declare module '@minecraft/server' {
86 namespace ScoreNames {
97 type Stat =
@@ -16,11 +14,11 @@ declare module '@minecraft/server' {
1614 | 'kills'
1715 | 'deaths'
1816
19- type OnlineTime = `${ 'total' | LushWayGameModes } OnlineTime`
17+ type GameModes = 'anarchy'
2018
21- type Date = `${'lastSeen ' | 'join' } Date `
19+ type OnlineTime = `${'total ' | GameModes } OnlineTime `
2220
23- type GameModes = 'anarchy'
21+ type Date = `${ 'lastSeen' | 'join' } Date`
2422
2523 type GameModesStat = `${GameModes } ${Capitalize < Stat | Date > } `
2624
@@ -42,7 +40,6 @@ export const scoreboardDisplayNames: Record<import('@minecraft/server').ScoreNam
4240 deaths : 'Смертей' ,
4341 raid : 'Рейд-блок' ,
4442 totalOnlineTime : 'Онлайн всего' ,
45- anarchyOnlineTime : 'Онлайн на анархии' ,
4643 blocksPlaced : 'Блоков поставлено' ,
4744 blocksBroken : 'Блоков сломано' ,
4845 fireworksLaunched : 'Фейрверков запущено' ,
@@ -52,6 +49,7 @@ export const scoreboardDisplayNames: Record<import('@minecraft/server').ScoreNam
5249 joinTimes : 'Всего входов на сервер' ,
5350 joinDate : 'Время первого входа' ,
5451
52+ anarchyOnlineTime : 'Онлайн на анархии' ,
5553 anarchyBlocksPlaced : 'Блоков поставлено' ,
5654 anarchyBlocksBroken : 'Блоков сломано' ,
5755 anarchyFireworksLaunched : 'Фейрверков запущено' ,
@@ -79,12 +77,12 @@ const statScores: Record<ScoreNames.Stat, string> = {
7977 deaths : '' ,
8078}
8179
82- const scorebaordStatNames = Object . keys ( statScores )
80+ const scoreboardStatNames = Object . keys ( statScores )
8381export const scoreboardObjectiveNames = {
84- stats : scorebaordStatNames ,
85- gameModeStats : scorebaordStatNames
82+ stats : scoreboardStatNames ,
83+ gameModeStats : scoreboardStatNames
8684 . map ( e => `anarchy${ capitalize ( e ) } ` )
87- . concat ( scorebaordStatNames ) as ScoreNames . GameModesStat [ ] ,
85+ . concat ( scoreboardStatNames ) as ScoreNames . GameModesStat [ ] ,
8886}
8987
9088const untypedDisplayNames : Record < string , string > = scoreboardDisplayNames
@@ -107,6 +105,10 @@ Reflect.defineProperty(Player.prototype, 'scores', {
107105} )
108106
109107export class ScoreboardDB {
108+ static defineName ( id : string , name : string ) {
109+ untypedDisplayNames [ id ] = name
110+ }
111+
110112 static getOrCreateProxyFor ( playerId : string ) {
111113 const scoreboardPlayer = players [ playerId ]
112114 if ( scoreboardPlayer ) {
@@ -141,13 +143,14 @@ export class ScoreboardDB {
141143 }
142144 }
143145
144- static objectives : Record < string , ScoreboardObjective > = { }
146+ private static objectives = new Map < string , ScoreboardObjective > ( )
145147
146- static objective ( name : string , displayName = name ) {
147- if ( this . objectives [ name ] ) return this . objectives [ name ]
148-
149- const objective = ( this . objectives [ name ] =
150- world . scoreboard . getObjective ( name ) ?? world . scoreboard . addObjective ( name , displayName ) )
148+ static objective ( id : string , displayName = id ) {
149+ let objective = this . objectives . get ( id )
150+ if ( ! objective ) {
151+ objective = world . scoreboard . getObjective ( id ) ?? world . scoreboard . addObjective ( id , displayName )
152+ this . objectives . set ( id , objective )
153+ }
151154
152155 return objective
153156 }
@@ -163,28 +166,16 @@ export class ScoreboardDB {
163166 this . scoreboard = ScoreboardDB . objective ( name , displayName )
164167 }
165168
166- /**
167- * @param {Entity | string } id
168- * @param {number } value
169- */
170169 set ( id : Entity | string , value : number ) {
171170 if ( typeof id !== 'string' ) id = id . id
172171 this . scoreboard . setScore ( id , value )
173172 }
174173
175- /**
176- * @param {Entity | string } id
177- * @param {number } value
178- */
179174 add ( id : Entity | string , value : number ) {
180175 if ( typeof id !== 'string' ) id = id . id
181176 this . scoreboard . setScore ( id , this . get ( id ) + value )
182177 }
183178
184- /**
185- * @param {Entity | string } id
186- * @returns {number }
187- */
188179 get ( id : Entity | string ) : number {
189180 if ( typeof id !== 'string' ) id = id . id
190181 try {
@@ -193,21 +184,4 @@ export class ScoreboardDB {
193184 return 0
194185 }
195186 }
196-
197- reset ( ) {
198- this . scoreboard . getParticipants ( ) . forEach ( e => this . scoreboard . removeParticipant ( e ) )
199- }
200187}
201-
202- /*
203- const objective = new ScoreboardDB('objectiveName', 'display name')
204-
205- const score = objective.get(player)
206- objective.set(player, 1)
207- objective.add(player, 1)
208-
209- objective.nameSet('custom name', 1)
210- objective.nameGet('custom name')
211-
212- objective.reset()
213- */
0 commit comments