Skip to content

NPE on PlayerInteractEvent in RpgEntities #148

@Lochnair

Description

@Lochnair

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);
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions