Why isn't this working?

Discussion in 'Plugin Development' started by civ77, Dec 28, 2011.

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

    civ77

    //client is a player and plugin.BankLoc is a Location variable called from the main class of the plugin
    client.distance(plugin.BankLoc)

    //bukkit is saying "The method distance(Location) is undefined for the type Player"
    //Why isn't this working?
     
  2. Offline

    thescreem

    As far as I'm aware, there is no distance() method for a Player object...
     
    WizzleDonker likes this.
  3. Offline

    civ77

    ooooohhhhh.... TY
     
  4. Use getLocation() and then distance() to other location, that will return a integer number I think which is the distance between those 2 points :}
     
  5. Offline

    civ77

    getLocation doesn't seem to work with a player
     
  6. Since when ?
    Players have locations so getLocation() exists, are you sure you're using the right variable or even understand what you're doing ? :p
     
  7. Offline

    civ77

    well I'm on shaky ground as far as understanding;) but I'm now also having the same problem with getPlayerListName
    it's acting as though these methods don't exist.

    For the sake of clarity here's the code I'm having problems with:

    Code:
    if(sender instanceof Player){
        Player client = (Player) sender;
    
        if(getLocation(client).distance(plugin.BankLoc)<= 3){
        xp = client.getTotalExperience();
        client.setTotalExperience(0);
        if(plugin.ExpBankAccs.containsKey(getPlayerListName(client))){
        }
    }
            }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  8. Are you sure you're not forgetting the parentheses, "()" ? :}
    Also, it could be your editor is updating verry slowly, try saving to see if it reviews the code and no longer complains... or it may be something else that's wrong and it can't really tell what it is and it's marking good code as bad.

    So... post your code :p

    EDIT: yes, that code is not valid because there isn't a method getLocation() in your FILE/class, you're not calling it on the Player object :p

    this is how it should be:
    Code:
    if(sender instanceof Player)
    {
        Player client = (Player) sender;
    
        if(client.getLocation().distance(plugin.BankLoc) <= 3)
        {
            xp = client.getTotalExperience();
            client.setTotalExperience(0);
    
            if(plugin.ExpBankAccs.containsKey(getPlayerListName(client)))
            {
                 // ???
            }
        }
    }
     
    civ77 likes this.
  9. Offline

    civ77

Thread Status:
Not open for further replies.

Share This Page