File tree Expand file tree Collapse file tree 4 files changed +24
-43
lines changed
src/main/java/net/azisaba/kdstatusreloaded Expand file tree Collapse file tree 4 files changed +24
-43
lines changed Original file line number Diff line number Diff line change 1+ package net .azisaba .kdstatusreloaded .api ;
2+
3+ import net .azisaba .kdstatusreloaded .KDStatusReloaded ;
4+ import net .azisaba .kdstatusreloaded .playerkd .model .KDUserData ;
5+
6+ import java .util .Optional ;
7+ import java .util .UUID ;
8+
9+ public class KDSAPI {
10+ public static KDUserData getPlayerData (UUID uuid ) {
11+ Optional <KDUserData > data = KDStatusReloaded .getPlugin ().getPlayerKd ().getPlayerDataWithNoCaching (uuid );
12+ return data .orElseGet (() -> new KDUserData (uuid , "" ));
13+ }
14+ }
Original file line number Diff line number Diff line change 77import net .azisaba .kdstatusreloaded .playerkd .listener .PlayerEventListener ;
88
99import java .util .List ;
10+ import java .util .Optional ;
1011import java .util .UUID ;
1112
1213public class PlayerKD {
@@ -32,6 +33,11 @@ public KDUserData getPlayerData(UUID uuid) {
3233 return kdCache .get (uuid );
3334 }
3435
36+ public Optional <KDUserData > getPlayerDataWithNoCaching (UUID uuid ) {
37+ if (kdCache .isCached (uuid )) return Optional .of (kdCache .get (uuid ));
38+ return kdDatabase .kdUserDataRepository ().findById (uuid );
39+ }
40+
3541 public void migrate () {
3642 kdDatabase .migration ();
3743 }
Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ public void remove(UUID uuid) {
4343 }
4444 }
4545
46+ public boolean isCached (UUID uuid ) {
47+ return cacheMap .containsKey (uuid );
48+ }
49+
4650 public void removeAll () {
4751 cacheMap .forEach ((uuid , kdUserData ) -> dataRepository .upsert (kdUserData ));
4852 }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments