Skip to content

Commit

Permalink
Add copy sub command
Browse files Browse the repository at this point in the history
  • Loading branch information
PresentKim committed Jan 27, 2018
1 parent 06f0847 commit 5746233
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 3 deletions.
3 changes: 3 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ permissions:
humanoid.cmd.remove:
description: Humanoid command - remove
default: op
humanoid.cmd.copy:
description: Humanoid command - copy
default: op
humanoid.cmd.cancel:
description: Humanoid command - cancel
default: op
Expand Down
9 changes: 8 additions & 1 deletion resources/lang/eng.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ prefix: "[Humanoid] "

humanoid-add@success: "Humanoid was created"
humanoid-remove@success: "Humanoid was removed"
humanoid-copy@success-copy: "Touch the block to paste humanoid"
humanoid-copy@success-paste: "Humanoid was copied"

humanoid-set-name@success: "Humanoid's name was setted to {%0}"
humanoid-set-rotation@success: "Humanoid's rotation was setted to {%0}:{%1}"
Expand All @@ -19,7 +21,7 @@ command-generic-failure@invalid: "{%0} is invalid value"
command-generic-failure@invalid-player: "{%0} is invalid player name"

command-humanoid: "humanoid"
command-humanoid@usage: "/humanoid <add | set | remove | cancel | lang | reload | save>"
command-humanoid@usage: "/humanoid <add | set | remove | copy | cancel | lang | reload | save>"
command-humanoid@description: "Main command of Humanoid"
command-humanoid@aliases: ["hm"]

Expand Down Expand Up @@ -72,6 +74,11 @@ command-humanoid-set-scale: "scale"
command-humanoid-set-scale@usage: "/humanoid Set Scale <scale percent>"
command-humanoid-set-scale@aliases: ["sc"]

command-humanoid-copy: "copy"
command-humanoid-copy@usage: "/humanoid Copy"
command-humanoid-copy@success: "Touch the humanoid to copy"
command-humanoid-copy@aliases: ["cp"]

command-humanoid-remove: "remove"
command-humanoid-remove@usage: "/humanoid Remove"
command-humanoid-remove@success: "Touch the humanoid to remove"
Expand Down
9 changes: 8 additions & 1 deletion resources/lang/kor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ prefix: "[Humanoid] "

humanoid-add@success: "휴머노이드가 생성되었습니다"
humanoid-remove@success: "휴머노이드가 제거되었습니다"
humanoid-copy@success-copy: "휴머노이드를 붙여넣기할 블럭을 터치해주세요"
humanoid-copy@success-paste: "휴머노이드가 복사되었습니다"

humanoid-set-name@success: "휴머노이드의 이름이 {%0}로 설정되었습니다"
humanoid-set-rotation@success: "휴머노이드의 방향이 {%0}:{%1}로 설정되었습니다"
Expand All @@ -19,7 +21,7 @@ command-generic-failure@invalid: "{%0}는 잘못된 값입니다"
command-generic-failure@invalid-player: "{%0}는 잘못된 플레이어 명입니다"

command-humanoid: "humanoid"
command-humanoid@usage: "/humanoid <add | set | remove | cancel | lang | reload | save>"
command-humanoid@usage: "/humanoid <add | set | remove | copy | cancel | lang | reload | save>"
command-humanoid@description: "Humanoid의 메인 명령어"
command-humanoid@aliases: ["hm"]

Expand Down Expand Up @@ -77,6 +79,11 @@ command-humanoid-remove@usage: "/humanoid Remove"
command-humanoid-remove@success: "제거할 휴머노이드를 터치해주세요"
command-humanoid-remove@aliases: ["r"]

command-humanoid-copy: "copy"
command-humanoid-copy@usage: "/humanoid Copy"
command-humanoid-copy@success: "복사할 휴머노이드를 터치해주세요"
command-humanoid-copy@aliases: ["cp"]

command-humanoid-cancel: "cancel"
command-humanoid-cancel@usage: "/humanoid cancel"
command-humanoid-cancel@success: "행동이 취소되었습니다"
Expand Down
3 changes: 2 additions & 1 deletion src/presentkim/humanoid/HumanoidMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use presentkim\humanoid\command\PoolCommand;
use presentkim\humanoid\command\subcommands\{
AddSubCommand, SetSubCommand, RemoveSubCommand, CancelSubCommand, LangSubCommand, ReloadSubCommand
AddSubCommand, SetSubCommand, RemoveSubCommand, CopySubCommand, CancelSubCommand, LangSubCommand, ReloadSubCommand
};
use presentkim\humanoid\entity\Humanoid;
use presentkim\humanoid\listener\DataPacketEventListener;
Expand Down Expand Up @@ -78,6 +78,7 @@ public function reloadCommand() : void{
$this->command->createSubCommand(AddSubCommand::class);
$this->command->createSubCommand(SetSubCommand::class);
$this->command->createSubCommand(RemoveSubCommand::class);
$this->command->createSubCommand(CopySubCommand::class);
$this->command->createSubCommand(CancelSubCommand::class);
$this->command->createSubCommand(LangSubCommand::class);
$this->command->createSubCommand(ReloadSubCommand::class);
Expand Down
86 changes: 86 additions & 0 deletions src/presentkim/humanoid/command/subcommands/CopySubCommand.php
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;
}
}

0 comments on commit 5746233

Please sign in to comment.