it's faster now

This commit is contained in:
boy0001 2015-02-12 18:41:26 +11:00
parent 0bb4afbd9a
commit 643d907792
4 changed files with 46 additions and 36 deletions

View File

@ -59,7 +59,7 @@ public class DebugExec extends SubCommand {
@Override @Override
public boolean execute(final Player player, final String... args) { 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", "trim-check-chunks", "trim-get-chunks"}); List<String> allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired", "seen", "trim-check"});
if (args.length > 0) { if (args.length > 0) {
String arg = args[0].toLowerCase(); String arg = args[0].toLowerCase();
switch (arg) { switch (arg) {
@ -133,7 +133,7 @@ public class DebugExec extends SubCommand {
} }
case "trim-check": { 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-check <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");
} }
@ -142,12 +142,12 @@ public class DebugExec extends SubCommand {
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]); return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
} }
final ArrayList<ChunkLoc> empty = new ArrayList<>(); final ArrayList<ChunkLoc> empty = new ArrayList<>();
Trim.getTrimRegions(empty, world, new Runnable() { boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
@Override @Override
public void run() { public void run() {
Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:"); Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
Trim.sendMessage(" - MCA #: " + empty.size()); Trim.sendMessage(" - MCA #: " + empty.size());
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 256) + " (max)"); Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
Trim.sendMessage("Exporting log for manual approval..."); Trim.sendMessage("Exporting log for manual approval...");
final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "trim.txt"); final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "trim.txt");
PrintWriter writer; PrintWriter writer;
@ -158,7 +158,7 @@ public class DebugExec extends SubCommand {
writer.println(worldname +"/region/r." + loc.x + "." + loc.z +".mca" ); writer.println(worldname +"/region/r." + loc.x + "." + loc.z +".mca" );
} }
writer.close(); writer.close();
Trim.sendMessage("File saved"); Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
Trim.sendMessage("File failed to save! :("); Trim.sendMessage("File failed to save! :(");
@ -169,7 +169,10 @@ public class DebugExec extends SubCommand {
Trim.sendMessage(" - Add 31 to each number to get the end position"); Trim.sendMessage(" - Add 31 to each number to get the end position");
} }
}); });
return true; if (!result) {
PlayerFunctions.sendMessage(null, "Trim task already started!");
}
return result;
} }
} }
} }

View File

@ -67,7 +67,7 @@ public class RegenAllRoads extends SubCommand {
PlotMain.sendConsoleSenderMessage("&cIf no schematic is set, the following will not do anything"); PlotMain.sendConsoleSenderMessage("&cIf no schematic is set, the following will not do anything");
PlotMain.sendConsoleSenderMessage("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic"); PlotMain.sendConsoleSenderMessage("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
PlotMain.sendConsoleSenderMessage("&6Potential chunks to update: &7"+ (chunks.size() * 256)); PlotMain.sendConsoleSenderMessage("&6Potential chunks to update: &7"+ (chunks.size() * 1024));
PlotMain.sendConsoleSenderMessage("&6Estimated time: &7"+ (chunks.size()) + " seconds"); PlotMain.sendConsoleSenderMessage("&6Estimated time: &7"+ (chunks.size()) + " seconds");
boolean result = hpm.scheduleRoadUpdate(world); boolean result = hpm.scheduleRoadUpdate(world);

View File

@ -29,10 +29,12 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -46,6 +48,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.ChunkManager; 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.PlotHelper;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
public class Trim extends SubCommand { public class Trim extends SubCommand {
@ -180,40 +183,42 @@ public class Trim extends SubCommand {
if (Trim.TASK) { if (Trim.TASK) {
return false; return false;
} }
final long startOld = System.currentTimeMillis();
sendMessage("Collecting region data..."); sendMessage("Collecting region data...");
final ArrayList<ChunkLoc> chunks = ChunkManager.getChunkChunks(world); final ArrayList<Plot> plots = new ArrayList<>();
plots.addAll(PlotMain.getPlots(world).values());
final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.getChunkChunks(world));
sendMessage(" - MCA #: " + chunks.size()); sendMessage(" - MCA #: " + chunks.size());
sendMessage(" - CHUNKS: " + (chunks.size() * 256) +" (max)"); sendMessage(" - CHUNKS: " + (chunks.size() * 1024) +" (max)");
sendMessage(" - TIME ESTIMATE: " + (chunks.size()/1200) +" minutes"); sendMessage(" - TIME ESTIMATE: " + (chunks.size()/1200) +" minutes");
Trim.TASK_ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() { Trim.TASK_ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() {
@Override @Override
public void run() { public void run() {
if (chunks.size() == 0) { long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 50) {
if (plots.size() == 0) {
empty.addAll(chunks);
System.out.print("DONE!");
Trim.TASK = false;
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
Bukkit.getScheduler().cancelTask(Trim.TASK_ID); Bukkit.getScheduler().cancelTask(Trim.TASK_ID);
return; return;
} }
ChunkLoc loc = chunks.get(0); Plot plot = plots.get(0);
int sx = loc.x << 5; plots.remove(0);
int sz = loc.z << 5; Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id);
Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
boolean delete = true; Location pos3 = new Location(world, pos1.getBlockX(), 64, pos2.getBlockZ());
Location pos4 = new Location(world, pos2.getBlockX(), 64, pos1.getBlockZ());
loop: chunks.remove(ChunkManager.getChunkChunk(pos1));
for (int x = sx; x < sx + 32; x++) { chunks.remove(ChunkManager.getChunkChunk(pos2));
for (int z = sz; z < sz + 32; z++) { chunks.remove(ChunkManager.getChunkChunk(pos3));
Chunk chunk = world.getChunkAt(x, z); chunks.remove(ChunkManager.getChunkChunk(pos4));
if (ChunkManager.hasPlot(world, chunk) != null) {
delete = false;
break loop;
} }
} }
} }, 20L, 20L);
if (delete) {
empty.add(loc);
}
}
}, 1L, 1L);
Trim.TASK = true; Trim.TASK = true;
return true; return true;
} }

View File

@ -34,15 +34,11 @@ import org.bukkit.block.Skull;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType; import org.bukkit.block.banner.PatternType;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -57,6 +53,12 @@ public class ChunkManager {
public static MutableInt index = new MutableInt(0); public static MutableInt index = new MutableInt(0);
public static HashMap<Integer, Integer> tasks = new HashMap<>(); public static HashMap<Integer, Integer> tasks = new HashMap<>();
public static ChunkLoc getChunkChunk(Location loc) {
int x = loc.getBlockX() >> 9;
int z = loc.getBlockZ() >> 9;
return new ChunkLoc(x, z);
}
public static ArrayList<ChunkLoc> getChunkChunks(World world) { public static ArrayList<ChunkLoc> getChunkChunks(World world) {
File[] regionFiles = new File(world.getName() + File.separator + "region").listFiles(); File[] regionFiles = new File(world.getName() + File.separator + "region").listFiles();
ArrayList<ChunkLoc> chunks = new ArrayList<>(); ArrayList<ChunkLoc> chunks = new ArrayList<>();