22
33import net .azisaba .kdstatusreloaded .playerkd .model .KDUserData ;
44import net .azisaba .kdstatusreloaded .playerkd .db .KDUserDataRepository ;
5+ import org .bukkit .Bukkit ;
56import org .jspecify .annotations .NullMarked ;
67
78import java .util .Calendar ;
89import java .util .HashMap ;
910import java .util .UUID ;
11+ import java .util .function .Supplier ;
1012
1113@ NullMarked
1214public class KDCache {
@@ -19,24 +21,32 @@ public KDCache(KDUserDataRepository dataRepository) {
1921 }
2022
2123 public KDUserData getData (UUID uuid ) {
22- return get (uuid ).clone ();
24+ return get (uuid , () -> {
25+ var findResult = Bukkit .getOnlinePlayers ().stream ().filter (p -> p .getUniqueId () == uuid ).findFirst ();
26+ if (findResult .isEmpty ()) throw new RuntimeException ("Failed to get name for " + uuid );
27+ return findResult .get ().getName ();
28+ }).clone ();
2329 }
2430
2531 // For internal
26- protected KDUserData get (UUID uuid ) {
32+ protected KDUserData get (UUID uuid , String name ) {
33+ return get (uuid , () -> name );
34+ }
35+
36+ protected KDUserData get (UUID uuid , Supplier <String > nameSupplier ) {
2737 if (!cacheMap .containsKey (uuid )) {
2838 cacheMap .put (
2939 uuid ,
30- dataRepository .findById (uuid ).orElse (new KDUserData (uuid , "" ))
40+ dataRepository .findById (uuid ).orElse (new KDUserData (uuid , nameSupplier . get () ))
3141 );
3242 }
3343 return cacheMap .get (uuid );
3444 }
3545
36- public void store (UUID uuid ) {
46+ public void store (UUID uuid , String name ) {
3747 cacheMap .put (
3848 uuid ,
39- dataRepository .findById (uuid ).orElse (new KDUserData (uuid , "" ))
49+ dataRepository .findById (uuid ).orElse (new KDUserData (uuid , name ))
4050 );
4151 }
4252
@@ -57,8 +67,8 @@ public void removeAll() {
5767 }
5868
5969 // 責務を超えてしまうが、ここにkill/deathのincrement処理を追記する。
60- public void addKill (UUID uuid , int count ) {
61- KDUserData kdUserData = get (uuid );
70+ public void addKill (UUID uuid , String name , int count ) {
71+ KDUserData kdUserData = get (uuid , name );
6272 kdUserData .totalKills += count ;
6373
6474 fixCorrectValue (kdUserData );
@@ -69,8 +79,8 @@ public void addKill(UUID uuid, int count) {
6979 updateTimestamp (kdUserData );
7080 }
7181
72- public void addDeath (UUID uuid , int count ) {
73- KDUserData kdUserData = get (uuid );
82+ public void addDeath (UUID uuid , String name , int count ) {
83+ KDUserData kdUserData = get (uuid , name );
7484 kdUserData .deaths += count ;
7585
7686 updateTimestamp (kdUserData );
0 commit comments