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

View File

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

View File

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

View File

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

View File

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