1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-25 20:16:13 +01:00

Excluding job count with ignore-jobs-max

This commit is contained in:
Zrips 2023-12-19 12:57:33 +02:00
parent ddc9000f8f
commit a23b0af09b
11 changed files with 44 additions and 28 deletions

View File

@ -5,7 +5,6 @@ import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -97,7 +96,7 @@ public class GuiManager {
Job job = jobsList.get(i);
List<String> lore = new ArrayList<>();
for (JobProgression onePJob : jPlayer.progression) {
for (JobProgression onePJob : jPlayer.getJobProgression()) {
if (onePJob.getJob().getName().equalsIgnoreCase(job.getName())) {
lore.add(Jobs.getLanguage().getMessage("command.info.gui.working"));
break;
@ -272,7 +271,7 @@ public class GuiManager {
ItemStack guiItem = job.getGuiItem().clone();
int level = prog != null ? prog.getLevel() : 1;
int numjobs = jPlayer.progression.size();
int numjobs = jPlayer.getJobProgression().size();
int nextButton = Jobs.getGCManager().getJobsGUINextButton();
int backButton = Jobs.getGCManager().getJobsGUIBackButton();
@ -488,7 +487,7 @@ public class GuiManager {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job);
int numjobs = jPlayer.progression.size();
int numjobs = jPlayer.getJobProgression().size();
int level = jPlayer.getJobProgression(job) != null ? jPlayer.getJobProgression(job).getLevel() : 1;
ItemStack guiItem = job.getGuiItem().clone();
@ -510,15 +509,15 @@ public class GuiManager {
double income = jInfo.getIncome(level, numjobs, jPlayer.maxJobsEquation);
income = boost.getFinalAmount(CurrencyType.MONEY, income);
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
String incomeColor = income >= 0 ? "" : CMIChatColor.DARK_RED.toString();
double xp = jInfo.getExperience(level, numjobs, jPlayer.maxJobsEquation);
xp = boost.getFinalAmount(CurrencyType.EXP, xp);
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
String xpColor = xp >= 0 ? "" : CMIChatColor.GRAY.toString();
double points = jInfo.getPoints(level, numjobs, jPlayer.maxJobsEquation);
points = boost.getFinalAmount(CurrencyType.POINTS, points);
String pointsColor = points >= 0 ? "" : ChatColor.RED.toString();
String pointsColor = points >= 0 ? "" : CMIChatColor.RED.toString();
if (income == 0D && points == 0D && xp == 0D)
continue;

View File

@ -382,7 +382,7 @@ public class Placeholder {
try {
int id = Integer.parseInt(value);
if (id > 0)
return user.progression.get(id - 1);
return user.getJobProgression().get(id - 1);
} catch (IndexOutOfBoundsException | NumberFormatException e) {
Job job = Jobs.getJob(value);
if (job != null)
@ -465,18 +465,18 @@ public class Placeholder {
case user_displayhonorific:
return user.getDisplayHonorific();
case user_joinedjobcount:
return Integer.toString(user.progression.size());
return Integer.toString(user.getJobProgression().size());
case user_archived_jobs:
return Integer.toString(user.getArchivedJobs().getArchivedJobs().size());
case user_jobs:
StringBuilder jobNames = new StringBuilder();
for (JobProgression prog : user.progression) {
for (JobProgression prog : user.getJobProgression()) {
if (!jobNames.toString().isEmpty()) {
jobNames.append(LC.info_ListSpliter.getLocale());
}
jobNames.append(prog.getJob().getDisplayName());
}
if (user.progression.isEmpty()) {
if (user.getJobProgression().isEmpty()) {
if (Jobs.getNoneJob() != null)
jobNames.append(Jobs.getNoneJob().getDisplayName());
}
@ -579,7 +579,7 @@ public class Placeholder {
if (!Jobs.getCommandManager().hasJobPermission(player, job) ||
user.isInJob(job) ||
job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots() ||
!job.isIgnoreMaxJobs() && !Jobs.getPlayerManager().getJobsLimit(user, (short) user.progression.size()))
!job.isIgnoreMaxJobs() && !Jobs.getPlayerManager().getJobsLimit(user, (short) user.getJobProgression().size()))
return convert(false);
return convert(true);

View File

@ -325,7 +325,7 @@ public class PlayerManager {
if (!resetID && jPlayer.getUserId() == -1)
continue;
for (JobProgression oneJ : jPlayer.progression)
for (JobProgression oneJ : jPlayer.getJobProgression())
dao.insertJob(jPlayer, oneJ);
dao.saveLog(jPlayer);
@ -547,7 +547,7 @@ public class PlayerManager {
* @param jPlayer {@link JobsPlayer}
*/
public void leaveAllJobs(JobsPlayer jPlayer) {
for (JobProgression job : new ArrayList<>(jPlayer.progression))
for (JobProgression job : new ArrayList<>(jPlayer.getJobProgression()))
leaveJob(jPlayer, job.getJob());
jPlayer.leaveAllJobs();
@ -976,7 +976,7 @@ public class PlayerManager {
*/
public void reload() {
for (JobsPlayer jPlayer : playersUUID.values()) {
for (JobProgression progression : jPlayer.progression) {
for (JobProgression progression : jPlayer.getJobProgression()) {
Job job = Jobs.getJob(progression.getJob().getName());
if (job != null)
progression.setJob(job);
@ -1193,13 +1193,13 @@ public class PlayerManager {
return;
int playerMaxJobs = getMaxJobs(jPlayer);
int playerCurrentJobs = jPlayer.progression.size();
int playerCurrentJobs = jPlayer.getJobProgression().size();
if (playerMaxJobs == 0 || playerMaxJobs != -1 && playerCurrentJobs >= playerMaxJobs)
return;
for (Job one : Jobs.getJobs()) {
if (playerMaxJobs != -1 && jPlayer.progression.size() >= playerMaxJobs)
if (playerMaxJobs != -1 && jPlayer.getJobProgression().size() >= playerMaxJobs)
return;
if (one.getMaxSlots() != null && Jobs.getUsedSlots(one) >= one.getMaxSlots())

View File

@ -364,7 +364,7 @@ public class JobsCommands implements CommandExecutor {
}
int level = prog != null ? prog.getLevel() : 1;
int numjobs = player.progression.size();
int numjobs = player.getJobCount();
for (JobInfo info : job.getJobInfo(type)) {

View File

@ -48,7 +48,7 @@ public class fireall implements Cmd {
return true;
}
if (jPlayer.progression.isEmpty()) {
if (jPlayer.getJobProgression().isEmpty()) {
Language.sendMessage(sender, "command.fireall.error.nojobs");
return true;
}

View File

@ -66,8 +66,8 @@ public class join implements Cmd {
Language.sendMessage(sender, "command.join.error.fullslots", "%jobname%", job.getDisplayName());
return true;
}
if (!job.isIgnoreMaxJobs() && !Jobs.getPlayerManager().getJobsLimit(jPlayer, (short) jPlayer.progression.size())) {
if (!job.isIgnoreMaxJobs() && !Jobs.getPlayerManager().getJobsLimit(jPlayer, (short) jPlayer.getJobCount(false))) {
Language.sendMessage(sender, "command.join.error.maxjobs");
return true;
}

View File

@ -89,7 +89,7 @@ public class quests implements Cmd {
Language.sendMessage(sender, "command.quests.toplineseparator", "[playerName]", jPlayer.getName(), "[questsDone]", jPlayer.getDoneQuests());
for (JobProgression jobProg : jPlayer.progression) {
for (JobProgression jobProg : jPlayer.getJobProgression()) {
List<QuestProgression> list = jPlayer.getQuestProgressions(jobProg.getJob());
for (QuestProgression q : list) {
@ -171,7 +171,7 @@ public class quests implements Cmd {
gui.addLock(InvType.Gui);
gui.addLock(InvType.Main);
for (JobProgression jobProg : jPlayer.progression) {
for (JobProgression jobProg : jPlayer.getJobProgression()) {
List<QuestProgression> list = jPlayer.getQuestProgressions(jobProg.getJob());
for (QuestProgression q : list) {

View File

@ -35,7 +35,7 @@ public class stats implements Cmd {
return true;
}
if (jPlayer.progression.isEmpty()) {
if (jPlayer.getJobProgression().isEmpty()) {
Language.sendMessage(sender, "command.stats.error.nojob");
return true;
}

View File

@ -27,7 +27,7 @@ public class BossBarManager {
if (Version.getCurrent().isLower(Version.v1_9_R1) || player == null)
return;
for (JobProgression oneJob : player.progression) {
for (JobProgression oneJob : player.getJobProgression()) {
if (oneJob.getLastExperience() != 0) {
ShowJobProgression(player, oneJob, oneJob.getLastExperience());
}

View File

@ -168,14 +168,14 @@ public class JobProgression {
public void reloadMaxExperience() {
Map<String, Double> param = new HashMap<>();
param.put("joblevel", (double) level);
param.put("numjobs", (double) jPlayer.progression.size());
param.put("numjobs", (double) jPlayer.getJobProgression().size());
maxExperience = (int) job.getMaxExp(param);
}
public int getMaxExperience(int level) {
Map<String, Double> param = new HashMap<>();
param.put("joblevel", (double) level);
param.put("numjobs", (double) jPlayer.progression.size());
param.put("numjobs", (double) jPlayer.getJobProgression().size());
return (int) job.getMaxExp(param);
}

View File

@ -46,7 +46,6 @@ import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMINumber;
import net.Zrips.CMILib.Equations.Parser;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Time.CMITimeManager;
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
import net.Zrips.CMILib.Version.Schedulers.CMITask;
@ -476,6 +475,24 @@ public class JobsPlayer {
return Collections.unmodifiableList(progression);
}
public int getJobCount() {
return getJobCount(true);
}
public int getJobCount(boolean includeIgnoredMaxJobs) {
if (includeIgnoredMaxJobs)
return progression.size();
int count = 0;
for (JobProgression one : progression) {
if (one.getJob().isIgnoreMaxJobs())
continue;
count++;
}
return count;
}
/**
* Get the job progression from the certain job
*