diff --git a/plugin.yml b/plugin.yml index 9efa5e22..af705e84 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: EssentialsPE main: EssentialsPE\Loader -version: 1.1.0 Beta 8 +version: 1.1.0 Beta 9 api: 1.12.0 author: LegendsOfMCPE Team website: https://github.com/LegendOfMCPE/EssentialsPE diff --git a/src/EssentialsPE/BaseFiles/BaseKit.php b/src/EssentialsPE/BaseFiles/BaseKit.php index c9bd1a58..49a5b106 100644 --- a/src/EssentialsPE/BaseFiles/BaseKit.php +++ b/src/EssentialsPE/BaseFiles/BaseKit.php @@ -1,7 +1,9 @@ items[$id]; } + + /** + * @param Inventory $inventory + */ + public function addToInventory(Inventory $inventory){ + foreach($this->getItems() as $i){ + $inventory->setItem($inventory->firstEmpty(), clone $i); + } + } + + /** + * @param Player $player + */ + public function giveToPlayer(Player $player){ + $this->addToInventory($player->getInventory()); + } } \ No newline at end of file diff --git a/src/EssentialsPE/Commands/Kit.php b/src/EssentialsPE/Commands/Kit.php index 21855947..af81d449 100644 --- a/src/EssentialsPE/Commands/Kit.php +++ b/src/EssentialsPE/Commands/Kit.php @@ -2,7 +2,6 @@ namespace EssentialsPE\Commands; use EssentialsPE\BaseFiles\BaseCommand; -use EssentialsPE\BaseFiles\BaseKit; use EssentialsPE\Loader; use pocketmine\command\CommandSender; use pocketmine\Player; @@ -41,7 +40,7 @@ public function execute(CommandSender $sender, $alias, array $args){ $sender->sendMessage(TextFormat::RED . "[Error] You can't get this kit"); return false; } - $this->giveItems($sender, $kit); + $kit->giveToPlayer($sender); $sender->sendMessage(TextFormat::GREEN . "Getting kit " . TextFormat::AQUA . $kit->getName() . "..."); break; case 2: @@ -58,7 +57,7 @@ public function execute(CommandSender $sender, $alias, array $args){ $sender->sendMessage(TextFormat::RED . "[Error] Player not found"); return false; } - $this->giveItems($player, $kit); + $kit->giveToPlayer($player); $player->sendMessage(TextFormat::GREEN . "Getting kit " . TextFormat::AQUA . $kit->getName() . "..."); $sender->sendMessage(TextFormat::GREEN . "Giving " . TextFormat::YELLOW . $player->getDisplayName() . TextFormat::GREEN . " kit " . TextFormat::AQUA . $kit->getName() . TextFormat::GREEN . "..."); break; @@ -69,16 +68,4 @@ public function execute(CommandSender $sender, $alias, array $args){ } return true; } - - /** - * @param Player $player - * @param BaseKit $kit - * @return bool - */ - private function giveItems(Player $player, BaseKit $kit){ - foreach($kit->getItems() as $k){ - $player->getInventory()->setItem($player->getInventory()->firstEmpty(), $k); - } - return true; - } } \ No newline at end of file diff --git a/src/EssentialsPE/EventHandlers/PlayerEvents.php b/src/EssentialsPE/EventHandlers/PlayerEvents.php index dfbb2317..e6197cf4 100644 --- a/src/EssentialsPE/EventHandlers/PlayerEvents.php +++ b/src/EssentialsPE/EventHandlers/PlayerEvents.php @@ -16,6 +16,7 @@ use pocketmine\event\player\PlayerPreLoginEvent; use pocketmine\event\player\PlayerQuitEvent; use pocketmine\event\TextContainer; +use pocketmine\event\TranslationContainer; use pocketmine\Player; use pocketmine\utils\TextFormat; @@ -43,7 +44,11 @@ public function onPlayerPreLogin(PlayerPreLoginEvent $event){ public function onPlayerJoin(PlayerJoinEvent $event){ // Nick and NameTag set: $message = $event->getJoinMessage(); - if($message instanceof TextContainer){ + if($message instanceof TranslationContainer){ + foreach($message->getParameters() as $i => $m){ + $message->setParameter($i, str_replace($event->getPlayer()->getName(), $event->getPlayer()->getDisplayName(), $m)); + } + }elseif($message instanceof TextContainer){ $message->setText(str_replace($event->getPlayer()->getName(), $event->getPlayer()->getDisplayName(), $message->getText())); }else{ $message = str_replace($event->getPlayer()->getName(), $event->getPlayer()->getDisplayName(), $message); @@ -65,7 +70,11 @@ public function onPlayerJoin(PlayerJoinEvent $event){ public function onPlayerQuit(PlayerQuitEvent $event){ // Quit message (nick): $message = $event->getQuitMessage(); - if($message instanceof TextContainer){ + if($message instanceof TranslationContainer){ + foreach($message->getParameters() as $i => $m){ + $message->setParameter($i, str_replace($event->getPlayer()->getName(), $event->getPlayer()->getDisplayName(), $m)); + } + }elseif($message instanceof TextContainer){ $message->setText(str_replace($event->getPlayer()->getName(), $event->getPlayer()->getDisplayName(), $message->getText())); }else{ $message = str_replace($event->getPlayer()->getName(), $event->getPlayer()->getDisplayName(), $message); diff --git a/src/EssentialsPE/EventHandlers/SignEvents.php b/src/EssentialsPE/EventHandlers/SignEvents.php index acb57f06..d3514cf8 100644 --- a/src/EssentialsPE/EventHandlers/SignEvents.php +++ b/src/EssentialsPE/EventHandlers/SignEvents.php @@ -19,7 +19,6 @@ public function onSignTap(PlayerInteractEvent $event){ $tile = $event->getBlock()->getLevel()->getTile(new Vector3($event->getBlock()->getFloorX(), $event->getBlock()->getFloorY(), $event->getBlock()->getFloorZ())); if($tile instanceof Sign){ // Free sign - // TODO Implement costs if($tile->getText()[0] === "[Free]"){ $event->setCancelled(true); if(!$event->getPlayer()->hasPermission("essentials.sign.use.free")){ @@ -85,29 +84,15 @@ public function onSignTap(PlayerInteractEvent $event){ $event->getPlayer()->sendMessage(TextFormat::RED . "[Error] You're in " . $event->getPlayer()->getServer()->getGamemodeString($event->getPlayer()->getGamemode()) . " mode"); return; }else{ - if(!$event->getPlayer()->hasPermission("essentials.kits." . strtolower($tile->getText()[1]))){ - $event->getPlayer()->sendMessage(TextFormat::RED . "[Error] You don't have permissions to get this kit"); - return; - }elseif(!$this->getPlugin()->getKit($tile->getText()[1])){ + if(!($kit = $this->getPlugin()->getKit($tile->getText()[1]))){ $event->getPlayer()->sendMessage(TextFormat::RED . "[Error] Kit doesn't exists"); return; + }elseif(!$event->getPlayer()->hasPermission("essentials.kits." . $kit->getName())){ + $event->getPlayer()->sendMessage(TextFormat::RED . "[Error] You don't have permissions to get this kit"); + return; }else{ - foreach($tile->getText()[1] as $k){ - $k = explode(" ", $k); - if(count($k) > 1){ - $amount = $k[1]; - }else{ - $amount = 1; - } - $item_name = $k[0]; - $item = $this->getPlugin()->getItem($item_name); - if($item->getID() === 0) { - return; - } - $item->setCount($amount); - $event->getPlayer()->getInventory()->setItem($event->getPlayer()->getInventory()->firstEmpty(), $item); - } - $event->getPlayer()->sendMessage(TextFormat::GREEN . "Getting kit " . $tile->getText()[1] . "..."); + $kit->giveToPlayer($event->getPlayer()); + $event->getPlayer()->sendMessage(TextFormat::GREEN . "Getting kit " . TextFormat::AQUA . $kit->getName() . "..."); } } } @@ -188,7 +173,7 @@ public function onSignTap(PlayerInteractEvent $event){ $event->getPlayer()->sendMessage(TextFormat::RED . "[Error] You can't teleport to that warp"); return; } - $event->getPlayer()->teleport($warp[0], $warp[1], $warp[2]); + $event->getPlayer()->teleport($warp); $event->getPlayer()->sendMessage(TextFormat::GREEN . "Warping to " . $tile->getText()[1] . "..."); } }