1 | package com.example.vehiclesplusplugin;
|
2 |
|
3 | import org.bukkit.plugin.java.JavaPlugin;
|
4 | import com.github.vehiclesplus.vehicles.api.VehiclesPlusAPI;
|
5 |
|
6 | public class VehiclesPlusPlugin extends JavaPlugin {
|
7 |
|
8 | @Override
|
9 | public void onEnable() {
|
10 | // Plugin startup logic
|
11 | getLogger().info("VehiclesPlusPlugin has been enabled!");
|
12 |
|
13 | // Example of using the VehiclesPlus API
|
14 | VehiclesPlusAPI vehiclesPlusAPI = VehiclesPlusAPI.getInstance();
|
15 | if (vehiclesPlusAPI != null) {
|
16 | getLogger().info("Successfully hooked into VehiclesPlus API!");
|
17 | } else {
|
18 | getLogger().severe("Failed to hook into VehiclesPlus API!");
|
19 | }
|
20 |
|
21 | // Register command
|
22 | this.getCommand("spawndrill").setExecutor(new SpawnDrillCommand());
|
23 | }
|
24 |
|
25 | @Override
|
26 | public void onDisable() {
|
27 | // Plugin shutdown logic
|
28 | getLogger().info("VehiclesPlusPlugin has been disabled!");
|
29 | }
|
30 | }
|
31 | This ^^^ is Vehiclesplusplugin.java
|
32 | package com.example.vehiclesplusplugin;
|
33 |
|
34 | import com.github.vehiclesplus.vehicles.api.VehiclesPlusAPI;
|
35 | import com.github.vehiclesplus.vehicles.api.vehicle.VehicleType;
|
36 | import org.bukkit.command.Command;
|
37 | import org.bukkit.command.CommandExecutor;
|
38 | import org.bukkit.command.CommandSender;
|
39 | import org.bukkit.entity.Player;
|
40 |
|
41 | public class SpawnDrillCommand implements CommandExecutor {
|
42 |
|
43 | @Override
|
44 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
45 | if (!(sender instanceof Player)) {
|
46 | sender.sendMessage("This command can only be used by players.");
|
47 | return true;
|
48 | }
|
49 |
|
50 | Player player = (Player) sender;
|
51 | VehiclesPlusAPI vehiclesPlusAPI = VehiclesPlusAPI.getInstance();
|
52 |
|
53 | if (vehiclesPlusAPI == null) {
|
54 | player.sendMessage("VehiclesPlus API is not available.");
|
55 | return true;
|
56 | }
|
57 |
|
58 | // Example: Spawn a custom drill vehicle
|
59 | VehicleType vehicleType = VehicleType.CAR; // Use an existing type as a base
|
60 | DrillVehicle drillVehicle = new DrillVehicle(vehicleType, player.getLocation());
|
61 |
|
62 | if (drillVehicle != null) {
|
63 | vehiclesPlusAPI.getVehicleManager().registerVehicle(drillVehicle);
|
64 | player.sendMessage("Drill vehicle spawned successfully!");
|
65 | } else {
|
66 | player.sendMessage("Failed to spawn drill vehicle.");
|
67 | }
|
68 |
|
69 | return true;
|
70 | }
|
71 | }
|
72 | this ^^^ is Spawndrillcommand.java
|
73 | package com.example.vehiclesplusplugin;
|
74 |
|
75 | import com.github.vehiclesplus.vehicles.api.vehicle.Vehicle;
|
76 | import com.github.vehiclesplus.vehicles.api.vehicle.VehicleType;
|
77 | import org.bukkit.Location;
|
78 | import org.bukkit.Material;
|
79 | import org.bukkit.block.Block;
|
80 | import org.bukkit.entity.Player;
|
81 |
|
82 | public class DrillVehicle extends Vehicle {
|
83 |
|
84 | public DrillVehicle(VehicleType type, Location location) {
|
85 | super(type, location);
|
86 | }
|
87 |
|
88 | @Override
|
89 | public void onMove(Player driver) {
|
90 | super.onMove(driver);
|
91 |
|
92 | // Get the direction the vehicle is facing
|
93 | Location frontLocation = getLocation().clone().add(getLocation().getDirection().multiply(2));
|
94 |
|
95 | // Mine a 3x3 area in front of the vehicle
|
96 | for (int x = -1; x <= 1; x++) {
|
97 | for (int y = -1; y <= 1; y++) {
|
98 | Location blockLocation = frontLocation.clone().add(x, y, 0);
|
99 | Block block = blockLocation.getBlock();
|
100 | if (block.getType() != Material.AIR) {
|
101 | block.breakNaturally();
|
102 | }
|
103 | }
|
104 | }
|
105 | }
|
106 | }
|
107 | and this is ^^^^ Drillvehicle.java
|