Run commands only for certain players?

Discussion in 'Plugin Development' started by BestMcPlayers, Dec 15, 2014.

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

    BestMcPlayers

    Hi, I'm making a command for my custom plugin, for a server. Basically what I need is the coding for making a command runnable by one or more players only.

    For example what if I wanted a command /idk, but only the player BestMcPlayers could use it. If anyone else used it, another command would happen, and it would send a messages "Your not BestMcPlayers"!

    Let's say it killed someone who tried to use the command, than sent them a message saying "Your not BestMcPlayers"

    Thanks!
     
  2. Offline

    mythbusterma

    @BestMcPlayers

    Check the name of the player that executed it, compare it to a value, and then execute code accordingly.
     
  3. Offline

    Skionz

    @BestMcPlayers Check if the players name is equals to "BestMcPlayers" or compare UUIDs. Make sure to use Object#equals() or String#equalsIgnoreCase() instead of the == operator when comparing strings.
    EDIT: Ninja'd
     
  4. Offline

    BestMcPlayers

    So, this is the beginning of the command file! Edit this for me please!
    Code:
        {
            if (args.length != 1)
            {
                return false;
            }
    
            final Player player = getPlayer(args[0]);
    
            if (player == null)
            {
                sender.sendMessage("This player can't be found!");
                return true;
            }
    
    //Commands and other things down here
     
  5. Offline

    Skionz

    No.
    We told you how to solve your issue. A big part of development is translating oral languages to code.
     
    leon3001, ChipDev and eyamaz like this.
  6. Offline

    BestMcPlayers

    I'm just being lazy, no problem! I guess.
     
  7. Offline

    ChipDev

    Thats a good quote for a description ;)
    Exactly, Don't devote to developing if you cannot put work into it, other wise you would copy-paste it and not learn ANYTHING. < Learning is the point, to all of this :O
    EDIT:
    Oh and yes, you used getPlayer(args[0]); use Command#getSender(), also check if the sender instanceof player.
    \/ \/ \/
     
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page