getting a player in a public void

Discussion in 'Plugin Development' started by ahuby09, Apr 16, 2014.

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

    ahuby09

    i need to know how to get a player in a public void
     
  2. Offline

    Bammerbom

    ahuby09 I dont understand you.
    Do you mean: Bukkit.getPlayer("Name")
     
  3. Offline

    MCForger

    ahuby09
    I am sorry can you place explain your question a little bit better?
    Do you mean grab a player that is currently online? Or....
     
  4. Offline

    qlimax5000

    Don't use a public void.. use public Player. Example:
    Code:java
    1. public Player getPlayer() {
    2. return WHERE_YOU_STORED_THE_PLAYER;
    3. }
     
    XvBaseballkidvX likes this.
  5. Offline

    ahuby09

    i mean
    Code:
    public void Team(String string){ 
     
    if(TeamBlue.contains(player.getName())){
    Team("blue");
    }else if(TeamRed.contains(player.getName())){
    Team("Red");
    }
    }
    i need the to get player so i can use its methods
     
  6. Offline

    Konkz


    Two ways of doing it,

    1. You can loop through all players online for (Player p : Bukkit.getOnlinePlayers()) { //code }
    2. You can put Player player in signature, so when you call the method you have to put the player.

    Example of number 2:
    PHP:
    public void Team(Player player){
     
    if(
    TeamBlue.contains(player.getName()) {
    Team("blue");
    return;
    }
     
    if(
    TeamRed.contains(player.getName()){
    Team("Red");
    return;
    }
    }
     
  7. Offline

    coasterman10

    What is this method designed to do? Right now it looks like it could create an infinite loop.
     
  8. Offline

    ahuby09

    designed to get whether the player is red or blue and am going to call it when i type a / command so i would put p.sendMessage(team());inside the command bit and it would work as it would return a string of which team they are on , sorry but im not good at explaining

    and won't read your reply till i get home later as im going out

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  9. Offline

    coasterman10

    If you want to return a string, your method should return a String, not accept a String as a parameter. Then, accept the player as a parameter.
    Code:java
    1. public String Team(Player player) {
    2. if (TeamBlue.contains(player.getName())
    3. return "blue";
    4. if (TeamRed.contains(player.getName())
    5. return "red";
    6. }
     
  10. Offline

    SnipsRevival

    coasterman10 This is also what I would do, but this won't compile because you need to add a default return value such as "not in team" if the player isn't in either team.
     
  11. Offline

    coasterman10

    SnipsRevival That was intentional; if it's just copy-pasted, then it won't work. I feel like the OP should get some more experience with Java first.
     
  12. Offline

    MrInspector

    Code:java
    1. public void Team(Player player, String string) {
    2. // code
    3. }
     
Thread Status:
Not open for further replies.

Share This Page