From 98609f7a62ea11cb7da5ccb993f61019c5168d6f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 8 Apr 2023 15:30:56 +0200 Subject: [PATCH] Add Speed to BoatRace --- src/de/steamwar/lobby/LobbySystem.properties | 2 +- src/de/steamwar/lobby/boatrace/BoatRace.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/lobby/LobbySystem.properties b/src/de/steamwar/lobby/LobbySystem.properties index cb49a38..fdb5cb1 100644 --- a/src/de/steamwar/lobby/LobbySystem.properties +++ b/src/de/steamwar/lobby/LobbySystem.properties @@ -150,7 +150,7 @@ GAMES_LEFT = §7{0} left the game BOAT_RACE_TIME = §7Finished in §e{0} BOAT_RACE_NEW_BEST = §aNew best time! -BOAT_RACE_TITLE = §6Checkpoint {0}/6§7: {1} +BOAT_RACE_TITLE = §6Checkpoint {0}/6§7: {1} §8• §e{2}km/h # Easter Egg Hunt DIFFICULTY_EASY = §aEasy diff --git a/src/de/steamwar/lobby/boatrace/BoatRace.java b/src/de/steamwar/lobby/boatrace/BoatRace.java index 1573941..34d7fdf 100644 --- a/src/de/steamwar/lobby/boatrace/BoatRace.java +++ b/src/de/steamwar/lobby/boatrace/BoatRace.java @@ -57,11 +57,14 @@ public class BoatRace implements EventListener, Listener { private final BukkitTask task; private final BossBar bossBar; private boolean hasBacked = false; + private double lastDistance; @EventHandler public void onBoatMove(VehicleMoveEvent event) { if (event.getVehicle() != boat) return; + lastDistance = event.getFrom().distance(event.getTo()); + if(nextCheckpoint == 0 && inRegion(player, BoatRacePositions.BACKWARDS[0], BoatRacePositions.BACKWARDS[1])) { player.eject(); player.teleport(BoatRacePositions.END); @@ -137,8 +140,9 @@ public class BoatRace implements EventListener, Listener { task = Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> { hasBacked = false; if (nextCheckpoint != 0) { + double kmh = lastDistance * 20 * 3.6; bossBar.setProgress((nextCheckpoint - 1d) / (BoatRacePositions.CHECKPOINTS.length - 1d)); - bossBar.setTitle(LobbySystem.getMessage().parse("BOAT_RACE_TITLE", player, nextCheckpoint, renderTime(System.currentTimeMillis() - startTime))); + bossBar.setTitle(LobbySystem.getMessage().parse("BOAT_RACE_TITLE", player, nextCheckpoint, renderTime(System.currentTimeMillis() - startTime), (int) kmh)); } }, 0, 1); Bukkit.getPluginManager().registerEvents(this, LobbySystem.getPlugin());