more trim'n

This commit is contained in:
boy0001 2015-01-08 01:10:22 +11:00
parent 162e91bef2
commit ce388ed018
2 changed files with 119 additions and 61 deletions

View File

@ -51,6 +51,8 @@ import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -117,13 +119,17 @@ import org.bukkit.entity.Player;
} }
PlayerFunctions.sendMessage(plr, "Modified: "+modified); PlayerFunctions.sendMessage(plr, "Modified: "+modified);
// trim ID // trim ID
return true;
}
if (!arg.equals("all")) {
PlayerFunctions.sendMessage(plr, C.TRIM_SYNTAX);
return false;
} }
if (arg.equals("all")) {
sendMessage("Initializing..."); sendMessage("Initializing...");
String directory = new File(".").getAbsolutePath() + File.separator + world.getName() + File.separator + "region"; String directory = new File(".").getAbsolutePath() + File.separator + world.getName() + File.separator + "region";
File folder = new File(directory); File folder = new File(directory);
File[] regionFiles = folder.listFiles(); File[] regionFiles = folder.listFiles();
ArrayList<ChunkLoc> chunks = new ArrayList<>(); ArrayList<ChunkLoc> chunkChunks = new ArrayList<>();
sendMessage("Step 1: Bulk chunk trim"); sendMessage("Step 1: Bulk chunk trim");
int count = 0; int count = 0;
@ -155,7 +161,7 @@ import org.bukkit.entity.Player;
int x = Integer.parseInt(split[1]); int x = Integer.parseInt(split[1]);
int z = Integer.parseInt(split[2]); int z = Integer.parseInt(split[2]);
ChunkLoc loc = new ChunkLoc(x, z); ChunkLoc loc = new ChunkLoc(x, z);
chunks.add(loc); chunkChunks.add(loc);
} }
catch (Exception e) { } catch (Exception e) { }
} }
@ -165,6 +171,10 @@ import org.bukkit.entity.Player;
count = 0; count = 0;
PlotMain.sendConsoleSenderMessage("&6 - bulk trim removed " + (count * 256) + " chunks"); PlotMain.sendConsoleSenderMessage("&6 - bulk trim removed " + (count * 256) + " chunks");
if (manager == null) {
sendMessage("Could not continue as the selected world is not a HybridPlotWorld");
return false;
}
sendMessage("Step 2: Plot trim"); sendMessage("Step 2: Plot trim");
{ {
Set<Plot> plots = getOldPlots(world.getName()); Set<Plot> plots = getOldPlots(world.getName());
@ -174,17 +184,35 @@ import org.bukkit.entity.Player;
if (plot.hasOwner()) { if (plot.hasOwner()) {
modified = HybridPlotManager.checkModified(plot, 0); modified = HybridPlotManager.checkModified(plot, 0);
} }
if (plot.owner == null || HybridPlotManager.checkModified(plot, manager.REQUIRED_CHANGES)); if (plot.owner == null || !HybridPlotManager.checkModified(plot, plotworld.REQUIRED_CHANGES)) {
PlotMain.removePlot(worldname, id, true);
count++;
}
} }
} }
PlotMain.sendConsoleSenderMessage("&6 - plot trim removed " + count + " plots"); PlotMain.sendConsoleSenderMessage("&6 - plot trim removed " + count + " plots");
sendMessage("Step 3: Chunk trim"); sendMessage("Step 3: Chunk trim");
for (ChunkLoc loc : chunkChunks) {
int sx = loc.x << 4;
int sz = loc.z << 4;
boolean delete = true;
loop:
for (int x = sx; x < sx + 16; x++) {
for (int z = sz; z < sz + 16; z++) {
Chunk chunk = world.getChunkAt(x, z);
if (hasPlot(world, chunk)) {
delete = false;
break loop;
} }
PlayerFunctions.sendMessage(plr, C.TRIM_SYNTAX); }
return false; }
if (delete) {
deleteRegionFile(worldname, loc);
}
}
return true;
} }
public Set<Plot> getOldPlots(String world) { public Set<Plot> getOldPlots(String world) {
@ -218,6 +246,35 @@ import org.bukkit.entity.Player;
return toRemove; return toRemove;
} }
public void deleteRegionFile(String world, ChunkLoc loc) {
String directory = new File(".").getAbsolutePath() + File.separator + world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca";
File file = new File(directory);
if (file.exists()) {
file.delete();
}
}
private boolean hasPlot(World world, Chunk chunk) {
int x1 = chunk.getX() << 4;
int z1 = chunk.getZ() << 4;
int x2 = x1 + 15;
int z2 = z1 + 15;
Location bot = new Location(world, x1, 0, z1);
Plot plot;
plot = PlotHelper.getCurrentPlot(bot);
if (plot.owner != null) {
return true;
}
Location top = new Location(world, x2, 0, z2);
plot = PlotHelper.getCurrentPlot(top);
if (plot.owner != null) {
return true;
}
return false;
}
private void sendMessage(final String message) { private void sendMessage(final String message) {
PlotMain.sendConsoleSenderMessage("&3PlotSquared -> World trim&8: " + message); PlotMain.sendConsoleSenderMessage("&3PlotSquared -> World trim&8: " + message);
} }

View File

@ -45,7 +45,6 @@ public class HybridPlotWorld extends PlotWorld {
* are used as little as possible to optimize math performance in many of * are used as little as possible to optimize math performance in many of
* the functions/algorithms * the functions/algorithms
*/ */
/** /**
* Default Road Height: 64 * Default Road Height: 64
*/ */
@ -139,6 +138,8 @@ public class HybridPlotWorld extends PlotWorld {
public short OFFSET; public short OFFSET;
public short SCHEMATIC_HEIGHT; public short SCHEMATIC_HEIGHT;
public short REQUIRED_CHANGES = 0;
/* /*
* Here we are just calling the super method, nothing special * Here we are just calling the super method, nothing special
*/ */