Search in sources :

Example 6 with TownyException

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

the class PlotClaim method residentUnclaim.

private boolean residentUnclaim(WorldCoord worldCoord) throws TownyException {
    try {
        TownBlock townBlock = worldCoord.getTownBlock();
        townBlock.setResident(null);
        townBlock.setPlotPrice(townBlock.getTown().getPlotTypePrice(townBlock.getType()));
        // Set the plot permissions to mirror the towns.
        townBlock.setType(townBlock.getType());
        TownyUniverse.getDataSource().saveTownBlock(townBlock);
        plugin.updateCache(worldCoord);
    } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_not_own_place"));
    }
    return true;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 7 with TownyException

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

the class AreaSelectionUtil method selectWorldCoordAreaCircle.

public static List<WorldCoord> selectWorldCoordAreaCircle(TownBlockOwner owner, WorldCoord pos, String[] args) throws TownyException {
    List<WorldCoord> out = new ArrayList<WorldCoord>();
    if (pos.getTownyWorld().isClaimable()) {
        if (args.length > 0) {
            int r = 0, available = 0;
            if (owner instanceof Town) {
                Town town = (Town) owner;
                available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
            } else if (owner instanceof Resident) {
                available = TownySettings.getMaxResidentPlots((Resident) owner);
            }
            if (args[0].equalsIgnoreCase("auto")) {
                if (// Since: 0 - ceil(Pi * 0^2) >= 0 is a true statement.
                available > 0)
                    while (available - Math.ceil(Math.PI * r * r) >= 0) r += 1;
            } else {
                try {
                    r = Integer.parseInt(args[0]);
                } catch (NumberFormatException e) {
                    throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
                }
            }
            if (r > 1000)
                r = 1000;
            for (int z = -r; z <= r; z++) for (int x = -r; x <= r; x++) if ((x * x + z * z <= r * r) && (out.size() < available))
                out.add(new WorldCoord(pos.getWorldName(), pos.getX() + x, pos.getZ() + z));
        } else {
            throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
        }
    }
    return out;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 8 with TownyException

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

the class AreaSelectionUtil method selectWorldCoordAreaRect.

public static List<WorldCoord> selectWorldCoordAreaRect(TownBlockOwner owner, WorldCoord pos, String[] args) throws TownyException {
    List<WorldCoord> out = new ArrayList<WorldCoord>();
    if (pos.getTownyWorld().isClaimable()) {
        if (args.length > 0) {
            int r = 0, available = 1000;
            if (owner instanceof Town) {
                Town town = (Town) owner;
                available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
            } else if (owner instanceof Resident) {
                available = TownySettings.getMaxResidentPlots((Resident) owner);
            }
            if (args[0].equalsIgnoreCase("auto")) {
                while (available - Math.pow((r + 1) * 2 - 1, 2) >= 0) r += 1;
            } else {
                try {
                    r = Integer.parseInt(args[0]);
                } catch (NumberFormatException e) {
                    throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
                }
            }
            if (r > 1000)
                r = 1000;
            for (int z = -r; z <= r; z++) for (int x = -r; x <= r; x++) if (out.size() < available)
                out.add(new WorldCoord(pos.getWorldName(), pos.getX() + x, pos.getZ() + z));
        } else {
            throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
        }
    }
    return out;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 9 with TownyException

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

the class TownyUniverse method getOnlineResidents.

public static List<Resident> getOnlineResidents(Player player, String[] names) {
    List<Resident> invited = new ArrayList<Resident>();
    for (String name : names) {
        List<Player> matches = BukkitTools.matchPlayer(name);
        if (matches.size() > 1) {
            String line = "Multiple players selected";
            for (Player p : matches) line += ", " + p.getName();
            TownyMessaging.sendErrorMsg(player, line);
        } else if (matches.size() == 1)
            try {
                Resident target = getDataSource().getResident(matches.get(0).getName());
                invited.add(target);
            } catch (TownyException x) {
                TownyMessaging.sendErrorMsg(player, x.getMessage());
            }
    }
    return invited;
}
Also used : Player(org.bukkit.entity.Player) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 10 with TownyException

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

the class TownyUniverse method getTownSpawnLocation.

public Location getTownSpawnLocation(Player player) throws TownyException {
    try {
        Resident resident = getDataSource().getResident(player.getName());
        Town town = resident.getTown();
        return town.getSpawn();
    } catch (TownyException x) {
        throw new TownyException("Unable to get spawn location");
    }
}
Also used : 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