Class VehicleUtils
java.lang.Object
nl.mtvehicles.core.infrastructure.vehicle.VehicleUtils
Useful methods for vehicles
- See Also:
Vehicle
-
Field Summary
Modifier and TypeFieldDescriptionHashMap containing information about which trunk a player has opened (determined by vehicle's license plate) -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Check whether a player can ride/drive the vehicle.static boolean
Check whether a player can sit in the vehicle.static org.bukkit.inventory.ItemStack
createAndGetItemByUUID(org.bukkit.entity.Player owner, String uuid)
Create a vehicle and get its item by UUID (UUID may be found in vehicles.yml)static void
despawnVehicle(String... licensePlates)
Despawn a vehicle specified by its license plate from all worldsstatic void
despawnVehicle(org.bukkit.World world, String... licensePlates)
Despawn a vehicle specified by its license plate from a specified worldstatic void
enterVehicle(String licensePlate, org.bukkit.entity.Player p)
CreateVehicleData
(necessary for driving to work), helicopter blades, and make player enter a vehicle.static boolean
existsByLicensePlate(String licensePlate)
Check whether this vehicle exists in the database (vehicleData.yml)Get a list of all spawned vehicles' license plates in all worlds.getAllSpawnedVehiclePlates(org.bukkit.World world)
Get a list of all spawned vehicles' license plates in a specified world.static @Nullable org.bukkit.entity.Player
getCurrentDriver(String licensePlate)
Get the current driver of the vehicle.static Vehicle
getDrivenVehicle(org.bukkit.entity.Player p)
Get the player's driven vehiclestatic @Nullable String
getDrivenVehiclePlate(org.bukkit.entity.Player p)
Get the license plate of player's driven vehiclestatic boolean
getHornByDamage(int damage)
Check whether horn is enabled on this vehicle.static org.bukkit.inventory.ItemStack
Get a vehicle item by UUID.static org.bukkit.inventory.ItemStack
getItemByLicensePlate(String licensePlate)
Get a vehicle item by license plate.static org.bukkit.inventory.ItemStack
getItemByUUID(org.bukkit.entity.Player p, String uuid)
Deprecated.static String
getLicensePlate(@Nullable org.bukkit.entity.Entity entity)
Get license plate of an entity (which should be a vehicle - seeisVehicle(Entity)
.static String
getLicensePlate(org.bukkit.inventory.ItemStack item)
Get license plate from a vehicle itemstatic double
getMaxHealthByDamage(int damage)
Check what is the max health of this vehicle.static UUID
getOwnerUUID(String licensePlate)
Get the UUID of the vehicle's ownerstatic Double
Get vehicle's pricestatic String
getRidersAsString(String licensePlate)
Deprecated.UsecanRide(Player, String)
instead.static Vehicle.Seat
getSeat(org.bukkit.entity.Player player)
Shortcut forVehicle.Seat.getSeat(Player)
Get list of seats for a vehicle (specified by license plate)Get a list of all spawned vehicles' license plates in all worlds.getUniqueSpawnedVehiclePlates(org.bukkit.World world)
Get a list of all spawned vehicles' license plates in a specified worlds.static String
Get the UUID of a car by its license platestatic Vehicle
getVehicle(String licensePlate)
Get the Vehicle instance by a vehicle's license placestatic boolean
isInsideVehicle(org.bukkit.entity.Player p)
Check whether a player is inside a vehiclestatic boolean
isTrunkInventoryOpen(org.bukkit.entity.Player p, String license)
Check if trunk of a vehicle is opened by a specified playerstatic boolean
isVehicle(org.bukkit.entity.Entity entity)
Check whether an entity is a vehiclestatic boolean
kickOut(org.bukkit.entity.Player player)
Kick a player out of a vehicle; if the player is a driver,turnOff(Vehicle)
is called as well.static void
Open a vehicle's trunk to a playerstatic void
pickupVehicle(String license, org.bukkit.entity.Player player)
Pick up a vehicle and put it to player's inventorystatic void
spawnVehicle(String licensePlate, org.bukkit.Location location)
Spawn a vehiclestatic boolean
static boolean
DeleteVehicleData
, helicopter blades; save fuel, etc...static boolean
vehicleUUIDExists(String uuid)
Check if given UUID exists (to prevent further issues)
-
Field Details
-
openedTrunk
HashMap containing information about which trunk a player has opened (determined by vehicle's license plate)- See Also:
VehicleData.getTrunkViewers(String)
-
-
Method Details
-
spawnVehicle
public static void spawnVehicle(String licensePlate, org.bukkit.Location location) throws IllegalArgumentExceptionSpawn a vehicle- Parameters:
licensePlate
- Vehicle's license platelocation
- Location where the vehicle should be spawned- Throws:
IllegalArgumentException
- If vehicle with given license plate does not exist
-
getLicensePlate
Get license plate from a vehicle item- Parameters:
item
- Vehicle as Item- Returns:
- Vehicle's license plate
-
getDrivenVehiclePlate
Get the license plate of player's driven vehicle- Parameters:
p
- Player- Returns:
- Returns null if no vehicle is being driven
- See Also:
getDrivenVehicle(Player)
-
getDrivenVehicle
Get the player's driven vehicle- Parameters:
p
- Player- Returns:
- Returns null if no vehicle is being driven
- See Also:
getDrivenVehiclePlate(Player)
-
getItemByUUID
@Deprecated public static org.bukkit.inventory.ItemStack getItemByUUID(org.bukkit.entity.Player p, String uuid)Deprecated.Renamed tocreateAndGetItemByUUID(Player, String)
for clarity.Create a vehicle and get its item by UUID (UUID may be found in vehicles.yml) -
vehicleUUIDExists
Check if given UUID exists (to prevent further issues)- Since:
- 2.5.1
-
createAndGetItemByUUID
public static org.bukkit.inventory.ItemStack createAndGetItemByUUID(org.bukkit.entity.Player owner, String uuid)Create a vehicle and get its item by UUID (UUID may be found in vehicles.yml)- Parameters:
owner
- Vehicle's owneruuid
- Vehicle's UUID (UUID may be found in vehicles.yml)- Returns:
- Null if vehicle was not found by given UUID; otherwise, vehicle item
-
getHornByDamage
public static boolean getHornByDamage(int damage)Check whether horn is enabled on this vehicle.- Parameters:
damage
- The vehicle item's durability- Returns:
- True if horn is enabled
-
getMaxHealthByDamage
public static double getMaxHealthByDamage(int damage)Check what is the max health of this vehicle.- Parameters:
damage
- The vehicle item's durability- Returns:
- Max health of the vehicle
-
getItemByLicensePlate
Get a vehicle item by license plate. Does not create a new vehicle.- Parameters:
licensePlate
- Vehicle's license plate- Returns:
- The vehicle item - just aesthetic (null if license plate is not found)
- Since:
- 2.5.1
- See Also:
getItem(String)
-
getItem
Get a vehicle item by UUID. Does not create a new vehicle - just for aesthetic purposes. (Otherwise, usecreateAndGetItemByUUID(Player, String)
)- Parameters:
carUUID
- Vehicle's UUID (UUID may be found in vehicles.yml)- Returns:
- The vehicle item - just aesthetic (null if UUID is not found)
-
isVehicle
public static boolean isVehicle(org.bukkit.entity.Entity entity)Check whether an entity is a vehicle- Parameters:
entity
- Checked entity- Returns:
- True if the entity is a vehicle
-
getCurrentDriver
Get the current driver of the vehicle.- Parameters:
licensePlate
- Vehicle's license plate- Returns:
- Returns null if the vehicle is not being driven by any player at the moment.
- Since:
- 2.5.1
-
getLicensePlate
Get license plate of an entity (which should be a vehicle - seeisVehicle(Entity)
.- Parameters:
entity
- Vehicle's main armor stand- Returns:
- Vehicle's license plate
-
getUUID
Get the UUID of a car by its license plate- Parameters:
licensePlate
- Vehicle's license plate- Returns:
- Vehicle's UUID
-
getVehicle
Get the Vehicle instance by a vehicle's license place- Parameters:
licensePlate
- Vehicle's license plate- Returns:
- Vehicle instance
- See Also:
Vehicle
-
existsByLicensePlate
Check whether this vehicle exists in the database (vehicleData.yml)- Parameters:
licensePlate
- Vehicle's license plate- Returns:
- True if vehicle is in the database (vehicleData.yml)
-
canRide
Check whether a player can ride/drive the vehicle.- Parameters:
player
- PlayerlicensePlate
- Vehicle's license plate- Returns:
- True if player is the vehicle's set rider.
-
canSit
Check whether a player can sit in the vehicle.- Parameters:
player
- PlayerlicensePlate
- Vehicle's license plate- Returns:
- True if player is the vehicle's set passenger/member.
-
getOwnerUUID
Get the UUID of the vehicle's owner- Parameters:
licensePlate
- Vehicle's license plate- Returns:
- UUID of vehicle's owner
-
openTrunk
Open a vehicle's trunk to a player- Parameters:
p
- Player who is opening the trunklicense
- Vehicle's license plate
-
isTrunkInventoryOpen
Check if trunk of a vehicle is opened by a specified player- Parameters:
p
- Playerlicense
- Vehicle's license plate- Since:
- 2.5.1
-
isInsideVehicle
public static boolean isInsideVehicle(org.bukkit.entity.Player p)Check whether a player is inside a vehicle- Parameters:
p
- Player- Returns:
- True if player is inside any MTV vehicle
-
getRidersAsString
Deprecated.UsecanRide(Player, String)
instead.Get all the vehicle's set drivers/riders.- Parameters:
licensePlate
- Vehicle's license plate- Returns:
- String of all the drivers/riders separated by commas
-
pickupVehicle
Pick up a vehicle and put it to player's inventory- Parameters:
license
- Vehicle's license plateplayer
- Player
-
despawnVehicle
Despawn a vehicle specified by its license plate from all worlds- Parameters:
licensePlates
- Vehicle's license plate- Throws:
IllegalArgumentException
- Thrown if given license plate is invalid.- Since:
- 2.5.1
- See Also:
despawnVehicle(World, String...)
-
despawnVehicle
public static void despawnVehicle(org.bukkit.World world, String... licensePlates) throws IllegalArgumentExceptionDespawn a vehicle specified by its license plate from a specified world- Parameters:
world
- World where the vehicle is being removedlicensePlates
- Vehicle's license plate- Throws:
IllegalArgumentException
- Thrown if given license plate is invalid.- Since:
- 2.5.1
-
getAllSpawnedVehiclePlates
Get a list of all spawned vehicles' license plates in all worlds.- Returns:
- May return list with duplicates - if the same vehicle is spawned multiple times (see
getUniqueSpawnedVehiclePlates()
). - Since:
- 2.5.1
- See Also:
getAllSpawnedVehiclePlates(World)
-
getAllSpawnedVehiclePlates
Get a list of all spawned vehicles' license plates in a specified world.- Returns:
- May return list with duplicates - if the same vehicle is spawned multiple times (see
getUniqueSpawnedVehiclePlates(World)
). - Since:
- 2.5.1
- See Also:
getAllSpawnedVehiclePlates()
-
getUniqueSpawnedVehiclePlates
Get a list of all spawned vehicles' license plates in all worlds.- Returns:
- Returns HashSet with no duplicates (see
getAllSpawnedVehiclePlates()
). - Since:
- 2.5.1
- See Also:
getUniqueSpawnedVehiclePlates(World)
-
getUniqueSpawnedVehiclePlates
Get a list of all spawned vehicles' license plates in a specified worlds.- Returns:
- Returns HashSet with no duplicates (see
getAllSpawnedVehiclePlates(World)
). - Since:
- 2.5.1
- See Also:
getUniqueSpawnedVehiclePlates()
-
enterVehicle
CreateVehicleData
(necessary for driving to work), helicopter blades, and make player enter a vehicle.- Parameters:
licensePlate
- Vehicle's license platep
- Player who is entering the vehicle
-
getSeat
Shortcut forVehicle.Seat.getSeat(Player)
-
kickOut
Kick a player out of a vehicle; if the player is a driver,turnOff(Vehicle)
is called as well.- Returns:
- True if successful
- Throws:
IllegalStateException
- If player is not seated in a (valid) vehicle
-
turnOff
DeleteVehicleData
, helicopter blades; save fuel, etc... after a driver has left the vehicle.- Parameters:
vehicle
- Vehicle- Returns:
- False if the driver is seated in the vehicle, or if the vehicle doesn't have
VehicleData
and thus is not created (seeenterVehicle(String, Player)
-> the vehicle can't be turned off. Otherwise, true. - Beware!
- Do not call this method if a vehicle is being used! Use
kickOut(Player)
instead.
-
turnOff
- Parameters:
licensePlate
- Vehicle's license plate- See Also:
turnOff(Vehicle)
-
getSeats
Get list of seats for a vehicle (specified by license plate)- See Also:
Vehicle.getSeats()
-
getPrice
Get vehicle's price- Parameters:
carUUID
- Vehicle's UUID- Returns:
- Price of the vehicle, null if UUID is not found
-
createAndGetItemByUUID(Player, String)
for clarity.