Move a player to a location

Discussion in 'Plugin Development' started by xSpreeZ, Jan 13, 2018.

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

    xSpreeZ

    Hi! Im new to this with coding, and im trying to make when a snowball hits the ground it will build a pillar and drag me to the pillars highest point, but i got no idea how to make it. Here is my code:

    @EventHandlerpublic void onArrowHit(ProjectileHitEvent e) {
    if (this.snowball.containsKey(e.getEntity())) {
    Entity p = e.getEntity();
    Location loc = e.getEntity().getLocation();
    loc.getBlock().setType(Material.STONE);
    loc.add(0, 1, 0).getBlock().setType(Material.STONE);
    loc.add(0, 1, 0).getBlock().setType(Material.STONE);
    loc.add(0, 1, 0).getBlock().setType(Material.STONE);
    loc.add(0, 1, 0).getBlock().setType(Material.COBBLESTONE);


    Location l = loc.add(0, 4, 0);
     
  2. And what isn't working?

    Sent from my SM-G903F using Tapatalk
     
  3. Offline

    Tabuu_

    I can't test methode I'm going to give you now but it might be worth a shot.


    Code:
    loc.add();
    does not change the loc value.
    So you eighter have to use:
    Code:
    loc.add(0, 1, 0).#
    loc.add(0, 2, 0).#
    loc.add(0, 3, 0).#
    loc.add(0, 4, 0).#
    Or something like this:
    Code:
    for(int i = 0; i < 4; i++){
        loc = loc.add(0, 1, 0);
        if(i != 4)
            loc.getBlock().setType(Material.STONE);
        else
              loc.getBlock().setType(Material.COBBLESTONE); 
    }
    And for the player teleporting you can use:
    Code:
    p.teleport(Location);
     
  4. Offline

    xSpreeZ

    Everything is working with the code, but i want the player to be sucked to the block

    Yeah my code works fine atm, but i need help with the players being draged to the block, not teleported like if the block is a vacuum and he is getting sucked to the block

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 14, 2018
  5. Given the fact that all modifying methods return Locations, I think, like Strings, they are immutable, like you said.

    Sent from my SM-G903F using Tapatalk
     
  6. Offline

    xSpreeZ

    The teleport doesent work becouse "p" is "Entity p = e.getEntity();" And not the player i think
     
  7. Offline

    Tabuu_

    No it works. I'm sure about that.
     
  8. @xSpreeZ
    When you do
    Code:
    Location l = loc.add(0, 4, 0);
    you're not actually changing anything, just assigning a new location variable.

    If you want to 'suck' the player to the block as you put it you have two methods.
    • Teleport the player directly to the block.
    • Work out a finite set of points between the players location and the block and teleport him along these points in quick succession.
    • Or the best solution, but the trickier one to implement would be to edit the players velocity recursively until he reaches (or gets close enough to) the target location.
     
Thread Status:
Not open for further replies.

Share This Page