2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
|
|
|
* Copyright (C) 2020 IntellectualSites
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.util;
|
2016-02-23 05:11:28 +01:00
|
|
|
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.PlotSquared;
|
2020-04-16 06:14:33 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.generator.ClassicPlotWorld;
|
|
|
|
import com.plotsquared.core.location.Location;
|
|
|
|
import com.plotsquared.core.plot.Plot;
|
|
|
|
import com.plotsquared.core.plot.PlotArea;
|
|
|
|
import com.plotsquared.core.plot.schematic.Schematic;
|
2020-07-17 16:41:06 +02:00
|
|
|
import com.plotsquared.core.queue.QueueCoordinator;
|
2020-07-19 14:23:55 +02:00
|
|
|
import com.plotsquared.core.util.net.AbstractDelegateOutputStream;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.util.task.RunnableVal;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.util.task.TaskManager;
|
2020-07-15 13:18:09 +02:00
|
|
|
import com.plotsquared.core.util.task.TaskTime;
|
2020-05-19 12:53:18 +02:00
|
|
|
import com.sk89q.jnbt.ByteArrayTag;
|
2019-05-14 03:57:41 +02:00
|
|
|
import com.sk89q.jnbt.CompoundTag;
|
2020-05-19 12:53:18 +02:00
|
|
|
import com.sk89q.jnbt.IntArrayTag;
|
|
|
|
import com.sk89q.jnbt.IntTag;
|
|
|
|
import com.sk89q.jnbt.ListTag;
|
2019-05-14 03:57:41 +02:00
|
|
|
import com.sk89q.jnbt.NBTInputStream;
|
|
|
|
import com.sk89q.jnbt.NBTOutputStream;
|
2020-05-19 12:53:18 +02:00
|
|
|
import com.sk89q.jnbt.ShortTag;
|
|
|
|
import com.sk89q.jnbt.StringTag;
|
|
|
|
import com.sk89q.jnbt.Tag;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.extension.platform.Capability;
|
2019-11-04 20:55:55 +01:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
2019-05-14 03:57:41 +02:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader;
|
2019-11-04 18:44:23 +01:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
2018-12-20 00:18:57 +01:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2019-11-10 18:47:37 +01:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2020-03-24 09:08:56 +01:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2018-12-20 00:18:57 +01:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
2020-04-09 17:41:55 +02:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
2020-07-12 21:49:05 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2020-07-17 16:41:06 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2020-07-19 14:23:55 +02:00
|
|
|
import javax.annotation.Nullable;
|
2019-11-04 18:44:23 +01:00
|
|
|
import java.io.BufferedReader;
|
2020-05-19 12:53:18 +02:00
|
|
|
import java.io.ByteArrayOutputStream;
|
2019-11-04 18:44:23 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.OutputStream;
|
2020-07-19 14:23:55 +02:00
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.MalformedURLException;
|
2016-02-23 05:11:28 +01:00
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLConnection;
|
|
|
|
import java.nio.channels.Channels;
|
|
|
|
import java.nio.channels.ReadableByteChannel;
|
2020-07-19 14:23:55 +02:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2020-05-19 12:53:18 +02:00
|
|
|
import java.util.ArrayDeque;
|
2019-11-04 18:44:23 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
2020-05-19 12:53:18 +02:00
|
|
|
import java.util.HashMap;
|
2019-11-04 18:44:23 +01:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2020-05-19 12:53:18 +02:00
|
|
|
import java.util.Map;
|
2020-07-19 14:23:55 +02:00
|
|
|
import java.util.Scanner;
|
2019-11-04 18:44:23 +01:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
2018-12-06 18:01:33 +01:00
|
|
|
import java.util.stream.Collectors;
|
2020-05-19 12:53:18 +02:00
|
|
|
import java.util.stream.IntStream;
|
2016-02-23 05:11:28 +01:00
|
|
|
import java.util.zip.GZIPInputStream;
|
|
|
|
import java.util.zip.GZIPOutputStream;
|
|
|
|
|
|
|
|
public abstract class SchematicHandler {
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2020-07-17 16:41:06 +02:00
|
|
|
private static final Logger logger =
|
|
|
|
LoggerFactory.getLogger("P2/" + SchematicHandler.class.getSimpleName());
|
2016-02-23 05:11:28 +01:00
|
|
|
public static SchematicHandler manager;
|
2020-07-10 22:12:37 +02:00
|
|
|
private final WorldUtil worldUtil;
|
2020-07-17 16:41:06 +02:00
|
|
|
private boolean exportAll = false;
|
2020-07-10 22:12:37 +02:00
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
public SchematicHandler(@Nonnull final WorldUtil worldUtil) {
|
2020-07-10 22:12:37 +02:00
|
|
|
this.worldUtil = worldUtil;
|
|
|
|
}
|
|
|
|
|
2020-07-19 14:23:55 +02:00
|
|
|
public static void upload(@Nullable UUID uuid, @Nullable final String file,
|
|
|
|
@Nonnull final String extension, @Nullable final RunnableVal<OutputStream> writeTask,
|
|
|
|
@Nonnull final RunnableVal<URL> whenDone) {
|
|
|
|
if (writeTask == null) {
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final String filename;
|
|
|
|
final String website;
|
|
|
|
if (uuid == null) {
|
|
|
|
uuid = UUID.randomUUID();
|
|
|
|
website = Settings.Web.URL + "upload.php?" + uuid;
|
|
|
|
filename = "plot." + extension;
|
|
|
|
} else {
|
|
|
|
website = Settings.Web.URL + "save.php?" + uuid;
|
|
|
|
filename = file + '.' + extension;
|
|
|
|
}
|
|
|
|
final URL url;
|
|
|
|
try {
|
|
|
|
url = new URL(Settings.Web.URL + "?key=" + uuid + "&type=" + extension);
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
whenDone.run();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TaskManager.runTaskAsync(() -> {
|
|
|
|
try {
|
|
|
|
String boundary = Long.toHexString(System.currentTimeMillis());
|
|
|
|
URLConnection con = new URL(website).openConnection();
|
|
|
|
con.setDoOutput(true);
|
|
|
|
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
|
|
|
try (OutputStream output = con.getOutputStream();
|
|
|
|
PrintWriter writer = new PrintWriter(
|
|
|
|
new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) {
|
|
|
|
String CRLF = "\r\n";
|
|
|
|
writer.append("--" + boundary).append(CRLF);
|
|
|
|
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
|
|
|
|
writer.append(
|
|
|
|
"Content-Type: text/plain; charset=" + StandardCharsets.UTF_8.displayName())
|
|
|
|
.append(CRLF);
|
|
|
|
String param = "value";
|
|
|
|
writer.append(CRLF).append(param).append(CRLF).flush();
|
|
|
|
writer.append("--" + boundary).append(CRLF);
|
|
|
|
writer.append(
|
|
|
|
"Content-Disposition: form-data; name=\"schematicFile\"; filename=\""
|
|
|
|
+ filename + '"').append(CRLF);
|
|
|
|
writer
|
|
|
|
.append("Content-Type: " + URLConnection.guessContentTypeFromName(filename))
|
|
|
|
.append(CRLF);
|
|
|
|
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
|
|
|
|
writer.append(CRLF).flush();
|
|
|
|
writeTask.value = new AbstractDelegateOutputStream(output) {
|
|
|
|
@Override public void close() {
|
|
|
|
} // Don't close
|
|
|
|
};
|
|
|
|
writeTask.run();
|
|
|
|
output.flush();
|
|
|
|
writer.append(CRLF).flush();
|
|
|
|
writer.append("--" + boundary + "--").append(CRLF).flush();
|
|
|
|
}
|
|
|
|
String content;
|
|
|
|
try (Scanner scanner = new Scanner(con.getInputStream()).useDelimiter("\\A")) {
|
|
|
|
content = scanner.next().trim();
|
|
|
|
}
|
|
|
|
if (!content.startsWith("<")) {
|
|
|
|
}
|
|
|
|
int responseCode = ((HttpURLConnection) con).getResponseCode();
|
|
|
|
if (responseCode == 200) {
|
|
|
|
whenDone.value = url;
|
|
|
|
}
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
public boolean exportAll(Collection<Plot> collection, final File outputDir,
|
|
|
|
final String namingScheme, final Runnable ifSuccess) {
|
2016-03-29 01:30:55 +02:00
|
|
|
if (this.exportAll) {
|
2016-02-23 05:11:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (collection.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-29 01:30:55 +02:00
|
|
|
this.exportAll = true;
|
2016-03-14 07:18:04 +01:00
|
|
|
final ArrayList<Plot> plots = new ArrayList<>(collection);
|
2016-02-23 05:11:28 +01:00
|
|
|
TaskManager.runTask(new Runnable() {
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void run() {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (plots.isEmpty()) {
|
2016-03-29 01:30:55 +02:00
|
|
|
SchematicHandler.this.exportAll = false;
|
2016-02-23 05:11:28 +01:00
|
|
|
TaskManager.runTask(ifSuccess);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-29 01:30:55 +02:00
|
|
|
Iterator<Plot> i = plots.iterator();
|
2016-02-23 05:11:28 +01:00
|
|
|
final Plot plot = i.next();
|
|
|
|
i.remove();
|
2020-05-19 23:05:36 +02:00
|
|
|
|
|
|
|
final String owner;
|
|
|
|
if (plot.hasOwner()) {
|
|
|
|
owner = plot.getOwnerAbs().toString();
|
|
|
|
} else {
|
2019-05-22 00:32:26 +02:00
|
|
|
owner = "unknown";
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2020-05-19 23:05:36 +02:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
final String name;
|
|
|
|
if (namingScheme == null) {
|
2019-05-22 00:32:26 +02:00
|
|
|
name =
|
2020-07-19 17:03:40 +02:00
|
|
|
plot.getId().getX() + ";" + plot.getId().getY() + ',' + plot.getArea() + ','
|
|
|
|
+ owner;
|
2016-02-23 05:11:28 +01:00
|
|
|
} else {
|
2020-06-27 21:38:55 +02:00
|
|
|
name = namingScheme.replaceAll("%id%", plot.getId().toString())
|
2020-07-18 11:05:16 +02:00
|
|
|
.replaceAll("%idx%", plot.getId().getX() + "")
|
|
|
|
.replaceAll("%idy%", plot.getId().getY() + "")
|
2018-08-10 17:01:10 +02:00
|
|
|
.replaceAll("%world%", plot.getArea().toString());
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2020-05-20 11:27:11 +02:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
final String directory;
|
|
|
|
if (outputDir == null) {
|
2016-06-10 19:00:34 +02:00
|
|
|
directory = Settings.Paths.SCHEMATICS;
|
2016-02-23 05:11:28 +01:00
|
|
|
} else {
|
2016-03-11 05:33:18 +01:00
|
|
|
directory = outputDir.getAbsolutePath();
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2020-05-20 11:27:11 +02:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
final Runnable THIS = this;
|
2020-07-10 22:12:37 +02:00
|
|
|
getCompoundTag(plot, new RunnableVal<CompoundTag>() {
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void run(final CompoundTag value) {
|
2020-07-13 22:51:57 +02:00
|
|
|
if (value != null) {
|
2018-12-21 01:49:15 +01:00
|
|
|
TaskManager.runTaskAsync(() -> {
|
2020-07-17 16:41:06 +02:00
|
|
|
boolean result =
|
|
|
|
save(value, directory + File.separator + name + ".schem");
|
2018-12-21 01:49:15 +01:00
|
|
|
if (!result) {
|
2020-07-13 23:04:27 +02:00
|
|
|
logger.error("[P2] Failed to save {}", plot.getId());
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
TaskManager.runTask(THIS);
|
2016-02-23 05:11:28 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-02 07:42:04 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2016-03-29 01:30:55 +02:00
|
|
|
* Paste a schematic.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
|
|
|
* @param schematic the schematic object to paste
|
|
|
|
* @param plot plot to paste in
|
2018-08-10 17:01:10 +02:00
|
|
|
* @param xOffset offset x to paste it from plot origin
|
|
|
|
* @param zOffset offset z to paste it from plot origin
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2018-08-10 17:01:10 +02:00
|
|
|
public void paste(final Schematic schematic, final Plot plot, final int xOffset,
|
2018-12-21 00:33:24 +01:00
|
|
|
final int yOffset, final int zOffset, final boolean autoHeight,
|
|
|
|
final RunnableVal<Boolean> whenDone) {
|
2018-12-20 00:18:57 +01:00
|
|
|
|
2018-12-21 01:49:15 +01:00
|
|
|
TaskManager.runTask(() -> {
|
|
|
|
if (whenDone != null) {
|
|
|
|
whenDone.value = false;
|
|
|
|
}
|
|
|
|
if (schematic == null) {
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
BlockVector3 dimension = schematic.getClipboard().getDimensions();
|
|
|
|
final int WIDTH = dimension.getX();
|
|
|
|
final int LENGTH = dimension.getZ();
|
|
|
|
final int HEIGHT = dimension.getY();
|
|
|
|
// Validate dimensions
|
2019-11-04 22:08:33 +01:00
|
|
|
CuboidRegion region = plot.getLargestRegion();
|
2020-02-24 18:42:02 +01:00
|
|
|
if (((region.getMaximumPoint().getX() - region.getMinimumPoint().getX() + xOffset
|
|
|
|
+ 1) < WIDTH) || (
|
|
|
|
(region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + zOffset
|
|
|
|
+ 1) < LENGTH) || (HEIGHT > 256)) {
|
2016-02-23 05:11:28 +01:00
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
return;
|
|
|
|
}
|
2018-12-21 01:49:15 +01:00
|
|
|
// block type and data arrays
|
2019-11-04 20:55:55 +01:00
|
|
|
final Clipboard blockArrayClipboard = schematic.getClipboard();
|
2018-12-21 01:49:15 +01:00
|
|
|
// Calculate the optimal height to paste the schematic at
|
|
|
|
final int y_offset_actual;
|
|
|
|
if (autoHeight) {
|
|
|
|
if (HEIGHT >= 256) {
|
|
|
|
y_offset_actual = yOffset;
|
|
|
|
} else {
|
|
|
|
PlotArea pw = plot.getArea();
|
|
|
|
if (pw instanceof ClassicPlotWorld) {
|
|
|
|
y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT;
|
2016-02-23 05:11:28 +01:00
|
|
|
} else {
|
2020-07-17 16:41:06 +02:00
|
|
|
y_offset_actual = yOffset + 1 + this.worldUtil
|
2020-04-30 12:01:52 +02:00
|
|
|
.getHighestBlockSynchronous(plot.getWorldName(),
|
2020-02-24 18:42:02 +01:00
|
|
|
region.getMinimumPoint().getX() + 1,
|
2019-11-04 22:08:33 +01:00
|
|
|
region.getMinimumPoint().getZ() + 1);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-02 07:42:04 +01:00
|
|
|
}
|
2018-12-21 01:49:15 +01:00
|
|
|
} else {
|
|
|
|
y_offset_actual = yOffset;
|
|
|
|
}
|
2020-07-09 22:28:46 +02:00
|
|
|
|
2020-07-17 16:41:06 +02:00
|
|
|
final Location pos1 = Location
|
|
|
|
.at(plot.getWorldName(), region.getMinimumPoint().getX() + xOffset,
|
|
|
|
y_offset_actual, region.getMinimumPoint().getZ() + zOffset);
|
2020-07-09 22:28:46 +02:00
|
|
|
final Location pos2 = pos1.add(WIDTH - 1, HEIGHT - 1, LENGTH - 1);
|
|
|
|
|
2018-12-21 01:49:15 +01:00
|
|
|
final int p1x = pos1.getX();
|
|
|
|
final int p1z = pos1.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;
|
2020-07-24 16:17:42 +02:00
|
|
|
// Paste schematic here
|
|
|
|
final QueueCoordinator queue = plot.getArea().getQueue();
|
2016-02-23 05:11:28 +01:00
|
|
|
|
2020-07-24 16:17:42 +02:00
|
|
|
for (int ry = 0; ry < Math.min(256, HEIGHT); ry++) {
|
|
|
|
int yy = y_offset_actual + ry;
|
|
|
|
if (yy > 255) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int rz = 0; rz <= blockArrayClipboard.getDimensions().getZ(); rz++) {
|
|
|
|
for (int rx = 0; rx < blockArrayClipboard.getDimensions().getX(); rx++) {
|
|
|
|
int xx = p1x + xOffset + rx;
|
|
|
|
int zz = p1z + zOffset + rz;
|
|
|
|
BaseBlock id =
|
|
|
|
blockArrayClipboard.getFullBlock(BlockVector3.at(rx, ry, rz));
|
|
|
|
queue.setBlock(xx, yy, zz, id);
|
|
|
|
if (ry == 0) {
|
|
|
|
BiomeType biome =
|
|
|
|
blockArrayClipboard.getBiome(BlockVector3.at(rx, ry, rz));
|
|
|
|
queue.setBiome(xx, yy, zz, biome);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2018-12-21 01:49:15 +01:00
|
|
|
}
|
2018-12-21 00:33:24 +01:00
|
|
|
}
|
2020-07-24 16:17:42 +02:00
|
|
|
}
|
2020-07-19 17:03:40 +02:00
|
|
|
if (whenDone != null) {
|
|
|
|
whenDone.value = true;
|
|
|
|
}
|
|
|
|
queue.setCompleteTask(whenDone);
|
|
|
|
queue.enqueue();
|
2018-12-21 01:49:15 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
TaskManager.runTask(whenDone);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-03-29 01:30:55 +02:00
|
|
|
|
2020-07-17 16:41:06 +02:00
|
|
|
public abstract boolean restoreTile(QueueCoordinator queue, CompoundTag tag, int x, int y,
|
2018-08-10 17:01:10 +02:00
|
|
|
int z);
|
2016-02-23 05:11:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a schematic
|
|
|
|
*
|
|
|
|
* @param name to check
|
|
|
|
* @return schematic if found, else null
|
|
|
|
*/
|
2018-12-20 00:18:57 +01:00
|
|
|
public Schematic getSchematic(String name) throws UnsupportedFormatException {
|
2018-11-14 15:44:07 +01:00
|
|
|
File parent =
|
2020-07-19 14:23:55 +02:00
|
|
|
FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS);
|
2016-02-23 05:11:28 +01:00
|
|
|
if (!parent.exists()) {
|
|
|
|
if (!parent.mkdir()) {
|
|
|
|
throw new RuntimeException("Could not create schematic parent directory");
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 12:39:01 +02:00
|
|
|
if (!name.endsWith(".schem") && !name.endsWith(".schematic")) {
|
|
|
|
name = name + ".schem";
|
|
|
|
}
|
2020-07-19 14:23:55 +02:00
|
|
|
File file = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
2019-04-24 00:48:22 +02:00
|
|
|
Settings.Paths.SCHEMATICS + File.separator + name);
|
2019-04-01 12:39:01 +02:00
|
|
|
if (!file.exists()) {
|
2020-07-19 14:23:55 +02:00
|
|
|
file = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
2020-03-26 21:55:27 +01:00
|
|
|
Settings.Paths.SCHEMATICS + File.separator + name);
|
2019-04-01 12:39:01 +02:00
|
|
|
}
|
2016-02-23 05:11:28 +01:00
|
|
|
return getSchematic(file);
|
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2018-12-06 18:01:33 +01:00
|
|
|
/**
|
|
|
|
* Get an immutable collection containing all schematic names
|
|
|
|
*
|
|
|
|
* @return Immutable collection with schematic names
|
|
|
|
*/
|
2019-05-14 03:57:41 +02:00
|
|
|
public Collection<String> getSchematicNames() {
|
2018-12-20 00:18:57 +01:00
|
|
|
final File parent =
|
2020-07-19 14:23:55 +02:00
|
|
|
FileUtils.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS);
|
2018-12-06 18:01:33 +01:00
|
|
|
final List<String> names = new ArrayList<>();
|
|
|
|
if (parent.exists()) {
|
2019-04-24 00:48:22 +02:00
|
|
|
final String[] rawNames =
|
|
|
|
parent.list((dir, name) -> name.endsWith(".schematic") || name.endsWith(".schem"));
|
2018-12-06 18:01:33 +01:00
|
|
|
if (rawNames != null) {
|
2018-12-20 00:18:57 +01:00
|
|
|
final List<String> transformed = Arrays.stream(rawNames)
|
2019-09-12 03:44:31 +02:00
|
|
|
//.map(rawName -> rawName.substring(0, rawName.length() - 10))
|
2018-12-06 18:01:33 +01:00
|
|
|
.collect(Collectors.toList());
|
|
|
|
names.addAll(transformed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Collections.unmodifiableList(names);
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
|
|
|
* Get a schematic
|
|
|
|
*
|
|
|
|
* @param file to check
|
|
|
|
* @return schematic if found, else null
|
|
|
|
*/
|
2018-12-20 00:18:57 +01:00
|
|
|
public Schematic getSchematic(File file) throws UnsupportedFormatException {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (!file.exists()) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-03-26 21:55:27 +01:00
|
|
|
ClipboardFormat format = ClipboardFormats.findByFile(file);
|
|
|
|
if (format != null) {
|
|
|
|
try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
|
2019-11-04 20:55:55 +01:00
|
|
|
Clipboard clip = reader.read();
|
2018-12-20 00:18:57 +01:00
|
|
|
return new Schematic(clip);
|
2020-03-26 21:55:27 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2018-12-20 00:18:57 +01:00
|
|
|
}
|
2020-03-26 21:55:27 +01:00
|
|
|
} else {
|
|
|
|
throw new UnsupportedFormatException(
|
|
|
|
"This schematic format is not recognised or supported.");
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-29 01:30:55 +02:00
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
public Schematic getSchematic(@Nonnull URL url) {
|
2016-02-23 05:11:28 +01:00
|
|
|
try {
|
2019-09-08 20:02:45 +02:00
|
|
|
ReadableByteChannel readableByteChannel = Channels.newChannel(url.openStream());
|
|
|
|
InputStream inputStream = Channels.newInputStream(readableByteChannel);
|
|
|
|
return getSchematic(inputStream);
|
2016-02-23 05:11:28 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-29 01:30:55 +02:00
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
public Schematic getSchematic(@Nonnull InputStream is) {
|
2016-02-23 05:11:28 +01:00
|
|
|
try {
|
2019-09-08 20:02:45 +02:00
|
|
|
SpongeSchematicReader schematicReader =
|
2018-12-20 00:18:57 +01:00
|
|
|
new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
|
2019-11-04 20:55:55 +01:00
|
|
|
Clipboard clip = schematicReader.read();
|
2018-12-20 00:18:57 +01:00
|
|
|
return new Schematic(clip);
|
|
|
|
} catch (IOException ignored) {
|
|
|
|
try {
|
2019-09-08 20:02:45 +02:00
|
|
|
MCEditSchematicReader schematicReader =
|
2018-12-20 00:18:57 +01:00
|
|
|
new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
|
2019-11-04 20:55:55 +01:00
|
|
|
Clipboard clip = schematicReader.read();
|
2018-12-20 00:18:57 +01:00
|
|
|
return new Schematic(clip);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-29 01:30:55 +02:00
|
|
|
|
|
|
|
public List<String> getSaves(UUID uuid) {
|
2019-02-15 18:50:43 +01:00
|
|
|
String rawJSON = "";
|
2016-02-23 05:11:28 +01:00
|
|
|
try {
|
2016-06-10 19:00:34 +02:00
|
|
|
String website = Settings.Web.URL + "list.php?" + uuid.toString();
|
2016-03-29 01:30:55 +02:00
|
|
|
URL url = new URL(website);
|
|
|
|
URLConnection connection = new URL(url.toString()).openConnection();
|
2016-02-23 05:11:28 +01:00
|
|
|
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
2019-02-15 18:50:43 +01:00
|
|
|
try (BufferedReader reader = new BufferedReader(
|
|
|
|
new InputStreamReader(connection.getInputStream()))) {
|
|
|
|
rawJSON = reader.lines().collect(Collectors.joining());
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2019-02-15 18:50:43 +01:00
|
|
|
JSONArray array = new JSONArray(rawJSON);
|
2016-03-29 01:30:55 +02:00
|
|
|
List<String> schematics = new ArrayList<>();
|
2016-02-23 05:11:28 +01:00
|
|
|
for (int i = 0; i < array.length(); i++) {
|
2016-03-29 01:30:55 +02:00
|
|
|
String schematic = array.getString(i);
|
2016-02-23 05:11:28 +01:00
|
|
|
schematics.add(schematic);
|
|
|
|
}
|
2016-06-16 09:31:02 +02:00
|
|
|
return schematics;
|
2016-02-23 05:11:28 +01:00
|
|
|
} catch (JSONException | IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2016-03-17 10:11:07 +01:00
|
|
|
public void upload(final CompoundTag tag, UUID uuid, String file, RunnableVal<URL> whenDone) {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (tag == null) {
|
2016-03-17 10:11:07 +01:00
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
return;
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2020-07-19 14:23:55 +02:00
|
|
|
upload(uuid, file, "schem", new RunnableVal<OutputStream>() {
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void run(OutputStream output) {
|
2018-12-23 23:49:43 +01:00
|
|
|
try (NBTOutputStream nos = new NBTOutputStream(
|
|
|
|
new GZIPOutputStream(output, true))) {
|
|
|
|
nos.writeNamedTag("Schematic", tag);
|
|
|
|
} catch (IOException e1) {
|
|
|
|
e1.printStackTrace();
|
2016-03-17 10:11:07 +01:00
|
|
|
}
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-17 10:11:07 +01:00
|
|
|
}, whenDone);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2016-03-29 01:30:55 +02:00
|
|
|
* Saves a schematic to a file path.
|
2016-02-23 05:11:28 +01:00
|
|
|
*
|
|
|
|
* @param tag to save
|
|
|
|
* @param path to save in
|
|
|
|
* @return true if succeeded
|
|
|
|
*/
|
2016-03-29 01:30:55 +02:00
|
|
|
public boolean save(CompoundTag tag, String path) {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (tag == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
2020-07-19 14:23:55 +02:00
|
|
|
File tmp = FileUtils.getFile(PlotSquared.platform().getDirectory(), path);
|
2016-02-23 05:11:28 +01:00
|
|
|
tmp.getParentFile().mkdirs();
|
2018-12-21 00:33:24 +01:00
|
|
|
try (NBTOutputStream nbtStream = new NBTOutputStream(
|
|
|
|
new GZIPOutputStream(new FileOutputStream(tmp)))) {
|
|
|
|
nbtStream.writeNamedTag("Schematic", tag);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-04-28 22:38:51 +02:00
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
2016-03-29 01:30:55 +02:00
|
|
|
} catch (IOException e) {
|
2016-02-23 05:11:28 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2020-05-19 12:53:18 +02:00
|
|
|
public void getCompoundTag(final String world, final Set<CuboidRegion> regions,
|
|
|
|
final RunnableVal<CompoundTag> whenDone) {
|
|
|
|
// async
|
|
|
|
TaskManager.runTaskAsync(() -> {
|
|
|
|
// Main positions
|
2020-07-19 14:23:55 +02:00
|
|
|
Location[] corners = RegionUtil.getCorners(world, regions);
|
2020-05-19 12:53:18 +02:00
|
|
|
final Location bot = corners[0];
|
|
|
|
final Location top = corners[1];
|
|
|
|
|
|
|
|
CuboidRegion cuboidRegion =
|
2020-07-10 22:12:37 +02:00
|
|
|
new CuboidRegion(this.worldUtil.getWeWorld(world), bot.getBlockVector3(),
|
2020-05-19 12:53:18 +02:00
|
|
|
top.getBlockVector3());
|
|
|
|
|
|
|
|
final int width = cuboidRegion.getWidth();
|
|
|
|
int height = cuboidRegion.getHeight();
|
|
|
|
final int length = cuboidRegion.getLength();
|
|
|
|
Map<String, Tag> schematic = new HashMap<>();
|
|
|
|
schematic.put("Version", new IntTag(2));
|
|
|
|
schematic.put("DataVersion", new IntTag(WorldEdit.getInstance().getPlatformManager()
|
|
|
|
.queryCapability(Capability.WORLD_EDITING).getDataVersion()));
|
|
|
|
|
|
|
|
Map<String, Tag> metadata = new HashMap<>();
|
|
|
|
metadata.put("WEOffsetX", new IntTag(0));
|
|
|
|
metadata.put("WEOffsetY", new IntTag(0));
|
|
|
|
metadata.put("WEOffsetZ", new IntTag(0));
|
|
|
|
|
|
|
|
schematic.put("Metadata", new CompoundTag(metadata));
|
|
|
|
|
|
|
|
schematic.put("Width", new ShortTag((short) width));
|
|
|
|
schematic.put("Height", new ShortTag((short) height));
|
|
|
|
schematic.put("Length", new ShortTag((short) length));
|
|
|
|
|
|
|
|
// The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin'
|
|
|
|
schematic.put("Offset", new IntArrayTag(new int[] {0, 0, 0,}));
|
|
|
|
|
|
|
|
Map<String, Integer> palette = new HashMap<>();
|
|
|
|
Map<String, Integer> biomePalette = new HashMap<>();
|
|
|
|
|
|
|
|
List<CompoundTag> tileEntities = new ArrayList<>();
|
|
|
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length);
|
|
|
|
ByteArrayOutputStream biomeBuffer = new ByteArrayOutputStream(width * length);
|
|
|
|
// Queue
|
|
|
|
final ArrayDeque<CuboidRegion> queue = new ArrayDeque<>(regions);
|
|
|
|
TaskManager.runTask(new Runnable() {
|
|
|
|
@Override public void run() {
|
|
|
|
if (queue.isEmpty()) {
|
|
|
|
TaskManager.runTaskAsync(() -> {
|
|
|
|
schematic.put("PaletteMax", new IntTag(palette.size()));
|
|
|
|
|
|
|
|
Map<String, Tag> paletteTag = new HashMap<>();
|
|
|
|
palette.forEach((key, value) -> paletteTag.put(key, new IntTag(value)));
|
|
|
|
|
|
|
|
schematic.put("Palette", new CompoundTag(paletteTag));
|
|
|
|
schematic.put("BlockData", new ByteArrayTag(buffer.toByteArray()));
|
|
|
|
schematic
|
|
|
|
.put("TileEntities", new ListTag(CompoundTag.class, tileEntities));
|
|
|
|
|
|
|
|
schematic.put("BiomePaletteMax", new IntTag(biomePalette.size()));
|
|
|
|
|
|
|
|
Map<String, Tag> biomePaletteTag = new HashMap<>();
|
|
|
|
biomePalette.forEach(
|
|
|
|
(key, value) -> biomePaletteTag.put(key, new IntTag(value)));
|
|
|
|
|
|
|
|
schematic.put("BiomePalette", new CompoundTag(biomePaletteTag));
|
|
|
|
schematic.put("BiomeData", new ByteArrayTag(biomeBuffer.toByteArray()));
|
|
|
|
whenDone.value = new CompoundTag(schematic);
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Runnable regionTask = this;
|
|
|
|
CuboidRegion region = queue.poll();
|
2020-07-09 22:28:46 +02:00
|
|
|
|
|
|
|
final Location pos1 = Location.at(world, region.getMinimumPoint());
|
|
|
|
final Location pos2 = Location.at(world, region.getMaximumPoint());
|
|
|
|
|
2020-05-19 12:53:18 +02:00
|
|
|
final int p1x = pos1.getX();
|
|
|
|
final int sy = pos1.getY();
|
|
|
|
final int p1z = pos1.getZ();
|
|
|
|
final int p2x = pos2.getX();
|
|
|
|
final int p2z = pos2.getZ();
|
|
|
|
final int ey = pos2.getY();
|
|
|
|
Iterator<Integer> yiter = IntStream.range(sy, ey + 1).iterator();
|
2020-06-27 21:38:55 +02:00
|
|
|
final Runnable yTask = new Runnable() {
|
|
|
|
@Override public void run() {
|
|
|
|
long ystart = System.currentTimeMillis();
|
|
|
|
while (yiter.hasNext() && System.currentTimeMillis() - ystart < 20) {
|
|
|
|
final int y = yiter.next();
|
|
|
|
Iterator<Integer> ziter = IntStream.range(p1z, p2z + 1).iterator();
|
|
|
|
final Runnable zTask = new Runnable() {
|
|
|
|
@Override public void run() {
|
|
|
|
long zstart = System.currentTimeMillis();
|
|
|
|
while (ziter.hasNext()
|
|
|
|
&& System.currentTimeMillis() - zstart < 20) {
|
|
|
|
final int z = ziter.next();
|
|
|
|
Iterator<Integer> xiter =
|
|
|
|
IntStream.range(p1x, p2x + 1).iterator();
|
|
|
|
final Runnable xTask = new Runnable() {
|
|
|
|
@Override public void run() {
|
|
|
|
long xstart = System.currentTimeMillis();
|
|
|
|
final int ry = y - sy;
|
|
|
|
final int rz = z - p1z;
|
|
|
|
while (xiter.hasNext()
|
|
|
|
&& System.currentTimeMillis() - xstart
|
|
|
|
< 20) {
|
|
|
|
final int x = xiter.next();
|
|
|
|
final int rx = x - p1x;
|
|
|
|
BlockVector3 point =
|
|
|
|
BlockVector3.at(x, y, z);
|
|
|
|
BaseBlock block = cuboidRegion.getWorld()
|
|
|
|
.getFullBlock(point);
|
|
|
|
if (block.getNbtData() != null) {
|
|
|
|
Map<String, Tag> values =
|
|
|
|
new HashMap<>();
|
|
|
|
for (Map.Entry<String, Tag> entry : block
|
|
|
|
.getNbtData().getValue()
|
|
|
|
.entrySet()) {
|
|
|
|
values.put(entry.getKey(),
|
|
|
|
entry.getValue());
|
|
|
|
}
|
|
|
|
// Remove 'id' if it exists. We want 'Id'
|
|
|
|
values.remove("id");
|
|
|
|
|
|
|
|
// Positions are kept in NBT, we don't want that.
|
|
|
|
values.remove("x");
|
|
|
|
values.remove("y");
|
|
|
|
values.remove("z");
|
|
|
|
|
|
|
|
values.put("Id",
|
|
|
|
new StringTag(block.getNbtId()));
|
|
|
|
values.put("Pos", new IntArrayTag(
|
|
|
|
new int[] {rx, ry, rz}));
|
|
|
|
|
|
|
|
tileEntities
|
|
|
|
.add(new CompoundTag(values));
|
|
|
|
}
|
|
|
|
String blockKey =
|
|
|
|
block.toImmutableState().getAsString();
|
|
|
|
int blockId;
|
|
|
|
if (palette.containsKey(blockKey)) {
|
|
|
|
blockId = palette.get(blockKey);
|
|
|
|
} else {
|
|
|
|
blockId = palette.size();
|
|
|
|
palette.put(blockKey, palette.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((blockId & -128) != 0) {
|
|
|
|
buffer.write(blockId & 127 | 128);
|
|
|
|
blockId >>>= 7;
|
|
|
|
}
|
|
|
|
buffer.write(blockId);
|
|
|
|
|
|
|
|
if (ry > 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
BlockVector2 pt = BlockVector2.at(x, z);
|
|
|
|
BiomeType biome =
|
|
|
|
cuboidRegion.getWorld().getBiome(pt);
|
|
|
|
String biomeStr = biome.getId();
|
|
|
|
int biomeId;
|
|
|
|
if (biomePalette.containsKey(biomeStr)) {
|
|
|
|
biomeId = biomePalette.get(biomeStr);
|
|
|
|
} else {
|
|
|
|
biomeId = biomePalette.size();
|
|
|
|
biomePalette.put(biomeStr, biomeId);
|
|
|
|
}
|
|
|
|
while ((biomeId & -128) != 0) {
|
|
|
|
biomeBuffer.write(biomeId & 127 | 128);
|
|
|
|
biomeId >>>= 7;
|
|
|
|
}
|
|
|
|
biomeBuffer.write(biomeId);
|
|
|
|
}
|
|
|
|
if (xiter.hasNext()) {
|
|
|
|
this.run();
|
|
|
|
}
|
2020-05-19 12:53:18 +02:00
|
|
|
}
|
2020-06-27 21:38:55 +02:00
|
|
|
};
|
|
|
|
xTask.run();
|
2020-05-19 12:53:18 +02:00
|
|
|
}
|
2020-06-27 21:38:55 +02:00
|
|
|
if (ziter.hasNext()) {
|
2020-05-19 12:53:18 +02:00
|
|
|
this.run();
|
|
|
|
}
|
2020-06-27 21:38:55 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
zTask.run();
|
|
|
|
}
|
|
|
|
if (yiter.hasNext()) {
|
2020-07-15 13:18:09 +02:00
|
|
|
TaskManager.runTaskLater(this, TaskTime.ticks(1L));
|
2020-06-27 21:38:55 +02:00
|
|
|
} else {
|
|
|
|
regionTask.run();
|
|
|
|
}
|
2020-05-19 12:53:18 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
yTask.run();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2016-02-29 16:01:52 +01:00
|
|
|
public void getCompoundTag(final Plot plot, final RunnableVal<CompoundTag> whenDone) {
|
2017-03-23 01:10:29 +01:00
|
|
|
getCompoundTag(plot.getWorldName(), plot.getRegions(), new RunnableVal<CompoundTag>() {
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void run(CompoundTag value) {
|
2016-03-07 07:34:57 +01:00
|
|
|
whenDone.run(value);
|
2016-02-29 16:01:52 +01:00
|
|
|
}
|
|
|
|
});
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2018-12-23 23:49:43 +01:00
|
|
|
|
2020-03-24 09:08:56 +01:00
|
|
|
public static class UnsupportedFormatException extends Exception {
|
2016-02-23 05:11:28 +01:00
|
|
|
/**
|
2018-12-20 00:18:57 +01:00
|
|
|
* Throw with a message.
|
2018-08-10 17:01:10 +02:00
|
|
|
*
|
2018-12-20 00:18:57 +01:00
|
|
|
* @param message the message
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2018-12-20 00:18:57 +01:00
|
|
|
public UnsupportedFormatException(String message) {
|
|
|
|
super(message);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-20 00:18:57 +01:00
|
|
|
* Throw with a message and a cause.
|
2018-08-10 17:01:10 +02:00
|
|
|
*
|
2018-12-20 00:18:57 +01:00
|
|
|
* @param message the message
|
|
|
|
* @param cause the cause
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2018-12-20 00:18:57 +01:00
|
|
|
public UnsupportedFormatException(String message, Throwable cause) {
|
|
|
|
super(message, cause);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|