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
    • setPackUuid

      public boolean setPackUuid(ResourcePack pack, UUID uuid)
      Set the uuid of a pack to a new value
      Parameters:
      pack - The pack to update
      uuid - The uuid to set
      Returns:
      Whether or not the hash changed
    • 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
    • setPackPath

      public boolean setPackPath(ResourcePack pack, String path)
      Set the url of a pack to a new value
      Parameters:
      pack - The pack to update
      path - The new local path 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
    • getByUuid

      public ResourcePack getByUuid(UUID uuid)
      Get the resourcepack by its uuid
      Parameters:
      uuid - The uuid of the pack to get
      Returns:
      The resourcepack with that uuid, 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
    • 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 @NonNull 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
    • setPack

      public @NonNull PackManager.PackSetResult 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:
      The result of setting a pack
    • setPack

      public @NonNull PackManager.PackSetResult 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/empty 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 result of setting a pack
    • setPack

      public @NonNull PackManager.PackSetResult setPack(UUID playerId, ResourcePack pack, boolean temporary, boolean removeExisting)
      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
      temporary - Should the pack be removed on log out or stored?
      removeExisting - Should existing packs be removed? (Only works on 1.20.3+, versions before that will always remove)
      Returns:
      The result of setting a pack
    • processSendEvent

      public ResourcePack processSendEvent(IResourcePackSendEvent event, List<ResourcePack> prev)
      Process the pack send event using the previous pack, this calculates if a pack should be sent (if it's null then the empty one will be returned and when it isn't different from the previous one then it will return null). Will also set the pack of the player in the UserManager
      Parameters:
      event - The event
      prev - The previous packs
      Returns:
      The pack that should be sent to the player or null if no pack should be sent
    • applyPack

      @Deprecated 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
    • applyPack

      public Set<ResourcePack> applyPack(ResourcepacksPlayer player, String serverName)
      Apply the pack that a player should have on that server/world
      Parameters:
      player - The player
      serverName - The name of the server/world
      Returns:
      The packs that were loaded by the client
    • getApplicablePacks

      @Deprecated public LinkedHashSet<ResourcePack> getApplicablePacks(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 packs for that server; an empty list if they should have none
    • getApplicablePacks

      public LinkedHashSet<ResourcePack> getApplicablePacks(ResourcepacksPlayer player, String serverName)
      Get the pack the player should have on that server
      Parameters:
      player - The player
      serverName - The name of the server
      Returns:
      The packs for that server; an empty list if they should have none
    • checkPacks

      protected IResourcePackSelectEvent.Status checkPacks(UUID playerId, List<ResourcePack> packs, IResourcePackSelectEvent.Status status)
    • 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
    • getPackUrl

      public String getPackUrl(ResourcePack pack)
      Get a pack's URL. Potentially with the hash appended to work around MC-164316
      Parameters:
      pack - The pack to get the URL for
      Returns:
      The url
    • shouldAppendHashToUrl

      public boolean shouldAppendHashToUrl()
      Whether to append the hash to the URL of a pack or not
      Returns:
      Whether to append the hash to the URL of a pack or not
    • setAppendHashToUrl

      public void setAppendHashToUrl(boolean appendHashToUrl)
      Set whether to append the hash to the URL of a pack or not
      Parameters:
      appendHashToUrl - Whether to append the hash to the URL of a pack or not
    • 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