1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-16 21:21:20 +01:00

Resolving issue with jobs not being recognized properly

This commit is contained in:
Zrips 2021-07-16 12:34:59 +03:00
parent 77971390cd
commit a110342157
4 changed files with 37 additions and 10 deletions

View File

@ -522,7 +522,7 @@ public final class Jobs extends JavaPlugin {
*/ */
public static Job getJob(int id) { public static Job getJob(int id) {
for (Job job : jobs) { for (Job job : jobs) {
if (job.getId() == id) { if (job.getId() == id || job.getLegacyId() == id) {
return job; return job;
} }
} }

View File

@ -93,6 +93,7 @@ public class Job {
private final List<Quest> quests = new ArrayList<>(); private final List<Quest> quests = new ArrayList<>();
private int maxDailyQuests = 1; private int maxDailyQuests = 1;
private int id = 0; private int id = 0;
private int legacyId = 0;
private boolean ignoreMaxJobs = false; private boolean ignoreMaxJobs = false;
@Deprecated @Deprecated
@ -688,4 +689,12 @@ public class Job {
public void setJobDisplayName(String jobDisplayName) { public void setJobDisplayName(String jobDisplayName) {
this.jobDisplayName = jobDisplayName; this.jobDisplayName = jobDisplayName;
} }
public int getLegacyId() {
return legacyId;
}
public void setLegacyId(int legacyId) {
this.legacyId = legacyId;
}
} }

View File

@ -42,6 +42,8 @@ import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.TimeManage;
import com.gamingmesh.jobs.stuff.Util; import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.Logs.CMIDebug;
public abstract class JobsDAO { public abstract class JobsDAO {
private JobsConnectionPool pool; private JobsConnectionPool pool;
@ -781,7 +783,6 @@ public abstract class JobsDAO {
job = Jobs.getJob(jobid); job = Jobs.getJob(jobid);
} else { } else {
job = Jobs.getJob(jobName); job = Jobs.getJob(jobName);
converted = false;
} }
if (job == null) if (job == null)
@ -1183,8 +1184,18 @@ public abstract class JobsDAO {
String name = res.getString(worldsTableFields.name.getCollumn()); String name = res.getString(worldsTableFields.name.getCollumn());
Job job = Jobs.getJob(name); Job job = Jobs.getJob(name);
if (job != null) if (job != null) {
job.setId(id); if (job.getId() == 0)
job.setId(id);
else {
// Prioritizing id which matches actual job name and not full name which can be different
if (job.getName().equals(name)) {
job.setLegacyId(job.getId());
job.setId(id);
} else
job.setLegacyId(id);
}
}
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -1846,12 +1857,15 @@ public abstract class JobsDAO {
PreparedStatement prest = null; PreparedStatement prest = null;
try { try {
prest = conn.prepareStatement("UPDATE `" + getJobsTableName() + "` SET `" + JobsTableFields.level.getCollumn() + "` = ?, `" + JobsTableFields.experience.getCollumn() prest = conn.prepareStatement("UPDATE `" + getJobsTableName() + "` SET `" + JobsTableFields.level.getCollumn() + "` = ?, `" + JobsTableFields.experience.getCollumn()
+ "` = ? WHERE `" + JobsTableFields.userid.getCollumn() + "` = ? AND `" + JobsTableFields.jobid.getCollumn() + "` = ?;"); + "` = ? WHERE `" + JobsTableFields.userid.getCollumn() + "` = ? AND `" + JobsTableFields.jobid.getCollumn() + "` = ? "
+ "OR `" + JobsTableFields.userid.getCollumn() + "` = ? AND `" + JobsTableFields.jobid.getCollumn() + "` = ?;");
for (JobProgression progression : player.getJobProgression()) { for (JobProgression progression : player.getJobProgression()) {
prest.setInt(1, progression.getLevel()); prest.setInt(1, progression.getLevel());
prest.setDouble(2, progression.getExperience()); prest.setDouble(2, progression.getExperience());
prest.setInt(3, player.getUserId()); prest.setInt(3, player.getUserId());
prest.setInt(4, progression.getJob().getId()); prest.setInt(4, progression.getJob().getId());
prest.setInt(5, player.getUserId());
prest.setInt(6, progression.getJob().getLegacyId());
prest.execute(); prest.execute();
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -2547,9 +2561,11 @@ public abstract class JobsDAO {
try { try {
prest = conn.prepareStatement("SELECT `" + JobsTableFields.userid.getCollumn() + "`, `" + JobsTableFields.level.getCollumn() + "`, `" + JobsTableFields.experience.getCollumn() + "` FROM `" prest = conn.prepareStatement("SELECT `" + JobsTableFields.userid.getCollumn() + "`, `" + JobsTableFields.level.getCollumn() + "`, `" + JobsTableFields.experience.getCollumn() + "` FROM `"
+ getJobsTableName() + "` WHERE `" + JobsTableFields.jobid.getCollumn() + "` LIKE ? ORDER BY `" + JobsTableFields.level.getCollumn() + "` DESC, LOWER(" + getJobsTableName() + "` WHERE `" + JobsTableFields.jobid.getCollumn() + "` LIKE ? OR `" + JobsTableFields.jobid.getCollumn() + "` LIKE ? ORDER BY `" + JobsTableFields.level.getCollumn()
+ "` DESC, LOWER("
+ JobsTableFields.experience.getCollumn() + ") DESC LIMIT " + limit + ", 50;"); + JobsTableFields.experience.getCollumn() + ") DESC LIMIT " + limit + ", 50;");
prest.setInt(1, job.getId()); prest.setInt(1, job.getId());
prest.setInt(2, job.getLegacyId());
res = prest.executeQuery(); res = prest.executeQuery();
while (res.next()) { while (res.next()) {
@ -2580,8 +2596,9 @@ public abstract class JobsDAO {
PreparedStatement prest = null; PreparedStatement prest = null;
ResultSet res = null; ResultSet res = null;
try { try {
prest = conn.prepareStatement("SELECT COUNT(*) FROM `" + getJobsTableName() + "` WHERE `" + JobsTableFields.jobid.getCollumn() + "` = ?;"); prest = conn.prepareStatement("SELECT COUNT(*) FROM `" + getJobsTableName() + "` WHERE `" + JobsTableFields.jobid.getCollumn() + "` = ? OR `" + JobsTableFields.jobid.getCollumn() + "` = ?;");
prest.setInt(1, job.getId()); prest.setInt(1, job.getId());
prest.setInt(2, job.getLegacyId());
res = prest.executeQuery(); res = prest.executeQuery();
if (res.next()) { if (res.next()) {
slot = res.getInt(1); slot = res.getInt(1);

View File

@ -76,7 +76,8 @@ public final class TabComplete implements TabCompleter {
case "[jobname]": case "[jobname]":
case "[newjob]": case "[newjob]":
for (Job one : Jobs.getJobs()) { for (Job one : Jobs.getJobs()) {
temp.add(one.getName()); temp.add(one.getJobFullName());
// temp.add(one.getName());
} }
break; break;
@ -127,14 +128,14 @@ public final class TabComplete implements TabCompleter {
if (onePlayerJob != null) if (onePlayerJob != null)
for (JobProgression oneOldJob : onePlayerJob.getJobProgression()) { for (JobProgression oneOldJob : onePlayerJob.getJobProgression()) {
temp.add(oneOldJob.getJob().getName()); temp.add(oneOldJob.getJob().getJobFullName());
} }
break; break;
case "[oldplayerjob]": case "[oldplayerjob]":
if (sender instanceof Player && (onePlayerJob = Jobs.getPlayerManager().getJobsPlayer((Player) sender)) != null) { if (sender instanceof Player && (onePlayerJob = Jobs.getPlayerManager().getJobsPlayer((Player) sender)) != null) {
for (JobProgression oneOldJob : onePlayerJob.getJobProgression()) { for (JobProgression oneOldJob : onePlayerJob.getJobProgression()) {
temp.add(oneOldJob.getJob().getName()); temp.add(oneOldJob.getJob().getJobFullName());
} }
} }