mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +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();
|
Vehicle vehicle = event.getVehicle();
|
||||||
|
|
||||||
// Check allowed
|
// 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) {
|
this.playerMove(moveTmp);
|
||||||
final Player player = (Player) passenger;
|
org.bukkit.Location dest;
|
||||||
// reset
|
if (moveTmp.isCancelled()) {
|
||||||
if (moveTmp == null)
|
dest = from;
|
||||||
moveTmp = new PlayerMoveEvent(null, from, to);
|
} else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX
|
||||||
moveTmp.setFrom(from);
|
|| MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) {
|
||||||
moveTmp.setTo(to);
|
dest = 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);
|
|
||||||
} else {
|
} else {
|
||||||
vehicle.eject();
|
dest = null;
|
||||||
vehicle.setVelocity(new Vector(0d, 0d, 0d));
|
}
|
||||||
vehicle.teleport(dest);
|
if (dest != null) {
|
||||||
vehicle.setPassenger(player);
|
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) {
|
||||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
switch (vehicle.getType()) {
|
||||||
switch (vehicle.getType()) {
|
case MINECART:
|
||||||
case MINECART:
|
case MINECART_CHEST:
|
||||||
case MINECART_CHEST:
|
case MINECART_COMMAND:
|
||||||
case MINECART_COMMAND:
|
case MINECART_FURNACE:
|
||||||
case MINECART_FURNACE:
|
case MINECART_HOPPER:
|
||||||
case MINECART_HOPPER:
|
case MINECART_MOB_SPAWNER:
|
||||||
case MINECART_MOB_SPAWNER:
|
case ENDER_CRYSTAL:
|
||||||
case ENDER_CRYSTAL:
|
case MINECART_TNT:
|
||||||
case MINECART_TNT:
|
case BOAT: {
|
||||||
case BOAT: {
|
List<MetadataValue> meta = vehicle.getMetadata("plot");
|
||||||
List<MetadataValue> meta = vehicle.getMetadata("plot");
|
Plot toPlot = BukkitUtil.getLocation(to).getPlot();
|
||||||
Plot toPlot = BukkitUtil.getLocation(to).getPlot();
|
if (!meta.isEmpty()) {
|
||||||
if (!meta.isEmpty()) {
|
Plot origin = (Plot) meta.get(0).value();
|
||||||
Plot origin = (Plot) meta.get(0).value();
|
if (!origin.getBasePlot(false).equals(toPlot)) {
|
||||||
if (!origin.getBasePlot(false).equals(toPlot)) {
|
vehicle.remove();
|
||||||
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