From 92786862cd633026acaa8e88f1a0d773406b117a Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 24 May 2020 23:39:55 +0200 Subject: [PATCH] feat: add border --- .../main/java/de/cliffbreak/varo/Varo.java | 13 +++++ .../listeners/InventoryClickListener.java | 1 - .../varo/listeners/PlayerDeathListener.java | 1 + .../varo/managers/BorderManager.java | 57 +++++++++++++++++++ .../varo/managers/GameTimeManager.java | 35 ++++++++++-- 5 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 varo/src/main/java/de/cliffbreak/varo/managers/BorderManager.java diff --git a/varo/src/main/java/de/cliffbreak/varo/Varo.java b/varo/src/main/java/de/cliffbreak/varo/Varo.java index 8664a80..bebd386 100644 --- a/varo/src/main/java/de/cliffbreak/varo/Varo.java +++ b/varo/src/main/java/de/cliffbreak/varo/Varo.java @@ -2,6 +2,7 @@ package de.cliffbreak.varo; import java.io.File; import java.io.IOException; +import java.time.Instant; import java.util.ArrayList; import org.bukkit.configuration.file.FileConfiguration; @@ -24,6 +25,7 @@ import de.cliffbreak.varo.listeners.PlayerInteractNPCListener; import de.cliffbreak.varo.listeners.PlayerJoinQuitListener; import de.cliffbreak.varo.listeners.PlayerLoginListener; import de.cliffbreak.varo.listeners.PlayerResourcePackStatusListener; +import de.cliffbreak.varo.managers.BorderManager; import de.cliffbreak.varo.managers.GameTimeManager; import de.cliffbreak.varo.managers.NPCManager; import de.cliffbreak.varo.managers.TeamManager; @@ -47,6 +49,7 @@ public class Varo extends JavaPlugin { private Database database; private GameTimeManager gameTimeManager; private PlayerUtils playerUtils; + private BorderManager borderManager; private boolean canCreatePortal = false; @@ -67,6 +70,7 @@ public class Varo extends JavaPlugin { this.database = new Database(); this.gameTimeManager = new GameTimeManager(this); this.playerUtils = new PlayerUtils(this); + this.borderManager = new BorderManager(this); this.config.addDefault("Varo.Start", 1590393600000f); this.config.addDefault("Varo.Debug", false); @@ -74,6 +78,11 @@ public class Varo extends JavaPlugin { this.config.addDefault("Varo.Discord.Channel", "numeric.channel.id"); this.config.addDefault("Varo.RetroHealthRegen", false); this.config.addDefault("Varo.Bans", new ArrayList()); + this.config.addDefault("Varo.Border.X", 0); + this.config.addDefault("Varo.Border.Z", 0); + this.config.addDefault("Varo.Border.Size", 4000); // 2.000x2.000 + this.config.addDefault("Varo.Border.NextSize", this.config.getDefaults().get("Varo.Border.Size")); + this.config.addDefault("Varo.Border.LastUpdate", Instant.now().toEpochMilli()); this.config.options().copyDefaults(true); this.saveConfig(); @@ -167,4 +176,8 @@ public class Varo extends JavaPlugin { public PlayerUtils getPlayerUtils() { return this.playerUtils; } + + public BorderManager getBorderManager() { + return this.borderManager; + } } diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/InventoryClickListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/InventoryClickListener.java index d1814e9..d4bc8d1 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/InventoryClickListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/InventoryClickListener.java @@ -15,7 +15,6 @@ public class InventoryClickListener implements Listener { return; } final Material mat = e.getCurrentItem().getType(); - System.out.println(mat); if (mat.equals(Material.AIR) || mat.equals(Material.BLAZE_POWDER) || mat.equals(Material.POTION) || mat.equals(Material.NETHER_WART) || mat.equals(Material.GLISTERING_MELON_SLICE)) { diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java index e130141..efab556 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java @@ -103,6 +103,7 @@ public class PlayerDeathListener implements Listener { e.getEntity().setHealth(20d); e.getEntity().setGameMode(GameMode.SPECTATOR); + this.plugin.getBorderManager().addPlayerDeath(); this.plugin.getBanUtils().addBan(e.getEntity().getUniqueId()); this.plugin.getDiscordBot().broadcastMessage("Der Spieler <@!" + this.plugin.getTeamManager().getDiscordIdByPlayer(e.getEntity()) + "> ist gestorben."); diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/BorderManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/BorderManager.java new file mode 100644 index 0000000..3958fa6 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/managers/BorderManager.java @@ -0,0 +1,57 @@ +package de.cliffbreak.varo.managers; + +import java.time.Instant; +import java.time.LocalDateTime; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.WorldBorder; + +import de.cliffbreak.varo.Varo; + +public class BorderManager { + + private final Varo plugin; + + public BorderManager(final Varo plugin) { + this.plugin = plugin; + init(); + } + + private void init() { + final int size = this.plugin.getConfig().getInt("Varo.Border.Size"); + final int x = this.plugin.getConfig().getInt("Varo.Border.X"); + final int z = this.plugin.getConfig().getInt("Varo.Border.Z"); + for (World world : Bukkit.getWorlds()) { + Environment env = world.getEnvironment(); + if (env.equals(Environment.THE_END)) + continue; + final WorldBorder border = world.getWorldBorder(); + border.reset(); + border.setCenter(x, z); + border.setSize(env.equals(Environment.NORMAL) ? size : (size / 8)); + border.setWarningDistance(25); + border.setWarningTime(0); + border.setDamageAmount(1); + border.setDamageBuffer(0); + } + } + + public LocalDateTime shrinkBorder() { + this.plugin.getConfig().set("Varo.Border.LastUpdate", Instant.now().toEpochMilli()); + int size = this.plugin.getConfig().getInt("Varo.Border.NextSize"); + size = size - 150; // 75*2 for both directions + this.plugin.getConfig().set("Varo.Border.Size", size); + this.plugin.saveConfig(); + return LocalDateTime.now(); + } + + public int addPlayerDeath() { + int size = this.plugin.getConfig().getInt("Varo.Border.NextSize"); + size = size - 50; // 25*2 for both directions + this.plugin.getConfig().set("Varo.Border.NextSize", size); + this.plugin.saveConfig(); + return size; + } +} \ 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 9348e77..bcd79a8 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java @@ -13,19 +13,22 @@ import org.bukkit.scheduler.BukkitRunnable; import de.cliffbreak.varo.Varo; +//TODO: Fix times after 24:00 public class GameTimeManager { private final Varo plugin; private static final int firstPlayTimeMinutes = 50; private static final int firstPlayTimeLoginMinutes = 10; private static final LocalTime firstPlayStart = LocalTime.of(19, 10, 00); - private static final int playTimeMinutes = 30; + // private static final int playTimeMinutes = 30; + private static final int playTimeMinutes = 250; private static final int playTimeLoginMinutes = 5; private static final LocalTime playStart = LocalTime.of(19, 30, 00); public GameTimeManager(final Varo plugin) { this.plugin = plugin; - startScheduler(); + startPlayTimeTimer(); + startBorderTimer(); } public int currentDay() { @@ -93,7 +96,7 @@ public class GameTimeManager { } } - private void startScheduler() { + private void startPlayTimeTimer() { new BukkitRunnable() { boolean playersTeleported = false; @@ -102,7 +105,7 @@ public class GameTimeManager { if (isLoginTimeOver()) { if (!this.playersTeleported) { this.playersTeleported = true; - System.out.println("Teleport Players!"); + System.out.println("TODO: Teleport Players!"); // plugin.getTeamManager(). } } @@ -116,4 +119,28 @@ public class GameTimeManager { }.runTaskTimer(this.plugin, 20l, 20l); } + private void startBorderTimer() { + new BukkitRunnable() { + final Instant instant = Instant.ofEpochMilli(plugin.getConfig().getLong("Varo.Border.LastUpdate")); + LocalDateTime lastUpdate = instant.atZone(ZoneId.systemDefault()).toLocalDateTime(); + + @Override + public void run() { + final LocalDateTime now = LocalDateTime.now(); + System.out.println(lastUpdate); + if (lastUpdate.getDayOfYear() < now.getDayOfYear()) { + if (currentDay() <= 1) { + System.out.println("Day 1 or smaller"); + return; + } + if (now.getHour() == playStart.minusMinutes(30).getHour() + && now.getMinute() == playStart.minusMinutes(30).getMinute()) { + System.out.println("Shrinking Border"); + lastUpdate = plugin.getBorderManager().shrinkBorder(); + } + } + } + }.runTaskTimer(this.plugin, 0, 60 * 20); + } + } \ No newline at end of file