use of com.palmergames.bukkit.towny.event.NewTownEvent in project Towny by ElgarL.
the class TownCommand method newTown.
public Town newTown(TownyWorld world, String name, Resident resident, Coord key, Location spawn) throws TownyException {
world.newTownBlock(key);
TownyUniverse.getDataSource().newTown(name);
Town town = TownyUniverse.getDataSource().getTown(name);
town.addResident(resident);
town.setMayor(resident);
TownBlock townBlock = world.getTownBlock(key);
townBlock.setTown(town);
town.setHomeBlock(townBlock);
// Set the plot permissions to mirror the towns.
townBlock.setType(townBlock.getType());
town.setSpawn(spawn);
if (world.isUsingPlotManagementRevert()) {
PlotBlockData plotChunk = TownyRegenAPI.getPlotChunk(townBlock);
if (plotChunk != null) {
// just claimed so stop regeneration.
TownyRegenAPI.deletePlotChunk(plotChunk);
} else {
// Not regenerating so create a new snapshot.
plotChunk = new PlotBlockData(townBlock);
plotChunk.initialize();
}
// Save a snapshot.
TownyRegenAPI.addPlotChunkSnapshot(plotChunk);
plotChunk = null;
}
TownyMessaging.sendDebugMsg("Creating new Town account: " + "town-" + name);
if (TownySettings.isUsingEconomy()) {
// TODO
try {
town.setBalance(0, "Deleting Town");
} catch (EconomyException e) {
e.printStackTrace();
}
}
TownyUniverse.getDataSource().saveResident(resident);
TownyUniverse.getDataSource().saveTownBlock(townBlock);
TownyUniverse.getDataSource().saveTown(town);
TownyUniverse.getDataSource().saveWorld(world);
TownyUniverse.getDataSource().saveTownList();
TownyUniverse.getDataSource().saveTownBlockList();
// Reset cache permissions for anyone in this TownBlock
plugin.updateCache(townBlock.getWorldCoord());
BukkitTools.getPluginManager().callEvent(new NewTownEvent(town));
return town;
}
Aggregations