} else if (event.getEventName().equals("CellDefended")) {
CellDefendedEvent cellDefendedEvent = (CellDefendedEvent)event;
Player player = cellDefendedEvent.getPlayer();
CellUnderAttack cell = cellDefendedEvent.getCell().getAttackData();
TownyUniverse universe = plugin.getTownyUniverse();
try {
TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName());
WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ());
universe.removeWarZone(worldCoord);
plugin.updateCache(worldCoord);
} catch (NotRegisteredException e) {
e.printStackTrace();
}
String playerName;
if (player == null) {
playerName = "Greater Forces";
} else {
playerName = player.getName();
try {
playerName = TownyUniverse.getDataSource().getResident(player.getName()).getFormattedName();
} catch (TownyException e) {
}
}
plugin.getServer().broadcastMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_defended"),
playerName,
cell.getCellString()));
} else if (event.getEventName().equals("CellWon")) {
CellWonEvent cellWonEvent = (CellWonEvent)event;
CellUnderAttack cell = cellWonEvent.getCellAttackData();
TownyUniverse universe = plugin.getTownyUniverse();
try {
Resident resident = TownyUniverse.getDataSource().getResident(cell.getNameOfFlagOwner());
Town town = resident.getTown();
Nation nation = town.getNation();
TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName());
WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ());
universe.removeWarZone(worldCoord);
TownBlock townBlock = worldCoord.getTownBlock();
TownyUniverse.getDataSource().removeTownBlock(townBlock);
try {
List<WorldCoord> selection = new ArrayList<WorldCoord>();
selection.add(worldCoord);
TownCommand.checkIfSelectionIsValid(town, selection, false, 0, false);
new TownClaim(plugin, null, town, selection, true, false).start();
//TownCommand.townClaim(town, worldCoord);
//TownyUniverse.getDataSource().saveTown(town);
//TownyUniverse.getDataSource().saveWorld(world);
//TODO
//PlotCommand.plotClaim(resident, worldCoord);
//TownyUniverse.getDataSource().saveResident(resident);
//TownyUniverse.getDataSource().saveWorld(world);
} catch (TownyException te) {
// Couldn't claim it.
}
plugin.updateCache(worldCoord);
TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_won"),
resident.getFormattedName(),
(nation.hasTag() ? nation.getTag() : nation.getFormattedName()),
cell.getCellString()));
} catch (NotRegisteredException e) {
e.printStackTrace();
}
} else if (event.getEventName().equals("CellAttackCanceled")) {
System.out.println("CellAttackCanceled");
CellAttackCanceledEvent cancelCellAttackerEvent = (CellAttackCanceledEvent)event;
CellUnderAttack cell = cancelCellAttackerEvent.getCell();
TownyUniverse universe = plugin.getTownyUniverse();
try {
TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName());
WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ());
universe.removeWarZone(worldCoord);
plugin.updateCache(worldCoord);
} catch (NotRegisteredException e) {
e.printStackTrace();
}
System.out.println(cell.getCellString());