Bukkit - How can I differentiate from the Console?

Any help topics that don't fit in the current categories can go here.
Post Reply
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

Bukkit - How can I differentiate from the Console?

Post 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!
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post 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.
Image
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

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

Post by offluffy »

Thanks! This seems to work perfectly XD
Post Reply