diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index f233ef51..7d61b99b 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -83,6 +83,7 @@ import com.gamingmesh.jobs.container.FastPayment; import com.gamingmesh.jobs.economy.BufferedEconomy; import com.gamingmesh.jobs.economy.BufferedPayment; import com.gamingmesh.jobs.economy.Economy; +import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.listeners.JobsListener; import com.gamingmesh.jobs.listeners.JobsPaymentListener; @@ -543,12 +544,19 @@ public class Jobs extends JavaPlugin { HashMap playersPoints = Jobs.getJobsDAO().getAllPoints(); HashMap> playersLogs = Jobs.getJobsDAO().getAllLogs(); HashMap playersArchives = Jobs.getJobsDAO().getAllArchivedJobs(); + HashMap playersLimits = Jobs.getJobsDAO().loadPlayerLimits(); Iterator> it = temp.entrySet().iterator(); while (it.hasNext()) { Entry one = it.next(); try { int id = one.getValue().getID(); - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(one.getValue(), playersJobs.get(id), playersPoints.get(id), playersLogs.get(id), playersArchives.get(id)); + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline( + one.getValue(), + playersJobs.get(id), + playersPoints.get(id), + playersLogs.get(id), + playersArchives.get(id), + playersLimits.get(id)); if (jPlayer == null) continue; Jobs.getPlayerManager().addPlayerToCache(jPlayer); diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 4ef9d262..f48c7034 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -55,6 +55,7 @@ import com.gamingmesh.jobs.container.PlayerInfo; import com.gamingmesh.jobs.container.PlayerPoints; import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.dao.JobsDAOData; +import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.economy.PointsData; import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.PerformCommands; @@ -287,7 +288,7 @@ public class PlayerManager { * @param player - the player who's job you're getting * @return the player job info of the player */ - public JobsPlayer getJobsPlayerOffline(PlayerInfo info, List jobs, PlayerPoints points, HashMap logs, ArchivedJobs archivedJobs) { + public JobsPlayer getJobsPlayerOffline(PlayerInfo info, List jobs, PlayerPoints points, HashMap logs, ArchivedJobs archivedJobs, PaymentData limits) { if (info == null) return null; @@ -320,6 +321,9 @@ public class PlayerManager { if (logs != null) jPlayer.setLog(logs); + + if (limits != null) + jPlayer.setPaymentLimit(limits); if (archivedJobs != null) { ArchivedJobs aj = new ArchivedJobs(); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 2af9f6e5..d63e297d 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -102,6 +102,10 @@ public class JobsPlayer { return i; } + public void setPaymentLimit(PaymentData limits) { + paymentLimits = limits; + } + public PaymentData getPaymentLimit() { if (paymentLimits == null) { paymentLimits = Jobs.getJobsDAO().getPlayersLimits(this); diff --git a/src/main/java/com/gamingmesh/jobs/container/PlayerInfo.java b/src/main/java/com/gamingmesh/jobs/container/PlayerInfo.java index 48a158cf..ace4541b 100644 --- a/src/main/java/com/gamingmesh/jobs/container/PlayerInfo.java +++ b/src/main/java/com/gamingmesh/jobs/container/PlayerInfo.java @@ -39,4 +39,10 @@ public class PlayerInfo { public UUID getUuid() { return uuid; } + + public JobsPlayer getJobsPlayer() { + if (player == null) + player = Jobs.getPlayerManager().getJobsPlayer(uuid); + return player; + } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 5fcd2e49..3a107d5d 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -954,6 +954,36 @@ public abstract class JobsDAO { return data; } + public synchronized HashMap loadPlayerLimits() { + HashMap map = new HashMap(); + JobsConnection conn = getConnection(); + if (conn == null) + return map; + PreparedStatement prest = null; + ResultSet res = null; + try { + prest = conn.prepareStatement("SELECT * FROM `" + prefix + "limits`;"); + res = prest.executeQuery(); + while (res.next()) { + int id = res.getInt(LimitTableFields.userid.getCollumn()); + PaymentData data = map.get(id); + if (data == null) + data = new PaymentData(); + CurrencyType type = CurrencyType.getByName(res.getString("type")); + if (type == null) + continue; + data.AddNewAmount(type, res.getDouble("collected"), res.getLong("started")); + map.put(id, data); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + close(res); + close(prest); + } + return map; + } + /** * Join a job (create player-job entry from storage) * @param player - player that wishes to join the job