Skip to content

Commit

Permalink
Add import command (suggestion #46)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicallyCoded committed Nov 4, 2021
1 parent 84ac124 commit ee29d22
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,55 @@
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);
}

@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());
}
return;
}

public static boolean shouldShowConfirmOption() {
return suggestConfirm.get();
}

}

0 comments on commit ee29d22

Please sign in to comment.