I need teleport highestScorer player!

Discussion in 'Plugin Development' started by mr_snake302, Apr 1, 2014.

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

    mr_snake302

    Hello!
    I have got problem, I have got code:
    Code:java
    1. Integer playerScore = scoreBoard.getScore(playerName);
    2. if (playerScore > highScore) {
    3. highestScorer = playerName;
    4. highScore = playerScore;


    And I need teleport highestScorer, but IDK how write this:

    Code:java
    1. Player player = (highestScorer) sender;
    2.  
    3. Location my = new Location(Bukkit.getWorld("world"),100,0,0);
    4.  
    5. player.teleport(my);


    Or may be Player player = highestScorer;

    highestScorer.teleport(my); - didn't work
     
  2. Offline

    amhokies

    It seems to me that highestScorer is of type String, yes?
     
  3. Offline

    mr_snake302

    yes
     
  4. Offline

    amhokies

    mr_snake302
    Player player = (highestScorer) sender;

    This line of code here. I'm assuming you're trying to get a Player object from a String, and that's not how you do it. There is a method, Bukkit.getPlayer(String name), that returns a Player object with a name that matches the one you pass in. If no player is found that matches the String passed in, it returns null, so make sure you check to see if it's null before you try to invoke any methods on the Player object returned.
     
    mr_snake302 likes this.
Thread Status:
Not open for further replies.

Share This Page