11/* i18n-ignore */
22
33import { Player , ScoreboardIdentityType , ScoreboardObjective , world } from '@minecraft/server'
4- import { ActionForm , BUTTON , Leaderboard , ModalForm } from 'lib'
4+ import { ActionForm , BUTTON , Leaderboard , ModalForm , noBoolean } from 'lib'
5+ import { defaultLang } from 'lib/assets/lang'
56import { ScoreboardDB } from 'lib/database/scoreboard'
67import { ArrayForm } from 'lib/form/array'
78import { selectPlayer } from 'lib/form/select-player'
8- import { i18n , noI18n } from 'lib/i18n/text'
9+ import { i18n , noI18n , textTable } from 'lib/i18n/text'
910
1011new Command ( 'scores' )
1112 . setDescription ( 'Управляет счетом игроков (монеты, листья)' )
@@ -18,13 +19,23 @@ alias('leafs')
1819alias ( 'money' )
1920
2021function alias ( name = 'leafs' ) {
21- new Command ( name )
22+ const cmd = new Command ( name )
2223 . setDescription ( 'Управляет счетом игроков (' + name + ')' )
2324 . setPermissions ( 'chefAdmin' )
2425 . executes ( ctx => {
2526 const obj = world . scoreboard . getObjective ( name )
2627 if ( obj ) scoreboardMenu ( ctx . player , obj )
2728 } )
29+
30+ cmd . int ( 'add' ) . executes ( ( ctx , add ) => {
31+ const obj = world . scoreboard . getObjective ( name )
32+ if ( obj ) {
33+ const proxy = new ScoreboardDB ( obj . id )
34+ const been = proxy . get ( ctx . player )
35+ proxy . add ( ctx . player , add )
36+ ctx . player . tell ( `${ ScoreboardDB . getName ( name ) . to ( ctx . player . lang ) } ${ been } -> ${ proxy . get ( ctx . player ) } ` )
37+ }
38+ } )
2839}
2940
3041function scoreManagerMenu ( player : Player ) {
@@ -37,7 +48,7 @@ function scoreManagerMenu(player: Player) {
3748 if ( a1 ) return - 1
3849 return 1
3950 } ) ) {
40- form . button ( scoreboard . displayName , ( ) => {
51+ form . button ( ScoreboardDB . getName ( scoreboard ) . to ( player . lang ) , ( ) => {
4152 scoreboardMenu ( player , scoreboard )
4253 } )
4354 }
@@ -48,7 +59,7 @@ function scoreManagerMenu(player: Player) {
4859function scoreboardMenu ( player : Player , objective : ScoreboardObjective ) {
4960 const scoreboard = new ScoreboardDB ( objective . id )
5061
51- new ArrayForm ( objective . displayName + '§r§f $page/$max' , objective . getParticipants ( ) )
62+ new ArrayForm ( ScoreboardDB . getName ( objective ) . to ( player . lang ) + '§r§f $page/$max' , objective . getParticipants ( ) )
5263 . filters ( {
5364 online : {
5465 name : 'Онлайн' ,
@@ -83,8 +94,8 @@ function scoreboardMenu(player: Player, objective: ScoreboardObjective) {
8394 . addCustomButtonBeforeArray ( form => {
8495 form . button ( '§3Добавить' , BUTTON [ '+' ] , ( ) => addTargetToScoreboardMenu ( player , objective ) )
8596 form . ask (
86- '§cУдалить таблицу' ,
87- '§cУдалить' ,
97+ noI18n . error `Удалить таблицу` ,
98+ noI18n . error `Удалить` ,
8899 ( ) => world . scoreboard . removeObjective ( objective . id ) ,
89100 undefined ,
90101 'textures/ui/trash_light' ,
@@ -120,10 +131,15 @@ function editPlayerScore(
120131function getScoreDescription ( targetId : string , targetName : string , manager : ScoreboardDB ) {
121132 const converted = Leaderboard . formatScore ( manager . scoreboard . id , manager . get ( targetId ) )
122133 const raw = manager . get ( targetId )
123- return noI18n `
124- §l§7Игрок: §r§f${ targetName } §r
125- §l§7Значение:§r §f${ raw }
126- ${ converted !== raw ? noI18n `§l§7Конвертированный счет: §r§f${ converted } ` : '' } `. trim ( )
134+ return textTable (
135+ (
136+ [
137+ [ 'Игрок' , targetName ] ,
138+ [ 'Значение' , raw ] ,
139+ converted !== raw ? ( [ 'Конвертированное' , converted ] as const ) : false ,
140+ ] as const
141+ ) . filter ( noBoolean ) ,
142+ ) . to ( defaultLang )
127143}
128144
129145function addOrSetPlayerScore (
@@ -135,7 +151,7 @@ function addOrSetPlayerScore(
135151 mode : 'add' | 'set' = 'add' ,
136152) {
137153 const action = mode === 'add' ? 'Добавить' : 'Установить'
138- new ModalForm ( manager . scoreboard . displayName + '§r§7 / §f' + action )
154+ new ModalForm ( ScoreboardDB . getName ( manager . scoreboard ) . to ( player . lang ) + '§r§7 / §f' + action )
139155 . addTextField (
140156 `${ getScoreDescription ( targetId , targetName , manager ) } \n§l§7${ action } :§r` ,
141157 'Ничего не произойдет' ,
@@ -148,9 +164,9 @@ function addOrSetPlayerScore(
148164 manager [ mode ] ( targetId , parseInt ( value ) )
149165
150166 Player . getById ( targetId ) ?. info (
151- `§7Игрок §f ${ player . name } §r§7 ${ mode === 'add' ? 'начислил вам' : 'установил значение счета' } §f ${
152- manager . scoreboard . displayName
153- } §r§7 ${ mode === 'set' ? 'на ' : '' } §f§l ${ value } `,
167+ noI18n `Игрок ${ player . name } ${ mode === 'add' ? 'начислил вам' : 'установил значение счета' } ${ ScoreboardDB . getName (
168+ manager . scoreboard ,
169+ ) . to ( defaultLang ) } : ${ value } `,
154170 )
155171 } // If no value then do nothing
156172
0 commit comments