[Solved]Get Player instance from an offline player

Discussion in 'Plugin Development' started by Yourdogsdead, Sep 5, 2012.

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

    Yourdogsdead

    Hello,

    I am trying to get an instance of a Player when a person is offline. Unfortunately I cannot figure out how to convert an OfflinePlayer to a Player. Any help is appreciated.
     
  2. Offline

    Giant

    OfflinePlayer.getPlayer(), however if said OfflinePlayer is indeed offline, the getPlayer() method will return null!
     
  3. Offline

    Yourdogsdead

    Thanks.

    I had to rework my method anyway. It originally sent a message to both players, but if one player is online you can't do that now can you. I instead passed along a String and tried to turn that into a player. If it's null, don't send the message. If it's not null, send the message

    Code:
    public void placeBounty(Player placer, String victim, int bounty){
           
            if(!checkPlayer(victim)){
                System.out.println("Victim is not in Hashmap");
     
                playerList.put(victim,new PlayerProfile(victim));
            }
           
            Inventory placerInv = placer.getInventory();
            if(placerInv.contains(266, bounty)){
                playerList.get(victim).addplayersetBounty(bounty);
                placer.sendMessage(ChatColor.DARK_GRAY + "Placed a bounty of " + bounty + " on " + victim);
                Player victimPlayer = Bukkit.getPlayer(victim);
                if(victimPlayer != null){
                victimPlayer.sendMessage(ChatColor.DARK_GRAY + placer.getName() + " placed a bounty of " + bounty + " on you");
                }
                calculateTop();
                }
           
            else{
                placer.sendMessage(ChatColor.RED + "Not enough gold to place bounty");
            }
        }
    Thanks for your help.
     
Thread Status:
Not open for further replies.

Share This Page