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

Area reset

Comments in 'Plugin Development' started by JackboyPlay, Apr 15, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Hello is it possible to reset an specified area also reset the blocks from the area when someone types /reset
  2. KubixQ
    Offline

    KubixQ Active Member

    Joined:
    Sep 13, 2015
    Posts:
    85
    Minecraft User:
    KubixQ
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  4. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Scan the area using for (height * length * width) and paste it in an array with vector3 and tile object, on reset just do foreach to reset all blocks
  5. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Do for loop from min to max X,Y,Z and save those blocks and save it in array. Then later just reset it. :p
    Tim // robske Büba likes this.
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:
    $x1 0;
    $x2 16;
    $y1 0;
    $y2 16;
    $z1 0;
    $z2 16;

    $n 0;

    for(
    $x $x1$x $x2$x++){
    for(
    $y $y1$y $y2$y++){
    for(
    $z $z1$z $z2$z++){

    $n++;

    $coo $this->getServer()->getLevelByName("lvl")->getBlock(new Vector3($x$y$z));


    if(
    $coo === null$coo $this->getServer()->getLevelByName("lvl")->getTile(new Vector3($x$y$z));


    if(
    $coo === null$coo = new Air();

    $this->ResetArea[$n][0] = new Vector3($x$y$z);
    $this->ResetArea[$n][1] = $coo;

    }}}



    // And to reset the area

    public function ResetArea(){

    foreach(
    $this->ResetArea as $key => $value){

    if(
    $value[1] instanceof Block){

    $this->getServer()->getLevelByName("lvl")->setBlock($value[0], $value[1]);

    }elseif(
    $value[1] instanceof Tile){

    $this->getServer()->getLevelByName("lvl")->setTile($value[0], $value[1]);
    }

    }

    }



    I hope, that I helped you! ;)
    Last edited: Apr 15, 2016
  7. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    1. What happened to indenting?
    2. You should probably save the level object, as you are executing getLevelByName quite often (especially on big areas) [Just looked in PM source, it could create some lagg)
    3. If there is no block, it doesn't mean there is an tile (It can be an tile AND an block at the same position)
    So the correct way of copying would be:
    PHP:
    <?
    public function 
    SaveArea(){
    $x1 0;
    $x2 16;
    $y1 0;
    $y2 16;
    $z1 0;
    $z2 16;

    $n 0;

    $level $this->getServer()->getLevelByName("lvl");

    for(
    $x $x1$x $x2$x++){
        for(
    $y $y1$y $y2$y++){
            for(
    $z $z1$z $z2$z++){
                
    $n++;
                
    $block $level->getBlock(new Vector3($x$y$z));
                
    $this->ResetArea[$n][0] = new Vector3($x$y$z);
                if(
    $block === NULL$block = new Air();
                
    $this->ResetArea[$n][1] = $block;
                
    $tile $level->getTile(new Vector3($x$y$z));
                
    $this->ResetArea[$n][2] = $tile;
                }
            }
        }
    }
    public function 
    ResetArea(){
        
    $level $this->getServer()->getLevelByName("lvl");
        foreach(
    $this->ResetArea as $key => $value){
            if(
    $value[1] instanceof Block){
                
    $level->setBlock($value[0], $value[1]);

            }
            if(
    $value[2] instanceof Tile){
                
    $level->setTile($value[0], $value[2]);
            }
        }
    }
    Last edited: Apr 16, 2016
  8. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Bruh, that code is so ugly that I can't even understand!
    MyNameIsTriXz and Nawaf_Craft1b like this.
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    You can code how you want, but you should indent properly. You do not have to but you SHOULD, and i couldn't even read it in un-indented!
    NULL === null What's wrong about this?
    Because they are needed
    and the <? was just for my crappy editor to understand that this is php.
    The function name is useless here, yes

    Your code was WRONG, there can be tiles and blocks at the same time at the same position!
    And I didn't want to sound rude, i just fixed your code and pointed out the errors
    I don't understand why you hate me now, i just wanted to help out with fixing code
    Hmm, because i fixed indenting, huh?

Share This Page

Advertisement