Skip to content

Commit 32b109c

Browse files
committed
同一コードを排除
1 parent 4c71e78 commit 32b109c

File tree

5 files changed

+33
-36
lines changed

5 files changed

+33
-36
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
他人のお金を確認
2424
/seecoin [playerName]
25+
26+
お金をセットする
27+
/setcoin [playerName]
2528
```
2629

2730
## API
@@ -72,3 +75,5 @@ https://github.com/SpaceServerDev/SecureCoinAPI/blob/87252872ac9dd25a450102f807d
7275
```php
7376
$api->getCoin($player->getName());
7477
```
78+
79+
お金をセット

src/space/yurisi/SecureCoinAPI/command/SecureCoinCommand.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace space\yurisi\SecureCoinAPI\command;
45

6+
use pocketmine\command\CommandSender;
57
use pocketmine\command\defaults\VanillaCommand;
68
use pocketmine\player\Player;
79
use pocketmine\Server;
810

911
abstract class SecureCoinCommand extends VanillaCommand {
1012

11-
public function getPlayer(string $name): string {
13+
protected function getPlayer(string $name): string {
1214
$receive_player = Server::getInstance()->getPlayerByPrefix($name);
1315

1416
if ($receive_player instanceof Player) {
@@ -19,4 +21,23 @@ public function getPlayer(string $name): string {
1921
return $receive_player;
2022
}
2123

24+
protected function getAmount(array $args, CommandSender $sender): ?int {
25+
if (!isset($args[0]) || !isset($args[1])) {
26+
$sender->sendMessage($this->getUsage());
27+
return null;
28+
}
29+
30+
if (!is_numeric($args[1])) {
31+
$sender->sendMessage($this->getUsage());
32+
return null;
33+
}
34+
35+
if ((int)$args[1] < 0) {
36+
$sender->sendMessage("数値は正の値を指定してください。");
37+
return null;
38+
}
39+
40+
return (int)floor((int)$args[1]);
41+
}
42+
2243
}

src/space/yurisi/SecureCoinAPI/command/addcoinCommand.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,9 @@ public function __construct(private SecureCoinAPI $main) {
1616
}
1717

1818
public function execute(CommandSender $sender, string $commandLabel, array $args) {
19-
if (!isset($args[0]) || !isset($args[1])) {
20-
$sender->sendMessage($this->getUsage());
21-
return;
22-
}
23-
24-
if (!is_numeric($args[1])) {
25-
$sender->sendMessage($this->getUsage());
26-
return;
27-
}
19+
$amount = $this->getAmount($args, $sender);
2820

29-
$amount = (int)floor((int)$args[1]);
21+
if($amount == null) return;
3022

3123
$receive_player = $this->getPlayer($args[0]);
3224

src/space/yurisi/SecureCoinAPI/command/setcoinCommand.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,9 @@ public function __construct(private SecureCoinAPI $main) {
1515
}
1616

1717
public function execute(CommandSender $sender, string $commandLabel, array $args) {
18-
if (!isset($args[0]) || !isset($args[1])) {
19-
$sender->sendMessage($this->getUsage());
20-
return;
21-
}
22-
23-
if (!is_numeric($args[1])) {
24-
$sender->sendMessage($this->getUsage());
25-
return;
26-
}
27-
28-
if ((int)$args[1] < 0) {
29-
$sender->sendMessage("数値は正の値を指定してください。");
30-
return;
31-
}
18+
$amount = $this->getAmount($args, $sender);
3219

33-
$amount = (int)floor((int)$args[1]);
20+
if($amount == null) return;
3421

3522
$receive_player = $this->getPlayer($args[0]);
3623

src/space/yurisi/SecureCoinAPI/command/takecoinCommand.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,9 @@ public function __construct(private SecureCoinAPI $main) {
1414
}
1515

1616
public function execute(CommandSender $sender, string $commandLabel, array $args) {
17-
if (!isset($args[0]) || !isset($args[1])) {
18-
$sender->sendMessage($this->getUsage());
19-
return;
20-
}
21-
22-
if (!is_numeric($args[1])) {
23-
$sender->sendMessage($this->getUsage());
24-
return;
25-
}
17+
$amount = $this->getAmount($args, $sender);
2618

27-
$amount = (int)floor((int)$args[1]);
19+
if($amount == null) return;
2820

2921
$receive_player = $this->getPlayer($args[0]);
3022

0 commit comments

Comments
 (0)