VehicleDestroyEvent

Discussion in 'Plugin Development' started by Welite, Feb 6, 2014.

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

    Welite

    Hi, I have a plugin that prevents boat from destroying but it prevents only from crashes but when for example boat falls from a waterfall the boat is destroyed by the fall. I have this code:


    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onVehicleDestroy(VehicleDestroyEvent event) {
    3. if ((event.getVehicle() instanceof Boat)) {
    4. event.setCancelled(true);
    5. Bukkit.broadcastMessage("VehicleDestroyEvent");
    6. }
    7. }


    It cancels perfectly when boat crash or something but when it falls or the boat gets out of water is destroyed and the event is not fired , also when a boat falls at another boat under waterfall the boat gets destroyed...
    So I dont know how to totally prevent boat from breaking.
     
  2. Offline

    Garris0n

    When it gets out of water? Is this the only plugin on the server?
     
  3. Offline

    Welite

    Yes it is.
    My boat does not get destroyed by crash but when the boat falls it still gets destroyed and the event VehicleDestroyEvent is not fired, it is a bug or there is another vehicle destroy event of something like that ?
     
  4. Offline

    Alshain01

    Try the VehicleDamageEvent. It can't be destroyed if it can't be damaged... in theory anyway.
     
  5. Offline

    Welite

    I have already tried it:


    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onVehicleEntityDestroy(EntityDeathEvent event) {
    3. if ((event.getEntity() instanceof Boat)) {
    4. Player pasazer = (Player)event.getEntity().getVehicle().getPassenger();
    5. if (pasazer != null) {
    6. Bukkit.broadcastMessage("EntityDamageEvent");
    7. }
    8. }
    9. }


    And also:
    Code:java
    1. @EventHandler
    2. public void onVehicleDamage(VehicleDamageEvent event) {
    3. if ((event.getVehicle() instanceof Boat)) {
    4. Player pasazer = (Player)event.getVehicle().getPassenger();
    5. if (pasazer != null) {
    6. event.setCancelled(true);
    7. Bukkit.broadcastMessage("VehicleDamageEvent");
    8. }
    9. }
    10. }



    These events are not even fired when I am crashing to some walls or obstacles.
     
  6. Offline

    Mr360zack

    Code:java
    1. @EventHandler
    2. public void onVehicleDestroy(VehicleDestroyEvent e) {
    3. if (e.getVehicle() instanceof Boat) {
    4. e.setCancelled(true);
    5. return;
    6. }
    7. }
    8.  
    9. @EventHandler
    10. public void onVehicleDamageEvent(VehicleDamageEvent e) {
    11. if (e.getVehicle() instanceof Boat) {
    12. if (e.getVehicle().getPassenger() == null) {
    13. e.getVehicle().remove();
    14. return;
    15. }
    16. e.setCancelled(true);
    17. return;
    18. }
    19. }
     
  7. Offline

    Welite

    What ? This I exactly posted in my reply above lol.

    Can someone list me please on which events can boat be destroyed ? Because in case of boat fall VehicleDestroyEvent is not fired so I dont know where to cancel destruction of the boat.

    Should this be marked as error in Bukkit ?

    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