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));
}
}
Aggregations