feat: improve GameManager and GameTimeManager
This commit is contained in:
parent
021cb7f988
commit
c323ea7075
4 changed files with 39 additions and 88 deletions
|
@ -19,7 +19,7 @@ public class PlayerLoginListener implements Listener {
|
||||||
public void onPlayerLogin(final PlayerLoginEvent e) {
|
public void onPlayerLogin(final PlayerLoginEvent e) {
|
||||||
if (this.plugin.getBanUtils().isBanned(e.getPlayer().getUniqueId())) {
|
if (this.plugin.getBanUtils().isBanned(e.getPlayer().getUniqueId())) {
|
||||||
e.disallow(Result.KICK_BANNED, this.plugin.getLangUtils().get("Service.BannedDead"));
|
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"));
|
e.disallow(Result.KICK_OTHER, this.plugin.getLangUtils().get("Service.KickNoPlayTime"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Skeleton;
|
import org.bukkit.entity.Skeleton;
|
||||||
import org.bukkit.entity.Spider;
|
import org.bukkit.entity.Spider;
|
||||||
import org.bukkit.entity.Zombie;
|
import org.bukkit.entity.Zombie;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import de.cliffbreak.varo.Varo;
|
import de.cliffbreak.varo.Varo;
|
||||||
import de.cliffbreak.varo.enums.GameState;
|
import de.cliffbreak.varo.enums.GameState;
|
||||||
|
@ -59,7 +60,6 @@ public class GameManager {
|
||||||
for (Entity entity : world.getEntitiesByClasses(Spider.class, Zombie.class, Skeleton.class,
|
for (Entity entity : world.getEntitiesByClasses(Spider.class, Zombie.class, Skeleton.class,
|
||||||
Creeper.class, Drowned.class, Enderman.class)) {
|
Creeper.class, Drowned.class, Enderman.class)) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
// TODO: test
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,23 @@ public class GameManager {
|
||||||
player.setFoodLevel(20);
|
player.setFoodLevel(20);
|
||||||
player.setSaturation(5.0f);
|
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.gameState = GameState.NOTIME;
|
||||||
this.plugin.getLogger().info("[GameManager] Set GameState to " + this.gameState);
|
this.plugin.getLogger().info("[GameManager] Set GameState to " + this.gameState);
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -7,10 +7,6 @@ import java.time.LocalTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.temporal.ChronoUnit;
|
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 org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import de.cliffbreak.varo.Varo;
|
import de.cliffbreak.varo.Varo;
|
||||||
|
@ -46,90 +42,24 @@ public class GameTimeManager {
|
||||||
* @return current Day the Server is running
|
* @return current Day the Server is running
|
||||||
*/
|
*/
|
||||||
public int currentDay() {
|
public int currentDay() {
|
||||||
return 1;
|
final Instant instant = Instant.ofEpochMilli(this.plugin.getConfig().getLong("Varo.Start"));
|
||||||
// TODO: uncomment
|
final LocalDateTime start = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||||
// final Instant instant = Instant.ofEpochMilli(this.plugin.getConfig().getLong("Varo.Start"));
|
final LocalDateTime current = LocalDateTime.now();
|
||||||
// final LocalDateTime start = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
|
return (int) Duration.between(start, current).toDays() + 1;
|
||||||
// final LocalDateTime current = LocalDateTime.now();
|
|
||||||
// return (int) Duration.between(start, current).toDays() + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rewrite
|
/**
|
||||||
public boolean canLogin() {
|
* @return time left the Game is in LOGIN State
|
||||||
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
|
|
||||||
public int getLoginTimeLeft() {
|
public int getLoginTimeLeft() {
|
||||||
final LocalTime currentTime = LocalTime.now();
|
final LocalTime currentTime = LocalTime.now();
|
||||||
if (this.currentDay() != 1) {
|
final LocalTime start = this.currentDay() == 1 ? firstPlayStart : playStart;
|
||||||
return (int) currentTime.until(playStart, ChronoUnit.SECONDS);
|
return (int) currentTime.until(start, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return time until the start and the game running (negative) before start > 0 and after start < 0
|
||||||
|
*/
|
||||||
// TODO: BREAKING handle times after 24:00
|
// TODO: BREAKING handle times after 24:00
|
||||||
public int getPlayTimeDeltaSeconds() {
|
public int getPlayTimeDeltaSeconds() {
|
||||||
final LocalTime currentTime = LocalTime.now();
|
final LocalTime currentTime = LocalTime.now();
|
||||||
|
|
|
@ -14,11 +14,12 @@ public class LangUtils {
|
||||||
this.config = YamlConfiguration.loadConfiguration(this.file);
|
this.config = YamlConfiguration.loadConfiguration(this.file);
|
||||||
|
|
||||||
this.config.addDefault("Service.KickNoPlayTime",
|
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",
|
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.LoadingTitle", "§a§lVaro 2020");
|
||||||
this.config.addDefault("Service.LoadingSubTitle", "Das Spiel startet gleich...");
|
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.LoadingCountdown", "§r§l Noch: %02d:%02d");
|
||||||
this.config.addDefault("Service.BannedDead",
|
this.config.addDefault("Service.BannedDead",
|
||||||
"§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden.");
|
"§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden.");
|
||||||
|
|
Loading…
Reference in a new issue