1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Implement method to retrieve the actual job instead of the name

Closes #1166
This commit is contained in:
montlikadani 2021-05-04 17:30:47 +02:00
parent 21ff1801cd
commit 2e210c52d8
7 changed files with 117 additions and 49 deletions

View File

@ -645,8 +645,8 @@ public class PlayerManager {
message = message.replace("%jobname%", job.getNameWithColor());
message = message.replace("%playername%", player != null ? plugin.getComplement().getDisplayName(player) : jPlayer.getName());
message = message.replace("%joblevel%", "" + prog.getLevel());
message = message.replace("%lostLevel%", "" + oldLevel);
message = message.replace("%joblevel%", Integer.toString(prog.getLevel()));
message = message.replace("%lostLevel%", Integer.toString(oldLevel));
if (player != null) {
for (String line : message.split("\n")) {
@ -668,7 +668,7 @@ public class PlayerManager {
// LevelUp event
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(
jPlayer,
job.getName(),
job,
prog.getLevel(),
Jobs.getTitleManager().getTitle(oldLevel, prog.getJob().getName()),
Jobs.getTitleManager().getTitle(prog.getLevel(), prog.getJob().getName()),
@ -753,7 +753,7 @@ public class PlayerManager {
.getChatColor().toString() + levelUpEvent.getOldTitle().getName());
message = message.replace("%playername%", player != null ? plugin.getComplement().getDisplayName(player) : jPlayer.getName());
message = message.replace("%joblevel%", "" + prog.getLevel());
message = message.replace("%joblevel%", Integer.toString(prog.getLevel()));
for (String line : message.split("\n")) {
if (Jobs.getGCManager().isBroadcastingLevelups()) {

View File

@ -3,36 +3,45 @@ package com.gamingmesh.jobs.api;
import org.bukkit.Sound;
import org.bukkit.event.Cancellable;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.Title;
public final class JobsLevelUpEvent extends BaseEvent implements Cancellable {
private JobsPlayer player;
private String jobName;
private Job job;
private Title oldTitle;
private Title newTitle;
private Sound soundLevelupSound;
private Sound soundTitleChangeSound;
private Sound levelupSound;
private Sound titleChangeSound;
private int level, soundLevelupVolume = 1, soundLevelupPitch = 3,
soundTitleChangeVolume = 1, soundTitleChangePitch = 3;
titleChangeVolume = 1, titleChangePitch = 3;
private boolean cancelled = false;
public JobsLevelUpEvent(JobsPlayer jPlayer, String JobName, int level, Title OldTitle, Title NewTitle, String soundLevelupSound, Integer soundLevelupVolume,
Integer soundLevelupPitch, String soundTitleChangeSound, Integer soundTitleChangeVolume, Integer soundTitleChangePitch) {
@Deprecated
public JobsLevelUpEvent(JobsPlayer jPlayer, String jobName, int level, Title oldTitle, Title newTitle, String soundLevelupSound, int soundLevelupVolume,
int soundLevelupPitch, String soundTitleChangeSound, int soundTitleChangeVolume, int soundTitleChangePitch) {
this(jPlayer, Jobs.getJob(jobName), level, oldTitle, newTitle, soundLevelupSound, soundLevelupVolume, soundLevelupPitch,
soundTitleChangeSound, soundTitleChangeVolume, soundTitleChangePitch);
}
public JobsLevelUpEvent(JobsPlayer jPlayer, Job job, int level, Title oldTitle, Title newTitle, String levelupSound, int soundLevelupVolume,
int soundLevelupPitch, String titleChangeSound, int titleChangeVolume, int titleChangePitch) {
this.player = jPlayer;
this.jobName = JobName;
this.oldTitle = OldTitle;
this.newTitle = NewTitle;
this.job = job;
this.oldTitle = oldTitle;
this.newTitle = newTitle;
this.level = level;
this.soundLevelupSound = getSound(soundLevelupSound);
this.levelupSound = getSound(levelupSound);
this.soundLevelupVolume = soundLevelupVolume;
this.soundLevelupPitch = soundLevelupPitch;
this.soundTitleChangeSound = getSound(soundTitleChangeSound);
this.soundTitleChangeVolume = soundTitleChangeVolume;
this.soundTitleChangePitch = soundTitleChangePitch;
this.titleChangeSound = getSound(titleChangeSound);
this.titleChangeVolume = titleChangeVolume;
this.titleChangePitch = titleChangePitch;
}
private Sound getSound(String soundName) {
@ -59,9 +68,20 @@ public final class JobsLevelUpEvent extends BaseEvent implements Cancellable {
* Gets the job name where the player level up.
*
* @return the job name
* @deprecated use {@link #getJob()} instead
*/
@Deprecated
public String getJobName() {
return jobName;
return job.getName();
}
/**
* Returns the Job in which the player have been level up.
*
* @return the corresponding {@link Job} instance
*/
public Job getJob() {
return job;
}
/**
@ -132,15 +152,15 @@ public final class JobsLevelUpEvent extends BaseEvent implements Cancellable {
@Deprecated
public String getSoundName() {
return this.soundLevelupSound != null ? this.soundLevelupSound.name() : "";
return this.levelupSound != null ? this.levelupSound.name() : "";
}
public Sound getSound() {
return soundLevelupSound;
return levelupSound;
}
public void setSound(Sound soundLevelupSound) {
this.soundLevelupSound = soundLevelupSound == null ? Sound.values()[0] : soundLevelupSound;
this.levelupSound = soundLevelupSound == null ? Sound.values()[0] : soundLevelupSound;
}
public int getSoundVolume() {
@ -161,37 +181,37 @@ public final class JobsLevelUpEvent extends BaseEvent implements Cancellable {
@Deprecated
public String getTitleChangeSoundName() {
return this.soundTitleChangeSound != null ? this.soundTitleChangeSound.name() : "";
return this.titleChangeSound != null ? this.titleChangeSound.name() : "";
}
public Sound getTitleChangeSound() {
return soundTitleChangeSound;
return titleChangeSound;
}
public void setTitleChangeSound(Sound soundTitleChangeSound) {
this.soundTitleChangeSound = soundTitleChangeSound == null ? Sound.values()[0] : soundTitleChangeSound;
this.titleChangeSound = soundTitleChangeSound == null ? Sound.values()[0] : soundTitleChangeSound;
}
public int getTitleChangeVolume() {
return soundTitleChangeVolume;
return titleChangeVolume;
}
public void setTitleChangeVolume(int soundTitleChangeVolume) {
this.soundTitleChangeVolume = soundTitleChangeVolume;
public void setTitleChangeVolume(int titleChangeVolume) {
this.titleChangeVolume = titleChangeVolume;
}
public int getTitleChangePitch() {
return soundTitleChangePitch;
return titleChangePitch;
}
public void setTitleChangePitch(int soundTitleChangePitch) {
this.soundTitleChangePitch = soundTitleChangePitch;
public void setTitleChangePitch(int titleChangePitch) {
this.titleChangePitch = titleChangePitch;
}
/**
* Returns the player job progression level.
* Returns the current job progression level.
*
* @return player job progression level
* @return job progression level
*/
public int getLevel() {
return level;

View File

@ -81,7 +81,7 @@ public final class JobsPaymentEvent extends Event implements Cancellable {
* @param type {@link CurrencyType}
* @return the amount of payment in specific type
*/
public Double get(CurrencyType type) {
public double get(CurrencyType type) {
return payments.getOrDefault(type, 0D);
}

View File

@ -40,7 +40,7 @@ public class leave implements Cmd {
Util.LEAVECONFIRM.add(uuid);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> Util.LEAVECONFIRM.remove(uuid),
20 * Jobs.getGCManager().ConfirmExpiryTime);
(long) (20 * Jobs.getGCManager().ConfirmExpiryTime));
pSender.sendMessage(Jobs.getLanguage().getMessage("command.leave.confirmationNeed", "[jobname]",
job.getNameWithColor(), "[time]", Jobs.getGCManager().ConfirmExpiryTime));

View File

@ -36,7 +36,7 @@ public class leaveall implements Cmd {
Util.LEAVECONFIRM.add(uuid);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> Util.LEAVECONFIRM.remove(uuid),
20 * Jobs.getGCManager().ConfirmExpiryTime);
(long) (20 * Jobs.getGCManager().ConfirmExpiryTime));
pSender.sendMessage(Jobs.getLanguage().getMessage("command.leaveall.confirmationNeed", "[time]",
Jobs.getGCManager().ConfirmExpiryTime));

View File

@ -67,18 +67,16 @@ public class GeneralConfigManager {
public int jobExpiryTime, BlockProtectionDays, FireworkPower, ShootTime,
globalblocktimer, CowMilkingTimer, InfoUpdateInterval, JobsTopAmount, PlaceholdersPage, ConfirmExpiryTime,
SegmentCount, BossBarTimer, AutoJobJoinDelay, DBCleaningJobsLvl, DBCleaningUsersDays, BlastFurnacesMaxDefault, SmokersMaxDefault;
SegmentCount, BossBarTimer, AutoJobJoinDelay, DBCleaningJobsLvl, DBCleaningUsersDays, BlastFurnacesMaxDefault, SmokersMaxDefault,
levelLossPercentageFromMax, levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume,
SoundTitleChangePitch, ToplistInScoreboardInterval;
protected int savePeriod, maxJobs, economyBatchDelay;
private int ResetTimeHour, ResetTimeMinute, DailyQuestsSkips, FurnacesMaxDefault, BrewingStandsMaxDefault,
BrowseAmountToShow, JobsGUIRows, JobsGUIBackButton, JobsGUINextButton, JobsGUIStartPosition, JobsGUIGroupAmount, JobsGUISkipAmount;
public double skipQuestCost, MinimumOveralPaymentLimit, minimumOveralExpLimit, MinimumOveralPointsLimit, MonsterDamagePercentage,
DynamicPaymentMaxPenalty, DynamicPaymentMaxBonus, TaxesAmount;
public Double TreeFellerMultiplier, gigaDrillMultiplier, superBreakerMultiplier;
public Integer levelLossPercentageFromMax, levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume,
SoundTitleChangePitch, ToplistInScoreboardInterval;
DynamicPaymentMaxPenalty, DynamicPaymentMaxBonus, TaxesAmount, TreeFellerMultiplier, gigaDrillMultiplier, superBreakerMultiplier;
public float maxPaymentCurveFactor;

View File

@ -129,11 +129,33 @@ public class Job {
}
}
/**
* Adds specific amount of boost to the given currency type. If there was a boost
* added before with the same currency type, it will be overridden to the new one.
*
* @param type the type of {@link CurrencyType}}
* @param point the amount of boost to add
*/
public void addBoost(CurrencyType type, double point) {
boost.add(type, point);
}
/**
* Adds specific amount of boost to the given currency type with the
* specified array of times. If there was a boost added before with
* the same currency type, it will be overridden to the new one.
* <p>
* The array of integer need at least to contain 3 elements
* to calculate the time in milliseconds using {@link Calendar}.
*
* @param type the type of {@link CurrencyType}}
* @param point the amount of boost to add
* @param times the array of integer of when to remove the boost
*/
public void addBoost(CurrencyType type, double point, int[] times) {
if (times.length < 3)
return;
final int h = times[2], m = times[1], s = times[0];
if (h == 0 && m == 0 && s == 0) {
addBoost(type, point);
@ -166,10 +188,21 @@ public class Job {
return boost;
}
/**
* Checks if the given {@link Job} is the same with this instance.
*
* @param job the {@link Job} to compare with it
* @return true if same
*/
public boolean isSame(Job job) {
return job != null && (id == job.getId() || fullName.equalsIgnoreCase(job.getName()));
}
/**
* Returns the total players retrieved synchronously from current database.
*
* @return the amount of total players in this job
*/
public int getTotalPlayers() {
if (totalPlayers == -1) {
updateTotalPlayers();
@ -178,6 +211,9 @@ public class Job {
return totalPlayers;
}
/**
* Updates the total players property from database synchronously.
*/
public void updateTotalPlayers() {
totalPlayers = Jobs.getJobsDAO().getTotalPlayerAmountByJobName(jobName);
@ -288,8 +324,9 @@ public class Job {
}
/**
* Get the job name
* @return the job name
* Returns the full job name
*
* @return the full job name
*/
public String getName() {
return fullName;
@ -300,8 +337,9 @@ public class Job {
}
/**
* Get the job name from the config
* @return the job name from the config
* Returns the job name retrieved from the config
*
* @return the job key name from config section
*/
public String getJobKeyName() {
return jobName;
@ -320,7 +358,8 @@ public class Job {
* Gets the description
*
* @return description
* @deprecated Not used anymore, use {@link #getFullDescription()} instead
* @deprecated Description can be list instead
* of plain string, use {@link #getFullDescription()}
*/
@Deprecated
public String getDescription() {
@ -364,14 +403,20 @@ public class Job {
}
/**
* Function to return the maximum level
* Function to return the maximum level of this job.
*
* @return the max level
* @return null - no max level
*/
public int getMaxLevel() {
return maxLevel;
}
/**
* Returns the maximum level of the specific {@link JobsPlayer}.
*
* @param player the {@link JobsPlayer} or null
* @return the max level of player
*/
public int getMaxLevel(JobsPlayer player) {
return player == null ? maxLevel : player.getMaxJobLevelAllowed(this);
}
@ -606,4 +651,9 @@ public class Job {
return ent != null && worldBlacklist.contains(ent.getWorld().getName());
}
@Override
public boolean equals(Object obj) {
return obj instanceof Job ? isSame((Job) obj) : false;
}
}