Skip to content

Commit

Permalink
Added /bcp show to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
matcracker committed May 25, 2020
1 parent 53c8931 commit b9343c1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
3 changes: 3 additions & 0 deletions resources/languages/eng.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ form.menu.option = Select an option:
form.menu.inspector = Enable/Disable inspector mode
form.menu.near = Lookup in data (radius)
form.menu.lookup = Lookup in data (advanced)
form.menu.show = Show logs
form.menu.purge = Purge data
form.menu.reload = Reload plugin
form.menu.status = Show plugin status
form.purge-menu.time = Delete data older than
form.input-menu.page-number = Number of page:
form.input-menu.lines-number = Number of lines:
form.input-menu.required-fields = Required fields:
form.input-menu.optional-fields = Optional fields:
form.input-menu.time = Time
Expand Down
3 changes: 3 additions & 0 deletions resources/languages/ita.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ form.menu.option = Seleziona un'opzione:
form.menu.inspector = Attiva/Disattiva modalità ispettore
form.menu.near = Ricerca nei dati (raggio)
form.menu.lookup = Ricerca nei dati (avanzato)
form.menu.show = Mostra dati
form.menu.purge = Elimina dati
form.menu.reload = Ricarica il plugin
form.menu.status = Mostra stato del plugin
form.purge-menu.time = Elimina dati più vecchi di
form.input-menu.page-number = Numero di pagina:
form.input-menu.lines-number = Numero di righe:
form.input-menu.required-fields = Campi richiesti:
form.input-menu.optional-fields = Campi opzionali:
form.input-menu.time = Tempo
Expand Down
3 changes: 3 additions & 0 deletions resources/languages/rus.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ form.menu.option = Выбор опции:
form.menu.inspector = Включить/выключить режим инспектора
form.menu.near = Просмотр логов (радиус)
form.menu.lookup = Просмотр логов (продвинутый)
form.menu.show = Show logs
form.menu.purge = Очистить логи
form.menu.reload = Перезапустить плагин
form.menu.status = Показать статус плагина
form.purge-menu.time = Удалить данные старше чем
form.input-menu.page-number = Number of page:
form.input-menu.lines-number = Number of lines:
form.input-menu.required-fields = Обязательные поля:
form.input-menu.optional-fields = Опциональные поля:
form.input-menu.time = Время
Expand Down
7 changes: 4 additions & 3 deletions src/matcracker/BedcoreProtect/commands/BCPCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,16 @@ function () use ($sender, $config, $lang) : Generator {
$page = 0;
$lines = 4;
$split = explode(":", $args[1]);
if ($ctype = ctype_digit($split[0])) {
if ($pageType = ctype_digit($split[0])) {
$page = (int)$split[0];
}

if (isset($split[1]) && $ctype = ctype_digit($split[1])) {
$lineType = true;
if (isset($split[1]) && $lineType = ctype_digit($split[1])) {
$lines = (int)$split[1];
}

if (!$ctype) {
if (!$pageType || !$lineType) {
$sender->sendMessage(TextFormat::colorize(Main::MESSAGE_PREFIX . '&c' . $lang->translateString('command.error.no-numeric-value')));

return true;
Expand Down
40 changes: 33 additions & 7 deletions src/matcracker/BedcoreProtect/ui/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use Closure;
use matcracker\BedcoreProtect\commands\CommandParser;
use matcracker\BedcoreProtect\Inspector;
use matcracker\BedcoreProtect\Main;
use matcracker\BedcoreProtect\utils\ConfigParser;
use matcracker\FormLib\BaseForm;
Expand All @@ -48,7 +49,7 @@ public function getMainMenu(): BaseForm
{
$lang = Main::getInstance()->getLanguage();
return (new Form(
function (Player $player, $data): void {
function (Player $player, $data) use ($lang): void {
switch ((int)$data) { //Clicked button
case 0: //Inspector
$player->chat('/bcp inspect');
Expand All @@ -59,22 +60,29 @@ function (Player $player, $data): void {
case 2: //Lookup
$player->sendForm($this->getInputMenu('lookup'));
break;
case 3: //Rollback
case 3: //Show
if (count(($logs = Inspector::getSavedLogs($player))) > 0) {
$player->sendForm($this->getShowMenu());
} else {
$player->sendMessage(TextFormat::colorize(Main::MESSAGE_PREFIX . '&c' . $lang->translateString('command.show.no-logs')));
}
break;
case 4: //Rollback
$player->sendForm($this->getInputMenu('rollback'));
break;
case 4: //Restore
case 5: //Restore
$player->sendForm($this->getInputMenu('restore'));
break;
case 5: //Undo
case 6: //Undo
$player->chat('/bcp undo');
break;
case 6: //Purge
case 7: //Purge
$player->sendForm($this->getPurgeMenu());
break;
case 7: //Reload
case 8: //Reload
$player->chat('/bcp reload');
break;
case 8: //Status
case 9: //Status
$player->chat('/bcp status');
break;
}
Expand All @@ -83,6 +91,7 @@ function (Player $player, $data): void {
->addClassicButton($lang->translateString('form.menu.inspector'))
->addClassicButton($lang->translateString('form.menu.near'))
->addClassicButton($lang->translateString('form.menu.lookup'))
->addClassicButton($lang->translateString('form.menu.show'))
->addClassicButton($lang->translateString('general.rollback'))
->addClassicButton($lang->translateString('general.restore'))
->addClassicButton($lang->translateString('general.undo'))
Expand All @@ -108,6 +117,23 @@ function (Player $player): void {
->setTitle(TextFormat::colorize('&3&l' . $lang->translateString('form.menu.near')));
}

private function getShowMenu(): BaseForm
{
$lang = Main::getInstance()->getLanguage();
return (new CustomForm(
static function (Player $player, $data): void {
if (is_array($data)) {
$player->chat("/bcp show {$data[0]}:{$data[1]}");
}
},
function (Player $player): void {
$player->sendForm($this->getMainMenu());
}
))->addInput($lang->translateString('form.input-menu.page-number'), "1", "1")
->addInput($lang->translateString('form.input-menu.lines-number'), "4", "4")
->setTitle(TextFormat::colorize('&3&l' . $lang->translateString('form.menu.show')));
}

private function getInputMenu(string $type): BaseForm
{
$lang = Main::getInstance()->getLanguage();
Expand Down

0 comments on commit b9343c1

Please sign in to comment.