mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 16:46:45 +01:00
fix regenallroads and made performance improvements to trim
This commit is contained in:
parent
a4af0efa04
commit
0bb4afbd9a
@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -43,6 +46,7 @@ import com.intellectualcrafters.plot.util.ChunkManager;
|
|||||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
|
||||||
public class DebugExec extends SubCommand {
|
public class DebugExec extends SubCommand {
|
||||||
|
|
||||||
@ -127,53 +131,46 @@ public class DebugExec extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(null, "Local: " + date.toLocaleString());
|
PlayerFunctions.sendMessage(null, "Local: " + date.toLocaleString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "trim-get-chunks": {
|
case "trim-check": {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
PlayerFunctions.sendMessage(null, "Use /plot debugexec trim-get-chunks <world>");
|
PlayerFunctions.sendMessage(null, "Use /plot debugexec trim-get-chunks <world>");
|
||||||
PlayerFunctions.sendMessage(null, "&7 - Generates a list of regions to trim");
|
PlayerFunctions.sendMessage(null, "&7 - Generates a list of regions to trim");
|
||||||
return PlayerFunctions.sendMessage(null, "&7 - Run after plot expiry has run");
|
return PlayerFunctions.sendMessage(null, "&7 - Run after plot expiry has run");
|
||||||
}
|
}
|
||||||
World world = Bukkit.getWorld(args[1]);
|
final World world = Bukkit.getWorld(args[1]);
|
||||||
if (world == null || !PlotMain.isPlotWorld(args[1])) {
|
if (world == null || !PlotMain.isPlotWorld(args[1])) {
|
||||||
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
|
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
|
||||||
}
|
}
|
||||||
ArrayList<ChunkLoc> chunks0 = Trim.getTrimChunks(world);
|
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||||
PlayerFunctions.sendMessage(null, "BULK MCR: " + chunks0.size());
|
Trim.getTrimRegions(empty, world, new Runnable() {
|
||||||
ArrayList<ChunkLoc> chunks = Trim.getTrimPlots(world);
|
@Override
|
||||||
chunks.addAll(chunks0);
|
public void run() {
|
||||||
this.chunks = chunks;
|
Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
|
||||||
this.world = world;
|
Trim.sendMessage(" - MCA #: " + empty.size());
|
||||||
PlayerFunctions.sendMessage(null, "MCR: " + chunks.size());
|
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 256) + " (max)");
|
||||||
PlayerFunctions.sendMessage(null, "CHUNKS: " + chunks.size() * 256);
|
Trim.sendMessage("Exporting log for manual approval...");
|
||||||
PlayerFunctions.sendMessage(null, "Calculating size on disk...");
|
final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "trim.txt");
|
||||||
PlayerFunctions.sendMessage(null, "SIZE (bytes): " + Trim.calculateSizeOnDisk(world, chunks));
|
PrintWriter writer;
|
||||||
|
try {
|
||||||
|
writer = new PrintWriter(file);
|
||||||
|
String worldname = world.getName();
|
||||||
|
for (ChunkLoc loc : empty) {
|
||||||
|
writer.println(worldname +"/region/r." + loc.x + "." + loc.z +".mca" );
|
||||||
|
}
|
||||||
|
writer.close();
|
||||||
|
Trim.sendMessage("File saved");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Trim.sendMessage("File failed to save! :(");
|
||||||
|
}
|
||||||
|
Trim.sendMessage("How to get the chunk coords from a region file:");
|
||||||
|
Trim.sendMessage(" - Locate the x,z values for the region file (the two numbers which are separated by a dot)");
|
||||||
|
Trim.sendMessage(" - Multiply each number by 32; this gives you the starting position");
|
||||||
|
Trim.sendMessage(" - Add 31 to each number to get the end position");
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
|
PlayerFunctions.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
|
||||||
|
@ -101,37 +101,49 @@ public class Trim extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_WORLD);
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (runTrimTask(world)) {
|
|
||||||
sendMessage(C.TRIM_START.s());
|
if (Trim.TASK) {
|
||||||
return true;
|
sendMessage(C.TRIM_IN_PROGRESS.s());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
sendMessage(C.TRIM_IN_PROGRESS.s());
|
|
||||||
return false;
|
sendMessage(C.TRIM_START.s());
|
||||||
|
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||||
|
getTrimRegions(empty, world, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
deleteChunks(world, empty);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean runTrimTask(final World world) {
|
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final World world, final Runnable whenDone) {
|
||||||
if (Trim.TASK) {
|
if (Trim.TASK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Trim.TASK = true;
|
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final HybridPlotManager manager = (HybridPlotManager) PlotMain.getPlotManager(world);
|
|
||||||
final HybridPlotWorld plotworld = (HybridPlotWorld) PlotMain.getWorldSettings(world);
|
|
||||||
final String worldname = world.getName();
|
|
||||||
String directory = world.getName() + File.separator + "region";
|
String directory = 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> chunkChunks = new ArrayList<>();
|
|
||||||
for (File file : regionFiles) {
|
for (File file : regionFiles) {
|
||||||
String name = file.getName();
|
String name = file.getName();
|
||||||
if (name.endsWith("mca")) {
|
if (name.endsWith("mca")) {
|
||||||
if (file.getTotalSpace() <= 8192) {
|
if (file.getTotalSpace() <= 8192) {
|
||||||
file.delete();
|
try {
|
||||||
|
String[] split = name.split("\\.");
|
||||||
|
int x = Integer.parseInt(split[1]);
|
||||||
|
int z = Integer.parseInt(split[2]);
|
||||||
|
ChunkLoc loc = new ChunkLoc(x, z);
|
||||||
|
empty.add(loc);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.print("INVALID MCA: " + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
boolean delete = false;
|
|
||||||
Path path = Paths.get(file.getPath());
|
Path path = Paths.get(file.getPath());
|
||||||
try {
|
try {
|
||||||
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
|
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
|
||||||
@ -139,51 +151,70 @@ public class Trim extends SubCommand {
|
|||||||
long modification = file.lastModified();
|
long modification = file.lastModified();
|
||||||
long diff = Math.abs(creation - modification);
|
long diff = Math.abs(creation - modification);
|
||||||
if (diff < 10000) {
|
if (diff < 10000) {
|
||||||
PlotMain.sendConsoleSenderMessage("&6 - Deleted region "+name+" (max 256 chunks)");
|
try {
|
||||||
file.delete();
|
String[] split = name.split("\\.");
|
||||||
delete = true;
|
int x = Integer.parseInt(split[1]);
|
||||||
|
int z = Integer.parseInt(split[2]);
|
||||||
|
ChunkLoc loc = new ChunkLoc(x, z);
|
||||||
|
empty.add(loc);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.print("INVALID MCA: " + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!delete) {
|
|
||||||
String[] split = name.split("\\.");
|
|
||||||
try {
|
|
||||||
int x = Integer.parseInt(split[1]);
|
|
||||||
int z = Integer.parseInt(split[2]);
|
|
||||||
ChunkLoc loc = new ChunkLoc(x, z);
|
|
||||||
chunkChunks.add(loc);
|
|
||||||
}
|
|
||||||
catch (Exception e) { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Set<Plot> plots = ExpireManager.getOldPlots(world.getName()).keySet();
|
Trim.TASK = false;
|
||||||
Trim.TASK_ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() {
|
TaskManager.runTask(whenDone);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (manager != null && plots.size() > 0) {
|
|
||||||
Plot plot = plots.iterator().next();
|
|
||||||
if (plot.hasOwner()) {
|
|
||||||
HybridPlotManager.checkModified(plot, 0);
|
|
||||||
}
|
|
||||||
if (plot.owner == null || !HybridPlotManager.checkModified(plot, plotworld.REQUIRED_CHANGES)) {
|
|
||||||
PlotMain.removePlot(worldname, plot.id, true);
|
|
||||||
}
|
|
||||||
plots.remove(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
trimPlots(world);
|
|
||||||
Trim.TASK = false;
|
|
||||||
sendMessage("Done!");
|
|
||||||
Bukkit.getScheduler().cancelTask(Trim.TASK_ID);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1, 1);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Trim.TASK = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final World world, final Runnable whenDone) {
|
||||||
|
if (Trim.TASK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sendMessage("Collecting region data...");
|
||||||
|
final ArrayList<ChunkLoc> chunks = ChunkManager.getChunkChunks(world);
|
||||||
|
sendMessage(" - MCA #: " + chunks.size());
|
||||||
|
sendMessage(" - CHUNKS: " + (chunks.size() * 256) +" (max)");
|
||||||
|
sendMessage(" - TIME ESTIMATE: " + (chunks.size()/1200) +" minutes");
|
||||||
|
Trim.TASK_ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (chunks.size() == 0) {
|
||||||
|
TaskManager.runTask(whenDone);
|
||||||
|
Bukkit.getScheduler().cancelTask(Trim.TASK_ID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ChunkLoc loc = chunks.get(0);
|
||||||
|
int sx = loc.x << 5;
|
||||||
|
int sz = loc.z << 5;
|
||||||
|
|
||||||
|
boolean delete = true;
|
||||||
|
|
||||||
|
loop:
|
||||||
|
for (int x = sx; x < sx + 32; x++) {
|
||||||
|
for (int z = sz; z < sz + 32; z++) {
|
||||||
|
Chunk chunk = world.getChunkAt(x, z);
|
||||||
|
if (ChunkManager.hasPlot(world, chunk) != null) {
|
||||||
|
delete = false;
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (delete) {
|
||||||
|
empty.add(loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1L, 1L);
|
||||||
|
Trim.TASK = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,99 +250,7 @@ public class Trim extends SubCommand {
|
|||||||
}, 1, 1);
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long calculateSizeOnDisk(World world, ArrayList<ChunkLoc> chunks) {
|
public static void deleteChunks(World world, ArrayList<ChunkLoc> chunks) {
|
||||||
int result = 0;
|
|
||||||
for (ChunkLoc loc : chunks) {
|
|
||||||
String directory = world.getName() + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca";
|
|
||||||
File file = new File(directory);
|
|
||||||
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 = world.getName() + File.separator + "region";
|
|
||||||
File folder = new File(directory);
|
|
||||||
File[] regionFiles = folder.listFiles();
|
|
||||||
for (File file : regionFiles) {
|
|
||||||
String name = file.getName();
|
|
||||||
if (name.endsWith("mca")) {
|
|
||||||
if (file.getTotalSpace() <= 8192) {
|
|
||||||
try {
|
|
||||||
String[] split = name.split("\\.");
|
|
||||||
int x = Integer.parseInt(split[1]);
|
|
||||||
int z = Integer.parseInt(split[2]);
|
|
||||||
ChunkLoc loc = new ChunkLoc(x, z);
|
|
||||||
toRemove.add(loc);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.out.print(name);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Path path = Paths.get(file.getPath());
|
|
||||||
try {
|
|
||||||
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
|
|
||||||
long creation = attr.creationTime().toMillis();
|
|
||||||
long modification = file.lastModified();
|
|
||||||
long diff = Math.abs(creation - modification);
|
|
||||||
if (diff < 10000) {
|
|
||||||
PlotMain.sendConsoleSenderMessage("&6 - Deleted region "+name+" (max 256 chunks)");
|
|
||||||
try {
|
|
||||||
String[] split = name.split("\\.");
|
|
||||||
int x = Integer.parseInt(split[1]);
|
|
||||||
int z = Integer.parseInt(split[2]);
|
|
||||||
ChunkLoc loc = new ChunkLoc(x, z);
|
|
||||||
toRemove.add(loc);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.out.print(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return toRemove;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<ChunkLoc> getTrimPlots(World world) {
|
|
||||||
ArrayList<ChunkLoc> toRemove = new ArrayList<>();
|
|
||||||
ArrayList<ChunkLoc> chunks = ChunkManager.getChunkChunks(world);
|
|
||||||
for (ChunkLoc loc : chunks) {
|
|
||||||
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 (ChunkManager.hasPlot(world, chunk) != null) {
|
|
||||||
delete = false;
|
|
||||||
break loop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (delete) {
|
|
||||||
toRemove.add(loc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return toRemove;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void trimPlots(World world) {
|
|
||||||
ArrayList<ChunkLoc> chunks = getTrimPlots(world);
|
|
||||||
String worldname = world.getName();
|
String worldname = world.getName();
|
||||||
for (ChunkLoc loc : chunks) {
|
for (ChunkLoc loc : chunks) {
|
||||||
ChunkManager.deleteRegionFile(worldname, loc);
|
ChunkManager.deleteRegionFile(worldname, loc);
|
||||||
@ -319,7 +258,7 @@ public class Trim extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(final String message) {
|
public static void sendMessage(final String message) {
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared -> World trim&8: " + message);
|
PlotMain.sendConsoleSenderMessage("&3PlotSquared -> World trim&8: &7" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -180,13 +180,13 @@ import com.intellectualcrafters.plot.util.SendChunk;
|
|||||||
|
|
||||||
public void regenerateChunkChunk(World world, ChunkLoc loc) {
|
public void regenerateChunkChunk(World world, ChunkLoc loc) {
|
||||||
|
|
||||||
int sx = loc.x << 4;
|
int sx = loc.x << 5;
|
||||||
int sz = loc.z << 4;
|
int sz = loc.z << 5;
|
||||||
|
|
||||||
HashSet<Chunk> chunks = new HashSet<Chunk>();
|
HashSet<Chunk> chunks = new HashSet<Chunk>();
|
||||||
|
|
||||||
for (int x = sx; x < sx + 16; x++) {
|
for (int x = sx; x < sx + 32; x++) {
|
||||||
for (int z = sz; z < sz + 16; z++) {
|
for (int z = sz; z < sz + 32; z++) {
|
||||||
Chunk chunk = world.getChunkAt(x, z);
|
Chunk chunk = world.getChunkAt(x, z);
|
||||||
chunk.load(false);
|
chunk.load(false);
|
||||||
chunks.add(chunk);
|
chunks.add(chunk);
|
||||||
|
@ -78,7 +78,7 @@ public class ChunkManager {
|
|||||||
public void run() {
|
public void run() {
|
||||||
String directory = 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);
|
File file = new File(directory);
|
||||||
PlotMain.sendConsoleSenderMessage("&6 - Deleted region "+file.getName()+" (max 256 chunks)");
|
PlotMain.sendConsoleSenderMessage("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user