[18:02:39] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected 'public' (T_PUBLIC), expecting case (T_CASE) or default (T_DEFAULT) or '}'" (EXCEPTION) in "plugins/CustSlapper.phar/src/CustSlapper/CustSlapper" at line 53 i got this error! in this line PHP: public function getNPCEntity() : ?Entity{ $level = $this->getServer()->getDefaultLevel(); if(is_null($this->NPCEntity)) { foreach ($level->getEntities() as $entity) { if ($entity instanceof Player) return null; $name = explode("\n", $entity->getNameTag()); if ($name[0] == TextFormat::GREEN . "CustSlapper") { $this->NPCEntity = $entity; return $entity; } } }else{ return $this->NPCEntity; } return null; } anyone know this? thank you
PHP: <?phpnamespace CustSlapper;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\entity\Entity;use pocketmine\entity\Human;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\item\Item;use pocketmine\level\Level;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\utils\TextFormat;class CustSlapper extends PluginBase{ /** @var Entity $NPCEntity */ private $NPCEntity; /** @var CustSlapper $instance */ public static $instance; public function spawnNPC(Player $player) : void{ $nbt = Entity::createBaseNBT($player, null, $player->getYaw(), $player->getPitch()); $skinTag = $player->namedtag->getCompoundTag("Skin"); assert($skinTag !== null); $nbt->setTag(clone $skinTag); $nametag = TextFormat::BOLD . TextFormat::AQUA . "CustSlapper" . TextFormat::RESET . "\n". TextFormat::YELLOW . "0 Playing"; $entity = Entity::createEntity("NPCEntity", $player->getLevel(), $nbt); $entity->setNameTag($nametag); $entity->spawnToAll(); } public function onCommand(CommandSender $player, Command $command, string $label, array $args): bool { if(strtolower($command->getName()) == "custslapper"){ if(empty($args[0]) || !$player->isOp())return false; switch($args[0]){ case "create"; if(!$player instanceof Player){ $player->sendMessage(TextFormat::RED . "This command can be executed only in game!"); return false; } /** * @return null|Entity */ public function getNPCEntity() : ?Entity{ $level = $this->getServer()->getDefaultLevel(); if(is_null($this->NPCEntity)) { foreach ($level->getEntities() as $entity) { if ($entity instanceof Player) return null; $name = explode("\n", $entity->getNameTag()); if ($name[0] == TextFormat::GREEN . "CustSlapper") { $this->NPCEntity = $entity; return $entity; } } }else{ return $this->NPCEntity; } return null; } this is the whole code! thanks.
[11:32:52] [Server thread/CRITICAL]: TypeError: "Return value of CustSlapper\CustSlapper:nCommand() must be of the type bool, none returned" (EXCEPTION) in "plugins/CustSlapper.phar/src/CustSlapper/CustSlapper" at line 57 PHP: <?phpnamespace CustSlapper;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\entity\Entity;use pocketmine\entity\Human;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\item\Item;use pocketmine\level\Level;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\utils\TextFormat;class CustSlapper extends PluginBase{ /** @var Entity $NPCEntity */ private $NPCEntity; /** @var CustSlapper $instance */ public static $instance; public function spawnNPC(Player $player) : void{ $nbt = Entity::createBaseNBT($player, null, $player->getYaw(), $player->getPitch()); $skinTag = $player->namedtag->getCompoundTag("Skin"); assert($skinTag !== null); $nbt->setTag(clone $skinTag); $nametag = TextFormat::BOLD . TextFormat::AQUA . "CustSlapper" . TextFormat::RESET . "\n". TextFormat::YELLOW . "0 Playing"; $entity = Entity::createEntity("NPCEntity", $player->getLevel(), $nbt); $entity->setNameTag($nametag); $entity->spawnToAll(); } public function onCommand(CommandSender $player, Command $command, string $label, array $args): bool { if(strtolower($command->getName()) == "custslapper"){ if(empty($args[0]) || !$player->isOp())return false; switch($args[0]){ case "create"; if(!$player instanceof Player){ $player->sendMessage(TextFormat::RED . "This command can be executed only in game!"); return false; } if(count($args) < 2){ $player->sendMessage(TextFormat::AQUA . "Usage: " . TextFormat::WHITE . "/custslapper create [name]"); return false; } } } } /**@return null|Entity */ public function getNPCEntity() : ?Entity{ $level = $this->getServer()->getDefaultLevel(); if(is_null($this->NPCEntity)) { foreach ($level->getEntities() as $entity) { if ($entity instanceof Player) return null; $name = explode("\n", $entity->getNameTag()); if ($name[0] == TextFormat::GREEN . "CustSlapper") { $this->NPCEntity = $entity; return $entity; } } }else{ return $this->NPCEntity; } return null; } }
i fixed that but my problem now after ichange this if(count($args) < 2){ into if(count($args) <=2){ still not working in game
Code: <?php namespace CustSlapper; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\entity\Entity; use pocketmine\entity\Human; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\Player; use pocketmine\plugin\PluginBase; use pocketmine\utils\TextFormat; class CustSlapper extends PluginBase { /** @var Entity $NPCEntity */ private $NPCEntity; /** @var CustSlapper $instance */ public static $instance; public function spawnNPC(Player $player) : void{ $nbt = Entity::createBaseNBT($player, null, $player->getYaw(), $player->getPitch()); $skinTag = $player->namedtag->getCompoundTag("Skin"); assert($skinTag !== null); $nbt->setTag(clone $skinTag); $nametag = TextFormat::BOLD . TextFormat::AQUA . "CustSlapper" . TextFormat::RESET . "\n". TextFormat::YELLOW . "0 Playing"; $entity = Entity::createEntity("NPCEntity", $player->getLevel(), $nbt); $entity->setNameTag($nametag); $entity->spawnToAll(); } public function onCommand(CommandSender $player, Command $command, string $label, array $args): bool { if(strtolower($command->getName()) == "custslapper"){ if(empty($args[0]) || !$player->isOp())return false; switch($args[0]){ case "create"; if(!$player instanceof Player){ $player->sendMessage(TextFormat::RED . "This command can be executed only in game!"); return false; } if(count($args) <=2){ $player->sendMessage(TextFormat::AQUA . "Usage: " . TextFormat::WHITE . "/custslapper create [name]"); return false; } } } return true; } /**@return null|Entity */ public function getNPCEntity() : ?Entity{ $level = $this->getServer()->getDefaultLevel(); if(is_null($this->NPCEntity)) { foreach ($level->getEntities() as $entity) { if ($entity instanceof Player) return null; $name = explode("\n", $entity->getNameTag()); if ($name[0] == TextFormat::GREEN . "CustSlapper") { $this->NPCEntity = $entity; return $entity; } } }else{ return $this->NPCEntity; } return null; } }