diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/ChallengeEvents/DeathrunChallengeEvent.java b/Challenge/src/main/java/de/fanta/challenge/challenges/ChallengeEvents/DeathrunChallengeEvent.java index b85f6a2..d1c59a8 100644 --- a/Challenge/src/main/java/de/fanta/challenge/challenges/ChallengeEvents/DeathrunChallengeEvent.java +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/ChallengeEvents/DeathrunChallengeEvent.java @@ -43,6 +43,7 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.HashMap; @@ -75,56 +76,52 @@ Player p = e.getPlayer(); World world = p.getWorld(); if (Objects.equals(Config.getString("event.type"), "deathrun") && plugin.getTimer().isRunning() && !plugin.getVanish().isVanish(p) && p.getGameMode() != GameMode.SPECTATOR) { - if (!deadPlayer.contains(p.getUniqueId())) { - Location playerLoc = p.getLocation(); - double posRelatedToCenter = playerLoc.getZ() - spawnLocation.getZ(); - double distanceToCenter = Math.abs(posRelatedToCenter); + Location playerLoc = p.getLocation(); + double posRelatedToCenter = playerLoc.getZ() - spawnLocation.getZ(); + double distanceToCenter = Math.abs(posRelatedToCenter); - List barrierLocations = currentBarrier.computeIfAbsent(p.getUniqueId(), uuid -> new ArrayList<>()); + List barrierLocations = currentBarrier.computeIfAbsent(p.getUniqueId(), uuid -> new ArrayList<>()); - int BARRIER_POS = 15; - int BARRIER_SIZE = 6; - if (distanceToCenter >= BARRIER_POS) { //Outside border - plugin.getComponentUtil().sendTitleToPlayer(p, Component.text("⟲ ⟲ ⟲ ⟲", Style.style(Color.RED, TextDecoration.BOLD)), Component.text("Kehre zurück auf die Strecke!", Color.RED), 0, 20, 0, true); - resetBarrier(p, world, barrierLocations); - CoordsTargeter.addLocation(p.getUniqueId(), new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), spawnLocation.getZ())); - if (p.getVehicle() instanceof Boat boat) { - boat.remove(); - boat.getWorld().dropItemNaturally(boat.getLocation(), new ItemStack(boat.getBoatType().getMaterial(), 3)); - boat.getWorld().dropItemNaturally(boat.getLocation(), new ItemStack(Material.STICK, 2)); - if (boat instanceof ChestBoat) { - boat.getWorld().dropItemNaturally(boat.getLocation(), new ItemStack(Material.CHEST, 1)); + int BARRIER_POS = 150; + int BARRIER_SIZE = 6; + if (distanceToCenter >= BARRIER_POS) { //Outside border + resetBarrier(p, world, barrierLocations); + + double knockbackStrength = 0.5; + double direction = posRelatedToCenter > 0 ? -1 : 1; + Vector knockbackVector = new Vector(0, 0, direction * knockbackStrength); + p.setVelocity(knockbackVector); + + if (p.getVehicle() instanceof Boat boat) { + boat.remove(); + boat.getWorld().dropItemNaturally(boat.getLocation(), new ItemStack(boat.getBoatType().getMaterial(), 3)); + boat.getWorld().dropItemNaturally(boat.getLocation(), new ItemStack(Material.STICK, 2)); + if (boat instanceof ChestBoat) { + boat.getWorld().dropItemNaturally(boat.getLocation(), new ItemStack(Material.CHEST, 1)); + } + } + } else if (distanceToCenter >= BARRIER_POS - 8) { //Inside border + //Send barrier + double barrierZ = spawnLocation.getZ() + BARRIER_POS * (posRelatedToCenter > 0 ? 1 : -1); + Location loc = new Location(p.getWorld(), playerLoc.getX() - BARRIER_SIZE / 2d, playerLoc.getY() - BARRIER_SIZE / 2d, barrierZ); + + resetBarrier(p, world, barrierLocations); + + for (int y = 0; y < BARRIER_SIZE; y++) { + for (int x = 0; x < BARRIER_SIZE; x++) { + Location blockLoc = loc.clone().add(x, y, 0); + if (!world.getBlockAt(blockLoc).isSolid()) { + p.sendBlockChange(blockLoc, Bukkit.createBlockData(barrierBlock)); + barrierLocations.add(blockLoc); } } - if (distanceToCenter >= BARRIER_POS + 3) { - p.damage(0.5); - } - } else if (distanceToCenter >= BARRIER_POS - 6) { //Inside border - //Send barrier - double barrierZ = spawnLocation.getZ() + BARRIER_POS * (posRelatedToCenter > 0 ? 1 : -1); - Location loc = new Location(p.getWorld(), playerLoc.getX() - BARRIER_SIZE / 2d, playerLoc.getY() - BARRIER_SIZE / 2d, barrierZ); - - resetBarrier(p, world, barrierLocations); - - if (CoordsTargeter.containsLocation(p.getUniqueId())) { - CoordsTargeter.removeLocation(p.getUniqueId()); - } - for (int y = 0; y < BARRIER_SIZE; y++) { - for (int x = 0; x < BARRIER_SIZE; x++) { - Location blockLoc = loc.clone().add(x, y, 0); - if (!world.getBlockAt(blockLoc).isSolid()) { - barrierLocations.add(blockLoc); - p.sendBlockChange(blockLoc, Bukkit.createBlockData(barrierBlock)); - } - } - } - } else if (!barrierLocations.isEmpty()) { //Away from border - resetBarrier(p, world, barrierLocations); } + } else if (!barrierLocations.isEmpty()) { //Away from border + resetBarrier(p, world, barrierLocations); + } - if (playerLoc.getY() > world.getMaxHeight() - 1) { - p.damage(1); - } + if (playerLoc.getY() > world.getMaxHeight() - 1) { + p.damage(1); } } } diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/ChallengeEvents/DeathrunChallengeEventMonth.java b/Challenge/src/main/java/de/fanta/challenge/challenges/ChallengeEvents/DeathrunChallengeEventMonth.java index f89e7b5..92c3d37 100644 --- a/Challenge/src/main/java/de/fanta/challenge/challenges/ChallengeEvents/DeathrunChallengeEventMonth.java +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/ChallengeEvents/DeathrunChallengeEventMonth.java @@ -51,12 +51,14 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerResourcePackStatusEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleDamageEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; import java.io.BufferedWriter; import java.io.File; @@ -148,9 +150,13 @@ int BARRIER_POS = 150; int BARRIER_SIZE = 6; if (distanceToCenter >= BARRIER_POS) { //Outside border - plugin.getComponentUtil().sendTitleToPlayer(p, Component.text("⟲ ⟲ ⟲ ⟲", Style.style(Color.RED, TextDecoration.BOLD)), Component.text("Kehre zurück auf die Strecke!", Color.RED), 0, 20, 0, true); resetBarrier(p, world, barrierLocations); - CoordsTargeter.addLocation(p.getUniqueId(), new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), spawnLocation.getZ())); + + double knockbackStrength = 0.5; + double direction = posRelatedToCenter > 0 ? -1 : 1; + Vector knockbackVector = new Vector(0, 0, direction * knockbackStrength); + p.setVelocity(knockbackVector); + if (p.getVehicle() instanceof Boat boat) { boat.remove(); boat.getWorld().dropItemNaturally(boat.getLocation(), new ItemStack(boat.getBoatType().getMaterial(), 3)); @@ -159,9 +165,6 @@ boat.getWorld().dropItemNaturally(boat.getLocation(), new ItemStack(Material.CHEST, 1)); } } - if (distanceToCenter >= BARRIER_POS + 3) { - p.damage(0.5); - } } else if (distanceToCenter >= BARRIER_POS - 8) { //Inside border //Send barrier double barrierZ = spawnLocation.getZ() + BARRIER_POS * (posRelatedToCenter > 0 ? 1 : -1); @@ -169,9 +172,6 @@ resetBarrier(p, world, barrierLocations); - if (CoordsTargeter.containsLocation(p.getUniqueId())) { - CoordsTargeter.removeLocation(p.getUniqueId()); - } for (int y = 0; y < BARRIER_SIZE; y++) { for (int x = 0; x < BARRIER_SIZE; x++) { Location blockLoc = loc.clone().add(x, y, 0); @@ -191,6 +191,19 @@ } } + + @EventHandler + public void onTeleport(PlayerTeleportEvent e) { + if (Objects.equals(Config.getString("event.type"), "deathrunMonth")) { + if (e.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { + if (e.getFrom().distance(e.getTo()) >= 100) { + plugin.getComponentUtil().sendErrorMessage(e.getPlayer(), "So weit kann man Enderperlen nicht werfen, du Schlingel."); + e.setCancelled(true); + } + } + } + } + @EventHandler public void onDamage(EntityDamageEvent e) { if (e.getEntity() instanceof Player p) {