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

Solved Invalid or uninitialized Zip object

Comments in 'Plugin Development' started by Andrey Nazarchuk, Jul 20, 2015.

  1. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Hello everyone,
    I have had this error for about a week and cannot find a solution for it.
    I am trying to make my plugin extract a zip, and this is what happens:
    Code:
    [Server thread/CRITICAL]: Could not execute task SkyWars\Timer: ZipArchive::extractTo(): Invalid or uninitialized Zip object
    [10:47:20] [Server thread/WARNING]: RuntimeException: "ZipArchive::extractTo(): Invalid or uninitialized Zip object" (E_WARNING) in "/SkyWars/src/SkyWars/SkyWars" at line 279
    
    Here is everything around line 279:
    PHP:
            $worldName $this->config->get('arenaworld');
            
    $zipPath $this->getDataFolder("worlds/$worldName/" $worldName ".zip");
            
    $this->extractWorld($zipPath$worldName);
            
    $seconds 0;
            return 
    true;
        }
      
        public function 
    extractWorld($zipPath$worldName){
            
    $zip = new \ZipArchive;
            
    $open $zip->open($zipPath);
    (
    279)$zip->extractTo($this->getServer()->getDataPath() . "worlds/$worldName/");
            
    $zip->close();
        }
    Here is a tree of my worlds folder:
    Code:
    \---worlds
        |   JungleRuins.zip
        | 
        +---JungleRuins
        |   |   JungleRuins.zip
        |   |   level.dat
        |   | 
        |   \---region
        |           r.-1.-1.mcr
        |           r.-1.0.mcr
        |           r.0.-1.mcr
        |           r.0.0.mcr
        |         
        \---world
            |   level.dat
            | 
            \---region
                    r.-1.-1.mcr
                    r.-1.0.mcr
                    r.0.-1.mcr
                    r.0.0.mcr
    
    I hope this is enough information, Thanks for reading and helping :D
    Last edited: Jul 21, 2015
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Are you sure your zip file is correct? Try doing a var_dump on $open.
  3. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Yes, I did send to compressed folder on windows because 7zip has problems unziping sometimes.
    Plus I put the zip everywhere in the world's folder.
    How do I do a var dump exactly?
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    var_dump($open).

    Also, it seems funny. You put the zip in somewhere that you are going to extract to? So does the world already exist or not?
  5. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    It won't overwrite the zip anyways, its good for keeping things orderly. The world does already exist in the folder.
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    lol. Using my post.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Did you delete the world? Maybe when you delete the world, the zip is deleted too.
    Legoboy0215 likes this.
  8. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    No, the world does not get deleted.
  9. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    SOLVED
    Remove the / after $worldName in extractTo. :D
    PHP:
    $worldName $this->config->get('arenaworld');
    $zipPath $this->getDataFolder("worlds/$worldName/" $worldName ".zip");
    $this->extractWorld($zipPath$worldName);
    seconds 0;
    return 
    true;
    }

    public function 
    extractWorld($zipPath$worldName){
    $zip = new \ZipArchive;$open $zip->open($zipPath);
    $zip->extractTo($this->getServer()->getDataPath() . "worlds/$worldName");
    $zip->close();
    }
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wait, is yoyr $this->getDataFolder the PluginBase one?
  11. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    I think so...
    Those line of code are in my main file. It says extends PluginBase implements Listener.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But getDataFolder accepts no parameters...
  13. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Noooo idea lol it works...
  14. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    @PEMapModder Ok so it does not work...
    I remember you send me a link to some code that does this in the LegionPE base, can I please have that link again?
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
  16. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
  17. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Is that your IP?
  18. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Huh?

Share This Page

Advertisement