-
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.
Freeze players for a few seconds when starting Columns of Chaos
- Loading branch information
Showing
6 changed files
with
94 additions
and
5 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
35 changes: 35 additions & 0 deletions
35
...etropics/minigames/common/core/game/behavior/instances/action/ApplyClientStateAction.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,35 @@ | ||
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.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.behavior.event.GamePlayerEvents; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientState; | ||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
public record ApplyClientStateAction(GameClientState state) implements IGameBehavior { | ||
public static final MapCodec<ApplyClientStateAction> CODEC = RecordCodecBuilder.mapCodec(i -> i.group( | ||
GameClientState.CODEC.fieldOf("state").forGetter(ApplyClientStateAction::state) | ||
).apply(i, ApplyClientStateAction::new)); | ||
|
||
@Override | ||
public void register(IGamePhase game, EventRegistrar events) { | ||
Set<UUID> appliedToPlayers = new HashSet<>(); | ||
events.listen(GameActionEvents.APPLY_TO_PLAYER, (context, target) -> { | ||
GameClientState.sendToPlayer(state, target); | ||
appliedToPlayers.add(target.getUUID()); | ||
return true; | ||
}); | ||
events.listen(GamePlayerEvents.REMOVE, player -> { | ||
if (appliedToPlayers.remove(player.getUUID())) { | ||
GameClientState.removeFromPlayer(state.getType(), player); | ||
} | ||
}); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...tropics/minigames/common/core/game/behavior/instances/action/RemoveClientStateAction.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,25 @@ | ||
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.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.client_state.GameClientState; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateType; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateTypes; | ||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
public record RemoveClientStateAction(GameClientStateType<?> type) implements IGameBehavior { | ||
public static final MapCodec<RemoveClientStateAction> CODEC = RecordCodecBuilder.mapCodec(i -> i.group( | ||
GameClientStateTypes.TYPE_CODEC.fieldOf("state").forGetter(RemoveClientStateAction::type) | ||
).apply(i, RemoveClientStateAction::new)); | ||
|
||
@Override | ||
public void register(IGamePhase game, EventRegistrar events) { | ||
events.listen(GameActionEvents.APPLY_TO_PLAYER, (context, target) -> { | ||
GameClientState.removeFromPlayer(type, target); | ||
return true; | ||
}); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...etropics/minigames/common/core/game/client_state/instance/DisablePlayerMovementState.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,17 @@ | ||
package com.lovetropics.minigames.common.core.game.client_state.instance; | ||
|
||
import com.lovetropics.minigames.common.core.game.client_state.GameClientState; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateType; | ||
import com.lovetropics.minigames.common.core.game.client_state.GameClientStateTypes; | ||
|
||
public class DisablePlayerMovementState implements GameClientState { | ||
public static final DisablePlayerMovementState INSTANCE = new DisablePlayerMovementState(); | ||
|
||
private DisablePlayerMovementState() { | ||
} | ||
|
||
@Override | ||
public GameClientStateType<?> getType() { | ||
return GameClientStateTypes.DISABLE_PLAYER_MOVEMENT.get(); | ||
} | ||
} |
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