File tree Expand file tree Collapse file tree 5 files changed +33
-36
lines changed
src/space/yurisi/SecureCoinAPI/command Expand file tree Collapse file tree 5 files changed +33
-36
lines changed Original file line number Diff line number Diff line change 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+ お金をセット
Original file line number Diff line number Diff line change 11<?php
2+ declare (strict_types=1 );
23
34namespace space \yurisi \SecureCoinAPI \command ;
45
6+ use pocketmine \command \CommandSender ;
57use pocketmine \command \defaults \VanillaCommand ;
68use pocketmine \player \Player ;
79use pocketmine \Server ;
810
911abstract 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments