diff --git a/TowerRun/src/de/steamwar/towerrun/FightInfoPacketSender.java b/TowerRun/src/de/steamwar/towerrun/FightInfoPacketSender.java
new file mode 100644
index 00000000..2893268f
--- /dev/null
+++ b/TowerRun/src/de/steamwar/towerrun/FightInfoPacketSender.java
@@ -0,0 +1,66 @@
+/*
+ *
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ * /
+ */
+
+package de.steamwar.towerrun;
+
+import de.steamwar.network.NetworkSender;
+import de.steamwar.network.packets.common.FightInfoPacket;
+import de.steamwar.sql.SteamwarUser;
+import de.steamwar.towerrun.config.Config;
+import de.steamwar.towerrun.game.TowerRunGame;
+import de.steamwar.towerrun.state.GameState;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class FightInfoPacketSender implements Runnable {
+
+ private final World world = Bukkit.getWorlds().get(0);
+
+ private final String serverName = Bukkit.getServer().getName();
+ private final String gameMode = "towerrun";
+ private final String worldName = world.getName();
+ private final String blueName = "§3Alive";
+ private final String redName = "§fEscaped";
+
+ @Override
+ public void run() {
+ if (Config.test()) {
+ return;
+ }
+
+ List alivePlayers = TowerRunGame.PLAYERS_ALIVE.stream().map(player -> SteamwarUser.get(player.player().getUniqueId()).getId()).collect(Collectors.toList());
+ List escapedPlayers = TowerRunGame.PLAYERS_ESCAPED.stream().map(player -> SteamwarUser.get(player.player().getUniqueId()).getId()).collect(Collectors.toList());
+ List spectatorPlayers = new ArrayList<>();
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ int id = SteamwarUser.get(player.getUniqueId()).getId();
+ if (!alivePlayers.contains(id) && !escapedPlayers.contains(id)) {
+ spectatorPlayers.add(id);
+ }
+ }
+
+ NetworkSender.send(new FightInfoPacket(serverName, gameMode, worldName, blueName, redName, GameState.getCurrentState().name().toLowerCase(), TowerRun.getGameCountdown().getPlayTimeInSeconds(), 0, 0, 0, 0, alivePlayers, escapedPlayers, spectatorPlayers));
+ }
+}
diff --git a/TowerRun/src/de/steamwar/towerrun/TowerRun.java b/TowerRun/src/de/steamwar/towerrun/TowerRun.java
index c0717b2f..23f00488 100644
--- a/TowerRun/src/de/steamwar/towerrun/TowerRun.java
+++ b/TowerRun/src/de/steamwar/towerrun/TowerRun.java
@@ -32,6 +32,7 @@ import de.steamwar.towerrun.listener.IngameListener;
import de.steamwar.towerrun.listener.LobbyListener;
import de.steamwar.towerrun.listener.NotLobbyListener;
import lombok.Getter;
+import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.annotation.dependency.Dependency;
import org.bukkit.plugin.java.annotation.plugin.ApiVersion;
@@ -79,6 +80,8 @@ public class TowerRun extends JavaPlugin {
new StartCommand(lobbyCountdown);
gameCountdown = new GameCountdown();
+ Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20);
+
TowerRunGame.reset();
}
}
diff --git a/TowerRun/src/de/steamwar/towerrun/config/Config.java b/TowerRun/src/de/steamwar/towerrun/config/Config.java
index 7890e785..bce0cb54 100644
--- a/TowerRun/src/de/steamwar/towerrun/config/Config.java
+++ b/TowerRun/src/de/steamwar/towerrun/config/Config.java
@@ -39,6 +39,8 @@ public class Config {
public static final int GAME_TIMER;
public static final int GAME_ESCAPE_TIMER;
+ private static final int EventKampfID;
+
static {
File configFile = new File(TowerRun.getInstance().getDataFolder(), "config.yml");
if (!configFile.exists()) {
@@ -53,6 +55,11 @@ public class Config {
GAME_TIMER = config.getInt("gameTimer", 20 * 60);
GAME_ESCAPE_TIMER = config.getInt("gameEscapeTimer", 60);
DESTROYABLE_BLOCKS = EnumSet.copyOf(config.getStringList("destroyable").stream().map(Material::valueOf).collect(Collectors.toSet()));
+
+ EventKampfID = Integer.parseInt(System.getProperty("fightID", "0"));
}
+ public static boolean test() {
+ return EventKampfID == -1;
+ }
}
diff --git a/TowerRun/src/de/steamwar/towerrun/countdowns/GameCountdown.java b/TowerRun/src/de/steamwar/towerrun/countdowns/GameCountdown.java
index b56c1f3b..29487859 100644
--- a/TowerRun/src/de/steamwar/towerrun/countdowns/GameCountdown.java
+++ b/TowerRun/src/de/steamwar/towerrun/countdowns/GameCountdown.java
@@ -28,6 +28,8 @@ import java.util.EnumSet;
public class GameCountdown extends Countdown {
+ private long startTime = 0;
+
public GameCountdown() {
super(EnumSet.of(GameStates.INGAME));
}
@@ -59,9 +61,21 @@ public class GameCountdown extends Countdown {
TowerRun.getMessage().broadcastActionbar("GAME_TIME", String.format("%02d", timeMinutes), String.format("%02d", timeSeconds));
}
+ @Override
+ public void enable() {
+ super.enable();
+ startTime = System.currentTimeMillis();
+ }
+
@Override
public void disable() {
super.disable();
setTime(defaultTime());
+ startTime = 0;
+ }
+
+ public int getPlayTimeInSeconds() {
+ if (startTime == 0) return 0;
+ return (int) ((System.currentTimeMillis() - startTime) / 1000);
}
}