minecart speed?

Discussion in 'Plugin Development' started by TopGear93, Dec 22, 2011.

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

    TopGear93

    sorry for asking alot of questions, im trying to get into new parts of bukkit.

    What do i need to do in order to get the speed of the minecart. I tried to do this.


    Code:
        public void onVehicleEntityCollision(VehicleEntityCollisionEvent event){
            Entity entity = event.getEntity();
            Vehicle vehicle = event.getVehicle();
            if(entity instanceof Player){
                Player player = (Player)entity;
                if (vehicle instanceof Minecart && (vehicle.getVelocity().equals(10)));
                        player.damage(1);
            }
        }
    }
    i tried to see if the velocity equals 10. But the player gets damaged even when the minecart is standing still.
     
  2. Offline

    unicode21B9

    Velocity is a vector, and can't be compared to an integer. You first have to get it's length:
    Code:
    if (vehicle instanceof Minecart && vehicle.getVelocity().length() >= 10)
        player.damage(1);
    }
    
     
  3. Offline

    nisovin

    Your problem is actually that you have a semicolon at the end of the if statement, so the line below it is actually not part of the if statement at all, but outside and after it.
     
Thread Status:
Not open for further replies.

Share This Page