Hello ! I'm coming to you because I'm brand new to Java and I'm encountering a problem.
My goal is to create a plugin that will allow boat races! So the first challenge, which seemed simple to me, is to be able to assemble blocks with a boat ☠️
The problem is that you can't teleport a boat or a player when a player is in a boat! You have to modify the boat's velocity, and these values are quite complex 😅
So I did a few tests, which turned out to be pretty good, with a block of sponge under the track:
public final class BoatRace extends JavaPlugin implements Listener {
private final HashMap<UUID, BukkitTask> raceTimers = new HashMap<>();
@Override
public void onEnable() {
getLogger().info("BoatRace has been enabled!");
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable() {
getLogger().info("BoatRace has been disabled!");
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (player.isInsideVehicle() && player.getVehicle() instanceof Boat) {
Boat boat = (Boat) player.getVehicle();
Location boatLocation = boat.getLocation();
// Vérifier le bloc deux blocs en dessous du bateau
Block blockTwoBelow = boatLocation.getBlock().getRelative(BlockFace.DOWN, 2);
if (blockTwoBelow.getType() == Material.SPONGE) {
boat.setVelocity(boat.getVelocity().add(new Vector(0, 0.6, 0)));
}
}
}
}
But....