-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06f0847
commit 5746233
Showing
5 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
86 changes: 86 additions & 0 deletions
86
src/presentkim/humanoid/command/subcommands/CopySubCommand.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace presentkim\humanoid\command\subcommands; | ||
|
||
use pocketmine\nbt\tag\DoubleTag; | ||
use pocketmine\nbt\tag\ListTag; | ||
use pocketmine\Player; | ||
use pocketmine\command\CommandSender; | ||
use pocketmine\entity\Entity; | ||
use pocketmine\event\player\PlayerInteractEvent; | ||
use pocketmine\nbt\tag\CompoundTag; | ||
|
||
use presentkim\humanoid\HumanoidMain as Plugin; | ||
use presentkim\humanoid\act\{ | ||
PlayerAct, ClickHumanoidAct, InteractAct | ||
}; | ||
use presentkim\humanoid\command\{ | ||
SubCommand, PoolCommand, | ||
}; | ||
use presentkim\humanoid\event\PlayerClickHumanoidEvent; | ||
use presentkim\humanoid\util\Translation; | ||
|
||
class CopySubCommand extends SubCommand{ | ||
|
||
public function __construct(PoolCommand $owner){ | ||
parent::__construct($owner, 'copy'); | ||
} | ||
|
||
/** | ||
* @param CommandSender $sender | ||
* @param String[] $args | ||
* | ||
* @return bool | ||
*/ | ||
public function onCommand(CommandSender $sender, array $args) : bool{ | ||
if ($sender instanceof Player) { | ||
PlayerAct::registerAct(new class ($sender) extends PlayerAct implements ClickHumanoidAct{ | ||
|
||
/** @param PlayerClickHumanoidEvent $event */ | ||
public function onClickHumanoid(PlayerClickHumanoidEvent $event) : void{ | ||
$this->cancel(); | ||
PlayerAct::registerAct(new class ($this->player, clone $event->getHumanoid()->namedtag) extends PlayerAct implements InteractAct{ | ||
|
||
/** @var CompoundTag */ | ||
private $nbt; | ||
|
||
/** | ||
* @param Player $player | ||
* @param CompoundTag $nbt | ||
*/ | ||
public function __construct(Player $player, CompoundTag $nbt){ | ||
parent::__construct($player); | ||
$this->nbt = $nbt; | ||
} | ||
|
||
/** @param PlayerInteractEvent $event */ | ||
public function onInteract(PlayerInteractEvent $event) : void{ | ||
$pos = $event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR ? $this->player->asPosition() : $pos = $event->getBlock(); | ||
$this->nbt->setTag(new ListTag("Pos", [ | ||
new DoubleTag("", $pos->x), | ||
new DoubleTag("", $pos->y), | ||
new DoubleTag("", $pos->z), | ||
])); | ||
|
||
$entity = Entity::createEntity('Humanoid', $pos->level, $this->nbt); | ||
$entity->spawnToAll(); | ||
|
||
$this->player->sendMessage(Plugin::$prefix . Translation::translate('humanoid-copy@success-paste')); | ||
|
||
$event->setCancelled(true); | ||
$this->cancel(); | ||
} | ||
}); | ||
|
||
$this->player->sendMessage(Plugin::$prefix . Translation::translate('humanoid-copy@success-copy')); | ||
|
||
$event->setCancelled(true); | ||
} | ||
}); | ||
$sender->sendMessage(Plugin::$prefix . $this->translate('success')); | ||
} else { | ||
$sender->sendMessage(Plugin::$prefix . Translation::translate('command-generic-failure@in-game')); | ||
} | ||
return true; | ||
} | ||
} |