Skip to content

Instantly share code, notes, and snippets.

@Muqsit
Created April 8, 2020 01:58
Show Gist options
  • Select an option

  • Save Muqsit/014c82e4e9074402408848f89bbc6b73 to your computer and use it in GitHub Desktop.

Select an option

Save Muqsit/014c82e4e9074402408848f89bbc6b73 to your computer and use it in GitHub Desktop.
low budget specter that respawns
<?php
declare(strict_types=1);
namespace muqsit\fakeplayer;
use pocketmine\entity\Skin;
use pocketmine\event\Listener;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\PacketSender;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\RespawnPacket;
use pocketmine\player\PlayerInfo;
use pocketmine\plugin\PluginBase;
use pocketmine\scheduler\ClosureTask;
use pocketmine\utils\UUID;
final class Loader extends PluginBase implements Listener{
protected function onEnable() : void{
$_players = $this->getResource("players.json");
$players = json_decode(stream_get_contents($_players), true, 512, JSON_THROW_ON_ERROR);
fclose($_players);
$this->getScheduler()->scheduleDelayedTask(new ClosureTask(function(int $currentTick) use($players) : void{
foreach($players as $uuid => $data){
["xuid" => $xuid, "gamertag" => $gamertag] = $data;
$this->addPlayer(UUID::fromString($uuid), $xuid, $gamertag, $data["extra_data"] ?? []);
}
}), 1);
}
public function addPlayer(UUID $uuid, string $xuid, string $username, array $extra_data) : void{
$_skin_data = $this->getResource("skin.rgba");
$skin_data = stream_get_contents($_skin_data);
fclose($_skin_data);
$server = $this->getServer();
$network = $server->getNetwork();
$session = new class($server, $network->getSessionManager(), new class implements PacketSender{
public function send(string $payload, bool $immediate) : void{}
public function close(string $reason = "unknown reason") : void{}
}, $server->getIp(), $server->getPort()) extends NetworkSession{
public function sendDataPacket(ClientboundPacket $packet, bool $immediate = false) : bool{
if(parent::sendDataPacket($packet, $immediate)){
if($packet instanceof RespawnPacket){
$this->getPlayer()->respawn();
}
return true;
}
return false;
}
};
$network->getSessionManager()->add($session);
$session->setPlayerInfo(new PlayerInfo($username, $uuid, new Skin("Standard_Custom", $skin_data), "en-US", $xuid, $extra_data));
$session->onLoginSuccess();
$session->onResourcePacksDone();
$session->getPlayer()->setViewDistance(4);
$session->onSpawn();
}
}
@Muqsit
Copy link
Copy Markdown
Author

Muqsit commented Apr 8, 2020

players.json:

{
    "dbd5485b-425c-3336-97fe-a3f5c947e6e0": {
        "xuid": "2535448890738751",
        "gamertag": "BoxierChimera37",
        "extra_data": {
            "DeviceId": "ea78448a-6b33-3bbd-0e04-22dc3fb9f250",
            "DeviceModel": "PocketMine-MP",
            "DeviceOS": 7
        }
    }
}

skin.rgba: https://www.dropbox.com/s/1mxtrfhahjty64i/skin.rgba?dl=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment