Fixed world regeneration

This commit is contained in:
main() 2012-08-06 15:17:14 +02:00
parent b8a0891c4c
commit a9a5d7467a
4 changed files with 60 additions and 27 deletions

View File

@ -1048,36 +1048,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
/**
* {@inheritDoc}
* @deprecated This is deprecated!
*/
@Override
@Deprecated
public Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed) {
MultiverseWorld world = this.worldManager.getMVWorld(name);
if (world == null) {
return false;
}
List<Player> ps = world.getCBWorld().getPlayers();
if (useNewSeed) {
// Set the worldseed.
if (randomSeed) {
Random random = new Random();
Long newseed = random.nextLong();
seed = newseed.toString();
}
((WorldManager) this.worldManager).getConfigWorlds().set("worlds." + name + ".seed", seed);
}
if (this.worldManager.deleteWorld(name, false)) {
this.worldManager.loadWorlds(false);
SafeTTeleporter teleporter = this.getSafeTTeleporter();
Location newSpawn = this.getServer().getWorld(name).getSpawnLocation();
// Send all players that were in the old world, BACK to it!
for (Player p : ps) {
teleporter.safelyTeleport(null, p, newSpawn, true);
}
return true;
}
return false;
return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed);
}
/**

View File

@ -129,7 +129,10 @@ public interface Core {
* @param seed The seed of the world.
*
* @return True if success, false if fail.
*
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String)} instead.
*/
@Deprecated
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed);
/**

View File

@ -256,4 +256,16 @@ public interface MVWorldManager {
* @return The {@link MultiverseWorld} new players should spawn in.
*/
MultiverseWorld getFirstSpawnWorld();
/**
* Regenerates a world.
*
* @param name Name of the world to regenerate
* @param useNewSeed If a new seed should be used
* @param randomSeed IF the new seed should be random
* @param seed The seed of the world.
*
* @return True if success, false if fail.
*/
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed);
}

View File

@ -17,6 +17,7 @@ import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.Location;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.configuration.ConfigurationSection;
@ -36,6 +37,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.logging.Level;
@ -783,6 +785,46 @@ public class WorldManager implements MVWorldManager {
return allNames;
}
/**
* {@inheritDoc}
*/
@Override
public boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed) {
MultiverseWorld world = this.getMVWorld(name);
if (world == null)
return false;
List<Player> ps = world.getCBWorld().getPlayers();
if (useNewSeed) {
long theSeed;
if (randomSeed) {
theSeed = new Random().nextLong();
} else {
try {
theSeed = Long.parseLong(seed);
} catch (NumberFormatException e) {
theSeed = seed.hashCode();
}
}
world.setSeed(theSeed);
}
if (this.deleteWorld(name, false)) {
this.doLoad(name, true);
SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
Location newSpawn = world.getSpawnLocation();
// Send all players that were in the old world, BACK to it!
for (Player p : ps) {
teleporter.safelyTeleport(null, p, newSpawn, true);
}
return true;
}
return false;
}
/**
* Gets the {@link FileConfiguration} that this {@link WorldManager} is using.
* @return The {@link FileConfiguration} that this {@link WorldManager} is using.