mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-12 10:24:07 +01:00
more debug trim stuff
This commit is contained in:
parent
e9aa1be58c
commit
cd0f9b92ee
@ -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<ChunkLoc> 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<String> allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired", "seen"});
|
||||
List<String> 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<ChunkLoc> 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<ChunkLoc> chunkChunks = new ArrayList<>();
|
||||
@ -222,16 +222,21 @@ public class Trim extends SubCommand {
|
||||
public static long calculateSizeOnDisk(World world, ArrayList<ChunkLoc> 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<ChunkLoc> getTrimChunks(World world) {
|
||||
ArrayList<ChunkLoc> 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;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class ChunkManager {
|
||||
public static HashMap<Integer, Integer> tasks = new HashMap<>();
|
||||
|
||||
public static ArrayList<ChunkLoc> 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<ChunkLoc> 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<BlockLoc, ItemStack[]> 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();
|
||||
|
Loading…
Reference in New Issue
Block a user