mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 05:36:45 +01:00
Simplified mass schematic export
This commit is contained in:
parent
be8db522fd
commit
e239a49be1
@ -20,8 +20,10 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
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 com.intellectualcrafters.jnbt.CompoundTag;
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||||
import com.intellectualcrafters.plot.PlotSquared;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
@ -45,7 +47,6 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
|||||||
public class SchematicCmd extends SubCommand {
|
public class SchematicCmd extends SubCommand {
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
private Plot[] plots;
|
|
||||||
private int task;
|
private int task;
|
||||||
|
|
||||||
public SchematicCmd() {
|
public SchematicCmd() {
|
||||||
@ -196,52 +197,24 @@ public class SchematicCmd extends SubCommand {
|
|||||||
}
|
}
|
||||||
final HashMap<PlotId, Plot> plotmap = PlotSquared.getPlots(args[1]);
|
final HashMap<PlotId, Plot> plotmap = PlotSquared.getPlots(args[1]);
|
||||||
if ((plotmap == null) || (plotmap.size() == 0)) {
|
if ((plotmap == null) || (plotmap.size() == 0)) {
|
||||||
MainUtil.sendMessage(null, "&cInvalid world. Use &7/plots sch exportall <world>");
|
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.running) {
|
Collection<Plot> plots = plotmap.values();
|
||||||
MainUtil.sendMessage(null, "&cTask is already running.");
|
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
|
||||||
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots...");
|
|
||||||
final String worldname = args[1];
|
|
||||||
final Collection<Plot> values = plotmap.values();
|
|
||||||
this.plots = values.toArray(new Plot[values.size()]);
|
|
||||||
this.running = true;
|
|
||||||
this.counter = 0;
|
|
||||||
this.task = TaskManager.runTaskRepeat(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (SchematicCmd.this.counter >= SchematicCmd.this.plots.length) {
|
MainUtil.sendMessage(plr, "&aFinished mass export");
|
||||||
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
|
|
||||||
SchematicCmd.this.running = false;
|
|
||||||
PlotSquared.TASK.cancelTask(SchematicCmd.this.task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Plot plot = SchematicCmd.this.plots[SchematicCmd.this.counter];
|
|
||||||
final CompoundTag sch = SchematicHandler.manager.getCompoundTag(worldname, plot.id);
|
|
||||||
final String o = UUIDHandler.getName(plot.owner);
|
|
||||||
final String owner = o == null ? "unknown" : o;
|
|
||||||
if (sch == null) {
|
|
||||||
MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
|
|
||||||
} else {
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MainUtil.sendMessage(null, "&6ID: " + plot.id);
|
|
||||||
final boolean result = SchematicHandler.manager.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic");
|
|
||||||
if (!result) {
|
|
||||||
MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id);
|
|
||||||
} else {
|
|
||||||
MainUtil.sendMessage(null, "&7 - &a success: " + plot.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!result) {
|
||||||
|
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
SchematicCmd.this.counter++;
|
else {
|
||||||
|
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
||||||
|
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots...");
|
||||||
}
|
}
|
||||||
}, 20);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "export":
|
case "export":
|
||||||
@ -288,41 +261,22 @@ public class SchematicCmd extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.plots = new Plot[] { p2 };
|
|
||||||
this.running = true;
|
Collection<Plot> plots = new ArrayList<Plot>();
|
||||||
this.counter = 0;
|
plots.add(p2);
|
||||||
this.task = TaskManager.runTaskRepeat(new Runnable() {
|
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (SchematicCmd.this.counter >= SchematicCmd.this.plots.length) {
|
MainUtil.sendMessage(plr, "&aFinished export");
|
||||||
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
|
|
||||||
SchematicCmd.this.running = false;
|
|
||||||
PlotSquared.TASK.cancelTask(SchematicCmd.this.task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Plot plot = SchematicCmd.this.plots[SchematicCmd.this.counter];
|
|
||||||
final CompoundTag sch = SchematicHandler.manager.getCompoundTag(world, plot.id);
|
|
||||||
final String o = UUIDHandler.getName(plot.owner);
|
|
||||||
final String owner = o == null ? "unknown" : o;
|
|
||||||
if (sch == null) {
|
|
||||||
MainUtil.sendMessage(plr, "&7 - Skipped plot &c" + plot.id);
|
|
||||||
} else {
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MainUtil.sendMessage(plr, "&6ID: " + plot.id);
|
|
||||||
final boolean result = SchematicHandler.manager.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + world + "," + owner.trim() + ".schematic");
|
|
||||||
if (!result) {
|
|
||||||
MainUtil.sendMessage(plr, "&7 - Failed to save &c" + plot.id);
|
|
||||||
} else {
|
|
||||||
MainUtil.sendMessage(plr, "&7 - &aExport success: " + plot.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!result) {
|
||||||
|
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
SchematicCmd.this.counter++;
|
else {
|
||||||
|
MainUtil.sendMessage(plr, "&7Starting export...");
|
||||||
}
|
}
|
||||||
}, 60);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -6,12 +6,16 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import com.intellectualcrafters.jnbt.ByteArrayTag;
|
import com.intellectualcrafters.jnbt.ByteArrayTag;
|
||||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||||
import com.intellectualcrafters.jnbt.IntTag;
|
import com.intellectualcrafters.jnbt.IntTag;
|
||||||
@ -21,16 +25,84 @@ import com.intellectualcrafters.jnbt.NBTOutputStream;
|
|||||||
import com.intellectualcrafters.jnbt.ShortTag;
|
import com.intellectualcrafters.jnbt.ShortTag;
|
||||||
import com.intellectualcrafters.jnbt.Tag;
|
import com.intellectualcrafters.jnbt.Tag;
|
||||||
import com.intellectualcrafters.plot.PlotSquared;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
|
import com.intellectualcrafters.plot.commands.SchematicCmd;
|
||||||
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
||||||
import com.intellectualcrafters.plot.object.schematic.StateWrapper;
|
import com.intellectualcrafters.plot.object.schematic.StateWrapper;
|
||||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
public abstract class SchematicHandler {
|
public abstract class SchematicHandler {
|
||||||
public static SchematicHandler manager = new BukkitSchematicHandler();
|
public static SchematicHandler manager = new BukkitSchematicHandler();
|
||||||
|
|
||||||
|
private boolean exportAll = false;
|
||||||
|
|
||||||
|
public boolean exportAll(final Collection<Plot> plots, final File outputDir, final String namingScheme, final Runnable ifSuccess) {
|
||||||
|
if (exportAll) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (plots.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
exportAll = true;
|
||||||
|
TaskManager.index.increment();
|
||||||
|
final Integer currentIndex = TaskManager.index.toInteger();
|
||||||
|
final int task = TaskManager.runTaskRepeat(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (plots.size() == 0) {
|
||||||
|
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||||
|
TaskManager.tasks.remove(currentIndex);
|
||||||
|
TaskManager.runTask(ifSuccess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Iterator<Plot> i = plots.iterator();
|
||||||
|
final Plot plot = i.next();
|
||||||
|
i.remove();
|
||||||
|
final CompoundTag sch = SchematicHandler.manager.getCompoundTag(plot.world, plot.id);
|
||||||
|
String o = UUIDHandler.getName(plot.owner);
|
||||||
|
if (o == null) {
|
||||||
|
o = "unknown";
|
||||||
|
}
|
||||||
|
final String name;
|
||||||
|
if (namingScheme == null) {
|
||||||
|
name = plot.id.x + ";" + plot.id.y + "," + plot.world + "," + o;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = namingScheme.replaceAll("%owner%", o).replaceAll("%id%", plot.id.toString()).replaceAll("%idx%", plot.id.x + "").replaceAll("%idy%", plot.id.y + "").replaceAll("%world%", plot.world);
|
||||||
|
}
|
||||||
|
final String directory;
|
||||||
|
if (outputDir == null) {
|
||||||
|
directory = Settings.SCHEMATIC_SAVE_PATH;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
directory = outputDir.getPath();
|
||||||
|
}
|
||||||
|
if (sch == null) {
|
||||||
|
MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
|
||||||
|
} else {
|
||||||
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainUtil.sendMessage(null, "&6ID: " + plot.id);
|
||||||
|
final boolean result = SchematicHandler.manager.save(sch, directory + File.separator + name + ".schematic");
|
||||||
|
if (!result) {
|
||||||
|
MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id);
|
||||||
|
} else {
|
||||||
|
MainUtil.sendMessage(null, "&7 - &a success: " + plot.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 20);
|
||||||
|
TaskManager.tasks.put(currentIndex, task);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paste a schematic
|
* Paste a schematic
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user