This commit is contained in:
dordsor21 2021-09-07 14:02:48 +01:00
parent da3fb1abec
commit 8e5e33eec2
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
4 changed files with 21 additions and 23 deletions

View File

@ -139,7 +139,7 @@ public class Download extends SubCommand {
);
return;
}
player.sendMessage(TranslatableCaption.of("web.generation_link_success"), Template.of("url", url.toString()));
player.sendMessage(TranslatableCaption.of("web.generation_link_success_legacy_world"), Template.of("url", url.toString()));
}
});
} else {

View File

@ -28,7 +28,6 @@ package com.plotsquared.core.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;
/**
* @author DPOH-VAR
@ -52,18 +51,6 @@ public class ReflectionUtils {
}
}
public static <T, V> Map<T, V> getMap(Map<T, V> map) {
try {
Class<? extends Map> clazz = map.getClass();
Field m = clazz.getDeclaredField("m");
m.setAccessible(true);
return (Map<T, V>) m.get(map);
} catch (Throwable e) {
e.printStackTrace();
return map;
}
}
public static Class<?> getClass(String name) {
try {
return Class.forName(name);

View File

@ -55,6 +55,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@ -245,7 +246,7 @@ public abstract class WorldUtil {
final @Nullable String file,
final @NonNull RunnableVal<URL> whenDone
) {
plot.getHome(home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
plot.getHome(home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<>() {
@Override
public void run(OutputStream output) {
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
@ -255,16 +256,23 @@ public abstract class WorldUtil {
ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName());
zos.putNextEntry(ze);
try (NBTInputStream nis = new NBTInputStream(new GZIPInputStream(new FileInputStream(dat)))) {
CompoundTag tag = (CompoundTag) nis.readNamedTag().getTag();
CompoundTag data = (CompoundTag) tag.getValue().get("Data");
Map<String, Tag> map = ReflectionUtils.getMap(data.getValue());
map.put("SpawnX", new IntTag(home.getX()));
map.put("SpawnY", new IntTag(home.getY()));
map.put("SpawnZ", new IntTag(home.getZ()));
Map<String, Tag> tag = ((CompoundTag) nis.readNamedTag().getTag()).getValue();
Map<String, Tag> newMap = new HashMap<>();
for (Map.Entry<String, Tag> entry : tag.entrySet()) {
if (!entry.getKey().equals("Data")) {
newMap.put(entry.getKey(), entry.getValue());
continue;
}
Map<String, Tag> data = new HashMap<>(((CompoundTag) entry.getValue()).getValue());
data.put("SpawnX", new IntTag(home.getX()));
data.put("SpawnY", new IntTag(home.getY()));
data.put("SpawnZ", new IntTag(home.getZ()));
newMap.put("Data", new CompoundTag(data));
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (NBTOutputStream out = new NBTOutputStream(new GZIPOutputStream(baos, true))) {
//TODO Find what this should be called
out.writeNamedTag("Schematic????", tag);
out.writeNamedTag("Schematic????", new CompoundTag(newMap));
}
zos.write(baos.toByteArray());
}
@ -272,6 +280,7 @@ public abstract class WorldUtil {
}
setSpawn(spawn);
byte[] buffer = new byte[1024];
Set<BlockVector2> added = new HashSet<>();
for (Plot current : plot.getConnectedPlots()) {
Location bot = current.getBottomAbs();
Location top = current.getTopAbs();
@ -281,13 +290,14 @@ public abstract class WorldUtil {
int trz = top.getZ() >> 9;
Set<BlockVector2> files = getChunkChunks(bot.getWorldName());
for (BlockVector2 mca : files) {
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz && mca.getZ() <= trz) {
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz && mca.getZ() <= trz && !added.contains(mca)) {
final File file = getMcr(plot.getWorldName(), mca.getX(), mca.getZ());
if (file != null) {
//final String name = "r." + (x - cx) + "." + (z - cz) + ".mca";
String name = file.getName();
final ZipEntry ze = new ZipEntry("world" + File.separator + "region" + File.separator + name);
zos.putNextEntry(ze);
added.add(mca);
try (FileInputStream in = new FileInputStream(file)) {
int len;
while ((len = in.read(buffer)) > 0) {

View File

@ -22,6 +22,7 @@
"web.plot_merged": "<prefix><red>This plot is merged and therefore cannot be downloaded</red>",
"web.generating_link_failed": "<prefix><red>Failed to generate download link for plot <plot>!</red>",
"web.generation_link_success": "<prefix><gold>Download: <gray><click:open_url:<download>><download></click></gray> \n Deletion: <gray><click:open_url:<delete>><delete></click></gray>\n<red>Attention: Opening the deletion link will delete the file immediately.</red></gold>",
"web.generation_link_success_legacy_world": "<prefix><gold>Download: <gray><click:open_url:<url>><url></click></gray>",
"web.save_failed": "<prefix><red>Failed to save.</red>",
"web.load_null": "<prefix><gray>Please use </gray><dark_aqua><command> </dark_aqua><gray>to get a list of schematics.</gray>",
"web.load_failed": "<prefix><red>Failed to load schematic.</red>",