Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved setBlock() doesn't work

Comments in 'Plugin Development' started by Taha_The_Hacker, Oct 14, 2015.

  1. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Hey,

    I've used setBlock() to set blocks, everything else works fine except it,I get No Errors or messages, code:

    Main:
    PHP:
      public function gameStart(){
        
    $this->gameStarted true;
        
    $level $this->getServer()->getLevelByName($this->yml["spleef-world"]);
        for(
    $x $this->yml["spleef-Min-floor-X"]; $x <= $this->yml["spleef-Max-floor-X"]; $x++):
        for(
    $y $this->yml["spleef-Min-floor-Y"]; $y <= $this->yml["spleef-Max-floor-Y"]; $y++):
        for(
    $z $this->yml["spleef-Min-floor-Z"]; $z <= $this->yml["spleef-Max-floor-X"]; $z++):
                
    $level->setBlock(new Vector3($x$y$z), Block::get($this->yml["spleef-floor-reset-block-ID"]));
              endfor;
              endfor;
              endfor;
              
    $this->gameStartTask $this->getServer()->getScheduler()->scheduleRepeatingTask(new GameEnd($this), 20)->getTaskId();
              
    $this->getServer()->broadcastMessage("Spleef Game Started!");
      }
    //GameStart
    // On a command i made it runs gameStart(); to do those.
    GameEnd.php :
    PHP:
    <?php

    namespace TahaTheHacker\MSpleef;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\event\Event;
    use 
    pocketmine\item\item;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\block\Block;

    class 
    GameEnd extends PluginTask{

      public function 
    __construct(Main $plugin){
        
    $this->plugin $plugin;
        
    parent::__construct($plugin);
      }

      public function 
    onRun($tick){
        
    $this->plugin->seconds++;
       
    $level $this->plugin->getServer()->getLevelByName($this->yml["spleef-world"]);
        if(
    $this->plugin->seconds === 120){
        for(
    $x $this->plugin->yml["spleef-Min-floor-X"]; $x <= $this->plugin->yml["spleef-Max-floor-X"]; $x++):
        for(
    $y $this->plugin->yml["spleef-Min-floor-Y"]; $y <= $this->plugin->yml["spleef-Max-floor-Y"]; $y++):
        for(
    $z $this->plugin->yml["spleef-Min-floor-Z"]; $z <= $this->plugin->yml["spleef-Max-floor-X"]; $z++):
                
    $level->setBlock(new Vector3($x$y$z), Block::get(7));
          
    $this->plugin->getServer()->getScheduler()->cancelTask($this->plugin->gameStartTask);
          endfor;
          endfor;
          endfor;
          
    $this->plugin->gameStarted false;
          
    $this->plugin->getServer()->broadcastMessage("Spleef Game Ended!");
      }
    //If Seconds.
      
    }//onRun

    }//Class
    config.yml:
    Code:
    #MSpleef's default config.yml
    
    #the world where spleef starts
    spleef-world: "lobby"
    
    #Min position for the spleef floor to reset (from)
    spleef-Min-floor-X: 45
    spleef-Min-floor-Y: 45
    spleef-Min-floor-Z: 45
    
    #Max position for the spleef floor to reset (to)
    spleef-Max-floor-X: 44
    spleef-Max-floor-Y: 44
    spleef-Max-floor-Z: 44
    
    #the block id that the spleef floor will reset to
    spleef-floor-reset-block-ID: 1
    ##To-Do things:
    
    spleef-started-message: "Spleef Game Started!"
    
    But everything works fine expect setBlocks, Please Help if you know what's wrong :)
    I have Events registered, Listener used.
    Thanks for replying ;)

    ++ Sorry if i made too many Questions today! because i am doing something awesome.
    Last edited: Oct 14, 2015
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Oh Then You Have No Idea...
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Have a look at Github repository. I have added new commit with few bug fixes. I used another method how initConfigs, but it'll work the same ($this->cfgname["stuff"])... Your problem was that you didn't declared public $yml; public... at the start and you used for($x = 0; $x <= 1; $x++){ wrongly. Use "{", not the ":" and endfor; (It's used rather in PHP webpages)
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    wow.. Thanks!
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Using endfor is perfectly fine, except that it is not commonly used (not a common coding style in this community). There is no limitation to webpages. Why did everyone like this? https://forums.pocketmine.net/profile-posts/8105/
    Moreover, if it didn't work, it would have syntax errors.

Share This Page

Advertisement