Add suggestion after schematics are uploaded
This commit is contained in:
1 parent
5cf8c57f5a
commit
547b58f21a
1 file changed
+13
-7
@@ -143,19 +143,15 @@ public class SchematicUploader extends WebHandler {
|
|||||||
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) {
|
sendSuccess(player, baseFileName);
|
||||||
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")) {
|
||||||
try (var converter = new LitematicConverterV3(file.content(), new NbtSizeTracker(config.maxSchematicSize, 64))) {
|
try (var converter = new LitematicConverterV3(file.content(), new NbtSizeTracker(config.maxSchematicSize, 64))) {
|
||||||
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(sign.issuer()+": Schematic " + name + " has been saved!");
|
log.info(sign.issuer() + ": Schematic " + name + " has been saved!");
|
||||||
if (player != null) {
|
sendSuccess(player, name);
|
||||||
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) {
|
||||||
log.error("Error occurred when serializing .litematic to disk.", e);
|
log.error("Error occurred when serializing .litematic to disk.", e);
|
||||||
@@ -171,4 +167,14 @@ public class SchematicUploader extends WebHandler {
|
|||||||
}
|
}
|
||||||
context.result("Uploaded!");
|
context.result("Uploaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void sendSuccess(ServerPlayerEntity player, String fileName) {
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.sendMessage(Text.literal("Schematic " + fileName + " has been saved! Use //schem list to find it").withColor(Color.GREEN.getRGB()));
|
||||||
|
player.sendMessage(Text.literal("Or you can click this").styled(it->it.withUnderline(true).withClickEvent(
|
||||||
|
new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "//schem load " + fileName)
|
||||||
|
)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user