-
Notifications
You must be signed in to change notification settings - Fork 25
PHP to Bukkit
Prior to connecting to Websend from PHP, you need enable this feature in the configuration file. Once you have setup the Bukkit server with the Websend plugin, you can connect to Websend from PHP with the Websend.php script included in the Websend download. Include Websend.php, construct a new Websend object, call the connect function and you should be connected and ready to go. From there you can do commands, print output to players/console, run scripts or even tap into plugin output. An example script is provided in the Websend download under "ExternalTimeSet.php".
-
constructor
( string host [,integer port] )
Constructs a Websend object. Pass a string with the bukkit server address.
The port defaults to 4445. If you specified a different port in your websend config, then you also need to pass that as an integer.
Note that the constructor does not actually connect to the server. To do that use connect(). -
connect
( string password )
This function attempts to connect to the Websend plugin using the host and port specified in the constuctor, and pass the password.
The password passed as argument should be the same as the password in the configuration file of the Websend plugin.
Note that if the password is incorrect, the connection is lost. -
disconnect
()
Sends a disconnect packet, requesting for disconnection. -
doCommandAsPlayer
( string command, string playername )
Runs a command as if the specified player typed it into the chat.
Returns true if the command and player were found, else false. -
doCommandAsConsole
( string command )
Run a command as if it were typed into the console.
Returns true if the command was found, else false. -
doScript
( string scriptname )
Runs a script. The script has to be in the Websend scripts directory and has to be compiled and loaded before this is runned. -
startPluginOutputListening
( string pluginname )
Start plugin output capture. Will probably not work. For more information see this. -
stopPluginOutputListening
( string pluginname )
Stop plugin output capture.
Returns an array of strings that contains the output. -
writeOutputToConsole
( string message )
Print output to the console window. Invisible to players. -
writeOutputToPlayer
( string message, string playerName )
Prints message to the specified player.
Returns true if the player was found, else false. -
broadcast
( string message )
Prints a message to all players and the console.
Although Websend supports the capturing of output provided by plugins, this has certain restrictions due to the way Java/Bukkit works.
Not all output is captured, only the output that is handled through the plugin logger supplied by Bukkit is recorded. Messages of this type are mostly recognizable by the "[PluginName]" infront of their output. (Enabling messages excluded.)
Additional output may be captured by enabling WRAP_COMMAND_EXECUTOR in your Websend configuration file. Note however that this option toggles methods that may affect plugins that use CraftBukkit to access internal craftbukkit methods and data. These may behave unexpectedly when this is turned on.
Also note that Bukkit output cannot be captured for now.
To catch the output of a plugin you need:
- To know the name of the plugin as specified in the plugin.yml
- To be using a php -> bukkit connection
First you use websend->startPluginOutputListening("nameoftargetplugin")
where nameoftargetplugin
is for example Websend.
Then you perform any actions you want to capture the output of.
If these actions take some time to complete, you might need to put a sleep in your php document before calling websend->stopPluginOutputListening("nameoftargetplugin")
.
This will stop Websend from recording output and the method will return an array of strings that contains the recorded output.