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:
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 for 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 manually.
@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
Was this helpful?
No custom Vehicles
As our FAQ already hinted towards, you can't create your own Vehicles with this plugin. Not even using the API.
No automatic Vehicle movement
You can't force Vehicles to follow a specific path (eg: like TrainCarts).
Want something added?
Tell us on our discord and the developer can see what is possible. Don't ask about new Vehicles though =).
Movement tracking is resource intensive
Default MoveEvents from Bukkit and other checks don't work, as only the armorstand moves.
ProtocolLib offers a VehicleSteerPacket, which can register the movement.
VehicleEnterEvent
This event gets fired when a player right clicks a Vehicle to mount it. You can not manually fire this event.