Get no errors, yet code does not work

Recently I’ve been trying to learn the bukkit (minecraft plugin platform) API. In part of my code, when the player clicks a blaze rod all the blocks within a radius of 5 turn into fire.

for (Location loc : circle(player.getLocation(), 3, 1,
							false, false, 0)) {
						    loc.getBlock().setType(Material.FIRE);						
						e.getPlayer().getInventory().remove(Material.BLAZE_ROD); 
						e.getPlayer().getInventory().setItemInHand(new ItemStack(Material.STICK)); 
						player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 200, 0));
						locList.add(loc);

However, when i add the statement

if(loc.getBlock().getType()!= Material.AIR) 

to check whether the block is air before replacing it with fire, the code stops working.
The code as it is now:

				final List<Location> locList = new ArrayList<>();
				for (Location loc : circle(player.getLocation(), 3, 1,
						false, false, 0)) {
					    if(loc.getBlock().getType()!= Material.AIR) loc.getBlock().setType(Material.FIRE);						
					e.getPlayer().getInventory().remove(Material.BLAZE_ROD); 
					e.getPlayer().getInventory().setItemInHand(new ItemStack(Material.STICK)); 
					player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 200, 0));
					locList.add(loc);
				}

It appears that the

if(loc.getBlock().getType()!= Material.AIR)

it stopping if from working, yet I can’t seem to figure out why and how to fix it.

Could someone please help?

full class, if anyone wants to see more:

http://www.hastebin.com/egadiqamup.avrasm

As much as I would love to help you, I have no clue about bukkit. I never used minecraft so I had no need. Yet, they have their own community. Have you tried to ask there?

I hate not being able to give you an answer… but…

Anyway, I’ll move the topic to programming because, for sure, nodody in this area will know.

I didn’t put it in getting started, it was moved there by another member of staff. IMO the categories on this forums are not very clear cut.

And yes, I’ll ask on the bukkit forums.

I’m sorry for the confusion. Your question doesn’t fit in any of our general categories because this forum is dedicated to Web development.
To add to this confusion, not all members of staff are programmers and some programming questions are, indeed, answered in getting started. But most programmers don’t visit that fourm.

I suspect that your question will be easy to answer by someone that used bukkit but I’m personally unfamiliar with it. Yet, in this case, I think that you have more chances to find a possible answer here, where a programmer will be able to see it.

I would tell you what I do in similar cases though.

I don’t know if this will help you at all but…

When I think that my problem is in the IF clause, I check the values using a message box (or echo or similar, depending on the language) so the values of the variable, or the result, are on the screen.

If everything seems correct, then I use the same trick but inside the IF itself, and the ELSE, to see where which line of code is being used.

P.E. If I have two variable a and b

alert(eval(a===b));
    If (a===b) {
    alert("any message so I know that the code used is this one");
    
    code goes here
}
ELSE{
alert("any message so I know that the code used is this one");

code goes here
}

In this way, I know the variables are being evaluated correctly

ok, thanks for the debug tip. I’ll try it out.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.