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

Check if sender is not null

Check if this is same job by name, not by constructor
This commit is contained in:
Zrips 2016-08-05 14:08:08 +03:00
parent d94e2dea58
commit c308e0db66
5 changed files with 29 additions and 20 deletions

View File

@ -245,14 +245,14 @@ public class PlayerManager {
return jPlayer;
}
/**
* Get the player job info for specific player
* @param player - the player who's job you're getting
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayerOffline(Entry<String, PlayerInfo> info) {
if (info == null)
return null;
@ -282,7 +282,7 @@ public class PlayerManager {
return jPlayer;
}
/**
* Causes player to join their job
* @param jPlayer
@ -317,21 +317,22 @@ public class PlayerManager {
* @param jPlayer
* @param job
*/
public void leaveJob(JobsPlayer jPlayer, Job job) {
public boolean leaveJob(JobsPlayer jPlayer, Job job) {
// synchronized (jPlayer.saveLock) {
if (!jPlayer.isInJob(job))
return;
Jobs.getJobsDAO().recordToArchive(jPlayer, job);
// let the user leave the job
if (!jPlayer.leaveJob(job))
return;
return false;
// JobsJoin event
JobsLeaveEvent jobsleaveevent = new JobsLeaveEvent(jPlayer, job);
Bukkit.getServer().getPluginManager().callEvent(jobsleaveevent);
// If event is canceled, dont do anything
if (jobsleaveevent.isCancelled())
return;
return false;
Jobs.getJobsDAO().recordToArchive(jPlayer, job);
// let the user leave the job
if (!jPlayer.leaveJob(job))
return false;
Jobs.getJobsDAO().quitJob(jPlayer, job);
PerformCommands.PerformCommandsOnLeave(jPlayer, job);
@ -340,6 +341,7 @@ public class PlayerManager {
Jobs.getSignUtil().SignUpdate(job.getName());
Jobs.getSignUtil().SignUpdate("gtoplist");
job.updateTotalPlayers();
return true;
// }
}
@ -638,7 +640,7 @@ public class PlayerManager {
return data;
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
if (iih == null || prog == null)
return data;

View File

@ -11,7 +11,6 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
public class leave implements Cmd {
@Override
@ -35,10 +34,11 @@ public class leave implements Cmd {
return true;
}
Jobs.getPlayerManager().leaveJob(jPlayer, job);
String message = Jobs.getLanguage().getMessage("command.leave.success");
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
sender.sendMessage(message);
if (Jobs.getPlayerManager().leaveJob(jPlayer, job)) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.leave.success", "%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE));
} else
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
}

View File

@ -121,7 +121,11 @@ public class Job {
public void setPointBoost(double Point) {
this.PointBoost = Point;
}
public boolean same(Job job) {
return this.getName().equalsIgnoreCase(job.getName());
}
public double getPointBoost() {
return this.PointBoost;
}

View File

@ -293,7 +293,7 @@ public class JobsPlayer {
*/
public JobProgression getJobProgression(Job job) {
for (JobProgression prog : progression) {
if (prog.getJob().equals(job))
if (prog.getJob().same(job))
return prog;
}
return null;
@ -456,7 +456,7 @@ public class JobsPlayer {
// synchronized (saveLock) {
if (!isInJob(newjob)) {
for (JobProgression prog : progression) {
if (!prog.getJob().equals(oldjob))
if (!prog.getJob().same(oldjob))
continue;
prog.setJob(newjob);
@ -490,7 +490,7 @@ public class JobsPlayer {
*/
public boolean isInJob(Job job) {
for (JobProgression prog : progression) {
if (prog.getJob().equals(job))
if (prog.getJob().same(job))
return true;
}
return false;

View File

@ -122,6 +122,9 @@ public class ActionBar {
if (msg == null || nmsChatSerializer == null)
return;
if (receivingPacket == null)
return;
if (cleanVersion < 1800 || !(receivingPacket instanceof Player)) {
receivingPacket.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
return;