API

Please keep in mind that this wiki only shows a limited selection of methods, functions and possibilites.

For further questions regarding the development of addons, methods, or just general questions about what is possible, ask us on our discord server. Do read the entire page here though.


Using the API

Step 1:

Create a /libs folder in your project, and drag and drop the Vehicles jar into the folder.

Step 2:

Add the following to your pom.xml if you are using Maven:

<dependency>
  <groupId>Vehicles</groupId>
  <artifactId>Vehicles</artifactId>
  <scope>system</scope>
  <version>1.0</version>
  <systemPath>${pom.basedir}/src/main/java/<path>/<to>/<folder>/libs/Vehicles.jar</systemPath>
</dependency>

Depending on how you called your Vehicles.jar, you may also need to change that part in the SystemPath.

Step 3:

You can now use the Vehicles API. Don't forget to add Vehicles as a dependency to your plugin.yml

The Vehicle object is a custom one. It is not the same as the org.bukkit.entity Vehicle. Please make sure to import the correct Vehicle. eg.:

import es.pollitoyeye.vehicles.interfaces.Vehicle;

Limitations of the API


Available Events


General API Methods

The following code selections are based off of the VehiclesMain instance:

VehiclesMain mainClass = VehiclesMain.getPlugin()
mainClass.<snippet>;

The following code selections are generalised and should give insight on what info you can get/set from Vehicles. Please keep in mind, that you call these methods with a Vehicle object.


Code Examples

Spawn a new Vehicle

Spawning is done via the VehicleManager. Each Vehicle has its own Manager.

// General VehicleManager
VehicleManager vehicleManager;

// Examples of the "per Vehicle" Managers
VehicleManager carManager = new CarManager();
VehicleManager tankManager = new TankManager();
VehicleManager planeManager = new PlaneManager();                      

// General method and parameters
vehicleManager.spawn(location, ownerUUID, vehicleSubType);

// Example of spawning a car
carManager.spawn(new Location(Bukkit.getWorld("world"), 0, 0, 0), "5ec4c0de-17ed-4d34-bddf-c703b5ac5737", "BLACK");
Instant Mount a Player on a Vehicle

Due to Vehicles having a 20L delay when all interaction is blocked with it, you need to delay the mounting as well. Mounting only works by firing a playerInteractAtEntityEvent yourself.

@EventHandler
public void onVehicleSpawn(VehicleSpawnedEvent event) {
    // Grab a random armorstand to fire the event on
    ArmorStand armorStand = event.getVehicleParts().get(0);
    Location location = armorStand.getLocation();

    // Create new Vector from its location
    Vector vector = new Vector(location.getBlockX(), location.getBlockY(), location.getBlockZ());

    // Create PlayerInteractAtEntityEvent
    Player player = Bukkit.getPlayer(UUID.fromString(event.getOwner()));
    PlayerInteractAtEntityEvent playerInteractAtEntityEvent = new PlayerInteractAtEntityEvent(player, armorStand, vector, EquipmentSlot.HAND);
    
    // Schedule event to fire after the delay
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable(){
        @Override
        public void run(){
            Bukkit.getServer().getPluginManager().callEvent(playerInteractAtEntityEvent);
        }
    }, 21L);
}

Last updated