Solved Confused about WorldCreator...

Discussion in 'Spigot Plugin Development' started by Realm, Jun 6, 2017.

  1. So I have this code:
    Code (Text):
        public static void copyWorldToMain(String mapName) {
            System.out.println("Loading world...");
            newEnd = new WorldCreator(mapName).createWorld();

            if (!isNewEndWorld(newEnd)) {
                copyFileStructure(new File(path, mapName), new File(Bukkit.getWorldContainer(), mapName));
                System.out.println("World " + newEnd.getName() + " was recreated.");
                return;
            }
         
            System.out.println("World " + newEnd.getName() + " was not recreated.");
        }
    newEnd is a world object.
    copyFileStructure simply copies a specified file to another location.

    Code (Text):
        private static boolean isNewEndWorld(World world) {
            int i = 0;
            int z = world.getSpawnLocation().getBlockZ();
            int x = world.getSpawnLocation().getBlockX();

            for (int y = 0; y <= 256; y++) {
                Block block = world.getBlockAt(x, y, z);
                if (block.getType() != Material.ENDER_STONE) continue;
                i++;
            }
            return i == 40;
        }
    (Only way I can think of checking if the new world is the correct world ;p)
    The spawn point has 60 or so blocks of Ender Stone underneath it.

    My issue is, if I build something on the server, then restart the server, the whole map gets reset and the builds are gone.

    This is what gets printed in console when this method gets executed:
    Code (Text):
    06.06 03:07:37 [Server] INFO Loading world...
    06.06 03:07:37 [Server] INFO -------- World Settings For [flat_end] --------
    06.06 03:07:37 [Server] INFO Mob Spawn Range: 4
    06.06 03:07:37 [Server] INFO Anti X-Ray: true
    06.06 03:07:37 [Server] INFO Engine Mode: 1
    06.06 03:07:37 [Server] INFO Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    06.06 03:07:37 [Server] INFO Replace Blocks: [1, 5]
    It will never print either of the println messages...
    My understanding of WorldCreator is that it doesn't create a new world, unless the specified world name doesn't exist. Which is great in this case, because it is a custom world, and Im just loading it as a world in memory onEnable. However it keeps resetting the world.
     
  2. TomTheDeveloper

    Supporter

    So I may assume your code does not get further than the following line?

     
  3. Presumably. It seemingly never prints after that.


    Sent from my iPhone using Tapatalk
     
  4. Still stuck...
    I used this code:
    Code (Text):
        public static void copyWorldToMain(String mapName) {
            System.out.println("Loading world...");
            newEnd = new WorldCreator(mapName).createWorld();
            System.out.println("World loaded!");
            if (!isNewEndWorld(newEnd)) {
                copyFileStructure(new File(path, mapName), new File(Bukkit.getWorldContainer(), mapName));
                System.out.println("World " + newEnd.getName() + " was recreated.");
                return;
            }

            System.out.println("World " + newEnd.getName() + " was not recreated.");
        }
    But it never made it past the WorldCreator line...

    Code (Text):
    07.06 04:43:10 [Server] INFO [EndWorld] Enabling EndWorld v1.0
    07.06 04:43:10 [Server] INFO Directory NewEnd in plugins/EndWorld/NewEnd already exists
    07.06 04:43:10 [Server] INFO Loading world...
    07.06 04:43:10 [Server] INFO -------- World Settings For [flat_end] --------
    07.06 04:43:10 [Server] INFO Mob Spawn Range: 4
    07.06 04:43:10 [Server] INFO Anti X-Ray: true
    07.06 04:43:10 [Server] INFO Engine Mode: 1
    07.06 04:43:10 [Server] INFO Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    07.06 04:43:10 [Server] INFO Replace Blocks: [1, 5]
    07.06 04:43:10 [Multicraft] Skipped 36 lines due to rate limit (40/s)
     
  5. Ended up figuring out. The messages from console were showing, just not in console. They were showing in the logs though. From there I was able to conclude that the reason it wasn't doing what I thought it should be, is because my 'isNewEndWorld' check returned true if i == 40, but I was supposed to write i >= 40. ;p
     
  6. WorldCreater I think loads an exising world, but if the world does not exist it makes a new world
     
  7. I did say that in my original post. I was just confused why it didnt work like I thought it should, but the issue is solved now, and the resolution I already posted.
     
  8. Aaa shit guess its my bad then :p