Class PackManager

java.lang.Object
de.themoep.resourcepacksplugin.core.PackManager

public class PackManager extends Object
Created by Phoenix616 on 25.03.2015.
  • Field Details

  • Constructor Details

  • Method Details

    • init

      public void init()
      Initialize this pack manager
    • loadPack

      public ResourcePack loadPack(String name, Map<String,​Object> config) throws IllegalArgumentException
      Creates a new ResourcePack instance from a config. Does not add it!
      Parameters:
      name - The name of the pack
      config -
      Returns:
      Throws:
      IllegalArgumentException
    • addPack

      public ResourcePack addPack(ResourcePack pack) throws IllegalArgumentException
      Registers a new resource pack with the packmanager
      Parameters:
      pack - The resourcepack to register
      Returns:
      If a pack with that name was known before it returns the past pack, null if none was known
      Throws:
      IllegalArgumentException - when there already is a pack with the same url or hash but not name defined
    • removePack

      public boolean removePack(ResourcePack pack)
      Unregisters a resource pack from the packmanager
      Parameters:
      pack - The resourcepack to unregister
      Returns:
      If that pack was known before it returns true, if not false
    • setPackHash

      public boolean setPackHash(ResourcePack pack, String hash)
      Set the hash of a pack to a new value
      Parameters:
      pack - The pack to update
      hash - The new hash to set
      Returns:
      Whether or not the hash changed
    • setPackUrl

      public boolean setPackUrl(ResourcePack pack, String url)
      Set the url of a pack to a new value
      Parameters:
      pack - The pack to update
      url - The new url to set
      Returns:
      Whether or not the url changed
    • getByName

      public ResourcePack getByName(String name)
      Get the resourcepack by its name
      Parameters:
      name - The name of the pack to get
      Returns:
      The resourcepack with that name, null if there is none
    • getByHash

      public ResourcePack getByHash(String hash)
      Get the resourcepack by its hash
      Parameters:
      hash - The hash of the pack to get
      Returns:
      The resourcepack with that hash, null if there is none
    • getByHash

      public ResourcePack getByHash(byte[] hash)
      Get the resourcepack by its hash
      Parameters:
      hash - The hash of the pack to get
      Returns:
      The resourcepack with that hash, null if there is none
    • getByUrl

      public ResourcePack getByUrl(String url)
      Get the resourcepack by its url
      Parameters:
      url - The url of the pack to get
      Returns:
      The resourcepack with that url, null if there is none
    • setEmptyPack

      public ResourcePack setEmptyPack(ResourcePack pack)
      Set the empty Resource Pack
      Parameters:
      pack - The pack to set as empty pack
      Returns:
      The previous empty pack, null if none was set
    • setEmptyPack

      public ResourcePack setEmptyPack(String packname)
      Set the empty Resource Pack
      Parameters:
      packname - The name of the pack to set as empty pack
      Returns:
      The previous empty pack, null if none was set
    • getEmptyPack

      public ResourcePack getEmptyPack()
      Get the empty Resource Pack
      Returns:
      The empty pack, null if none is set
    • setStoredPacksOverride

      public void setStoredPacksOverride(boolean playerPacksOverride)
      Set whether or not stored packs should override assignments
      Parameters:
      playerPacksOverride - Whether or not stored packs should override assignments
    • getStoredPacksOverride

      public boolean getStoredPacksOverride()
      Get whether or not stored packs should override assignments
      Returns:
      Whether or not stored packs should override assignments
    • setGlobalPack

      @Deprecated public ResourcePack setGlobalPack(ResourcePack pack)
      Set the global Resource Pack
      Parameters:
      pack - The pack to set as global
      Returns:
      The previous global pack, null if none was set
    • setGlobalPack

      @Deprecated public ResourcePack setGlobalPack(String packname)
      Set the global Resource Pack
      Parameters:
      packname - The name of the pack to set as global
      Returns:
      The previous global pack, null if none was set
    • getGlobalPack

      @Deprecated public ResourcePack getGlobalPack()
      Get the global Resource Pack
      Returns:
      The global pack, null if none is set
    • addGlobalSecondary

      @Deprecated public boolean addGlobalSecondary(ResourcePack pack)
      Add a secondary global Resource Pack
      Parameters:
      pack - The pack to add to the list of secondary ones
      Returns:
      False if the pack already was in the list; True if not
    • addGlobalSecondary

      @Deprecated public boolean addGlobalSecondary(String packname)
      Add a secondary global Resource Pack
      Parameters:
      packname - The name of the pack to add to the list of secondary ones
      Returns:
      False if the pack already was in the list; True if not
    • isGlobalSecondary

      @Deprecated public boolean isGlobalSecondary(ResourcePack pack)
      Get if a pack is in the list of secondary global Resource Packs
      Parameters:
      pack - The pack to check
      Returns:
      True if it is a global secondary pack, false if not
    • isGlobalSecondary

      @Deprecated public boolean isGlobalSecondary(String packname)
      Get if a pack is in the list of secondary global Resource Packs
      Parameters:
      packname - The name of the pack to check
      Returns:
      True if it is a global secondary pack, false if not
    • getGlobalSecondary

      @Deprecated public List<String> getGlobalSecondary()
      Get the list of global seconday packs
      Returns:
      A list of packnames that are global secondary packs
    • getServerPack

      @Deprecated public ResourcePack getServerPack(String server)
      Get the resourcepack of a server
      Parameters:
      server - The name of the server, "!global" for the global pack
      Returns:
      The resourcepack of the server, null if there is none
    • getUserPack

      @Deprecated public ResourcePack getUserPack(UUID playerid)
      Deprecated.
      Get the resourcepack of a user
      Parameters:
      playerid - The UUID of this player
      Returns:
      The resourcepack the player has selected, null if he has none/isn't known
    • setUserPack

      @Deprecated public ResourcePack setUserPack(UUID playerid, ResourcePack pack)
      Set the resourcepack of a user
      Parameters:
      playerid - The UUID of this player
      pack - The resourcepack of the user
      Returns:
      The resourcepack the player had selected previous, null if he had none before
    • clearUserPack

      @Deprecated public ResourcePack clearUserPack(UUID playerid)
      Clear the resourcepack of a user
      Parameters:
      playerid - The UUID of this player
      Returns:
      The resourcepack the player had selected previous, null if he had none before
    • addServer

      @Deprecated public void addServer(String server, ResourcePack pack)
      Add a server to a resourcepack
      Parameters:
      server - The server this pack should be active on
      pack - The resourcepack
    • getGlobalAssignment

      public PackAssignment getGlobalAssignment()
      Get the global assignment
      Returns:
      The global PackAssignment
    • setGlobalAssignment

      public void setGlobalAssignment(PackAssignment assignment)
      Set the global assignment
      Parameters:
      assignment - The PackAssignment that you want to set
    • addAssignment

      public PackAssignment addAssignment(PackAssignment assignment)
      Add a new assignment to a server/world
      Parameters:
      assignment - The new PackAssignment
      Returns:
      The previous assignment or null if there was none
    • getAssignment

      public PackAssignment getAssignment(String server)
      Get the assignment of a server/world
      Parameters:
      server - The name of the server/world
      Returns:
      The PackAssignment; an empty one if there is none
    • getAssignmentByName

      public PackAssignment getAssignmentByName(String name)
      Get an assignment by its name
      Parameters:
      name - The name of the assignment
      Returns:
      The PackAssignment or null if not found
    • getAssignments

      public Collection<? extends PackAssignment> getAssignments()
      Get all assignments
      Returns:
      The all PackAssignments
    • loadAssignment

      public PackAssignment loadAssignment(String name, Map<String,​Object> config)
      Load an assignment from a map representing the section in the config
      Parameters:
      name - The name of the assignment
      config - A map representing the config section
      Returns:
      The PackAssignment
    • removeServer

      @Deprecated public boolean removeServer(String server)
      Deprecated.
      Removes the pack of a server
      Parameters:
      server - The server the pack should get removed from
      Returns:
      True if the server had a pack, false if not
    • removeAssignment

      public boolean removeAssignment(String key)
      Removes the assignment of a server/world
      Parameters:
      key - The name of the server/world the pack should get removed from
      Returns:
      True if there was a assignment for that key, false if not
    • removeAssignment

      public boolean removeAssignment(PackAssignment assignment)
      Removes the assignment of a server/world
      Parameters:
      assignment - The assigned to remove
      Returns:
      True if there was a assignment for that key, false if not
    • addServerSecondary

      @Deprecated public boolean addServerSecondary(String server, ResourcePack pack)
      Add a secondary server Resource Pack
      Parameters:
      server - The server to add a secondary pack to
      pack - The pack to add to the list of secondary ones
      Returns:
      False if the pack already was in the list; True if not
    • addServerSecondary

      @Deprecated public boolean addServerSecondary(String server, String packname)
      Add a secondary server Resource Pack
      Parameters:
      server - The server to add a secondary pack to
      packname - The name of the pack to add to the list of secondary ones
      Returns:
      False if the pack already was in the list; True if not
    • isServerSecondary

      @Deprecated public boolean isServerSecondary(String server, ResourcePack pack)
      Get if a pack is in the list of secondary Resource Packs for this server
      Parameters:
      server - The check the secondary pack of
      pack - The pack to check
      Returns:
      True if it is a global secondary pack, false if not
    • isServerSecondary

      @Deprecated public boolean isServerSecondary(String server, String packname)
      Get if a pack is in the list of secondary Resource Packs for this server
      Parameters:
      server - The server to add a secondary pack to
      packname - The name of the pack to check
      Returns:
      True if it is a global secondary pack, false if not
    • getServerSecondary

      @Deprecated public List<String> getServerSecondary(String server)
      Get the list of secondary packs of a specific server
      Parameters:
      server - The name of the server
      Returns:
      The list of secondary packs; empty if none found
    • setPack

      public boolean setPack(UUID playerId, ResourcePack pack)
      Set the pack of a player and send it to him, calls a ResourcePackSendEvent
      Parameters:
      playerId - The UUID of the player to set the pack for
      pack - The ResourcePack to set, if it is null it will reset to empty if the player has a pack applied
      Returns:
      true if the pack was set; false if not
    • setPack

      public IResourcePackSelectEvent.Status setPack(UUID playerId, ResourcePack pack, boolean temporary)
      Set the pack of a player and send it to him, calls a ResourcePackSendEvent
      Parameters:
      playerId - The UUID of the player to set the pack for
      pack - The ResourcePack to set, if it is null it will reset to empty if the player has a pack applied
      temporary - Should the pack be removed on log out or stored?
      Returns:
      the status, SUCCESS if the pack was set
    • applyPack

      public void applyPack(UUID playerId, String serverName)
      Apply the pack that a player should have on that server/world
      Parameters:
      playerId - The UUID of the player
      serverName - The name of the server/world
    • getApplicablePack

      public ResourcePack getApplicablePack(UUID playerId, String serverName)
      Get the pack the player should have on that server
      Parameters:
      playerId - The UUID of the player
      serverName - The name of the server
      Returns:
      The pack for that server; null if he should have none
    • checkPack

      protected IResourcePackSelectEvent.Status checkPack(UUID playerId, ResourcePack pack, IResourcePackSelectEvent.Status status)
    • getPacks

      public List<ResourcePack> getPacks()
      Get a list of all packs
      Returns:
      A new array list of packs
    • generateHashes

      public void generateHashes(ResourcepacksPlayer sender)
      Download the pack files and generate sha1 hashes from them, also saves the changes to the config!
      Parameters:
      sender - The player that executed the command, null if it was the console
    • getPackFormat

      public int getPackFormat(int version)
      Get the format of the pack a player can maximally use
      Parameters:
      version - The Protocol version to get the format for
      Returns:
      The pack format; -1 if the player has an unknown version
    • setDirty

      public void setDirty(boolean dirty)
      Mark the manager state as dirty so it gets saved on next modification
      Parameters:
      dirty - Whether or not this manager state should be considered dirty
    • checkDirty

      public void checkDirty()
      Check whether or not the manager state is dirty and if so save the config