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
|
||||
description: Example usages of the api
|
||||
published: false
|
||||
date: 2024-12-28T21:11:02.102Z
|
||||
date: 2024-12-28T21:28:03.948Z
|
||||
tags: developers
|
||||
editor: markdown
|
||||
dateCreated: 2024-12-28T21:11:02.102Z
|
||||
|
@ -35,25 +35,21 @@ public void giveCar(Garage garage, String vehicleType) {
|
|||
|
||||
```java
|
||||
// Give car to player's default garage
|
||||
public void giveCar(Player player, String vehicleType) {
|
||||
// Attempt to create a vehicle
|
||||
StorageVehicle vehicle = VehiclesPlusAPI.createVehicle(vehicleType);
|
||||
public void giveCar(Player player, String vehicleType) {
|
||||
// Attempt to create a vehicle
|
||||
StorageVehicle vehicle = VehiclesPlusAPI.createVehicle(vehicleType);
|
||||
|
||||
// Retrieve the player's default garage
|
||||
Optional<Garage> optionalGarage = VehiclesPlusAPI.getGarage(player.getName());
|
||||
// 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
|
||||
}
|
||||
if (vehicle == null) {
|
||||
System.err.println("Failed to create vehicle of type: " + vehicleType);
|
||||
return; // Exit if the vehicle could not be created
|
||||
}
|
||||
|
||||
if (optionalGarage.isPresent()) {
|
||||
Garage garage = optionalGarage.get();
|
||||
garage.addVehicle(vehicle.getUuid());
|
||||
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