Skip to content

Commit 7441c56

Browse files
committed
権限設定、givecoinの完成
1 parent 61fb7ff commit 7441c56

11 files changed

Lines changed: 117 additions & 14 deletions

File tree

plugin.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
name: SecureCoinAPI
22
main: space\yurisi\SecureCoinAPI\SecureCoinAPI
33
author: yurisi
4-
# depend:
5-
# - EconomyAPI
64
version: 1.0.0
75
api: 4.0.0
8-
# permissions:
9-
# space.yurisi.SecureCoinAPI.example:
10-
# default: op
11-
# description: 詳細
6+
permissions:
7+
space.yurisi.SecureCoinAPI.addcoin:
8+
default: op
9+
space.yurisi.SecureCoinAPI.coinhistory:
10+
default: op
11+
space.yurisi.SecureCoinAPI.givecoin:
12+
default: true
13+
space.yurisi.SecureCoinAPI.mycoin:
14+
default: true
15+
space.yurisi.SecureCoinAPI.seecoin:
16+
default: true
17+
space.yurisi.SecureCoinAPI.setcoin:
18+
default: op
19+
space.yurisi.SecureCoinAPI.takecoin:
20+
default: op

src/space/yurisi/SecureCoinAPI/SecureCoinAPI.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use space\yurisi\SecureCoinAPI\command\seecoinCommand;
1212
use space\yurisi\SecureCoinAPI\command\setcoinCommand;
1313
use space\yurisi\SecureCoinAPI\command\takecoinCommand;
14+
use space\yurisi\SecureCoinAPI\command\givecoinCommand;
1415
use space\yurisi\SecureCoinAPI\database\coinJson;
1516
use space\yurisi\SecureCoinAPI\database\historySQLite;
1617
use space\yurisi\SecureCoinAPI\lib\APIMethod;
@@ -31,6 +32,7 @@ protected function onEnable(): void {
3132
$this->registerEvents();
3233
$this->registerCommands();
3334
self::$main = $this;
35+
$this->register('testuser');
3436
}
3537

3638
private function registerEvents() {
@@ -49,13 +51,13 @@ private function registerCommands() {
4951
new mycoinCommand($this),
5052
new seecoinCommand($this),
5153
new takecoinCommand($this),
52-
new setcoinCommand($this)
54+
new setcoinCommand($this),
55+
new givecoinCommand($this)
5356
]);
5457
}
5558

5659
protected function onDisable(): void {
57-
$this->coinJson->save();
58-
$this->history->save();
60+
$this->save();
5961
}
6062

6163
public static function getInstance(): self {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
namespace space\yurisi\SecureCoinAPI\command;
55

66
use pocketmine\command\CommandSender;
7-
use pocketmine\command\defaults\VanillaCommand;
8-
use pocketmine\player\Player;
97
use space\yurisi\SecureCoinAPI\History;
108
use space\yurisi\SecureCoinAPI\SecureCoinAPI;
119

1210
class addcoinCommand extends SecureCoinCommand {
1311

1412
public function __construct(private SecureCoinAPI $main) {
1513
parent::__construct("addcoin", "プレイヤーにお金を渡します", "/addcoin [playerName] [amount]");
14+
$this->setPermission("space.yurisi.SecureCoinAPI.addcoin");
1615
}
1716

1817
public function execute(CommandSender $sender, string $commandLabel, array $args) {
18+
if (!$this->testPermission($sender)) return;
19+
1920
$amount = $this->getAmount($args, $sender);
2021

2122
if($amount == null) return;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
class coinhistoryCommand extends SecureCoinCommand {
99

1010
public function __construct() {
11-
parent::__construct("coinhistory", "履歴を表示する", "/coinhistory [pluginName]");
11+
parent::__construct("coinhistory", "履歴を表示する", "/coinhistory [pluginName] [page = 1]");
12+
$this->setPermission("space.yurisi.SecureCoinAPI.coinhistory");
1213
}
1314

1415
public function execute(CommandSender $sender, string $commandLabel, array $args) {
15-
// TODO: Implement execute() method.
16+
if (!$this->testPermission($sender)) return;
17+
//TODO
1618
}
1719
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace space\yurisi\SecureCoinAPI\command;
5+
6+
use pocketmine\command\CommandSender;
7+
use pocketmine\player\Player;
8+
use space\yurisi\SecureCoinAPI\History;
9+
use space\yurisi\SecureCoinAPI\SecureCoinAPI;
10+
11+
class givecoinCommand extends SecureCoinCommand{
12+
13+
public function __construct(private SecureCoinAPI $main) {
14+
parent::__construct('givecoin', '自分のお金を他人に譲渡します。', '/givecoin [playerName] [amount]');
15+
$this->setPermission("space.yurisi.SecureCoinAPI.givecoin");
16+
}
17+
18+
public function execute(CommandSender $sender, string $commandLabel, array $args) {
19+
if (!$this->testPermission($sender)) return;
20+
21+
$amount = $this->getAmount($args, $sender);
22+
23+
if (!$sender instanceof Player){
24+
$sender->sendMessage('ゲーム内で実行してください。');
25+
return;
26+
}
27+
$receive_player = $this->getPlayer($args[0]);
28+
$sent_player = $sender->getName();
29+
30+
if (!$this->main->isRegister($receive_player) || !$this->main->isRegister($sent_player)) {
31+
$sender->sendMessage("対象が存在しません。");
32+
return;
33+
}
34+
35+
if ($receive_player == $sent_player) {
36+
$sender->sendMessage("自分自身には渡せません。");
37+
return;
38+
}
39+
40+
if($this->main->getCoin($sent_player) < $amount){
41+
$sender->sendMessage("お金が足りません。");
42+
return;
43+
}
44+
45+
$this->main->addCoin(new History(
46+
$receive_player,
47+
$sent_player,
48+
$amount,
49+
$this->main->getName(),
50+
$this->getDescription()
51+
));
52+
53+
$this->main->takeCoin(new History(
54+
$sent_player,
55+
$receive_player,
56+
$amount,
57+
$this->main->getName(),
58+
$this->getDescription()
59+
));
60+
61+
$sender->sendMessage("§c{$receive_player}{$amount}円を渡しました");
62+
}
63+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ class mycoinCommand extends SecureCoinCommand {
1212

1313
public function __construct(private SecureCoinAPI $main) {
1414
parent::__construct("mycoin", "所持金を確認します", "/mycoin");
15+
$this->setPermission("space.yurisi.SecureCoinAPI.mycoin");
1516
}
1617

1718
public function execute(CommandSender $sender, string $commandLabel, array $args) {
19+
if (!$this->testPermission($sender)) return;
1820
if (!$sender instanceof Player) {
1921
$sender->sendMessage("プレイヤーのみ実行できるコマンドです");
2022
return;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
namespace space\yurisi\SecureCoinAPI\command;
44

55
use pocketmine\command\CommandSender;
6-
use pocketmine\player\Player;
76
use space\yurisi\SecureCoinAPI\SecureCoinAPI;
87

98
class seecoinCommand extends SecureCoinCommand {
109

1110
public function __construct(private SecureCoinAPI $main) {
1211
parent::__construct("seecoin", "プレイヤーのお金を確認します", "/seecoin [playerName]");
12+
$this->setPermission("space.yurisi.SecureCoinAPI.seecoin");
1313
}
1414

1515
public function execute(CommandSender $sender, string $commandLabel, array $args) {
16+
if (!$this->testPermission($sender)) return;
17+
1618
if (!isset($args[0])) {
1719
$sender->sendMessage($this->getUsage());
1820
return;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ class setcoinCommand extends SecureCoinCommand {
1212

1313
public function __construct(private SecureCoinAPI $main) {
1414
parent::__construct("setcoin", 'プレイヤーのお金を変更します。', '/setcoin [playerName] [amount]');
15+
$this->setPermission("space.yurisi.SecureCoinAPI.setcoin");
1516
}
1617

1718
public function execute(CommandSender $sender, string $commandLabel, array $args) {
19+
if (!$this->testPermission($sender)) return;
20+
1821
$amount = $this->getAmount($args, $sender);
1922

2023
if($amount == null) return;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ class takecoinCommand extends SecureCoinCommand {
1111

1212
public function __construct(private SecureCoinAPI $main) {
1313
parent::__construct("takecoin", "プレイヤーからお金を奪います", "/takecoin [playerName] [amount]");
14+
$this->setPermission("space.yurisi.SecureCoinAPI.takecoin");
1415
}
1516

1617
public function execute(CommandSender $sender, string $commandLabel, array $args) {
18+
if (!$this->testPermission($sender)) return;
19+
1720
$amount = $this->getAmount($args, $sender);
1821

1922
if($amount == null) return;

src/space/yurisi/SecureCoinAPI/database/historySQLite.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function registerHistory(History $history) {
2828
$this->history[] = $history;
2929
}
3030

31+
public function getHistoryCount(): int {
32+
return count($this->history);
33+
}
34+
3135
public function save() {
3236
if (count($this->history) <= 0) return;
3337
$value = [];

0 commit comments

Comments
 (0)