Fake Player

So here is my predicament…

I want to run commands as a player, even if that player is offline. I can run them as the console, but that doesn’t take in account player permissions.

Is it possible to create a fake player, apply a normal player’s permissions to it, and then run a command as that fake player.

On top of that, I’d love to capture the results of that command.

Any help is much appreciated, and examples are more than welcome!

1 Like

Make a class that implements CommandSource. Get the command mapping. Manually call the method to apply the command.

You lost me a bit… :slight_smile:

Also do you know how permissions can be handled?

A command is managed by a CommandCallable, and you can get them from the CommandManager. Make a class that implements CommandSource, and get the User from the UserStorageService. Proxy all the Data API methods to the User. Make sure that the hasPermission() method returns true for all the permissions you’re concerned about. Then manually call the method of the CommandCallable, providing an instance of your custom CommandSource as the source for the command.
Also, what plugin is this? If the command can reasonably be done on a User, maybe they should change the command so that it can use the userOrSource argument.

1 Like

Hey thanks for you help! I figured it out!