Change block under player

Discussion in 'Plugin Development' started by longroad, May 2, 2016.

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

    longroad

    Hey Guys,
    i'm coding my own minigame, but I have a problem. I want to change the block under a player, but Java says that there is a problem.
    Code:
        Location loc = p.getLocation();
                double y = loc.getY()-1;
                World w = Bukkit.getWorld("CaptureTheBomb");
                w.getBlockAt(y).setType(Material.TNT);
    I tested arround a lot but couldn't find a solution. If y is a double, Java says I should change it to "Location". But if it is an Location I cannot subtract 1. Please help me!
     
  2. Offline

    Protophite

    idk how you are getting that problem. Make sure you import the right stuff.

    @longroad
     
  3. Offline

    Zombie_Striker

    @longroad
    This method does not exist for type World. You need to use the "getBlockAt(X ,Y, Z)" to get a block at a specific location.
     
  4. Offline

    longroad

    @Zombie_Striker but how can i change the block under a player? I don't want to set it on the ground, it should be in the ground
     
  5. Offline

    Zombie_Striker

    @longroad
    The only thing you need to do is change "getBlockAt(y)" to "getBlockAt (X, y, Z)"
     
  6. @longroad
    Like @Zombie_Striker said, the method you re using requires 3 arguments.
    You can get the X, Y and Z by using the "loc.getX(), loc.getY() and loc.getZ()" methods, then you can minus the value of Y inside the method(?) like getBlockAt(x, loc.getY()-1, z)
     
  7. Offline

    longroad

    Thanks to everybody, stupid mistake^^
     
Thread Status:
Not open for further replies.

Share This Page