Skip to content

Commit

Permalink
catch IOException in ExportCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
yqs112358 committed Aug 7, 2024
1 parent cb1e6a1 commit f893b59
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions
import net.minecraft.server.command.CommandManager.literal
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.Text
import java.io.IOException
import java.nio.file.Path
import java.util.*
import kotlin.io.path.pathString
Expand Down Expand Up @@ -51,20 +52,28 @@ object ExportCommand : BuildableCommand {
}
val dataExporter = DataExporter(params, exportAdapter, source)

val exportedFilePath: Path? = dataExporter.exportTo(config.getExportDir())
if (exportedFilePath == null) {
try {
val exportedFilePath: Path? = dataExporter.exportTo(config.getExportDir())
if (exportedFilePath == null) {
source.sendFeedback({
Text.translatable("text.ledger.export.failed").setStyle(TextColorPallet.primary)
}, false)
} else {
source.sendFeedback({
Text.translatable(
"text.ledger.export.completed",
exportedFilePath.pathString.literal()
.setStyle(TextColorPallet.primaryVariant)
).setStyle(TextColorPallet.primary)
}, false)
}
} catch (e: IOException) {
e.printStackTrace()
source.sendFeedback({
Text.translatable("text.ledger.export.failed").setStyle(TextColorPallet.primary)
}, false)
} else {
source.sendFeedback({
Text.translatable(
"text.ledger.export.completed",
exportedFilePath.pathString.literal()
.setStyle(TextColorPallet.primaryVariant)
).setStyle(TextColorPallet.primary)
}, false)
}

}
return 1
}
Expand Down

0 comments on commit f893b59

Please sign in to comment.