Skip to content

Commit

Permalink
Clear kill tracker after dying in Dodgeball
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Nov 17, 2024
1 parent c8e6aac commit 9ef7dcb
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
import java.util.Map;
import java.util.Optional;

public record ImmediateRespawnBehavior(Optional<PlayerRole> role, Optional<PlayerRole> respawnAsRole, Optional<TemplatedText> deathMessage, boolean dropInventory, GameActionList<ServerPlayer> respawnAction, boolean spectateKiller) implements IGameBehavior {
public record ImmediateRespawnBehavior(Optional<PlayerRole> role, Optional<PlayerRole> respawnAsRole, Optional<TemplatedText> deathMessage, boolean dropInventory, GameActionList<ServerPlayer> respawnAction, boolean spectateKiller, boolean clearKillTracker) implements IGameBehavior {
public static final MapCodec<ImmediateRespawnBehavior> CODEC = RecordCodecBuilder.mapCodec(i -> i.group(
PlayerRole.CODEC.optionalFieldOf("role").forGetter(c -> c.role),
PlayerRole.CODEC.optionalFieldOf("respawn_as").forGetter(c -> c.respawnAsRole),
TemplatedText.CODEC.optionalFieldOf("death_message").forGetter(c -> c.deathMessage),
Codec.BOOL.optionalFieldOf("drop_inventory", false).forGetter(c -> c.dropInventory),
GameActionList.PLAYER_CODEC.optionalFieldOf("respawn_action", GameActionList.EMPTY).forGetter(c -> c.respawnAction),
Codec.BOOL.optionalFieldOf("spectate_killer", true).forGetter(c -> c.spectateKiller)
Codec.BOOL.optionalFieldOf("spectate_killer", true).forGetter(c -> c.spectateKiller),
Codec.BOOL.optionalFieldOf("clear_kill_tracker", false).forGetter(c -> c.clearKillTracker)
).apply(i, ImmediateRespawnBehavior::new));

@Override
Expand Down Expand Up @@ -76,6 +77,14 @@ private void respawnPlayer(IGamePhase game, ServerPlayer player, @Nullable Playe
player.fallDistance = 0.0f;

respawnAction.apply(game, GameActionContext.EMPTY, player);

if (clearKillTracker) {
for (ServerPlayer otherPlayer : game.participants()) {
if (otherPlayer.getKillCredit() == player) {
otherPlayer.setLastHurtByPlayer(null);
}
}
}
}

private void sendDeathMessage(IGamePhase game, ServerPlayer player) {
Expand Down

0 comments on commit 9ef7dcb

Please sign in to comment.