mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
City is a nub
This commit is contained in:
parent
d09dbee3c7
commit
57c849cbaa
@ -17,6 +17,8 @@ import java.util.Map;
|
|||||||
public final class NBTInputStream implements Closeable {
|
public final class NBTInputStream implements Closeable {
|
||||||
private final DataInputStream is;
|
private final DataInputStream is;
|
||||||
|
|
||||||
|
private int count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@code NBTInputStream}, which will source its data from the specified input stream.
|
* Creates a new {@code NBTInputStream}, which will source its data from the specified input stream.
|
||||||
*
|
*
|
||||||
@ -36,7 +38,18 @@ public final class NBTInputStream implements Closeable {
|
|||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public Tag readTag() throws IOException {
|
public Tag readTag() throws IOException {
|
||||||
return readTag(0);
|
return readTag(0, Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads an NBT tag from the stream.
|
||||||
|
*
|
||||||
|
* @return The tag that was read.
|
||||||
|
*
|
||||||
|
* @throws IOException if an I/O error occurs.
|
||||||
|
*/
|
||||||
|
public Tag readTag(int maxDepth) throws IOException {
|
||||||
|
return readTag(0, maxDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,7 +61,9 @@ public final class NBTInputStream implements Closeable {
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private Tag readTag(final int depth) throws IOException {
|
private Tag readTag(final int depth, int maxDepth) throws IOException {
|
||||||
|
System.out.print("READING TAG!!!");
|
||||||
|
if ((count++) > maxDepth) throw new IOException("Exceeds max depth: " + count);
|
||||||
final int type = this.is.readByte() & 0xFF;
|
final int type = this.is.readByte() & 0xFF;
|
||||||
String name;
|
String name;
|
||||||
if (type != NBTConstants.TYPE_END) {
|
if (type != NBTConstants.TYPE_END) {
|
||||||
@ -59,7 +74,7 @@ public final class NBTInputStream implements Closeable {
|
|||||||
} else {
|
} else {
|
||||||
name = "";
|
name = "";
|
||||||
}
|
}
|
||||||
return readTagPayload(type, name, depth);
|
return readTagPayload(type, name, depth, maxDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +88,10 @@ public final class NBTInputStream implements Closeable {
|
|||||||
*
|
*
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
private Tag readTagPayload(final int type, final String name, final int depth) throws IOException {
|
private Tag readTagPayload(final int type, final String name, final int depth, int maxDepth) throws IOException {
|
||||||
|
if ((count++) > maxDepth) throw new IOException("Exceeds max depth: " + count);
|
||||||
|
count++;
|
||||||
|
System.out.print(count + " | " + type);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NBTConstants.TYPE_END:
|
case NBTConstants.TYPE_END:
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
@ -95,20 +113,35 @@ public final class NBTInputStream implements Closeable {
|
|||||||
return new DoubleTag(name, this.is.readDouble());
|
return new DoubleTag(name, this.is.readDouble());
|
||||||
case NBTConstants.TYPE_BYTE_ARRAY:
|
case NBTConstants.TYPE_BYTE_ARRAY:
|
||||||
int length = this.is.readInt();
|
int length = this.is.readInt();
|
||||||
|
|
||||||
|
// Max depth
|
||||||
|
if ((count += length) > maxDepth) throw new IOException("Exceeds max depth: " + count);
|
||||||
|
//
|
||||||
|
|
||||||
byte[] bytes = new byte[length];
|
byte[] bytes = new byte[length];
|
||||||
this.is.readFully(bytes);
|
this.is.readFully(bytes);
|
||||||
return new ByteArrayTag(name, bytes);
|
return new ByteArrayTag(name, bytes);
|
||||||
case NBTConstants.TYPE_STRING:
|
case NBTConstants.TYPE_STRING:
|
||||||
length = this.is.readShort();
|
length = this.is.readShort();
|
||||||
|
|
||||||
|
// Max depth
|
||||||
|
if ((count += length) > maxDepth) throw new IOException("Exceeds max depth: " + count);
|
||||||
|
//
|
||||||
|
|
||||||
bytes = new byte[length];
|
bytes = new byte[length];
|
||||||
this.is.readFully(bytes);
|
this.is.readFully(bytes);
|
||||||
return new StringTag(name, new String(bytes, NBTConstants.CHARSET));
|
return new StringTag(name, new String(bytes, NBTConstants.CHARSET));
|
||||||
case NBTConstants.TYPE_LIST:
|
case NBTConstants.TYPE_LIST:
|
||||||
final int childType = this.is.readByte();
|
final int childType = this.is.readByte();
|
||||||
length = this.is.readInt();
|
length = this.is.readInt();
|
||||||
|
|
||||||
|
// Max depth
|
||||||
|
if ((count += length) > maxDepth) throw new IOException("Exceeds max depth: " + count);
|
||||||
|
//
|
||||||
|
|
||||||
final List<Tag> tagList = new ArrayList<Tag>();
|
final List<Tag> tagList = new ArrayList<Tag>();
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
final Tag tag = readTagPayload(childType, "", depth + 1);
|
final Tag tag = readTagPayload(childType, "", depth + 1, maxDepth);
|
||||||
if (tag instanceof EndTag) {
|
if (tag instanceof EndTag) {
|
||||||
throw new IOException("TAG_End not permitted in a list.");
|
throw new IOException("TAG_End not permitted in a list.");
|
||||||
}
|
}
|
||||||
@ -118,7 +151,7 @@ public final class NBTInputStream implements Closeable {
|
|||||||
case NBTConstants.TYPE_COMPOUND:
|
case NBTConstants.TYPE_COMPOUND:
|
||||||
final Map<String, Tag> tagMap = new HashMap<String, Tag>();
|
final Map<String, Tag> tagMap = new HashMap<String, Tag>();
|
||||||
while (true) {
|
while (true) {
|
||||||
final Tag tag = readTag(depth + 1);
|
final Tag tag = readTag(depth + 1, maxDepth);
|
||||||
if (tag instanceof EndTag) {
|
if (tag instanceof EndTag) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -128,6 +161,9 @@ public final class NBTInputStream implements Closeable {
|
|||||||
return new CompoundTag(name, tagMap);
|
return new CompoundTag(name, tagMap);
|
||||||
case NBTConstants.TYPE_INT_ARRAY:
|
case NBTConstants.TYPE_INT_ARRAY:
|
||||||
length = this.is.readInt();
|
length = this.is.readInt();
|
||||||
|
// Max depth
|
||||||
|
if ((count += length) > maxDepth) throw new IOException("Exceeds max depth: " + count);
|
||||||
|
//
|
||||||
final int[] data = new int[length];
|
final int[] data = new int[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
data[i] = this.is.readInt();
|
data[i] = this.is.readInt();
|
||||||
|
@ -293,7 +293,6 @@ public class PS {
|
|||||||
if (!plots.containsKey(world)) {
|
if (!plots.containsKey(world)) {
|
||||||
plots.put(world, new HashMap<PlotId, Plot>());
|
plots.put(world, new HashMap<PlotId, Plot>());
|
||||||
}
|
}
|
||||||
plot.hasChanged = true;
|
|
||||||
plots.get(world).put(plot.id, plot);
|
plots.get(world).put(plot.id, plot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,6 @@ public class DebugClaimTest extends SubCommand {
|
|||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
|
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
|
||||||
plot.owner = uuid;
|
plot.owner = uuid;
|
||||||
plot.hasChanged = true;
|
|
||||||
plots.add(plot);
|
plots.add(plot);
|
||||||
} else {
|
} else {
|
||||||
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
||||||
|
@ -44,7 +44,7 @@ public class Download extends SubCommand {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
URL url = SchematicHandler.manager.upload(value);
|
URL url = SchematicHandler.manager.upload(value, null);
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
|
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
|
||||||
MainUtil.runners.remove(plot);
|
MainUtil.runners.remove(plot);
|
||||||
|
@ -20,12 +20,16 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
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;
|
||||||
@ -84,13 +88,30 @@ public class SchematicCmd extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String file2 = args[1];
|
final String location = args[1];
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final Schematic schematic = SchematicHandler.manager.getSchematic(file2);
|
Schematic schematic;
|
||||||
|
if (location.startsWith("url:")) {
|
||||||
|
try {
|
||||||
|
UUID uuid = UUID.fromString(location.substring(4));
|
||||||
|
URL base = new URL(Settings.WEB_URL);
|
||||||
|
URL url = new URL(base, "uploads/" + uuid + ".schematic");
|
||||||
|
schematic = SchematicHandler.manager.getSchematic(url);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent url: " + location);
|
||||||
|
SchematicCmd.this.running = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
schematic = SchematicHandler.manager.getSchematic(location);
|
||||||
|
}
|
||||||
if (schematic == null) {
|
if (schematic == null) {
|
||||||
SchematicCmd.this.running = false;
|
SchematicCmd.this.running = false;
|
||||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
||||||
|
@ -52,30 +52,37 @@ public class Plot {
|
|||||||
* plot owner
|
* plot owner
|
||||||
*/
|
*/
|
||||||
public UUID owner;
|
public UUID owner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of trusted (with plot permissions)
|
* List of trusted (with plot permissions)
|
||||||
|
* Direct access is Deprecated: use getTrusted()
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public HashSet<UUID> trusted;
|
public HashSet<UUID> trusted;
|
||||||
/**
|
/**
|
||||||
* List of members users (with plot permissions)
|
* List of members users (with plot permissions)
|
||||||
|
* Direct access is Deprecated: use getMembers()
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public HashSet<UUID> members;
|
public HashSet<UUID> members;
|
||||||
/**
|
/**
|
||||||
* List of denied players
|
* List of denied players
|
||||||
|
* Direct access is Deprecated: use getDenied()
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public HashSet<UUID> denied;
|
public HashSet<UUID> denied;
|
||||||
/**
|
/**
|
||||||
* External settings class<br>
|
* External settings class<br>
|
||||||
* - Please favor the methods over direct access to this class<br>
|
* - Please favor the methods over direct access to this class<br>
|
||||||
* - The methods are more likely to be left unchanged from version changes<br>
|
* - The methods are more likely to be left unchanged from version changes<br>
|
||||||
|
* Direct access is Deprecated: use getSettings()
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public PlotSettings settings;
|
public PlotSettings settings;
|
||||||
/**
|
/**
|
||||||
* Has the plot changed since the last save cycle?
|
* Has the plot changed since the last save cycle?
|
||||||
*/
|
*/
|
||||||
public boolean hasChanged = false;
|
|
||||||
public boolean countsTowardsMax = true;
|
public boolean countsTowardsMax = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this plot is temporary i.e. not stored in the DB
|
* If this plot is temporary i.e. not stored in the DB
|
||||||
*/
|
*/
|
||||||
|
@ -77,6 +77,8 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
final int height = (pos2.getY() - pos1.getY()) + 1;
|
final int height = (pos2.getY() - pos1.getY()) + 1;
|
||||||
final int length = (pos2.getZ() - pos1.getZ()) + 1;
|
final int length = (pos2.getZ() - pos1.getZ()) + 1;
|
||||||
|
|
||||||
|
System.out.print(width + "," + height + "," + length);
|
||||||
|
|
||||||
// Main Schematic tag
|
// Main Schematic tag
|
||||||
final HashMap<String, Tag> schematic = new HashMap<>();
|
final HashMap<String, Tag> schematic = new HashMap<>();
|
||||||
|
|
||||||
@ -116,6 +118,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
|
|
||||||
Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
||||||
if (!bc.load(false)) {
|
if (!bc.load(false)) {
|
||||||
|
System.out.print("FAILED TO LOAD CHUNK: " + chunk.x + "," + chunk.z);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ import java.io.PrintWriter;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -33,6 +35,7 @@ import com.intellectualcrafters.jnbt.StringTag;
|
|||||||
import com.intellectualcrafters.jnbt.Tag;
|
import com.intellectualcrafters.jnbt.Tag;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
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;
|
||||||
@ -142,11 +145,9 @@ public abstract class SchematicHandler {
|
|||||||
* @return boolean true if succeeded
|
* @return boolean true if succeeded
|
||||||
*/
|
*/
|
||||||
public void paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset, final RunnableVal<Boolean> whenDone) {
|
public void paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset, final RunnableVal<Boolean> whenDone) {
|
||||||
System.out.print(1);
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.print(2);
|
|
||||||
if (whenDone != null) whenDone.value = false;
|
if (whenDone != null) whenDone.value = false;
|
||||||
if (schematic == null) {
|
if (schematic == null) {
|
||||||
PS.log("Schematic == null :|");
|
PS.log("Schematic == null :|");
|
||||||
@ -154,42 +155,97 @@ public abstract class SchematicHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
System.out.print(3);
|
|
||||||
final Dimension demensions = schematic.getSchematicDimension();
|
final Dimension demensions = schematic.getSchematicDimension();
|
||||||
final int WIDTH = demensions.getX();
|
final int WIDTH = demensions.getX();
|
||||||
final int LENGTH = demensions.getZ();
|
final int LENGTH = demensions.getZ();
|
||||||
final int HEIGHT = demensions.getY();
|
final int HEIGHT = demensions.getY();
|
||||||
|
|
||||||
byte[] ids = schematic.ids;
|
// Validate dimensions
|
||||||
byte[] datas = schematic.datas;
|
Location bottom = plot.getBottom();
|
||||||
|
Location top = plot.getTop();
|
||||||
|
if (top.getX() - bottom.getX() < WIDTH || top.getZ() - bottom.getZ() < LENGTH || HEIGHT > 256) {
|
||||||
|
System.out.print((top.getX() - bottom.getX() + 1) + "," + (top.getZ() - bottom.getZ() + 1));
|
||||||
|
System.out.print(WIDTH + "," + HEIGHT + "," + LENGTH);
|
||||||
|
PS.log("Schematic is too large");
|
||||||
|
TaskManager.runTask(whenDone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int y_offset;
|
final byte[] ids = schematic.ids;
|
||||||
|
final byte[] datas = schematic.datas;
|
||||||
|
|
||||||
|
final int y_offset;
|
||||||
if (HEIGHT >= 256) {
|
if (HEIGHT >= 256) {
|
||||||
y_offset = -1;
|
y_offset = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
y_offset = BukkitUtil.getMaxHeight(plot.world) - 1;
|
y_offset = BukkitUtil.getMaxHeight(plot.world);
|
||||||
}
|
}
|
||||||
|
|
||||||
Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1 + x_offset, y_offset, 1 + z_offset);
|
Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1 + x_offset, y_offset - 1, 1 + z_offset);
|
||||||
|
Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1);
|
||||||
|
|
||||||
int X = bottom.getX();
|
final int p1x = pos1.getX();
|
||||||
int Y = bottom.getY();
|
final int p1z = pos1.getZ();
|
||||||
int Z = bottom.getZ();
|
final int p2x = pos2.getX();
|
||||||
|
final int p2z = pos2.getZ();
|
||||||
|
final int bcx = p1x >> 4;
|
||||||
|
final int bcz = p1z >> 4;
|
||||||
|
final int tcx = p2x >> 4;
|
||||||
|
final int tcz = p2z >> 4;
|
||||||
|
|
||||||
|
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
||||||
|
|
||||||
|
for (int x = bcx; x <= tcx; x++) {
|
||||||
|
for (int z = bcz; z <= tcz; z++) {
|
||||||
|
chunks.add(new ChunkLoc(x, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.print("chunks: " + chunks.size());
|
||||||
|
|
||||||
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int count = 0;
|
||||||
|
System.out.print("RUNNING: " + chunks.size());
|
||||||
|
while (chunks.size() > 0 && count < 256) {
|
||||||
|
count++;
|
||||||
|
ChunkLoc chunk = chunks.remove(0);
|
||||||
|
int x = chunk.x;
|
||||||
|
int z = chunk.z;
|
||||||
|
int xxb = x << 4;
|
||||||
|
int zzb = z << 4;
|
||||||
|
int xxt = xxb + 15;
|
||||||
|
int zzt = zzb + 15;
|
||||||
|
if (x == bcx) {
|
||||||
|
xxb = p1x;
|
||||||
|
}
|
||||||
|
if (x == tcx) {
|
||||||
|
xxt = p2x;
|
||||||
|
}
|
||||||
|
if (z == bcz) {
|
||||||
|
zzb = p1z;
|
||||||
|
}
|
||||||
|
if (z == tcz) {
|
||||||
|
zzt = p2z;
|
||||||
|
}
|
||||||
|
// Paste schematic here
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
System.out.print(4);
|
for (int ry = 0; ry < Math.max(256, HEIGHT); ry++) {
|
||||||
|
int i1 = ry * WIDTH * LENGTH;
|
||||||
|
for (int rz = zzb - p1z; rz <= zzt - p1z; rz++) {
|
||||||
|
int i2 = rz * WIDTH + i1;
|
||||||
|
for (int rx = xxb - p1x; rx <= xxt - p1x; rx++) {
|
||||||
|
int i = i2 + rx;
|
||||||
|
|
||||||
System.out.print("HEIGHT: " + HEIGHT);
|
int xx = p1x + rx;
|
||||||
|
int zz = p1z + rz;
|
||||||
|
int yy = y_offset + ry;
|
||||||
|
|
||||||
for (int y = 0; y < Math.max(256, HEIGHT); y++) {
|
|
||||||
int i1 = y * WIDTH * LENGTH;
|
|
||||||
for (int z = 0; z < LENGTH; z++) {
|
|
||||||
int i2 = z * WIDTH + i1;
|
|
||||||
for (int x = 0; x < WIDTH; x++) {
|
|
||||||
int i = i2 + x;
|
|
||||||
id = ids[i];
|
id = ids[i];
|
||||||
|
|
||||||
switch(id) {
|
switch(id) {
|
||||||
case 0:
|
case 0:
|
||||||
case 2:
|
case 2:
|
||||||
@ -262,32 +318,36 @@ public abstract class SchematicHandler {
|
|||||||
case 190:
|
case 190:
|
||||||
case 191:
|
case 191:
|
||||||
case 192: {
|
case 192: {
|
||||||
SetBlockQueue.setBlock(plot.world, X + x, Y + y, Z + z, id);
|
SetBlockQueue.setBlock(plot.world, xx, yy, zz, id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
SetBlockQueue.setBlock(plot.world, X + x, Y + y, Z + z, new PlotBlock((short) id, (byte) datas[i]));
|
SetBlockQueue.setBlock(plot.world, xx, yy, zz, new PlotBlock((short) id, (byte) datas[i]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set block
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
System.out.print(5);
|
if (chunks.size() != 0) {
|
||||||
|
final Runnable task = this;
|
||||||
|
// Run when the queue is free
|
||||||
|
SetBlockQueue.addNotify(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.gc();
|
||||||
|
TaskManager.runTaskLaterAsync(task, 80);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.gc();
|
||||||
|
// Finished
|
||||||
SetBlockQueue.addNotify(new Runnable() {
|
SetBlockQueue.addNotify(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
System.out.print(6);
|
|
||||||
|
|
||||||
pasteStates(schematic, plot, x_offset, z_offset);
|
pasteStates(schematic, plot, x_offset, z_offset);
|
||||||
|
|
||||||
System.out.print(7);
|
|
||||||
|
|
||||||
if (whenDone != null) {
|
if (whenDone != null) {
|
||||||
whenDone.value = true;
|
whenDone.value = true;
|
||||||
whenDone.run();
|
whenDone.run();
|
||||||
@ -295,6 +355,9 @@ public abstract class SchematicHandler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
@ -334,7 +397,7 @@ public abstract class SchematicHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Schematic getSchematic(final CompoundTag tag, final File file) {
|
public Schematic getSchematic(final CompoundTag tag) {
|
||||||
final Map<String, Tag> tagMap = tag.getValue();
|
final Map<String, Tag> tagMap = tag.getValue();
|
||||||
// Slow
|
// Slow
|
||||||
// byte[] addId = new byte[0];
|
// byte[] addId = new byte[0];
|
||||||
@ -369,7 +432,7 @@ public abstract class SchematicHandler {
|
|||||||
// Schematic schem = new Schematic(collection, dimension, file);
|
// Schematic schem = new Schematic(collection, dimension, file);
|
||||||
|
|
||||||
Dimension dimensions = new Dimension(width, height, length);
|
Dimension dimensions = new Dimension(width, height, length);
|
||||||
Schematic schem = new Schematic(block, data, dimensions , file);
|
Schematic schem = new Schematic(block, data, dimensions);
|
||||||
|
|
||||||
// Slow
|
// Slow
|
||||||
try {
|
try {
|
||||||
@ -422,25 +485,58 @@ public abstract class SchematicHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final InputStream iStream = new FileInputStream(file);
|
return getSchematic(new FileInputStream(file));
|
||||||
final NBTInputStream stream = new NBTInputStream(new GZIPInputStream(iStream));
|
|
||||||
final CompoundTag tag = (CompoundTag) stream.readTag();
|
|
||||||
stream.close();
|
|
||||||
return getSchematic(tag, file);
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
PS.log(file.toString() + " is not in GZIP format");
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Schematic getSchematic(URL url) {
|
||||||
|
try {
|
||||||
|
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
|
||||||
|
InputStream is = Channels.newInputStream(rbc);
|
||||||
|
return getSchematic(is);
|
||||||
|
// fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL upload(final CompoundTag tag) {
|
public Schematic getSchematic(InputStream is) {
|
||||||
|
if (is == null) {
|
||||||
|
System.out.print("SCHEM IS NULL!!!!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final NBTInputStream stream = new NBTInputStream(new GZIPInputStream(is));
|
||||||
|
final CompoundTag tag = (CompoundTag) stream.readTag(1073741824);
|
||||||
|
is.close();
|
||||||
|
stream.close();
|
||||||
|
return getSchematic(tag);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
PS.log(is.toString() + " | " + is.getClass().getCanonicalName() + " is not in GZIP format : " + e.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL upload(final CompoundTag tag, UUID uuid) {
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
PS.log("&cCannot save empty tag");
|
PS.log("&cCannot save empty tag");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
UUID uuid = UUID.randomUUID();
|
String website;
|
||||||
String website = Settings.WEB_URL + "upload.php?" + uuid;
|
if (uuid == null) {
|
||||||
|
uuid = UUID.randomUUID();
|
||||||
|
website = Settings.WEB_URL + "upload.php?" + uuid;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
website = Settings.WEB_URL + "save.php?" + uuid;
|
||||||
|
}
|
||||||
String charset = "UTF-8";
|
String charset = "UTF-8";
|
||||||
String param = "value";
|
String param = "value";
|
||||||
String boundary = Long.toHexString(System.currentTimeMillis());
|
String boundary = Long.toHexString(System.currentTimeMillis());
|
||||||
@ -632,38 +728,39 @@ public abstract class SchematicHandler {
|
|||||||
private DataCollection[] collection;
|
private DataCollection[] collection;
|
||||||
|
|
||||||
private final Dimension schematicDimension;
|
private final Dimension schematicDimension;
|
||||||
private final File file;
|
|
||||||
private HashSet<PlotItem> items;
|
private HashSet<PlotItem> items;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is deprecated as having a wrapper for each block is really slow.<br>
|
* This is deprecated as having a wrapper for each block is slow.<br>
|
||||||
* - There's also a performance hit by having the cast the DataCollection short / byte
|
* - There's also a performance hit by having to cast the DataCollection short / byte
|
||||||
* -
|
* -
|
||||||
* @param blockCollection
|
* @param blockCollection
|
||||||
* @param schematicDimension
|
* @param schematicDimension
|
||||||
* @param file
|
* @param file
|
||||||
*/
|
*/
|
||||||
// @Deprecated
|
@Deprecated
|
||||||
// public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) {
|
public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension) {
|
||||||
// ids = new byte[blockCollection.length];
|
ids = new byte[blockCollection.length];
|
||||||
// datas = new byte[blockCollection.length];
|
datas = new byte[blockCollection.length];
|
||||||
// for (int i = 0; i < blockCollection.length; i++) {
|
for (int i = 0; i < blockCollection.length; i++) {
|
||||||
// DataCollection block = blockCollection[i];
|
DataCollection block = blockCollection[i];
|
||||||
// ids[i] = (byte) block.block;
|
ids[i] = (byte) block.block;
|
||||||
// datas[i] = block.data;
|
datas[i] = block.data;
|
||||||
// }
|
}
|
||||||
// this.collection = blockCollection;
|
this.collection = blockCollection;
|
||||||
// this.schematicDimension = schematicDimension;
|
this.schematicDimension = schematicDimension;
|
||||||
// this.file = file;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
public Schematic(final byte[] i, final byte[] b, final Dimension d, final File f) {
|
public Schematic(final byte[] i, final byte[] b, final Dimension d) {
|
||||||
ids = i;
|
ids = i;
|
||||||
datas = b;
|
datas = b;
|
||||||
schematicDimension = d;
|
schematicDimension = d;
|
||||||
file = f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an item to the schematic
|
||||||
|
* @param item
|
||||||
|
*/
|
||||||
public void addItem(PlotItem item) {
|
public void addItem(PlotItem item) {
|
||||||
if (this.items == null) {
|
if (this.items == null) {
|
||||||
this.items = new HashSet<>();
|
this.items = new HashSet<>();
|
||||||
@ -671,36 +768,52 @@ public abstract class SchematicHandler {
|
|||||||
items.add(item);
|
items.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get any items associated with this schematic
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public HashSet<PlotItem> getItems() {
|
public HashSet<PlotItem> getItems() {
|
||||||
return this.items;
|
return this.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile() {
|
/**
|
||||||
return this.file;
|
* Get the schematic dimensions
|
||||||
}
|
* @return
|
||||||
|
*/
|
||||||
public Dimension getSchematicDimension() {
|
public Dimension getSchematicDimension() {
|
||||||
return this.schematicDimension;
|
return this.schematicDimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the block id array
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public byte[] getIds() {
|
public byte[] getIds() {
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the block data array
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public byte[] getDatas() {
|
public byte[] getDatas() {
|
||||||
return datas;
|
return datas;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Deprecated
|
/**
|
||||||
// public DataCollection[] getBlockCollection() {
|
* @deprecated as it is slow to wrap each block
|
||||||
// if (this.collection == null) {
|
* @return DataCollection of schematic blocks
|
||||||
// collection = new DataCollection[ids.length];
|
*/
|
||||||
// for (int i = 0; i < ids.length; i++) {
|
@Deprecated
|
||||||
// collection[i] = new DataCollection(ids[i], datas[i]);
|
public DataCollection[] getBlockCollection() {
|
||||||
// }
|
if (this.collection == null) {
|
||||||
// }
|
collection = new DataCollection[ids.length];
|
||||||
// return this.collection;
|
for (int i = 0; i < ids.length; i++) {
|
||||||
// }
|
collection[i] = new DataCollection(ids[i], datas[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.collection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -734,9 +847,10 @@ public abstract class SchematicHandler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Schematic Data Collection
|
* Schematic Data Collection
|
||||||
*
|
* @deprecated as it is slow to wrap each block
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class DataCollection {
|
public class DataCollection {
|
||||||
private final short block;
|
private final short block;
|
||||||
private final byte data;
|
private final byte data;
|
||||||
|
@ -68,6 +68,7 @@ public class SetBlockQueue {
|
|||||||
TaskManager.runTask(runnable);
|
TaskManager.runTask(runnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastBlock = null;
|
||||||
runnables = null;
|
runnables = null;
|
||||||
blocks = new HashMap<>();
|
blocks = new HashMap<>();
|
||||||
running = false;
|
running = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user