FFAPvP   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 122
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A register() 0 5 1
A unregister() 0 4 1
A get() 0 4 1
A add() 0 4 1
A addKill() 0 4 1
A addDeath() 0 4 1
A addExp() 0 4 1
A getRankingByKill() 0 4 1
A getRankingByExp() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: UramnOIL
5
 * Date: 2018/10/06
6
 * Time: 22:46
7
 */
8
9
namespace VectorNetworkProject\DataProvider\Tables\FFAPvP;
10
11
use pocketmine\IPlayer;
12
use VectorNetworkProject\DataProvider\Tables\TableBase;
13
14
class FFAPvP extends TableBase
15
{
16
	public const INIT					= 'userdataprovider.ffapvp.init';
17
	public const REGISTER				= 'userdataprovider.ffapvp.register';
18
	public const UNREGISTER				= 'userdataprovider.ffapvp.unregister';
19
	public const GET					= 'userdataprovider.ffapvp.get';
20
	public const ADD_COUNT				= 'userdataprovider.ffapvp.addcount';
21
	public const GET_RANKING_BY_KILL	= 'userdataprovider.ffapvp.getrankingbykill';
22
	public const GET_RANKING_BY_EXP		= 'userdataprovider.ffapvp.getrankingbyexp';
23
24
	public function init(): void
25
	{
26
		$this->connector->executeGeneric(self::INIT);
27
	}
28
29
	/**
30
	 * プレイヤーを登録します。
31
	 *
32
	 * @param IPlayer $player
33
	 * @param callable|null $onInserted
34
	 * @param callable|null $onError
35
	 */
36
	public function register(IPLayer $player, ?callable $onInserted = null, ?callable $onError = null): void
37
	{
38
		$this->connector->executeInsert(self::REGISTER, [$player->getname()], $onInserted, $onError);
39
40
	}
41
42
	/**
43
	 * プレイヤーを登録解除します
44
	 *
45
	 * @param IPlayer $player
46
	 * @param callable|null $onSuccess
47
	 * @param callable|null $onError
48
	 */
49
	public function unregister(IPLayer $player, ?callable $onSuccess = null, ?callable $onError = null): void
50
	{
51
		$this->connector->executeChange(self::UNREGISTER, [$player->getName()], $onSuccess, $onError );
52
	}
53
54
	/**
55
	 * プレイヤーの情報を取得します
56
	 *
57
	 * @param IPlayer $player
58
	 * @param callable|null $onSuccess
59
	 * @param callable|null $onError
60
	 */
61
	public function get(IPlayer $player, callable $onSuccess = null, ?callable $onError = null): void
62
	{
63
		$this->connector->executeSelect(self::GET, [$player->getName()], $onSuccess, $onError);
64
	}
65
66
	/**
67
	 * プレイヤーのそれぞれのカウントを増やします
68
	 *
69
	 * @param IPlayer $player
70
	 * @param int $kill
71
	 * @param int $death
72
	 * @param int $exp
73
	 */
74
	public function add(IPlayer $player, int $kill = 0, int $death = 0, int $exp = 0)
75
	{
76
		$this->connector->executeChange(self::ADD_COUNT, [$player->getName(), $kill, $death, $exp]);
77
	}
78
79
	/**
80
	 * プレイヤーのキル数を増やします
81
	 *
82
	 * @param IPlayer $player
83
	 * @param int $kill
84
	 */
85
	public function addKill(IPlayer $player, int $kill)
86
	{
87
		$this->add($player, $kill);
88
	}
89
90
	/**
91
	 * プレイヤーのデス数を増やします
92
	 *
93
	 * @param IPlayer $player
94
	 * @param int $death
95
	 */
96
	public function addDeath(IPlayer $player, int $death)
97
	{
98
		$this->add($player, 0, $death);
99
	}
100
101
	/**
102
	 * プレイヤーのEXPを増やします
103
	 *
104
	 * @param IPlayer $player
105
	 * @param int $exp
106
	 */
107
	public function addExp(IPlayer $player,int $exp)
108
	{
109
		$this->add($player, 0, 0, $exp);
110
	}
111
112
	/**
113
	 * キル数のランキングを取得します
114
	 *
115
	 * @param int $limit
116
	 * @param callable|null $onSelect
117
	 * @param callable|null $onError
118
	 */
119
	public function getRankingByKill(int $limit, ?callable $onSelect = null, ?callable $onError = null): void
120
	{
121
		$this->connector->executeSelect(self::GET_RANKING_BY_KILL, [$limit], $onSelect, $onError);
122
	}
123
124
	/**
125
	 * EXPのランキングを取得します
126
	 *
127
	 * @param int $limit
128
	 * @param callable|null $onSelect
129
	 * @param callable|null $onError
130
	 */
131
	public function getRankingByExp(int $limit, ?callable $onSelect = null, ?callable $onError = null): void
132
	{
133
		$this->connector->executeSelect(self::GET_RANKING_BY_EXP, [$limit], $onSelect, $onError);
134
	}
135
}