1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 22:13:25 +01:00
Jobs/com/gamingmesh/jobs/container/Job.java

378 lines
11 KiB
Java
Raw Normal View History

2015-08-21 15:10:08 +02:00
/**
* Jobs Plugin for Bukkit
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gamingmesh.jobs.container;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.config.ConfigManager;
import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.stuff.ChatColor;
public class Job {
2016-01-09 13:58:33 +01:00
// job info
private EnumMap<ActionType, List<JobInfo>> jobInfo = new EnumMap<ActionType, List<JobInfo>>(ActionType.class);
// permissions
private List<JobPermission> jobPermissions;
// commands
private List<JobCommands> jobCommands;
// conditions
private List<JobConditions> jobConditions;
// items
private List<JobItems> jobItems;
// limited items
private List<JobLimitedItems> jobLimitedItems;
// job name
private String jobName;
// job short name (for use in multiple jobs)
private String jobShortName;
// short description of the job
private String description;
// job chat colour
private ChatColor jobColour;
// job leveling equation
private Parser maxExpEquation;
// display method
private DisplayMethod displayMethod;
// max level
private int maxLevel;
// vip max level
private int vipmaxLevel = 0;
// max number of people allowed with this job on the server.
private Integer maxSlots;
// Commands to be performed on player job join
private List<String> CmdOnJoin = new ArrayList<String>();
// Commands to be performed on player job leave
private List<String> CmdOnLeave = new ArrayList<String>();
// Item for GUI
private ItemStack GUIitem;
private int totalPlayers = -1;
private double bonus = 0.0;
private double ExpBoost = 1.0;
private double MoneyBoost = 1.0;
/**
* Constructor
* @param jobName - the name of the job
* @param jobShortName - the shortened version of the name of the job.
* @param description - a short description of the job.
* @param jobColour - the colour of the job title as displayed in chat.
* @param maxExpEquation - the equation by which the exp needed to level up is calculated
* @param displayMethod - the display method for this job.
* @param maxLevel - the maximum level allowed (null for no max level)
* @param vipmaxLevel - the maximum vip level allowed (null for no max level)
* @param maxSlots - the maximum number of people allowed to have this job at one time (null for no limits)
* @param jobPermissions - permissions gained for having the job
* @param jobCommands - commands to perform on levelup
* @param jobItems - items with boost
* @param jobLimitedItems - limited items by lvl
* @param CmdOnJoin - commands performed on player join
* @param CmdOnLeave - commands performed on player leave
* @param jobConditions - jobs conditions
*/
public Job(String jobName, String jobShortName, String description, ChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, List<JobItems> jobItems,
List<JobLimitedItems> jobLimitedItems, List<String> CmdOnJoin, List<String> CmdOnLeave, ItemStack GUIitem) {
this.jobName = jobName;
this.jobShortName = jobShortName;
this.description = description;
this.jobColour = jobColour;
this.maxExpEquation = maxExpEquation;
this.displayMethod = displayMethod;
this.maxLevel = maxLevel;
this.vipmaxLevel = vipmaxLevel;
this.maxSlots = maxSlots;
this.jobPermissions = jobPermissions;
this.jobCommands = jobCommands;
this.jobConditions = jobConditions;
this.jobItems = jobItems;
this.jobLimitedItems = jobLimitedItems;
this.CmdOnJoin = CmdOnJoin;
this.CmdOnLeave = CmdOnLeave;
this.GUIitem = GUIitem;
}
public void setMoneyBoost(double amount) {
this.MoneyBoost = amount;
}
public double getMoneyBoost() {
return this.MoneyBoost;
}
public void setExpBoost(double amount) {
this.ExpBoost = amount;
}
public double getExpBoost() {
return this.ExpBoost;
}
public int getTotalPlayers() {
if (this.totalPlayers == -1) {
this.totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(this.jobName);
updateBonus();
2015-08-21 15:10:08 +02:00
}
2016-01-09 13:58:33 +01:00
return this.totalPlayers;
}
public void updateTotalPlayers() {
this.totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(this.jobName);
updateBonus();
}
public void updateBonus() {
if (!ConfigManager.getJobsConfiguration().useDynamicPayment)
return;
Parser eq = ConfigManager.getJobsConfiguration().DynamicPaymentEquation;
eq.setVariable("totalworkers", Jobs.getJobsDAO().getTotalPlayers());
eq.setVariable("totaljobs", Jobs.getJobs().size());
eq.setVariable("jobstotalplayers", getTotalPlayers());
double now = eq.getValue();
if (now > ConfigManager.getJobsConfiguration().DynamicPaymentMaxBonus)
now = ConfigManager.getJobsConfiguration().DynamicPaymentMaxBonus;
if (now < ConfigManager.getJobsConfiguration().DynamicPaymentMaxPenalty * -1)
now = ConfigManager.getJobsConfiguration().DynamicPaymentMaxPenalty * -1;
this.bonus = now;
}
public double getBonus() {
if (this.bonus == 0.0)
updateBonus();
return this.bonus;
}
public List<String> getCmdOnJoin() {
return this.CmdOnJoin;
}
public List<String> getCmdOnLeave() {
return this.CmdOnLeave;
}
public ItemStack getGuiItem() {
return this.GUIitem;
}
/**
* Sets job info for action type
* @param type - The action type
* @param info - the job info
*/
public void setJobInfo(ActionType type, List<JobInfo> info) {
jobInfo.put(type, info);
}
/**
* Gets the job info for the particular type
* @param type - The action type
* @return Job info list
*/
public List<JobInfo> getJobInfo(ActionType type) {
return Collections.unmodifiableList(jobInfo.get(type));
}
/**
* Gets the job info list
* @return Job info list
*/
public EnumMap<ActionType, List<JobInfo>> getJobInfoList() {
return jobInfo;
}
/**
* Function to get the income for an action
* @param action - The action info
* @param level - players job level
* @param numjobs - number of jobs for the player
* @return the income received for performing action
*/
public Double getIncome(ActionInfo action, int level, int numjobs) {
List<JobInfo> jobInfo = getJobInfo(action.getType());
for (JobInfo info : jobInfo) {
if (info.getName().equalsIgnoreCase(action.getName()) || info.getName().equalsIgnoreCase(action.getNameWithSub())) {
2016-01-22 13:42:25 +01:00
if (!info.isInLevelRange(level))
return 0D;
2016-01-09 13:58:33 +01:00
return info.getIncome(level, numjobs);
}
2015-08-21 15:10:08 +02:00
}
2016-01-09 13:58:33 +01:00
return null;
}
/**
* Function to get the income for an action
* @param action - The action info
* @param level - players job level
* @param numjobs - number of jobs for the player
* @return the income received for performing action
*/
public Double getExperience(ActionInfo action, int level, int numjobs) {
List<JobInfo> jobInfo = getJobInfo(action.getType());
for (JobInfo info : jobInfo) {
2016-01-22 13:42:25 +01:00
if (info.getName().equalsIgnoreCase(action.getName()) || info.getName().equalsIgnoreCase(action.getNameWithSub())){
if (!info.isInLevelRange(level))
return 0D;
2016-01-09 13:58:33 +01:00
return info.getExperience(level, numjobs);
2016-01-22 13:42:25 +01:00
}
2015-08-21 15:10:08 +02:00
}
2016-01-09 13:58:33 +01:00
return null;
}
/**
* Get the job name
* @return the job name
*/
public String getName() {
return jobName;
}
/**
* Get the shortened version of the jobName
* @return the shortened version of the jobName
*/
public String getShortName() {
return jobShortName;
}
/**
* Gets the description
* @return description
*/
public String getDescription() {
return description;
}
/**
* Get the Color of the job for chat
* @return the Color of the job for chat
*/
public ChatColor getChatColor() {
return jobColour;
}
/**
* Get the MaxExpEquation of the job
* @return the MaxExpEquation of the job
*/
public Parser getMaxExpEquation() {
return maxExpEquation;
}
/**
* Function to return the appropriate max exp for this level
* @param level - current level
* @return the correct max exp for this level
*/
public double getMaxExp(Map<String, Double> param) {
for (Map.Entry<String, Double> temp : param.entrySet()) {
maxExpEquation.setVariable(temp.getKey(), temp.getValue());
2015-08-21 15:10:08 +02:00
}
2016-01-09 13:58:33 +01:00
return maxExpEquation.getValue();
}
/**
* Function to get the display method
* @return the display method
*/
public DisplayMethod getDisplayMethod() {
return displayMethod;
}
/**
* Function to return the maximum level
* @return the max level
* @return null - no max level
*/
public int getMaxLevel() {
return maxLevel;
}
/**
* Function to return the maximum level
* @return the max level
* @return null - no max level
*/
public int getVipMaxLevel() {
return vipmaxLevel;
}
/**
* Function to return the maximum slots
* @return the max slots
* @return null - no max slots
*/
public Integer getMaxSlots() {
return maxSlots;
}
/**
* Get the permission nodes for this job
* @return Permissions for this job
*/
public List<JobPermission> getPermissions() {
return Collections.unmodifiableList(jobPermissions);
}
/**
* Get the command nodes for this job
* @return Commands for this job
*/
public List<JobCommands> getCommands() {
return Collections.unmodifiableList(jobCommands);
}
/**
* Get the conditions for this job
* @return Conditions for this job
*/
public List<JobConditions> getConditions() {
return Collections.unmodifiableList(jobConditions);
}
/**
* Get the item nodes for this job
* @return Items for this job
*/
public List<JobItems> getItems() {
return Collections.unmodifiableList(jobItems);
}
/**
* Get the limited item nodes for this job
* @return Limited items for this job
*/
public List<JobLimitedItems> getLimitedItems() {
return Collections.unmodifiableList(jobLimitedItems);
}
2015-08-21 15:10:08 +02:00
}