From cd8cfcaaf3123e312b6afaa0522c839107b91473 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sat, 28 Dec 2024 21:28:06 +0000 Subject: [PATCH] docs: update vehiclesplus-v3/api/examples --- vehiclesplus-v3/api/examples.md | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/vehiclesplus-v3/api/examples.md b/vehiclesplus-v3/api/examples.md index d86d48d..967bfd5 100644 --- a/vehiclesplus-v3/api/examples.md +++ b/vehiclesplus-v3/api/examples.md @@ -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 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 (optionalGarage.isPresent()) { - Garage garage = optionalGarage.get(); + if (vehicle == null) { + System.err.println("Failed to create vehicle of type: " + vehicleType); + return; // Exit if the vehicle could not be created + } + 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