Question about onVehicleExit

Discussion in 'Plugin Development' started by kerovan, Jul 27, 2011.

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

    kerovan

    I am trying to set event.setCancelled(true) to prevent a player from exiting the minecart while they are traveling in our subway system.

    The event is firing because the message I send to the player is sent however I still exit the cart.

    Is the actual act of leaving the cart completed before this event fires perhaps in the Player_Interact event??

    Any help is greatly appreciated.

    I am still fairly new to plugin develeopment and Java in general so go easy on me :)
     
  2. Offline

    vcazan

    I dont know what you are using but I use onVehicleExit and its working great.
    Code:
    public void onVehicleExit(VehicleExitEvent event){
          event.setCancelled(true);
    }
     
  3. Offline

    kerovan

    Thank you vcazan for your reply.


    That is what I am using. The only thing extra is the message being sent to the player.

    When I get home tonight I will post the code, maybe I am doing something wrong with the player object that
    is causing the setCancelled to mess up.
     
  4. Offline

    kerovan

    Ok, I forgot to post the code lastnight.. I can say this, I cut the function out completely and pasted in your code and I got the same result - I still exited the minecart. Any other ideas?
     
  5. 2 possible things:
    1. You don't register your event properly.
    2. Your class with the method in it extends the wrong superclass (freaking use @Override!)
     
  6. Offline

    boduzapho

    As I am trying to duplicate this in 1.2.5-r2, It still seems buggy.
    I looked at your code and i could not find ANY where you were cancelling the VehicleExitEvent.

    I suggest you make sure you have tested your code before saying it works.

    Code:
    @EventHandler(priority = EventPriority.HIGH) public void onVehicleExit(VehicleExitEvent event)
    {
    {
          if (event.getExited() instanceof Player)
          {
          Player p = (Player) event.getExited();
          Entity cart = event.getVehicle(); //<-- works as expected
          cart.remove(); //<-- works as expected
          p.sendMessage("Goodbye!"); //<-- works as expected
          Methods.handlewarp("spawn", p); //<-- Does not work (same as player.teleport)
          }
      }
    }
     
    @EventHandler(priority = EventPriority.HIGH) public void onVehicleExit(VehicleExitEvent event)
        {
            event.setCancelled(true);  // <-- Does not work
        }
     
    
     
  7. p.sendMessage("Goodbye!"); //<-- works as expected
    ^^ wont work, sendMessage(String) is not definited for p
     
  8. Offline

    boduzapho

    It works fine for me, changed my method in above post to match what I am testing now.
     
Thread Status:
Not open for further replies.

Share This Page