13
0

Player Seat Listener
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
zOnlyKroks 2022-03-24 14:13:14 +01:00
Ursprung 65f6789c95
Commit 38bea9af63
2 geänderte Dateien mit 111 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -56,6 +56,7 @@ public class LobbySystem extends JavaPlugin {
new ParticleListener(); new ParticleListener();
new InventoryInteraction(); new InventoryInteraction();
new WorldInteraction(); new WorldInteraction();
new PlayerSeatListener();
new AlphaWall(l -> l.getX() > 1199, AlphaWall.REFLECT_X); new AlphaWall(l -> l.getX() > 1199, AlphaWall.REFLECT_X);
new AlphaWall(l -> l.getX() < 2977, AlphaWall.REFLECT_X); new AlphaWall(l -> l.getX() < 2977, AlphaWall.REFLECT_X);

Datei anzeigen

@ -0,0 +1,110 @@
package de.steamwar.lobby.listener;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.type.Stairs;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.spigotmc.event.entity.EntityDismountEvent;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
public class PlayerSeatListener extends BasicListener{
private static class SeatLocation {
private int x;
private int y;
private int z;
public SeatLocation(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SeatLocation)) return false;
SeatLocation that = (SeatLocation) o;
return x == that.x &&
y == that.y &&
z == that.z;
}
@Override
public int hashCode() {
return Objects.hash(x, y, z);
}
}
private Set<SeatLocation> seats = new HashSet<>();
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
if (!event.getClickedBlock().getType().name().toLowerCase().contains("stairs"))
return;
if (event.getPlayer().getGameMode() != GameMode.ADVENTURE && event.getPlayer().getGameMode() != GameMode.SURVIVAL)
return;
if (((Stairs) event.getClickedBlock().getBlockData()).getHalf() != Bisected.Half.BOTTOM)
return;
if (((Stairs) event.getClickedBlock().getBlockData()).getShape() != Stairs.Shape.STRAIGHT)
return;
if (event.getPlayer().isInsideVehicle())
event.getPlayer().getVehicle().remove();
if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR)
return;
Location location = event.getClickedBlock().getLocation();
SeatLocation seatLocation = getSeatLocation(location);
if (seats.contains(seatLocation))
return;
seats.add(seatLocation);
Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(location.add(0.5, 0, 0.5), EntityType.ARROW);
arrow.setGravity(false);
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
arrow.addPassenger(event.getPlayer());
arrow.setPersistent(true);
}
@EventHandler
public void onEntityDismount(EntityDismountEvent event) {
seats.remove(getSeatLocation(event.getDismounted().getLocation()));
if (event.getEntityType() != EntityType.PLAYER)
return;
event.getDismounted().remove();
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if (event.getPlayer().isInsideVehicle())
event.getPlayer().getVehicle().remove();
}
public SeatLocation getSeatLocation(Location location) {
return new SeatLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
}