RpgEssentials
RpgEssentials copied to clipboard
NPE on PlayerInteractEvent in RpgEntities
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);
}
}
}