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

Solved Explosion doesn't work

Discussion in 'Development' started by Khaled, Mar 24, 2020.

  1. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    Hello, it has been long since i tried to code something, i created a plugin where i can select a place to explode by using a detonator
    "/detonator" to take the detonator
    "/setdetxyz" to set the coordinates of the explosion
    so the coordinates are working fine so far, commands, and the config
    but the problem is that when i set the coordinates the explosion just doesn't work(no smoke even) and no erros in the console for some reason, i hope someone can help

    PHP:
    <?php

    namespace Detonator;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\level\Explosion;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\player\PlayerInteractEvent;


    class 
    Main extends PluginBase implements Listener
    {


        public function 
    onEnable()
        {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            @
    mkdir($this->getDataFolder());
            
    $this->config = new Config($this->getDataFolder() . "config.yml"Config::YAML);
            
    $this->config->save();
        }

        public function 
    onDisable()
        {
            
    unlink($this->getDataFolder() . "config.yml");
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool
        
    {
            if (
    $cmd->getName() === "detonator") {
                
    $det Item::get(34701);
                
    $det->setCustomName("§aDetonator");
                
    $sender->getInventory()->addItem($det);
                return 
    true;
            }
            if (
    $cmd->getName() === "setdetxyz") {
                
    $sender->sendMessage("You can now choose a block to explode!");
                
    $this->config->setNested($sender->getName().".allowxyz"true);
                
    $this->config->save();
                return 
    true;
            }
        }

        public function 
    addExplosion(Position $p){
            
    $exp = new Explosion($p6null);
            
    $exp->explodeA();
            
    $exp->explodeB();
        }

        public function 
    onTouch(PlayerInteractEvent $event)
        {
            
    $player $event->getPlayer();
            
    $item $event->getItem();

            if(
    $this->config->get($player->getName())){
                if(
    $this->config->getNested($player->getName().".allowxyz")){
                    
    $b $event->getBlock();
                    
    $xx $b->getX();
                    
    $yy $b->getY();
                    
    $zz $b->getZ();
                    
    $this->config->setNested($player->getName().".X"$xx);
                    
    $this->config->setNested($player->getName().".Y"$yy);
                    
    $this->config->setNested($player->getName().".Z"$zz);
                    
    $this->config->save();
                    
    $this->config->setNested($player->getName().".allowxyz"false);
                    
    $this->config->save();
                    
    $this->config->setNested($player->getName().".allowdet"true);
                    
    $this->config->save();
                    
    $player->sendMessage("§aBlock coordinates are set");
                } else {
                    return;
                }
            }
            if(
    $item->getCustomName() == "§aDetonator"){
                
    $x $this->config->getNested($player->getName().".X");
                
    $y $this->config->getNested($player->getName().".Y");
                
    $z $this->config->getNested($player->getName().".Z");
                
    $this->addExplosion(new Position($x$y$z$player->getLevel()));
                
    $player->sendMessage("Exploded!");
                
    $this->config->setNested($player->getName().".allowdet"false);
                
    $this->config->save();
                
    $this->config->setNested($player->getName().".X", []);
                
    $this->config->save();
                
    $this->config->setNested($player->getName().".Y", []);
                
    $this->config->save();
                
    $this->config->setNested($player->getName().".Z", []);
                
    $this->config->save();
            }
            
    dont mind this/*if($item->getId() == 347 or $item->getCustomName() == "§aDetonator" and (in_array($this->config->get("players"), $player->getName()))){
                $player->sendMessage("Boom!");
                $this->addExplosion(new Position($player->getX(), $player->getY(), $player->getZ(), $player->getLevel()));
                $this->config->setNested($player->getName().".allowdet", false);
                $this->config->save();
            } */ 
    dont mind this
        
    }
    }
     
    Last edited: Mar 24, 2020
  2. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    Never mind guys i fixed it myself... seems like nobody else did, i just recoded the last part and now it works.
     
  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.