1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Correctly preloading player limits

This commit is contained in:
Zrips 2017-11-03 16:48:50 +02:00
parent e45df7f217
commit 8d98e8ddf3
5 changed files with 54 additions and 2 deletions

View File

@ -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<Integer, PlayerPoints> playersPoints = Jobs.getJobsDAO().getAllPoints();
HashMap<Integer, HashMap<String, Log>> playersLogs = Jobs.getJobsDAO().getAllLogs();
HashMap<Integer, ArchivedJobs> playersArchives = Jobs.getJobsDAO().getAllArchivedJobs();
HashMap<Integer, PaymentData> playersLimits = Jobs.getJobsDAO().loadPlayerLimits();
Iterator<Entry<UUID, PlayerInfo>> it = temp.entrySet().iterator();
while (it.hasNext()) {
Entry<UUID, PlayerInfo> 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);

View File

@ -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<JobsDAOData> jobs, PlayerPoints points, HashMap<String, Log> logs, ArchivedJobs archivedJobs) {
public JobsPlayer getJobsPlayerOffline(PlayerInfo info, List<JobsDAOData> jobs, PlayerPoints points, HashMap<String, Log> 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();

View File

@ -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);

View File

@ -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;
}
}

View File

@ -954,6 +954,36 @@ public abstract class JobsDAO {
return data;
}
public synchronized HashMap<Integer, PaymentData> loadPlayerLimits() {
HashMap<Integer, PaymentData> map = new HashMap<Integer, PaymentData>();
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