From 2c441bbcfd1e9cf049e7f6b656b778d6bf3a9c90 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 7 Apr 2023 22:19:10 +0200 Subject: [PATCH] Add TicTacToe --- src/de/steamwar/lobby/games/GamesCommand.java | 7 ++++--- src/de/steamwar/lobby/games/TicTacToe.java | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/lobby/games/GamesCommand.java b/src/de/steamwar/lobby/games/GamesCommand.java index 1cdb267..c6e597d 100644 --- a/src/de/steamwar/lobby/games/GamesCommand.java +++ b/src/de/steamwar/lobby/games/GamesCommand.java @@ -3,16 +3,16 @@ package de.steamwar.lobby.games; import de.steamwar.command.SWCommand; import de.steamwar.lobby.LobbySystem; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; public class GamesCommand extends SWCommand { - private final HashMap> CHALLENGES = new HashMap<>(); + private final Map> CHALLENGES = new HashMap<>(); public GamesCommand() { super("games"); @@ -27,7 +27,8 @@ public class GamesCommand extends SWCommand { if(CHALLENGES.containsKey(player) && CHALLENGES.get(player).contains(target)) { new TicTacToe(player, target).updateBoard(); - CHALLENGES.get(player).remove(target); + CHALLENGES.remove(player); + CHALLENGES.remove(target); return; } diff --git a/src/de/steamwar/lobby/games/TicTacToe.java b/src/de/steamwar/lobby/games/TicTacToe.java index 64addc5..ecf847a 100644 --- a/src/de/steamwar/lobby/games/TicTacToe.java +++ b/src/de/steamwar/lobby/games/TicTacToe.java @@ -37,6 +37,8 @@ public class TicTacToe implements Listener { private int turns = 0; + private boolean running = true; + public TicTacToe(Player player1, Player player2) { this.player1 = player1; this.player2 = player2; @@ -65,6 +67,7 @@ public class TicTacToe implements Listener { } private void win(Player player, int[] winningCombination) { + running = false; SWInventory inventory = createCurrentBoard(player1, LobbySystem.getMessage().parse("GAMES_WON", player1, player.getName())); SWInventory inventory2 = createCurrentBoard(player2, LobbySystem.getMessage().parse("GAMES_WON", player2, player.getName())); for (int j : winningCombination) { @@ -77,6 +80,7 @@ public class TicTacToe implements Listener { } private void draw() { + running = false; SWInventory inventory = createCurrentBoard(player1, LobbySystem.getMessage().parse("GAMES_DRAW", player1)); SWInventory inventory2 = createCurrentBoard(player2, LobbySystem.getMessage().parse("GAMES_DRAW", player2)); remake(inventory, inventory2); @@ -92,6 +96,7 @@ public class TicTacToe implements Listener { } private void end() { + running = false; HandlerList.unregisterAll(this); } @@ -99,7 +104,7 @@ public class TicTacToe implements Listener { SWInventory inventory = createCurrentBoard(player, LobbySystem.getMessage().parse("GAMES_TURN", player, turn.getName())); inventory.addCloseRunnable(() -> { Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> { - if(player.getOpenInventory().getTopInventory().getType() != InventoryType.DROPPER) { + if(player.getOpenInventory().getTopInventory().getType() != InventoryType.DROPPER && running) { player1.closeInventory(); player2.closeInventory(); LobbySystem.getMessage().send("GAMES_LEFT", player1, player.getName());