Getting player from another method

Discussion in 'Plugin Development' started by CrazyGuy3000, Oct 4, 2013.

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

    CrazyGuy3000

    Hi guys,
    How does one get a player from another method. I thought it might be possible to do this without temporarily storing him in a hashmap but i'm not sure.
     
  2. Offline

    Henzz

    CrazyGuy3000
    Depends what you do with the player, I'd use a set a or a map.
     
  3. Offline

    CrazyGuy3000

    Well im going to be using him to get his location. Can you perhaps show some code?
     
  4. Offline

    Ultimate_n00b

    I saw a good tutorial on multiple classes/passing things from one class to another. Search the resources section.
     
  5. Offline

    Henzz

    CrazyGuy3000
    I'd store the player's location in a hashmap like so.
    PHP:
    private HashMap<StringLocationplayerLoc = new HashMap<StringLocation>();
     
        
    // To add the player's location
        
    private void add(Player player) {
            
    playerLoc.put(player.getName(), player.getLocation());
        }
     
        
    // To get the player's location
        
    private Location getLoc(Player player) {
            return 
    playerLoc.get(player.getName());
        }
     
        
    // And I think this can be a way
        // of getting a specific player's location
        
    private Location getLocFor(String name) {
            return 
    playerLoc.get(Bukkit.getPlayerExact(name));
        }
     
Thread Status:
Not open for further replies.

Share This Page