Solved Teleport to location: NumberFormatExeption

Discussion in 'Plugin Development' started by Pella, Aug 17, 2017.

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

    Pella

    Hi,

    I am trying to create teleport, please can you help me with this error and if is possible to add special player position (North,....) like this:

    For create:
    Code:
    Warp _wp = new Warp();
    _wp.Name = args[1];
    Location pos = player.getLocation();
    _wp.World = pos.getWorld().getName();
    _wp.Location = pos.getX() + "|" + pos.getY() + "|" + pos.getZ();
    _warps.put(args[1].toLowerCase(), _wp);
    player.sendMessage("Warp  has been created");
    
    and for use:
    Code:
    Warp _warp = Dic._warps.get(args[0]);
    
    String[] _loc = _warp.Location.split("|");
    World world = Bukkit.getWorld(_warp.World);
    double x = Double.parseDouble(_loc[0]);
    double y = Double.parseDouble(_loc[1]);
    double z = Double.parseDouble(_loc[2]);
    
    Location position = new Location(world, x, y, z);
    player.teleport(position);
    
    And error is when I try to call the warp

    upload_2017-8-17_22-27-20.png

    Thank you so much
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Pella What is your input string?
     
  3. Offline

    Pella

    @timtower

    _wp.Location = pos.getX() + "|" + pos.getY() + "|" + pos.getZ();
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Pella And can you print the value of _warp.Location to the console?
     
  5. Offline

    Pella

  6. Offline

    timtower Administrator Administrator Moderator

    @Pella You probably want to save the int values and not the double/floats.
    getBlockX will do the trick probably.
     
  7. Offline

    Pella

    @timtower
    GetBlock();


    upload_2017-8-17_22-55-40.png

    now is For input "|"
     

    Attached Files:

  8. Offline

    timtower Administrator Administrator Moderator

    @Pella Then start printing the values.
     
  9. Offline

    blueye_

    Why do you make a String out of your location just to parse it right back into doubles? You could just pass the Location itself.

    In your Main Class:
    Code:
    _wp.setPositon(player.getLocation());
    

    And in your Warp Class:
    Code:
    _wp.setPositon(Location pos){
       this.pos = pos;
    }
    
     
Thread Status:
Not open for further replies.

Share This Page