From 14fb1937830beeffc90d06a3c73932af87bee047 Mon Sep 17 00:00:00 2001 From: levischnorr Date: Wed, 7 Feb 2024 10:58:19 +0100 Subject: [PATCH] Don't allow marking fields after win --- .../src/main/java/mavenmcserver/game/Game.java | 2 ++ .../main/java/mavenmcserver/game/GameListener.java | 11 +++++++++++ mavenmcserver/src/main/resources/classes.uml | 1 + .../test/java/mavenmcserver/game/GameStateTest.java | 1 - 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mavenmcserver/src/main/java/mavenmcserver/game/Game.java b/mavenmcserver/src/main/java/mavenmcserver/game/Game.java index c38b9cd..2e9ac70 100644 --- a/mavenmcserver/src/main/java/mavenmcserver/game/Game.java +++ b/mavenmcserver/src/main/java/mavenmcserver/game/Game.java @@ -321,6 +321,8 @@ public void checkForWin() { if(this.state.getWinnerIfAny(this.config.winRequiredAmount, this.lastPlacePosition) != FieldState.NEUTRAL) { + this.listener.allowMarkingFields = false; + new BukkitRunnable() { int i = -1; diff --git a/mavenmcserver/src/main/java/mavenmcserver/game/GameListener.java b/mavenmcserver/src/main/java/mavenmcserver/game/GameListener.java index da8eaa4..a93758b 100644 --- a/mavenmcserver/src/main/java/mavenmcserver/game/GameListener.java +++ b/mavenmcserver/src/main/java/mavenmcserver/game/GameListener.java @@ -21,6 +21,12 @@ public class GameListener implements Listener { Game game; + /** + * If set to *false*, the game's players cannot mark any fields anymore. + * True to *false* when the game ends. + */ + public boolean allowMarkingFields = true; + public GameListener(Game game) { this.game = game; } @@ -113,6 +119,11 @@ public void onPlayerInteract(PlayerInteractEvent event) { if(event.getAction() == Action.RIGHT_CLICK_BLOCK && this.game.getPlayerInTurn() == event.getPlayer()) { + if(!this.allowMarkingFields) { + event.setCancelled(true); + return; + } + if(this.game.gameArea.contains(event.getClickedBlock().getLocation())) { try { diff --git a/mavenmcserver/src/main/resources/classes.uml b/mavenmcserver/src/main/resources/classes.uml index f30eda9..f80d418 100644 --- a/mavenmcserver/src/main/resources/classes.uml +++ b/mavenmcserver/src/main/resources/classes.uml @@ -121,6 +121,7 @@ class GameState { +class GameListener { .. Fields .. Game game + +boolean allowMarkingFields .. Methods .. +GameListener(Game game) diff --git a/mavenmcserver/src/test/java/mavenmcserver/game/GameStateTest.java b/mavenmcserver/src/test/java/mavenmcserver/game/GameStateTest.java index 608141f..7f85806 100644 --- a/mavenmcserver/src/test/java/mavenmcserver/game/GameStateTest.java +++ b/mavenmcserver/src/test/java/mavenmcserver/game/GameStateTest.java @@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.Arrays; import java.util.Map; import static java.util.Map.entry;