I want it to do so that when a player looks at sponge, he'll explode. This seems really simple to me, and the code seems pretty clear, but it doesn't work. Code:java package me.Anrza.SpongeExplode; import org.bukkit.Bukkit;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.block.Block;import org.bukkit.entity.EntityType;import org.bukkit.entity.Player;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerMoveEvent;import org.bukkit.plugin.java.JavaPlugin; public class SpongeExplode extends JavaPlugin implements Listener{ public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); } public void onPlayerMoveEvent(PlayerMoveEvent event) { Player player = (Player) event.getPlayer(); @SuppressWarnings("deprecation") Block block = (Block) player.getTargetBlock(null, 50); player.sendMessage("moving"); if (block.equals(Material.SPONGE)); Location loc = (Location) player.getLocation(); loc.getWorld().spawnEntity(loc, EntityType.PRIMED_TNT); player.sendMessage("looking at sponge"); }}
You can just create an explosion without TNT: Code:java world.createExplosion(location, power, setFire);
TheMcScavenger Thanks! Will enjoy this! Btw, what does power specify, and is it an integer? EDIT: Oh, derp moment. Of course Power specifies power, but is it in radius in meters/Hearts of damage or something else?
Anrza aside from that, you also messed your if check, you are trying to compare a Block with Material, which wont work, see javadocs and get material of block.
Necrodoom Ty, obvious mistake. But my problem isn't quite solved yet. I'm not getting either of the debug messages, even with the recent correction of the code.
Necrodoom Noob mistake. Thank you very much. And oh, wow, another noob mistake, failed with the squiggly brackets.