improve it
This commit is contained in:
parent
5f0c4e2f00
commit
a0ad960b17
@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import me.xginko.villageroptimizer.models.WrappedVillager;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
@ -16,37 +17,37 @@ public class VillagerCache {
|
||||
|
||||
protected VillagerCache() {}
|
||||
|
||||
public Collection<WrappedVillager> getAll() {
|
||||
public @NotNull Collection<WrappedVillager> getAll() {
|
||||
return this.villagerCache.asMap().values();
|
||||
}
|
||||
|
||||
public @Nullable WrappedVillager get(UUID uuid) {
|
||||
public @Nullable WrappedVillager get(@NotNull UUID uuid) {
|
||||
return villagerCache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
public WrappedVillager getOrAddIfAbsent(Villager villager) {
|
||||
public @NotNull WrappedVillager getOrAddIfAbsent(@NotNull Villager villager) {
|
||||
WrappedVillager wrappedVillager = villagerCache.getIfPresent(villager.getUniqueId());
|
||||
if (wrappedVillager == null) wrappedVillager = new WrappedVillager(villager);
|
||||
this.villagerCache.put(villager.getUniqueId(), wrappedVillager); // refresh cache
|
||||
return wrappedVillager;
|
||||
}
|
||||
|
||||
public WrappedVillager add(WrappedVillager villager) {
|
||||
public @NotNull WrappedVillager add(@NotNull WrappedVillager villager) {
|
||||
villagerCache.put(villager.villager().getUniqueId(), villager);
|
||||
return villager;
|
||||
}
|
||||
|
||||
public WrappedVillager add(Villager villager) {
|
||||
public @NotNull WrappedVillager add(@NotNull Villager villager) {
|
||||
WrappedVillager wrapped = new WrappedVillager(villager);
|
||||
villagerCache.put(villager.getUniqueId(), wrapped);
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
public boolean contains(WrappedVillager villager) {
|
||||
public boolean contains(@NotNull WrappedVillager villager) {
|
||||
return villagerCache.getIfPresent(villager.villager().getUniqueId()) != null;
|
||||
}
|
||||
|
||||
public boolean contains(Villager villager) {
|
||||
public boolean contains(@NotNull Villager villager) {
|
||||
return villagerCache.getIfPresent(villager.getUniqueId()) != null;
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public final class VillagerOptimizer extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
logger = getLogger();
|
||||
villagerCache = new VillagerCache();
|
||||
|
||||
logger.info("Loading Translations");
|
||||
reloadLang();
|
||||
|
Loading…
x
Reference in New Issue
Block a user