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