Get Offline players gamemode

Discussion in 'Plugin Development' started by Mozartripper, Dec 1, 2012.

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

    Mozartripper

    Hi, as the title says I am trying to get the gamemode of offline players. Right now i have this code to check your own gamemode but id like to know how to get other game mode even if they atre offline.
    Code:
    if(commandLabel.equalsIgnoreCase("gm"))
    {
    if(player.getGameMode() == GameMode.CREATIVE) {
    player.sendMessage(ChatColor.GOLD +" Is in creative!");
    }
    else
    {
    player.sendMessage(ChatColor.GOLD +" Is in Survival!");
    }
    }
    return false;
     
  2. Offline

    RealDope

    OfflinePlayer player = getServer().getOfflinePlayer("name");
    player.getGameMode();
     
  3. Offline

    Mozartripper

    where should this go ? sorry im kinda noob with java.
     
  4. Code:java
    1. OfflinePlayer player = getServer().getOfflinePlayer(args[1]);
    2. if(commandLabel.equalsIgnoreCase("gm"))
    3. {
    4. if(player.getGameMode() == GameMode.CREATIVE) {
    5. sender.sendMessage(ChatColor.GOLD + " Is in creative!");
    6. }
    7. else
    8. {
    9. sender.sendMessage(ChatColor.GOLD + " Is in Survival!");
    10. }
    11. }
    12. return false;
     
  5. Offline

    Mozartripper

    eclipse gives me error with the first line of this code
    -OfflinePlayer cannot be resolved to a type
    -duplicate local variable player
    -Line breakpoint oncommand(CommandSender, Command, String, String[])

    As I said my knowledge of java is really limited
     
  6. Offline

    SoThatsIt

    that means that you have 2 variables called player.... just rename one of them
     
  7. Offline

    fireblast709

    Mozartripper "OfflinePlayer cannot be resolved to a type" means you forgot to import 'org.bukkit.OfflinePlayer'
     
  8. can you show me your whole oncommand so i can see what the problem is.
     
  9. Offline

    teunie75

    Try this:
    And in the main class you type this:
    Code:
    this.getCommand("gm").setExecutor(new <classname>(this));
    Code:
    private main plugin;
    public <classname>(main plugin){
    this.plugin = plugin;
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
    if(commandLabel.equalsIgnoreCase("gm"))
    {
    if(player.getGameMode() == GameMode.CREATIVE) {
    sender.sendMessage(ChatColor.GOLD + player.getName() + " Is in creative!");
    }
    else
    {
    if(player.getGameMode() == GameMode.SURVIVAL){
    sender.sendMessage(ChatColor.GOLD + player.getName() + " Is in Survival!");
    }
    }
    }
    return false;
    It will display the name of the player with the gamemode in the message.
    Were you looking for this?
     
Thread Status:
Not open for further replies.

Share This Page