Search in sources :

Example 1 with Option

use of ca.xshade.questionmanager.Option 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)

Example 2 with Option

use of ca.xshade.questionmanager.Option in project Towny by ElgarL.

the class NationCommand method nationInviteTown.

private static void nationInviteTown(Player player, Nation nation, Town town) throws AlreadyRegisteredException {
    Plugin test = plugin.getServer().getPluginManager().getPlugin("Questioner");
    Resident townMayor = town.getMayor();
    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 JoinNationTask(townMayor, nation)));
        options.add(new Option(TownySettings.questionerDeny(), new ResidentNationQuestionTask(townMayor, nation) {

            @Override
            public void run() {
                TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_deny_invite"), getResident().getName()));
            }
        }));
        Question question = new Question(townMayor.getName(), String.format(TownySettings.getLangString("msg_invited"), nation.getName()), options);
        try {
            plugin.appendQuestion(questioner, question);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    } else {
        nation.addTown(town);
        plugin.resetCache();
        TownyUniverse.getDataSource().saveTown(town);
    }
}
Also used : ResidentNationQuestionTask(com.palmergames.bukkit.towny.questioner.ResidentNationQuestionTask) JoinNationTask(com.palmergames.bukkit.towny.questioner.JoinNationTask) Questioner(ca.xshade.bukkit.questioner.Questioner) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) Option(ca.xshade.questionmanager.Option) Question(ca.xshade.questionmanager.Question) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) EmptyNationException(com.palmergames.bukkit.towny.exceptions.EmptyNationException) EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) InvalidNameException(javax.naming.InvalidNameException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) Plugin(org.bukkit.plugin.Plugin)

Example 3 with Option

use of ca.xshade.questionmanager.Option in project Towny by ElgarL.

the class TownCommand method townInviteResident.

private static void townInviteResident(Town town, Resident newMember) throws AlreadyRegisteredException {
    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 JoinTownTask(newMember, town)));
        options.add(new Option(TownySettings.questionerDeny(), new ResidentTownQuestionTask(newMember, town) {

            @Override
            public void run() {
                TownyMessaging.sendTownMessage(getTown(), String.format(TownySettings.getLangString("msg_deny_invite"), getResident().getName()));
            }
        }));
        Question question = new Question(newMember.getName(), String.format(TownySettings.getLangString("msg_invited"), town.getName()), options);
        try {
            plugin.appendQuestion(questioner, question);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    } else
        try {
            townAddResident(town, newMember);
        } catch (AlreadyRegisteredException e) {
        }
}
Also used : JoinTownTask(com.palmergames.bukkit.towny.questioner.JoinTownTask) Questioner(ca.xshade.bukkit.questioner.Questioner) ArrayList(java.util.ArrayList) Option(ca.xshade.questionmanager.Option) ResidentTownQuestionTask(com.palmergames.bukkit.towny.questioner.ResidentTownQuestionTask) Question(ca.xshade.questionmanager.Question) InvalidNameException(javax.naming.InvalidNameException) Plugin(org.bukkit.plugin.Plugin)

Example 4 with Option

use of ca.xshade.questionmanager.Option 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)4 Option (ca.xshade.questionmanager.Option)4 Question (ca.xshade.questionmanager.Question)4 ArrayList (java.util.ArrayList)4 Plugin (org.bukkit.plugin.Plugin)4 InvalidNameException (javax.naming.InvalidNameException)3 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)2 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)2 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)2 ResidentTownQuestionTask (com.palmergames.bukkit.towny.questioner.ResidentTownQuestionTask)2 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)1 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)1 EmptyTownException (com.palmergames.bukkit.towny.exceptions.EmptyTownException)1 Resident (com.palmergames.bukkit.towny.object.Resident)1 JoinNationTask (com.palmergames.bukkit.towny.questioner.JoinNationTask)1 JoinTownTask (com.palmergames.bukkit.towny.questioner.JoinTownTask)1 PurgeQuestionTask (com.palmergames.bukkit.towny.questioner.PurgeQuestionTask)1 ResidentNationQuestionTask (com.palmergames.bukkit.towny.questioner.ResidentNationQuestionTask)1 TownQuestionTask (com.palmergames.bukkit.towny.questioner.TownQuestionTask)1 ResidentPurge (com.palmergames.bukkit.towny.tasks.ResidentPurge)1