Merge branch 'ammaraskar_folder'

This commit is contained in:
main() 2012-10-22 19:08:15 +02:00
commit 96e8208f3d
3 changed files with 45 additions and 5 deletions

View File

@ -89,6 +89,17 @@ public interface MVWorldManager {
* @return True if success, false if failure.
*/
boolean deleteWorld(String name, boolean removeConfig);
/**
*
* @param name The name of the world to remove
* @param removeFromConfig If true(default), we'll remove the entries from the
* config. If false, they'll stay and the world may come back.
* @param deleteWorldFolder If true the world folder will be completely deleted. If false
* only the contents of the world folder will be deleted
* @return True if success, false if failure.
*/
boolean deleteWorld(String name, boolean removeFromConfig, boolean deleteWorldFolder);
/**
* Unload a world from Multiverse.

View File

@ -44,6 +44,27 @@ public class FileUtils {
return false;
}
}
/**
* Used to delete the contents of a folder, without deleting the folder itself
*
* @param file The folder whose contents to delete.
* @return true if the contents were successfully deleted
*/
public static boolean deleteFolderContents(File file) {
if (file.exists()) {
boolean ret = true;
// If the file exists, and it has more than one file in it.
if (file.isDirectory()) {
for (File f : file.listFiles()) {
ret = ret && deleteFolder(f);
}
}
return ret;
} else {
return false;
}
}
private static final int COPY_BLOCK_SIZE = 1024;

View File

@ -405,7 +405,7 @@ public class WorldManager implements MVWorldManager {
* {@inheritDoc}
*/
@Override
public boolean deleteWorld(String name, boolean removeFromConfig) {
public boolean deleteWorld(String name, boolean removeFromConfig, boolean deleteWorldFolder) {
World world = this.plugin.getServer().getWorld(name);
if (world == null) {
// We can only delete loaded worlds
@ -433,15 +433,15 @@ public class WorldManager implements MVWorldManager {
try {
File worldFile = world.getWorldFolder();
plugin.log(Level.FINER, "deleteWorld(): worldFile: " + worldFile.getAbsolutePath());
boolean deletedWorld = FileUtils.deleteFolder(worldFile);
if (deletedWorld) {
if (deleteWorldFolder ? FileUtils.deleteFolder(worldFile) : FileUtils.deleteFolderContents(worldFile)) {
this.plugin.log(Level.INFO, "World " + name + " was DELETED.");
return true;
} else {
this.plugin.log(Level.SEVERE, "World " + name + " was NOT deleted.");
this.plugin.log(Level.SEVERE, "Are you sure the folder " + name + " exists?");
this.plugin.log(Level.SEVERE, "Please check your file permissions on " + name);
return false;
}
return deletedWorld;
} catch (Throwable e) {
this.plugin.log(Level.SEVERE, "Hrm, something didn't go as planned. Here's an exception for ya.");
this.plugin.log(Level.SEVERE, "You can go politely explain your situation in #multiverse on esper.net");
@ -452,6 +452,14 @@ public class WorldManager implements MVWorldManager {
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean deleteWorld(String name, boolean removeFromConfig) {
return this.deleteWorld(name, removeFromConfig, true);
}
/**
* {@inheritDoc}
*/
@ -791,7 +799,7 @@ public class WorldManager implements MVWorldManager {
world.setSeed(theSeed);
}
if (this.deleteWorld(name, false)) {
if (this.deleteWorld(name, false, false)) {
this.doLoad(name, true);
SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
Location newSpawn = world.getSpawnLocation();