RpgEssentials icon indicating copy to clipboard operation
RpgEssentials copied to clipboard

NPE on PlayerInteractEvent in RpgEntities

Open Lochnair opened this issue 12 years ago • 0 comments

How to reproduce: Right-click a block without holding anything

Fix: Simply changing the method from

@EventHandler
    public void onplayerInteract(PlayerInteractEvent event){
        if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(event.getItem().getTypeId() == Material.STICK.getId()){
                Location l = event.getClickedBlock().getLocation().add(0, 1, 0);
                RpgEntities.em.spawnRpgEntity(l, EntityType.WOLF);
            }
        }
    }

To this

@EventHandler
    public void onplayerInteract(PlayerInteractEvent event){
        if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(event.getItem() != null && event.getItem().getTypeId() == Material.STICK.getId()){
                Location l = event.getClickedBlock().getLocation().add(0, 1, 0);
                RpgEntities.em.spawnRpgEntity(l, EntityType.WOLF);
            }
        }
    }

Lochnair avatar Jun 17 '13 13:06 Lochnair