From cd0f9b92eeb8297aaad4ebb7da16eb8b8411f15d Mon Sep 17 00:00:00 2001 From: boy0001 Date: Wed, 11 Feb 2015 20:25:04 +1100 Subject: [PATCH] more debug trim stuff --- .../plot/commands/DebugExec.java | 35 ++++++++++++++++++- .../plot/commands/Trim.java | 25 ++++++++----- .../plot/util/ChunkManager.java | 14 ++++---- 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index 9660e4674..ee28f480b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -31,6 +31,7 @@ import java.util.UUID; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.entity.Player; @@ -38,19 +39,23 @@ import org.bukkit.entity.Player; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; public class DebugExec extends SubCommand { + private ArrayList chunks = null; + private World world; + public DebugExec() { super("debugexec", "plots.admin", "Multi-purpose debug command", "debugexec", "exec", CommandCategory.DEBUG, false); } @Override public boolean execute(final Player player, final String... args) { - List allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired", "seen"}); + List allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired", "seen", "trim-check-chunks", "trim-get-chunks"}); if (args.length > 0) { String arg = args[0].toLowerCase(); switch (arg) { @@ -136,10 +141,38 @@ public class DebugExec extends SubCommand { PlayerFunctions.sendMessage(null, "BULK MCR: " + chunks0.size()); ArrayList chunks = Trim.getTrimPlots(world); chunks.addAll(chunks0); + this.chunks = chunks; + this.world = world; PlayerFunctions.sendMessage(null, "MCR: " + chunks.size()); PlayerFunctions.sendMessage(null, "CHUNKS: " + chunks.size() * 256); PlayerFunctions.sendMessage(null, "Calculating size on disk..."); PlayerFunctions.sendMessage(null, "SIZE (bytes): " + Trim.calculateSizeOnDisk(world, chunks)); + return true; + } + case "trim-check-chunks": { + if (this.chunks == null) { + return PlayerFunctions.sendMessage(null, "Please run the 'trim-get-chunks' command first"); + } + + PlayerFunctions.sendMessage(null, "Checking MCR files for existing plots:"); + int count = 0; + for (ChunkLoc loc : chunks) { + int sx = loc.x << 4; + int sz = loc.z << 4; + loop: + for (int x = sx; x < sx + 16; x++) { + for (int z = sz; z < sz + 16; z++) { + Chunk chunk = world.getChunkAt(x, z); + Plot plot = ChunkManager.hasPlot(world, chunk); + if (plot != null) { + PlayerFunctions.sendMessage(null, " - " + plot); + count++; + break loop; + } + } + } + } + PlayerFunctions.sendMessage(null, "Found " + count + "plots."); } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index 3882e732a..dff5a158d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -120,7 +120,7 @@ public class Trim extends SubCommand { final HybridPlotManager manager = (HybridPlotManager) PlotMain.getPlotManager(world); final HybridPlotWorld plotworld = (HybridPlotWorld) PlotMain.getWorldSettings(world); final String worldname = world.getName(); - String directory = new File(".").getAbsolutePath() + File.separator + world.getName() + File.separator + "region"; + String directory = world.getName() + File.separator + "region"; File folder = new File(directory); File[] regionFiles = folder.listFiles(); ArrayList chunkChunks = new ArrayList<>(); @@ -222,16 +222,21 @@ public class Trim extends SubCommand { public static long calculateSizeOnDisk(World world, ArrayList chunks) { int result = 0; for (ChunkLoc loc : chunks) { - String directory = new File(".").getAbsolutePath() + File.separator + world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca"; + String directory = world.getName() + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca"; File file = new File(directory); - result += file.getTotalSpace(); + try { + result += file.length(); + } + catch (Exception e) { + e.printStackTrace(); + } } return result; } public static ArrayList getTrimChunks(World world) { ArrayList toRemove = new ArrayList<>(); - String directory = new File(".").getAbsolutePath() + File.separator + world.getName() + File.separator + "region"; + String directory = world.getName() + File.separator + "region"; File folder = new File(directory); File[] regionFiles = folder.listFiles(); for (File file : regionFiles) { @@ -245,11 +250,12 @@ public class Trim extends SubCommand { ChunkLoc loc = new ChunkLoc(x, z); toRemove.add(loc); } - catch (Exception e) {} + catch (Exception e) { + System.out.print(name); + } continue; } else { - boolean delete = false; Path path = Paths.get(file.getPath()); try { BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class); @@ -265,8 +271,9 @@ public class Trim extends SubCommand { ChunkLoc loc = new ChunkLoc(x, z); toRemove.add(loc); } - catch (Exception e) {} - delete = true; + catch (Exception e) { + System.out.print(name); + } } } catch (Exception e) { @@ -290,7 +297,7 @@ public class Trim extends SubCommand { for (int x = sx; x < sx + 16; x++) { for (int z = sz; z < sz + 16; z++) { Chunk chunk = world.getChunkAt(x, z); - if (ChunkManager.hasPlot(world, chunk)) { + if (ChunkManager.hasPlot(world, chunk) != null) { delete = false; break loop; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 1657fbbfd..d8454ac48 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -51,7 +51,7 @@ public class ChunkManager { public static HashMap tasks = new HashMap<>(); public static ArrayList getChunkChunks(World world) { - File[] regionFiles = new File(new File(".").getAbsolutePath() + File.separator + world.getName() + File.separator + "region").listFiles(); + File[] regionFiles = new File(world.getName() + File.separator + "region").listFiles(); ArrayList chunks = new ArrayList<>(); for (File file : regionFiles) { String name = file.getName(); @@ -69,7 +69,7 @@ public class ChunkManager { TaskManager.runTask(new Runnable() { @Override public void run() { - String directory = new File(".").getAbsolutePath() + File.separator + world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca"; + String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca"; File file = new File(directory); PlotMain.sendConsoleSenderMessage("&6 - Deleted region "+file.getName()+" (max 256 chunks)"); if (file.exists()) { @@ -79,7 +79,7 @@ public class ChunkManager { }); } - public static boolean hasPlot(World world, Chunk chunk) { + public static Plot hasPlot(World world, Chunk chunk) { int x1 = chunk.getX() << 4; int z1 = chunk.getZ() << 4; int x2 = x1 + 15; @@ -89,14 +89,14 @@ public class ChunkManager { Plot plot; plot = PlotHelper.getCurrentPlot(bot); if (plot != null && plot.owner != null) { - return true; + return plot; } Location top = new Location(world, x2, 0, z2); plot = PlotHelper.getCurrentPlot(top); if (plot != null && plot.owner != null) { - return true; + return plot; } - return false; + return null; } private static HashMap chestContents; @@ -335,7 +335,6 @@ public class ChunkManager { if (state instanceof Skull) { Object[] data = skullData.get(loc); if (data[0] != null) { - System.out.print("SET OWNER"); ((Skull) (state)).setOwner((String) data[0]); } if (((Integer) data[1]) != 0) { @@ -523,7 +522,6 @@ public class ChunkManager { hopperContents.put(bl, invHop); break; case 397: - System.out.print("SAVING SKULL"); bl = new BlockLoc(x, y, z); Skull skull = (Skull) block.getState(); String o = skull.getOwner();