Comment on page
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.
Create a
/libs
folder in your project, and drag and drop the Vehicles jar into the folder.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
.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;
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 =).
VehiclePickupEvent
This event gets fired when a player tries to pick a Vehicle up. You can not manually fire this event.
The following code selections are based off of the VehiclesMain instance:
VehiclesMain mainClass = VehiclesMain.getPlugin()
mainClass.<snippet>;
Get current mounted Vehicle from Player
.getPlayerVehicle(player);
Generate subtype from String
.vehicleSubTypeFromString(VehicleType type, String subtype)
Get all current mounted Vehicles as a Hashmap
.playerVehicles;
Get other config options:
.<Config Option here>;
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.
Get the
mainstand
of a VehicleVehicle#getMainstand();
Edit Vehicle stats
Vehicle#setHealth(double);
Vehicle#damage(double);
Vehicle#setFuel(double);
Get current Players on Vehicle
Vehicle#getRidingPlayers();
Get Type / Subtype of Vehicle
Vehicle#getType();
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");
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 modified 4mo ago