A PocketMine-MP Virion to easily send RCON Commands to remote Minecraft / PocketMine-MP Servers
LGPL-3.0 License
A PocketMine-MP Virion to easily send RCON Commands to remote Minecraft / PocketMine-MP Servers
Installation is easy, you may get a compiled phar here or integrate the virion itself into your plugin.
This virion is purely object oriented. So, to use it you'll just have to import the RCONClient
object.
You'll need to import this class in order to easily use it within our code.
<?php
use CortexPE\PMRCON\RCONClient;
use pocketmine\Server; // optional, only used here in the example to easily get the server's logger
RCONClient
objectYou'll need the remote server's IP Address, Port, and the RCON Password for this.
You'll have to supply the timeout seconds as well, 2
seconds is the recommended value.
Supply the server's logger (You cannot use the plugin's logger) and that's all that's needed.
This will start a new RCONClientThread
thread and automatically attempt to login.
// $rcon = new RCONClient("tcp://ADDRESS HERE", PORT, "PASSWORD", TIMEOUT, Server::getInstance()->getLogger());
$rconClient = new RCONClient("tcp://127.0.0.1", 19133, "SuperStronkPassword", 2, Server::getInstance()->getLogger());
You can easily send commands to the remote server now! This will enqueue the command to the RCONClientThread
s command queue then send it to the remote server, whenever possible.
$rconClient->sendCommand("say Hello World!");
This is necessary for a smooth, clean shutdown of the server, This should usually be done on your plugin's onDisable
method.
Executing it will stop the thread's loop, then close the socket used to connect to the remote server.
$rconClient->stop();
Easy as 1-2-3! 🎉
$rconClient = new RCONClient("tcp://127.0.0.1", 19133, "ILYErinUwU", 2, Server::getInstance()->getLogger());
$rconClient->sendCommand("say IT WORKS!");
$this->getScheduler()->scheduleDelayedTask(new ClosureTask(function(int $currentTick) use ($rconClient) : void {
$rconClient->stop();
}), 100); // Stop the RCON Client after 5 seconds
This API was made with ❤️ by CortexPE, Enjoy!~ :3