Class VehicleUtils

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

public final class VehicleUtils extends Object
Useful methods for vehicles
See Also:
Vehicle
BEWARE! THIS IS IMPORTANT:
This class may be moved in v2.5.0. Bear it in mind if you're using it in your addon.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static HashMap<org.bukkit.entity.Player,​String>
    HashMap containing information about which trunk a player has opened (determined by vehicle's license plate)
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canRide​(org.bukkit.entity.Player player, String licensePlate)
    Check whether a player can ride/drive the vehicle.
    static boolean
    canSit​(org.bukkit.entity.Player player, String licensePlate)
    Check whether a player can sit in the vehicle.
    static void
    enterVehicle​(String licensePlate, org.bukkit.entity.Player p)
    Create VehicleData (necessary for driving to work) and make player enter a vehicle.
    static boolean
    existsByLicensePlate​(String licensePlate)
    Check whether this vehicle exists in the database (vehicleData.yml)
    static Vehicle
    getByLicensePlate​(String licensePlate)
    Deprecated.
    Renamed to getVehicle(String).
    static org.bukkit.inventory.ItemStack
    getCarItem​(String carUUID)
    Get a vehicle item by UUID.
    static String
    getCarUUID​(String licensePlate)
    Get the UUID of a car by its license plate
    static boolean
    getHornByDamage​(int damage)
    Check whether horn is enabled on this vehicle.
    static org.bukkit.inventory.ItemStack
    getItemByUUID​(org.bukkit.entity.Player p, String uuid)
    Create a vehicle and get its item by UUID (UUID may be found in vehicles.yml)
    static String
    getLicensePlate​(@Nullable org.bukkit.entity.Entity entity)
    Get license plate of an entity (which should be a vehicle - see isVehicle(Entity).
    static String
    getLicensePlate​(org.bukkit.inventory.ItemStack item)
    Get license plate from a vehicle item
    static 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 owner
    static String
    getRidersAsString​(String licensePlate)
    Deprecated.
    static Vehicle
    getVehicle​(String licensePlate)
    Get the Vehicle instance by a vehicle's license place
    static boolean
    isInsideVehicle​(org.bukkit.entity.Player p)
    Check whether a player is inside a vehicle
    static boolean
    isVehicle​(org.bukkit.entity.Entity entity)
    Check whether an entity is a vehicle
    static void
    openTrunk​(org.bukkit.entity.Player p, String license)
    Open a vehicle's trunk to a player
    static void
    pickupVehicle​(String license, org.bukkit.entity.Player player)
    Pick up a vehicle and put it to player's inventory
    static void
    spawnVehicle​(String licensePlate, org.bukkit.Location location)
    Spawn a vehicle

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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)
  • 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
    • getItemByUUID

      public static org.bukkit.inventory.ItemStack getItemByUUID(org.bukkit.entity.Player p, String uuid)
      Create a vehicle and get its item by UUID (UUID may be found in vehicles.yml)
      Parameters:
      p - Vehicle's owner
      uuid - Vehicle's UUID (UUID may be found in vehicles.yml)
      Returns:
      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
    • getCarItem

      public static org.bukkit.inventory.ItemStack getCarItem(String carUUID)
      Get a vehicle item by UUID. Does not create a new vehicle - just for aesthetic purposes. (Otherwise, use getItemByUUID(Player, String))
      Parameters:
      carUUID - Vehicle's UUID (UUID may be found in vehicles.yml)
      Returns:
      The vehicle item - just aesthetic
    • 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
    • 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
    • getCarUUID

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

      @Deprecated public static Vehicle getByLicensePlate(String licensePlate)
      Deprecated.
      Renamed to getVehicle(String).
      Get the Vehicle instance by a vehicle's license place
      Parameters:
      licensePlate - Vehicle's license plate
      Returns:
      Vehicle instance
    • 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
    • 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
    • enterVehicle

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