From 2230f28e97c6125f0d430e96870c079c08a9557e Mon Sep 17 00:00:00 2001 From: szymon Date: Sat, 8 Aug 2020 22:19:44 +0200 Subject: [PATCH] Statics.LOGGER.sendInfo is now used everywhere instead of source.sendFeedback --- .../commands/create/CleanupCommand.java | 9 +++++--- .../commands/permission/BlacklistCommand.java | 22 ++++++------------- .../commands/permission/WhitelistCommand.java | 19 ++++++---------- .../commands/restore/KillRestoreCommand.java | 5 ++--- .../commands/restore/ListBackupsCommand.java | 8 ++++--- .../restore/RestoreBackupCommand.java | 9 ++++---- 6 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/commands/create/CleanupCommand.java b/src/main/java/net/szum123321/textile_backup/commands/create/CleanupCommand.java index 7090eab..d76ddaf 100644 --- a/src/main/java/net/szum123321/textile_backup/commands/create/CleanupCommand.java +++ b/src/main/java/net/szum123321/textile_backup/commands/create/CleanupCommand.java @@ -22,6 +22,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; +import net.szum123321.textile_backup.Statics; import net.szum123321.textile_backup.core.create.BackupHelper; import net.szum123321.textile_backup.core.Utilities; @@ -32,9 +33,11 @@ public class CleanupCommand { } private static int execute(ServerCommandSource source) { - int a = BackupHelper.executeFileLimit(source, Utilities.getLevelName(source.getMinecraftServer())); - - source.sendFeedback(new LiteralText("Deleted: " + a + " files."), false); + Statics.LOGGER.sendInfo( + source, + "Deleted: {} files.", + BackupHelper.executeFileLimit(source, Utilities.getLevelName(source.getMinecraftServer())) + ); return 1; } diff --git a/src/main/java/net/szum123321/textile_backup/commands/permission/BlacklistCommand.java b/src/main/java/net/szum123321/textile_backup/commands/permission/BlacklistCommand.java index 8c40d74..14df9a3 100644 --- a/src/main/java/net/szum123321/textile_backup/commands/permission/BlacklistCommand.java +++ b/src/main/java/net/szum123321/textile_backup/commands/permission/BlacklistCommand.java @@ -8,8 +8,6 @@ import net.minecraft.command.arguments.EntityArgumentType; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.text.TranslatableText; import net.szum123321.textile_backup.Statics; public class BlacklistCommand { @@ -29,7 +27,7 @@ public class BlacklistCommand { } private static int help(ServerCommandSource source) { - source.sendFeedback(new LiteralText("Available command are: add [player], remove [player], list."), false); + Statics.LOGGER.sendInfo(source, "Available command are: add [player], remove [player], list."); return 1; } @@ -44,7 +42,7 @@ public class BlacklistCommand { builder.append(", "); } - source.sendFeedback(new LiteralText(builder.toString()), false); + Statics.LOGGER.sendInfo(source, builder.toString()); return 1; } @@ -53,8 +51,8 @@ public class BlacklistCommand { ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); if(Statics.CONFIG.playerBlacklist.contains(player.getEntityName())) { - ctx.getSource().sendFeedback(new TranslatableText("Player: %s is already blacklisted.", player.getEntityName()), false); - }else{ + Statics.LOGGER.sendInfo(ctx.getSource(), "Player: {} is already blacklisted.", player.getEntityName()); + } else { Statics.CONFIG.playerBlacklist.add(player.getEntityName()); ConfigManager.saveConfig(Statics.CONFIG); @@ -83,20 +81,14 @@ public class BlacklistCommand { ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); if(!Statics.CONFIG.playerBlacklist.contains(player.getEntityName())) { - ctx.getSource().sendFeedback(new TranslatableText("Player: %s newer was blacklisted.", player.getEntityName()), false); - }else{ + Statics.LOGGER.sendInfo(ctx.getSource(), "Player: {} newer was blacklisted.", player.getEntityName()); + } else { Statics.CONFIG.playerBlacklist.remove(player.getEntityName()); ConfigManager.saveConfig(Statics.CONFIG); - StringBuilder builder = new StringBuilder(); - - builder.append("Player: "); - builder.append(player.getEntityName()); - builder.append(" removed from the blacklist successfully."); - ctx.getSource().getMinecraftServer().getCommandManager().sendCommandTree(player); - Statics.LOGGER.sendInfo(ctx.getSource(), builder.toString()); + Statics.LOGGER.sendInfo(ctx.getSource(), "Player: {} removed from the blacklist successfully.", player.getEntityName()); } return 1; diff --git a/src/main/java/net/szum123321/textile_backup/commands/permission/WhitelistCommand.java b/src/main/java/net/szum123321/textile_backup/commands/permission/WhitelistCommand.java index 92b3795..aa4fa6b 100644 --- a/src/main/java/net/szum123321/textile_backup/commands/permission/WhitelistCommand.java +++ b/src/main/java/net/szum123321/textile_backup/commands/permission/WhitelistCommand.java @@ -29,7 +29,7 @@ public class WhitelistCommand { } private static int help(ServerCommandSource source){ - source.sendFeedback(new LiteralText("Available command are: add [player], remove [player], list."), false); + Statics.LOGGER.sendInfo(source, "Available command are: add [player], remove [player], list."); return 1; } @@ -44,7 +44,7 @@ public class WhitelistCommand { builder.append(", "); } - source.sendFeedback(new LiteralText(builder.toString()), false); + Statics.LOGGER.sendInfo(source, builder.toString()); return 1; } @@ -53,8 +53,8 @@ public class WhitelistCommand { ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); if(Statics.CONFIG.playerWhitelist.contains(player.getEntityName())) { - ctx.getSource().sendFeedback(new TranslatableText("Player: %s is already whitelisted.", player.getEntityName()), false); - }else{ + Statics.LOGGER.sendInfo(ctx.getSource(), "Player: {} is already whitelisted.", player.getEntityName()); + } else { Statics.CONFIG.playerWhitelist.add(player.getEntityName()); ConfigManager.saveConfig(Statics.CONFIG); @@ -83,19 +83,14 @@ public class WhitelistCommand { ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); if(!Statics.CONFIG.playerWhitelist.contains(player.getEntityName())) { - ctx.getSource().sendFeedback(new TranslatableText("Player: %s newer was on the whitelist.", player.getEntityName()), false); - }else{ + Statics.LOGGER.sendInfo(ctx.getSource(), "Player: {} newer was whitelisted.", player.getEntityName()); + } else { Statics.CONFIG.playerWhitelist.remove(player.getEntityName()); ConfigManager.saveConfig(Statics.CONFIG); - StringBuilder builder = new StringBuilder(); - - builder.append("Player: "); - builder.append(player.getEntityName()); - builder.append(" removed from the whitelist successfully."); ctx.getSource().getMinecraftServer().getCommandManager().sendCommandTree(player); - Statics.LOGGER.sendInfo(ctx.getSource(), builder.toString()); + Statics.LOGGER.sendInfo(ctx.getSource(), "Player: {} removed from the whitelist successfully.", player.getEntityName()); } return 1; diff --git a/src/main/java/net/szum123321/textile_backup/commands/restore/KillRestoreCommand.java b/src/main/java/net/szum123321/textile_backup/commands/restore/KillRestoreCommand.java index 902b6b9..8ea451a 100644 --- a/src/main/java/net/szum123321/textile_backup/commands/restore/KillRestoreCommand.java +++ b/src/main/java/net/szum123321/textile_backup/commands/restore/KillRestoreCommand.java @@ -21,7 +21,6 @@ package net.szum123321.textile_backup.commands.restore; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; import net.szum123321.textile_backup.Statics; public class KillRestoreCommand { @@ -30,13 +29,13 @@ public class KillRestoreCommand { .executes(ctx -> { if(Statics.restoreAwaitThread != null && Statics.restoreAwaitThread.isAlive()) { Statics.restoreAwaitThread.interrupt(); - ctx.getSource().sendFeedback(new LiteralText("Backup restoration successfully stopped"), false); + Statics.LOGGER.sendInfo(ctx.getSource(), "Backup restoration successfully stopped"); Statics.LOGGER.info("{} cancelled backup restoration.", ctx.getSource().getEntity() != null ? "Player: " + ctx.getSource().getName() : "SERVER" ); } else { - ctx.getSource().sendFeedback(new LiteralText("Failed to stop backup restoration"), false); + Statics.LOGGER.sendInfo(ctx.getSource(), "Failed to stop backup restoration"); } return 1; }); diff --git a/src/main/java/net/szum123321/textile_backup/commands/restore/ListBackupsCommand.java b/src/main/java/net/szum123321/textile_backup/commands/restore/ListBackupsCommand.java index 0ba8d48..dfbde8a 100644 --- a/src/main/java/net/szum123321/textile_backup/commands/restore/ListBackupsCommand.java +++ b/src/main/java/net/szum123321/textile_backup/commands/restore/ListBackupsCommand.java @@ -21,9 +21,10 @@ package net.szum123321.textile_backup.commands.restore; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; +import net.szum123321.textile_backup.Statics; import net.szum123321.textile_backup.core.restore.RestoreHelper; +import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -31,7 +32,7 @@ public class ListBackupsCommand { public static LiteralArgumentBuilder register() { return CommandManager.literal("list") .executes(ctx -> { StringBuilder builder = new StringBuilder(); - List backups = RestoreHelper.getAvailableBackups(ctx.getSource().getMinecraftServer()); + List backups = RestoreHelper.getAvailableBackups(ctx.getSource().getMinecraftServer()); if(backups.size() == 0) { builder.append("There a no backups available for this world."); @@ -39,6 +40,7 @@ public class ListBackupsCommand { builder.append("There is only one backup available: "); builder.append(backups.get(0).toString()); } else { + backups.sort(Comparator.comparing(RestoreHelper.RestoreableFile::getCreationTime)); Iterator iterator = backups.iterator(); builder.append("Available backups: "); @@ -50,7 +52,7 @@ public class ListBackupsCommand { } } - ctx.getSource().sendFeedback(new LiteralText(builder.toString()), false); + Statics.LOGGER.sendInfo(ctx.getSource(), builder.toString()); return 1; }); diff --git a/src/main/java/net/szum123321/textile_backup/commands/restore/RestoreBackupCommand.java b/src/main/java/net/szum123321/textile_backup/commands/restore/RestoreBackupCommand.java index 56e5ff7..c25dc4f 100644 --- a/src/main/java/net/szum123321/textile_backup/commands/restore/RestoreBackupCommand.java +++ b/src/main/java/net/szum123321/textile_backup/commands/restore/RestoreBackupCommand.java @@ -62,9 +62,9 @@ public class RestoreBackupCommand { ).executes(context -> { ServerCommandSource source = context.getSource(); - source.sendFeedback(new LiteralText("To restore given backup you have to provide exact creation time in format:"), false); - source.sendFeedback(new LiteralText("[YEAR]-[MONTH]-[DAY]_[HOUR].[MINUTE].[SECOND]"), false); - source.sendFeedback(new LiteralText("Example: 2020-08-05_10.58.33"), false); + Statics.LOGGER.sendInfo(source, "To restore given backup you have to provide exact creation time in format:"); + Statics.LOGGER.sendInfo(source, "[YEAR]-[MONTH]-[DAY]_[HOUR].[MINUTE].[SECOND]"); + Statics.LOGGER.sendInfo(source, "Example: 2020-08-05_10.58.33"); return 1; }); @@ -108,7 +108,8 @@ public class RestoreBackupCommand { Statics.restoreAwaitThread.start(); } else if(Statics.restoreAwaitThread != null && Statics.restoreAwaitThread.isAlive()) { - source.sendFeedback(new LiteralText("Someone has already started another restoration."), false); + Statics.LOGGER.sendInfo(source, "Someone has already started another restoration."); + return 0; }