Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
a9f560ba5e
Commit
f0a23e0d5f
@ -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<Player, List<AbstractWarpEntity>> warpsShown = new HashMap<>();
|
||||
private Map<Player, List<Warp>> selectedWarps = new HashMap<>();
|
||||
private Map<Player, List<Location>> 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<AbstractWarpEntity> 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);
|
||||
|
||||
Map<String, Location> locations = new HashMap<>();
|
||||
if (event.getPlayer().isSneaking()) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
locations.put(player.getName(), player.getLocation());
|
||||
});
|
||||
} else {
|
||||
Warp.getWarps().forEach(warp -> {
|
||||
Vector vector = warp.getLocation().toVector().subtract(event.getPlayer().getLocation().toVector());
|
||||
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<Warp> selected = selectedWarps.getOrDefault(event.getPlayer(), new ArrayList<>());
|
||||
if (selected.size() != 1) {
|
||||
List<Location> 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());
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren