/**
 * Copyright (C) 2013 MK124
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.gtaun.shoebill.common.vehicle;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import net.gtaun.shoebill.Shoebill;
import net.gtaun.shoebill.constant.PlayerState;
import net.gtaun.shoebill.object.Player;
import net.gtaun.shoebill.object.Vehicle;

public final class VehicleUtils
{
	private VehicleUtils()
	{
		
	}

	public static boolean isVehicleDriver(Vehicle vehicle, Player player)
	{
		return player.getVehicle() == vehicle && player.getState() == PlayerState.DRIVER;
	}

	public static Player getVehicleDriver(Vehicle vehicle)
	{
		for (Player player : Shoebill.get().getSampObjectManager().getPlayers())
		{
			if (player.getVehicle() == vehicle && player.getState() == PlayerState.DRIVER) return player;
		}
		
		return null;
	}
	
	public static List<Player> getVehiclePassengers(Vehicle vehicle)
	{
		List<Player> passengers = new ArrayList<>();
		for (Player player : Shoebill.get().getSampObjectManager().getPlayers())
		{
			if (player.getVehicle() == vehicle && player.getState() == PlayerState.PASSENGER) passengers.add(player);
		}
		
		Collections.sort(passengers, new Comparator<Player>()
		{
			@Override
			public int compare(Player o1, Player o2)
			{
				return o1.getVehicleSeat() - o2.getVehicleSeat();
			}
		});
		
		return passengers;
	}
}

@@ -649,21 +649,16 @@
 va.util.
-Array
 List;%0Aim
@@ -676,109 +676,27 @@
 til.
-Collections;%0Aimport java.util.Comparator;%0Aimport java.util.List;%0A%0Aimport net.gtaun.shoebill.Shoebill;
+stream.Collectors;%0A
 %0Aimp
@@ -1119,202 +1119,148 @@
 %7B%0A%09%09
-for (Player player : Shoebill.get().getSampObjectManager().getPlayers())%0A%09%09%7B%0A%09%09%09if (player.getVehicle() == vehicle && player.getState() == PlayerState.DRIVER) return player;%0A%09%09%7D%0A%09%09%0A%09%09return 
+return Player.get().stream()%0A%09%09%09.filter((p) -%3E p.getState() == PlayerState.DRIVER && p.getVehicle() == vehicle)%0A%09%09%09.findFirst().orElse(
 null
+)
 ;%0A%09%7D
@@ -1337,382 +1337,147 @@
 %7B%0A%09%09
-List%3CPlayer%3E passengers = new ArrayList%3C%3E();%0A%09%09for (Player player : Shoebill.get().getSampObjectManager().getPlayers())%0A%09%09%7B%0A%09%09%09if (player.getVehicle() == vehicle && player.getState() == PlayerState.PASSENGER) passengers.add(player);%0A%09%09%7D%0A%09%09%0A%09%09Collections.sort(passengers, new Comparator%3CPlayer%3E()%0A%09%09%7B%0A%09%09%09@Override%0A%09%09%09public int compare(Player o1, Player o2)%0A%09%09%09%7B%0A%09%09%09%09return o
+return Player.get().stream()%0A%09%09%09.filter((p) -%3E p.getState() == PlayerState.PASSENGER && p.getVehicle() == vehicle)%0A%09%09%09.sorted((p1, p2) -%3E p
 1.ge
@@ -1493,17 +1493,17 @@
 eat() - 
-o
+p
 2.getVeh
@@ -1516,43 +1516,42 @@
 at()
-;%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09%0A%09%09return passengers
+)%0A%09%09%09.collect(Collectors.toList())
 ;%0A%09%7D

Update VehicleUtils for Java 8