Skip to content

Commit 427b7d4

Browse files
committed
Remove entry when entity goes invalid.
1 parent 7814b62 commit 427b7d4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/java/io/izzel/mesmerize/impl/service/SimpleStatsService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class SimpleStatsService implements StatsService {
4949

5050
private final CacheLoader<Entity, StatsSet> cacheLoader = entity -> {
5151
if (!entity.isValid() || entity.isDead()) {
52-
return new StatsSet();
52+
return null;
5353
}
5454
Callable<StatsSet> callable = () -> {
5555
StatsSet statsSet = new StatsSet();
@@ -94,15 +94,17 @@ public StatsSet cachedSetFor(@NotNull Entity entity) {
9494
if (!Bukkit.isPrimaryThread()) {
9595
throw new IllegalStateException("async stats get");
9696
}
97+
StatsSet set;
9798
if (entityLock.contains(entity.getEntityId())) {
9899
try {
99-
return cacheLoader.load(entity);
100+
set = cacheLoader.load(entity);
100101
} catch (Exception e) {
101102
throw new RuntimeException(e);
102103
}
103104
} else {
104-
return statsSetCache.get(entity);
105+
set = statsSetCache.get(entity);
105106
}
107+
return set == null ? new StatsSet() : set;
106108
}
107109

108110
@Override

0 commit comments

Comments
 (0)