From f0a23e0d5faa723822f0ca91b6042fc3aced695e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 20 Jan 2022 20:19:04 +0100 Subject: [PATCH] Update WarpListener Signed-off-by: yoyosource --- .../bausystem/features/warp/WarpListener.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java index 70c28696..ab4924de 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java @@ -22,7 +22,7 @@ package de.steamwar.bausystem.features.warp; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.core.VersionedCallable; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -42,7 +42,7 @@ import java.util.Map; public class WarpListener implements Listener { private Map> warpsShown = new HashMap<>(); - private Map> selectedWarps = new HashMap<>(); + private Map> selected = new HashMap<>(); @EventHandler public void onPlayerMove(PlayerMoveEvent event) { @@ -56,12 +56,24 @@ public class WarpListener implements Listener { return; } - selectedWarps.remove(event.getPlayer()); + selected.remove(event.getPlayer()); List warps = warpsShown.getOrDefault(event.getPlayer(), new ArrayList<>()); Vector current = event.getPlayer().getLocation().clone().add(event.getPlayer().getLocation().getDirection().multiply(5)).toVector(); current.setY(event.getPlayer().getLocation().getY() - 1); - Warp.getWarps().forEach(warp -> { - Vector vector = warp.getLocation().toVector().subtract(event.getPlayer().getLocation().toVector()); + + Map locations = new HashMap<>(); + if (event.getPlayer().isSneaking()) { + Bukkit.getOnlinePlayers().forEach(player -> { + locations.put(player.getName(), player.getLocation()); + }); + } else { + Warp.getWarps().forEach(warp -> { + locations.put(warp.getName(), warp.getLocation()); + }); + } + + locations.forEach((name, location) -> { + Vector vector = location.toVector().subtract(event.getPlayer().getLocation().toVector()); if (vector.getX() * vector.getX() + vector.getZ() * vector.getZ() < 25) { return; } @@ -70,10 +82,9 @@ public class WarpListener implements Listener { Vector position = event.getPlayer().getLocation().toVector().clone().add(vector.normalize().multiply(5)); position.setY(event.getPlayer().getLocation().getY() - 1); - String name = warp.getName(); if (position.distanceSquared(current) < 0.2) { name = "§a§l" + name; - selectedWarps.computeIfAbsent(event.getPlayer(), player -> new ArrayList<>()).add(warp); + selected.computeIfAbsent(event.getPlayer(), player -> new ArrayList<>()).add(location); } warps.add(createEntity(event.getPlayer(), position, name)); }); @@ -92,11 +103,13 @@ public class WarpListener implements Listener { if (event.getAction() != Action.RIGHT_CLICK_AIR) { return; } - List selected = selectedWarps.getOrDefault(event.getPlayer(), new ArrayList<>()); - if (selected.size() != 1) { + List locations = selected.getOrDefault(event.getPlayer(), new ArrayList<>()); + if (locations.size() != 1) { return; } - selected.get(0).teleport(event.getPlayer()); + Location location = locations.get(0); + event.getPlayer().teleport(location); + event.getPlayer().playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1); event.setCancelled(true); } @@ -107,6 +120,6 @@ public class WarpListener implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { warpsShown.remove(event.getPlayer()); - selectedWarps.remove(event.getPlayer()); + selected.remove(event.getPlayer()); } }