Search in sources :

Example 56 with NotRegisteredException

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

the class OnPlayerLogin method warningMessage.

/**
	 * Send a warning message if the town or nation is due to be deleted.
	 * 
	 * @param resident
	 */
private void warningMessage(Resident resident) {
    if (TownyEconomyHandler.isActive() && TownySettings.isTaxingDaily()) {
        if (resident.hasTown()) {
            try {
                Town town = resident.getTown();
                if (town.hasUpkeep()) {
                    double upkeep = TownySettings.getTownUpkeepCost(town);
                    try {
                        if ((upkeep > 0) && (!town.canPayFromHoldings(upkeep))) {
                            /*
								 *  Warn that the town is due to be deleted.
								 */
                            TownyMessaging.sendMessage(resident, String.format(TownySettings.getLangString("msg_warning_delete"), town.getName()));
                        }
                    } catch (EconomyException ex) {
                    // Economy error, so ignore it and try to continue.
                    }
                }
                if (town.hasNation()) {
                    Nation nation = town.getNation();
                    double upkeep = TownySettings.getNationUpkeepCost(nation);
                    try {
                        if ((upkeep > 0) && (!nation.canPayFromHoldings(upkeep))) {
                            /*
								 *  Warn that the nation is due to be deleted.
								 */
                            TownyMessaging.sendMessage(resident, String.format(TownySettings.getLangString("msg_warning_delete"), nation.getName()));
                        }
                    } catch (EconomyException ex) {
                    // Economy error, so ignore it and try to continue.
                    }
                }
            } catch (NotRegisteredException ex) {
            // Should never reach here as we tested it beforehand.
            }
        }
    }
}
Also used : EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) Nation(com.palmergames.bukkit.towny.object.Nation) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town)

Example 57 with NotRegisteredException

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

the class TownyHModFlatFileSource method loadWorlds.

@Override
public boolean loadWorlds() {
    System.out.println("[Towny] [hMod Conversion] Town Blocks");
    String line;
    String[] tokens;
    //Default world is the first one loaded
    TownyWorld world = getWorlds().toArray(new TownyWorld[0])[0];
    try {
        BufferedReader fin = new BufferedReader(new FileReader(rootFolder + dataFolder + "/townblocks.csv"));
        while ((line = fin.readLine()) != null) {
            tokens = line.split(",");
            if (tokens.length >= 4)
                try {
                    Town town = getTown(tokens[2]);
                    int x = Integer.parseInt(tokens[0]);
                    int z = Integer.parseInt(tokens[1]);
                    try {
                        world.newTownBlock(x, z);
                    } catch (AlreadyRegisteredException e) {
                    }
                    TownBlock townblock = world.getTownBlock(x, z);
                    if (town != null)
                        townblock.setTown(town);
                    try {
                        townblock.setResident(getResident(tokens[3]));
                    } catch (NotRegisteredException e) {
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (NotRegisteredException e) {
                    e.printStackTrace();
                }
        }
        fin.close();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Example 58 with NotRegisteredException

use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException 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 59 with NotRegisteredException

use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException 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)

Example 60 with NotRegisteredException

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

the class RepeatingTimerTask method run.

@Override
public void run() {
    // Perform a single block regen in each regen area, if any are left to do.
    if (TownyRegenAPI.hasPlotChunks()) {
        // only execute if the correct amount of time has passed.
        if (Math.max(1L, TownySettings.getPlotManagementSpeed()) >= ++timerCounter) {
            for (PlotBlockData plotChunk : new ArrayList<PlotBlockData>(TownyRegenAPI.getPlotChunks().values())) {
                if (!plotChunk.restoreNextBlock()) {
                    TownyRegenAPI.deletePlotChunk(plotChunk);
                    TownyRegenAPI.deletePlotChunkSnapshot(plotChunk);
                }
            }
            timerCounter = 0L;
        }
    }
    // Take a snapshot of the next townBlock and save.
    if (TownyRegenAPI.hasWorldCoords()) {
        try {
            TownBlock townBlock = TownyRegenAPI.getWorldCoord().getTownBlock();
            PlotBlockData plotChunk = new PlotBlockData(townBlock);
            // Create a new snapshot.
            plotChunk.initialize();
            if (!plotChunk.getBlockList().isEmpty() && !(plotChunk.getBlockList() == null))
                // Save the snapshot.
                TownyRegenAPI.addPlotChunkSnapshot(plotChunk);
            plotChunk = null;
            townBlock.setLocked(false);
            TownyUniverse.getDataSource().saveTownBlock(townBlock);
            plugin.updateCache(townBlock.getWorldCoord());
            if (!TownyRegenAPI.hasWorldCoords())
                TownyLogger.log.info("Plot snapshots completed.");
        } catch (NotRegisteredException e) {
        // Not a townblock so ignore.
        }
    }
    // Perform the next plot_management block_delete
    if (TownyRegenAPI.hasDeleteTownBlockIdQueue()) {
        TownyRegenAPI.doDeleteTownBlockIds(TownyRegenAPI.getDeleteTownBlockIdQueue());
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) ArrayList(java.util.ArrayList) PlotBlockData(com.palmergames.bukkit.towny.regen.PlotBlockData) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Aggregations

NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)80 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)38 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)31 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)27 Resident (com.palmergames.bukkit.towny.object.Resident)24 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)19 Player (org.bukkit.entity.Player)18 Town (com.palmergames.bukkit.towny.object.Town)17 ArrayList (java.util.ArrayList)17 EventHandler (org.bukkit.event.EventHandler)17 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)14 Nation (com.palmergames.bukkit.towny.object.Nation)11 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)9 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)9 IOException (java.io.IOException)9 Location (org.bukkit.Location)9 Entity (org.bukkit.entity.Entity)9 LivingEntity (org.bukkit.entity.LivingEntity)8 Coord (com.palmergames.bukkit.towny.object.Coord)7 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)7