From 8f183a40342724e8310af5e3bee7cf2ac23c2a54 Mon Sep 17 00:00:00 2001 From: leaftail1880 <110915645+leaftaul1880@users.noreply.github.com> Date: Sun, 25 Aug 2024 23:00:54 +0300 Subject: [PATCH] fix: improve internal tools --- src/modules/commands/db.ts | 57 ++++++++++++++--------------------- src/modules/commands/index.ts | 1 + src/modules/commands/pid.ts | 29 ++++++++++++++++++ 3 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 src/modules/commands/pid.ts diff --git a/src/modules/commands/db.ts b/src/modules/commands/db.ts index 1cf0d684..1c3bb05a 100644 --- a/src/modules/commands/db.ts +++ b/src/modules/commands/db.ts @@ -1,5 +1,5 @@ import { Player, system, world } from '@minecraft/server' -import { ROLES, getRole, inspect, util } from 'lib' +import { ArrayForm, ROLES, getRole, inspect, util } from 'lib' import { DatabaseTable, getProvider } from 'lib/database/abstract' import { ActionForm } from 'lib/form/action' import { ModalForm } from 'lib/form/modal' @@ -23,41 +23,30 @@ function selectTable(player: Player, firstCall?: true) { function showTable(player: Player, tableId: string, table: DatabaseTable) { const selfback = () => showTable(player, tableId, table) - const menu = new ActionForm(tableId) - - menu.addButton(ActionForm.backText, () => selectTable(player)) - menu.addButton('§3Новое значение§r', () => { - changeValue( - player, - null, - (newVal, key) => { - table[key] = newVal - }, - selfback, - ) - }) - - menu.addButton('§3Посмотреть в §fRAW', () => { - let raw = getProvider().getRawTableData(tableId) - try { - if (typeof raw === 'string') raw = JSON.parse(raw) as typeof raw - } catch {} - - new ActionForm('§3RAW table §f' + tableId, inspect(raw)).addButton('Oк', selectTable).show(player) - }) - const keys = Object.keys(table) - for (const key of keys) { - let name = key - if (tableId === 'player') { - const playerDatabase = table as typeof Player.database - name = `${playerDatabase[key].name} ${(ROLES[getRole(key)] as string | undefined) ?? '§7Без роли'}\n§8(${key})` - } - - menu.addButton(name, () => tableProperty(key, table, player, selfback)) - } + new ArrayForm(`${tableId} ${keys.length}`, keys) + .addCustomButtonBeforeArray(form => { + form + .addButton('§3Новое значение§r', () => { + changeValue(player, null, (newVal, key) => (table[key] = newVal), selfback) + }) + .addButtonPrompt('§cОчистить таблицу', 'ДААА УДАЛИТЬ ВСЕ НАФИГ', () => { + Object.keys(table).forEach(e => Reflect.deleteProperty(table, e)) + }) + }) + .back(() => selectTable(player)) + .button(key => { + let name = key + if (tableId === 'player') { + const playerDatabase = table as typeof Player.database + name = `${playerDatabase[key].name} ${(ROLES[getRole(key)] as string | undefined) ?? '§7Без роли'}\n§8(${key})` + } else { + name += `\n§7${JSON.stringify(table[key]).replace(/"/g, '')}` + } - menu.show(player) + return [name, () => tableProperty(key, table, player, selfback)] as const + }) + .show(player) } function tableProperty(key: string, table: DatabaseTable, player: Player, back: VoidFunction) { diff --git a/src/modules/commands/index.ts b/src/modules/commands/index.ts index 0fce2134..1a9920ab 100644 --- a/src/modules/commands/index.ts +++ b/src/modules/commands/index.ts @@ -2,6 +2,7 @@ import './camera' import './db' import './gamemode' import './help' +import './pid' import './kill' import './leaderboard' import './mail' diff --git a/src/modules/commands/pid.ts b/src/modules/commands/pid.ts new file mode 100644 index 00000000..f6e14f96 --- /dev/null +++ b/src/modules/commands/pid.ts @@ -0,0 +1,29 @@ +import { Player } from '@minecraft/server' +import { is, ModalForm } from 'lib' +import { selectPlayer } from 'lib/form/select-player' + +new Command('pid') + .setDescription('Выдает ваш айди') + .executes(ctx => + pid( + ctx.player.id, + ctx.player.name, + ctx.player, + is(ctx.player.id, 'techAdmin') ? () => playersPid(ctx.player) : () => void 0, + ), + ) + + .overload('get') + .setPermissions('techAdmin') + .setDescription('Открывает форму для получения айди других игроков') + .executes(ctx => playersPid(ctx.player)) + +function playersPid(player: Player) { + selectPlayer(player, 'PID').then(({ id, name }) => { + pid(id, name, player, () => playersPid(player)) + }) +} + +function pid(id: string, name: string, player: Player, then: VoidFunction) { + new ModalForm('PlayerID').addTextField(name, 'pid', id).show(player, then) +}