Skip to content

Commit

Permalink
Don't allow marking fields after win
Browse files Browse the repository at this point in the history
  • Loading branch information
lscgh committed Feb 7, 2024
1 parent 305a2f0 commit 14fb193
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mavenmcserver/src/main/java/mavenmcserver/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions mavenmcserver/src/main/java/mavenmcserver/game/GameListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions mavenmcserver/src/main/resources/classes.uml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class GameState {
+class GameListener {
.. Fields ..
Game game
+boolean allowMarkingFields

.. Methods ..
+GameListener(Game game)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 14fb193

Please sign in to comment.