Created
May 25, 2020 07:10
-
-
Save PJZ9n/3279912949cec51826861bb4f8ff5892 to your computer and use it in GitHub Desktop.
スキンのテスト(NPC)
This file contains hidden or 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 | |
/** | |
* @name SaveSkin | |
* @version 1.0.0 | |
* @main PJZ9n\SaveSkin\Main | |
* @api 3.0.0 | |
*/ | |
declare(strict_types=1); | |
namespace PJZ9n\SaveSkin { | |
use pocketmine\command\Command; | |
use pocketmine\command\CommandSender; | |
use pocketmine\command\PluginCommand; | |
use pocketmine\entity\Entity; | |
use pocketmine\entity\Human; | |
use pocketmine\event\Listener; | |
use pocketmine\Player; | |
use pocketmine\plugin\PluginBase; | |
class Main extends PluginBase implements Listener | |
{ | |
public function onEnable(): void | |
{ | |
$command = new PluginCommand("ss", $this); | |
$this->getServer()->getCommandMap()->register($this->getName(), $command); | |
$command = new PluginCommand("sc", $this); | |
$this->getServer()->getCommandMap()->register($this->getName(), $command); | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
} | |
public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool | |
{ | |
if (!$sender instanceof Player) { | |
return true; | |
} | |
switch ($label) { | |
case "ss": | |
if (!isset($args[0])) { | |
return false; | |
} | |
file_put_contents($this->getDataFolder() . "{$args[0]}.skin", serialize($sender->namedtag->getTag("Skin"))); | |
$sender->sendMessage($this->getDataFolder() . "{$args[0]}.skinにセーブしました!"); | |
break; | |
case "sc": | |
if (!isset($args[0])) { | |
return false; | |
} | |
$skinTag = unserialize(file_get_contents($this->getDataFolder() . "{$args[0]}.skin")); | |
$nbt = Entity::createBaseNBT($sender->asVector3(), null, $sender->getYaw(), $sender->getPitch()); | |
$nbt->setTag($skinTag); | |
$npc = new Human($sender->getLevel(), $nbt); | |
$npc->setNameTag("nametag"); | |
$npc->setImmobile(); | |
$npc->spawnToAll(); | |
$sender->sendMessage($this->getDataFolder() . "{$args[0]}.skinを着せたNPCを作りました!"); | |
break; | |
} | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment