Set boat speed

Discussion in 'Plugin Development' started by Welite, Jan 22, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Welite

    Hi, I am trying to "freeze" boat by seting speed of the boat to 0, but for some reason the function in bukkit does not work.

    My code:
    Code:java
    1.  
    2. Entity e = event.getVehicle();
    3. Boat boat = (Boat)e;
    4. p.sendMessage("" + boat.getMaxSpeed());
    5. boat.setMaxSpeed(0.0);
    6. p.sendMessage("" + boat.getMaxSpeed());


    The debug messages are saying:
    0.4
    0.4
    So the speed of the boat is not changed after boat.setMaxSpeed(0.0);


    Can someone tell me what I am doing wrong or it is just simply broken in bukkit ?
     
  2. Welite You might want to try this:
    Code:java
    1. @EventHandler
    2. public void onVehicleDrive(VehicleMoveEvent event){
    3. Entity vehicle = event.getVehicle();
    4. Entity passenger = event.getVehicle().getPassenger();
    5. if (vehicle instanceof Boat){
    6. if(passenger instanceof Player){
    7. Boat boat = (Boat) vehicle;
    8. Player player = (Player)passenger;
    9. double newMaxSpeed = 0;
    10. player.sendMessage("" + boat.getMaxSpeed());
    11. boat.setMaxSpeed(newMaxSpeed);
    12. player.sendMessage("" + boat.getMaxSpeed());
    13. }
    14. }
    15. }


    Never worked with this, so idk. Just something what I think that might work.

    EDIT: Change the event to whatever event you used I do not know which one that was as you did not show it.
     
  3. Offline

    Welite

    Hi, thanks for you message, but it seems like it does not work.

    I have exactly this code:
    Code:java
    1. @EventHandler
    2. public void onVehicleCreate(VehicleCreateEvent event) {
    3. for (Player p : Bukkit.getOnlinePlayers()) {
    4. if (temp.getString("List.queue").contains(p.getName())) {
    5. Entity e = event.getVehicle();
    6. if (e instanceof Boat){
    7. temp.set("List.queue", temp.getString("List.queue").replace(p.getName(), " "));
    8. event.getVehicle().setPassenger(p);
    9. event.getVehicle().getUniqueId();
    10. String uuids = temp.getString("Arenas." + getArena(p) + ".UUID");
    11. String newuuids = uuids + " " + event.getVehicle().getUniqueId();
    12. temp.set("Arenas." + getArena(p) + ".UUID", newuuids);
    13. saveall();
    14. Boat boat = (Boat)e;
    15. p.sendMessage("" + boat.getMaxSpeed());
    16. boat.setMaxSpeed(0.0);
    17. p.sendMessage("" + boat.getMaxSpeed());
    18. }
    19. }
    20. }
    21. }


    And the output is:
    0.4
    0.4
    So it seems like the " boat.setMaxSpeed(0.0);" is totally ignored.

    Also it is not possible to cancel VehicleMoveEvent so how can I stop for a while moving boat with player and then let him move again ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page