diff --git a/src/main/java/com/nuclyon/technicallycoded/inventoryrollback/commands/inventoryrollback/ImportSubCmd.java b/src/main/java/com/nuclyon/technicallycoded/inventoryrollback/commands/inventoryrollback/ImportSubCmd.java index f624544..bc6f8a7 100644 --- a/src/main/java/com/nuclyon/technicallycoded/inventoryrollback/commands/inventoryrollback/ImportSubCmd.java +++ b/src/main/java/com/nuclyon/technicallycoded/inventoryrollback/commands/inventoryrollback/ImportSubCmd.java @@ -5,11 +5,16 @@ import com.nuclyon.technicallycoded.inventoryrollback.util.BackupConversionUtil; import me.danjono.inventoryrollback.config.MessageData; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import java.util.concurrent.atomic.AtomicBoolean; + public class ImportSubCmd extends IRPCommand { + private static final AtomicBoolean suggestConfirm = new AtomicBoolean(false); + public ImportSubCmd(InventoryRollbackPlus mainIn) { super(mainIn); } @@ -17,8 +22,29 @@ public ImportSubCmd(InventoryRollbackPlus mainIn) { @Override public void onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.hasPermission("inventoryrollbackplus.import")) { + + // Check that player confirms this operation + if (args.length < 2 || !args[1].equalsIgnoreCase("confirm")) { + // Send player help + sender.sendMessage(ChatColor.RED + "/" + label.toLowerCase() + " import " + ChatColor.BOLD + "confirm"); + + // Handle suggestions + suggestConfirm.set(true); + + // Reset suggestion availability after 10 seconds + this.main.getServer().getScheduler().runTaskLaterAsynchronously(this.main, () -> { + suggestConfirm.set(false); + }, 10 * 20); + + return; + } + + // Execute import Bukkit.getScheduler().runTaskAsynchronously(main, BackupConversionUtil::convertOldBackupData); + // Reset suggestion to not visible + suggestConfirm.set(false); + sender.sendMessage(MessageData.getPluginPrefix() + MessageData.getImportSuccess()); } else { sender.sendMessage(MessageData.getPluginPrefix() + MessageData.getNoPermission()); @@ -26,4 +52,8 @@ public void onCommand(CommandSender sender, Command cmd, String label, String[] return; } + public static boolean shouldShowConfirmOption() { + return suggestConfirm.get(); + } + }