Class VehicleUtils

java.lang.Object
nl.mtvehicles.core.infrastructure.vehicle.VehicleUtils

public final class VehicleUtils extends Object
Useful methods for vehicles
See Also:
Vehicle
  • Field Details

    • openedTrunk

      public static HashMap<org.bukkit.entity.Player,​String> 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 IllegalArgumentException
      Spawn a vehicle
      Parameters:
      licensePlate - Vehicle's license plate
      location - Location where the vehicle should be spawned
      Throws:
      IllegalArgumentException - If vehicle with given license plate does not exist
    • getLicensePlate

      public static String getLicensePlate(org.bukkit.inventory.ItemStack item)
      Get license plate from a vehicle item
      Parameters:
      item - Vehicle as Item
      Returns:
      Vehicle's license plate
    • getDrivenVehiclePlate

      @Nullable public static @Nullable String getDrivenVehiclePlate(org.bukkit.entity.Player p)
      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

      public static Vehicle getDrivenVehicle(org.bukkit.entity.Player p)
      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.
      Create a vehicle and get its item by UUID (UUID may be found in vehicles.yml)
    • vehicleUUIDExists

      public static boolean vehicleUUIDExists(String uuid)
      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 owner
      uuid - 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

      public static org.bukkit.inventory.ItemStack getItemByLicensePlate(String licensePlate)
      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

      public static org.bukkit.inventory.ItemStack getItem(String carUUID)
      Get a vehicle item by UUID. Does not create a new vehicle - just for aesthetic purposes. (Otherwise, use createAndGetItemByUUID(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

      @Nullable public static @Nullable org.bukkit.entity.Player getCurrentDriver(String licensePlate)
      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

      public static String getLicensePlate(@Nullable @Nullable org.bukkit.entity.Entity entity)
      Get license plate of an entity (which should be a vehicle - see isVehicle(Entity).
      Parameters:
      entity - Vehicle's main armor stand
      Returns:
      Vehicle's license plate
    • getUUID

      public static String getUUID(String licensePlate)
      Get the UUID of a car by its license plate
      Parameters:
      licensePlate - Vehicle's license plate
      Returns:
      Vehicle's UUID
    • getVehicle

      public static Vehicle getVehicle(String licensePlate)
      Get the Vehicle instance by a vehicle's license place
      Parameters:
      licensePlate - Vehicle's license plate
      Returns:
      Vehicle instance
      See Also:
      Vehicle
    • existsByLicensePlate

      public static boolean existsByLicensePlate(String licensePlate)
      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

      public static boolean canRide(org.bukkit.entity.Player player, String licensePlate)
      Check whether a player can ride/drive the vehicle.
      Parameters:
      player - Player
      licensePlate - Vehicle's license plate
      Returns:
      True if player is the vehicle's set rider.
    • canSit

      public static boolean canSit(org.bukkit.entity.Player player, String licensePlate)
      Check whether a player can sit in the vehicle.
      Parameters:
      player - Player
      licensePlate - Vehicle's license plate
      Returns:
      True if player is the vehicle's set passenger/member.
    • getOwnerUUID

      public static UUID getOwnerUUID(String licensePlate)
      Get the UUID of the vehicle's owner
      Parameters:
      licensePlate - Vehicle's license plate
      Returns:
      UUID of vehicle's owner
    • openTrunk

      public static void openTrunk(org.bukkit.entity.Player p, String license)
      Open a vehicle's trunk to a player
      Parameters:
      p - Player who is opening the trunk
      license - Vehicle's license plate
    • isTrunkInventoryOpen

      public static boolean isTrunkInventoryOpen(org.bukkit.entity.Player p, String license)
      Check if trunk of a vehicle is opened by a specified player
      Parameters:
      p - Player
      license - 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 public static String getRidersAsString(String licensePlate)
      Deprecated.
      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

      public static void pickupVehicle(String license, org.bukkit.entity.Player player)
      Pick up a vehicle and put it to player's inventory
      Parameters:
      license - Vehicle's license plate
      player - Player
    • despawnVehicle

      public static void despawnVehicle(String... licensePlates) throws IllegalArgumentException
      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 IllegalArgumentException
      Despawn a vehicle specified by its license plate from a specified world
      Parameters:
      world - World where the vehicle is being removed
      licensePlates - Vehicle's license plate
      Throws:
      IllegalArgumentException - Thrown if given license plate is invalid.
      Since:
      2.5.1
    • getAllSpawnedVehiclePlates

      public static List<String> 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

      public static List<String> getAllSpawnedVehiclePlates(org.bukkit.World world)
      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

      public static Set<String> 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

      public static Set<String> getUniqueSpawnedVehiclePlates(org.bukkit.World world)
      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

      public static void enterVehicle(String licensePlate, org.bukkit.entity.Player p)
      Create VehicleData (necessary for driving to work), helicopter blades, and make player enter a vehicle.
      Parameters:
      licensePlate - Vehicle's license plate
      p - Player who is entering the vehicle
    • getSeat

      public static Vehicle.Seat getSeat(org.bukkit.entity.Player player)
    • kickOut

      public static boolean kickOut(org.bukkit.entity.Player player) throws IllegalStateException
      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

      public static boolean turnOff(@NotNull @NotNull Vehicle vehicle)
      Delete VehicleData, 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 (see enterVehicle(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

      public static boolean turnOff(@NotNull @NotNull String licensePlate)
      Parameters:
      licensePlate - Vehicle's license plate
      See Also:
      turnOff(Vehicle)
    • getSeats

      public static List<Map<String,​Double>> getSeats(String licensePlate)
      Get list of seats for a vehicle (specified by license plate)
      See Also:
      Vehicle.getSeats()
    • getPrice

      public static Double getPrice(String carUUID)
      Get vehicle's price
      Parameters:
      carUUID - Vehicle's UUID
      Returns:
      Price of the vehicle, null if UUID is not found