Search in sources :

Example 1 with TownQuestionTask

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

the class TownCommand method townDelete.

public void townDelete(Player player, String[] split) {
    Town town = null;
    if (split.length == 0)
        try {
            Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
            town = resident.getTown();
        } catch (TownyException x) {
            TownyMessaging.sendErrorMsg(player, x.getMessage());
            return;
        }
    else
        try {
            if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOWN_DELETE.getNode()))
                throw new TownyException(TownySettings.getLangString("msg_err_admin_only_delete_town"));
            town = TownyUniverse.getDataSource().getTown(split[0]);
        } catch (TownyException x) {
            TownyMessaging.sendErrorMsg(player, x.getMessage());
            return;
        }
    // Use questioner to confirm.
    Plugin test = BukkitTools.getServer().getPluginManager().getPlugin("Questioner");
    if (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 TownQuestionTask(player, town) {

            @Override
            public void run() {
                TownyUniverse.getDataSource().removeTown(town);
                TownyMessaging.sendGlobalMessage(TownySettings.getDelTownMsg(town));
            }
        }));
        options.add(new Option(TownySettings.questionerDeny(), new TownQuestionTask(player, town) {

            @Override
            public void run() {
                TownyMessaging.sendMessage(getSender(), "Delete Aborted!");
            }
        }));
        Question question = new Question(player.getName(), "Do you really want to delete this town", options);
        try {
            plugin.appendQuestion(questioner, question);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    } else {
        TownyUniverse.getDataSource().removeTown(town);
        TownyMessaging.sendGlobalMessage(TownySettings.getDelTownMsg(town));
    }
}
Also used : ResidentTownQuestionTask(com.palmergames.bukkit.towny.questioner.ResidentTownQuestionTask) TownQuestionTask(com.palmergames.bukkit.towny.questioner.TownQuestionTask) Questioner(ca.xshade.bukkit.questioner.Questioner) ArrayList(java.util.ArrayList) Option(ca.xshade.questionmanager.Option) Question(ca.xshade.questionmanager.Question) InvalidNameException(javax.naming.InvalidNameException) 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 ResidentTownQuestionTask (com.palmergames.bukkit.towny.questioner.ResidentTownQuestionTask)1 TownQuestionTask (com.palmergames.bukkit.towny.questioner.TownQuestionTask)1 ArrayList (java.util.ArrayList)1 InvalidNameException (javax.naming.InvalidNameException)1 Plugin (org.bukkit.plugin.Plugin)1