Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the dump command #19

Open
wants to merge 1 commit into
base: 1.19.4
Choose a base branch
from

Conversation

haykam821
Copy link
Contributor

This pull request adds a command that can be used to export entity, block entity, or command storage NBT to a file.

For example:

  • /dump entity 2a99a580-41d7-4c93-aa87-abd90664ff52 armor_stand
  • /dump block 18 -60 20 chest
  • /dump storage taters nucleoid:tater_box

@Gegy Gegy self-requested a review June 8, 2023 20:32
}
}

private static Path getAndCheckDataPath(Path path, Identifier identifier, String extension) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we should probably apply this to the map template exporter, too 😅

var path = getAndCheckDataPath(generatedPath, identifier, FILE_EXTENSION);

var json = NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, nbt);
System.out.println(json);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed?

}

public static CompletableFuture<Void> saveToExport(MinecraftServer server, NbtCompound nbt, Identifier identifier) {
return CompletableFuture.supplyAsync(() -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: CompletableFuture.runAsync(() -> {})

Comment on lines +44 to +45
try (var output = Files.newOutputStream(path)) {
var jsonWriter = new JsonWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try (var output = Files.newOutputStream(path)) {
var jsonWriter = new JsonWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
try (var writer = new JsonWriter(Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {

jsonWriter.setIndent(" ");

JsonHelper.writeSorted(jsonWriter, json, DataProvider.JSON_KEY_SORTING_COMPARATOR);
jsonWriter.flush();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be needed if including the JsonWriter in the try-with-resources


var future = DumpExporter.saveToExport(source.getServer(), nbt, identifier);

future.handle((v, throwable) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whenCompleteAsync(..., server)? Sending messages off-thread has potential to explode 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants