|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2018 VectorNetworkProject. All rights reserved. MIT license. |
|
4
|
|
|
* |
|
5
|
|
|
* GitHub: https://github.com/VectorNetworkProject/TheMix |
|
6
|
|
|
* Website: https://www.vector-network.tk |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace VectorNetworkProject\TheMix\command\defaults; |
|
10
|
|
|
|
|
11
|
|
|
use pocketmine\command\CommandSender; |
|
12
|
|
|
use pocketmine\command\PluginCommand; |
|
13
|
|
|
use pocketmine\level\Position; |
|
14
|
|
|
use pocketmine\Player; |
|
15
|
|
|
use pocketmine\plugin\Plugin; |
|
16
|
|
|
use pocketmine\Server; |
|
17
|
|
|
use pocketmine\utils\TextFormat; |
|
18
|
|
|
use tokyo\pmmp\libform\element\Button; |
|
19
|
|
|
use tokyo\pmmp\libform\element\Dropdown; |
|
20
|
|
|
use tokyo\pmmp\libform\element\Slider; |
|
21
|
|
|
use tokyo\pmmp\libform\FormApi; |
|
22
|
|
|
use VectorNetworkProject\TheMix\command\Permissions; |
|
23
|
|
|
use VectorNetworkProject\TheMix\game\corepvp\blue\BlueCoreManager; |
|
24
|
|
|
use VectorNetworkProject\TheMix\game\corepvp\red\RedCoreManager; |
|
25
|
|
|
use VectorNetworkProject\TheMix\game\DefaultConfig; |
|
26
|
|
|
|
|
27
|
|
|
class ModeratorCommand extends PluginCommand |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* ModeratorCommand constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param Plugin $owner |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(Plugin $owner) |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct('moderator', $owner); |
|
37
|
|
|
$this->setDescription('モデレーター専用メニュー(管理権限持ちのユーザー以外使用不可能)'); |
|
38
|
|
|
$this->setPermission(Permissions::ADMIN.'moderator'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param CommandSender $sender |
|
43
|
|
|
* @param string $commandLabel |
|
44
|
|
|
* @param array $args |
|
45
|
|
|
* |
|
46
|
|
|
* @return bool|mixed |
|
47
|
|
|
*/ |
|
48
|
|
|
public function execute(CommandSender $sender, string $commandLabel, array $args) |
|
49
|
|
|
{ |
|
50
|
|
|
if (!$this->testPermission($sender)) { |
|
51
|
|
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
$sender instanceof Player |
|
54
|
|
|
? self::sendModeratorUI($sender) |
|
55
|
|
|
: $sender->sendMessage(TextFormat::RED.'プレイヤーのみ実行可能です。'); |
|
56
|
|
|
|
|
57
|
|
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public static function sendModeratorUI(Player $player): void |
|
61
|
|
|
{ |
|
62
|
|
|
$form = FormApi::makeListForm(function (Player $player, ?int $data) { |
|
63
|
|
|
if (FormApi::formCancelled($data)) { |
|
64
|
|
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
switch ($data) { |
|
67
|
|
|
case 0: |
|
68
|
|
|
self::sendLevelManagerUI($player); |
|
69
|
|
|
break; |
|
70
|
|
|
case 1: |
|
71
|
|
|
self::sendCoreManagerUI($player); |
|
72
|
|
|
break; |
|
73
|
|
|
} |
|
74
|
|
|
}); |
|
75
|
|
|
$form->setTitle('Moderator Menu'); |
|
76
|
|
|
$form->setContent('行う処理を選んで下さい。'); |
|
77
|
|
|
$form->addButton(new Button('テレポート')); |
|
78
|
|
|
$form->addButton(new Button('CoreManager')); |
|
79
|
|
|
$form->sendToPlayer($player); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public static function sendLevelManagerUI(Player $player): void |
|
83
|
|
|
{ |
|
84
|
|
|
$form = FormApi::makeListForm(function (Player $player, ?int $data) { |
|
85
|
|
|
if (FormApi::formCancelled($data)) { |
|
86
|
|
|
return; |
|
87
|
|
|
} |
|
88
|
|
|
switch ($data) { |
|
89
|
|
|
case 0: |
|
90
|
|
|
$player->teleport(Server::getInstance()->getDefaultLevel()->getSpawnLocation()); |
|
91
|
|
|
break; |
|
92
|
|
|
case 1: |
|
93
|
|
|
$player->teleport(new Position(0, 75, 0, Server::getInstance()->getLevelByName(DefaultConfig::getStageLevelName()))); |
|
94
|
|
|
break; |
|
95
|
|
|
case 2: |
|
96
|
|
|
self::sendModeratorUI($player); |
|
97
|
|
|
break; |
|
98
|
|
|
} |
|
99
|
|
|
}); |
|
100
|
|
|
$form->setTitle('WorldManager'); |
|
101
|
|
|
$form->setContent('テレポートするワールドを選択して下さい。'); |
|
102
|
|
|
$form->addButton(new Button('lobby(default world)')); |
|
103
|
|
|
$form->addButton(new Button('Stage')); |
|
104
|
|
|
$form->addButton(new Button('戻る')); |
|
105
|
|
|
$form->sendToPlayer($player); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public static function sendCoreManagerUI(Player $player): void |
|
109
|
|
|
{ |
|
110
|
|
|
$form = FormApi::makeCustomForm(function (Player $player, ?array $data) { |
|
111
|
|
|
if (FormApi::formCancelled($data)) { |
|
112
|
|
|
return; |
|
113
|
|
|
} |
|
114
|
|
|
if ($data[0] === 0) { |
|
115
|
|
|
RedCoreManager::setHP($data[1]); |
|
116
|
|
|
Server::getInstance()->broadcastMessage(TextFormat::GRAY.'[MODERATOR] '.$player->getName().'がREDチームのHPを'.$data[1].'に変更しました。'); |
|
117
|
|
|
} else { |
|
118
|
|
|
BlueCoreManager::setHP($data[1]); |
|
119
|
|
|
Server::getInstance()->broadcastMessage(TextFormat::GRAY.'[MODERATOR] '.$player->getName().'がBLUEチームのHPを'.$data[1].'に変更しました。'); |
|
120
|
|
|
} |
|
121
|
|
|
}); |
|
122
|
|
|
$form->setTitle('CoreManager'); |
|
123
|
|
|
$form->addElement(new Dropdown('HPを変更するチームを選んで下さい。', ['RED', 'BLUE'])); |
|
124
|
|
|
$form->addElement(new Slider('HP', 1, 75)); |
|
125
|
|
|
$form->sendToPlayer($player); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|