Changing a block at a players location

Discussion in 'Plugin Development' started by MetaSurvival, Sep 22, 2013.

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

    MetaSurvival

    I want, so when a player goes onto a piece of dirt, the dirt turns into Cobweb.
    I have this code, but with this, nothing happens.
    Code:
    @EventHandler
        public void onMove(PlayerMoveEvent event){
            Location location = event.getPlayer().getLocation();
            Block block = location.getBlock();
            if(block.getType().equals(Material.DIRT)){
                block.setType(Material.WEB);
            }
        }
     
  2. Offline

    valon750

    MetaSurvival

    For starters, are you actually registering the event?

    Secondly, you may need to use..
    Block block = player getBlock().add(0,-1,0);

    Or something along those lines, so it's looking for the block the player is on.
     
    MetaSurvival likes this.
  3. Offline

    MetaSurvival

    valon750
    "add" dosen't exist, and yes I am registering the events.
     
  4. Offline

    valon750

    MetaSurvival

    Like I said, "something along those lines".

    Or you could do...
    Location loc = player.getLocation().add(0,-1,0);
    Block block = player.getWorld().getBlockAt(loc);

    Initiative man! It's what plugins are all about! :)
     
    MetaSurvival likes this.
  5. Offline

    MetaSurvival

    valon750
    Thank you! :)

    valon750
    How would I do this with string instead of dirt? I tried replace string with dirt, but it dosnt work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. Offline

    valon750

    MetaSurvival

    Well the string will be in the block the player is in, so in this instance, the method you used to use should work :)
     
    MetaSurvival likes this.
Thread Status:
Not open for further replies.

Share This Page