use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class War method start.
public void start() {
warTime = true;
// Seed spoils of war
try {
warSpoils.pay(TownySettings.getBaseSpoilsOfWar(), "Start of War - Base Spoils");
TownyMessaging.sendMsg("[War] Seeding spoils of war with " + TownySettings.getBaseSpoilsOfWar());
} catch (EconomyException e) {
TownyMessaging.sendErrorMsg("[War] Could not seed spoils of war.");
}
// Gather all nations at war
for (Nation nation : TownyUniverse.getDataSource().getNations()) {
if (!nation.isNeutral()) {
add(nation);
TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_war_join_nation"), nation.getName()));
} else if (!TownySettings.isDeclaringNeutral()) {
try {
nation.setNeutral(false);
add(nation);
TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_war_join_forced"), nation.getName()));
} catch (TownyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// warTimer.scheduleAtFixedRate(new WarTimerTask(this), 0, 1000);
int id = BukkitTools.scheduleAsyncRepeatingTask(new WarTimerTask(plugin, this), 0, TimeTools.convertToTicks(5));
if (id == -1) {
TownyMessaging.sendErrorMsg("Could not schedule war event loop.");
end();
} else
addTaskId(id);
checkEnd();
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class TownyWar method checkIfNationHasMinOnlineForWar.
public static void checkIfNationHasMinOnlineForWar(Nation nation) throws TownyException {
int requiredOnline = TownyWarConfig.getMinPlayersOnlineInNationForWar();
int onlinePlayerCount = TownyUniverse.getOnlinePlayers(nation).size();
if (onlinePlayerCount < requiredOnline)
throw new TownyException(String.format(TownySettings.getLangString("msg_err_enemy_war_require_online"), requiredOnline, nation.getFormattedName()));
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class Towny method onEnable.
@Override
public void onEnable() {
System.out.println("==================== Towny ========================");
/*
* Register Metrics
*/
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (IOException e) {
System.err.println("[Towny] Error setting up metrics");
}
version = this.getDescription().getVersion();
townyUniverse = new TownyUniverse(this);
// Setup classes
BukkitTools.initialize(this);
TownyTimerHandler.initialize(this);
TownyEconomyHandler.initialize(this);
TownyFormatter.initialize(this);
TownyRegenAPI.initialize(this);
PlayerCacheUtil.initialize(this);
TownyPerms.initialize(this);
if (load()) {
// Setup bukkit command interfaces
getCommand("townyadmin").setExecutor(new TownyAdminCommand(this));
getCommand("townyworld").setExecutor(new TownyWorldCommand(this));
getCommand("resident").setExecutor(new ResidentCommand(this));
getCommand("towny").setExecutor(new TownyCommand(this));
getCommand("town").setExecutor(new TownCommand(this));
getCommand("nation").setExecutor(new NationCommand(this));
getCommand("plot").setExecutor(new PlotCommand(this));
TownyWar.onEnable();
if (TownySettings.isTownyUpdating(getVersion()))
update();
// Register all child permissions for ranks
TownyPerms.registerPermissionNodes();
}
registerEvents();
TownyLogger.log.info("=============================================================");
if (isError())
TownyLogger.log.info("[WARNING] - ***** SAFE MODE ***** " + version);
else
TownyLogger.log.info("[Towny] Version: " + version + " - Mod Enabled");
TownyLogger.log.info("=============================================================");
if (!isError()) {
// Re login anyone online. (In case of plugin reloading)
for (Player player : BukkitTools.getOnlinePlayers()) if (player != null)
try {
getTownyUniverse().onLogin(player);
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class TownyAsciiMap method generateAndSend.
public static void generateAndSend(Towny plugin, Player player, int lineHeight) {
// Collect Sample Data
boolean hasTown = false;
Resident resident;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
if (resident.hasTown())
hasTown = true;
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
TownyWorld world;
try {
world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
} catch (NotRegisteredException e1) {
TownyMessaging.sendErrorMsg(player, "You are not in a registered world.");
return;
}
if (!world.isUsingTowny()) {
TownyMessaging.sendErrorMsg(player, "This world is not using towny.");
return;
}
Coord pos = Coord.parseCoord(plugin.getCache(player).getLastLocation());
// Generate Map
int halfLineHeight = lineHeight / 2;
String[][] townyMap = new String[lineWidth][lineHeight];
int x, y = 0;
for (int tby = pos.getX() + (lineWidth - halfLineWidth - 1); tby >= pos.getX() - halfLineWidth; tby--) {
x = 0;
for (int tbx = pos.getZ() - halfLineHeight; tbx <= pos.getZ() + (lineHeight - halfLineHeight - 1); tbx++) {
try {
TownBlock townblock = world.getTownBlock(tby, tbx);
// TODO: possibly claim outside of towns
if (!townblock.hasTown())
throw new TownyException();
if (x == halfLineHeight && y == halfLineWidth)
// location
townyMap[y][x] = Colors.Gold;
else if (hasTown) {
if (resident.getTown() == townblock.getTown()) {
// own town
townyMap[y][x] = Colors.LightGreen;
try {
if (resident == townblock.getResident())
// own plot
townyMap[y][x] = Colors.Yellow;
} catch (NotRegisteredException e) {
}
} else if (resident.hasNation()) {
if (resident.getTown().getNation().hasTown(townblock.getTown()))
// towns
townyMap[y][x] = Colors.Green;
else if (townblock.getTown().hasNation()) {
Nation nation = resident.getTown().getNation();
if (nation.hasAlly(townblock.getTown().getNation()))
townyMap[y][x] = Colors.Green;
else if (nation.hasEnemy(townblock.getTown().getNation()))
// towns
townyMap[y][x] = Colors.Red;
else
townyMap[y][x] = Colors.White;
} else
townyMap[y][x] = Colors.White;
} else
townyMap[y][x] = Colors.White;
} else
townyMap[y][x] = Colors.White;
// Registered town block
if (townblock.getPlotPrice() != -1) {
// override the colour if it's a shop plot for sale
if (townblock.getType().equals(TownBlockType.COMMERCIAL))
townyMap[y][x] = Colors.Blue;
townyMap[y][x] += "$";
} else if (townblock.isHomeBlock())
townyMap[y][x] += "H";
else
townyMap[y][x] += townblock.getType().getAsciiMapKey();
} catch (TownyException e) {
if (x == halfLineHeight && y == halfLineWidth)
townyMap[y][x] = Colors.Gold;
else
townyMap[y][x] = Colors.Gray;
// Unregistered town block
townyMap[y][x] += "-";
}
x++;
}
y++;
}
String[] compass = generateCompass(player);
// Output
player.sendMessage(ChatTools.formatTitle("Towny Map " + Colors.White + "(" + pos.toString() + ")"));
String line;
int lineCount = 0;
// Variables have been rotated to fit N/S/E/W properly
for (int my = 0; my < lineHeight; my++) {
line = compass[0];
if (lineCount < compass.length)
line = compass[lineCount];
for (int mx = lineWidth - 1; mx >= 0; mx--) line += townyMap[mx][my];
if (lineCount < help.length)
line += help[lineCount];
player.sendMessage(line);
lineCount++;
}
// Current town block data
try {
TownBlock townblock = world.getTownBlock(pos);
TownyMessaging.sendMsg(player, ("Town: " + (townblock.hasTown() ? townblock.getTown().getName() : "None") + " : " + "Owner: " + (townblock.hasResident() ? townblock.getResident().getName() : "None")));
} catch (TownyException e) {
// plugin.sendErrorMsg(player, e.getError());
// Send a blank line instead of an error, to keep the map position tidy.
player.sendMessage("");
}
}
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"));
}
Aggregations