feat: add border
This commit is contained in:
parent
48cefd4b01
commit
92786862cd
5 changed files with 102 additions and 5 deletions
|
@ -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<String>());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue