send message using player name

Discussion in 'Plugin Development' started by hardcorebadger, Jan 18, 2011.

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

    hardcorebadger

    I have a command and split[1] is where the person types in the username. I want to send that player a message. How would I go about checking if its a real player then sending the message?
     
  2. Offline

    Mixcoatl

    You could do something like this:
    Code:
    if (split.length != 2) {
        player.sendMessage("Usage: ...");
    } else {
        List<Player> players = plugin.getServer().matchPlayer(split[1]);
        if (players.size() == 0) {
            player.sendMessage("No matching player.");
        } else if (players.size() != 1) {
            player.sendMessage("Matched more than one player!  Be more specific!");
        } else {
            Player victim = players.get(0);
            victim.sendMessage(player.getName() + " sent you a message!");
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page