Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
3a5e0efa26
Commit
d2bbcc2d98
@ -29,6 +29,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -42,31 +43,40 @@ public class WarpListener implements Listener {
|
||||
private Map<Player, List<AbstractWarpEntity>> warpsShown = new HashMap<>();
|
||||
private Map<Player, List<Location>> selected = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
||||
ItemStack itemStack = e.getPlayer().getInventory().getItem(e.getNewSlot());
|
||||
Material material = itemStack == null ? Material.AIR : itemStack.getType();
|
||||
createStuff(e.getPlayer(), material, e.getPlayer().isSneaking());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
createStuff(event, event.getPlayer().isSneaking());
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
createStuff(p, p.getInventory().getItemInMainHand().getType(), p.isSneaking());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
createStuff(event, event.isSneaking());
|
||||
createStuff(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand().getType(), event.isSneaking());
|
||||
}
|
||||
|
||||
private void createStuff(PlayerEvent event, boolean sneaking) {
|
||||
if (warpsShown.containsKey(event.getPlayer())) {
|
||||
warpsShown.get(event.getPlayer()).forEach(warp -> {
|
||||
warp.hide(event.getPlayer());
|
||||
private void createStuff(Player p, Material material, boolean sneaking) {
|
||||
if (warpsShown.containsKey(p)) {
|
||||
warpsShown.get(p).forEach(warp -> {
|
||||
warp.hide(p);
|
||||
});
|
||||
warpsShown.remove(event.getPlayer());
|
||||
warpsShown.remove(p);
|
||||
}
|
||||
if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.COMPASS) {
|
||||
if (material != Material.COMPASS) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
selected.remove(p);
|
||||
List<AbstractWarpEntity> warps = warpsShown.getOrDefault(p, new ArrayList<>());
|
||||
Vector current = p.getLocation().clone().add(p.getLocation().getDirection().multiply(5)).toVector();
|
||||
current.setY(p.getLocation().getY() - 1);
|
||||
|
||||
Map<String, Location> locations = new HashMap<>();
|
||||
if (sneaking) {
|
||||
@ -80,25 +90,25 @@ public class WarpListener implements Listener {
|
||||
}
|
||||
|
||||
locations.forEach((name, location) -> {
|
||||
Vector vector = location.toVector().subtract(event.getPlayer().getLocation().toVector());
|
||||
Vector vector = location.toVector().subtract(p.getLocation().toVector());
|
||||
if (vector.getX() * vector.getX() + vector.getZ() * vector.getZ() < 25) {
|
||||
return;
|
||||
}
|
||||
vector.setY(0);
|
||||
|
||||
Vector position = event.getPlayer().getLocation().toVector().clone().add(vector.normalize().multiply(5));
|
||||
position.setY(event.getPlayer().getLocation().getY() - 1);
|
||||
Vector position = p.getLocation().toVector().clone().add(vector.normalize().multiply(5));
|
||||
position.setY(p.getLocation().getY() - 1);
|
||||
|
||||
if (position.distanceSquared(current) < 0.2) {
|
||||
name = "§a§l" + name;
|
||||
selected.computeIfAbsent(event.getPlayer(), player -> new ArrayList<>()).add(location);
|
||||
selected.computeIfAbsent(p, player -> new ArrayList<>()).add(location);
|
||||
}
|
||||
warps.add(createEntity(event.getPlayer(), position, name));
|
||||
warps.add(createEntity(p, position, name));
|
||||
});
|
||||
|
||||
warpsShown.put(event.getPlayer(), warps);
|
||||
warpsShown.put(p, warps);
|
||||
warps.forEach(warp -> {
|
||||
warp.display(event.getPlayer());
|
||||
warp.display(p);
|
||||
});
|
||||
}
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren