Fix schematic v3 converter: expect list type COMPOUND but END_TYPE
This commit is contained in:
1 parent
555d7a781c
commit
1d2a49025e
4 files changed
+50
-13
No files matched your search
@@ -5,6 +5,7 @@ import com.mojang.brigadier.Command;
|
|||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import io.ib67.sfcraft.config.SFConfig;
|
import io.ib67.sfcraft.config.SFConfig;
|
||||||
|
import io.ib67.sfcraft.inject.MinecraftServerSupplier;
|
||||||
import io.ib67.sfcraft.module.SignatureService;
|
import io.ib67.sfcraft.module.SignatureService;
|
||||||
import io.ib67.sfcraft.module.supervisor.WebHandler;
|
import io.ib67.sfcraft.module.supervisor.WebHandler;
|
||||||
import io.ib67.sfcraft.util.Helper;
|
import io.ib67.sfcraft.util.Helper;
|
||||||
@@ -43,6 +44,8 @@ public class SchematicUploader extends WebHandler {
|
|||||||
SFConfig config;
|
SFConfig config;
|
||||||
@Inject
|
@Inject
|
||||||
SignatureService signatureService;
|
SignatureService signatureService;
|
||||||
|
@Inject
|
||||||
|
MinecraftServerSupplier serverSupplier;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -103,12 +106,19 @@ public class SchematicUploader extends WebHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var signRaw = Base64.getUrlDecoder().decode(context.queryParam("sign"));
|
var signRaw = Base64.getUrlDecoder().decode(context.queryParam("sign"));
|
||||||
var verifiedSign = signatureService.readSignature(Unpooled.wrappedBuffer(signRaw));
|
try {
|
||||||
if ((verifiedSign.permission() & PERMISSION_UPLOAD_SCHEMATICS) == 0) {
|
var verifiedSign = signatureService.readSignature(Unpooled.wrappedBuffer(signRaw));
|
||||||
context.result("Permission denied!");
|
if ((verifiedSign.permission() & PERMISSION_UPLOAD_SCHEMATICS) == 0) {
|
||||||
|
context.result("Permission denied!");
|
||||||
|
context.status(403);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
context.attribute("sign", verifiedSign);
|
||||||
|
} catch (Exception e) {
|
||||||
|
context.result("Invalid signature. Please re-run /upload schematic in game.");
|
||||||
|
context.status(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
context.attribute("sign", verifiedSign);
|
|
||||||
var files = context.uploadedFileMap();
|
var files = context.uploadedFileMap();
|
||||||
var name = context.pathParam("name");
|
var name = context.pathParam("name");
|
||||||
files.forEach((k, v) -> handleUploadSchematic(context, name, v));
|
files.forEach((k, v) -> handleUploadSchematic(context, name, v));
|
||||||
@@ -128,24 +138,23 @@ public class SchematicUploader extends WebHandler {
|
|||||||
if (fileName.length() <= 10) return;
|
if (fileName.length() <= 10) return;
|
||||||
var baseFileName = Helper.cleanFileName(fileName.substring(0, fileName.length() - 10));
|
var baseFileName = Helper.cleanFileName(fileName.substring(0, fileName.length() - 10));
|
||||||
var sign = context.<SignatureService.Signature>attribute("sign");
|
var sign = context.<SignatureService.Signature>attribute("sign");
|
||||||
//var player = serverSupplier.get().getPlayerManager().getPlayer(sign.issuer());
|
var player = serverSupplier.get().getPlayerManager().getPlayer(sign.issuer());
|
||||||
ServerPlayerEntity player = null;
|
log.info("Handling file {} from player {}", fileName, sign.issuer());
|
||||||
if (fileName.endsWith(".schematic") || fileName.endsWith(".schem")) {
|
if (fileName.endsWith(".schematic") || fileName.endsWith(".schem")) {
|
||||||
Files.write(SCHEMATIC_DIR.resolve(baseFileName + ".schematic"), file.content().readAllBytes());
|
Files.write(SCHEMATIC_DIR.resolve(baseFileName + ".schematic"), file.content().readAllBytes());
|
||||||
log.info("Saved " + fileName + " as a schematic.");
|
log.info("Saved " + fileName + " as a schematic.");
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.sendMessage(Text.literal("Schematic " + baseFileName + " has been saved!").withColor(Color.GREEN.getRGB()));
|
player.sendMessage(Text.literal(sign.issuer()+": Schematic " + baseFileName + " has been saved! Use //schem list to find it").withColor(Color.GREEN.getRGB()));
|
||||||
}
|
}
|
||||||
} else if (fileName.endsWith(".litematic")) {
|
} else if (fileName.endsWith(".litematic")) {
|
||||||
log.info("Handling new litematic: {}", fileName);
|
try (var converter = new LitematicConverterV3(file.content(), new NbtSizeTracker(config.maxSchematicSize, 64))) {
|
||||||
try (var converter = new LitematicConverterV3(file.content(), new NbtSizeTracker(config.maxSchematicSize, 16))) {
|
|
||||||
converter.read((name, nbt) -> {
|
converter.read((name, nbt) -> {
|
||||||
name = baseFileName + "-" + name + ".schematic";
|
name = baseFileName + "-" + name + ".schematic";
|
||||||
try {
|
try {
|
||||||
NbtIo.writeCompressed(nbt, SCHEMATIC_DIR.resolve(name));
|
NbtIo.writeCompressed(nbt, SCHEMATIC_DIR.resolve(name));
|
||||||
log.info("Schematic " + name + " has been saved!");
|
log.info(sign.issuer()+": Schematic " + name + " has been saved!");
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.sendMessage(Text.literal("Schematic " + name + " has been saved!").withColor(Color.GREEN.getRGB()));
|
player.sendMessage(Text.literal("Schematic " + name + " has been saved! Use //schem list to find it").withColor(Color.GREEN.getRGB()));
|
||||||
}
|
}
|
||||||
context.result("Success!");
|
context.result("Success!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package io.ib67.sfcraft.util;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NbtElement;
|
||||||
|
import net.minecraft.nbt.NbtList;
|
||||||
|
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TypedNbtList extends NbtList {
|
||||||
|
public TypedNbtList(List<NbtElement> list, byte type) {
|
||||||
|
super(list, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
output.writeByte(this.getHeldType());
|
||||||
|
output.writeInt(this.size());
|
||||||
|
|
||||||
|
for (NbtElement nbtElement : this) {
|
||||||
|
nbtElement.write(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package io.ib67.sfcraft.util.litematic;
|
package io.ib67.sfcraft.util.litematic;
|
||||||
|
|
||||||
|
import io.ib67.sfcraft.util.TypedNbtList;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import net.minecraft.nbt.*;
|
import net.minecraft.nbt.*;
|
||||||
|
import org.apache.commons.compress.utils.Lists;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -76,7 +78,8 @@ public class LitematicConverter implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected NbtList convertToWETileEntities(NbtList tileEntities) {
|
protected NbtList convertToWETileEntities(NbtList tileEntities) {
|
||||||
var weTEs = new NbtList();
|
var weTEs = new TypedNbtList(Lists.newArrayList(), NbtElement.COMPOUND_TYPE);
|
||||||
|
|
||||||
for (NbtElement _tileEntity : tileEntities) {
|
for (NbtElement _tileEntity : tileEntities) {
|
||||||
var weTE = new NbtCompound();
|
var weTE = new NbtCompound();
|
||||||
var tE = (NbtCompound) _tileEntity;
|
var tE = (NbtCompound) _tileEntity;
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
accessWidener v2 named
|
accessWidener v2 named
|
||||||
mutable field net/minecraft/item/Item registryEntry Lnet/minecraft/registry/entry/RegistryEntry$Reference;
|
mutable field net/minecraft/item/Item registryEntry Lnet/minecraft/registry/entry/RegistryEntry$Reference;
|
||||||
|
accessible method net/minecraft/nbt/NbtList <init> (Ljava/util/List;B)V
|
||||||
Reference in new issue
Block a user