From 7b0a6b7497dbbb8a78e07d253204a4e9e5fa805c Mon Sep 17 00:00:00 2001 From: luiz-otavio Date: Sun, 27 Feb 2022 08:11:48 -0300 Subject: [PATCH] feat: add some utilities messages on each case of compressor command --- src/main/java/foxz/command/CmdCompressor.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/foxz/command/CmdCompressor.java b/src/main/java/foxz/command/CmdCompressor.java index 630d332d5..d022d9b84 100644 --- a/src/main/java/foxz/command/CmdCompressor.java +++ b/src/main/java/foxz/command/CmdCompressor.java @@ -37,6 +37,10 @@ public class CmdCompressor extends ChMcLogger { permissions = {OpOnly.class} ) public boolean onConvert(String[] args) throws ExecutionException, InterruptedException, TimeoutException { + if (args.length == 0) { + sendmessage("Usage: /noppes compressor update [|all] [json|zstd]"); + return true; + } if (args.length == 1) { sendmessage("Please specify the type of compression to use"); return true; @@ -56,12 +60,14 @@ public class CmdCompressor extends ChMcLogger { File directory = PlayerDataController.instance.getSaveDir(); if (args[0].equalsIgnoreCase("all")) { + sendmessage("Converting all files in the current directory to compressed files"); + for (File file : directory.listFiles()) { if (file.isDirectory()) { continue; } - if (!file.getName().endsWith(".json") && type.equalsIgnoreCase("json")) { + if (file.getName().endsWith(".json") && type.equalsIgnoreCase("zstd")) { submit(() -> { try { NBTTagCompound compound = NBTJsonUtil.LoadFile(file); @@ -74,24 +80,21 @@ public class CmdCompressor extends ChMcLogger { compressed.toPath(), bytes, StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE ); } catch (Exception exception) { exception.printStackTrace(); } }); - } else if (!file.getName().endsWith(".zstd") && type.equalsIgnoreCase("zstd")) { + } + + if (file.getName().endsWith(".zstd") && type.equalsIgnoreCase("json")) { submit(() -> { try { NBTTagCompound compound = ZstdCompressor.readCompressCompound( new RandomAccessFile(file, "r") ); - if (compound == null) { - return; - } - File compressed = new File(file.getParentFile(), file.getName().replace(".zstd", ".json")); NBTJsonUtil.SaveFile(compressed, compound); @@ -135,7 +138,6 @@ public class CmdCompressor extends ChMcLogger { compressed.toPath(), bytes, StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE );