Solved why does VehicleExitEvent not work?

Discussion in 'Plugin Development' started by xize, Jul 28, 2014.

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

    xize

    Hello,

    so I'm trying to make a chairs plugin but I ecountered a strange problem the VehicleExitEvent just don't gets fired on chickens.

    however sitting on a chair/chicken works fine so I know that the event is registered properly since both events are in the same class.

    my qeustion is why does it not fire? my code:

    Code:
        @EventHandler
        public void onInteract(PlayerInteractEvent e) {
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if(e.getClickedBlock().getType() == Material.WOOD_STAIRS || e.getClickedBlock().getType() == Material.COBBLESTONE_STAIRS || e.getClickedBlock().getType() == Material.SMOOTH_STAIRS || e.getClickedBlock().getType() == Material.BRICK_STAIRS) {
                    if(isChair(e.getClickedBlock())) {
                        Chicken chicken = (Chicken)e.getClickedBlock().getWorld().spawnEntity(e.getClickedBlock().getLocation().add(0.5, 0, 0.5), EntityType.CHICKEN);
                        chicken.setMetadata("chair", new FixedMetadataValue(xEssentials.getPlugin(), e.getPlayer().getName()));
                        chicken.setPassenger(e.getPlayer());
                        e.getPlayer().sendMessage(ChatColor.GREEN + "you are now sitting on a chair.");
                    }
                }
            }
        }
        
        @EventHandler
        public void onEject(VehicleExitEvent e) {
            System.out.print("entity: " + e.getVehicle().getType().name()); //here it says nothing.
            if(e.getVehicle() instanceof Chicken) {
                Chicken chicken = (Chicken) e.getVehicle();
                if(chicken.hasMetadata("chair")) {
                    System.out.print("chicken found.");
                    Player p = (Player) e.getExited();
                    p.sendMessage(ChatColor.GREEN + "you are no longer sitting on a chair.");
                    chicken.remove();
                }
            }
        }
    
    I dismount myself using q (sneak) btw.
     
  2. Offline

    GameplayJDK

    xize likes this.
  3. Offline

    xize

    GameplayJDK

    thanks:), ive just tried it through a HashMap in combination with the sneak event and it works fine :D
     
  4. Offline

    ChipDev

    Code:java
    1. Chicken chicken = //bla bla bla.

    Don't put (Chicken) after Chicken chicken.
    It adds a whole 8 bytes to the plugin :eek:
     
  5. Oh no!
     
    ChipDev likes this.
Thread Status:
Not open for further replies.

Share This Page