Skip to content

Commit 375d136

Browse files
authored
Merge pull request #41 from AzisabaNetwork/feat/define-api
APIを定義する
2 parents 4dc2c78 + dfcdd3e commit 375d136

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
11
# v2 is under development. Don't use this!!!
2+
3+
## Todo
4+
- `/kdstatus refresh-cache`の実装
5+
6+
## 開発上の注意
7+
- パッチバージョンで破壊的変更を行わないでください。
8+
- 適切なバージョニングを心がけてください。
9+
- APIの仕様変更をする場合\
10+
すぐに、APIからメソッドを消すのではなく、`@Deprecated`を2つ以上先のマイナーバージョンに向けて付けること
11+
12+
## APIの仕様
13+
- このAPIは読み取り専用であり、書き込み等は行えない。
14+
- APIの使用時には、毎回`KDStatusReloaded.getAPI()`を行うことが推奨される。\
15+
(プラグインの再読み込み等により、内部の値が変化している可能性があるため)
16+
- APIは、同じマイナーバージョン内では破壊的変更が行われることはない。
17+
18+
## 運用上の注意
19+
- APIのキャッシュ等は時間ベースではなく、変化したタイミングで行なっている。 \
20+
そのため、データベースを直接書き換える等の操作が行われた場合には手動で`/kdstatus refresh-cache`を行う必要性がある。
21+
- データベースへの接続のヘルスチェックはconfig内で設定された間隔で行います\
22+
状況に応じて、適切な間隔に設定してください。
23+
24+
## データベース切り替え
25+
このKDStatusReloadedでは、複数のデータベースがサポートされており、切り替えることができます。\
26+
切り替えコマンドは、`/kdstatus switch-db <db-alias>`となっています。\
27+
db-aliasは、
28+
29+
| データベース名 | db-alias |
30+
|---------|----------|
31+
| MySQL | mysql |
32+
| MariaDB | mariadb |
33+
| SQLite3 | sqlite3 |
34+
となっています。
35+
36+
## 緊急時
37+
- メインデータベースへ接続が不可能になった場合には、sqlite3を用いて、ローカルに自動的に保存されます。
38+
- もしも、APIも何もかも死んだ時には、`/kdstatus force-reload`をかけることでこれらのタスクが走ります。
39+
- データベースへ再接続
40+
- キャッシュの再取得
41+
- APIのリフレッシュ

src/main/java/jp/azisaba/lgw/kdstatus/api/KDAPIInterface.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,26 @@
1414
*/
1515
interface KDAPIInterface {
1616
/**
17-
* Get specific user's data
17+
* Get specific user's data. If data wasn't found, create new userdata.
1818
* @param uuid UUID of player
1919
* @param name Name of player
20+
* @return returns KDUserData.
21+
*/
22+
@NotNull
23+
KDUserData getOrCreateUserData(@NotNull UUID uuid, @NotNull String name);
24+
25+
/**
26+
* Get specific user's data
27+
* @param uuid UUID of player
2028
* @return returns KDUserData. If failed, returns null.
2129
*/
2230
@Nullable
23-
KDUserData getUserData(@NotNull UUID uuid, @NotNull String name);
31+
KDUserData getUserData(@NotNull UUID uuid);
2432

2533
/**
2634
* Get specific user's ranking
2735
* @param uuid UUID of player
28-
* @param unit Name of player
36+
* @param unit Unit of ranking
2937
* @return returns ranking order. If failed, returns -1.
3038
*/
3139
int getRank(@NotNull UUID uuid, @NotNull TimeUnit unit);
@@ -37,4 +45,28 @@ interface KDAPIInterface {
3745
* @return List of {@link KillRankingData}. If failed, returns empty list.
3846
*/
3947
List<KillRankingData> getTopKillRankingData(@NotNull TimeUnit unit, int maxSize);
48+
49+
// === Won't need to implement each ===
50+
/**
51+
* Get specific user's kill count
52+
* @param uuid UUID of player
53+
* @param unit Unit of ranking
54+
* @return returns kill count. If failed, returns -1.
55+
*/
56+
default int getKills(@NotNull UUID uuid, @NotNull TimeUnit unit) {
57+
var userdata = getUserData(uuid);
58+
if(userdata == null) return -1;
59+
return userdata.getKills(unit);
60+
}
61+
62+
/**
63+
* Get specific user's death count
64+
* @param uuid UUID of player
65+
* @return returns total death count. If failed, returns -1
66+
*/
67+
default int getDeaths(@NotNull UUID uuid) {
68+
var userdata = getUserData(uuid);
69+
if(userdata == null) return -1;
70+
return userdata.getDeaths();
71+
}
4072
}

0 commit comments

Comments
 (0)