2024-12-28 21:11:05 +00:00
|
|
|
---
|
|
|
|
title: Examples
|
|
|
|
description: Example usages of the api
|
|
|
|
published: false
|
2024-12-28 21:29:50 +00:00
|
|
|
date: 2024-12-28T21:29:47.658Z
|
2024-12-28 21:11:05 +00:00
|
|
|
tags: developers
|
|
|
|
editor: markdown
|
|
|
|
dateCreated: 2024-12-28T21:11:02.102Z
|
|
|
|
---
|
|
|
|
|
|
|
|
# VehiclesPlus API Examples
|
|
|
|
|
|
|
|
In this section, you'll find additional examples of how to use the VehiclesPlus API (v3) for various tasks.
|
|
|
|
|
|
|
|
## Example 1: Adding a Car to Someone's Garage
|
|
|
|
|
|
|
|
```java
|
|
|
|
// Give car to garage
|
|
|
|
public void giveCar(Garage garage, String vehicleType) {
|
|
|
|
// Attempt to create a vehicle
|
|
|
|
StorageVehicle vehicle = VehiclesPlusAPI.createVehicle(vehicleType);
|
|
|
|
|
|
|
|
if (vehicle == null) {
|
|
|
|
System.err.println("Failed to create vehicle of type: " + vehicleType);
|
|
|
|
return; // Exit if the vehicle could not be created
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the vehicle's UUID to the garage
|
|
|
|
garage.addVehicle(vehicle.getUuid());
|
|
|
|
System.out.println("Vehicle created and added to the garage successfully.");
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example 2: Adding a Vehicle to the Player's Default Garage
|
|
|
|
|
|
|
|
```java
|
|
|
|
// Give car to player's default garage
|
2024-12-28 21:28:06 +00:00
|
|
|
public void giveCar(Player player, String vehicleType) {
|
|
|
|
// Attempt to create a vehicle
|
|
|
|
StorageVehicle vehicle = VehiclesPlusAPI.createVehicle(vehicleType);
|
|
|
|
|
|
|
|
// Retrieve the player's default garage
|
|
|
|
// Note: This method will always return a garage, even if the player does not have one.
|
|
|
|
// If the player does not have a garage, the garage will be created.
|
|
|
|
Garage garage = VehiclesPlusAPI.getPersonalGarage(player);
|
|
|
|
|
|
|
|
if (vehicle == null) {
|
|
|
|
System.err.println("Failed to create vehicle of type: " + vehicleType);
|
|
|
|
return; // Exit if the vehicle could not be created
|
|
|
|
}
|
|
|
|
|
2024-12-28 21:11:05 +00:00
|
|
|
garage.addVehicle(vehicle.getUuid());
|
|
|
|
System.out.println("Vehicle created and added to the garage successfully.");
|
|
|
|
}
|
|
|
|
```
|