diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index 8c7dfd53..87744c08 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -144,16 +144,16 @@ public class PlayerManager { */ public void playerQuit(Player player) { JobsPlayer jPlayer = this.players.remove(player.getName().toLowerCase()); + if (jPlayer == null) + jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) + return; playersCache.put(player.getName().toLowerCase(), jPlayer); if (Jobs.getGCManager().saveOnDisconnect()) { - if (jPlayer != null) { - jPlayer.save(); - jPlayer.onDisconnect(); - } + jPlayer.save(); + jPlayer.onDisconnect(); } else { - if (jPlayer != null) { - jPlayer.onDisconnect(); - } + jPlayer.onDisconnect(); } } diff --git a/com/gamingmesh/jobs/container/Job.java b/com/gamingmesh/jobs/container/Job.java index 1a069c3e..7f67d679 100644 --- a/com/gamingmesh/jobs/container/Job.java +++ b/com/gamingmesh/jobs/container/Job.java @@ -23,14 +23,11 @@ import java.util.Collections; import java.util.EnumMap; import java.util.List; import java.util.Map; -import java.util.Random; - import org.bukkit.inventory.ItemStack; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.stuff.ChatColor; -import com.gamingmesh.jobs.stuff.Debug; public class Job { // job info diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index f8abdac2..8a4b4511 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -391,19 +391,22 @@ public abstract class JobsDAO { JobsConnection conn = getConnection(); if (conn == null) return; - PreparedStatement prest = null; + PreparedStatement prest2 = null; try { - prest = conn.prepareStatement("DELETE FROM `" + prefix + "limits` WHERE `userid` = ?;"); - prest.setInt(1, jPlayer.getUserId()); - prest.execute(); + prest2 = conn.prepareStatement("DELETE FROM `" + prefix + "limits` WHERE `userid` = ?;"); + prest2.setInt(1, jPlayer.getUserId()); + prest2.execute(); } catch (SQLException e) { e.printStackTrace(); } finally { - close(prest); + close(prest2); } + PreparedStatement prest = null; try { PaymentData limit = jPlayer.getPaymentLimit(); + prest = conn.prepareStatement("INSERT INTO `" + prefix + "limits` (`userid`, `type`, `collected`, `started`) VALUES (?, ?, ?, ?);"); + conn.setAutoCommit(false); for (CurrencyType type : CurrencyType.values()) { if (limit == null) continue; @@ -412,14 +415,16 @@ public abstract class JobsDAO { if (limit.GetLeftTime(type) < 0) continue; - prest = conn.prepareStatement("INSERT INTO `" + prefix + "limits` (`userid`, `type`, `collected`, `started`) VALUES (?, ?, ?, ?);"); prest.setInt(1, jPlayer.getUserId()); prest.setString(2, type.getName()); prest.setDouble(3, limit.GetAmount(type)); prest.setLong(4, limit.GetTime(type)); - prest.execute(); + prest.addBatch(); } - } catch (SQLException e) { + prest.executeBatch(); + conn.commit(); + conn.setAutoCommit(true); + } catch (Exception e) { e.printStackTrace(); } finally { close(prest); diff --git a/com/gamingmesh/jobs/dao/JobsDAOMySQL.java b/com/gamingmesh/jobs/dao/JobsDAOMySQL.java index 61ce59d9..0e3c48a3 100644 --- a/com/gamingmesh/jobs/dao/JobsDAOMySQL.java +++ b/com/gamingmesh/jobs/dao/JobsDAOMySQL.java @@ -310,10 +310,8 @@ public class JobsDAOMySQL extends JobsDAO { if (insert != null) insert.close(); - if (rs != null) - rs.close(); - if (pst1 != null) - pst1.close(); + rs.close(); + pst1.close(); executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "jobs`;"); executeSQL("ALTER TABLE `" + getPrefix() + "jobs_temp` RENAME TO `" + getPrefix() + "jobs`;"); @@ -374,10 +372,8 @@ public class JobsDAOMySQL extends JobsDAO { conn.commit(); conn.setAutoCommit(true); - if (rs1 != null) - rs1.close(); - if (pst11 != null) - pst11.close(); + rs1.close(); + pst11.close(); if (insert1 != null) insert1.close(); @@ -447,10 +443,8 @@ public class JobsDAOMySQL extends JobsDAO { conn.commit(); conn.setAutoCommit(true); - if (pst111 != null) - pst111.close(); - if (rs11 != null) - rs11.close(); + pst111.close(); + rs11.close(); if (insert11 != null) insert11.close(); @@ -815,7 +809,7 @@ public class JobsDAOMySQL extends JobsDAO { } return true; } - + private boolean createDefaultLimitBase() { try { executeSQL("CREATE TABLE IF NOT EXISTS `" + getPrefix() diff --git a/com/gamingmesh/jobs/dao/JobsDAOSQLite.java b/com/gamingmesh/jobs/dao/JobsDAOSQLite.java index 1e947bf6..b2f865ac 100644 --- a/com/gamingmesh/jobs/dao/JobsDAOSQLite.java +++ b/com/gamingmesh/jobs/dao/JobsDAOSQLite.java @@ -22,14 +22,8 @@ import java.io.File; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map.Entry; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; - import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.PlayerInfo; import com.gamingmesh.jobs.stuff.UUIDUtil; @@ -318,10 +312,8 @@ public class JobsDAOSQLite extends JobsDAO { conn.commit(); conn.setAutoCommit(true); - if (rs != null) - rs.close(); - if (pst1 != null) - pst1.close(); + rs.close(); + pst1.close(); if (insert != null) insert.close(); @@ -389,10 +381,9 @@ public class JobsDAOSQLite extends JobsDAO { insert1.executeBatch(); conn.commit(); conn.setAutoCommit(true); - if (rs1 != null) - rs1.close(); - if (pst11 != null) - pst11.close(); + + rs1.close(); + pst11.close(); if (insert1 != null) insert1.close(); executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "archive`;"); @@ -464,10 +455,9 @@ public class JobsDAOSQLite extends JobsDAO { insert11.executeBatch(); conn.commit(); conn.setAutoCommit(true); - if (rs11 != null) - rs11.close(); - if (pst111 != null) - pst111.close(); + + rs11.close(); + pst111.close(); if (insert11 != null) insert11.close(); @@ -685,10 +675,8 @@ public class JobsDAOSQLite extends JobsDAO { insert11.execute(); } } - if (rs11 != null) - rs11.close(); - if (pst111 != null) - pst111.close(); + rs11.close(); + pst111.close(); if (insert11 != null) insert11.close(); try { @@ -881,7 +869,7 @@ public class JobsDAOSQLite extends JobsDAO { } return true; } - + private boolean createDefaultLimitBase() { try { executeSQL("CREATE TABLE IF NOT EXISTS `" + getPrefix()