1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-31 21:37:57 +01:00

Hiding more information when requirements are not met for shop items

This commit is contained in:
Zrips 2023-06-23 13:44:18 +03:00
parent 789e8ff7a6
commit aba467be70
3 changed files with 263 additions and 240 deletions

View File

@ -65,6 +65,7 @@ import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.NBT.CMINBT; import net.Zrips.CMILib.NBT.CMINBT;
import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Version;
@ -487,6 +488,9 @@ public class PlayerManager {
job.updateTotalPlayers(); job.updateTotalPlayers();
jPlayer.maxJobsEquation = getMaxJobs(jPlayer); jPlayer.maxJobsEquation = getMaxJobs(jPlayer);
// Removing from cached item boost for recalculation
cache.remove(jPlayer.getUniqueId());
} }
private static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) { private static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) {
@ -528,6 +532,10 @@ public class PlayerManager {
Jobs.getSignUtil().updateAllSign(job); Jobs.getSignUtil().updateAllSign(job);
job.updateTotalPlayers(); job.updateTotalPlayers();
// Removing from cached item boost for recalculation
cache.remove(jPlayer.getUniqueId());
return true; return true;
} }
@ -1055,6 +1063,8 @@ public class PlayerManager {
continue; continue;
} }
} }
CMIDebug.d("get bonus item");
jitems.add(getJobsItemByNbt(item)); jitems.add(getJobsItemByNbt(item));
} }
} }

View File

@ -113,11 +113,14 @@ public class ShopManager {
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
CMIMaterial mat = CMIMaterial.get(item.getIconMaterial()); CMIMaterial mat = CMIMaterial.get(item.getIconMaterial());
boolean hiddenLore = false;
if (item.isHideWithoutPerm()) { if (item.isHideWithoutPerm()) {
for (String onePerm : item.getRequiredPerm()) { for (String onePerm : item.getRequiredPerm()) {
if (!player.hasPermission(onePerm)) { if (!player.hasPermission(onePerm)) {
mat = CMIMaterial.STONE_BUTTON; mat = CMIMaterial.STONE_BUTTON;
lore.add(Jobs.getLanguage().getMessage("command.shop.info.NoPermToBuy")); lore.add(Jobs.getLanguage().getMessage("command.shop.info.NoPermToBuy"));
hiddenLore = true;
break; break;
} }
} }
@ -127,6 +130,7 @@ public class ShopManager {
jPlayer.getTotalLevels() < item.getRequiredTotalLevels()) { jPlayer.getTotalLevels() < item.getRequiredTotalLevels()) {
mat = CMIMaterial.STONE_BUTTON; mat = CMIMaterial.STONE_BUTTON;
lore.add(Jobs.getLanguage().getMessage("command.shop.info.NoPoints")); lore.add(Jobs.getLanguage().getMessage("command.shop.info.NoPoints"));
hiddenLore = true;
} }
if (mat == CMIMaterial.NONE) if (mat == CMIMaterial.NONE)
@ -142,48 +146,50 @@ public class ShopManager {
if (item.getIconName() != null) if (item.getIconName() != null)
meta.setDisplayName(item.getIconName()); meta.setDisplayName(item.getIconName());
lore.addAll(item.getIconLore()); if (!hiddenLore) {
lore.addAll(item.getIconLore());
if (item.getPointPrice() > 0) { if (item.getPointPrice() > 0) {
String color = item.getPointPrice() >= points ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor"); String color = item.getPointPrice() >= points ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor");
lore.add(Jobs.getLanguage().getMessage("command.shop.info.pointsPrice", "%currentpoints%", color + points, "%price%", item.getPointPrice())); lore.add(Jobs.getLanguage().getMessage("command.shop.info.pointsPrice", "%currentpoints%", color + points, "%price%", item.getPointPrice()));
}
if (item.getVaultPrice() > 0) {
String color = item.getVaultPrice() >= balance ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor");
lore.add(Jobs.getLanguage().getMessage("command.shop.info.moneyPrice", "%currentbalance%", color + Jobs.getEconomy().getEconomy().format(balance), "%price%", item.getVaultPrice()));
}
if (!item.getRequiredJobs().isEmpty()) {
lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobs"));
for (Entry<String, Integer> one : item.getRequiredJobs().entrySet()) {
Job job = Jobs.getJob(one.getKey());
if (job == null) {
continue;
}
String jobColor = "";
String levelColor = "";
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null) {
jobColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsColor");
levelColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsLevelColor");
}
if (prog != null && prog.getLevel() < one.getValue())
levelColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsLevelColor");
lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobsList", "%jobsname%",
jobColor + one.getKey(), "%level%", levelColor + one.getValue()));
} }
}
if (item.getRequiredTotalLevels() != -1) { if (item.getVaultPrice() > 0) {
lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevel", String color = item.getVaultPrice() >= balance ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor");
"%totalLevel%", (jPlayer.getTotalLevels() < item.getRequiredTotalLevels() lore.add(Jobs.getLanguage().getMessage("command.shop.info.moneyPrice", "%currentbalance%", color + Jobs.getEconomy().getEconomy().format(balance), "%price%", item.getVaultPrice()));
? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels())); }
if (!item.getRequiredJobs().isEmpty()) {
lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobs"));
for (Entry<String, Integer> one : item.getRequiredJobs().entrySet()) {
Job job = Jobs.getJob(one.getKey());
if (job == null) {
continue;
}
String jobColor = "";
String levelColor = "";
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null) {
jobColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsColor");
levelColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsLevelColor");
}
if (prog != null && prog.getLevel() < one.getValue())
levelColor = Jobs.getLanguage().getMessage("command.shop.info.reqJobsLevelColor");
lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobsList", "%jobsname%",
jobColor + one.getKey(), "%level%", levelColor + one.getValue()));
}
}
if (item.getRequiredTotalLevels() != -1) {
lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevel",
"%totalLevel%", (jPlayer.getTotalLevels() < item.getRequiredTotalLevels()
? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels()));
}
} }
meta.setLore(lore); meta.setLore(lore);

View File

@ -101,41 +101,41 @@ public class Job {
@Deprecated @Deprecated
public Job(String jobName, String jobDisplayName, String fullName, String jobShortName, String description, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel, public Job(String jobName, String jobDisplayName, String fullName, String jobShortName, String description, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, Map<String, JobItems> jobItems, int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, Map<String, JobItems> jobItems,
Map<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) { Map<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) {
this(jobName, jobDisplayName, fullName, jobShortName, jobColour, maxExpEquation, displayMethod, maxLevel, this(jobName, jobDisplayName, fullName, jobShortName, jobColour, maxExpEquation, displayMethod, maxLevel,
vipmaxLevel, maxSlots, jobPermissions, jobCommands, jobConditions, vipmaxLevel, maxSlots, jobPermissions, jobCommands, jobConditions,
jobLimitedItems, cmdOnJoin, cmdOnLeave, guiItem, guiSlot, worldBlacklist); jobLimitedItems, cmdOnJoin, cmdOnLeave, guiItem, guiSlot, worldBlacklist);
this.jobItems = jobItems; this.jobItems = jobItems;
this.description = description; this.description = description;
} }
public Job(String jobName, String jobDisplayName, String fullName, String jobShortName, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel, public Job(String jobName, String jobDisplayName, String fullName, String jobShortName, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions,
Map<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, List<String> worldBlacklist) { Map<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, List<String> worldBlacklist) {
this.jobName = jobName == null ? "" : jobName; this.jobName = jobName == null ? "" : jobName;
this.fullName = fullName == null ? "" : fullName; this.fullName = fullName == null ? "" : fullName;
this.jobShortName = jobShortName; this.jobShortName = jobShortName;
this.jobColour = jobColour; this.jobColour = jobColour;
this.maxExpEquation = maxExpEquation; this.maxExpEquation = maxExpEquation;
this.displayMethod = displayMethod; this.displayMethod = displayMethod;
this.maxLevel = maxLevel; this.maxLevel = maxLevel;
this.vipmaxLevel = vipmaxLevel; this.vipmaxLevel = vipmaxLevel;
this.maxSlots = maxSlots; this.maxSlots = maxSlots;
this.jobPermissions = jobPermissions; this.jobPermissions = jobPermissions;
this.jobCommands = jobCommands; this.jobCommands = jobCommands;
this.jobConditions = jobConditions; this.jobConditions = jobConditions;
this.jobLimitedItems = jobLimitedItems; this.jobLimitedItems = jobLimitedItems;
this.cmdOnJoin = cmdOnJoin; this.cmdOnJoin = cmdOnJoin;
this.cmdOnLeave = cmdOnLeave; this.cmdOnLeave = cmdOnLeave;
this.guiItem = guiItem; this.guiItem = guiItem;
this.guiSlot = guiSlot; this.guiSlot = guiSlot;
this.jobDisplayName = CMIChatColor.translate(jobDisplayName); this.jobDisplayName = CMIChatColor.translate(jobDisplayName);
if (worldBlacklist != null) { if (worldBlacklist != null) {
this.worldBlacklist = worldBlacklist; this.worldBlacklist = worldBlacklist;
} }
} }
/** /**
@ -146,7 +146,7 @@ public class Job {
* @param point the amount of boost to add * @param point the amount of boost to add
*/ */
public void addBoost(CurrencyType type, double point) { public void addBoost(CurrencyType type, double point) {
boost.add(type, point); boost.add(type, point);
} }
/** /**
@ -163,20 +163,20 @@ public class Job {
*/ */
public void addBoost(CurrencyType type, double point, long duration) { public void addBoost(CurrencyType type, double point, long duration) {
if (duration <= 0) { if (duration <= 0) {
addBoost(type, point); addBoost(type, point);
return; return;
} }
boost.add(type, point, System.currentTimeMillis() + (duration * 1000L)); boost.add(type, point, System.currentTimeMillis() + (duration * 1000L));
} }
public void setBoost(BoostMultiplier boost) { public void setBoost(BoostMultiplier boost) {
this.boost = boost; this.boost = boost;
} }
public BoostMultiplier getBoost() { public BoostMultiplier getBoost() {
return boost; return boost;
} }
/** /**
@ -186,8 +186,8 @@ public class Job {
* @return true if same * @return true if same
*/ */
public boolean isSame(Job job) { public boolean isSame(Job job) {
return job != null && (id == job.getId() || jobName.equalsIgnoreCase(job.getName()) return job != null && (id == job.getId() || jobName.equalsIgnoreCase(job.getName())
|| fullName.equalsIgnoreCase(job.getJobFullName()) || fullName.equalsIgnoreCase(job.getName())); || fullName.equalsIgnoreCase(job.getJobFullName()) || fullName.equalsIgnoreCase(job.getName()));
} }
/** /**
@ -196,67 +196,74 @@ public class Job {
* @return the amount of total players in this job * @return the amount of total players in this job
*/ */
public int getTotalPlayers() { public int getTotalPlayers() {
if (totalPlayers == -1) { if (totalPlayers == -1) {
updateTotalPlayers(); updateTotalPlayers();
} }
return totalPlayers; return totalPlayers;
} }
/** /**
* Updates the total players property from database synchronously. * Updates the total players property from database synchronously.
*/ */
public void updateTotalPlayers() { public void updateTotalPlayers() {
totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(jobName); totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(jobName);
if (totalPlayers <= 0) { if (totalPlayers <= 0) {
totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(fullName); totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(fullName);
} }
updateBonus(); updateBonus();
} }
public void updateBonus() { public void updateBonus() {
if (!Jobs.getGCManager().useDynamicPayment) if (!Jobs.getGCManager().useDynamicPayment)
return; return;
Parser eq = Jobs.getGCManager().DynamicPaymentEquation; Parser eq = Jobs.getGCManager().DynamicPaymentEquation;
eq.setVariable("totalworkers", Jobs.getJobsDAO().getTotalPlayers()); eq.setVariable("totalworkers", Jobs.getJobsDAO().getTotalPlayers());
eq.setVariable("totaljobs", Jobs.getJobs().size()); eq.setVariable("totaljobs", Jobs.getJobs().size());
eq.setVariable("jobstotalplayers", getTotalPlayers()); eq.setVariable("jobstotalplayers", getTotalPlayers());
double now = eq.getValue(); double now = 0D;
CMIDebug.d("Now",now); try {
if (now > Jobs.getGCManager().DynamicPaymentMaxBonus) now = eq.getValue();
now = Jobs.getGCManager().DynamicPaymentMaxBonus; } catch (Throwable e) {
e.printStackTrace();
}
if (now < Jobs.getGCManager().DynamicPaymentMaxPenalty) CMIDebug.d("Now", now, this.getName(), getTotalPlayers(), now == Double.POSITIVE_INFINITY);
now = Jobs.getGCManager().DynamicPaymentMaxPenalty;
this.bonus = now; if (now > Jobs.getGCManager().DynamicPaymentMaxBonus)
now = Jobs.getGCManager().DynamicPaymentMaxBonus;
if (now < Jobs.getGCManager().DynamicPaymentMaxPenalty)
now = Jobs.getGCManager().DynamicPaymentMaxPenalty;
this.bonus = now;
} }
public double getBonus() { public double getBonus() {
if (bonus == null) if (bonus == null)
updateBonus(); updateBonus();
return bonus == null ? 0D : bonus; return bonus == null ? 0D : bonus;
} }
public List<String> getCmdOnJoin() { public List<String> getCmdOnJoin() {
return cmdOnJoin; return cmdOnJoin;
} }
public List<String> getCmdOnLeave() { public List<String> getCmdOnLeave() {
return cmdOnLeave; return cmdOnLeave;
} }
public ItemStack getGuiItem() { public ItemStack getGuiItem() {
return guiItem; return guiItem;
} }
public int getGuiSlot() { public int getGuiSlot() {
return guiSlot; return guiSlot;
} }
/** /**
@ -265,7 +272,7 @@ public class Job {
* @param info - the job info * @param info - the job info
*/ */
public void setJobInfo(ActionType type, List<JobInfo> info) { public void setJobInfo(ActionType type, List<JobInfo> info) {
jobInfo.put(type, info); jobInfo.put(type, info);
} }
/** /**
@ -274,7 +281,7 @@ public class Job {
* @return Job info list * @return Job info list
*/ */
public List<JobInfo> getJobInfo(ActionType type) { public List<JobInfo> getJobInfo(ActionType type) {
return jobInfo.get(type); return jobInfo.get(type);
} }
/** /**
@ -282,41 +289,41 @@ public class Job {
* @return Job info list * @return Job info list
*/ */
public Map<ActionType, List<JobInfo>> getJobInfoList() { public Map<ActionType, List<JobInfo>> getJobInfoList() {
return jobInfo; return jobInfo;
} }
public JobInfo getJobInfo(ActionInfo action, int level) { public JobInfo getJobInfo(ActionInfo action, int level) {
BiPredicate<JobInfo, ActionInfo> condition = (jobInfo, actionInfo) -> { BiPredicate<JobInfo, ActionInfo> condition = (jobInfo, actionInfo) -> {
if (actionInfo instanceof PotionItemActionInfo) { if (actionInfo instanceof PotionItemActionInfo) {
String subName = ((PotionItemActionInfo) action).getNameWithSub(); String subName = ((PotionItemActionInfo) action).getNameWithSub();
return jobInfo.getName().equalsIgnoreCase(subName) || (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(subName); return jobInfo.getName().equalsIgnoreCase(subName) || (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(subName);
} }
if (actionInfo instanceof EnchantActionInfo) { if (actionInfo instanceof EnchantActionInfo) {
return Util.enchantMatchesActionInfo(jobInfo.getName(), (EnchantActionInfo) actionInfo); return Util.enchantMatchesActionInfo(jobInfo.getName(), (EnchantActionInfo) actionInfo);
} }
return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) || return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) ||
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) || (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) ||
jobInfo.getName().equalsIgnoreCase(action.getName()); jobInfo.getName().equalsIgnoreCase(action.getName());
}; };
String shortActionName = CMIMaterial.getGeneralMaterialName(action.getName()); String shortActionName = CMIMaterial.getGeneralMaterialName(action.getName());
for (JobInfo info : getJobInfo(action.getType())) { for (JobInfo info : getJobInfo(action.getType())) {
if (condition.test(info, action)) { if (condition.test(info, action)) {
if (!info.isInLevelRange(level)) { if (!info.isInLevelRange(level)) {
break; break;
} }
return info; return info;
} }
if ((shortActionName + ":ALL").equalsIgnoreCase(info.getName())) { if ((shortActionName + ":ALL").equalsIgnoreCase(info.getName())) {
return info; return info;
} }
} }
return null; return null;
} }
/** /**
@ -325,20 +332,20 @@ public class Job {
* @return the name of this job * @return the name of this job
*/ */
public String getName() { public String getName() {
return jobName; return jobName;
} }
public String getJobFullName() { public String getJobFullName() {
return fullName; return fullName;
} }
@Deprecated @Deprecated
public String getJobDisplayName() { public String getJobDisplayName() {
return getDisplayName(); return getDisplayName();
} }
public String getDisplayName() { public String getDisplayName() {
return jobDisplayName == null ? jobColour + fullName : jobDisplayName; return jobDisplayName == null ? jobColour + fullName : jobDisplayName;
} }
/** /**
@ -349,7 +356,7 @@ public class Job {
*/ */
@Deprecated @Deprecated
public String getNameWithColor() { public String getNameWithColor() {
return jobColour + fullName; return jobColour + fullName;
} }
/** /**
@ -358,7 +365,7 @@ public class Job {
* @return the shortened version of the jobName * @return the shortened version of the jobName
*/ */
public String getShortName() { public String getShortName() {
return jobShortName; return jobShortName;
} }
/** /**
@ -370,7 +377,7 @@ public class Job {
*/ */
@Deprecated @Deprecated
public String getDescription() { public String getDescription() {
return description; return description;
} }
/** /**
@ -378,7 +385,7 @@ public class Job {
* @return the Color of the job for chat * @return the Color of the job for chat
*/ */
public CMIChatColor getChatColor() { public CMIChatColor getChatColor() {
return jobColour; return jobColour;
} }
/** /**
@ -386,7 +393,7 @@ public class Job {
* @return the MaxExpEquation of the job * @return the MaxExpEquation of the job
*/ */
public Parser getMaxExpEquation() { public Parser getMaxExpEquation() {
return maxExpEquation; return maxExpEquation;
} }
/** /**
@ -395,10 +402,10 @@ public class Job {
* @return the correct max exp for this level * @return the correct max exp for this level
*/ */
public double getMaxExp(Map<String, Double> level) { public double getMaxExp(Map<String, Double> level) {
for (Map.Entry<String, Double> temp : level.entrySet()) { for (Map.Entry<String, Double> temp : level.entrySet()) {
maxExpEquation.setVariable(temp.getKey(), temp.getValue()); maxExpEquation.setVariable(temp.getKey(), temp.getValue());
} }
return maxExpEquation.getValue(); return maxExpEquation.getValue();
} }
/** /**
@ -406,7 +413,7 @@ public class Job {
* @return the display method * @return the display method
*/ */
public DisplayMethod getDisplayMethod() { public DisplayMethod getDisplayMethod() {
return displayMethod; return displayMethod;
} }
/** /**
@ -415,7 +422,7 @@ public class Job {
* @return the max level * @return the max level
*/ */
public int getMaxLevel() { public int getMaxLevel() {
return maxLevel; return maxLevel;
} }
/** /**
@ -425,20 +432,20 @@ public class Job {
* @return the max level of player * @return the max level of player
*/ */
public int getMaxLevel(JobsPlayer player) { public int getMaxLevel(JobsPlayer player) {
return player == null ? maxLevel : player.getMaxJobLevelAllowed(this); return player == null ? maxLevel : player.getMaxJobLevelAllowed(this);
} }
public int getMaxLevel(CommandSender sender) { public int getMaxLevel(CommandSender sender) {
if (sender == null) if (sender == null)
return maxLevel; return maxLevel;
if (sender instanceof Player) { if (sender instanceof Player) {
JobsPlayer player = Jobs.getPlayerManager().getJobsPlayer((Player) sender); JobsPlayer player = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
if (player != null) if (player != null)
return player.getMaxJobLevelAllowed(this); return player.getMaxJobLevelAllowed(this);
} }
return maxLevel > vipmaxLevel ? maxLevel : vipmaxLevel; return maxLevel > vipmaxLevel ? maxLevel : vipmaxLevel;
} }
/** /**
@ -447,7 +454,7 @@ public class Job {
* @return null - no max level * @return null - no max level
*/ */
public int getVipMaxLevel() { public int getVipMaxLevel() {
return vipmaxLevel; return vipmaxLevel;
} }
/** /**
@ -456,7 +463,7 @@ public class Job {
* @return null - no max slots * @return null - no max slots
*/ */
public Integer getMaxSlots() { public Integer getMaxSlots() {
return maxSlots; return maxSlots;
} }
/** /**
@ -464,7 +471,7 @@ public class Job {
* @return Permissions for this job * @return Permissions for this job
*/ */
public List<JobPermission> getPermissions() { public List<JobPermission> getPermissions() {
return Collections.unmodifiableList(jobPermissions); return Collections.unmodifiableList(jobPermissions);
} }
/** /**
@ -472,7 +479,7 @@ public class Job {
* @return Commands for this job * @return Commands for this job
*/ */
public List<JobCommands> getCommands() { public List<JobCommands> getCommands() {
return Collections.unmodifiableList(jobCommands); return Collections.unmodifiableList(jobCommands);
} }
/** /**
@ -480,7 +487,7 @@ public class Job {
* @return Conditions for this job * @return Conditions for this job
*/ */
public List<JobConditions> getConditions() { public List<JobConditions> getConditions() {
return Collections.unmodifiableList(jobConditions); return Collections.unmodifiableList(jobConditions);
} }
/** /**
@ -489,14 +496,14 @@ public class Job {
*/ */
@Deprecated @Deprecated
public Map<String, JobItems> getItemBonus() { public Map<String, JobItems> getItemBonus() {
if (jobItems == null) if (jobItems == null)
jobItems = new HashMap<String, JobItems>(); jobItems = new HashMap<String, JobItems>();
return jobItems; return jobItems;
} }
@Deprecated @Deprecated
public JobItems getItemBonus(String key) { public JobItems getItemBonus(String key) {
return jobItems.get(key.toLowerCase()); return jobItems.get(key.toLowerCase());
} }
/** /**
@ -504,192 +511,192 @@ public class Job {
* @return Limited items for this job * @return Limited items for this job
*/ */
public Map<String, JobLimitedItems> getLimitedItems() { public Map<String, JobLimitedItems> getLimitedItems() {
return jobLimitedItems; return jobLimitedItems;
} }
public JobLimitedItems getLimitedItems(String key) { public JobLimitedItems getLimitedItems(String key) {
return jobLimitedItems.get(key.toLowerCase()); return jobLimitedItems.get(key.toLowerCase());
} }
public String getBossbar() { public String getBossbar() {
return bossbar; return bossbar;
} }
public void setBossbar(String bossbar) { public void setBossbar(String bossbar) {
this.bossbar = bossbar; this.bossbar = bossbar;
} }
public Parser getMoneyEquation() { public Parser getMoneyEquation() {
return moneyEquation; return moneyEquation;
} }
public void setMoneyEquation(Parser moneyEquation) { public void setMoneyEquation(Parser moneyEquation) {
this.moneyEquation = moneyEquation; this.moneyEquation = moneyEquation;
} }
public Parser getXpEquation() { public Parser getXpEquation() {
return xpEquation; return xpEquation;
} }
public void setXpEquation(Parser xpEquation) { public void setXpEquation(Parser xpEquation) {
this.xpEquation = xpEquation; this.xpEquation = xpEquation;
} }
public Parser getPointsEquation() { public Parser getPointsEquation() {
return pointsEquation; return pointsEquation;
} }
public void setPointsEquation(Parser pointsEquation) { public void setPointsEquation(Parser pointsEquation) {
this.pointsEquation = pointsEquation; this.pointsEquation = pointsEquation;
} }
public Long getRejoinCd() { public Long getRejoinCd() {
return rejoinCd; return rejoinCd;
} }
public void setRejoinCd(Long rejoinCd) { public void setRejoinCd(Long rejoinCd) {
this.rejoinCd = rejoinCd; this.rejoinCd = rejoinCd;
} }
public List<String> getFullDescription() { public List<String> getFullDescription() {
return fDescription; return fDescription;
} }
public void setFullDescription(List<String> fDescription) { public void setFullDescription(List<String> fDescription) {
this.fDescription.clear(); this.fDescription.clear();
if (fDescription != null) { if (fDescription != null) {
this.fDescription.addAll(fDescription); this.fDescription.addAll(fDescription);
this.description = String.join("\n", this.fDescription); this.description = String.join("\n", this.fDescription);
} }
} }
public void setMaxLevelCommands(List<String> commands) { public void setMaxLevelCommands(List<String> commands) {
maxLevelCommands.clear(); maxLevelCommands.clear();
if (commands != null) { if (commands != null) {
maxLevelCommands.addAll(commands); maxLevelCommands.addAll(commands);
} }
} }
public List<String> getMaxLevelCommands() { public List<String> getMaxLevelCommands() {
return maxLevelCommands; return maxLevelCommands;
} }
public List<Quest> getQuests() { public List<Quest> getQuests() {
return quests; return quests;
} }
public Quest getQuest(String name) { public Quest getQuest(String name) {
if (name == null || name.trim().isEmpty()) { if (name == null || name.trim().isEmpty()) {
return null; return null;
} }
for (Quest one : quests) { for (Quest one : quests) {
if (one.getConfigName().equalsIgnoreCase(name)) if (one.getConfigName().equalsIgnoreCase(name))
return one; return one;
} }
return null; return null;
} }
public void setQuests(List<Quest> quests) { public void setQuests(List<Quest> quests) {
this.quests.clear(); this.quests.clear();
if (quests != null) { if (quests != null) {
this.quests.addAll(quests); this.quests.addAll(quests);
} }
} }
public Quest getNextQuest(List<String> excludeQuests, Integer level) { public Quest getNextQuest(List<String> excludeQuests, Integer level) {
List<Quest> ls = new ArrayList<>(quests); List<Quest> ls = new ArrayList<>(quests);
Collections.shuffle(ls); Collections.shuffle(ls);
int i = 0; int i = 0;
while (true) { while (true) {
i++; i++;
int target = new Random(System.nanoTime()).nextInt(100); int target = new Random(System.nanoTime()).nextInt(100);
for (Quest one : ls) { for (Quest one : ls) {
if (one.isEnabled() && one.getChance() >= target && (excludeQuests == null || !excludeQuests.contains(one.getConfigName().toLowerCase())) if (one.isEnabled() && one.getChance() >= target && (excludeQuests == null || !excludeQuests.contains(one.getConfigName().toLowerCase()))
&& one.isInLevelRange(level)) { && one.isInLevelRange(level)) {
return one; return one;
} }
} }
if (i > 20) if (i > 20)
return null; return null;
} }
} }
public int getMaxDailyQuests() { public int getMaxDailyQuests() {
return maxDailyQuests; return maxDailyQuests;
} }
public void setMaxDailyQuests(int maxDailyQuests) { public void setMaxDailyQuests(int maxDailyQuests) {
this.maxDailyQuests = maxDailyQuests; this.maxDailyQuests = maxDailyQuests;
} }
public int getId() { public int getId() {
return id; return id;
} }
public void setId(int id) { public void setId(int id) {
this.id = id; this.id = id;
} }
public List<String> getWorldBlacklist() { public List<String> getWorldBlacklist() {
return worldBlacklist; return worldBlacklist;
} }
public boolean isWorldBlackListed(Entity ent) { public boolean isWorldBlackListed(Entity ent) {
return isWorldBlackListed(null, ent); return isWorldBlackListed(null, ent);
} }
public boolean isWorldBlackListed(Block block) { public boolean isWorldBlackListed(Block block) {
return isWorldBlackListed(block, null); return isWorldBlackListed(block, null);
} }
public boolean isWorldBlackListed(Block block, Entity ent) { public boolean isWorldBlackListed(Block block, Entity ent) {
if (worldBlacklist.isEmpty()) if (worldBlacklist.isEmpty())
return reversedWorldBlacklist; return reversedWorldBlacklist;
if (block != null) if (block != null)
return worldBlacklist.contains(block.getWorld().getName()) != reversedWorldBlacklist; return worldBlacklist.contains(block.getWorld().getName()) != reversedWorldBlacklist;
return ent != null && worldBlacklist.contains(ent.getWorld().getName()) != reversedWorldBlacklist; return ent != null && worldBlacklist.contains(ent.getWorld().getName()) != reversedWorldBlacklist;
} }
public boolean isReversedWorldBlacklist() { public boolean isReversedWorldBlacklist() {
return reversedWorldBlacklist; return reversedWorldBlacklist;
} }
public void setReversedWorldBlacklist(boolean reversedWorldBlacklist) { public void setReversedWorldBlacklist(boolean reversedWorldBlacklist) {
this.reversedWorldBlacklist = reversedWorldBlacklist; this.reversedWorldBlacklist = reversedWorldBlacklist;
} }
public boolean isIgnoreMaxJobs() { public boolean isIgnoreMaxJobs() {
return ignoreMaxJobs; return ignoreMaxJobs;
} }
public void setIgnoreMaxJobs(boolean ignoreMaxJobs) { public void setIgnoreMaxJobs(boolean ignoreMaxJobs) {
this.ignoreMaxJobs = ignoreMaxJobs; this.ignoreMaxJobs = ignoreMaxJobs;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof Job && isSame((Job) obj); return obj instanceof Job && isSame((Job) obj);
} }
public void setJobDisplayName(String jobDisplayName) { public void setJobDisplayName(String jobDisplayName) {
this.jobDisplayName = jobDisplayName; this.jobDisplayName = jobDisplayName;
} }
public int getLegacyId() { public int getLegacyId() {
return legacyId; return legacyId;
} }
public void setLegacyId(int legacyId) { public void setLegacyId(int legacyId) {
this.legacyId = legacyId; this.legacyId = legacyId;
} }
} }