Skip to main content

API reference

Almost everything you need is exposed through the static nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI class. This page lists its methods grouped by purpose. For the full, always-up-to-date signatures see the Javadoc.

The object model

Understanding the vehicle types makes the API much easier:

Vehicle                     (base type)
├── StorageVehicle a vehicle as stored data (in a garage, not in the world)
└── SpawnedVehicle a vehicle that exists in the world (has armor stands)
├── DrivableVehicle a normal, drivable spawned vehicle
└── PersistentVehicle a spawned vehicle that survives restarts
  • A vehicle lives in a Garage until it's spawned. Spawning turns a StorageVehicle into a SpawnedVehicle; despawning turns it back.
  • Each vehicle is built from a VehicleModel (its definition: parts, stats, price…).
  • Use vehicle.isSpawned(), getSpawnedVehicle(), getStorageVehicle() and getAsDrivableVehicle() / getAsPersistentVehicle() to move between these views.

Lookups (registries)

MethodReturns
getVehicleModel(String id)Optional<VehicleModel>
getVehicleType(String id)Optional<VehicleType>
getFuelType(String id)Optional<FuelType>
getRimDesign(String id)Optional<RimDesign>

Creating vehicles

All createVehicle(...) overloads create a StorageVehicle, save it, and (if a garage is given) add it to that garage. They return null if the model doesn't exist or the updater returned null.

MethodNotes
createVehicle(String modelID)By model id.
createVehicle(String modelID, Garage garage)…and add it to a garage.
createVehicle(String modelID, Function<StorageVehicle,StorageVehicle> updater)…running an updater (e.g. to set a color) before saving.
createVehicle(String modelID, Garage garage, Function<…> updater)Both.
createVehicle(VehicleModel model)Same set of overloads, but taking a VehicleModel.
createVehicle(VehicleModel model, Garage garage)
createVehicle(VehicleModel model, Function<…> updater)
createVehicle(VehicleModel model, Garage garage, Function<…> updater)The core overload.
The updater

The updater lets you configure the freshly-created vehicle before it's saved — e.g. apply a color to its skins. Return the (modified) vehicle, or null to abort creation.


Querying vehicles

MethodReturns / purpose
getVehicle(UUID uuid)The Vehicle with that id, or null.
getVehicle(Player p)Optional<SpawnedVehicle> — the vehicle the player is in.
getVehicleFromHolder(ArmorStand stand)Optional<SpawnedVehicle> — from the invisible holder stand.
getVehicleFromPart(ArmorStand stand)Optional<SpawnedVehicle> — from a visible part stand.
getVehicles(OfflinePlayer p)List<Vehicle> — all of a player's vehicles.
doesPlayerOwnVehicles(OfflinePlayer p)boolean.
getStorageVehicles()List<StorageVehicle> — every stored vehicle.
getSpawnedVehicles()List<SpawnedVehicle> — every vehicle currently in the world.
getStorageVehicles(OfflinePlayer p, boolean force)A player's stored vehicles.
getSpawnedVehicles(OfflinePlayer p)A player's currently-spawned vehicles.
despawnVehiclesOfModel(String modelId)Despawn every spawned vehicle of a model (persistent ones re-spawn). Returns the count.

Garages

MethodReturns / purpose
getPersonalGarage(OfflinePlayer p)The player's personal garage (created if missing).
getGarages(OfflinePlayer p)List<Garage> — garages the player is in.
getGarages(OfflinePlayer p, boolean ownerOnly)…optionally only those they own.
getGarage(String name)Optional<Garage> — a named garage.
getGarage(Vehicle vehicle)Optional<Garage> — the garage holding a vehicle.
addGarage(Garage garage, boolean force)Register a garage.
removeGarage(String name)Remove a garage. Returns true on success.

A Garage exposes getOwner(), getMembers(), getRole(Player), getVehicles() (UUIDs), getDisplayName(), addVehicle(UUID), addMember(...) and more — see Garages and the Javadoc.


Extending the plugin

MethodPurpose
registerHook(Runnable hook)Run code once VehiclesPlus is ready (e.g. to register custom content safely).
registerPart(Class<? extends Part> partClass)Register your own custom part type so it can be used in models.

See the Examples page for these methods in action, and Events to react to what happens in-game.