Code:java if(!(b==null) && !(b.getType().equals(Material.AIR))) This line of code isn't working properly and doesn't activate any code under that line.
Wait, I was wrong, Adam was right. Full code please? Or, you could simply have above it Code:java System.out.println("b.getType() =" + b.getType());
Code:java if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR){ if(e.getPlayer().getItemInHand().equals(thorAxe)){ if(thorCooldown.contains(e.getPlayer().getName())){ e.getPlayer().sendMessage(prefix+ChatColor.RED+"Your Powers are still on cooldown."); return; }else{ for(Block b : e.getPlayer().getLineOfSight(null,10)){ if(!(b==null) && !(b.getType().equals(Material.AIR))){ e.getPlayer().sendMessage(prefix+ChatColor.RED+"Success"); e.getPlayer().getWorld().strikeLightning(b.getLocation()); e.getPlayer().sendMessage(prefix+ChatColor.YELLOW+"Boom!"); thorCooldown.add(e.getPlayer().getName()); break; }else{ return; } } Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this,new Runnable(){ public void run() { thorCooldown.remove(e.getPlayer().getName()); e.getPlayer().sendMessage(prefix+ChatColor.RED+"You may now use your Powers again."); } } ,100); } } AdamQpzm
That's not the "full code", right? I mean, you still have the @EventHandler part and all that, right? So what event is this triggering on? PlayerInteractionEvent?
Code0 Put this above the check: PHP: if(b == null) System.out.println("block is null");else System.out.println("block is " + b.getType());
What I'm trying to say is, you're still getting the System.out.println() on line 21, right? Because otherwise, the error could be anywhere, not just in this code.
Bobit Even if 21 doesn't print, there's not necessarily an error anywhere. Code0 Just properly looked at your code, are you sure this is the logic you're looking for? For each of the blocks in the player's line of sight: If the first block is not null and not air, do lightning and message stuff, then stop looking at the blocks. If it is null or air, stop the whole method.
itzrobotix I'm trying to give myself a little bit of a challenge xD Doesn't change anything. Code isn't executed after that if statement. So it always returns null ( no errors) EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code0 No, trust me, the else statement executes if the if fails. That's what it's made for. You're essentially checking the first block in their line of sight, and no more.