mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
World template exporting
This commit is contained in:
parent
fe9e4b7c51
commit
a63bcbba1a
@ -61,10 +61,6 @@
|
||||
<id>sk80q</id>
|
||||
<url>http://maven.sk89q.com/artifactory/repo/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -40,7 +40,7 @@ public class MainCommand {
|
||||
/**
|
||||
* 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>() {
|
||||
{
|
||||
addAll(Arrays.asList(_subCommands));
|
||||
|
@ -20,13 +20,22 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
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.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.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
@ -34,7 +43,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Template extends SubCommand {
|
||||
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
|
||||
@ -49,6 +58,7 @@ public class Template extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "import": {
|
||||
// TODO import template
|
||||
@ -56,28 +66,63 @@ public class Template extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
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 created based on these packaged files
|
||||
return true;
|
||||
}
|
||||
|
||||
public static byte[] getBytes(PlotWorld plotworld) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
ConfigurationSection section = config.getConfigurationSection("");
|
||||
plotworld.saveConfiguration(section);
|
||||
return config.saveToString().getBytes();
|
||||
}
|
||||
|
||||
public void gzipIt(final String output, final String input) {
|
||||
final byte[] buffer = new byte[1024];
|
||||
public static boolean zip(final String world, final byte[] bytes, String location, File output) {
|
||||
try {
|
||||
final GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(output));
|
||||
final FileInputStream in = new FileInputStream(input);
|
||||
int len;
|
||||
while ((len = in.read(buffer)) > 0) {
|
||||
gzos.write(buffer, 0, len);
|
||||
}
|
||||
in.close();
|
||||
gzos.finish();
|
||||
gzos.close();
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,9 +90,6 @@ public class HybridGen extends PlotGenerator {
|
||||
if (this.plotworld == null) {
|
||||
this.plotworld = (HybridPlotWorld) plotworld;
|
||||
}
|
||||
|
||||
System.out.print("INITIALIZING ===================================");
|
||||
|
||||
this.plotsize = this.plotworld.PLOT_WIDTH;
|
||||
this.pathsize = this.plotworld.ROAD_WIDTH;
|
||||
this.roadblock = this.plotworld.ROAD_BLOCK.id;
|
||||
@ -238,7 +235,6 @@ public class HybridGen extends PlotGenerator {
|
||||
h = (prime * h) + cz;
|
||||
this.state = h;
|
||||
}
|
||||
System.out.print(this.maxY);
|
||||
this.result = new short[this.maxY / 16][];
|
||||
if (this.plotworld.PLOT_BEDROCK) {
|
||||
for (short x = 0; x < 16; x++) {
|
||||
|
@ -20,6 +20,10 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
@ -31,6 +35,15 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
@SuppressWarnings("deprecation")
|
||||
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
|
||||
* function, as it is fast, and uses NMS code - It also makes use of the fact that deleting chunks is a lot faster
|
||||
|
@ -345,8 +345,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public static void onWorldChanged(final PlayerChangedWorldEvent event) {
|
||||
final PlotPlayer player = BukkitUtil.getPlayer(event.getPlayer());
|
||||
((BukkitPlayer) player).hasPerm = null;
|
||||
((BukkitPlayer) player).noPerm = null;
|
||||
((BukkitPlayer) player).hasPerm = new HashSet<>();
|
||||
((BukkitPlayer) player).noPerm = new HashSet<>();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
|
@ -192,6 +192,9 @@ public class WorldEditListener implements Listener {
|
||||
return;
|
||||
}
|
||||
final Location f = e.getFrom();
|
||||
if ((f.getX() == t.getX()) && (f.getZ() == t.getZ())) {
|
||||
return;
|
||||
}
|
||||
final Player p = e.getPlayer();
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(p);
|
||||
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
|
||||
|
@ -13,8 +13,8 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
public final Player player;
|
||||
UUID uuid;
|
||||
String name;
|
||||
public HashSet<String> hasPerm;
|
||||
public HashSet<String> noPerm;
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> noPerm = new HashSet<>();
|
||||
private int op = 0;
|
||||
|
||||
/**
|
||||
|
@ -20,8 +20,12 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.commands.Template;
|
||||
|
||||
public abstract class PlotManager {
|
||||
/*
|
||||
* 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 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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user