Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 023235a

Browse files
authored
Merge pull request #23 from VectorNetworkProject/develop
Develop
2 parents c8b7de9 + 941a212 commit 023235a

File tree

6 files changed

+171
-10
lines changed

6 files changed

+171
-10
lines changed

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: DataProvider
2-
version: 0.2.0
2+
version: 0.3.0
33
api: 3.2
44
main: VectorNetworkProject\DataProvider\Main
55
prefix: DataProvider

resources/sqlite.sql

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,58 @@ FROM accounts
2727
WHERE name = :name;
2828
-- # }
2929
-- # }
30+
-- # { networklevel
31+
-- # { init
32+
CREATE TABLE IF NOT EXISTS networklevel(
33+
id INTEGER NOT NULL,
34+
exp INTEGER NOT NULL DEFAULT 0
35+
);
36+
-- # }
37+
-- # { register
38+
-- # :name string
39+
INSERT INTO networklevel(
40+
id
41+
)
42+
SELECT id
43+
FROM accounts
44+
WHERE name = :name;
45+
-- # }
46+
-- # { unregister
47+
-- # :name string
48+
DELETE FROM networklevel
49+
WHERE id
50+
IN (
51+
SELECT accounts.id
52+
FROM networklevel
53+
INNER JOIN accounts
54+
ON networklevel.id = accounts.id
55+
WHERE accounts.name = :name
56+
);
57+
-- # }
58+
-- # { get
59+
-- # :name string
60+
SELECT accounts.id, accounts.name, networklevel.exp
61+
FROM networklevel
62+
INNER JOIN accounts
63+
ON networklevel.id = accounts.id
64+
WHERE accounts.name = :name;
65+
-- # }
66+
-- # { add
67+
-- # :name string
68+
-- # :exp int
69+
UPDATE networklevel
70+
SET exp = exp + :exp
71+
WHERE id IN (
72+
SELECT networklevel.id
73+
FROM networklevel
74+
INNER JOIN accounts
75+
ON (
76+
accounts.id = networklevel.id
77+
)
78+
WHERE accounts.name = :name
79+
);
80+
-- # }
81+
-- # }
3082
-- # { ffapvp
3183
-- # { init
3284
CREATE TABLE IF NOT EXISTS ffapvp(

src/VectorNetworkProject/DataProvider/Tables/CorePvP/CorePvP.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function init(): void
3232
* @param callable|null $onSuccess
3333
* @param callable|null $onError
3434
*/
35-
public function regsiter(IPlayer $player, ?callable $onSuccess = null, ?callable $onError = null): void
35+
public function register(IPlayer $player, ?callable $onSuccess = null, ?callable $onError = null): void
3636
{
3737
$this->connector->executeInsert(self::REGISTER, [$player->getname()], $onSuccess, $onError);
3838
}
@@ -42,7 +42,7 @@ public function regsiter(IPlayer $player, ?callable $onSuccess = null, ?callable
4242
* @param callable $onSuccess
4343
* @param callable|null $onError
4444
*/
45-
public function unregister(IPlayer $player, callable $onSuccess, ?callable $onError = null): void
45+
public function unregister(IPlayer $player, ?callable $onSuccess = null, ?callable $onError = null): void
4646
{
4747
$this->connector->executeInsert(self::UNREGISTER, [$player->getname()], $onSuccess, $onError);
4848
}

src/VectorNetworkProject/DataProvider/Tables/Dual/Dual.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function init(): void
3232
* @param callable $onInserted
3333
* @param callable|null $onError
3434
*/
35-
public function register(IPlayer $player, callable $onInserted, ?callable $onError = null): void
35+
public function register(IPlayer $player, ?callable $onInserted = null, ?callable $onError = null): void
3636
{
3737
$this->connector->executeInsert(self::REGISTER, [$player->getName()], $onInserted, $onError);
3838
}
@@ -44,7 +44,7 @@ public function register(IPlayer $player, callable $onInserted, ?callable $onErr
4444
* @param callable|null $onSelect
4545
* @param callable|null $onError
4646
*/
47-
public function unregister(IPlayer $player, ?callable $onSelect, ?callable $onError = null): void
47+
public function unregister(IPlayer $player, ?callable $onSelect = null, ?callable $onError = null): void
4848
{
4949
$this->connector->executeChange(self::REGISTER, [$player->getName()], $onSelect, $onError);
5050
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: UramnOIL
5+
* Date: 2018/10/13
6+
* Time: 23:26
7+
*/
8+
9+
namespace VectorNetworkProject\DataProvider\Tables\NetworkLevel;
10+
11+
use pocketmine\IPlayer;
12+
use VectorNetworkProject\DataProvider\Tables\TableBase;
13+
14+
class NetworkLevel extends TableBase
15+
{
16+
public const INiT = 'databaseprovider.networklevel.init';
17+
public const REGISTER = 'databaseprovider.networklevel.register';
18+
public const UNREGISTER = 'databaseprovider.networklevel.unregister';
19+
public const GET = 'databaseprovider.networklevel.get';
20+
public const ADD = 'databaseprovider.networklevel.add';
21+
22+
public function init(): void
23+
{
24+
$this->connector->executeGeneric(self::INiT);
25+
}
26+
27+
/**
28+
* プレイヤーを登録します。
29+
*
30+
* @param IPlayer $player
31+
* @param callable|null $onInserted
32+
* @param callable|null $onError
33+
*/
34+
public function register(IPLayer $player, ?callable $onInserted = null, ?callable $onError = null): void
35+
{
36+
$this->connector->executeInsert(self::REGISTER, [$player->getname()], $onInserted, $onError);
37+
38+
}
39+
40+
/**
41+
* プレイヤーを登録解除します
42+
*
43+
* @param IPlayer $player
44+
* @param callable|null $onSuccess
45+
* @param callable|null $onError
46+
*/
47+
public function unregister(IPLayer $player, ?callable $onSuccess = null, ?callable $onError = null): void
48+
{
49+
$this->connector->executeChange(self::UNREGISTER, [$player->getName()], $onSuccess, $onError);
50+
}
51+
52+
/**
53+
* プレイヤーの情報を取得します
54+
*
55+
* @param IPlayer $player
56+
* @param callable|null $onSuccess
57+
* @param callable|null $onError
58+
*/
59+
public function get(IPlayer $player, callable $onSuccess = null, ?callable $onError = null): void
60+
{
61+
$this->connector->executeSelect(self::GET, [$player->getName()], $onSuccess, $onError);
62+
}
63+
64+
/**
65+
* プレイヤーのカウントを増やします
66+
*
67+
* @param IPlayer $player
68+
* @param int $exp
69+
* @param callable|null $onSuccess
70+
* @param callable|null $onError
71+
*/
72+
public function add(IPlayer $player, int $exp = 0, ?callable $onSuccess = null, ?callable $onError = null): void
73+
{
74+
$this->connector->executeChange(self::ADD, [$player->getName(), $exp], $onSuccess, $onError);
75+
}
76+
}

src/VectorNetworkProject/DataProvider/Tables/TableManager.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010

1111

1212
use poggit\libasynql\DataConnector;
13+
use pocketmine\IPlayer;
1314
use VectorNetworkProject\DataProvider\Tables\Accounts\Accounts;
1415
use VectorNetworkProject\DataProvider\Tables\CorePvP\CorePvP;
1516
use VectorNetworkProject\DataProvider\Tables\Dual\Dual;
1617
use VectorNetworkProject\DataProvider\Tables\FFAPvP\FFAPvP;
18+
use VectorNetworkProject\DataProvider\Tables\NetworkLevel\NetworkLevel;
1719

1820
class TableManager
1921
{
2022
/** @var DataConnector */
2123
protected $connector;
2224

25+
/** @var NetworkLevel */
26+
private $networklevel;
2327
/** @var Accounts */
2428
protected $accounts;
2529
/** @var FFAPvP */
@@ -29,12 +33,33 @@ class TableManager
2933
/** @var CorePvP */
3034
protected $corepvp;
3135

32-
public function __construct(DataConnector $connector) {
36+
public function __construct(DataConnector $connector)
37+
{
3338
$this->connector = $connector;
34-
$this->accounts = new Accounts($connector);
35-
$this->ffapvp = new FFAPvP($connector);
36-
$this->dual = new Dual($connector);
37-
$this->corepvp = new CorePvP($connector);
39+
40+
$this->networklevel = new NetworkLevel($connector);
41+
$this->accounts = new Accounts($connector);
42+
$this->ffapvp = new FFAPvP($connector);
43+
$this->dual = new Dual($connector);
44+
$this->corepvp = new CorePvP($connector);
45+
}
46+
47+
public function register(IPlayer $player)
48+
{
49+
$this->networklevel->register($player);
50+
$this->accounts->register($player);
51+
$this->ffapvp->register($player);
52+
$this->dual->register($player);
53+
$this->corepvp->register($player);
54+
}
55+
56+
public function unregister(IPlayer $player)
57+
{
58+
$this->networklevel->unregister($player);
59+
$this->accounts->unregister($player);
60+
$this->ffapvp->unregister($player);
61+
$this->dual->unregister($player);
62+
$this->corepvp->unregister($player);
3863
}
3964

4065
/**
@@ -45,6 +70,14 @@ public function getAccounts(): Accounts
4570
return $this->accounts;
4671
}
4772

73+
/**
74+
* @return NetworkLevel
75+
*/
76+
public function getNetworklevel(): NetworkLevel
77+
{
78+
return $this->networklevel;
79+
}
80+
4881
/**
4982
* @return FFAPvP
5083
*/

0 commit comments

Comments
 (0)