mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Added command to save a schematic.
This commit is contained in:
parent
1a9f10951d
commit
20554f7ed1
@ -69,6 +69,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_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"),
|
||||
|
@ -1078,6 +1078,7 @@ public class PlotMain extends JavaPlugin {
|
||||
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
|
||||
options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT);
|
||||
options.put("web.enabled", Web.ENABLED);
|
||||
options.put("web.directory", "/var/www");
|
||||
options.put("web.port", Web.PORT);
|
||||
options.put("metrics", true);
|
||||
options.put("debug", true);
|
||||
@ -1097,6 +1098,7 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
Web.ENABLED = config.getBoolean("web.enabled");
|
||||
Web.PORT = config.getInt("web.port");
|
||||
Web.PATH = config.getString("web.directory");
|
||||
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
|
||||
Settings.WORLDGUARD = config.getBoolean("worldguard.enabled");
|
||||
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding");
|
||||
|
@ -23,7 +23,7 @@ import java.util.zip.GZIPInputStream;
|
||||
*/
|
||||
public class SchematicHandler {
|
||||
|
||||
public boolean paste(Location location, Schematic schematic, Plot plot) {
|
||||
public static boolean paste(Location location, Schematic schematic, Plot plot) {
|
||||
if (schematic == null) {
|
||||
PlotMain.sendConsoleSenderMessage("Schematic == null :|");
|
||||
return false;
|
||||
@ -71,7 +71,7 @@ public class SchematicHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Schematic getSchematic(String name) {
|
||||
public static Schematic getSchematic(String name) {
|
||||
{
|
||||
File parent =
|
||||
new File(JavaPlugin.getPlugin(PlotMain.class).getDataFolder() + File.separator + "schematics");
|
||||
@ -163,7 +163,7 @@ public class SchematicHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public class Dimension {
|
||||
public static class Dimension {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
@ -193,7 +193,7 @@ public class SchematicHandler {
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public boolean save(CompoundTag tag, String path) {
|
||||
public static boolean save(CompoundTag tag, String path) {
|
||||
|
||||
if (tag==null) {
|
||||
PlotMain.sendConsoleSenderMessage("&cCannot save empty tag");
|
||||
@ -219,16 +219,16 @@ public class SchematicHandler {
|
||||
* @param plot
|
||||
* @return
|
||||
*/
|
||||
public CompoundTag getCompoundTag(World world, Plot plot) {
|
||||
public static CompoundTag getCompoundTag(World world, PlotId id) {
|
||||
|
||||
if (!PlotMain.getPlots(world).containsKey(plot.id)) {
|
||||
if (!PlotMain.getPlots(world).containsKey(id)) {
|
||||
return null;
|
||||
// Plot is empty
|
||||
}
|
||||
|
||||
// loading chunks
|
||||
final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
|
||||
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
|
||||
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) {
|
||||
Chunk chunk = world.getChunkAt(i, j);
|
||||
@ -268,19 +268,19 @@ public class SchematicHandler {
|
||||
|
||||
Block block = world.getBlockAt(new Location(world, pos1.getBlockX() + x, 0 + y, pos1.getBlockZ() + z));
|
||||
|
||||
int id = block.getTypeId();
|
||||
int id2 = block.getTypeId();
|
||||
|
||||
if (id > 255) {
|
||||
if (id2 > 255) {
|
||||
if (addBlocks == null) {
|
||||
addBlocks = new byte[(blocks.length >> 1) + 1];
|
||||
}
|
||||
|
||||
addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
|
||||
addBlocks[index >> 1] & 0xF0 | (id >> 8) & 0xF
|
||||
: addBlocks[index >> 1] & 0xF | ((id >> 8) & 0xF) << 4);
|
||||
addBlocks[index >> 1] & 0xF0 | (id2 >> 8) & 0xF
|
||||
: addBlocks[index >> 1] & 0xF | ((id2 >> 8) & 0xF) << 4);
|
||||
}
|
||||
|
||||
blocks[index] = (byte) id;
|
||||
blocks[index] = (byte) id2;
|
||||
blockData[index] = (byte) block.getData();
|
||||
|
||||
|
||||
@ -300,7 +300,7 @@ public class SchematicHandler {
|
||||
return schematicTag;
|
||||
}
|
||||
|
||||
public class DataCollection {
|
||||
public static class DataCollection {
|
||||
private short block;
|
||||
private byte data;
|
||||
|
||||
|
@ -73,6 +73,7 @@ public class Settings {
|
||||
public static class Web {
|
||||
public static boolean ENABLED = false;
|
||||
public static int PORT = 9000;
|
||||
public static String PATH = "/var/www";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,12 +1,19 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.C;
|
||||
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.Plot;
|
||||
import com.intellectualcrafters.plot.PlotHelper;
|
||||
import com.intellectualcrafters.plot.PlotId;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
|
||||
public class Schematic extends SubCommand {
|
||||
|
||||
@ -17,12 +24,12 @@ public class Schematic extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player plr, String... args) {
|
||||
public boolean execute(final Player plr, String... args) {
|
||||
if (args.length < 1) {
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
return true;
|
||||
}
|
||||
String arg = args[0];
|
||||
String arg = args[0].toLowerCase();
|
||||
String file;
|
||||
SchematicHandler.Schematic schematic;
|
||||
switch (arg) {
|
||||
@ -69,6 +76,66 @@ public class Schematic extends SubCommand {
|
||||
}
|
||||
sendMessage(plr, C.SCHEMATIC_VALID);
|
||||
break;
|
||||
case "save":
|
||||
final PlotId i;
|
||||
final String world;
|
||||
if (plr!=null) {
|
||||
if(!PlayerFunctions.isInPlot(plr)) {
|
||||
sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
Plot myplot = PlayerFunctions.getCurrentPlot(plr);
|
||||
if(!myplot.hasRights(plr)) {
|
||||
sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
i = myplot.id;
|
||||
world = plr.getWorld().getName();
|
||||
}
|
||||
else {
|
||||
if (args.length==3) {
|
||||
try {
|
||||
world = args[0];
|
||||
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>");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CompoundTag schematic = SchematicHandler.getCompoundTag(Bukkit.getWorld(world), i);
|
||||
if (schematic==null) {
|
||||
PlayerFunctions.sendMessage(plr, "&cInvalid plot");
|
||||
return;
|
||||
}
|
||||
boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+i.x+"-"+i.y+"-"+world+".schematic");
|
||||
|
||||
if (!result) {
|
||||
PlayerFunctions.sendMessage(plr, "&cFailed to save schematic");
|
||||
return;
|
||||
}
|
||||
PlayerFunctions.sendMessage(plr, "&aSuccessfully saved schematic!");
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
default:
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
break;
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: PlotSquared
|
||||
main: com.intellectualcrafters.plot.PlotMain
|
||||
version: 2.1.1
|
||||
version: 2.1.2
|
||||
load: STARTUP
|
||||
description: >
|
||||
Easy, yet powerful Plot World generation and management.
|
||||
|
Loading…
Reference in New Issue
Block a user