mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 12:06:15 +01:00
Fixed exportall command (spigot would attempt to restart because of lag)
This commit is contained in:
parent
760921a43b
commit
ed3003a2f6
@ -68,8 +68,7 @@ public enum C {
|
||||
/*
|
||||
* Schematic Stuff
|
||||
*/
|
||||
SCHEMATIC_MISSING_ARG("&cYou need to specify an argument. Possible values: &6test <name>"),
|
||||
SCHEMATIC_MISSING_ARG2("&cYou need to specify an argument. Possible values: &6save"),
|
||||
SCHEMATIC_MISSING_ARG("&cYou need to specify an argument. Possible values: &6test <name>&7 , &6save&7 , &6paste &7, &6exportall"),
|
||||
SCHEMATIC_INVALID("&cThat is not a valid schematic. Reason: &c%s"),
|
||||
SCHEMATIC_VALID("&cThat is a valid schematic"),
|
||||
SCHEMATIC_PASTE_FAILED("&cFailed to paste the schematic"),
|
||||
|
@ -229,8 +229,11 @@ public class SchematicHandler {
|
||||
// loading chunks
|
||||
final Location pos1 = PlotHelper.getPlotBottomLoc(world, id).add(1, 0, 1);
|
||||
final Location pos2 = PlotHelper.getPlotTopLoc(world, id);
|
||||
for (int i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) {
|
||||
for (int j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
try {
|
||||
for (i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) {
|
||||
for (j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) {
|
||||
Chunk chunk = world.getChunkAt(i, j);
|
||||
boolean result = chunk.load(false);
|
||||
if (!result) {
|
||||
@ -241,6 +244,11 @@ public class SchematicHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
PlotMain.sendConsoleSenderMessage("&7 - Cannot save: corrupt chunk at "+(i/16)+", "+(j/16));
|
||||
return null;
|
||||
}
|
||||
int width = pos2.getBlockX()-pos1.getBlockX();
|
||||
int height = 256;
|
||||
int length = pos2.getBlockZ()-pos1.getBlockZ();
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.C;
|
||||
@ -22,11 +24,19 @@ import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore;
|
||||
public class Schematic extends SubCommand {
|
||||
|
||||
public Schematic() {
|
||||
super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, true);
|
||||
super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false);
|
||||
|
||||
// TODO command to fetch schematic from worldedit directory
|
||||
}
|
||||
|
||||
private int counter = 0;
|
||||
private boolean running = false;
|
||||
private Plot[] plots;
|
||||
private int task;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean execute(final Player plr, String... args) {
|
||||
if (args.length < 1) {
|
||||
@ -38,6 +48,10 @@ public class Schematic extends SubCommand {
|
||||
SchematicHandler.Schematic schematic;
|
||||
switch (arg) {
|
||||
case "paste":
|
||||
if (plr==null) {
|
||||
PlotMain.sendConsoleSenderMessage(C.IS_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (!PlotMain.hasPermission(plr, "plots.schematic.save")) {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste");
|
||||
return false;
|
||||
@ -51,8 +65,8 @@ public class Schematic extends SubCommand {
|
||||
break;
|
||||
}
|
||||
file = args[1];
|
||||
schematic = new SchematicHandler().getSchematic(file);
|
||||
boolean s = new SchematicHandler().paste(plr.getLocation(), schematic, PlayerFunctions.getCurrentPlot(plr));
|
||||
schematic = SchematicHandler.getSchematic(file);
|
||||
boolean s = SchematicHandler.paste(plr.getLocation(), schematic, PlayerFunctions.getCurrentPlot(plr));
|
||||
if (s) {
|
||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||
}
|
||||
@ -61,6 +75,10 @@ public class Schematic extends SubCommand {
|
||||
}
|
||||
break;
|
||||
case "test":
|
||||
if (plr==null) {
|
||||
PlotMain.sendConsoleSenderMessage(C.IS_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (!PlotMain.hasPermission(plr, "plots.schematic.save")) {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
|
||||
return false;
|
||||
@ -70,7 +88,7 @@ public class Schematic extends SubCommand {
|
||||
break;
|
||||
}
|
||||
file = args[1];
|
||||
schematic = new SchematicHandler().getSchematic(file);
|
||||
schematic = SchematicHandler.getSchematic(file);
|
||||
if (schematic == null) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
|
||||
break;
|
||||
@ -95,39 +113,65 @@ public class Schematic extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (args.length!=2) {
|
||||
PlayerFunctions.sendMessage(plr, "&cNeed world arg. Use &7/plots schem exportall <world>");
|
||||
PlayerFunctions.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
HashMap<PlotId, Plot> plotmap = PlotMain.getPlots(args[1]);
|
||||
if (plotmap==null || plotmap.size()==0) {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world. Use &7/plots schem exportall <world>");
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
if (running) {
|
||||
PlayerFunctions.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
|
||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Found &c"+plotmap.size()+"&7 plots...");
|
||||
final Collection<Plot> plots = plotmap.values();
|
||||
final World worldname = Bukkit.getWorld(args[1]);
|
||||
final World worldObj = Bukkit.getWorld(args[1]);
|
||||
final String worldname = Bukkit.getWorld(args[1]).getName();
|
||||
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared");
|
||||
|
||||
|
||||
this.plots = plotmap.values().toArray(new Plot[0]);
|
||||
this.running = true;
|
||||
this.counter = 0;
|
||||
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (counter>=plots.length) {
|
||||
PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
|
||||
Bukkit.getScheduler().cancelTask(task);
|
||||
return;
|
||||
}
|
||||
final Plot plot = plots[counter];
|
||||
final CompoundTag sch = SchematicHandler.getCompoundTag(worldObj, plot.id);
|
||||
if (sch==null) {
|
||||
PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c"+plot.id);
|
||||
}
|
||||
else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
for (Plot plot:plots) {
|
||||
CompoundTag schematic = SchematicHandler.getCompoundTag(worldname, plot.id);
|
||||
if (schematic==null) {
|
||||
PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c"+plot.id);
|
||||
return;
|
||||
}
|
||||
boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+plot.id.x+"-"+plot.id.y+"-"+worldname+".schematic");
|
||||
counter++;
|
||||
PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id);
|
||||
boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+".schematic");
|
||||
|
||||
if (!result) {
|
||||
PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
PlayerFunctions.sendMessage(plr, "&7 - &aExport success: "+plot.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}, 20, 20);
|
||||
break;
|
||||
case "export":
|
||||
case "save":
|
||||
if (!PlotMain.hasPermission(plr, "plots.schematic.save")) {
|
||||
@ -156,18 +200,18 @@ public class Schematic extends SubCommand {
|
||||
String[] split = args[2].split(";");
|
||||
i = new PlotId(Integer.parseInt(split[0]),Integer.parseInt(split[1]));
|
||||
if (PlotMain.getPlots(world)==null || PlotMain.getPlots(world).get(i) == null) {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save <world> <id>");
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save <world> <id>");
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save <world> <id>");
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -182,7 +226,7 @@ public class Schematic extends SubCommand {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid plot");
|
||||
return;
|
||||
}
|
||||
boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+i.x+"-"+i.y+"-"+world+".schematic");
|
||||
boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+i.x+","+i.y+","+world+".schematic");
|
||||
|
||||
if (!result) {
|
||||
PlayerFunctions.sendMessage(plr, "&cFailed to save schematic");
|
||||
@ -191,7 +235,6 @@ public class Schematic extends SubCommand {
|
||||
PlayerFunctions.sendMessage(plr, "&aSuccessfully saved schematic!");
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
default:
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
|
Loading…
Reference in New Issue
Block a user