Can't cancel event

Discussion in 'Plugin Development' started by Laekh, Jan 9, 2013.

Thread Status:
Not open for further replies.
  1. Hello Bukkit,

    I need the event to leave the Minecart to get cancelled, but it will just let the player leave it anyhow.

    Code:
    @EventHandler
    public void onVehicleExit(VehicleExitEvent event) {
    Player player = (Player) event.getVehicle().getPassenger();
    if(!player.hasPermission("NGOM.CanLeave")) {
    event.setCancelled(true);
    player.sendMessage("You're not allowed to leave the Minecart");
    }
    }
    
    The message 'You're not allowed to leave the Minecart' shows up, but it still ejects me.
    The permission works as I removed the exclamation mark and it didn't prompt me that message anymore.
    Any ideas?

    Thank you,
    Cupcakes.
     
  2. Offline

    zachoooo

    Try changing the event priority, maybe some other plugin is interfering?
     
  3. Offline

    CubixCoders

    I believe EventPriority.LOWEST makes it the first to run so try that
     
  4. Offline

    zachoooo

    No... it should run last to make sure its cancelled
     
  5. Offline

    CubixCoders

    Touche'
     
  6. The highest priority makes it run it through that first, yes.
    The problem is, that I'm not using any other plugins on my test server.
     
  7. Offline

    fireblast709

    Cupcakes69 That is because Craftbukkit does not care about the cancel. Just make it enter the vehicle 1 tick later
    Code:java
    1. new BukkitRunnable()
    2. {
    3. public void run()
    4. {
    5. event.getVehicle().setPassenger(e.getExited());
    6. }
    7. }.runTaskLater(<plugin instance>, 1L);
     
    Cupcakes69 likes this.
  8. That fixed my issue,
    thank you.

    Would you mind explaining why it doesn't care about the cancel?
     
  9. Offline

    fireblast709

    It just calls the event, but afterwards it does nothing with the event (the VehicleExitEvent variable is just ignored)
     
    Cupcakes69 likes this.
  10. Oh, I see.
    Thank you for your information :)
     
Thread Status:
Not open for further replies.

Share This Page