Skip to content

Commit

Permalink
fix: Fix crash on revival #144
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Nov 4, 2024
1 parent fd7af22 commit 1434879
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.blay09.mods.hardcorerevival;

import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;

class InMemoryPlayerRevivalData {
private boolean knockedOut;
Expand Down Expand Up @@ -68,11 +69,12 @@ public void setRescueTime(int rescueTime) {
this.rescueTime = rescueTime;
}

@Nullable
public Player getRescueTarget() {
return rescueTarget;
}

public void setRescueTarget(Player rescueTarget) {
public void setRescueTarget(@Nullable Player rescueTarget) {
this.rescueTarget = rescueTarget;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.blay09.mods.hardcorerevival;

import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -85,7 +86,7 @@ public int getRescueTime(Player player) {
}

@Override
public void setRescueTarget(Player player, Player rescueTarget) {
public void setRescueTarget(Player player, @Nullable Player rescueTarget) {
getPlayerData(player).setRescueTarget(rescueTarget);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.blay09.mods.balm.api.Balm;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;

public class PersistentRevivalDataProvider implements RevivalDataProvider {

Expand Down Expand Up @@ -93,8 +94,12 @@ public int getRescueTime(Player player) {
}

@Override
public void setRescueTarget(Player player, Player rescueTarget) {
getRevivalData(player).putUUID(RESCUE_TARGET, rescueTarget.getGameProfile().getId());
public void setRescueTarget(Player player, @Nullable Player rescueTarget) {
if (rescueTarget != null) {
getRevivalData(player).putUUID(RESCUE_TARGET, rescueTarget.getGameProfile().getId());
} else {
getRevivalData(player).remove(RESCUE_TARGET);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ public static int getRescueTime(Player player) {
return getRevivalDataProvider(player.level()).getRescueTime(player);
}

public static void setRescueTarget(Player player, Player rescueTarget) {
public static void setRescueTarget(Player player, @Nullable Player rescueTarget) {
getRevivalDataProvider(player.level()).setRescueTarget(player, rescueTarget);
}

@Nullable
public static Player getRescueTarget(Player player) {
return getRevivalDataProvider(player.level()).getRescueTarget(player);
}
Expand Down

0 comments on commit 1434879

Please sign in to comment.