1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Clarify some event documentation and improved quests resetting

This commit is contained in:
montlikadani 2021-05-05 08:07:35 +02:00
parent 2e210c52d8
commit ecd103e09f
13 changed files with 76 additions and 62 deletions

View File

@ -122,7 +122,7 @@ public class PermissionManager {
* @see #getMaxPermission(JobsPlayer, String, boolean, boolean)
* @return the max value
*/
public Double getMaxPermission(JobsPlayer jPlayer, String perm) {
public double getMaxPermission(JobsPlayer jPlayer, String perm) {
return getMaxPermission(jPlayer, perm, false, false);
}
@ -135,7 +135,7 @@ public class PermissionManager {
* @see #getMaxPermission(JobsPlayer, String, boolean, boolean)
* @return the max value
*/
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
public double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
return getMaxPermission(jPlayer, perm, force, false);
}
@ -150,7 +150,7 @@ public class PermissionManager {
* @param cumulative if true it sums the maximum values of fount permissions
* @return the max value
*/
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) {
public double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) {
if (jPlayer == null || jPlayer.getPlayer() == null)
return 0D;

View File

@ -461,7 +461,7 @@ public class PlayerManager {
* @param job {@link Job}
*/
public void joinJob(JobsPlayer jPlayer, Job job) {
if (jPlayer == null || jPlayer.isInJob(job))
if (jPlayer == null)
return;
// let the user join the job
@ -884,7 +884,7 @@ public class PlayerManager {
return Jobs.getGCManager().getMaxJobs();
}
int max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max", false).intValue();
int max = (int) Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max", false);
return max == 0 ? Jobs.getGCManager().getMaxJobs() : max;
}
@ -948,9 +948,10 @@ public class PlayerManager {
return c.getBoostMultiplier();
}
public BoostMultiplier getInventoryBoost(Player player, Job prog) {
public BoostMultiplier getInventoryBoost(Player player, Job job) {
BoostMultiplier data = new BoostMultiplier();
if (player == null || prog == null)
if (player == null || job == null)
return data;
ItemStack iih;
@ -976,9 +977,11 @@ public class PlayerManager {
}
}
JobProgression progress = getJobsPlayer(player).getJobProgression(job);
for (JobItems jitem : jitems) {
if (jitem != null && jitem.getJobs().contains(prog)) {
data.add(jitem.getBoost(getJobsPlayer(player).getJobProgression(prog)));
if (jitem != null && jitem.getJobs().contains(job)) {
data.add(jitem.getBoost(progress));
}
}

View File

@ -8,6 +8,7 @@ import com.gamingmesh.jobs.container.CuboidArea;
* Called when a player attempted to select an area.
*/
public final class JobsAreaSelectionEvent extends BaseEvent {
private CuboidArea area;
private Player player;

View File

@ -3,12 +3,14 @@ package com.gamingmesh.jobs.api;
import org.bukkit.Chunk;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
/**
* Fired when there is a new chunk explored by player moving.
* <p>
* <b>This is same behaviour when using {@link org.bukkit.event.player.PlayerMoveEvent}
*/
public final class JobsChunkChangeEvent extends BaseEvent implements Cancellable {
private Player player;
private Chunk oldChunk;
private Chunk newChunk;
@ -21,7 +23,7 @@ public final class JobsChunkChangeEvent extends BaseEvent implements Cancellable
}
/**
* Gets the player who explored a chunk.
* Gets the player who explored a new chunk.
*
* @return {@link Player}
*/

View File

@ -10,7 +10,7 @@ import com.gamingmesh.jobs.container.ActionInfo;
import com.gamingmesh.jobs.container.Job;
/**
* Called when a player gains exp from jobs.
* Called when a player gains experience from specific jobs.
*/
public final class JobsExpGainEvent extends BaseEvent implements Cancellable {
@ -41,7 +41,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable {
}
/**
* Returns the player who got exp.
* Returns the player who got experience.
*
* @return {@link OfflinePlayer}
*/
@ -50,7 +50,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable {
}
/**
* Returns the job where the player is got the exp from.
* Returns the job where the player got the experience from.
*
* @return {@link Job}
*/
@ -59,16 +59,16 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable {
}
/**
* Returns the amount of gained exp for player.
* Returns the amount of gained experience for player.
*
* @return got exp amount
* @return the amount of experience the player got
*/
public double getExp() {
return exp;
}
/**
* Sets the exp to a new value.
* Sets the experience to a new value.
*
* @param exp the new value
*/
@ -88,7 +88,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable {
/**
* Returns the entity that the player killed or did something before.
* <p>
* This method is used for Citizens NPCs and armor stand breaking.
* This method is used for Citizens NPCs and armour stand breaking.
*
* @return {@link Entity}
*/

View File

@ -6,6 +6,7 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
public final class JobsJoinEvent extends BaseEvent implements Cancellable {
private JobsPlayer player;
private Job job;
private boolean cancelled = false;

View File

@ -6,6 +6,7 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
public final class JobsLeaveEvent extends BaseEvent implements Cancellable {
private JobsPlayer player;
private Job job;
private boolean cancelled = false;

View File

@ -76,10 +76,11 @@ public final class JobsPaymentEvent extends Event implements Cancellable {
}
/**
* Returns the payment amount of currency type.
* Returns the primitive type of payment of the given
* currency type if exist, otherwise returns 0.
*
* @param type {@link CurrencyType}
* @return the amount of payment in specific type
* @return the amount of payment from specific {@link CurrencyType}
*/
public double get(CurrencyType type) {
return payments.getOrDefault(type, 0D);
@ -90,14 +91,15 @@ public final class JobsPaymentEvent extends Event implements Cancellable {
*
* @param type {@link CurrencyType}
* @param amount the new amount
* @return the given amount
* @return the given amount if the previous value associated with key,
* more precisely {@link Map#put(Object, Object)}
*/
public Double set(CurrencyType type, double amount) {
return payments.put(type, amount);
}
/**
* Returns all payment types map.
* Returns all cached payment returned as {@link Map}.
*
* @return {@link Map}
*/

View File

@ -15,7 +15,7 @@ public class JobsScheduleStartEvent extends BaseEvent implements Cancellable {
}
/**
* Returns the schedule which started.
* Returns the schedule which have been started.
*
* @return {@link Schedule}
*/

View File

@ -15,7 +15,7 @@ public class JobsScheduleStopEvent extends BaseEvent implements Cancellable {
}
/**
* Returns the schedule which stopped.
* Returns the schedule which have been stopped.
*
* @return {@link Schedule}
*/

View File

@ -206,8 +206,11 @@ public class JobItems {
public void setJobs(List<Job> jobs) {
this.jobs.clear();
if (jobs != null) {
this.jobs.addAll(jobs);
}
}
public Map<Enchantment, Integer> getEnchants() {
return enchants;

View File

@ -90,7 +90,7 @@ public class JobsPlayer {
private final Map<UUID, Map<Job, Long>> leftTimes = new HashMap<>();
private PlayerPoints pointsData;
private PlayerPoints pointsData = new PlayerPoints();
public JobsPlayer(String userName) {
this.userName = userName == null ? "Unknown" : userName;
@ -100,8 +100,6 @@ public class JobsPlayer {
* @return the cached or new instance of {@link PlayerPoints}
*/
public PlayerPoints getPointsData() {
if (pointsData == null)
pointsData = new PlayerPoints();
return pointsData;
}
@ -111,7 +109,7 @@ public class JobsPlayer {
* @param points the amount of points
*/
public void addPoints(double points) {
getPointsData().addPoints(points);
pointsData.addPoints(points);
}
/**
@ -120,7 +118,7 @@ public class JobsPlayer {
* @param points the amount of points
*/
public void takePoints(double points) {
getPointsData().takePoints(points);
pointsData.takePoints(points);
}
/**
@ -129,7 +127,7 @@ public class JobsPlayer {
* @param points the amount of points
*/
public void setPoints(double points) {
getPointsData().setPoints(points);
pointsData.setPoints(points);
}
/**
@ -138,9 +136,9 @@ public class JobsPlayer {
* @param points {@link PlayerPoints}
*/
public void setPoints(PlayerPoints points) {
getPointsData().setPoints(points.getCurrentPoints());
getPointsData().setTotalPoints(points.getTotalPoints());
getPointsData().setDbId(points.getDbId());
pointsData.setPoints(points.getCurrentPoints());
pointsData.setTotalPoints(points.getTotalPoints());
pointsData.setDbId(points.getDbId());
}
/**
@ -150,7 +148,7 @@ public class JobsPlayer {
* @return true if yes
*/
public boolean havePoints(double points) {
return getPointsData().getCurrentPoints() >= points;
return pointsData.getCurrentPoints() >= points;
}
/**
@ -385,10 +383,10 @@ public class JobsPlayer {
}
public int getPlayerMaxQuest(String jobName) {
int m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest." + jobName, false, true).intValue();
int m1 = (int) Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest." + jobName, false, true);
int max = m1;
m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest.all", false, true).intValue();
m1 = (int) Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest.all", false, true);
if (m1 != 0 && (m1 > max || m1 < max)) {
max = m1;
}
@ -447,10 +445,13 @@ public class JobsPlayer {
* @return the job progression or null if job not exists
*/
public JobProgression getJobProgression(Job job) {
if (job != null) {
for (JobProgression prog : progression) {
if (prog.getJob().isSame(job))
return prog;
}
}
return null;
}
@ -581,9 +582,7 @@ public class JobsPlayer {
*/
public boolean leaveJob(Job job) {
// synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog != null) {
progression.remove(prog);
if (progression.remove(getJobProgression(job))) {
reloadMaxExperience();
reloadLimits();
reloadHonorific();
@ -614,9 +613,12 @@ public class JobsPlayer {
* @param levels - number of levels to promote
*/
public void promoteJob(Job job, int levels) {
if (levels <= 0)
return;
// synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null || levels <= 0)
if (prog == null)
return;
int oldLevel = prog.getLevel(),
@ -636,9 +638,12 @@ public class JobsPlayer {
* @param levels - number of levels to demote
*/
public void demoteJob(Job job, int levels) {
if (levels <= 0)
return;
// synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null || levels <= 0)
if (prog == null)
return;
int newLevel = prog.getLevel() - levels;
@ -708,11 +713,11 @@ public class JobsPlayer {
else
maxLevel = job.getMaxLevel();
int tMax = Jobs.getPermissionManager().getMaxPermission(this, "jobs." + job.getName() + ".vipmaxlevel").intValue();
int tMax = (int) Jobs.getPermissionManager().getMaxPermission(this, "jobs." + job.getName() + ".vipmaxlevel");
if (tMax > maxLevel)
maxLevel = tMax;
tMax = Jobs.getPermissionManager().getMaxPermission(this, "jobs.all.vipmaxlevel").intValue();
tMax = (int) Jobs.getPermissionManager().getMaxPermission(this, "jobs.all.vipmaxlevel");
if (tMax > maxLevel)
maxLevel = tMax;
@ -726,13 +731,7 @@ public class JobsPlayer {
* @return true if this player is in the given job, otherwise false
*/
public boolean isInJob(Job job) {
if (job == null)
return false;
for (JobProgression prog : progression) {
if (prog.getJob().isSame(job))
return true;
}
return false;
return getJobProgression(job) != null;
}
/**
@ -1008,13 +1007,13 @@ public class JobsPlayer {
public void resetQuests(List<QuestProgression> quests) {
for (QuestProgression oneQ : quests) {
if (oneQ.getQuest() == null) {
continue;
}
if (oneQ.getQuest() != null) {
Map<String, QuestProgression> map = qProgression.remove(oneQ.getQuest().getJob().getName());
Job job = oneQ.getQuest().getJob();
getNewQuests(job);
qProgression.remove(job.getName());
if (map != null) {
map.clear();
}
}
}
}
@ -1058,7 +1057,9 @@ public class JobsPlayer {
if (q.getConfigName().equals(quest.getConfigName()))
return;
if (prog.containsKey(q.getConfigName().toLowerCase()))
String confName = q.getConfigName().toLowerCase();
if (prog.containsKey(confName))
return;
if (q.getJob() != quest.getJob() && prog.size() >= q.getJob().getMaxDailyQuests())
@ -1068,7 +1069,7 @@ public class JobsPlayer {
orProg.remove(quest.getConfigName().toLowerCase());
}
prog.put(q.getConfigName().toLowerCase(), new QuestProgression(q));
prog.put(confName, new QuestProgression(q));
skippedQuests++;
}