Solved Player moving

Discussion in 'Plugin Development' started by Anrza, Jul 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Anrza

    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
    1. package me.Anrza.SpongeExplode;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.entity.EntityType;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerMoveEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class SpongeExplode extends JavaPlugin implements Listener{
    14.  
    15. public void onEnable() {
    16. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    17. }
    18.  
    19. public void onPlayerMoveEvent(PlayerMoveEvent event) {
    20. Player player = (Player) event.getPlayer();
    21. @SuppressWarnings("deprecation")
    22. Block block = (Block) player.getTargetBlock(null, 50);
    23. player.sendMessage("moving");
    24. if (block.equals(Material.SPONGE));
    25. Location loc = (Location) player.getLocation();
    26. loc.getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
    27. player.sendMessage("looking at sponge");
    28.  
    29.  
    30.  
    31. }
    32. }
     
  2. Offline

    TheMcScavenger

    You can just create an explosion without TNT:
    Code:java
    1. world.createExplosion(location, power, setFire);
     
  3. Offline

    Anrza

    TheMcScavenger Thanks! :D 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?
     
  4. Offline

    TheMcScavenger

    Power is power.... How powerful the explosion is; size of boom boom. It's a float.
     
    Anrza likes this.
  5. Offline

    Anrza

  6. Offline

    Necrodoom

    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.
     
  7. Offline

    Anrza

    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.
     
  8. Offline

    Necrodoom

    Anrza you forgot the event handler annotation.
     
  9. Offline

    Anrza

    Necrodoom Noob mistake. Thank you very much. And oh, wow, another noob mistake, failed with the squiggly brackets.
     
  10. Offline

    Necrodoom

    Anrza Mr. Squiggles always tries to run.
     
    ProMCKingz likes this.
Thread Status:
Not open for further replies.

Share This Page