mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 18:24:43 +02:00
Hows this?
This commit is contained in:
@ -48,71 +48,54 @@ description = "Delete unmodified portions of your plotworld",
|
||||
usage = "/plot trim",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.DEBUG)
|
||||
public class Trim extends SubCommand
|
||||
{
|
||||
|
||||
public class Trim extends SubCommand {
|
||||
|
||||
public static boolean TASK = false;
|
||||
public static ArrayList<Plot> expired = null;
|
||||
private static int TASK_ID = 0;
|
||||
|
||||
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone)
|
||||
{
|
||||
if (Trim.TASK) { return false; }
|
||||
TaskManager.runTaskAsync(new Runnable()
|
||||
{
|
||||
|
||||
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
|
||||
if (Trim.TASK) {
|
||||
return false;
|
||||
}
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
final String directory = world + File.separator + "region";
|
||||
final File folder = new File(PS.get().IMP.getWorldContainer(), directory);
|
||||
final File[] regionFiles = folder.listFiles();
|
||||
for (final File file : regionFiles)
|
||||
{
|
||||
for (final File file : regionFiles) {
|
||||
final String name = file.getName();
|
||||
if (name.endsWith("mca"))
|
||||
{
|
||||
if (file.getTotalSpace() <= 8192)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (name.endsWith("mca")) {
|
||||
if (file.getTotalSpace() <= 8192) {
|
||||
try {
|
||||
final String[] split = name.split("\\.");
|
||||
final int x = Integer.parseInt(split[1]);
|
||||
final int z = Integer.parseInt(split[2]);
|
||||
final ChunkLoc loc = new ChunkLoc(x, z);
|
||||
empty.add(loc);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
PS.debug("INVALID MCA: " + name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
final Path path = Paths.get(file.getPath());
|
||||
try
|
||||
{
|
||||
try {
|
||||
final BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
|
||||
final long creation = attr.creationTime().toMillis();
|
||||
final long modification = file.lastModified();
|
||||
final long diff = Math.abs(creation - modification);
|
||||
if (diff < 10000)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (diff < 10000) {
|
||||
try {
|
||||
final String[] split = name.split("\\.");
|
||||
final int x = Integer.parseInt(split[1]);
|
||||
final int z = Integer.parseInt(split[2]);
|
||||
final ChunkLoc loc = new ChunkLoc(x, z);
|
||||
empty.add(loc);
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
PS.debug("INVALID MCA: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Exception e)
|
||||
{}
|
||||
} catch (final Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,10 +106,11 @@ public class Trim extends SubCommand
|
||||
Trim.TASK = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone)
|
||||
{
|
||||
if (Trim.TASK) { return false; }
|
||||
|
||||
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
|
||||
if (Trim.TASK) {
|
||||
return false;
|
||||
}
|
||||
System.currentTimeMillis();
|
||||
sendMessage("Collecting region data...");
|
||||
final ArrayList<Plot> plots = new ArrayList<>();
|
||||
@ -135,16 +119,12 @@ public class Trim extends SubCommand
|
||||
sendMessage(" - MCA #: " + chunks.size());
|
||||
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
|
||||
sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes");
|
||||
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable()
|
||||
{
|
||||
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
while ((System.currentTimeMillis() - start) < 50)
|
||||
{
|
||||
if (plots.size() == 0)
|
||||
{
|
||||
while ((System.currentTimeMillis() - start) < 50) {
|
||||
if (plots.size() == 0) {
|
||||
empty.addAll(chunks);
|
||||
Trim.TASK = false;
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
@ -152,19 +132,17 @@ public class Trim extends SubCommand
|
||||
return;
|
||||
}
|
||||
final Plot plot = plots.remove(0);
|
||||
|
||||
|
||||
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id);
|
||||
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
|
||||
|
||||
|
||||
final int ccx1 = (pos1.getX() >> 9);
|
||||
final int ccz1 = (pos1.getZ() >> 9);
|
||||
final int ccx2 = (pos2.getX() >> 9);
|
||||
final int ccz2 = (pos2.getZ() >> 9);
|
||||
|
||||
for (int x = ccx1; x <= ccx2; x++)
|
||||
{
|
||||
for (int z = ccz1; z <= ccz2; z++)
|
||||
{
|
||||
|
||||
for (int x = ccx1; x <= ccx2; x++) {
|
||||
for (int z = ccz1; z <= ccz2; z++) {
|
||||
chunks.remove(new ChunkLoc(x, z));
|
||||
}
|
||||
}
|
||||
@ -174,74 +152,61 @@ public class Trim extends SubCommand
|
||||
Trim.TASK = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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.log("&3PlotSquared -> World trim&8: &7" + message);
|
||||
}
|
||||
|
||||
public PlotId getId(final String id)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
public PlotId getId(final String id) {
|
||||
try {
|
||||
final String[] split = id.split(";");
|
||||
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer plr, final String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
final PlotId id = getId(arg);
|
||||
if (id != null)
|
||||
{
|
||||
if (id != null) {
|
||||
MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("all"))
|
||||
{
|
||||
if (arg.equals("all")) {
|
||||
MainUtil.sendMessage(plr, "/plot trim all &l<world>");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2)
|
||||
{
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String arg = args[0].toLowerCase();
|
||||
if (!arg.equals("all"))
|
||||
{
|
||||
if (!arg.equals("all")) {
|
||||
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String world = args[1];
|
||||
if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null))
|
||||
{
|
||||
if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
|
||||
return false;
|
||||
}
|
||||
if (Trim.TASK)
|
||||
{
|
||||
if (Trim.TASK) {
|
||||
sendMessage(C.TRIM_IN_PROGRESS.s());
|
||||
return false;
|
||||
}
|
||||
sendMessage(C.TRIM_START.s());
|
||||
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||
getTrimRegions(empty, world, new Runnable()
|
||||
{
|
||||
getTrimRegions(empty, world, new Runnable() {
|
||||
public void run() {
|
||||
deleteChunks(world, empty, new Runnable() {
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user