PEMapModder PEMapModder - 10 months ago 44
PHP Question

How to create commands with localized description in PocketMine plugins?

How to create commands with translated description or usage using the PocketMine API in plugins?

In vanilla commands, strings of translation codes such as
are passed. They are references to the lang file in the original PocketMine, and plugins cannot modify them.

When a player executes
, the
class concatenates the result of
with the help client output format. Then, it is passed to
, which passes the string to
and then
, and then internally lookup translations at occurrences of
. Throughout this process, it is not possible to add anything, unless the server
is replaced.

Answer Source

Handle DataPacketSendEvent and modify TextPackets. Make your identifier something special that you can extract from arbitrary string.

Use this event handler:

public function e_dps(DataPacketSendEvent $event){
    if(($pk = $event->getPacket()) instanceof TextPacket){
        $pk->message = preg_replace_callback(
            '/PluginName\-SomeRandomBytesHere\-ForSecurityGenerateThemEveryRestart\-([0-9]+)\-AnotherDelimiterHere/', function($match){
                return $this->translate($match[1], $event->getPlayer());
            }, $pk->message);