Class PackManager
java.lang.Object
de.themoep.resourcepacksplugin.core.PackManager
Created by Phoenix616 on 25.03.2015.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The result of setting a pack -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAssignment
(PackAssignment assignment) Add a new assignment to a server/worldaddPack
(ResourcePack pack) Registers a new resource pack with the packmanagerapplyPack
(ResourcepacksPlayer player, String serverName) Apply the pack that a player should have on that server/worldvoid
Deprecated.void
Check whether or not the manager state is dirty and if so save the configprotected IResourcePackSelectEvent.Status
checkPack
(UUID playerId, ResourcePack pack, IResourcePackSelectEvent.Status status) protected IResourcePackSelectEvent.Status
checkPacks
(UUID playerId, List<ResourcePack> packs, IResourcePackSelectEvent.Status status) void
generateHashes
(ResourcepacksPlayer sender) Download the pack files and generate sha1 hashes from them, also saves the changes to the config!getApplicablePacks
(ResourcepacksPlayer player, String serverName) Get the pack the player should have on that servergetApplicablePacks
(UUID playerId, String serverName) Deprecated.UsegetApplicablePacks(ResourcepacksPlayer, String)
instead@NonNull PackAssignment
getAssignment
(String server) Get the assignment of a server/worldgetAssignmentByName
(String name) Get an assignment by its nameCollection<? extends PackAssignment>
Get all assignmentsgetByHash
(byte[] hash) Get the resourcepack by its hashGet the resourcepack by its hashGet the resourcepack by its nameGet the resourcepack by its urlGet the resourcepack by its uuidGet the empty Resource PackGet the global assignmentint
getPackFormat
(int version) Get the format of the pack a player can maximally usegetPacks()
Get a list of all packsgetPackUrl
(ResourcePack pack) Get a pack's URL.boolean
Get whether or not stored packs should override assignmentsvoid
init()
Initialize this pack managerloadAssignment
(String name, Map<String, Object> config) Load an assignment from a map representing the section in the configCreates a new ResourcePack instance from a config.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).boolean
removeAssignment
(PackAssignment assignment) Removes the assignment of a server/worldboolean
removeAssignment
(String key) Removes the assignment of a server/worldboolean
removePack
(ResourcePack pack) Unregisters a resource pack from the packmanagerboolean
removeServer
(String server) Deprecated.void
setAppendHashToUrl
(boolean appendHashToUrl) Set whether to append the hash to the URL of a pack or notvoid
setDirty
(boolean dirty) Mark the manager state as dirty so it gets saved on next modificationsetEmptyPack
(ResourcePack pack) Set the empty Resource PacksetEmptyPack
(String packname) Set the empty Resource Packvoid
setGlobalAssignment
(PackAssignment assignment) Set the global assignment@NonNull PackManager.PackSetResult
setPack
(UUID playerId, ResourcePack pack) Set the pack of a player and send it to him, calls a ResourcePackSendEvent@NonNull PackManager.PackSetResult
setPack
(UUID playerId, ResourcePack pack, boolean temporary) Set the pack of a player and send it to him, calls a ResourcePackSendEvent@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 ResourcePackSendEventboolean
setPackHash
(ResourcePack pack, String hash) Set the hash of a pack to a new valueboolean
setPackPath
(ResourcePack pack, String path) Set the url of a pack to a new valueboolean
setPackUrl
(ResourcePack pack, String url) Set the url of a pack to a new valueboolean
setPackUuid
(ResourcePack pack, UUID uuid) Set the uuid of a pack to a new valuevoid
setStoredPacksOverride
(boolean playerPacksOverride) Set whether or not stored packs should override assignmentsboolean
Whether to append the hash to the URL of a pack or not
-
Field Details
-
EMPTY_IDENTIFIER
- See Also:
-
HASH_KEY
- See Also:
-
-
Constructor Details
-
PackManager
-
-
Method Details
-
init
public void init()Initialize this pack manager -
loadPack
public ResourcePack loadPack(String name, Map<String, Object> config) throws IllegalArgumentExceptionCreates a new ResourcePack instance from a config. Does not add it!- Parameters:
name
- The name of the packconfig
-- Returns:
- Throws:
IllegalArgumentException
-
addPack
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
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
Set the uuid of a pack to a new value- Parameters:
pack
- The pack to updateuuid
- The uuid to set- Returns:
- Whether or not the hash changed
-
setPackHash
Set the hash of a pack to a new value- Parameters:
pack
- The pack to updatehash
- The new hash to set- Returns:
- Whether or not the hash changed
-
setPackUrl
Set the url of a pack to a new value- Parameters:
pack
- The pack to updateurl
- The new url to set- Returns:
- Whether or not the url changed
-
setPackPath
Set the url of a pack to a new value- Parameters:
pack
- The pack to updatepath
- The new local path to set- Returns:
- Whether or not the url changed
-
getByName
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
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
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
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
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
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
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
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
Get the global assignment- Returns:
- The global PackAssignment
-
setGlobalAssignment
Set the global assignment- Parameters:
assignment
- The PackAssignment that you want to set
-
addAssignment
Add a new assignment to a server/world- Parameters:
assignment
- The new PackAssignment- Returns:
- The previous assignment or null if there was none
-
getAssignment
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
Get an assignment by its name- Parameters:
name
- The name of the assignment- Returns:
- The PackAssignment or null if not found
-
getAssignments
Get all assignments- Returns:
- The all PackAssignments
-
loadAssignment
Load an assignment from a map representing the section in the config- Parameters:
name
- The name of the assignmentconfig
- A map representing the config section- Returns:
- The PackAssignment
-
removeServer
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
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
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
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 forpack
- 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 forpack
- The ResourcePack to set, if it is null/empty it will reset to empty if the player has a pack appliedtemporary
- 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 forpack
- The ResourcePack to settemporary
- 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
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 eventprev
- The previous packs- Returns:
- The pack that should be sent to the player or null if no pack should be sent
-
applyPack
Deprecated.UseapplyPack(ResourcepacksPlayer, String)
insteadApply the pack that a player should have on that server/world- Parameters:
playerId
- The UUID of the playerserverName
- The name of the server/world
-
applyPack
Apply the pack that a player should have on that server/world- Parameters:
player
- The playerserverName
- The name of the server/world- Returns:
- The packs that were loaded by the client
-
getApplicablePacks
Deprecated.UsegetApplicablePacks(ResourcepacksPlayer, String)
insteadGet the pack the player should have on that server- Parameters:
playerId
- The UUID of the playerserverName
- 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 playerserverName
- 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
Get a list of all packs- Returns:
- A new array list of packs
-
generateHashes
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
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
-
applyPack(ResourcepacksPlayer, String)
instead