3
0
Fork 0

Update to use bukkit loggers

This commit is contained in:
cedric 2025-01-12 20:09:03 +01:00
parent deb9bd2fc7
commit 87c8cdeeed
3 changed files with 15 additions and 12 deletions

View file

@ -4,6 +4,7 @@ import nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI;
import nl.sbdeveloper.vehiclesplus.api.garages.Garage; import nl.sbdeveloper.vehiclesplus.api.garages.Garage;
import nl.sbdeveloper.vehiclesplus.api.vehicles.Vehicle; import nl.sbdeveloper.vehiclesplus.api.vehicles.Vehicle;
import nl.sbdeveloper.vehiclesplus.storage.db.exceptions.DataStorageException; import nl.sbdeveloper.vehiclesplus.storage.db.exceptions.DataStorageException;
import org.bukkit.Bukkit;
import java.util.Optional; import java.util.Optional;
@ -22,7 +23,7 @@ public class DeleteVehicle {
// Check if the police garage exists, and if not, print an error message and exit // Check if the police garage exists, and if not, print an error message and exit
if (policeGarageOptional.isEmpty()) { if (policeGarageOptional.isEmpty()) {
System.err.println("Error: The 'police' garage does not exist."); Bukkit.getLogger().warning("Error: The 'police' garage does not exist.");
return; return;
} }
@ -45,15 +46,15 @@ public class DeleteVehicle {
try { try {
// Remove the vehicle from the garage // Remove the vehicle from the garage
vehicleToRemove.remove(); vehicleToRemove.remove();
System.out.println("Vehicle with model '" + vehicleModelName + "' has been successfully removed from the police garage."); Bukkit.getLogger().info("Vehicle with model '" + vehicleModelName + "' has been successfully removed from the police garage.");
} catch (DataStorageException e) { } catch (DataStorageException e) {
// Handle any errors that occur during the removal process // Handle any errors that occur during the removal process
System.err.println("Error: Failed to remove vehicle with model '" + vehicleModelName + "' from the garage."); Bukkit.getLogger().warning("Error: Failed to remove vehicle with model '" + vehicleModelName + "' from the garage.");
throw new RuntimeException("Error while removing vehicle", e); throw new RuntimeException("Error while removing vehicle", e);
} }
} else { } else {
// If no matching vehicle was found, print an error message // If no matching vehicle was found, print an error message
System.err.println("Error: No vehicle with model '" + vehicleModelName + "' found in the police garage."); Bukkit.getLogger().warning("Error: No vehicle with model '" + vehicleModelName + "' found in the police garage.");
} }
} }
} }

View file

@ -4,6 +4,7 @@ import nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI;
import nl.sbdeveloper.vehiclesplus.api.events.impl.VehicleDespawnEvent; import nl.sbdeveloper.vehiclesplus.api.events.impl.VehicleDespawnEvent;
import nl.sbdeveloper.vehiclesplus.api.vehicles.Vehicle; import nl.sbdeveloper.vehiclesplus.api.vehicles.Vehicle;
import nl.sbdeveloper.vehiclesplus.api.vehicles.impl.SpawnedVehicle; import nl.sbdeveloper.vehiclesplus.api.vehicles.impl.SpawnedVehicle;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -26,10 +27,10 @@ public class DespawnVehicle {
if (firstSpawnedVehicleOptional.isPresent()) { if (firstSpawnedVehicleOptional.isPresent()) {
// Despawn the vehicle using the API's despawn reason // Despawn the vehicle using the API's despawn reason
firstSpawnedVehicleOptional.get().despawn(VehicleDespawnEvent.DespawnReason.API); firstSpawnedVehicleOptional.get().despawn(VehicleDespawnEvent.DespawnReason.API);
System.out.println("Vehicle despawned successfully."); Bukkit.getLogger().info("Vehicle despawned successfully.");
} else { } else {
// Handle the case where the player doesn't have a spawned vehicle // Handle the case where the player doesn't have a spawned vehicle
System.err.println("Player does not have a spawned vehicle."); Bukkit.getLogger().warning("Player does not have a spawned vehicle.");
} }
} }
@ -54,10 +55,10 @@ public class DespawnVehicle {
if (closestVehicleOptional.isPresent()) { if (closestVehicleOptional.isPresent()) {
// Despawn the closest vehicle using the API's despawn reason // Despawn the closest vehicle using the API's despawn reason
closestVehicleOptional.get().despawn(VehicleDespawnEvent.DespawnReason.API); closestVehicleOptional.get().despawn(VehicleDespawnEvent.DespawnReason.API);
System.out.println("Closest vehicle despawned successfully."); Bukkit.getLogger().info("Closest vehicle despawned successfully.");
} else { } else {
// Handle the case where no spawned vehicles are found for the target player // Handle the case where no spawned vehicles are found for the target player
System.err.println("Target player does not have any spawned vehicles."); Bukkit.getLogger().warning("Target player does not have any spawned vehicles.");
} }
} }
} }

View file

@ -3,6 +3,7 @@ package tech.sbdevelopment.websiteExample.examples;
import nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI; import nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI;
import nl.sbdeveloper.vehiclesplus.api.garages.Garage; import nl.sbdeveloper.vehiclesplus.api.garages.Garage;
import nl.sbdeveloper.vehiclesplus.api.vehicles.impl.StorageVehicle; import nl.sbdeveloper.vehiclesplus.api.vehicles.impl.StorageVehicle;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class GiveVehicle { public class GiveVehicle {
@ -20,13 +21,13 @@ public class GiveVehicle {
// If vehicle creation fails, log the error and exit // If vehicle creation fails, log the error and exit
if (createdVehicle == null) { if (createdVehicle == null) {
System.err.println("Failed to create vehicle of type: " + vehicleType); Bukkit.getLogger().warning("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
} }
// Add the created vehicle's UUID to the target garage // Add the created vehicle's UUID to the target garage
targetGarage.addVehicle(createdVehicle.getUuid()); targetGarage.addVehicle(createdVehicle.getUuid());
System.out.println("Vehicle created and added to the garage successfully."); Bukkit.getLogger().info("Vehicle created and added to the garage successfully.");
} }
/** /**
@ -45,12 +46,12 @@ public class GiveVehicle {
// If vehicle creation fails, log the error and exit // If vehicle creation fails, log the error and exit
if (createdVehicle == null) { if (createdVehicle == null) {
System.err.println("Failed to create vehicle of type: " + vehicleType); Bukkit.getLogger().warning("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
} }
// Add the created vehicle's UUID to the player's personal garage // Add the created vehicle's UUID to the player's personal garage
playerGarage.addVehicle(createdVehicle.getUuid()); playerGarage.addVehicle(createdVehicle.getUuid());
System.out.println("Vehicle created and added to the player's personal garage successfully."); Bukkit.getLogger().info("Vehicle created and added to the player's personal garage successfully.");
} }
} }