Solved Detect if player stands on a block.

Discussion in 'Plugin Development' started by BenyTheBuff, Aug 24, 2014.

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

    BenyTheBuff

    How would I detect if a player stands on a SandBlock?
     
  2. Offline

    TheMcScavenger

    • Get the location of the player
    • Get the block below the player's feet
    • Get the material of the previously found block
    • Check the material against the material of a sand block
    • Run your code
     
  3. Offline

    BenyTheBuff

    I did this but nothing happends when you stand on a lapis block :(

    @SuppressWarnings("null")
    @EventHandler(priority = EventPriority.NORMAL)
    public void onPlayerMoveEvent(PlayerMoveEvent event) {

    Player player = null;

    if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.LAPIS_BLOCK) {
    player.sendMessage("You Stood On Lapis Block");
    }
    }
    }
     
  4. Offline

    Tecno_Wizard

    BenyTheBuff, this might seem a bit obvious, but you can't get the location of a player that's null...
     
    Skye likes this.
  5. Offline

    Zupsub

    Your IDE already told you the problem... Don't ignore all warnings from your IDE....
     
  6. Offline

    BenyTheBuff

    I tried Player player = event.getPlayer(); but that didn't seem to work either.
     
  7. Offline

    Tecno_Wizard

    Okay, that is a problem on your end. If it continues to not work, i've got nothing
     
  8. Offline

    Zupsub

    Are you sure you stand on lapis block? (not ore)?
    Is the event fired? Which block type is it instead?
     
  9. Offline

    TheMcScavenger

    Did you register the event?
     
  10. Offline

    BenyTheBuff

    I mean this is my whole class I even followed this off another guys one and he said it worked for him.

    package me.ben;

    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.Material;
    import org.bukkit.Location;


    public class RadiationClass extends JavaPlugin {

    public void onPlayerMoveEvent(PlayerMoveEvent event) {

    Player player = (Player) event.getPlayer();

    if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.LAPIS_BLOCK) {
    player.sendMessage("You are on a lapis block!");
    }
    }
    }
     
  11. Offline

    xTigerRebornx

    BenyTheBuff You've forgotten the @EventHandler annotation and you've forgotten to register your events.
     
  12. Offline

    BenyTheBuff

Thread Status:
Not open for further replies.

Share This Page