From a1103421578ef29daf43acc62a4d877d73dc639c Mon Sep 17 00:00:00 2001 From: Zrips Date: Fri, 16 Jul 2021 12:34:59 +0300 Subject: [PATCH] Resolving issue with jobs not being recognized properly --- src/main/java/com/gamingmesh/jobs/Jobs.java | 2 +- .../com/gamingmesh/jobs/container/Job.java | 9 ++++++ .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 29 +++++++++++++++---- .../gamingmesh/jobs/stuff/TabComplete.java | 7 +++-- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index d94c22ee..ea553e5b 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -522,7 +522,7 @@ public final class Jobs extends JavaPlugin { */ public static Job getJob(int id) { for (Job job : jobs) { - if (job.getId() == id) { + if (job.getId() == id || job.getLegacyId() == id) { return job; } } diff --git a/src/main/java/com/gamingmesh/jobs/container/Job.java b/src/main/java/com/gamingmesh/jobs/container/Job.java index 1dbefd14..2510203e 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Job.java +++ b/src/main/java/com/gamingmesh/jobs/container/Job.java @@ -93,6 +93,7 @@ public class Job { private final List quests = new ArrayList<>(); private int maxDailyQuests = 1; private int id = 0; + private int legacyId = 0; private boolean ignoreMaxJobs = false; @Deprecated @@ -688,4 +689,12 @@ public class Job { public void setJobDisplayName(String jobDisplayName) { this.jobDisplayName = jobDisplayName; } + + public int getLegacyId() { + return legacyId; + } + + public void setLegacyId(int legacyId) { + this.legacyId = legacyId; + } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 34b5170e..33b778dc 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -42,6 +42,8 @@ import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.Util; +import net.Zrips.CMILib.Logs.CMIDebug; + public abstract class JobsDAO { private JobsConnectionPool pool; @@ -781,7 +783,6 @@ public abstract class JobsDAO { job = Jobs.getJob(jobid); } else { job = Jobs.getJob(jobName); - converted = false; } if (job == null) @@ -1183,8 +1184,18 @@ public abstract class JobsDAO { String name = res.getString(worldsTableFields.name.getCollumn()); Job job = Jobs.getJob(name); - if (job != null) - job.setId(id); + if (job != null) { + 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) { e.printStackTrace(); @@ -1846,12 +1857,15 @@ public abstract class JobsDAO { PreparedStatement prest = null; try { 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()) { prest.setInt(1, progression.getLevel()); prest.setDouble(2, progression.getExperience()); prest.setInt(3, player.getUserId()); prest.setInt(4, progression.getJob().getId()); + prest.setInt(5, player.getUserId()); + prest.setInt(6, progression.getJob().getLegacyId()); prest.execute(); } } catch (SQLException e) { @@ -2547,9 +2561,11 @@ public abstract class JobsDAO { try { 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;"); prest.setInt(1, job.getId()); + prest.setInt(2, job.getLegacyId()); res = prest.executeQuery(); while (res.next()) { @@ -2580,8 +2596,9 @@ public abstract class JobsDAO { PreparedStatement prest = null; ResultSet res = null; 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(2, job.getLegacyId()); res = prest.executeQuery(); if (res.next()) { slot = res.getInt(1); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java index 8c809c5c..2c1fbd02 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java @@ -76,7 +76,8 @@ public final class TabComplete implements TabCompleter { case "[jobname]": case "[newjob]": for (Job one : Jobs.getJobs()) { - temp.add(one.getName()); + temp.add(one.getJobFullName()); +// temp.add(one.getName()); } break; @@ -127,14 +128,14 @@ public final class TabComplete implements TabCompleter { if (onePlayerJob != null) for (JobProgression oneOldJob : onePlayerJob.getJobProgression()) { - temp.add(oneOldJob.getJob().getName()); + temp.add(oneOldJob.getJob().getJobFullName()); } break; case "[oldplayerjob]": if (sender instanceof Player && (onePlayerJob = Jobs.getPlayerManager().getJobsPlayer((Player) sender)) != null) { for (JobProgression oneOldJob : onePlayerJob.getJobProgression()) { - temp.add(oneOldJob.getJob().getName()); + temp.add(oneOldJob.getJob().getJobFullName()); } }