From d0f3ace73fd2dfd2cfe96e71f4b09b998aca58d7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 13 Nov 2022 16:24:04 +0100 Subject: [PATCH] Add JumpAndRun --- src/de/steamwar/lobby/LobbySystem.properties | 4 ++-- .../steamwar/lobby/jumpandrun/JumpAndRun.java | 24 ++++++++++++++++--- .../lobby/listener/DoubleJumpListener.java | 3 +++ .../lobby/listener/ParticleListener.java | 4 ++++ .../steamwar/lobby/listener/PlayerSpawn.java | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/lobby/LobbySystem.properties b/src/de/steamwar/lobby/LobbySystem.properties index 0d98160..9b83870 100644 --- a/src/de/steamwar/lobby/LobbySystem.properties +++ b/src/de/steamwar/lobby/LobbySystem.properties @@ -83,6 +83,6 @@ PARTICLE_EVENT_RAIN_CLOUD = §fRaincloud PARTICLE_EVENT_WGS = §fWGS PARTICLE_EVENT_WARGEARCLASH = §fClash -JUMP_AND_RUN_PROGRESS = §e{0}§8/§f{1} §7{2} +JUMP_AND_RUN_PROGRESS = §e{0}§8/§f{1} §c{2} §7{3} JUMP_AND_RUN_TIME = mm:ss SSS -JUMP_AND_RUN_FINISHED = §aFinished in {0} \ No newline at end of file +JUMP_AND_RUN_FINISHED = §aFinished in {0} with {1} fails \ No newline at end of file diff --git a/src/de/steamwar/lobby/jumpandrun/JumpAndRun.java b/src/de/steamwar/lobby/jumpandrun/JumpAndRun.java index 11824e4..2161fcb 100644 --- a/src/de/steamwar/lobby/jumpandrun/JumpAndRun.java +++ b/src/de/steamwar/lobby/jumpandrun/JumpAndRun.java @@ -2,18 +2,20 @@ package de.steamwar.lobby.jumpandrun; import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.listener.BasicListener; +import de.steamwar.lobby.listener.PlayerSpawn; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import java.text.SimpleDateFormat; -import java.time.format.DateTimeFormatter; import java.util.*; public class JumpAndRun extends BasicListener { @@ -21,6 +23,7 @@ public class JumpAndRun extends BasicListener { public static List points = new ArrayList<>(); private static final Map CURRENT_POS = new HashMap<>(); + private static final Map FAILS = new HashMap<>(); private static final Map START = new HashMap<>(); static { @@ -36,13 +39,15 @@ public class JumpAndRun extends BasicListener { location.setY(point.getY()); location.setZ(point.getZ()); player.teleport(location); + player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, 1, 1); + FAILS.put(player, FAILS.getOrDefault(player, 0) + 1); } } long time = System.currentTimeMillis() - START.get(player); SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT); String parsed = format.format(new Date(time)); - LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PROGRESS", player, ChatMessageType.ACTION_BAR, index + 1, points.size(), parsed.substring(0, parsed.length() - 2)); + LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PROGRESS", player, ChatMessageType.ACTION_BAR, index + 1, points.size(), FAILS.get(player), parsed.substring(0, parsed.length() - 2)); }); }, 1, 1); } @@ -68,16 +73,28 @@ public class JumpAndRun extends BasicListener { return; } CURRENT_POS.put(event.getPlayer(), index); + event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 0.4F, 1); + if (index < points.size() - 1) { + event.getPlayer().setCompassTarget(points.get(index + 1).toLocation(location.getWorld())); + } if (index == 0) { + event.getPlayer().setAllowFlight(false); + event.getPlayer().getInventory().clear(); + event.getPlayer().updateInventory(); + event.getPlayer().getInventory().setItem(4, new ItemStack(Material.COMPASS, 1)); + FAILS.put(event.getPlayer(), 0); START.put(event.getPlayer(), System.currentTimeMillis()); } if (index == points.size() - 1) { long time = System.currentTimeMillis() - START.get(event.getPlayer()); SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", event.getPlayer()), Locale.ROOT); String parsed = format.format(new Date(time)); - LobbySystem.getMessage().send("JUMP_AND_RUN_FINISHED", event.getPlayer(), parsed.substring(0, parsed.length() - 2)); + LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_FINISHED", event.getPlayer(), parsed.substring(0, parsed.length() - 2), FAILS.get(event.getPlayer())); + PlayerSpawn.giveItems(event.getPlayer()); + event.getPlayer().setAllowFlight(true); CURRENT_POS.remove(event.getPlayer()); START.remove(event.getPlayer()); + FAILS.remove(event.getPlayer()); } } @@ -86,5 +103,6 @@ public class JumpAndRun extends BasicListener { Player player = event.getPlayer(); CURRENT_POS.remove(player); START.remove(player); + FAILS.remove(player); } } diff --git a/src/de/steamwar/lobby/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index 80da30d..ae554f6 100644 --- a/src/de/steamwar/lobby/listener/DoubleJumpListener.java +++ b/src/de/steamwar/lobby/listener/DoubleJumpListener.java @@ -19,6 +19,7 @@ package de.steamwar.lobby.listener; +import de.steamwar.lobby.jumpandrun.JumpAndRun; import de.steamwar.lobby.util.LobbyPlayer; import org.bukkit.GameMode; import org.bukkit.Material; @@ -44,6 +45,7 @@ public class DoubleJumpListener extends BasicListener { @EventHandler public void handlePlayerToggleFlight(PlayerToggleFlightEvent event) { Player player = event.getPlayer(); + if (JumpAndRun.isPlayerInJumpAndRun(player)) return; if (player.getGameMode() != GameMode.ADVENTURE && player.getGameMode() != GameMode.SURVIVAL) { return; } @@ -67,6 +69,7 @@ public class DoubleJumpListener extends BasicListener { @EventHandler public void handlePlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); + if (JumpAndRun.isPlayerInJumpAndRun(player)) return; if(player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR) return; if (LobbyPlayer.getLobbyPlayer(player).isFlying()) return; diff --git a/src/de/steamwar/lobby/listener/ParticleListener.java b/src/de/steamwar/lobby/listener/ParticleListener.java index f3a42e0..43ac5b8 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -20,6 +20,7 @@ package de.steamwar.lobby.listener; import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.jumpandrun.JumpAndRun; import de.steamwar.lobby.particle.BaseParticle; import de.steamwar.lobby.particle.ParticleData; import de.steamwar.lobby.particle.ParticleInventory; @@ -45,6 +46,7 @@ public class ParticleListener extends BasicListener { deg += 0.1; if (deg > 360) deg = 0; Bukkit.getOnlinePlayers().forEach(player -> { + if (JumpAndRun.isPlayerInJumpAndRun(player)) return; LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); ParticleEnum particle = lobbyPlayer.getParticle(); if (particle == null) return; @@ -60,6 +62,7 @@ public class ParticleListener extends BasicListener { public void handlePlayerInteract(PlayerInteractEvent event) { if (Bukkit.getOnlinePlayers().size() > PLAYER_MAX_SIZE) return; Player player = event.getPlayer(); + if (JumpAndRun.isPlayerInJumpAndRun(player)) return; if (!PlayerSpawn.PARTICLE.equals(event.getItem())) return; event.setCancelled(true); @@ -70,6 +73,7 @@ public class ParticleListener extends BasicListener { public void handlePlayerMove(PlayerMoveEvent event) { if (Bukkit.getOnlinePlayers().size() > PLAYER_MAX_SIZE) return; Player player = event.getPlayer(); + if (JumpAndRun.isPlayerInJumpAndRun(player)) return; LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); ParticleEnum particle = lobbyPlayer.getParticle(); if (particle == null) return; diff --git a/src/de/steamwar/lobby/listener/PlayerSpawn.java b/src/de/steamwar/lobby/listener/PlayerSpawn.java index 29ff64e..6e6c7f9 100644 --- a/src/de/steamwar/lobby/listener/PlayerSpawn.java +++ b/src/de/steamwar/lobby/listener/PlayerSpawn.java @@ -61,7 +61,7 @@ public class PlayerSpawn extends BasicListener { Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> NetworkSender.send(new ImALobbyPacket(), player), 20); } - private void giveItems(Player player) { + public static void giveItems(Player player) { PlayerInventory inventory = player.getInventory(); inventory.setItem(EquipmentSlot.CHEST, ELYTRA);