World template exporting

This commit is contained in:
boy0001 2015-02-25 18:50:17 +11:00
parent fe9e4b7c51
commit a63bcbba1a
9 changed files with 89 additions and 26 deletions

View File

@ -61,10 +61,6 @@
<id>sk80q</id> <id>sk80q</id>
<url>http://maven.sk89q.com/artifactory/repo/</url> <url>http://maven.sk89q.com/artifactory/repo/</url>
</repository> </repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -40,7 +40,7 @@ public class MainCommand {
/** /**
* Main Permission Node * Main Permission Node
*/ */
private final static SubCommand[] _subCommands = new SubCommand[] { new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense() }; private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense() };
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() { public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{ {
addAll(Arrays.asList(_subCommands)); addAll(Arrays.asList(_subCommands));

View File

@ -20,13 +20,22 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Set;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
@ -34,7 +43,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
public class Template extends SubCommand { public class Template extends SubCommand {
public Template() { public Template() {
super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, true); super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, false);
} }
@Override @Override
@ -49,6 +58,7 @@ public class Template extends SubCommand {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false; return false;
} }
PlotManager manager = PlotSquared.getPlotManager(world);
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "import": { case "import": {
// TODO import template // TODO import template
@ -56,7 +66,8 @@ public class Template extends SubCommand {
return true; return true;
} }
case "export": { case "export": {
MainUtil.sendMessage(plr, "TODO"); manager.export(plotworld);
MainUtil.sendMessage(plr, "Done!");
} }
} }
// TODO allow world settings (including schematics to be packed into a single file) // TODO allow world settings (including schematics to be packed into a single file)
@ -64,20 +75,54 @@ public class Template extends SubCommand {
return true; return true;
} }
public void gzipIt(final String output, final String input) { public static byte[] getBytes(PlotWorld plotworld) {
final byte[] buffer = new byte[1024]; YamlConfiguration config = new YamlConfiguration();
try { ConfigurationSection section = config.getConfigurationSection("");
final GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(output)); plotworld.saveConfiguration(section);
final FileInputStream in = new FileInputStream(input); return config.saveToString().getBytes();
int len;
while ((len = in.read(buffer)) > 0) {
gzos.write(buffer, 0, len);
} }
in.close();
gzos.finish(); public static boolean zip(final String world, final byte[] bytes, String location, File output) {
gzos.close(); try {
output.mkdirs();
FileOutputStream fos = new FileOutputStream(output + File.separator + world + ".template");
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry ze = new ZipEntry(location);
zos.putNextEntry(ze);
zos.write(bytes);
zos.closeEntry();
zos.close();
return true;
} catch (final IOException ex) { } catch (final IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
return false;
}
}
public static boolean zip(final String world, final File file, File output) {
if (!file.exists()) {
System.out.print("NOT EXIST: " + file);
return false;
}
byte[] buffer = new byte[1024];
try {
output.mkdirs();
FileOutputStream fos = new FileOutputStream(output + File.separator + world + ".template");
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry ze= new ZipEntry(file.getPath());
zos.putNextEntry(ze);
FileInputStream in = new FileInputStream(file.getPath());
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
zos.closeEntry();
zos.close();
return true;
} catch (final IOException ex) {
ex.printStackTrace();
return false;
} }
} }
} }

View File

@ -90,9 +90,6 @@ public class HybridGen extends PlotGenerator {
if (this.plotworld == null) { if (this.plotworld == null) {
this.plotworld = (HybridPlotWorld) plotworld; this.plotworld = (HybridPlotWorld) plotworld;
} }
System.out.print("INITIALIZING ===================================");
this.plotsize = this.plotworld.PLOT_WIDTH; this.plotsize = this.plotworld.PLOT_WIDTH;
this.pathsize = this.plotworld.ROAD_WIDTH; this.pathsize = this.plotworld.ROAD_WIDTH;
this.roadblock = this.plotworld.ROAD_BLOCK.id; this.roadblock = this.plotworld.ROAD_BLOCK.id;
@ -238,7 +235,6 @@ public class HybridGen extends PlotGenerator {
h = (prime * h) + cz; h = (prime * h) + cz;
this.state = h; this.state = h;
} }
System.out.print(this.maxY);
this.result = new short[this.maxY / 16][]; this.result = new short[this.maxY / 16][];
if (this.plotworld.PLOT_BEDROCK) { if (this.plotworld.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) { for (short x = 0; x < 16; x++) {

View File

@ -20,6 +20,10 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.io.File;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.Template;
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.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
@ -31,6 +35,15 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class HybridPlotManager extends ClassicPlotManager { public class HybridPlotManager extends ClassicPlotManager {
@Override
public void export(PlotWorld plotworld) {
super.export(plotworld);
String directory = PlotSquared.IMP.getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotworld.worldname + File.separator;
Template.zip(plotworld.worldname, new File(directory + "sideroad.schematic"), new File(PlotSquared.IMP.getDirectory() + File.separator + "templates"));
Template.zip(plotworld.worldname, new File(directory + "intersection.schematic"), new File(PlotSquared.IMP.getDirectory() + File.separator + "templates"));
Template.zip(plotworld.worldname, new File(directory + "plot.schematic"), new File(PlotSquared.IMP.getDirectory() + File.separator + "templates"));
}
/** /**
* Clearing the plot needs to only consider removing the blocks - This implementation has used the SetCuboid * Clearing the plot needs to only consider removing the blocks - This implementation has used the SetCuboid
* function, as it is fast, and uses NMS code - It also makes use of the fact that deleting chunks is a lot faster * function, as it is fast, and uses NMS code - It also makes use of the fact that deleting chunks is a lot faster

View File

@ -345,8 +345,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onWorldChanged(final PlayerChangedWorldEvent event) { public static void onWorldChanged(final PlayerChangedWorldEvent event) {
final PlotPlayer player = BukkitUtil.getPlayer(event.getPlayer()); final PlotPlayer player = BukkitUtil.getPlayer(event.getPlayer());
((BukkitPlayer) player).hasPerm = null; ((BukkitPlayer) player).hasPerm = new HashSet<>();
((BukkitPlayer) player).noPerm = null; ((BukkitPlayer) player).noPerm = new HashSet<>();
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)

View File

@ -192,6 +192,9 @@ public class WorldEditListener implements Listener {
return; return;
} }
final Location f = e.getFrom(); final Location f = e.getFrom();
if ((f.getX() == t.getX()) && (f.getZ() == t.getZ())) {
return;
}
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p); final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {

View File

@ -13,8 +13,8 @@ public class BukkitPlayer implements PlotPlayer {
public final Player player; public final Player player;
UUID uuid; UUID uuid;
String name; String name;
public HashSet<String> hasPerm; public HashSet<String> hasPerm = new HashSet<>();
public HashSet<String> noPerm; public HashSet<String> noPerm = new HashSet<>();
private int op = 0; private int op = 0;
/** /**

View File

@ -20,8 +20,12 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.Template;
public abstract class PlotManager { public abstract class PlotManager {
/* /*
* Plot locations (methods with Abs in them will not need to consider mega * Plot locations (methods with Abs in them will not need to consider mega
@ -81,4 +85,10 @@ public abstract class PlotManager {
public abstract boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds); public abstract boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds); public abstract boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public void export(PlotWorld plotworld) {
byte[] bytes = Template.getBytes(plotworld);
Template.zip(plotworld.worldname, bytes, "settings.yml", new File(PlotSquared.IMP.getDirectory() + File.separator + "templates"));
}
} }