Reputation: 13
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 SOS could use it. If anyone else used it, another command would happen, and it would send a messages "Your not SOS"!
Let's say it killed someone who tried to use the command, than sent them a message saying "Your not SOS"
Thanks!
This is my start below!
{
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
Upvotes: 0
Views: 1542
Reputation: 365
You could check for the name of the sender or the command itself
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (cmd.getName().equalsIgnoreCase("idk")) {
if (sender.getName().equalsIgnoreCase("SOS")) {
sender.sendMessage("You are SOS");
} else {
sender.sendMessage("You are not SOS!");
}
return true;
}
return false;
}
Upvotes: 2