use of com.minecolonies.coremod.network.messages.SchematicSaveMessage in project minecolonies by Minecolonies.
the class WindowBuildTool method requestScannedSchematic.
/**
* Request to build a player scan.
*
* @param structureName of the scan to be built.
*/
private void requestScannedSchematic(@NotNull final Structures.StructureName structureName) {
if (!Structures.isPlayerSchematicsAllowed()) {
return;
}
if (Structures.hasMD5(structureName)) {
final String md5 = Structures.getMD5(structureName.toString());
final String serverSideName = Structures.SCHEMATICS_CACHE + '/' + md5;
if (!Structures.hasMD5(new Structures.StructureName(serverSideName))) {
final InputStream stream = Structure.getStream(structureName.toString());
if (stream != null) {
Log.getLogger().info("BuilderTool: sending schematic " + structureName + "(md5:" + md5 + ") to the server");
MineColonies.getNetwork().sendToServer(new SchematicSaveMessage(Structure.getStreamAsByteArray(stream)));
} else {
Log.getLogger().warn("BuilderTool: Can not load " + structureName);
}
} else {
Log.getLogger().warn("BuilderTool: server does not have " + serverSideName);
}
MineColonies.getNetwork().sendToServer(new BuildToolPlaceMessage(serverSideName, structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), false, Settings.instance.getMirror()));
} else {
Log.getLogger().warn("BuilderTool: Can not send schematic without md5: " + structureName);
}
}
use of com.minecolonies.coremod.network.messages.SchematicSaveMessage in project minecolonies by Minecolonies.
the class WindowBuildTool method requestScannedSchematic.
/**
* Request to build a player scan.
*
* @param paste if it should be pasted.
* @param complete if pasted, should it be complete.
* @param structureName of the scan to be built.
*/
private static void requestScannedSchematic(@NotNull final StructureName structureName, final boolean paste, final boolean complete) {
if (!Structures.isPlayerSchematicsAllowed()) {
return;
}
if (Structures.hasMD5(structureName)) {
final String md5 = Structures.getMD5(structureName.toString());
final String serverSideName = Structures.SCHEMATICS_CACHE + '/' + md5;
if (!Structures.hasMD5(new StructureName(serverSideName))) {
final InputStream stream = Structure.getStream(structureName.toString());
if (stream != null) {
final UUID id = UUID.randomUUID();
final byte[] structureAsByteArray = Structure.getStreamAsByteArray(stream);
if (structureAsByteArray.length <= MAX_MESSAGE_SIZE) {
MineColonies.getNetwork().sendToServer(new SchematicSaveMessage(structureAsByteArray, id, 1, 1));
} else {
final int pieces = structureAsByteArray.length / MAX_MESSAGE_SIZE;
Log.getLogger().info("BuilderTool: sending: " + pieces + " pieces with the schematic " + structureName + "(md5:" + md5 + ") to the server");
for (int i = 1; i <= pieces; i++) {
final int start = (i - 1) * MAX_MESSAGE_SIZE;
final int size;
if (i == pieces) {
size = structureAsByteArray.length - (start);
} else {
size = MAX_MESSAGE_SIZE;
}
final byte[] bytes = new byte[size];
Array.copy(structureAsByteArray, start, bytes, 0, size);
MineColonies.getNetwork().sendToServer(new SchematicSaveMessage(bytes, id, pieces, i));
}
}
} else {
Log.getLogger().warn("BuilderTool: Can not load " + structureName);
}
} else {
Log.getLogger().warn("BuilderTool: server does not have " + serverSideName);
}
if (paste) {
MineColonies.getNetwork().sendToServer(new BuildToolPasteMessage(serverSideName, structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), false, Settings.instance.getMirror(), complete, null));
} else {
MineColonies.getNetwork().sendToServer(new BuildToolPlaceMessage(serverSideName, structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), false, Settings.instance.getMirror()));
}
} else {
Log.getLogger().warn("BuilderTool: Can not send schematic without md5: " + structureName);
}
}
Aggregations