@EventHandler(priority = EventPriority.LOWEST)
public void onVehicleMove(VehicleMoveEvent event) {
Location from = event.getFrom();
Location to = event.getTo();
UUID id = event.getVehicle().getUniqueId();
for(Integer threshold : VehicleEvents.GetThresholdList()) {
Map<UUID, MCLocation> lastLocations = VehicleEvents.GetLastLocations(threshold);
if(!lastLocations.containsKey(id)) {
lastLocations.put(id, new BukkitMCLocation(from));
continue;
}
MCLocation last = lastLocations.get(id);
if(!to.getWorld().getName().equals(last.getWorld().getName())) {
lastLocations.put(id, new BukkitMCLocation(to));
continue;
}
BukkitMCLocation movedTo = new BukkitMCLocation(to);
if(last.distance(movedTo) > threshold) {
BukkitMCVehicleMoveEvent vme = new BukkitMCVehicleMoveEvent(event, threshold, last);
EventUtils.TriggerListener(Driver.VEHICLE_MOVE, "vehicle_move", vme);
if(!vme.isCancelled()) {
lastLocations.put(id, movedTo);
} else {
event.getVehicle().setVelocity(new Vector(0, 0, 0));
event.getVehicle().teleport(from);
}
}
}
}