Search in sources :

Example 11 with PlotGroup

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;
}
Also used : PlotGroup(com.palmergames.bukkit.towny.object.PlotGroup)

Example 12 with PlotGroup

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));
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) ArrayList(java.util.ArrayList) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) InvalidNameException(com.palmergames.bukkit.towny.exceptions.InvalidNameException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) InvalidNameException(com.palmergames.bukkit.towny.exceptions.InvalidNameException) Resident(com.palmergames.bukkit.towny.object.Resident) RenameTownEvent(com.palmergames.bukkit.towny.event.RenameTownEvent) PlotGroup(com.palmergames.bukkit.towny.object.PlotGroup) UUID(java.util.UUID) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 13 with PlotGroup

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);
}
Also used : PlotGroup(com.palmergames.bukkit.towny.object.PlotGroup)

Aggregations

PlotGroup (com.palmergames.bukkit.towny.object.PlotGroup)13 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)9 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)8 Resident (com.palmergames.bukkit.towny.object.Resident)8 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)7 Town (com.palmergames.bukkit.towny.object.Town)6 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)5 PermissionData (com.palmergames.bukkit.towny.object.PermissionData)5 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)4 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)4 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)4 Gson (com.google.gson.Gson)2 PlotPreChangeTypeEvent (com.palmergames.bukkit.towny.event.PlotPreChangeTypeEvent)2 TownBlockSettingsChangedEvent (com.palmergames.bukkit.towny.event.TownBlockSettingsChangedEvent)2 PlotTrustAddEvent (com.palmergames.bukkit.towny.event.plot.PlotTrustAddEvent)2 PlotTrustRemoveEvent (com.palmergames.bukkit.towny.event.plot.PlotTrustRemoveEvent)2 EmptyNationException (com.palmergames.bukkit.towny.exceptions.EmptyNationException)2 TownBlockOwner (com.palmergames.bukkit.towny.object.TownBlockOwner)2 TownBlockType (com.palmergames.bukkit.towny.object.TownBlockType)2