mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 11:55:38 +01:00
Fix NPE on VehicleMoveEvent. Fixes #2195.
This commit is contained in:
parent
f1cf541606
commit
d12bdcfda4
@ -642,72 +642,73 @@ import java.util.regex.Pattern;
|
||||
Vehicle vehicle = event.getVehicle();
|
||||
|
||||
// Check allowed
|
||||
if (!vehicle.getPassengers().isEmpty()) {
|
||||
Entity passenger = vehicle.getPassengers().get(0);
|
||||
|
||||
if (passenger instanceof Player) {
|
||||
final Player player = (Player) passenger;
|
||||
// reset
|
||||
if (moveTmp == null)
|
||||
moveTmp = new PlayerMoveEvent(null, from, to);
|
||||
moveTmp.setFrom(from);
|
||||
moveTmp.setTo(to);
|
||||
moveTmp.setCancelled(false);
|
||||
fieldPlayer.set(moveTmp, player);
|
||||
|
||||
Entity passenger = vehicle.getPassengers().get(1);
|
||||
List<Entity> passengers = vehicle.getPassengers();
|
||||
|
||||
if (passenger instanceof Player) {
|
||||
final Player player = (Player) passenger;
|
||||
// reset
|
||||
if (moveTmp == null)
|
||||
moveTmp = new PlayerMoveEvent(null, from, to);
|
||||
moveTmp.setFrom(from);
|
||||
moveTmp.setTo(to);
|
||||
moveTmp.setCancelled(false);
|
||||
fieldPlayer.set(moveTmp, player);
|
||||
|
||||
List<Entity> passengers = vehicle.getPassengers();
|
||||
|
||||
this.playerMove(moveTmp);
|
||||
org.bukkit.Location dest;
|
||||
if (moveTmp.isCancelled()) {
|
||||
dest = from;
|
||||
} else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX
|
||||
|| MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) {
|
||||
dest = to;
|
||||
} else {
|
||||
dest = null;
|
||||
}
|
||||
if (dest != null) {
|
||||
if (passengers != null) {
|
||||
vehicle.eject();
|
||||
vehicle.setVelocity(new Vector(0d, 0d, 0d));
|
||||
vehicle.teleport(dest);
|
||||
passengers.forEach(vehicle::addPassenger);
|
||||
this.playerMove(moveTmp);
|
||||
org.bukkit.Location dest;
|
||||
if (moveTmp.isCancelled()) {
|
||||
dest = from;
|
||||
} else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX
|
||||
|| MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) {
|
||||
dest = to;
|
||||
} else {
|
||||
vehicle.eject();
|
||||
vehicle.setVelocity(new Vector(0d, 0d, 0d));
|
||||
vehicle.teleport(dest);
|
||||
vehicle.setPassenger(player);
|
||||
dest = null;
|
||||
}
|
||||
if (dest != null) {
|
||||
if (passengers != null) {
|
||||
vehicle.eject();
|
||||
vehicle.setVelocity(new Vector(0d, 0d, 0d));
|
||||
vehicle.teleport(dest);
|
||||
passengers.forEach(vehicle::addPassenger);
|
||||
} else {
|
||||
vehicle.eject();
|
||||
vehicle.setVelocity(new Vector(0d, 0d, 0d));
|
||||
vehicle.teleport(dest);
|
||||
vehicle.setPassenger(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
switch (vehicle.getType()) {
|
||||
case MINECART:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case ENDER_CRYSTAL:
|
||||
case MINECART_TNT:
|
||||
case BOAT: {
|
||||
List<MetadataValue> meta = vehicle.getMetadata("plot");
|
||||
Plot toPlot = BukkitUtil.getLocation(to).getPlot();
|
||||
if (!meta.isEmpty()) {
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (!origin.getBasePlot(false).equals(toPlot)) {
|
||||
vehicle.remove();
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
switch (vehicle.getType()) {
|
||||
case MINECART:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case ENDER_CRYSTAL:
|
||||
case MINECART_TNT:
|
||||
case BOAT: {
|
||||
List<MetadataValue> meta = vehicle.getMetadata("plot");
|
||||
Plot toPlot = BukkitUtil.getLocation(to).getPlot();
|
||||
if (!meta.isEmpty()) {
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (!origin.getBasePlot(false).equals(toPlot)) {
|
||||
vehicle.remove();
|
||||
}
|
||||
} else if (toPlot != null) {
|
||||
vehicle.setMetadata("plot",
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot));
|
||||
}
|
||||
} else if (toPlot != null) {
|
||||
vehicle.setMetadata("plot",
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user