Changing a String to a Player Object

Discussion in 'Plugin Development' started by AstramG, Jan 21, 2013.

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

    AstramG

    Hello! I was playing with codes and I was trying to create a way to convert a string to a player object so I could kick someone. Here is my code so far.

    Code:
    public boolean onCommand(CommandSender cs, Command c, String l, String [] args) {
            if (l.equalsIgnoreCase("chnick")) {
                if (args.length == 2) {
                    if (cs.hasPermission("astram.changeothernick")) {
                        String other = args[0];
                        String nnick = args[1];
                        this.getConfig().set("People." + other + ".Name", nnick);
                        this.saveConfig();
                        cs.sendMessage(ChatColor.GREEN + "You've changed " + other + "'s nick to " + nnick);
                        //other.kickplayer("You're nickname was inappropriate!");
                    }
                }
            }
    The line //other.kickplayer("Your nickname was inappropriate!"); doesn't work because other isn't a player object and I don't know how to convert it from the string.
     
  2. Offline

    Cowboys1919

    Try Bukkit.getServer().getPlayer(username); to get a player
     
  3. Offline

    AstramG

    Thank you! It worked!
     
    Cowboys1919 likes this.
Thread Status:
Not open for further replies.

Share This Page