-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add deaths statistic and leaderboard to Dodgeball
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ropics/minigames/common/core/game/behavior/instances/action/IncrementStatisticAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.lovetropics.minigames.common.core.game.behavior.instances.action; | ||
|
||
import com.lovetropics.minigames.common.core.game.IGamePhase; | ||
import com.lovetropics.minigames.common.core.game.behavior.GameBehaviorType; | ||
import com.lovetropics.minigames.common.core.game.behavior.GameBehaviorTypes; | ||
import com.lovetropics.minigames.common.core.game.behavior.IGameBehavior; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.EventRegistrar; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.GameActionEvents; | ||
import com.lovetropics.minigames.common.core.game.state.statistics.StatisticKey; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public record IncrementStatisticAction(StatisticKey<Integer> statistic, int amount) implements IGameBehavior { | ||
public static final MapCodec<IncrementStatisticAction> CODEC = RecordCodecBuilder.mapCodec(i -> i.group( | ||
StatisticKey.typedCodec(Integer.class).fieldOf("statistic").forGetter(IncrementStatisticAction::statistic), | ||
Codec.INT.optionalFieldOf("amount", 1).forGetter(IncrementStatisticAction::amount) | ||
).apply(i, IncrementStatisticAction::new)); | ||
|
||
@Override | ||
public void register(IGamePhase game, EventRegistrar events) { | ||
events.listen(GameActionEvents.APPLY, context -> { | ||
game.statistics().global().incrementInt(statistic, amount); | ||
return true; | ||
}); | ||
events.listen(GameActionEvents.APPLY_TO_PLAYER, (context, target) -> { | ||
game.statistics().forPlayer(target).incrementInt(statistic, amount); | ||
return true; | ||
}); | ||
} | ||
|
||
@Override | ||
public Supplier<? extends GameBehaviorType<?>> behaviorType() { | ||
return GameBehaviorTypes.INCREMENT_STATISTIC; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters