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

Solved Chest Not Closing? BlockEventPacket

Discussion in 'Development' started by Astro, Dec 18, 2018.

  1. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    here is my code
    PHP:
    class VoteCrateTask extends Task
    {
        private 
    $player;
        private 
    $block;
        public 
    $seconds;

        public function 
    __construct(Player $playerMain $pluginBlock $block)
        {
            
    $this->player $player;
            
    $this->plugin $plugin;
            
    $this->block $block;
            
    $this->seconds 0;
        }

        public function 
    onRun(int $currentTick):void {
            
    $this->player->sendMessage("hi...");
            
    $timer $this->seconds--;
            if (
    $timer === 5) {
                
    $this->closeChest($this->block);
            }
        }

        public function 
    closeChest($block): void{
            
    $pk = new BlockEventPacket;
            
    $pk->= (int)$block->x;
            
    $pk->= (int)$block->y;
            
    $pk->= (int)$block->z;
            
    $pk->eventType 1;
            
    $pk->eventData 0;
            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $user$user->dataPacket($pk);
        }
     
  2. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    you set seconds equal to '0' and you are subtracting, when you should be adding or set seconds equal to 5 for it to work
     
  3. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    PHP:
    class VoteCrateTask extends Task
    {
        private 
    $player;
        private 
    $block;
        public 
    $seconds;

        public function 
    __construct(Player $playerMain $pluginBlock $block)
        {
            
    $this->player $player;
            
    $this->plugin $plugin;
            
    $this->block $block;
            
    $this->seconds 5;
        }

        public function 
    onRun(int $currentTick):void {
            
    $timer $this->seconds;
            
    $this->player->sendMessage("hi...");
            
    $timer--;
            if (
    $timer === 5) {
                
    $this->closeChest($this->block);
            }
        }

        public function 
    closeChest($block): void{
            
    $pk = new BlockEventPacket;
            
    $pk->= (int)$block->x;
            
    $pk->= (int)$block->y;
            
    $pk->= (int)$block->z;
            
    $pk->eventType 1;
            
    $pk->eventData 0;
            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $user$user->dataPacket($pk);
        }
     
  4. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    nop, that doesn't work either
     
  5. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    Okay well what is the problem and what are you attempting todo
     
  6. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    i'm trying to close the chest after 5 seconds, but that doesn't seem to work
     
  7. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    Show me how you are calling the task.
     
  8. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    PHP:
                        $pk = new BlockEventPacket;
                        if (
    $pk->eventData == 0) {
                            
    $pk->= (int)$block->x;
                            
    $pk->= (int)$block->y;
                            
    $pk->= (int)$block->z;
                            
    $pk->eventType 1;
                            
    $pk->eventData 1;
                            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $user$user->dataPacket($pk);
                            
    $this->plugin->getScheduler()->scheduleDelayedTask(new VoteCrateTask($player$this->plugin$block), 5);
                        } else {
                            
    $player->sendMessage("§8[§6!§8]§c This crate is already in use...");
                        }
     
  9. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    Exactly it must be a REPEATING task not DELAYED.
    PHP:
              $pk = new BlockEventPacket;
                        if (
    $pk->eventData == 0) {
                            
    $pk->= (int)$block->x;
                            
    $pk->= (int)$block->y;
                            
    $pk->= (int)$block->z;
                            
    $pk->eventType 1;
                            
    $pk->eventData 1;
                            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $user$user->dataPacket($pk);
                            
    $this->plugin->getScheduler()->scheduleRepeatingTask(new VoteCrateTask($player$this->plugin$block), 5);
                        } else {
                            
    $player->sendMessage("§8[§6!§8]§c This crate is already in use...");
                        }
     
    Astro likes this.
  10. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    oof! Thanks alot
     
  11. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    it made it even worse :D
     
  12. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    You have the task set at '5'
    PHP:
    $this->plugin->getScheduler()->scheduleRepeatingTask(new VoteCrateTask($player$this->plugin$block), 5);
    when it should be 20(20 because tasks are in ticks and 20 ticks equals 1 second)
    PHP:
    $this->plugin->getScheduler()->scheduleRepeatingTask(new VoteCrateTask($player$this->plugin$block), 20);
     
  13. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    yeah, what i'm talking about is crate isn't closing and it's just spamming my chat with the message "hi...", it's only supposed to do that one time and it's when opening the crate
     
  14. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    PHP:
    class VoteCrateTask extends Task
    {
        private 
    $player;
        private 
    $block;
        public 
    $seconds;

        public function 
    __construct(Player $playerMain $pluginBlock $block)
        {
            
    $this->player $player;
            
    $this->plugin $plugin;
            
    $this->block $block;
            
    $this->seconds 5;
        }

        public function 
    onRun(int $currentTick):void {
            
    $timer $this->seconds--;

            if (
    $timer === 5) {
                
    $this->player->sendMessage("hi...");
            }
            if (
    $timer === 0) {
                
    $this->closeChest($this->block);
            }
        }

        public function 
    closeChest($block): void{
            
    $pk = new BlockEventPacket;
            
    $pk->= (int)$block->x;
            
    $pk->= (int)$block->y;
            
    $pk->= (int)$block->z;
            
    $pk->eventType 1;
            
    $pk->eventData 0;
            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $user$user->dataPacket($pk);
        }
    try this not sure, will stop spam and maybe fix closing
     
  15. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    yeah, it did fix the crate, but not the message
     
  16. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    whats wrong with the message now?
     
  17. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    I just made it using another method and it fixed the message now i'm fixing the crate closing
    PHP:
        public function onRun(int $currentTick):void {
            switch (
    $this->spins) {
                case 
    0:
                    
    $this->player->sendMessage("opening a crate :)");
                    break;
                case 
    1:
                    
    $this->closeChest($this->block);
                    break;
            }
            
    $this->spins++;
            
    $scheduler $this->plugin->getScheduler();
            if(
    $this->spins 1$scheduler->scheduleDelayedTask(new VoteCrateTask($this->player$this->plugin$this->block$this->spins), 20);
        }
     
  18. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    still not working, current code:
    PHP:
    class VoteCrateTask extends Task
    {
        private 
    $player;
        private 
    $block;
        public 
    $seconds;

        public function 
    __construct(Player $playerMain $pluginBlock $block)
        {
            
    $this->player $player;
            
    $this->plugin $plugin;
            
    $this->block $block;
            
    $this->seconds 5;
        }

        public function 
    onRun(int $currentTick):void {
            
    $timer $this->seconds;
            
    $this->player->sendMessage("hi...");
            
    $timer--;
            if (
    $timer === 5) {
                
    $this->closeChest($this->block);
            }
        }

        public function 
    closeChest($block): void{
            
    $pk = new BlockEventPacket;
            
    $pk->= (int)$block->x;
            
    $pk->= (int)$block->y;
            
    $pk->= (int)$block->z;
            
    $pk->eventType 1;
            
    $pk->eventData 0;
            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $user$user->dataPacket($pk);
        }
     
  19. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Don’t add timer when u delay it
     
  20. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    then what should i use for the delay? :confused:
     
  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.