use of com.palmergames.bukkit.towny.object.PlotGroup in project Towny by TownyAdvanced.
the class TownyDataSource method savePlotGroups.
public boolean savePlotGroups() {
TownyMessaging.sendDebugMsg("Saving PlotGroups");
for (PlotGroup plotGroup : universe.getGroups()) /*
* Only save plotgroups which actually have townblocks associated with them.
*/
if (plotGroup.hasTownBlocks())
savePlotGroup(plotGroup);
else
deletePlotGroup(plotGroup);
return true;
}
use of com.palmergames.bukkit.towny.object.PlotGroup in project Towny by TownyAdvanced.
the class TownyDatabaseHandler method renameTown.
/*
* Rename Object Methods
*/
@Override
public void renameTown(Town town, String newName) throws AlreadyRegisteredException, NotRegisteredException {
lock.lock();
String oldName;
try {
String filteredName;
try {
filteredName = NameValidation.checkAndFilterName(newName);
} catch (InvalidNameException e) {
throw new NotRegisteredException(e.getMessage());
}
if (universe.hasTown(filteredName))
throw new AlreadyRegisteredException("The town " + filteredName + " is already in use.");
List<Resident> toSave = new ArrayList<>(town.getResidents());
boolean isCapital = false;
Nation nation = null;
double townBalance = 0.0;
oldName = town.getName();
// Clear accounts
if (TownyEconomyHandler.isActive())
try {
townBalance = town.getAccount().getHoldingBalance();
if (TownySettings.isEcoClosedEconomyEnabled()) {
town.getAccount().deposit(townBalance, "Town Rename");
}
town.getAccount().removeAccount();
} catch (Exception ignored) {
TownyMessaging.sendErrorMsg("The bank balance for the town " + oldName + ", could not be received from the economy plugin and will not be able to be converted.");
}
UUID oldUUID = town.getUUID();
long oldregistration = town.getRegistered();
// Store the nation in case we have to update the capitol
if (town.hasNation()) {
nation = town.getNation();
isCapital = town.isCapital();
}
// TODO: This was added because renaming was throwing an NRE
TownyWorld world = town.getHomeblockWorld();
if (// At some point worlds storing Towns will have to be re-evaluated.
world.hasTown(town))
// Worlds holding Towns is only useful when it comes to checking
world.removeTown(town);
// distances between townblocks.
/*
* Tidy up old files.
* Has to be done here else the town no longer exists
* and the file move command may fail.
*/
deleteTown(town);
/*
* Remove the old town from the townsMap
* and rename to the new name
*/
// Re-register the town in the unvierse maps
universe.unregisterTown(town);
town.setName(filteredName);
universe.registerTown(town);
world.addTown(town);
// If this was a nation capitol
if (isCapital) {
nation.setCapital(town);
}
town.setUUID(oldUUID);
town.setRegistered(oldregistration);
if (TownyEconomyHandler.isActive()) {
town.getAccount().setName(TownySettings.getTownAccountPrefix() + town.getName());
town.getAccount().setBalance(townBalance, "Rename Town - Transfer to new account");
}
for (Resident resident : toSave) {
saveResident(resident);
}
for (TownBlock townBlock : town.getTownBlocks()) {
// townBlock.setTown(town);
saveTownBlock(townBlock);
}
if (town.hasPlotGroups())
for (PlotGroup pg : town.getPlotGroups()) {
pg.setTown(town);
savePlotGroup(pg);
}
saveTown(town);
saveWorld(town.getHomeblockWorld());
if (nation != null) {
saveNation(nation);
}
} finally {
lock.unlock();
}
BukkitTools.getPluginManager().callEvent(new RenameTownEvent(oldName, town));
}
use of com.palmergames.bukkit.towny.object.PlotGroup in project Towny by TownyAdvanced.
the class TownyUniverse method newPlotGroupInternal.
/*
* PlotGroup Stuff.
*/
/**
* Used in loading only.
* @param uuid UUID to assign to the PlotGroup.
*/
public void newPlotGroupInternal(String uuid) {
PlotGroup group = new PlotGroup(UUID.fromString(uuid), null, null);
registerGroup(group);
}
Aggregations