Solved World Seed Won't Set

Discussion in 'Spigot Plugin Development' started by xPlumpOrange, May 2, 2017.

  1. Been working on a plugin where players can make there own worlds and play on them. Everything works fine, difficulty gets set, envirnment, etc.. BUT the seed doesn't set. I tried a lot of different things. No result. Heres the createWorld Function:
    Code (Text):
        public boolean createWorld(String player, Difficulty difficulty, long seed) {
            Player playerName = Bukkit.getServer().getPlayer(player);
            UUID playerId = Bukkit.getServer().getPlayer(player).getUniqueId();
            System.out.println("Creating Personal World '" + playerId.toString() + "'...");
            playerName.sendMessage(ChatColor.BOLD + "Creating World...");
            WorldCreator creator = new WorldCreator(playerId.toString());
         
    creator.seed(seed);
    creator.generateStructures(getConfig().getBoolean("DefaultValueForGeneratingStructures"));
            creator.environment(Environment.NORMAL);
            creator.type(WorldType.NORMAL);
         
         
            World world = creator.createWorld();
            world.setDifficulty(difficulty);
            world.setSpawnLocation(0, 0, 0);
            int y = world.getHighestBlockYAt(world.getSpawnLocation()) + 2;
            world.setSpawnLocation(0, y, 0);
         
            WorldBorder border = world.getWorldBorder();
            border.setSize(getConfig().getDouble("DefaultRadius"));
            border.setCenter(0.0, 0.0);
            border.setWarningDistance(0);
            border.setWarningTime(60);
            border.setDamageAmount(0.1);
            border.setDamageBuffer(0);
         
            world.save();
            System.out.println("Created Personal World '" + playerId.toString() + "'!");
            playerName.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "World Created! Teleporting You To It");
            Bukkit.getServer().getWorlds().add(world);
            Location loc = new Location(world, world.getSpawnLocation().getX(), world.getSpawnLocation().getY(), world.getSpawnLocation().getZ());
            playerName.teleport(loc);
         
            return true;
        }
    when the world is created it uses the same seed then when you delete it and create a new one it keeps the same seed as before, i tried changing the difficulties and stuff just in case it doesn't work with that but it does work with difficulty. Any Idea?
     
    #1 xPlumpOrange, May 2, 2017
    Last edited: May 2, 2017
  2. I think the world keeps existing in the folder, and when you try to create the word, it Gets the folder and load the folder world. Try and use an other name for your world.
     
  3. For what I'm doing I can't, also I have noticed that my file isn't deleting.
     
  4. The way world creator works from memory is that, if a world exists with the name you specify, it will load that world, else it will create a new one. If you need to have that name though I suggest getting that name, for example 'world' and adding a random variable after it, such as 'world68004792', then just check to see if a variable in the main server folder where all the worlds are contained starts with the word 'world' and unload. Or check for the whole name that you should have stored in memory. Whichever you want to do


    Sent from my iPhone using Tapatalk
     
  5. Also if you file isn't deleting its because you need to unload the world first then use something along the lines of FileUtils#forceDelete I think it's called


    Sent from my iPhone using Tapatalk
     
  6. I un load with Bukkit.getServer().getWorld(playerId.toString()).unload();
    But I delete by setting a file and doing file.delete();
     
  7. Are you sure that would work? You said you had problems deleting a file. Are you deleting a file or a directory? A world folder is a directory.
     
  8. I actually looked at ways in Java you can delete files and folders and I found one that worked and deleted the world folder and the seed works now too thanks for your help!
     
  9. Not a problem :)