Class TownyUniverse

java.lang.Object
com.palmergames.bukkit.towny.TownyUniverse

public class TownyUniverse extends Object
Towny's class for internal API Methods If you don't want to change the dataSource, war, permissions or similar behavior and only for example want to get Resident objects you should use TownyAPI
Author:
Articdive
  • Method Details

    • getInstance

      public static TownyUniverse getInstance()
    • performCleanupAndBackup

      public void performCleanupAndBackup()
      Performs CleanupTask and BackupTask in async,
    • clearAllObjects

      public void clearAllObjects()
      Clears the object maps.
    • finishTasks

      public void finishTasks()
      Run during onDisable() to finish cleanup and backup.
    • getDataSource

      public TownyDataSource getDataSource()
    • getPermissionSource

      public TownyPermissionSource getPermissionSource()
    • setPermissionSource

      public void setPermissionSource(TownyPermissionSource permissionSource)
    • getRootFolder

      public String getRootFolder()
    • hasResident

      public boolean hasResident(@NotNull @NotNull String residentName)
      Check if a resident exists with the passed in name. Will return true for fake residents and registered NPCs.
      Parameters:
      residentName - Resident name to check for.
      Returns:
      whether Towny has a resident matching that name.
    • hasResident

      public boolean hasResident(@NotNull @NotNull UUID residentUUID)
      Check if a resident exists matching the passed in UUID.
      Parameters:
      residentUUID - UUID of the resident to check.
      Returns:
      whether the resident matching the UUID exists.
    • getResident

      @Nullable public @Nullable Resident getResident(@NotNull @NotNull String residentName)
      Get the resident matching the passed in name. Any fake residents (not registered NPCs) will return a new instance of a resident on method call.
      Parameters:
      residentName - Name of the resident to fetch.
      Returns:
      the resident matching the given name or null if no resident is found.
    • getResidentOpt

      @NotNull public @NotNull Optional<Resident> getResidentOpt(@NotNull @NotNull String residentName)
      Get an optional instance of the resident matching the passed in name.
      Parameters:
      residentName - Name of the resident to fetch.
      Returns:
      Optional object that may contain the resident matching the given name.
    • getResident

      @Nullable public @Nullable Resident getResident(@NotNull @NotNull UUID residentUUID)
      Get the resident with the passed-in UUID.
      Parameters:
      residentUUID - UUID of the resident to get.
      Returns:
      the resident with the passed-in UUID or null if no resident is found.
    • getResidentOpt

      @NotNull public @NotNull Optional<Resident> getResidentOpt(@NotNull @NotNull UUID residentUUID)
      Get an optional object that may contain the resident with the passed-in UUID.
      Parameters:
      residentUUID - UUID of the resident to get.
      Returns:
      an optional object that may contain the resident with the passed-in UUID.
    • registerResidentUUID

      public void registerResidentUUID(@NotNull @NotNull Resident resident) throws AlreadyRegisteredException
      Throws:
      AlreadyRegisteredException
    • registerResident

      public void registerResident(@NotNull @NotNull Resident resident) throws AlreadyRegisteredException
      Register a resident into the internal structures. This will allow the resident to be fetched by name and UUID, as well as autocomplete the resident name. If a resident's name or UUID change, the resident must be re-registered into the maps. This does not modify the resident internally, nor saves the resident in the database.
      Parameters:
      resident - Resident to register.
      Throws:
      AlreadyRegisteredException - if another resident has been registered with the same name or UUID.
    • unregisterResident

      public void unregisterResident(@NotNull @NotNull Resident resident) throws NotRegisteredException
      Unregister a resident from the internal structures. This does not modify the resident internally, nor performs any database operations using the resident.
      Parameters:
      resident - Resident to unregister
      Throws:
      NotRegisteredException - if the resident's name or UUID was not registered.
    • getResidents

      public @Unmodifiable Collection<Resident> getResidents()
    • getNumResidents

      public int getNumResidents()
      Returns:
      number of residents that Towny has.
    • getResidentsTrie

      public Trie getResidentsTrie()
    • getJailedResidentMap

      public List<Resident> getJailedResidentMap()
    • hasTown

      public boolean hasTown(@NotNull @NotNull String townName)
    • hasTown

      public boolean hasTown(@NotNull @NotNull UUID townUUID)
    • getTown

      @Nullable public @Nullable Town getTown(@NotNull @NotNull String townName)
    • getTown

      @Nullable public @Nullable Town getTown(UUID townUUID)
    • getTowns

      public @Unmodifiable Collection<Town> getTowns()
    • getTownsTrie

      public Trie getTownsTrie()
    • newTownInternal

      public void newTownInternal(String name) throws AlreadyRegisteredException, InvalidNameException
      Throws:
      AlreadyRegisteredException
      InvalidNameException
    • newTown

      public void newTown(@NotNull @NotNull String name) throws AlreadyRegisteredException, InvalidNameException
      Create a new town from the string name.
      Parameters:
      name - Town name
      Throws:
      AlreadyRegisteredException - Town name is already in use.
      InvalidNameException - Town name is invalid.
    • registerTownUUID

      public void registerTownUUID(@NotNull @NotNull Town town) throws AlreadyRegisteredException
      Throws:
      AlreadyRegisteredException
    • registerTown

      public void registerTown(@NotNull @NotNull Town town) throws AlreadyRegisteredException
      Used to register a town into the TownyUniverse internal maps. This does not create a new town, or save a new town.
      Parameters:
      town - Town to register.
      Throws:
      AlreadyRegisteredException - Town is already in the universe maps.
    • unregisterTown

      public void unregisterTown(@NotNull @NotNull Town town) throws NotRegisteredException
      Used to unregister a town from the TownyUniverse internal maps. This does not delete a town, nor perform any actions that affect the town internally.
      Parameters:
      town - Town to unregister
      Throws:
      NotRegisteredException - Town is not registered in the universe maps.
    • hasNation

      public boolean hasNation(@NotNull @NotNull String nationName)
      Check if the nation matching the given name exists.
      Parameters:
      nationName - Name of the nation to check.
      Returns:
      whether the nation matching the name exists.
    • hasNation

      public boolean hasNation(@NotNull @NotNull UUID nationUUID)
      Check if the nation matching the given UUID exists.
      Parameters:
      nationUUID - UUID of the nation to check.
      Returns:
      whether the nation matching the UUID exists.
    • getNation

      @Nullable public @Nullable Nation getNation(@NotNull @NotNull String nationName)
      Get the nation with the passed-in nation name if it exists.
      Parameters:
      nationName - Name of the nation to fetch.
      Returns:
      the nation matching the name or null if it doesn't exist.
    • getNation

      @Nullable public @Nullable Nation getNation(@NotNull @NotNull UUID nationUUID)
      Get the nation with the given UUID if it exists.
      Parameters:
      nationUUID - UUID of the nation to get.
      Returns:
      the nation with the given UUID or null if it doesn't exist.
    • getNations

      public @Unmodifiable Collection<Nation> getNations()
    • getNumNations

      public int getNumNations()
    • registerNationUUID

      public void registerNationUUID(@NotNull @NotNull Nation nation) throws AlreadyRegisteredException
      Throws:
      AlreadyRegisteredException
    • registerNation

      public void registerNation(@NotNull @NotNull Nation nation) throws AlreadyRegisteredException
      Used to register a nation into the TownyUniverse internal maps. This does not create a new nation, or save a new nation.
      Parameters:
      nation - Nation to register.
      Throws:
      AlreadyRegisteredException - Nation is already in the universe maps.
    • unregisterNation

      public void unregisterNation(@NotNull @NotNull Nation nation) throws NotRegisteredException
      Used to unregister a nation from the TownyUniverse internal maps. This does not delete a nation, nor perform any actions that affect the nation internally.
      Parameters:
      nation - Nation to unregister
      Throws:
      NotRegisteredException - Nation is not registered in the universe maps.
    • getNationsTrie

      public Trie getNationsTrie()
    • newWorld

      public void newWorld(@NotNull @NotNull org.bukkit.World world)
      Causes a new TownyWorld object to be made in the Universe, from a Bukkit World.
    • registerTownyWorld

      public void registerTownyWorld(@NotNull @NotNull TownyWorld world)
    • getWorldIDMap

      public Map<UUID,TownyWorld> getWorldIDMap()
    • getWorld

      @Nullable public @Nullable TownyWorld getWorld(UUID uuid)
    • getWorldUUIDs

      public Set<UUID> getWorldUUIDs()
    • getWorldMap

      public Map<String,TownyWorld> getWorldMap()
    • getWorld

      @Nullable public @Nullable TownyWorld getWorld(String name)
    • getTownyWorlds

      public List<TownyWorld> getTownyWorlds()
    • hasTownyWorld

      public boolean hasTownyWorld(String worldName)
    • getTreeString

      public List<String> getTreeString(int depth)
    • newPlotGroupInternal

      public void newPlotGroupInternal(UUID uuid)
      Used in loading only.
      Parameters:
      uuid - UUID to assign to the PlotGroup.
    • registerGroup

      public void registerGroup(PlotGroup group)
    • unregisterGroup

      public void unregisterGroup(UUID uuid)
    • getGroups

      public Collection<PlotGroup> getGroups()
      Get all the plot object groups from all towns Returns a collection that does not reflect any group additions/removals
      Returns:
      collection of PlotObjectGroup
    • getPlotGroupUUIDs

      public Set<UUID> getPlotGroupUUIDs()
    • getGroup

      @Nullable public @Nullable PlotGroup getGroup(UUID groupID)
      Gets the plot group from the town name and the plot group UUID
      Parameters:
      groupID - UUID of the plot group
      Returns:
      PlotGroup if found, null if none found.
    • newDistrictInternal

      public void newDistrictInternal(UUID uuid)
      Used in loading only.
      Parameters:
      uuid - UUID to assign to the District.
    • registerDistrict

      public void registerDistrict(District district)
    • unregisterDistrict

      public void unregisterDistrict(UUID uuid)
    • getDistricts

      public Collection<District> getDistricts()
      Get all the districts from all towns Returns a collection that does not reflect any district additions/removals
      Returns:
      collection of District
    • getDistrictUUIDs

      public Set<UUID> getDistrictUUIDs()
    • getDistrict

      @Nullable public @Nullable District getDistrict(UUID districtID)
      Gets the district from the town name and the district UUID
      Parameters:
      districtID - UUID of the district
      Returns:
      District if found, null if none found.
    • addCustomCustomDataField

      public void addCustomCustomDataField(CustomDataField<?> cdf) throws KeyAlreadyRegisteredException
      Throws:
      KeyAlreadyRegisteredException
    • getRegisteredMetadataMap

      public Map<String,CustomDataField<?>> getRegisteredMetadataMap()
    • getRegisteredMetadata

      public Map<String,CustomDataField<?>> getRegisteredMetadata()
    • getTownBlock

      public TownBlock getTownBlock(WorldCoord worldCoord) throws NotRegisteredException
      How to get a TownBlock for now.
      Parameters:
      worldCoord - we are testing for a townblock.
      Returns:
      townblock if it exists, otherwise null.
      Throws:
      NotRegisteredException - if there is no homeblock to get.
    • getTownBlockOrNull

      @Nullable public @Nullable TownBlock getTownBlockOrNull(WorldCoord worldCoord)
    • getTownBlocks

      public Map<WorldCoord,TownBlock> getTownBlocks()
      Get Universe-wide ConcurrentHashMap of WorldCoords and their TownBlocks. Populated at load time from townblocks folder's files.
      Returns:
      townblocks hashmap read from townblock files.
    • addTownBlock

      public void addTownBlock(TownBlock townBlock)
    • hasTownBlock

      public boolean hasTownBlock(WorldCoord worldCoord)
      Does this WorldCoord have a TownBlock?
      Parameters:
      worldCoord - - the coord for which we want to know if there is a townblock.
      Returns:
      true if Coord is a townblock
    • removeTownBlock

      public void removeTownBlock(TownBlock townBlock)
      Remove one townblock from the TownyUniverse townblock map.
      Parameters:
      townBlock - to remove.
    • removeTownBlocks

      public void removeTownBlocks(List<TownBlock> townBlocks)
      Remove a list of TownBlocks from the TownyUniverse townblock map.
      Parameters:
      townBlocks - to remove.
    • getSpawnPoints

      @Internal public Map<SpawnPointLocation,SpawnPoint> getSpawnPoints()
    • getSpawnPoint

      @Nullable public @Nullable SpawnPoint getSpawnPoint(org.bukkit.Location loc)
    • hasSpawnPoint

      public boolean hasSpawnPoint(org.bukkit.Location loc)
    • addSpawnPoint

      public void addSpawnPoint(SpawnPoint spawn)
    • removeSpawnPoint

      public void removeSpawnPoint(org.bukkit.Location loc)
    • removeSpawnPoint

      public void removeSpawnPoint(SpawnPointLocation point)
    • getJails

      public List<Jail> getJails()
    • getJailUUIDMap

      public Map<UUID,Jail> getJailUUIDMap()
    • getJail

      @Nullable public @Nullable Jail getJail(UUID uuid)
    • hasJail

      public boolean hasJail(UUID uuid)
    • registerJail

      public void registerJail(Jail jail)
    • unregisterJail

      public void unregisterJail(Jail jail)
    • newJailInternal

      public void newJailInternal(String uuid)
      Used in loading only.
      Parameters:
      uuid - UUID of the given jail, taken from the Jail filename.
    • getWildernessMapDataMap

      public Map<WorldCoord,TownyMapData> getWildernessMapDataMap()
    • getReplacementNameMap

      public Map<String,String> getReplacementNameMap()