diff options
author | Keuin <[email protected]> | 2020-04-23 15:11:05 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2020-04-23 15:11:05 +0800 |
commit | 597cc299f02ae4b9577d9cccc5653570fedca639 (patch) | |
tree | 1e78065fb5f7de498294eaecaf28a5fed34b929b | |
parent | 720e8ec8eeb69d24afbb6b14068563cde2d470f0 (diff) |
Optimize code redundancy.
6 files changed, 16 insertions, 103 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java b/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java index 0407520..a9dcb38 100644 --- a/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java +++ b/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java @@ -7,7 +7,6 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; public final class KBCommandRegister { - // First make method to register public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { // register /kb and /kb help for help menu @@ -29,64 +28,5 @@ public final class KBCommandRegister { // register /kb cancel for cancelling the execution to be confirmed. OP is required. dispatcher.register(CommandManager.literal("kb").then(CommandManager.literal("cancel").requires(PermissionValidator::op).executes(KBCommandHandler::cancel))); -// LiteralCommandNode<ServerCommandSource> basenode = dispatcher.register(literal("findBiome") -// .then(argument("biome_identifier", identifier()).suggests(BiomeCompletionProvider.BIOMES) // We use Biome suggestions for identifier argument -// .then(argument("distance", integer(0, 20000)) -// .executes(ctx -> execute(ctx.getSource(), getIdentifier(ctx, "biome_identifier"), getInteger(ctx, "distance")))) -// .executes(ctx -> execute(ctx.getSource(), getIdentifier(ctx, "biome_identifier"), 1000)))); -// // Register redirect -// dispatcher.register(literal("biome") -// .redirect(basenode)); } - -// // Beginning of the method -// private static int execute(ServerCommandSource source, Identifier biomeId, int range) throws CommandSyntaxException { -// Biome biome = Registry.BIOME.get(biomeId); -// -// if(biome == null) { // Since the argument is an Identifier we need to check if the identifier actually exists in the registry -// throw new SimpleCommandExceptionType(new TranslatableText("biome.not.exist", biomeId)).create(); -// } -// -// List<Biome> bio = new ArrayList<Biome>(); -// bio.add(biome); -// -// ServerWorld world = source.getWorld(); -// -// BiomeSource bsource = world.getChunkManager().getChunkGenerator().getBiomeSource(); -// -// BlockPos loc = new BlockPos(source.getPosition()); -// // Now here is the heaviest part of the method. -// BlockPos pos = bsource.locateBiome(loc.getX(), loc.getZ(), range, bio, new Random(world.getSeed())); -// -// // Since this method can return null if it failed to find a biome -// if(pos == null) { -// throw new SimpleCommandExceptionType(new TranslatableText("biome.notfound", biome.getTranslationKey())).create(); -// } -// -// int distance = MathHelper.floor(getDistance(loc.getX(), loc.getZ(), pos.getX(), pos.getZ())); -// // Popup text that can suggest commands. This is the exact same system that /locate uses. -// Text teleportButtonPopup = Texts.bracketed(new TranslatableText("chat.coordinates", new Object[] { pos.getX(), "~", pos.getZ()})).styled((style_1x) -> { -// style_1x.setColor(Formatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + pos.getX() + " ~ " + pos.getZ())).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("chat.coordinates.tooltip", new Object[0]))); -// }); -// -// source.sendFeedback(new TranslatableText("commands.locate.success", new Object[] { new TranslatableText(Registry.BIOME.get(biomeId).getTranslationKey()), teleportButtonPopup, distance}), false); -// -// return 1; -// } -// // Just a normal old 2d distance method. -// private static float getDistance(int int_1, int int_2, int int_3, int int_4) { -// int int_5 = int_3 - int_1; -// int int_6 = int_4 - int_2; -// -// return MathHelper.sqrt((float) (int_5 * int_5 + int_6 * int_6)); -// } -// -// public static class BiomeCompletionProvider { -// // This provides suggestions of what biomes can be selected. Since this uses the registry, mods that add new biomes will work without modification. -// public static final SuggestionProvider<ServerCommandSource> BIOMES = SuggestionProviders.register(new Identifier("biomes"), (ctx, builder) -> { -// Registry.BIOME.getIds().stream().forEach(identifier -> builder.suggest(identifier.toString(), new TranslatableText(Registry.BIOME.get(identifier).getTranslationKey()))); -// return builder.buildFuture(); -// }); -// -// } } diff --git a/src/main/java/com/keuin/kbackupfabric/KBMain.java b/src/main/java/com/keuin/kbackupfabric/KBMain.java deleted file mode 100644 index f8a61f1..0000000 --- a/src/main/java/com/keuin/kbackupfabric/KBMain.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.keuin.kbackupfabric; - -public final class KBMain { - /** - * Perform real backup process. - * - * @param backupName the backup name. - * @return true if success, false if failed. - */ - public static boolean backup(String backupName) { - - return true; - } - - /** - * Perform real restore process. - * - * @param backupName the backup name. - * @return true if success, false if failed. - */ - public static boolean restore(String backupName) { - return true; - } -} diff --git a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java index e76155f..8c8a687 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java @@ -17,8 +17,8 @@ public final class PrintUtil { private static final Object syncInfo = new Object(); private static final Object syncMessage = new Object(); - public static CommandContext<ServerCommandSource> message(CommandContext<ServerCommandSource> context, String messageText) { - return message(context, messageText, false); + public static void message(CommandContext<ServerCommandSource> context, String messageText) { + message(context, messageText, false); } public static CommandContext<ServerCommandSource> message(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps) { diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java index 1ceeb60..fec4436 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java @@ -43,7 +43,7 @@ public final class ZipUtil { else { // 压缩目录中的文件或子目录 File[] childFileList = file.listFiles(); - if(childFileList != null) { + if (childFileList != null) { for (File value : childFileList) zip(srcRootDir, value, zos); } @@ -56,7 +56,7 @@ public final class ZipUtil { * @param srcPath 要压缩的源文件路径。如果是目录,则将递归压缩这个目录及其所有子文件、子目录树。 * @param zipPath 压缩文件保存的路径。注意:zipPath不能是srcPath路径下的子文件夹 * @param zipFileName 压缩文件名 - * @throws IOException IO Error + * @throws IOException IO Error * @throws ZipUtilException General exception, such as loop recursion or invalid input. */ public static void zip(String srcPath, String zipPath, String zipFileName) throws IOException, ZipUtilException { @@ -76,8 +76,8 @@ public final class ZipUtil { //判断压缩文件保存的路径是否存在,如果不存在,则创建目录 File zipDir = new File(zipPath); if (!zipDir.exists() || !zipDir.isDirectory()) { - if(!zipDir.mkdirs()) { - throw new IOException(String.format("Failed to make directory tree %s",zipDir.toString())); + if (!zipDir.mkdirs()) { + throw new IOException(String.format("Failed to make directory tree %s", zipDir.toString())); } } @@ -89,8 +89,8 @@ public final class ZipUtil { SecurityManager securityManager = new SecurityManager(); securityManager.checkDelete(zipFilePath); //删除已存在的目标文件 - if(!zipFile.delete()) { - throw new IOException(String.format("Failed to delete existing file %s",zipFile.toString())); + if (!zipFile.delete()) { + throw new IOException(String.format("Failed to delete existing file %s", zipFile.toString())); } } @@ -143,8 +143,8 @@ public final class ZipUtil { // 创建解压缩文件保存的路径 File unzipFileDir = new File(unzipFilePath); if (!unzipFileDir.exists() || !unzipFileDir.isDirectory()) { - if(!unzipFileDir.mkdirs()) - throw new IOException(String.format("Failed to make directory tree %s",unzipFileDir.toString())); + if (!unzipFileDir.mkdirs()) + throw new IOException(String.format("Failed to make directory tree %s", unzipFileDir.toString())); } // 开始解压 @@ -173,8 +173,8 @@ public final class ZipUtil { entryDir = new File(entryDirPath); // 如果文件夹路径不存在,则创建文件夹 if (!entryDir.exists() || !entryDir.isDirectory()) { - if(!entryDir.mkdirs()) - throw new IOException(String.format("Failed to make directory tree %s",entryDir.toString())); + if (!entryDir.mkdirs()) + throw new IOException(String.format("Failed to make directory tree %s", entryDir.toString())); } // 创建解压文件 @@ -184,13 +184,13 @@ public final class ZipUtil { SecurityManager securityManager = new SecurityManager(); securityManager.checkDelete(entryFilePath); // 删除已存在的目标文件 - if(!entryFile.delete()) - throw new IOException(String.format("Failed to delete existing file %s",entryFile.toString())); + if (!entryFile.delete()) + throw new IOException(String.format("Failed to delete existing file %s", entryFile.toString())); } if (entry.isDirectory()) { // If the entry is a directory, we make its corresponding directory. - if(!entryFile.mkdir()) - throw new IOException(String.format("Failed to create directory %s",entryFile.toString())); + if (!entryFile.mkdir()) + throw new IOException(String.format("Failed to create directory %s", entryFile.toString())); } else { // Is a file, we write the data // 写入文件 diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtilException.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtilException.java index 85bfec5..b31272d 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtilException.java +++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtilException.java @@ -1,8 +1,6 @@ package com.keuin.kbackupfabric.util; public class ZipUtilException extends Exception { - private static final long serialVersionUID = 1L; - public ZipUtilException() { } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0d471c0..18dfd31 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,7 +21,6 @@ }, "mixins": [ ], - "depends": { "fabricloader": ">=0.7.4", "fabric": "*", |