Search in sources :

Example 56 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class TownyAdminCommand method parseAdminUnclaimCommand.

public void parseAdminUnclaimCommand(String[] split) {
    if (split.length == 1 && split[0].equalsIgnoreCase("?")) {
        for (String line : ta_unclaim) ((CommandSender) getSender()).sendMessage(line);
    } else {
        if (isConsole) {
            sender.sendMessage("[Towny] InputError: This command was designed for use in game only.");
            return;
        }
        try {
            if (TownyUniverse.isWarTime())
                throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
            List<WorldCoord> selection;
            selection = AreaSelectionUtil.selectWorldCoordArea(null, new WorldCoord(player.getWorld().getName(), Coord.parseCoord(player)), split);
            selection = AreaSelectionUtil.filterWildernessBlocks(selection);
            new TownClaim(plugin, player, null, selection, false, false, true).start();
        } catch (TownyException x) {
            TownyMessaging.sendErrorMsg(player, x.getMessage());
            return;
        }
    }
}
Also used : TownClaim(com.palmergames.bukkit.towny.tasks.TownClaim) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 57 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class TownyCommand method parseTownyCommand.

private void parseTownyCommand(Player player, String[] split) {
    if (split.length == 0) {
        for (String line : towny_general_help) player.sendMessage(line);
        return;
    } else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help")) {
        for (String line : towny_help) player.sendMessage(Colors.strip(line));
        return;
    }
    try {
        if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY.getNode(split[0].toLowerCase())))
            throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
        if (split[0].equalsIgnoreCase("map"))
            if (split.length > 1 && split[1].equalsIgnoreCase("big"))
                TownyAsciiMap.generateAndSend(plugin, player, 18);
            else
                showMap(player);
        else if (split[0].equalsIgnoreCase("prices")) {
            Town town = null;
            if (split.length > 1) {
                try {
                    town = TownyUniverse.getDataSource().getTown(split[1]);
                } catch (NotRegisteredException x) {
                    sendErrorMsg(player, x.getMessage());
                    return;
                }
            } else if (split.length == 1)
                try {
                    Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                    town = resident.getTown();
                } catch (NotRegisteredException x) {
                }
            for (String line : getTownyPrices(town)) player.sendMessage(line);
        } else if (split[0].equalsIgnoreCase("top")) {
            TopCommand(player, StringMgmt.remFirstArg(split));
        } else if (split[0].equalsIgnoreCase("tree")) {
            consoleUseOnly(player);
        } else if (split[0].equalsIgnoreCase("time")) {
            TownyMessaging.sendMsg(player, "Time until a New Day: " + TimeMgmt.formatCountdownTime(TownyTimerHandler.townyTime()));
        } else if (split[0].equalsIgnoreCase("universe")) {
            for (String line : getUniverseStats()) player.sendMessage(line);
        } else if (split[0].equalsIgnoreCase("version") || split[0].equalsIgnoreCase("v")) {
            player.sendMessage(towny_version);
        } else if (split[0].equalsIgnoreCase("war")) {
            boolean war = TownyWar(StringMgmt.remFirstArg(split));
            for (String line : towny_war) player.sendMessage(Colors.strip(line));
            if (!war)
                sendErrorMsg(player, "The world isn't currently at war.");
            towny_war.clear();
        } else if (split[0].equalsIgnoreCase("spy")) {
            if (plugin.isPermissions() && TownyUniverse.getPermissionSource().has(player, PermissionNodes.TOWNY_CHAT_SPY.getNode())) {
                if (plugin.hasPlayerMode(player, "spy"))
                    plugin.removePlayerMode(player);
                else
                    plugin.setPlayerMode(player, split, true);
            } else
                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_command_disable"));
        } else
            sendErrorMsg(player, "Invalid sub command.");
    } catch (TownyException e) {
        TownyMessaging.sendErrorMsg(player, e.getMessage());
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 58 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class HealthRegenTimerTask method run.

@Override
public void run() {
    if (TownyUniverse.isWarTime())
        return;
    for (Player player : server.getOnlinePlayers()) {
        if (player.getHealth() <= 0)
            continue;
        Coord coord = Coord.parseCoord(player);
        try {
            TownyWorld world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
            TownBlock townBlock = world.getTownBlock(coord);
            if (CombatUtil.isAlly(townBlock.getTown(), TownyUniverse.getDataSource().getResident(player.getName()).getTown()))
                if (// only regen if not in an arena
                !townBlock.getType().equals(TownBlockType.ARENA))
                    incHealth(player);
        } catch (TownyException x) {
        }
    }
//if (TownySettings.getDebug())
//	System.out.println("[Towny] Debug: Health Regen");
}
Also used : Coord(com.palmergames.bukkit.towny.object.Coord) Player(org.bukkit.entity.Player) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 59 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class PlotClaim method run.

@Override
public void run() {
    int claimed = 0;
    if (player != null)
        TownyMessaging.sendMsg(player, "Processing " + ((claim) ? "Plot Claim..." : "Plot unclaim..."));
    if (selection != null) {
        for (WorldCoord worldCoord : selection) {
            // Make sure this is a valid world (mainly when unclaiming).
            try {
                this.world = worldCoord.getTownyWorld();
            } catch (NotRegisteredException e) {
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_err_not_configured"));
                continue;
            }
            try {
                if (claim) {
                    if (residentClaim(worldCoord))
                        claimed++;
                } else {
                    residentUnclaim(worldCoord);
                }
            } catch (EconomyException e) {
                /*
					 * Can't pay, but try the rest as we may be
					 * re-possessing and claiming for personal plots.
					 */
                TownyMessaging.sendErrorMsg(player, e.getError());
            } catch (TownyException x) {
                TownyMessaging.sendErrorMsg(player, x.getMessage());
            }
        }
    } else if (!claim) {
        residentUnclaimAll();
    }
    if (player != null) {
        if (claim) {
            if ((selection != null) && (selection.size() > 0) && (claimed > 0))
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_claimed") + ((selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
            else
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_not_claimed_1"));
        } else if (selection != null)
            TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_unclaimed") + ((selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
        else
            TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_unclaimed"));
    }
    TownyUniverse.getDataSource().saveResident(resident);
    plugin.resetCache();
}
Also used : EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 60 with TownyException

use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.

the class PlotClaim method residentClaim.

private boolean residentClaim(WorldCoord worldCoord) throws TownyException, EconomyException {
    //if (resident.hasTown())
    try {
        TownBlock townBlock = worldCoord.getTownBlock();
        Town town = townBlock.getTown();
        if ((resident.hasTown() && (resident.getTown() != town) && (!townBlock.getType().equals(TownBlockType.EMBASSY))) || ((!resident.hasTown()) && (!townBlock.getType().equals(TownBlockType.EMBASSY))))
            throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
        try {
            Resident owner = townBlock.getResident();
            if (townBlock.getPlotPrice() != -1) {
                if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), owner, "Plot - Buy From Seller"))
                    throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
                int maxPlots = TownySettings.getMaxResidentPlots(resident);
                if (maxPlots >= 0 && resident.getTownBlocks().size() + 1 > maxPlots)
                    throw new TownyException(String.format(TownySettings.getLangString("msg_max_plot_own"), maxPlots));
                TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(resident.getName(), owner.getName(), townBlock.getPlotPrice()));
                townBlock.setPlotPrice(-1);
                townBlock.setResident(resident);
                // Set the plot permissions to mirror the new owners.
                townBlock.setType(townBlock.getType());
                TownyUniverse.getDataSource().saveResident(owner);
                TownyUniverse.getDataSource().saveTownBlock(townBlock);
                // Update any caches for this WorldCoord
                plugin.updateCache(worldCoord);
                return true;
            } else if (player.hasPermission(PermissionNodes.TOWNY_COMMAND_PLOT_ASMAYOR.getNode())) {
                if (TownySettings.isUsingEconomy() && !town.payTo(0.0, owner, "Plot - Buy Back"))
                    throw new TownyException(TownySettings.getLangString("msg_town_no_money_purchase_plot"));
                TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(town.getName(), owner.getName(), 0.0));
                townBlock.setResident(null);
                townBlock.setPlotPrice(-1);
                // Set the plot permissions to mirror the towns.
                townBlock.setType(townBlock.getType());
                TownyUniverse.getDataSource().saveResident(owner);
                // Update the townBlock data file so it's no longer using custom settings.
                TownyUniverse.getDataSource().saveTownBlock(townBlock);
                return true;
            } else {
                //Should never reach here.
                throw new AlreadyRegisteredException(String.format(TownySettings.getLangString("msg_already_claimed"), owner.getName()));
            }
        } catch (NotRegisteredException e) {
            if (townBlock.getPlotPrice() == -1)
                throw new TownyException(TownySettings.getLangString("msg_err_plot_nfs"));
            double bankcap = TownySettings.getTownBankCap();
            if (bankcap > 0) {
                if (townBlock.getPlotPrice() + town.getHoldingBalance() > bankcap)
                    throw new TownyException(String.format(TownySettings.getLangString("msg_err_deposit_capped"), bankcap));
            }
            if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), town, "Plot - Buy From Town"))
                throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
            townBlock.setPlotPrice(-1);
            townBlock.setResident(resident);
            // Set the plot permissions to mirror the new owners.
            townBlock.setType(townBlock.getType());
            TownyUniverse.getDataSource().saveTownBlock(townBlock);
            return true;
        }
    } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
    }
//else
//	throw new TownyException(TownySettings.getLangString("msg_err_not_in_town_claim"));
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)70 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)37 Resident (com.palmergames.bukkit.towny.object.Resident)29 Town (com.palmergames.bukkit.towny.object.Town)17 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)16 Nation (com.palmergames.bukkit.towny.object.Nation)16 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)15 ArrayList (java.util.ArrayList)12 Player (org.bukkit.entity.Player)12 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)11 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)11 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)7 Location (org.bukkit.Location)7 IOException (java.io.IOException)6 EventHandler (org.bukkit.event.EventHandler)6 Coord (com.palmergames.bukkit.towny.object.Coord)5 InvalidNameException (javax.naming.InvalidNameException)5 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)4 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)3 EmptyTownException (com.palmergames.bukkit.towny.exceptions.EmptyTownException)3