13
0

Add TicTacToe #28

Zusammengeführt
YoyoNow hat 2 Commits von games nach master 2023-04-08 00:53:22 +02:00 zusammengeführt
2 geänderte Dateien mit 10 neuen und 4 gelöschten Zeilen
Nur Änderungen aus Commit 2c441bbcfd werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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<Player, List<Player>> CHALLENGES = new HashMap<>();
private final Map<Player, List<Player>> 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;
}

Datei anzeigen

@ -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());