Created
May 25, 2020 15:54
-
-
Save PJZ9n/51668720abd3a88b035dea6133f247bd 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\entity\EntityDamageByEntityEvent; | |
use pocketmine\event\entity\EntityDamageEvent; | |
use pocketmine\event\Listener; | |
use pocketmine\level\Level; | |
use pocketmine\nbt\tag\CompoundTag; | |
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); | |
Entity::registerEntity(NPC::class); | |
} | |
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], $args[1])) { | |
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 NPC($sender->getLevel(), $nbt, $args[1]); | |
$npc->setNameTag("nametag"); | |
$npc->setImmobile(); | |
$npc->spawnToAll(); | |
$sender->sendMessage($this->getDataFolder() . "{$args[0]}.skinを着せたNPCを作りました!"); | |
break; | |
} | |
return true; | |
} | |
} | |
class NPC extends Human | |
{ | |
/** @var string */ | |
private $message; | |
public function __construct(Level $level, CompoundTag $nbt, string $message) | |
{ | |
parent::__construct($level, $nbt); | |
$this->message = $message; | |
} | |
public function move(float $dx, float $dy, float $dz): void | |
{ | |
return; | |
} | |
public function attack(EntityDamageEvent $source): void | |
{ | |
if (!$source instanceof EntityDamageByEntityEvent) return; | |
$entity = $source->getDamager(); | |
if (!$entity instanceof Player) return; | |
$entity->sendMessage($this->message); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment