1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

help pls

Discussion in 'Plugin Help' started by princeace, Mar 9, 2020.

  1. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    [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
     
  2. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    You're missing a brace somewhere before your function. What are the lines before 53?
     
  3. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    PHP:
    <?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($playernull$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 $playerCommand $commandstring $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.
     
  4. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    [11:32:52] [Server thread/CRITICAL]: TypeError: "Return value of CustSlapper\CustSlapper::eek:nCommand() must be of the type bool, none returned" (EXCEPTION) in "plugins/CustSlapper.phar/src/CustSlapper/CustSlapper" at line 57

    PHP:
    <?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($playernull$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 $playerCommand $commandstring $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;
        }
        }
     
  5. Invy55

    Invy55 Witch

    Messages:
    52
    GitHub:
    invy55
    OnCommand need a true or false return :p
     
  6. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    i fixed that but my problem now after ichange this
    if(count($args) < 2){
    into
    if(count($args) <=2){
    still not working in game
     
  7. Invy55

    Invy55 Witch

    Messages:
    52
    GitHub:
    invy55
    Please post full code
     
  8. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    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;
        }
        }
     
  9. Invy55

    Invy55 Witch

    Messages:
    52
    GitHub:
    invy55
    What is the command that you are trying to execute and why "doesn't work"
     
  10. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    i dont know why not working

    this plugin like a slapper spawn entity with counting player in the text
     
  11. xSoapers

    xSoapers Spider

    Messages:
    6
    GitHub:
    xSoapers
    Counting player on world or counting online player?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.