Merge pull request #615 from MinelinkNetwork/fix-trimming

Fix trimming for worlds in non-standard directories
This commit is contained in:
Jesse Boyd 2015-09-11 08:52:30 +10:00
commit 063a369d8d
7 changed files with 50 additions and 15 deletions

View File

@ -32,6 +32,12 @@ public interface IPlotMain {
*/
File getDirectory();
/**
* Get the directory containing all the worlds
* @return
*/
File getWorldContainer();
/**
* Wrap a player into a PlotPlayer object
* @param obj

View File

@ -63,7 +63,7 @@ public class Trim extends SubCommand {
@Override
public void run() {
final String directory = world + File.separator + "region";
final File folder = new File(directory);
final File folder = new File(PS.get().IMP.getWorldContainer(), directory);
final File[] regionFiles = folder.listFiles();
for (final File file : regionFiles) {
final String name = file.getName();
@ -155,12 +155,12 @@ public class Trim extends SubCommand {
return true;
}
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) {
ChunkManager.manager.deleteRegionFiles(world, chunks);
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks, final Runnable whenDone) {
ChunkManager.manager.deleteRegionFiles(world, chunks, whenDone);
}
public static void sendMessage(final String message) {
PS.debug("&3PlotSquared -> World trim&8: &7" + message);
PS.log("&3PlotSquared -> World trim&8: &7" + message);
}
public PlotId getId(final String id) {
@ -211,10 +211,14 @@ public class Trim extends SubCommand {
getTrimRegions(empty, world, new Runnable() {
@Override
public void run() {
deleteChunks(world, empty);
deleteChunks(world, empty, new Runnable() {
@Override
public void run() {
PS.log("$1Trim task complete!");
}
});
}
});
return true;
}
}

View File

@ -111,6 +111,8 @@ public abstract class ChunkManager {
public abstract void deleteRegionFiles(final String world, final List<ChunkLoc> chunks);
public abstract void deleteRegionFiles(final String world, final List<ChunkLoc> chunks, final Runnable whenDone);
public abstract Plot hasPlot(String world, ChunkLoc chunk);
public abstract boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone);

View File

@ -181,6 +181,11 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
return getDataFolder();
}
@Override
public File getWorldContainer() {
return Bukkit.getWorldContainer();
}
@Override
public TaskManager getTaskManager() {
return new BukkitTaskManager();

View File

@ -68,8 +68,8 @@ import com.plotsquared.bukkit.object.entity.EntityWrapper;
public class BukkitChunkManager extends ChunkManager {
@Override
public ArrayList<ChunkLoc> getChunkChunks(final String world) {
final String directory = Bukkit.getWorldContainer() + File.separator + world + File.separator + "region";
final File folder = new File(directory);
final String directory = world + File.separator + "region";
final File folder = new File(PS.get().IMP.getWorldContainer(), directory);
final File[] regionFiles = folder.listFiles();
final ArrayList<ChunkLoc> chunks = new ArrayList<>();
if (regionFiles == null) {
@ -123,8 +123,8 @@ public class BukkitChunkManager extends ChunkManager {
@Override
public void run() {
final String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca";
final File file = new File(directory);
PS.debug("&6 - Deleting region: " + file.getName() + " (approx 1024 chunks)");
final File file = new File(PS.get().IMP.getWorldContainer(), directory);
PS.log("&6 - Deleting region: " + file.getName() + " (approx 1024 chunks)");
if (file.exists()) {
file.delete();
}
@ -136,18 +136,26 @@ public class BukkitChunkManager extends ChunkManager {
}
@Override
public void deleteRegionFiles(final String world, final List<ChunkLoc> chunks) {
public void deleteRegionFiles(String world, List<ChunkLoc> chunks) {
deleteRegionFiles(world, chunks, null);
}
@Override
public void deleteRegionFiles(final String world, final List<ChunkLoc> chunks, final Runnable whenDone) {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
for (ChunkLoc loc : chunks) {
final String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca";
final File file = new File(directory);
PS.debug("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)");
final File file = new File(PS.get().IMP.getWorldContainer(), directory);
PS.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)");
if (file.exists()) {
file.delete();
}
}
if (whenDone != null) {
whenDone.run();
}
}
});
}

View File

@ -427,6 +427,11 @@ public class SpongeMain implements IPlotMain, PluginContainer {
return new File("mods/PlotSquared");
}
@Override
public File getWorldContainer() {
return new File(".");
}
@Override
public void disable() {
PS.get().disable();

View File

@ -121,6 +121,11 @@ public class SpongeChunkManager extends ChunkManager {
}
@Override
public void deleteRegionFiles(String world, List<ChunkLoc> chunks, Runnable whenDone) {
// TODO Auto-generated method stub
}
@Override
public Plot hasPlot(String world, ChunkLoc chunk) {
// TODO Auto-generated method stub