Skip to content

Commit

Permalink
Fix: Use OptionalInt instead of Optional<Integer>
Browse files Browse the repository at this point in the history
  • Loading branch information
Skullians committed Dec 28, 2024
1 parent 29616e7 commit ea8835c
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
import net.skullian.skyfactions.common.util.SkyLocation;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public abstract class SkyUser {

public final UUID uuid;
public final Optional<PlayerData> data = Optional.empty();
public Optional<Integer> gems = Optional.empty();
public Optional<Integer> runes = Optional.empty();
public OptionalInt gems = OptionalInt.empty();
public OptionalInt runes = OptionalInt.empty();
public Optional<PlayerIsland> island = Optional.empty();
public Optional<List<InviteData>> incomingInvites = Optional.empty();
public Optional<JoinRequestData> activeJoinRequest = Optional.empty();
Expand Down Expand Up @@ -54,11 +51,11 @@ public PlayerData getPlayerData() {
public CompletableFuture<Integer> getGems() {
if (this.gems.isEmpty()) return SkyApi.getInstance().getDatabaseManager().getCurrencyManager().getGems(this.uuid).whenComplete((gems, ex) -> {
if (ex != null) return;
this.gems = Optional.of((this.gems.orElse(0)) + gems);
this.gems = OptionalInt.of((this.gems.orElse(0)) + gems);
});

if (SkyApi.getInstance().getCacheService().getPlayersToCache().containsKey(this.uuid) && this.gems.isPresent()) return CompletableFuture.completedFuture((this.gems.get() + SkyApi.getInstance().getCacheService().getEntry(this.uuid).getGems()));
else return CompletableFuture.completedFuture(this.gems.get());
if (SkyApi.getInstance().getCacheService().getPlayersToCache().containsKey(this.uuid) && this.gems.isPresent()) return CompletableFuture.completedFuture((this.gems.getAsInt() + SkyApi.getInstance().getCacheService().getEntry(this.uuid).getGems()));
else return CompletableFuture.completedFuture(this.gems.getAsInt());
}

public void addGems(int amount) {
Expand All @@ -72,11 +69,11 @@ public void removeGems(int amount) {
public CompletableFuture<Integer> getRunes() {
if (this.runes.isEmpty()) return SkyApi.getInstance().getDatabaseManager().getCurrencyManager().getRunes(this.uuid).whenComplete((runes, ex) -> {
if (ex != null) return;
this.runes = Optional.of((this.runes.orElse(0)) + runes);
this.runes = OptionalInt.of((this.runes.orElse(0)) + runes);
});

if (SkyApi.getInstance().getCacheService().getPlayersToCache().containsKey(this.uuid) && this.runes.isPresent()) return CompletableFuture.completedFuture((this.runes.get() + SkyApi.getInstance().getCacheService().getEntry(this.uuid).getRunes()));
else return CompletableFuture.completedFuture(this.runes.get());
if (SkyApi.getInstance().getCacheService().getPlayersToCache().containsKey(this.uuid) && this.runes.isPresent()) return CompletableFuture.completedFuture((this.runes.getAsInt() + SkyApi.getInstance().getCacheService().getEntry(this.uuid).getRunes()));
else return CompletableFuture.completedFuture(this.runes.getAsInt());
}

public void addRunes(int amount) {
Expand Down Expand Up @@ -109,8 +106,8 @@ public List<InviteData> getCachedInvites() {
}

public void onCacheComplete(int runesAddition, int gemsAddition) {
this.runes = Optional.of(this.runes.orElse(runesAddition));
this.gems = Optional.of(this.gems.orElse(gemsAddition));
this.runes = OptionalInt.of(this.runes.orElse(runesAddition));
this.gems = OptionalInt.of(this.gems.orElse(gemsAddition));
}

@Nullable public abstract CompletableFuture<JoinRequestData> getActiveJoinRequest();
Expand Down

0 comments on commit ea8835c

Please sign in to comment.