small improvement to cache class

This commit is contained in:
xGinko 2023-11-20 08:31:23 +01:00
parent 1d52156029
commit 19d223a16c
2 changed files with 8 additions and 8 deletions

View File

@ -25,12 +25,12 @@ public final class VillagerCache {
public @Nullable WrappedVillager get(@NotNull UUID uuid) { public @Nullable WrappedVillager get(@NotNull UUID uuid) {
WrappedVillager wrappedVillager = this.villagerCache.getIfPresent(uuid); WrappedVillager wrappedVillager = this.villagerCache.getIfPresent(uuid);
return wrappedVillager == null && Bukkit.getEntity(uuid) instanceof Villager villager ? add(villager) : wrappedVillager; return wrappedVillager == null && Bukkit.getEntity(uuid) instanceof Villager villager ? this.add(villager) : wrappedVillager;
} }
public @NotNull WrappedVillager getOrAdd(@NotNull Villager villager) { public @NotNull WrappedVillager getOrAdd(@NotNull Villager villager) {
WrappedVillager wrappedVillager = this.villagerCache.getIfPresent(villager.getUniqueId()); WrappedVillager wrappedVillager = this.villagerCache.getIfPresent(villager.getUniqueId());
return wrappedVillager == null ? add(new WrappedVillager(villager)) : add(wrappedVillager); return wrappedVillager == null ? this.add(new WrappedVillager(villager)) : this.add(wrappedVillager);
} }
public @NotNull WrappedVillager add(@NotNull WrappedVillager villager) { public @NotNull WrappedVillager add(@NotNull WrappedVillager villager) {
@ -47,10 +47,10 @@ public final class VillagerCache {
} }
public boolean contains(@NotNull WrappedVillager villager) { public boolean contains(@NotNull WrappedVillager villager) {
return this.villagerCache.getIfPresent(villager.villager().getUniqueId()) != null; return this.contains(villager.villager().getUniqueId());
} }
public boolean contains(@NotNull Villager villager) { public boolean contains(@NotNull Villager villager) {
return this.villagerCache.getIfPresent(villager.getUniqueId()) != null; return this.contains(villager.getUniqueId());
} }
} }

View File

@ -25,12 +25,12 @@ public final class VillagerCache {
public @Nullable WrappedVillager get(@NotNull UUID uuid) { public @Nullable WrappedVillager get(@NotNull UUID uuid) {
WrappedVillager wrappedVillager = this.villagerCache.getIfPresent(uuid); WrappedVillager wrappedVillager = this.villagerCache.getIfPresent(uuid);
return wrappedVillager == null && Bukkit.getEntity(uuid) instanceof Villager villager ? add(villager) : wrappedVillager; return wrappedVillager == null && Bukkit.getEntity(uuid) instanceof Villager villager ? this.add(villager) : wrappedVillager;
} }
public @NotNull WrappedVillager getOrAdd(@NotNull Villager villager) { public @NotNull WrappedVillager getOrAdd(@NotNull Villager villager) {
WrappedVillager wrappedVillager = this.villagerCache.getIfPresent(villager.getUniqueId()); WrappedVillager wrappedVillager = this.villagerCache.getIfPresent(villager.getUniqueId());
return wrappedVillager == null ? add(new WrappedVillager(villager)) : add(wrappedVillager); return wrappedVillager == null ? this.add(new WrappedVillager(villager)) : this.add(wrappedVillager);
} }
public @NotNull WrappedVillager add(@NotNull WrappedVillager villager) { public @NotNull WrappedVillager add(@NotNull WrappedVillager villager) {
@ -47,10 +47,10 @@ public final class VillagerCache {
} }
public boolean contains(@NotNull WrappedVillager villager) { public boolean contains(@NotNull WrappedVillager villager) {
return this.villagerCache.getIfPresent(villager.villager().getUniqueId()) != null; return this.contains(villager.villager().getUniqueId());
} }
public boolean contains(@NotNull Villager villager) { public boolean contains(@NotNull Villager villager) {
return this.villagerCache.getIfPresent(villager.getUniqueId()) != null; return this.contains(villager.getUniqueId());
} }
} }