From b7da5c9fe5453df68bcaf521c739190332c3f0a4 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sat, 28 Dec 2024 21:08:28 +0000 Subject: [PATCH 1/2] docs: update vehiclesplus-v3/api --- vehiclesplus-v3/api.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vehiclesplus-v3/api.md b/vehiclesplus-v3/api.md index aa9121a..eba5b3e 100644 --- a/vehiclesplus-v3/api.md +++ b/vehiclesplus-v3/api.md @@ -1,8 +1,8 @@ --- -title: API -description: Api usage examples +title: Getting Started +description: Api usage published: false -date: 2024-12-28T21:07:51.850Z +date: 2024-12-28T21:08:25.669Z tags: developers editor: markdown dateCreated: 2024-12-28T20:10:42.650Z From f35cd11f312ee4d053a786be2c5d30c336e95f7c Mon Sep 17 00:00:00 2001 From: Cedric Date: Sat, 28 Dec 2024 21:11:05 +0000 Subject: [PATCH 2/2] docs: create vehiclesplus-v3/api/examples --- vehiclesplus-v3/api/examples.md | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 vehiclesplus-v3/api/examples.md diff --git a/vehiclesplus-v3/api/examples.md b/vehiclesplus-v3/api/examples.md new file mode 100644 index 0000000..d86d48d --- /dev/null +++ b/vehiclesplus-v3/api/examples.md @@ -0,0 +1,59 @@ +--- +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 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. + } +} +``` \ No newline at end of file