Package me.fami6xx.rpuniverse.core.jobs
Class Job
java.lang.Object
me.fami6xx.rpuniverse.core.jobs.Job
Represents a job in the system.
-
Constructor Summary
ConstructorsConstructorDescriptionJob()Creates a new AJob instance that is empty.Creates a new AJob instance with the given parameters.Job(String jobName, int jobBank, org.bukkit.Location bossMenuLocation, List<Position> jobPositions)Creates a new AJob instance with the given parameters.Job(String jobName, int jobBank, org.bukkit.Location bossMenuLocation, List<Position> jobPositions, Map<UUID,Position> playerPositions)Creates a new AJob instance with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMoneyToJobBank(double money)Adds the specified amount of money to the job bank.voidaddPlayerToJob(UUID playerUUID)Adds a player to a job by associating their UUID with the default position.voidaddPlayerToJob(UUID playerUUID, Position position)Adds a player to a job by associating their UUID with a position.voidaddPosition(Position position)Adds a position to the jobPositions list.booleancanPlayerKickPlayer(UUID playerUUID, UUID playerToKickUUID)Determines if a player can kick another player based on their positions.voidchangePlayerPosition(UUID playerUUID, Position newPosition)Changes the position of a player by updating the player's UUID and the new position in the playerPositions map.booleancheckPositions(List<Position> positions)Checks if a list of positions contains at least one default position and at least one boss position.protected voidCreates a hologram for the boss menu.voideditPosition(String positionName, Position updatedPosition)Edits the details of a position in the job.static JobfromString(String s)Retrieves a list of all players in a job.getAllPositionsPlayerCanAssign(UUID playerUUID)Returns a list of all positions that a player can assign to.org.bukkit.LocationRetrieves the location of the boss menu associated with the job.doubleRetrieves the current amount of money available in the job bank.static JobRetrieves a Job object with the specified job name.static JobgetJobByUUID(String jobUUID)Retrieves a Job object with the specified job UUID.Retrieves the job type of the job.com.google.gson.JsonObjectRetrieves the job type data of the job.Retrieves the name of the job type.getName()Retrieves the name of the job.getPlayerPosition(UUID playerUUID)Retrieves the position of a player identified by their UUID.getPositionByName(String name)Retrieves a Position object from the jobPositions list based on the provided position name.Retrieves the list of positions associated with the job.intRetrieves the salaryInterval field.protected voidInitializes the object by creating the boss menu hologram.booleanRetrieves the bossCanEditPositions field.booleanRetrieves the bossCanRemoveMoneyFromBank field.Checks if the job is ready to be executed by validating various conditions.booleanisPlayerInJob(UUID playerUUID)Checks whether a player is in a job by checking if their UUID is associated with a position.booleanRetrieves the playersReceiveSalary field.booleanRetrieves the bossCanRemoveMoneyFromBank field.voidmovePositionUpAndDown(String positionName, boolean moveUp)Moves the position up or down in the job positions list.voidPrepares the Job object for saving by serializing the jobType to a JSON string.protected voidremove()Removes the job by deleting the boss menu hologram if it exists.booleanremoveMoneyFromJobBank(double money)Removes the specified amount of money from the job bank.voidremovePlayerFromJob(UUID playerUUID)Removes a player from the job by removing their UUID from the playerPositions map.voidremovePosition(String positionName)Removes a position from the jobPositions list based on the position name.voidRenames the job with the given new name.voidsetBossCanEditPositions(boolean bossCanEditPositions)Sets the bossCanEditPositions field.voidsetBossCanRemoveMoneyFromBank(boolean bossCanRemoveMoneyFromBank)Sets the bossCanRemoveMoneyFromBank field.voidsetBossMenuLocation(org.bukkit.Location location)Sets the location of the boss menu associated with the job.voidsetJobBank(double jobBank)Retrieves the current amount of money available in the job bank.voidsetJobType(@NotNull JobType jobType)Sets the job type of the job.voidsetPlayersReceiveSalary(boolean playersReceiveSalary)Sets the playersReceiveSalary field.voidsetSalaryBeingRemovedFromBank(boolean salaryBeingRemovedFromBank)Sets the salaryBeingRemovedFromBank field.voidsetSalaryInterval(int salaryInterval)Sets the salaryInterval field.toString()
-
Constructor Details
-
Job
public Job()Creates a new AJob instance that is empty. -
Job
Creates a new AJob instance with the given parameters.- Parameters:
jobName- The name of the job.jobBank- The initial amount of money in the job bank. Must be a positive integer.bossMenuLocation- The location of the boss menu.
-
Job
public Job(String jobName, int jobBank, org.bukkit.Location bossMenuLocation, List<Position> jobPositions)Creates a new AJob instance with the given parameters.- Parameters:
jobName- The name of the job.jobBank- The initial amount of money in the job bank. Must be a positive integer.bossMenuLocation- The location of the boss menu.jobPositions- The list of positions associated with the job.
-
Job
public Job(String jobName, int jobBank, org.bukkit.Location bossMenuLocation, List<Position> jobPositions, Map<UUID,Position> playerPositions)Creates a new AJob instance with the given parameters.- Parameters:
jobName- The name of the job.jobBank- The initial amount of money in the job bank. Must be a positive integer.bossMenuLocation- The location of the boss menu.jobPositions- The list of positions associated with the job.playerPositions- The map of player UUID to their assigned position.
-
-
Method Details
-
getJobUUID
-
initialize
protected void initialize()Initializes the object by creating the boss menu hologram. -
remove
protected void remove()Removes the job by deleting the boss menu hologram if it exists. -
createBossMenuHologram
protected void createBossMenuHologram()Creates a hologram for the boss menu. If bossMenuLocation is not null, creates a static hologram with the specified range. The hologram displays information about the job, such as job name, job bank, and job type. The hologram has two pages - one for regular players and one for admins. The regular player page allows opening the JobAdminMenu. The admin page allows opening the JobAdminMenu as well. -
getName
Retrieves the name of the job.- Returns:
- The name of the job as a String.
-
isBossCanEditPositions
public boolean isBossCanEditPositions()Retrieves the bossCanEditPositions field.- Returns:
- The bossCanEditPositions field as a boolean.
-
setBossCanEditPositions
public void setBossCanEditPositions(boolean bossCanEditPositions)Sets the bossCanEditPositions field.- Parameters:
bossCanEditPositions- The value to set the bossCanEditPositions field to.
-
isPlayersReceiveSalary
public boolean isPlayersReceiveSalary()Retrieves the playersReceiveSalary field.- Returns:
- The playersReceiveSalary field as a boolean.
-
setPlayersReceiveSalary
public void setPlayersReceiveSalary(boolean playersReceiveSalary)Sets the playersReceiveSalary field.- Parameters:
playersReceiveSalary- The value to set the playersReceiveSalary field to.
-
getSalaryInterval
public int getSalaryInterval()Retrieves the salaryInterval field. This field is in seconds.- Returns:
- The salaryInterval field as an integer.
-
setSalaryInterval
public void setSalaryInterval(int salaryInterval)Sets the salaryInterval field. This field is in seconds.- Parameters:
salaryInterval- The value to set the salaryInterval field to.
-
renameJob
Renames the job with the given new name.- Parameters:
newName- The new name for the job. Must not be null.
-
getBossMenuLocation
public org.bukkit.Location getBossMenuLocation()Retrieves the location of the boss menu associated with the job.- Returns:
- The location of the boss menu as a Location object.
-
setBossMenuLocation
public void setBossMenuLocation(@Nonnull org.bukkit.Location location)Sets the location of the boss menu associated with the job.- Parameters:
location- The location of the boss menu. Must not be null.
-
getJobType
Retrieves the job type of the job.- Returns:
- The job type of the job as a JobType object.
-
getJobTypeName
Retrieves the name of the job type.- Returns:
- The name of the job type as a String.
-
setJobType
Sets the job type of the job. Requires that the Job Type has been new instanced.JobType#getNewInstance(Job)- Parameters:
jobType- The job type to be set. Must not be null.
-
getJobTypeData
public com.google.gson.JsonObject getJobTypeData()Retrieves the job type data of the job.- Returns:
- The job type data of the job as a String.
-
movePositionUpAndDown
Moves the position up or down in the job positions list.- Parameters:
positionName- the name of the position to movemoveUp- true if the position should be moved up, false otherwise
-
addPosition
Adds a position to the jobPositions list.- Parameters:
position- The position to be added.
-
editPosition
Edits the details of a position in the job.- Parameters:
positionName- The name of the position to be edited.updatedPosition- The updated details of the position.
-
removePosition
Removes a position from the jobPositions list based on the position name.- Parameters:
positionName- The name of the position to be removed.
-
getPositions
Retrieves the list of positions associated with the job.- Returns:
- A List of Position objects representing the job positions.
-
getPositionByName
Retrieves a Position object from the jobPositions list based on the provided position name.- Parameters:
name- The name of the position to retrieve. Must not be null.- Returns:
- The Position object with the specified name, or null if no position with that name exists.
-
checkPositions
Checks if a list of positions contains at least one default position and at least one boss position.- Parameters:
positions- The list of positions to check.- Returns:
trueif the list contains at least one default position and at least one boss position,falseotherwise.
-
isJobReady
Checks if the job is ready to be executed by validating various conditions.- Returns:
- A list of error messages indicating the reasons why the job is not ready. An empty list signifies that the job is ready.
-
changePlayerPosition
Changes the position of a player by updating the player's UUID and the new position in the playerPositions map.- Parameters:
playerUUID- The UUID of the player to change the position for.newPosition- The new position to assign to the player.
-
addMoneyToJobBank
public void addMoneyToJobBank(double money)Adds the specified amount of money to the job bank. Calls the MoneyAddedToJobBankEvent.- Parameters:
money- The amount of money to add to the job bank. Must be a positive integer.
-
removeMoneyFromJobBank
public boolean removeMoneyFromJobBank(double money)Removes the specified amount of money from the job bank. Calls the MoneyRemovedFromJobBankEvent.- Parameters:
money- The amount of money to remove from the job bank. Must be a positive integer.- Returns:
trueif the money was successfully removed from the job bank,falseotherwise.
-
getCurrentMoneyInJobBank
public double getCurrentMoneyInJobBank()Retrieves the current amount of money available in the job bank.- Returns:
- An integer representing the current amount of money in the job bank.
-
setJobBank
public void setJobBank(double jobBank)Retrieves the current amount of money available in the job bank. It doesn't round the value. It doesn't call any event.- Parameters:
jobBank- The new amount of money in the job bank.
-
addPlayerToJob
Adds a player to a job by associating their UUID with a position.- Parameters:
playerUUID- The UUID of the player to add.position- The position to associate the player with.
-
addPlayerToJob
Adds a player to a job by associating their UUID with the default position.- Parameters:
playerUUID- The UUID of the player to add.
-
removePlayerFromJob
Removes a player from the job by removing their UUID from the playerPositions map.- Parameters:
playerUUID- The UUID of the player to remove from the job.
-
isPlayerInJob
Checks whether a player is in a job by checking if their UUID is associated with a position.- Parameters:
playerUUID- The UUID of the player to check.- Returns:
trueif the player is in a job,falseotherwise.
-
getPlayerPosition
Retrieves the position of a player identified by their UUID.- Parameters:
playerUUID- The UUID of the player.- Returns:
- The position of the player, or null if the player's position is not found.
-
getAllPlayersInJob
Retrieves a list of all players in a job. -
canPlayerKickPlayer
Determines if a player can kick another player based on their positions.- Parameters:
playerUUID- the UUID of the player initiating the kickplayerToKickUUID- the UUID of the player to be kicked- Returns:
- true if the player can kick the other player, false otherwise
-
getAllPositionsPlayerCanAssign
Returns a list of all positions that a player can assign to.- Parameters:
playerUUID- the UUID of the player- Returns:
- a list of Position objects that the player can assign to, empty if none found
-
prepareForSave
public void prepareForSave()Prepares the Job object for saving by serializing the jobType to a JSON string.This method checks if the jobType field is not null. If it is not null, it serializes the jobType to a JSON string using the
JobType.getJsonJobTypeData()method. The JSON string is then stored in the JSONJobTypeData field of the Job object.Note that it is crucial to use the GSON library to serialize the jobType to a JSON string.
- See Also:
JobType.getJsonJobTypeData()
-
getJob
Retrieves a Job object with the specified job name.- Parameters:
jobName- The name of the job to retrieve. Must not be null.- Returns:
- The Job object with the specified job name, or null if no job with that name exists.
-
getJobByUUID
Retrieves a Job object with the specified job UUID.- Parameters:
jobUUID- The UUID of the job to retrieve. Must not be null.- Returns:
- The Job object with the specified job UUID, or null if no job with that UUID exists.
-
fromString
-
toString
-
isSalaryBeingRemovedFromBank
public boolean isSalaryBeingRemovedFromBank()Retrieves the bossCanRemoveMoneyFromBank field.- Returns:
- The bossCanRemoveMoneyFromBank field as a boolean.
-
setSalaryBeingRemovedFromBank
public void setSalaryBeingRemovedFromBank(boolean salaryBeingRemovedFromBank)Sets the salaryBeingRemovedFromBank field.- Parameters:
salaryBeingRemovedFromBank- The value to set the salaryBeingRemovedFromBank field to.
-
isBossCanRemoveMoneyFromBank
public boolean isBossCanRemoveMoneyFromBank()Retrieves the bossCanRemoveMoneyFromBank field.- Returns:
- The bossCanRemoveMoneyFromBank field as a boolean.
-
setBossCanRemoveMoneyFromBank
public void setBossCanRemoveMoneyFromBank(boolean bossCanRemoveMoneyFromBank)Sets the bossCanRemoveMoneyFromBank field.- Parameters:
bossCanRemoveMoneyFromBank- The value to set the bossCanRemoveMoneyFromBank field to.
-