Compare commits
No commits in common. "f35cd11f312ee4d053a786be2c5d30c336e95f7c" and "7fe51a147a28165b3420473c63a53da54aa6fd85" have entirely different histories.
f35cd11f31
...
7fe51a147a
2 changed files with 3 additions and 62 deletions
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
title: Getting Started
|
||||
description: Api usage
|
||||
title: API
|
||||
description: Api usage examples
|
||||
published: false
|
||||
date: 2024-12-28T21:08:25.669Z
|
||||
date: 2024-12-28T21:07:51.850Z
|
||||
tags: developers
|
||||
editor: markdown
|
||||
dateCreated: 2024-12-28T20:10:42.650Z
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
---
|
||||
title: Examples
|
||||
description: Example usages of the api
|
||||
published: false
|
||||
date: 2024-12-28T21:11:02.102Z
|
||||
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
|
||||
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());
|
||||
|
||||
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