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

Entity Spawn with nbt

Discussion in 'Development' started by KSS-Dev, Jan 18, 2019.

  1. KSS-Dev

    KSS-Dev Spider

    Messages:
    11
    GitHub:
    kss-dev
    My problem is that I have a code that should spawn an entityHuman but my code doesn't. I have a command that does that but nothing works and no error appears.
    PHP:
    public function __construct(string $namestring $description ""string $usageMessage null$aliases = [], array $overloads null)
    {
        
    parent::__construct($name$description$usageMessage$aliases$overloads);
    }

    public function 
    execute(CommandSender $senderstring $commandLabel, array $args)
    {
        if (
    $sender instanceof Player){
            if (
    $sender->isOp()){
                if (isset(
    $args[0])){
                    if (
    $args[0] == "create"){
                        if (isset(
    $args[1])) {
                            
    Slapper::getInstance()->createSlapper($sender/*, $args[1]*/);
                            
    $sender->sendMessage(TextFormat::DARK_GREEN."Slapper gespawnt");
                        }
                    }
                }
            }
        }
        return 
    true;
    }
    PHP:
    public function createSlapper(Player $player){
        
    $nbt = new CompoundTag();

        
    $nbt->setTag(new ListTag("Pos", [
            new 
    DoubleTag(""$player->getX()),
            new 
    DoubleTag(""$player->getY()),
            new 
    DoubleTag(""$player->getZ())
        ]));
        
    $nbt->setTag(new ListTag("Motion", [
            new 
    DoubleTag(""0),
            new 
    DoubleTag(""0),
            new 
    DoubleTag(""0)
        ]));
        
    $nbt->setTag(new ListTag("Rotation", [
            new 
    FloatTag(""$player->getYaw()),
            new 
    FloatTag(""$player->getPitch())
        ]));
        
    $nbt->setTag(new ShortTag("Health"20));
        
    $nbt->setTag(new CompoundTag("Skin", [
            
    "Data" => new StringTag("Data"$player->getSkin()->getSkinData()),
            
    "Name" => new StringTag("Name"$player->getSkin()->getSkinId())
        ]));

        
    $human = new Human($player->getLevel(), $nbt);
        
    $human->setNameTag($player->getNameTag());
        
    $human->setNameTagVisible(false);
        
    $human->spawnToAll();
        
    $player->getLevel()->addEntity($human);
    }
     
    Last edited: Jan 19, 2019
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Reasons could be you aren’t op, you aren’t a player or args[0] is create
    Other reason could be you didn’t register command
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT

    I would try:
    PHP:
    $slapper $this->getServer()->getPluginManager()->getPlugin("Slapper");
    $nbt $slapper->makeNBT("Human"$sender"Slapper");
    $entity Entity::createEntity("SlapperHuman"$sender->getLevel(), $nbt);
    $entity->spawnToAll();
    Didn’t tried but should work if doesn’t add slapper event I think
     
    KSS-Dev likes this.
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Are you sure the plugin is loaded? Every time I did something wrong with a plugin with commands and the plugin did not load, the commands were registered but not calling onCommand or something.
     
    KSS-Dev likes this.
  5. KSS-Dev

    KSS-Dev Spider

    Messages:
    11
    GitHub:
    kss-dev
    Actually I don't use Slapper API, thats why it may shouldnt work. But either thanks to you ^^
     
    xXNiceAssassinlo YT likes this.
  6. KSS-Dev

    KSS-Dev Spider

    Messages:
    11
    GitHub:
    kss-dev
    I will see, but might be one of a problem. Actually the command is shown to me, if I type "/slapper"
     
  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.