From 48de4cb28514d6976af943bb84715835beee1e70 Mon Sep 17 00:00:00 2001 From: Zrips Date: Mon, 19 Jul 2021 13:02:48 +0300 Subject: [PATCH] Cleaning up duplicated jobs records --- .../java/com/gamingmesh/jobs/PlayerManager.java | 4 ++-- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 1eb6f253..011e49ea 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -444,7 +444,7 @@ public class PlayerManager { // Fixing issue with doubled jobs. Picking bigger job by level or exp JobProgression oldProg = jPlayer.getJobProgression(job); if (oldProg != null && (oldProg.getLevel() > jobdata.getLevel() || oldProg.getLevel() == jobdata.getLevel() && oldProg.getExperience() > jobdata.getExperience())) { - Jobs.getDBManager().getDB().removeSpecificJob(jPlayer, jobdata.getJobName(), jobdata.getLevel()); + Jobs.getDBManager().getDB().removeSpecificJob(jPlayer.getUserId(), job.getName(), job.getJobFullName(), jobdata.getLevel(), jobdata.getExperience()); CMIMessages.consoleMessage("Cleaned up duplicated jobs record for " + jPlayer.getName() + " Job:" + jobdata.getJobName() + " Level:" + jobdata.getLevel()); continue; } @@ -455,7 +455,7 @@ public class PlayerManager { } } } - + if (points != null) jPlayer.setPoints(points); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index efe5d6e3..2e718050 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1590,22 +1590,23 @@ public abstract class JobsDAO { } /** - * Quit a job (delete player-job entry from storage) - * @param player - player that wishes to quit the job - * @param job - job that the player wishes to quit + * Remove duplicated job by specific criteria */ - public synchronized boolean removeSpecificJob(JobsPlayer jPlayer, String jobName, int level) { + public synchronized boolean removeSpecificJob(int userId, String jobName, String legacyName, int level, double exp) { JobsConnection conn = getConnection(); if (conn == null) return false; PreparedStatement prest = null; boolean done = true; try { - prest = conn.prepareStatement("DELETE FROM `" + getJobsTableName() + "` WHERE `" + JobsTableFields.userid.getCollumn() + "` = ? AND `" + JobsTableFields.job.getCollumn() - + "` = ? AND `" + JobsTableFields.level.getCollumn() + "` = ?;"); - prest.setInt(1, jPlayer.getUserId()); + prest = conn.prepareStatement("DELETE FROM `" + getJobsTableName() + "` WHERE `" + JobsTableFields.userid.getCollumn() + "` = ? AND (`" + JobsTableFields.job.getCollumn() + + "` = ? OR `" + JobsTableFields.job.getCollumn() + + "` = ?) AND `" + JobsTableFields.level.getCollumn() + "` = ? AND `" + JobsTableFields.experience.getCollumn() + "` = ?;"); + prest.setInt(1, userId); prest.setString(2, jobName); - prest.setInt(3, level); + prest.setString(3, legacyName); + prest.setInt(4, level); + prest.setDouble(5, exp); prest.execute(); } catch (SQLException e) { e.printStackTrace();