Class Job

java.lang.Object
me.fami6xx.rpuniverse.core.jobs.Job

public class Job extends Object
Represents a job in the system.
  • Constructor Details

    • Job

      public Job()
      Creates a new AJob instance that is empty.
    • Job

      public Job(String jobName, int jobBank, org.bukkit.Location bossMenuLocation)
      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

      public UUID 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

      public String 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

      public void renameJob(String newName)
      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

      @Nullable public JobType getJobType()
      Retrieves the job type of the job.
      Returns:
      The job type of the job as a JobType object.
    • getJobTypeName

      public String getJobTypeName()
      Retrieves the name of the job type.
      Returns:
      The name of the job type as a String.
    • setJobType

      public void setJobType(@NotNull @NotNull JobType jobType)
      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

      public void movePositionUpAndDown(String positionName, boolean moveUp)
      Moves the position up or down in the job positions list.
      Parameters:
      positionName - the name of the position to move
      moveUp - true if the position should be moved up, false otherwise
    • addPosition

      public void addPosition(Position position)
      Adds a position to the jobPositions list.
      Parameters:
      position - The position to be added.
    • editPosition

      public void editPosition(String positionName, Position updatedPosition)
      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

      public void removePosition(String positionName)
      Removes a position from the jobPositions list based on the position name.
      Parameters:
      positionName - The name of the position to be removed.
    • getPositions

      public List<Position> getPositions()
      Retrieves the list of positions associated with the job.
      Returns:
      A List of Position objects representing the job positions.
    • getPositionByName

      public Position getPositionByName(String name)
      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

      public boolean checkPositions(List<Position> positions)
      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:
      true if the list contains at least one default position and at least one boss position, false otherwise.
    • isJobReady

      public List<String> 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

      public void changePlayerPosition(UUID playerUUID, Position newPosition)
      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:
      true if the money was successfully removed from the job bank, false otherwise.
    • 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

      public void addPlayerToJob(UUID playerUUID, Position position)
      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

      public void addPlayerToJob(UUID playerUUID)
      Adds a player to a job by associating their UUID with the default position.
      Parameters:
      playerUUID - The UUID of the player to add.
    • removePlayerFromJob

      public void removePlayerFromJob(UUID playerUUID)
      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

      public boolean isPlayerInJob(UUID playerUUID)
      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:
      true if the player is in a job, false otherwise.
    • getPlayerPosition

      @Nullable public Position getPlayerPosition(UUID playerUUID)
      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

      public List<UUID> getAllPlayersInJob()
      Retrieves a list of all players in a job.
      Returns:
      a List of UUID representing the player IDs in the job.
    • canPlayerKickPlayer

      public boolean canPlayerKickPlayer(UUID playerUUID, UUID playerToKickUUID)
      Determines if a player can kick another player based on their positions.
      Parameters:
      playerUUID - the UUID of the player initiating the kick
      playerToKickUUID - the UUID of the player to be kicked
      Returns:
      true if the player can kick the other player, false otherwise
    • getAllPositionsPlayerCanAssign

      public List<Position> getAllPositionsPlayerCanAssign(UUID playerUUID)
      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

      @Nullable public static Job getJob(String jobName)
      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

      @Nullable public static Job getJobByUUID(String jobUUID)
      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

      public static Job fromString(String s)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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.