mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 16:46:45 +01:00
schematic
This commit is contained in:
parent
42a95860ae
commit
70ff6d87c8
@ -146,7 +146,7 @@ public class DebugExec extends SubCommand {
|
|||||||
Trim.sendMessage(" - MCA #: " + empty.size());
|
Trim.sendMessage(" - MCA #: " + empty.size());
|
||||||
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
|
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
|
||||||
Trim.sendMessage("Exporting log for manual approval...");
|
Trim.sendMessage("Exporting log for manual approval...");
|
||||||
final File file = new File(PlotSquared.getMain().getDirectory() + File.separator + "trim.txt");
|
final File file = new File(PlotSquared.IMP.getDirectory() + File.separator + "trim.txt");
|
||||||
PrintWriter writer;
|
PrintWriter writer;
|
||||||
try {
|
try {
|
||||||
writer = new PrintWriter(file);
|
writer = new PrintWriter(file);
|
||||||
|
@ -145,7 +145,7 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
|||||||
CompoundTag sideroad = SchematicHandler.getCompoundTag(world, pos1, pos2);
|
CompoundTag sideroad = SchematicHandler.getCompoundTag(world, pos1, pos2);
|
||||||
CompoundTag intersection = SchematicHandler.getCompoundTag(world, pos3, pos4);
|
CompoundTag intersection = SchematicHandler.getCompoundTag(world, pos3, pos4);
|
||||||
|
|
||||||
String dir = PlotSquared.getMain().getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator;
|
String dir = PlotSquared.IMP.getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator;
|
||||||
|
|
||||||
SchematicHandler.save(sideroad, dir + "sideroad.schematic");
|
SchematicHandler.save(sideroad, dir + "sideroad.schematic");
|
||||||
SchematicHandler.save(intersection, dir + "intersection.schematic");
|
SchematicHandler.save(intersection, dir + "intersection.schematic");
|
||||||
|
@ -50,6 +50,7 @@ import com.intellectualcrafters.plot.PlotSquared;
|
|||||||
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.util.bukkit.BukkitUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schematic Handler
|
* Schematic Handler
|
||||||
@ -83,40 +84,38 @@ public class SchematicHandler {
|
|||||||
|
|
||||||
Location l1 = PlotHelper.getPlotBottomLoc(plot.world, plot.getId());
|
Location l1 = PlotHelper.getPlotBottomLoc(plot.world, plot.getId());
|
||||||
|
|
||||||
final int sy = location.getWorld().getHighestBlockYAt(l1.getX() + 1, l1.getZ() + 1);
|
final int sy = BukkitUtil.getHeighestBlock(location.getWorld(), l1.getX() + 1, l1.getZ() + 1);
|
||||||
|
|
||||||
l1 = l1.add(1, sy - 1, 1);
|
l1 = l1.add(1, sy - 1, 1);
|
||||||
|
|
||||||
final World world = location.getWorld();
|
|
||||||
|
|
||||||
int y_offset;
|
int y_offset;
|
||||||
if (HEIGHT == location.getWorld().getMaxHeight()) {
|
if (HEIGHT == BukkitUtil.getMaxHeight(location.getWorld())) {
|
||||||
y_offset = 0;
|
y_offset = 0;
|
||||||
} else {
|
} else {
|
||||||
y_offset = l1.getY();
|
y_offset = l1.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int[] xl = new int[blocks.length];
|
||||||
|
int[] yl = new int[blocks.length];
|
||||||
|
int[] zl = new int[blocks.length];
|
||||||
|
int[] ids = new int[blocks.length];
|
||||||
|
byte[] data = new byte[blocks.length];
|
||||||
|
|
||||||
for (int x = 0; x < WIDTH; x++) {
|
for (int x = 0; x < WIDTH; x++) {
|
||||||
for (int z = 0; z < LENGTH; z++) {
|
for (int z = 0; z < LENGTH; z++) {
|
||||||
for (int y = 0; y < HEIGHT; y++) {
|
for (int y = 0; y < HEIGHT; y++) {
|
||||||
final int index = (y * WIDTH * LENGTH) + (z * WIDTH) + x;
|
final int index = (y * WIDTH * LENGTH) + (z * WIDTH) + x;
|
||||||
|
|
||||||
final DataCollection block = blocks[index];
|
final DataCollection block = blocks[index];
|
||||||
|
xl[index] = x;
|
||||||
|
yl[index] = y;
|
||||||
|
zl[index] = z;
|
||||||
|
ids[index] = block.block;
|
||||||
|
data[index] = block.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BlockManager.setBlocks(plot.world, xl, yl, zl, ids, data);
|
||||||
|
|
||||||
final short id = block.getBlock();
|
|
||||||
final byte data = block.getData();
|
|
||||||
|
|
||||||
// if (block.tag != null) {
|
|
||||||
// WorldEditUtils.setNBT(world, id, data, l1.getX()
|
|
||||||
// + x + x_offset, y + y_offset, l1.getZ() + z +
|
|
||||||
// z_offset, block.tag);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
PlotHelper.setBlock(world, l1.getX() + x + x_offset, y + y_offset, l1.getZ() + z + z_offset, id, data);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -170,14 +169,14 @@ public class SchematicHandler {
|
|||||||
*/
|
*/
|
||||||
public static Schematic getSchematic(final String name) {
|
public static Schematic getSchematic(final String name) {
|
||||||
{
|
{
|
||||||
final File parent = new File(PlotSquared.getMain().getDirectory() + File.separator + "schematics");
|
final File parent = new File(PlotSquared.IMP.getDirectory() + File.separator + "schematics");
|
||||||
if (!parent.exists()) {
|
if (!parent.exists()) {
|
||||||
if (!parent.mkdir()) {
|
if (!parent.mkdir()) {
|
||||||
throw new RuntimeException("Could not create schematic parent directory");
|
throw new RuntimeException("Could not create schematic parent directory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final File file = new File(PlotSquared.getMain().getDirectory() + File.separator + "schematics" + File.separator + name + ".schematic");
|
final File file = new File(PlotSquared.IMP.getDirectory() + File.separator + "schematics" + File.separator + name + ".schematic");
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
PlotSquared.log(file.toString() + " doesn't exist");
|
PlotSquared.log(file.toString() + " doesn't exist");
|
||||||
return null;
|
return null;
|
||||||
@ -244,17 +243,14 @@ public class SchematicHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static CompoundTag getCompoundTag(final World world, Location pos1, Location pos2) {
|
public static CompoundTag getCompoundTag(final String world, Location pos1, Location pos2) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// loading chunks
|
// loading chunks
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
try {
|
try {
|
||||||
for (i = (pos1.getX() / 16) * 16; i < (16 + ((pos2.getX() / 16) * 16)); i += 16) {
|
for (i = (pos1.getX() / 16) * 16; i < (16 + ((pos2.getX() / 16) * 16)); i += 16) {
|
||||||
for (j = (pos1.getZ() / 16) * 16; j < (16 + ((pos2.getZ() / 16) * 16)); j += 16) {
|
for (j = (pos1.getZ() / 16) * 16; j < (16 + ((pos2.getZ() / 16) * 16)); j += 16) {
|
||||||
final Chunk chunk = world.getChunkAt(i, j);
|
final Chunk chunk = BukkitUtil.getChunkAt(world, i, j);
|
||||||
final boolean result = chunk.load(false);
|
final boolean result = chunk.load(false);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|
||||||
@ -301,8 +297,7 @@ public class SchematicHandler {
|
|||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
final int index = (y * width * length) + (z * width) + x;
|
final int index = (y * width * length) + (z * width) + x;
|
||||||
|
|
||||||
final Block block = world.getBlockAt(new Location(world, sx + x, sy + y, sz + z));
|
block = BukkitUtil.getBlock(new Location(world, sx + x, sy + y, sz + z));
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") final int id2 = block.getTypeId();
|
@SuppressWarnings("deprecation") final int id2 = block.getTypeId();
|
||||||
|
|
||||||
if (id2 > 255) {
|
if (id2 > 255) {
|
||||||
@ -335,17 +330,25 @@ public class SchematicHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean pastePart(final String world, final DataCollection[] blocks, final Location l1, final int x_offset, final int z_offset, final int i1, final int i2, final int WIDTH, final int LENGTH) {
|
public static boolean pastePart(final String world, final DataCollection[] blocks, final Location l1, final int x_offset, final int z_offset, final int i1, final int i2, final int WIDTH, final int LENGTH) {
|
||||||
int[] xl = new int[i2];
|
int length = 0;
|
||||||
int[] yl = new int[i2];
|
for (int i = i1; i <= i2; i++) {
|
||||||
int[] zl = new int[i2];
|
if (blocks[i].block == 0) {
|
||||||
int[] ids = new int[i2];
|
length++;
|
||||||
byte[] data = new byte[i2];
|
}
|
||||||
|
}
|
||||||
|
length = i2 - length;
|
||||||
|
int[] xl = new int[length];
|
||||||
|
int[] yl = new int[length];
|
||||||
|
int[] zl = new int[length];
|
||||||
|
int[] ids = new int[length];
|
||||||
|
byte[] data = new byte[length];
|
||||||
|
int count = 0;
|
||||||
for (int i = i1; i <= i2; i++) {
|
for (int i = i1; i <= i2; i++) {
|
||||||
final short id = blocks[i].block;
|
final short id = blocks[i].block;
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
count++;
|
||||||
|
|
||||||
final int area = WIDTH * LENGTH;
|
final int area = WIDTH * LENGTH;
|
||||||
final int r = i % (area);
|
final int r = i % (area);
|
||||||
@ -353,13 +356,12 @@ public class SchematicHandler {
|
|||||||
final int y = i / area;
|
final int y = i / area;
|
||||||
final int z = r / WIDTH;
|
final int z = r / WIDTH;
|
||||||
|
|
||||||
xl[i] = x;
|
xl[count] = x;
|
||||||
yl[i] = y;
|
yl[count] = y;
|
||||||
zl[i] = z;
|
zl[count] = z;
|
||||||
|
|
||||||
ids[i] = id;
|
|
||||||
data[i] = blocks[i].data;
|
|
||||||
|
|
||||||
|
ids[count] = id;
|
||||||
|
data[count] = blocks[i].data;
|
||||||
if (y > 256) {
|
if (y > 256) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.util.BlockManager;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
import com.intellectualcrafters.plot.util.SetBlockManager;
|
import com.intellectualcrafters.plot.util.SetBlockManager;
|
||||||
import com.intellectualcrafters.plot.util.SetBlockSlow;
|
import com.intellectualcrafters.plot.util.SetBlockSlow;
|
||||||
@ -37,6 +38,14 @@ public class BukkitUtil extends BlockManager {
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getMaxHeight(String world) {
|
||||||
|
return getWorld(world).getMaxHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getHeighestBlock(String world, int x, int z) {
|
||||||
|
return getWorld(world).getHighestBlockYAt(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
public static Chunk getChunkAt(String worldname, int x, int z) {
|
public static Chunk getChunkAt(String worldname, int x, int z) {
|
||||||
World world = getWorld(worldname);
|
World world = getWorld(worldname);
|
||||||
return world.getChunkAt(x, z);
|
return world.getChunkAt(x, z);
|
||||||
@ -77,6 +86,15 @@ public class BukkitUtil extends BlockManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PlotBlock getBlock(Location loc) {
|
||||||
|
World world = getWorld(loc.getWorld());
|
||||||
|
Block block = world.getBlockAt(loc.getX(), loc.getY(), loc.getZ());
|
||||||
|
if (block == null) {
|
||||||
|
return new PlotBlock((short) 0 , (byte) 0);
|
||||||
|
}
|
||||||
|
return new PlotBlock((short) block.getTypeId(), block.getData());
|
||||||
|
}
|
||||||
|
|
||||||
public static Location getLocation(Entity entity) {
|
public static Location getLocation(Entity entity) {
|
||||||
org.bukkit.Location loc = entity.getLocation();
|
org.bukkit.Location loc = entity.getLocation();
|
||||||
String world = loc.getWorld().getName();
|
String world = loc.getWorld().getName();
|
||||||
|
Loading…
Reference in New Issue
Block a user