docs: update vehiclesplus-v3/api/examples
This commit is contained in:
parent
1ed4df8193
commit
cd8cfcaaf3
1 changed files with 13 additions and 17 deletions
|
@ -2,7 +2,7 @@
|
||||||
title: Examples
|
title: Examples
|
||||||
description: Example usages of the api
|
description: Example usages of the api
|
||||||
published: false
|
published: false
|
||||||
date: 2024-12-28T21:11:02.102Z
|
date: 2024-12-28T21:28:03.948Z
|
||||||
tags: developers
|
tags: developers
|
||||||
editor: markdown
|
editor: markdown
|
||||||
dateCreated: 2024-12-28T21:11:02.102Z
|
dateCreated: 2024-12-28T21:11:02.102Z
|
||||||
|
@ -40,20 +40,16 @@ public void giveCar(Player player, String vehicleType) {
|
||||||
StorageVehicle vehicle = VehiclesPlusAPI.createVehicle(vehicleType);
|
StorageVehicle vehicle = VehiclesPlusAPI.createVehicle(vehicleType);
|
||||||
|
|
||||||
// Retrieve the player's default garage
|
// Retrieve the player's default garage
|
||||||
Optional<Garage> optionalGarage = VehiclesPlusAPI.getGarage(player.getName());
|
// 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) {
|
if (vehicle == null) {
|
||||||
System.err.println("Failed to create vehicle of type: " + vehicleType);
|
System.err.println("Failed to create vehicle of type: " + vehicleType);
|
||||||
return; // Exit if the vehicle could not be created
|
return; // Exit if the vehicle could not be created
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optionalGarage.isPresent()) {
|
|
||||||
Garage garage = optionalGarage.get();
|
|
||||||
garage.addVehicle(vehicle.getUuid());
|
garage.addVehicle(vehicle.getUuid());
|
||||||
System.out.println("Vehicle created and added to the garage successfully.");
|
System.out.println("Vehicle created and added to the garage successfully.");
|
||||||
} else {
|
|
||||||
System.err.println("Garage not found for player: " + player.getName());
|
|
||||||
// Optionally, you could create a new garage for the player here if the API allows it.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
Reference in a new issue