Skip to content

Instantly share code, notes, and snippets.

@BEcraft
Created June 25, 2019 05:45
Show Gist options
  • Save BEcraft/3e6940409a4e40b8a2ba6e517cf51ce1 to your computer and use it in GitHub Desktop.
Save BEcraft/3e6940409a4e40b8a2ba6e517cf51ce1 to your computer and use it in GitHub Desktop.
Formulario
<?php
namespace formulario;
use pocketmine\plugin\PluginBase;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\Listener;
use pocketmine\network\protocol\DataPacket;
class cargador extends PluginBase
{
/**
* @var bool
*/
const DEPURACION = true;
/**
* @var string
*/
static $DIRECTORIO;
public function onEnable()
{
if (self::DEPURACION)
{
$this->getServer()->getPluginManager()->registerEvents(new class implements Listener {
#Envia el formulario al interactuar.
public function interactuar(PlayerInteractEvent $evento)
{
$evento->getPlayer()->dataPacket(new Formulario());
}
}, $this);
}
self::$DIRECTORIO = $this->getDataFolder() . DIRECTORY_SEPARATOR;
}
}
class Formulario extends DataPacket
{
/**
* @var int
*/
const NETWORK_ID = 0x64;
/**
* @var int
*/
private $identificador;
/**
* @var string
*/
private $datos;
public function __construct()
{
$this->identificador = rand();
$this->datos = json_encode([
"type" => "form",
"title" => ("Formulario#" . $this->identificador),
"content" => "",
"buttons" => [
[
"text" => ("Hora: " . date("h : i : s")),
"image" => [
"type" => "url",
"data" => "http://www.newdesignfile.com/postpic/2015/02/mario-128x128-icon_245367.png"
]
]
]
]);
}
public function encode($playerProtocol)
{
$this->putVarInt(self::NETWORK_ID);
$this->putVarInt($this->identificador);
$this->putString($this->datos);
}
public function decode($playerProtocol)
{
//...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment