Page 1 of 1

Bukkit - How can I differentiate from the Console?

Posted: Thu Mar 29, 2012 8:54 am
by offluffy
I noticed on the plugin tutorial page (on bukkit) that to make sure that a command is or isn't sent by the console, you just check to see if it is/isn't an instance of a Player. Makes enough sense to me, but while I was working on my plugin, I didn't want the console to be able to use the command to view it's own IP, and I tried to use the "sender instanceof Player", but it still ignored it, as in, the console and players were still able to use the command as if the console was emulating a Player instance. So as a temporary fix, I just had it check if the getName() is "Console" (since as to date, I don't believe any player has registered with the name "Console", surprisingly enough. Of course this isn't intended to be a permanent fix, so how can I go about doing this in a better fashion? Thank in advance!

Re: Bukkit - How can I differentiate from the Console?

Posted: Thu Mar 29, 2012 2:50 pm
by jacek
I think the instanceof Player should work :s But the console is a ConsoleCommandSender so
if (sender instanceof ConsoleCommandSender){
    // Hi I'm the console
}
Should definitely work.

Re: Bukkit - How can I differentiate from the Console?

Posted: Thu Mar 29, 2012 8:45 pm
by offluffy
Thanks! This seems to work perfectly XD