Class VehicleUtils
java.lang.Object
nl.mtvehicles.core.infrastructure.vehicle.VehicleUtils
Useful methods for vehicles
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionHashMap containing information about which trunk a player has opened (determined by vehicle's license plate) -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck whether a player can ride/drive the vehicle.static booleanCheck whether a player can sit in the vehicle.static org.bukkit.inventory.ItemStackcreateAndGetItemByUUID(org.bukkit.OfflinePlayer owner, String uuid) Create a vehicle and get its item by UUID (UUID may be found in vehicles.yml)static voiddeleteVehicle(String... licensePlates) Delete a vehicle from the database and despawn it from all worldsstatic intdespawnVehicle(String... licensePlates) Despawn a vehicle specified by its license plate from all worldsstatic intdespawnVehicle(org.bukkit.World world, String... licensePlates) Despawn a vehicle specified by its license plate from a specified worldstatic voidenterVehicle(String licensePlate, org.bukkit.entity.Player p) CreateVehicleData(necessary for driving to work), helicopter blades, and make player enter a vehicle.static booleanexistsByLicensePlate(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.PlayergetCurrentDriver(String licensePlate) Get the current driver of the vehicle.static VehiclegetDrivenVehicle(org.bukkit.entity.Player p) Get the player's driven vehiclestatic @Nullable StringgetDrivenVehiclePlate(org.bukkit.entity.Player p) Get the license plate of player's driven vehiclestatic booleangetHornByDamage(int damage) Check whether horn is enabled on this vehicle.static org.bukkit.inventory.ItemStackGet a vehicle item by UUID.static org.bukkit.inventory.ItemStackgetItemByLicensePlate(String licensePlate) Get a vehicle item by license plate.static org.bukkit.inventory.ItemStackgetItemByUUID(org.bukkit.entity.Player p, String uuid) Deprecated.static StringgetLicensePlate(@Nullable org.bukkit.entity.Entity entity) Get license plate of an entity (which should be a vehicle - seeisVehicle(Entity).static StringgetLicensePlate(org.bukkit.inventory.ItemStack item) Get license plate from a vehicle itemstatic org.bukkit.LocationgetLocation(String licensePlate) Get the location of a vehiclestatic org.bukkit.LocationgetLocation(Vehicle vehicle) Get the location of a vehiclestatic doublegetMaxHealthByDamage(int damage) Check what is the max health of this vehicle.static UUIDgetOwnerUUID(String licensePlate) Get the UUID of the vehicle's ownerstatic DoubleGet vehicle's pricestatic StringgetRidersAsString(String licensePlate) Deprecated.UsecanRide(Player, String)instead.static Vehicle.SeatgetSeat(org.bukkit.entity.Player player) Shortcut forVehicle.Seat.getSeat(Player)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 StringGet the UUID of a car by its license platestatic VehiclegetVehicle(String licensePlate) Get the Vehicle instance by a vehicle's license platestatic VehiclegetVehicle(org.bukkit.inventory.ItemStack item) Get Vehicle instance from a vehicle itemstatic booleanisInsideVehicle(org.bukkit.entity.Player p) Check whether a player is inside a vehiclestatic booleanisOccupied(String licensePlate) Check whether a vehicle is occupiedstatic booleanisTrunkInventoryOpen(org.bukkit.entity.Player p, String license) Check if trunk of a vehicle is opened by a specified playerstatic booleanisVehicle(org.bukkit.entity.Entity entity) Check whether an entity is a vehiclestatic booleankickOut(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 voidOpen a vehicle's trunk to a playerstatic voidpickupVehicle(String license, org.bukkit.entity.Player player) Pick up a vehicle and put it to player's inventorystatic booleanSet vehicle's current fuel levelstatic voidspawnVehicle(String licensePlate, org.bukkit.Location location) Spawn a vehiclestatic voidteleportVehicle(String licensePlate, org.bukkit.Location location) Teleport a vehicle to a locationstatic booleanstatic booleanDeleteVehicleData, helicopter blades; save fuel, etc...static booleanvehicleUUIDExists(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:
-
-
Method Details
-
spawnVehicle
public static void spawnVehicle(String licensePlate, org.bukkit.Location location) throws IllegalArgumentException Spawn 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
-
getVehicle
Get Vehicle instance from a vehicle item- Parameters:
item- Vehicle as Item- Returns:
- Vehicle
- See Also:
-
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
Get the player's driven vehicle- Parameters:
p- Player- Returns:
- Returns null if no vehicle is being driven
- See Also:
-
getItemByUUID
@Deprecated public static org.bukkit.inventory.ItemStack getItemByUUID(org.bukkit.entity.Player p, String uuid) Deprecated.Renamed tocreateAndGetItemByUUID(OfflinePlayer, 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.OfflinePlayer 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
Get a vehicle item by UUID. Does not create a new vehicle - just for aesthetic purposes. (Otherwise, usecreateAndGetItemByUUID(OfflinePlayer, 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 plate- Parameters:
licensePlate- Vehicle's license plate- Returns:
- Vehicle instance
- See Also:
-
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
-
isOccupied
Check whether a vehicle is occupied- Parameters:
licensePlate- Vehicle's license plate- Returns:
- True if the vehicle is occupied
-
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
-
deleteVehicle
public static void deleteVehicle(String... licensePlates) throws IllegalArgumentException, IllegalStateException Delete a vehicle from the database and despawn it from all worlds- Parameters:
licensePlates- Vehicle's license plate- Throws:
IllegalArgumentException- Thrown if given license plate is invalid.IllegalStateException- Thrown if vehicle is already deleted- Since:
- 2.5.4
-
teleportVehicle
public static void teleportVehicle(String licensePlate, org.bukkit.Location location) throws IllegalArgumentException Teleport a vehicle to a location- Parameters:
licensePlate- Vehicle's license platelocation- Location where the vehicle should be teleported- Throws:
IllegalArgumentException- Thrown if given license plate is invalid.
-
despawnVehicle
Despawn a vehicle specified by its license plate from all worlds- Parameters:
licensePlates- Vehicle's license plate- Returns:
- Number of vehicles despawned
- Throws:
IllegalArgumentException- Thrown if given license plate is invalid.- Since:
- 2.5.1
- See Also:
-
despawnVehicle
public static int despawnVehicle(org.bukkit.World world, String... licensePlates) throws IllegalArgumentException Despawn a vehicle specified by its license plate from a specified world- Parameters:
world- World where the vehicle is being removedlicensePlates- Vehicle's license plate- Returns:
- Number of vehicles despawned
- Throws:
IllegalArgumentException- Thrown if given license plate is invalid.- Since:
- 2.5.1
- See Also:
-
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
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:
-
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
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:
-
setFuel
Set vehicle's current fuel level- Parameters:
licensePlate- Vehicle's license platefuel- Fuel level (0–100)- Returns:
- True if fuel level was set successfully
-
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
-
getLocation
Get the location of a vehicle- Parameters:
vehicle- Vehicle- Returns:
- Vehicle's location
- Since:
- 2.5.4
- See Also:
-
getLocation
Get the location of a vehicle- Parameters:
licensePlate- Vehicle's license plate- Returns:
- Vehicle's location
- Since:
- 2.5.4
-
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
VehicleDataand 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:
-
getPrice
Get vehicle's price- Parameters:
carUUID- Vehicle's UUID- Returns:
- Price of the vehicle, null if UUID is not found
-
createAndGetItemByUUID(OfflinePlayer, String)for clarity.