diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerLoginListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerLoginListener.java index 3c189fe..692da11 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerLoginListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerLoginListener.java @@ -19,7 +19,7 @@ public class PlayerLoginListener implements Listener { public void onPlayerLogin(final PlayerLoginEvent e) { if (this.plugin.getBanUtils().isBanned(e.getPlayer().getUniqueId())) { e.disallow(Result.KICK_BANNED, this.plugin.getLangUtils().get("Service.BannedDead")); - } else if (!this.plugin.getGameTimeManager().canLogin()) { + } else if (!this.plugin.getGameManager().canLogin()) { e.disallow(Result.KICK_OTHER, this.plugin.getLangUtils().get("Service.KickNoPlayTime")); } } diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/GameManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/GameManager.java index 4f5eabb..63f12d9 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/GameManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/GameManager.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; import org.bukkit.entity.Spider; import org.bukkit.entity.Zombie; +import org.bukkit.scheduler.BukkitRunnable; import de.cliffbreak.varo.Varo; import de.cliffbreak.varo.enums.GameState; @@ -59,7 +60,6 @@ public class GameManager { for (Entity entity : world.getEntitiesByClasses(Spider.class, Zombie.class, Skeleton.class, Creeper.class, Drowned.class, Enderman.class)) { entity.remove(); - // TODO: test } } } @@ -68,7 +68,23 @@ public class GameManager { player.setFoodLevel(20); player.setSaturation(5.0f); } - // Telport handled from PlayerUtils.java + + new BukkitRunnable() { + int i = 60; + + @Override + public void run() { + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendTitle(plugin.getLangUtils().get("Service.LoadingTitle"), + plugin.getLangUtils().get("Service.PreStartTitle").replace("%seconds%", i + ""), 0, 40, 0); + } + i--; + if (i == 0) { + this.cancel(); + } + } + }.runTaskTimer(this.plugin, 0, 20); + // Telport handled by PlayerUtils.java } /** @@ -106,7 +122,11 @@ public class GameManager { this.gameState = GameState.NOTIME; this.plugin.getLogger().info("[GameManager] Set GameState to " + this.gameState); for (Player player : Bukkit.getOnlinePlayers()) { - System.out.println(player.getName() + " kick.."); + player.kickPlayer(this.plugin.getLangUtils().get("Service.KickPlayTimeOver")); } } + + public boolean canLogin() { + return !this.gameState.equals(GameState.NOTIME); + } } \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java index 76c390c..6b0c552 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java @@ -7,10 +7,6 @@ import java.time.LocalTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.World.Environment; -import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import de.cliffbreak.varo.Varo; @@ -46,90 +42,24 @@ public class GameTimeManager { * @return current Day the Server is running */ public int currentDay() { - return 1; - // TODO: uncomment - // final Instant instant = Instant.ofEpochMilli(this.plugin.getConfig().getLong("Varo.Start")); - // final LocalDateTime start = instant.atZone(ZoneId.systemDefault()).toLocalDateTime(); - // final LocalDateTime current = LocalDateTime.now(); - // return (int) Duration.between(start, current).toDays() + 1; + final Instant instant = Instant.ofEpochMilli(this.plugin.getConfig().getLong("Varo.Start")); + final LocalDateTime start = instant.atZone(ZoneId.systemDefault()).toLocalDateTime(); + final LocalDateTime current = LocalDateTime.now(); + return (int) Duration.between(start, current).toDays() + 1; } - // TODO: Rewrite - public boolean canLogin() { - final LocalTime currentTime = LocalTime.now(); - if (this.currentDay() == 1) { - if (!currentTime.isBefore(firstPlayStart.minusMinutes(firstPlayTimeLoginMinutes)) - && !currentTime.isAfter(firstPlayStart.plusMinutes(firstPlayTimeMinutes))) { - return true; - } else { - return false; - } - } else { - if (!currentTime.isBefore(playStart.minusMinutes(playTimeLoginMinutes)) - && !currentTime.isAfter(playStart.plusMinutes(playTimeMinutes))) { - return true; - } else { - return false; - } - } - } - - // TODO: Rewrite - public boolean isLoginTimeOver() { - final LocalTime currentTime = LocalTime.now(); - if (this.currentDay() == 1) { - if (currentTime.isAfter(firstPlayStart)) { - return true; - } else { - return false; - } - } else { - if (currentTime.isAfter(playStart)) { - return true; - } else { - return false; - } - } - } - - // TODO: Rewrite + /** + * @return time left the Game is in LOGIN State + */ public int getLoginTimeLeft() { final LocalTime currentTime = LocalTime.now(); - if (this.currentDay() != 1) { - return (int) currentTime.until(playStart, ChronoUnit.SECONDS); - } else { - return (int) currentTime.until(firstPlayStart, ChronoUnit.SECONDS); - } - } - - // TODO: Rewrite - public int getGameTimeLeft() { - final LocalTime currentTime = LocalTime.now(); - if (this.currentDay() != 1) { - return (int) currentTime.until(playStart.plusMinutes(playTimeMinutes), ChronoUnit.MINUTES); - } else { - return (int) currentTime.until(firstPlayStart.plusMinutes(firstPlayTimeMinutes), ChronoUnit.MINUTES); - } - } - - // TODO: Rewrite - private boolean isPlayTimeOver() { - final LocalTime currentTime = LocalTime.now(); - if (this.currentDay() == 1) { - if (currentTime.isAfter(firstPlayStart.plusMinutes(firstPlayTimeMinutes))) { - return true; - } else { - return false; - } - } else { - if (currentTime.isAfter(playStart.plusMinutes(playTimeMinutes))) { - return true; - } else { - return false; - } - } + final LocalTime start = this.currentDay() == 1 ? firstPlayStart : playStart; + return (int) currentTime.until(start, ChronoUnit.SECONDS); } + /** + * @return time until the start and the game running (negative) before start > 0 and after start < 0 + */ // TODO: BREAKING handle times after 24:00 public int getPlayTimeDeltaSeconds() { final LocalTime currentTime = LocalTime.now(); diff --git a/varo/src/main/java/de/cliffbreak/varo/utils/LangUtils.java b/varo/src/main/java/de/cliffbreak/varo/utils/LangUtils.java index 35632e5..f4051ba 100644 --- a/varo/src/main/java/de/cliffbreak/varo/utils/LangUtils.java +++ b/varo/src/main/java/de/cliffbreak/varo/utils/LangUtils.java @@ -14,11 +14,12 @@ public class LangUtils { this.config = YamlConfiguration.loadConfiguration(this.file); this.config.addDefault("Service.KickNoPlayTime", - "§4Außerhalb der Spielzeit.\n \n§cVersuche es in %time% erneut."); + "§4Außerhalb der Spielzeit.\n \n§6Versuche es später erneut."); this.config.addDefault("Service.KickPlayTimeOver", - "§4Die Spielzeit ist abgelaufen.\n \n§cBis morgen :)"); + "§4Die Spielzeit ist abgelaufen.\n \n§6Bis morgen :)"); this.config.addDefault("Service.LoadingTitle", "§a§lVaro 2020"); this.config.addDefault("Service.LoadingSubTitle", "Das Spiel startet gleich..."); + this.config.addDefault("Service.PreStartTitle", "In %seconds% Sekunden geht es los."); this.config.addDefault("Service.LoadingCountdown", "§r§l Noch: %02d:%02d"); this.config.addDefault("Service.BannedDead", "§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden.");