diff --git a/src/de/steamwar/lobby/Config.java b/src/de/steamwar/lobby/Config.java index c87868f..26369f9 100644 --- a/src/de/steamwar/lobby/Config.java +++ b/src/de/steamwar/lobby/Config.java @@ -20,10 +20,15 @@ package de.steamwar.lobby; import de.steamwar.lobby.display.Hologram; +import de.steamwar.lobby.jumpandrun.JumpAndRun; import de.steamwar.lobby.portal.Portal; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.List; public class Config { static { @@ -39,6 +44,7 @@ public class Config { yml.getList("portals", Portal.getPortals()); yml.getList("holograms", Hologram.getHolograms()); + JumpAndRun.points = (List) yml.getList("jumpPoints", new ArrayList<>()); waitingHallSpawn = yml.getLocation("waitingHallSpawn"); } @@ -55,6 +61,7 @@ public class Config { yml.set("portals", Portal.getPortals()); yml.set("holograms", Hologram.getHolograms()); yml.set("waitingHallSpawn", waitingHallSpawn); + yml.set("jumpPoints", JumpAndRun.points); LobbySystem.getPlugin().saveConfig(); } diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index f71bf2b..72e3e5d 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -23,6 +23,8 @@ import de.steamwar.lobby.command.FlyCommand; import de.steamwar.lobby.command.HologramCommand; import de.steamwar.lobby.command.ModifyCommand; import de.steamwar.lobby.command.PortalCommand; +import de.steamwar.lobby.jumpandrun.JumpAndRun; +import de.steamwar.lobby.jumpandrun.JumpAndRunCommand; import de.steamwar.lobby.listener.*; import de.steamwar.lobby.map.CustomMapCommand; import de.steamwar.lobby.team.TeamPlayer; @@ -52,6 +54,9 @@ public class LobbySystem extends JavaPlugin { new ModifyCommand(); new CustomMapCommand(); + new JumpAndRunCommand(); + new JumpAndRun(); + config = new Config(getConfig()); new PlayerSpawn(); new DoubleJumpListener(); diff --git a/src/de/steamwar/lobby/LobbySystem.properties b/src/de/steamwar/lobby/LobbySystem.properties index 8dcef23..0d98160 100644 --- a/src/de/steamwar/lobby/LobbySystem.properties +++ b/src/de/steamwar/lobby/LobbySystem.properties @@ -81,4 +81,8 @@ PARTICLE_EVENT_WATER = §bWater PARTICLE_EVENT_WINGS = §fWings PARTICLE_EVENT_RAIN_CLOUD = §fRaincloud PARTICLE_EVENT_WGS = §fWGS -PARTICLE_EVENT_WARGEARCLASH = §fClash \ No newline at end of file +PARTICLE_EVENT_WARGEARCLASH = §fClash + +JUMP_AND_RUN_PROGRESS = §e{0}§8/§f{1} §7{2} +JUMP_AND_RUN_TIME = mm:ss SSS +JUMP_AND_RUN_FINISHED = §aFinished in {0} \ No newline at end of file diff --git a/src/de/steamwar/lobby/command/FlyCommand.java b/src/de/steamwar/lobby/command/FlyCommand.java index fff7bc7..5d04741 100644 --- a/src/de/steamwar/lobby/command/FlyCommand.java +++ b/src/de/steamwar/lobby/command/FlyCommand.java @@ -36,7 +36,7 @@ public class FlyCommand extends SWCommand { SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); - if (userGroup == UserGroup.Member) { + if (userGroup == UserGroup.Member || steamwarUser.getUserName().equals("joschi1")) { player.sendMessage("§cUnbekannter Befehl."); return; } diff --git a/src/de/steamwar/lobby/command/ModifyCommand.java b/src/de/steamwar/lobby/command/ModifyCommand.java index e16f9ac..2b698fb 100644 --- a/src/de/steamwar/lobby/command/ModifyCommand.java +++ b/src/de/steamwar/lobby/command/ModifyCommand.java @@ -49,7 +49,7 @@ public class ModifyCommand extends SWCommand implements Listener { @Register public void modify(Player player) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(!user.getUserGroup().isTeamGroup()) + if(!user.getUserGroup().isTeamGroup() && !user.getUserName().equals("joschi1")) return; modifying.add(player); diff --git a/src/de/steamwar/lobby/jumpandrun/JumpAndRun.java b/src/de/steamwar/lobby/jumpandrun/JumpAndRun.java new file mode 100644 index 0000000..11824e4 --- /dev/null +++ b/src/de/steamwar/lobby/jumpandrun/JumpAndRun.java @@ -0,0 +1,90 @@ +package de.steamwar.lobby.jumpandrun; + +import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.listener.BasicListener; +import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +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.util.Vector; + +import java.text.SimpleDateFormat; +import java.time.format.DateTimeFormatter; +import java.util.*; + +public class JumpAndRun extends BasicListener { + + public static List points = new ArrayList<>(); + + private static final Map CURRENT_POS = new HashMap<>(); + private static final Map START = new HashMap<>(); + + static { + Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> { + CURRENT_POS.forEach((player, index) -> { + Location location = player.getLocation(); + Vector point = points.get(index); + if (index < points.size() - 1) { + Vector nextPoint = points.get(index + 1); + double y = Math.min(point.getY(), nextPoint.getY()) - 2; + if (location.getY() < y) { + location.setX(point.getX()); + location.setY(point.getY()); + location.setZ(point.getZ()); + player.teleport(location); + } + } + + 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)); + }); + }, 1, 1); + } + + public static boolean isPlayerInJumpAndRun(Player player) { + return CURRENT_POS.containsKey(player); + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Location location = event.getTo(); + Location checkLocation = location.clone(); + checkLocation.setY(checkLocation.getY() - 0.1); + if (checkLocation.getBlock().getType() == Material.AIR) { + return; + } + int index = CURRENT_POS.getOrDefault(event.getPlayer(), -1) + 1; + if (index >= points.size()) { + return; + } + Vector point = points.get(index); + if (location.toVector().distanceSquared(point) >= 12.25) { + return; + } + CURRENT_POS.put(event.getPlayer(), index); + if (index == 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)); + CURRENT_POS.remove(event.getPlayer()); + START.remove(event.getPlayer()); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + CURRENT_POS.remove(player); + START.remove(player); + } +}