Created
October 7, 2017 18:20
-
-
Save Frago9876543210/1db0b5cbe976a98417643f4a29390d5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace test; | |
use pocketmine\entity\Skin; | |
use pocketmine\event\Listener; | |
use pocketmine\event\player\PlayerChatEvent; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\utils\TextFormat; | |
use pocketmine\utils\UUID; | |
class Main extends PluginBase implements Listener{ | |
public function onEnable(){ | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
} | |
public function chat(PlayerChatEvent $event){ | |
$player = $event->getPlayer(); | |
$skin = $player->getSkin(); | |
$message = $event->getMessage(); | |
if(substr($message, 0, 4) == "cape"){ | |
$event->setCancelled(); | |
$array = explode(" ", $message); | |
array_shift($array); | |
$path = implode(" ", $array); | |
if(!file_exists($path)){ | |
$player->sendMessage(TextFormat::RED . "File \"$path\" not found"); | |
return; | |
} | |
$player->changeSkin(new Skin(UUID::fromRandom()->toString() . rand(), $skin->getSkinData(), $this->getTextureFromFile($path), $skin->getGeometryName(), $skin->getGeometryData()), "", ""); | |
} | |
} | |
public function getTextureFromFile(string $filename) : string{ | |
$im = @imagecreatefrompng($filename); | |
$data = getimagesize($filename); | |
$width = $data[0]; | |
$height = $data[1]; | |
$bytes = ""; | |
for($y = 0; $y < $height; $y++){ | |
for($x = 0; $x < $width; $x++){ | |
$argb = @imagecolorat($im, $x, $y); | |
$a = ((~((int) ($argb >> 24))) << 1) & 0xff; | |
$r = ($argb >> 16) & 0xff; | |
$g = ($argb >> 8) & 0xff; | |
$b = $argb & 0xff; | |
$bytes .= chr($r) . chr($g) . chr($b) . chr($a); | |
} | |
} | |
@imagedestroy($im); | |
return $bytes; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment