Search in sources :

Example 1 with PurgeQuestionTask

use of com.palmergames.bukkit.towny.questioner.PurgeQuestionTask in project Towny by ElgarL.

the class TownyAdminCommand method purge.

/**
	 * Remove residents who havn't logged in for X amount of days.
	 * 
	 * @param split
	 */
public void purge(String[] split) {
    if (split.length == 0) {
        // command was '/townyadmin purge'
        player.sendMessage(ChatTools.formatTitle("/townyadmin purge"));
        player.sendMessage(ChatTools.formatCommand("", "/townyadmin purge", "[number of days]", ""));
        player.sendMessage(ChatTools.formatCommand("", "", "Removes offline residents not seen for this duration.", ""));
        return;
    }
    int days = 1;
    try {
        days = Integer.parseInt(split[0]);
    } catch (NumberFormatException e) {
        TownyMessaging.sendErrorMsg(getSender(), TownySettings.getLangString("msg_error_must_be_int"));
        return;
    }
    // Use questioner to confirm.
    Plugin test = BukkitTools.getServer().getPluginManager().getPlugin("Questioner");
    if (this.sender instanceof Player && TownySettings.isUsingQuestioner() && test != null && test instanceof Questioner && test.isEnabled()) {
        Questioner questioner = (Questioner) test;
        questioner.loadClasses();
        List<Option> options = new ArrayList<Option>();
        options.add(new Option(TownySettings.questionerAccept(), new PurgeQuestionTask(plugin, this.sender, TimeTools.getMillis(days + "d"))));
        options.add(new Option(TownySettings.questionerDeny(), new PurgeQuestionTask(plugin, this.sender, TimeTools.getMillis(days + "d")) {

            @Override
            public void run() {
                TownyMessaging.sendMessage(getSender(), "Purge Aborted!");
            }
        }));
        Question question = new Question(this.sender.getName(), "Do you really want to perform this purge", options);
        try {
            plugin.appendQuestion(questioner, question);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    } else {
        // Run a purge in it's own thread
        new ResidentPurge(plugin, this.sender, TimeTools.getMillis(days + "d")).start();
    }
}
Also used : Player(org.bukkit.entity.Player) ResidentPurge(com.palmergames.bukkit.towny.tasks.ResidentPurge) Questioner(ca.xshade.bukkit.questioner.Questioner) ArrayList(java.util.ArrayList) Option(ca.xshade.questionmanager.Option) Question(ca.xshade.questionmanager.Question) PurgeQuestionTask(com.palmergames.bukkit.towny.questioner.PurgeQuestionTask) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) EmptyTownException(com.palmergames.bukkit.towny.exceptions.EmptyTownException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) Plugin(org.bukkit.plugin.Plugin)

Aggregations

Questioner (ca.xshade.bukkit.questioner.Questioner)1 Option (ca.xshade.questionmanager.Option)1 Question (ca.xshade.questionmanager.Question)1 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)1 EmptyTownException (com.palmergames.bukkit.towny.exceptions.EmptyTownException)1 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)1 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)1 PurgeQuestionTask (com.palmergames.bukkit.towny.questioner.PurgeQuestionTask)1 ResidentPurge (com.palmergames.bukkit.towny.tasks.ResidentPurge)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Player (org.bukkit.entity.Player)1 Plugin (org.bukkit.plugin.Plugin)1