Skip to content

Commit

Permalink
Fix profiled data null problems
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Jan 11, 2025
1 parent ac94594 commit ade16c2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.option(ButtonOption.createBuilder()
.name(Text.translatable("skyblocker.config.otherLocations.end.resetName"))
.text(Text.translatable("skyblocker.config.otherLocations.end.resetText"))
.action((screen, opt) -> TheEnd.PROFILES_STATS.put(TheEnd.EndStats.EMPTY))
.action((screen, opt) -> TheEnd.PROFILES_STATS.put(TheEnd.EndStats.EMPTY.get()))
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.otherLocations.end.muteEndermanSounds"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Set<Location> availableLocations() {
public void updateContent() {
// Zealots
if (SkyblockerConfigManager.get().otherLocations.end.zealotKillsEnabled) {
TheEnd.EndStats endStats = TheEnd.PROFILES_STATS.putIfAbsent(TheEnd.EndStats.EMPTY);
TheEnd.EndStats endStats = TheEnd.PROFILES_STATS.computeIfAbsent(TheEnd.EndStats.EMPTY);
addComponent(new IcoTextComponent(ENDERMAN_HEAD, Text.literal("Zealots").formatted(Formatting.BOLD)));
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.zealotsSinceLastEye", endStats.zealotsSinceLastEye())));
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.zealotsTotalKills", endStats.totalZealotKills())));
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/de/hysky/skyblocker/skyblock/end/TheEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.function.Supplier;

public class TheEnd {
protected static final Logger LOGGER = LoggerFactory.getLogger(TheEnd.class);
Expand Down Expand Up @@ -132,7 +136,7 @@ private static void resetLocation() {
public static void onEntityDeath(Entity entity) {
if (!(entity instanceof EndermanEntity enderman) || !isZealot(enderman)) return;
if (hitZealots.contains(enderman.getUuid())) {
EndStats stats = PROFILES_STATS.putIfAbsent(EndStats.EMPTY);
EndStats stats = PROFILES_STATS.computeIfAbsent(EndStats.EMPTY);
if (isSpecialZealot(enderman)) {
PROFILES_STATS.put(new EndStats(stats.totalZealotKills() + 1, 0, stats.eyes() + 1));
} else {
Expand Down Expand Up @@ -172,7 +176,7 @@ public record EndStats(int totalZealotKills, int zealotsSinceLastEye, int eyes)
Codec.INT.fieldOf("zealotsSinceLastEye").forGetter(EndStats::zealotsSinceLastEye),
Codec.INT.fieldOf("eyes").forGetter(EndStats::eyes)
).apply(instance, EndStats::new));
public static final EndStats EMPTY = new EndStats(0, 0, 0);
public static final Supplier<EndStats> EMPTY = () -> new EndStats(0, 0, 0);
}

public record ProtectorLocation(int x, int z, Text name, Waypoint waypoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void handleClick(Slot slot, int slotId, DefaultedList<Slot> slots)
String profileId = Utils.getProfileId();

if (!itemId.isEmpty() && !profileId.isEmpty()) {
MUSEUM_ITEM_CACHE.putIfAbsent(ProfileMuseumData.EMPTY.get()).collectedItemIds().add(itemId);
MUSEUM_ITEM_CACHE.computeIfAbsent(ProfileMuseumData.EMPTY).collectedItemIds().add(itemId);
MUSEUM_ITEM_CACHE.save();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,22 @@ public T get(UUID uuid, String profileId) {
return getPlayerData(uuid).get(profileId);
}

@Nullable
public T put(T value) {
return put(Utils.getUuid(), Utils.getProfileId(), value);
}

@Nullable
public T put(UUID uuid, String profileId, T value) {
return getPlayerData(uuid).put(profileId, value);
}

@Nullable
public T putIfAbsent(T value) {
return putIfAbsent(Utils.getUuid(), Utils.getProfileId(), value);
}

@Nullable
public T putIfAbsent(UUID uuid, String profileId, T value) {
return getPlayerData(uuid).putIfAbsent(profileId, value);
}
Expand All @@ -155,10 +159,12 @@ public T computeIfAbsent(UUID uuid, String profileId, Supplier<T> valueSupplier)
return getPlayerData(uuid).computeIfAbsent(profileId, _profileId -> valueSupplier.get());
}

@Nullable
public T remove() {
return remove(Utils.getUuid(), Utils.getProfileId());
}

@Nullable
public T remove(UUID uuid, String profileId) {
return getPlayerData(uuid).remove(profileId);
}
Expand Down

0 comments on commit ade16c2

Please sign in to comment.