mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-17 21:51:20 +01:00
Allot faster player data pre loading
This commit is contained in:
parent
1dc24ca1b0
commit
2370c8afc2
@ -73,7 +73,9 @@ import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobInfo;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.container.Log;
|
||||
import com.gamingmesh.jobs.container.PlayerInfo;
|
||||
import com.gamingmesh.jobs.container.PlayerPoints;
|
||||
import com.gamingmesh.jobs.dao.*;
|
||||
import com.gamingmesh.jobs.container.FastPayment;
|
||||
import com.gamingmesh.jobs.economy.BufferedEconomy;
|
||||
@ -90,6 +92,7 @@ import com.gamingmesh.jobs.stuff.Loging;
|
||||
import com.gamingmesh.jobs.stuff.TabComplete;
|
||||
import com.gamingmesh.jobs.stuff.VersionChecker;
|
||||
import com.gamingmesh.jobs.stuff.CMIScoreboardManager;
|
||||
import com.gamingmesh.jobs.stuff.Debug;
|
||||
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
|
||||
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
|
||||
|
||||
@ -531,40 +534,27 @@ public class Jobs extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static void loadAllPlayersData() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int i = 0;
|
||||
int y = 0;
|
||||
int total = Jobs.getPlayerManager().getMapSize();
|
||||
long time = System.currentTimeMillis();
|
||||
// Cloning to avoid issues
|
||||
HashMap<UUID, PlayerInfo> temp = new HashMap<UUID, PlayerInfo>(Jobs.getPlayerManager().getPlayersInfoUUIDMap());
|
||||
Iterator<Entry<UUID, PlayerInfo>> it = temp.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, PlayerInfo> one = it.next();
|
||||
if (!running)
|
||||
return;
|
||||
try {
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(one.getValue());
|
||||
if (jPlayer == null)
|
||||
continue;
|
||||
Jobs.getPlayerManager().addPlayerToCache(jPlayer);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
i++;
|
||||
y++;
|
||||
if (y >= 1000) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loaded " + i + "/" + total + " players data");
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
dao.getMap().clear();
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Preloaded " + i + " players data in " + ((int) (((System.currentTimeMillis() - time)
|
||||
/ 1000d) * 100) / 100D));
|
||||
return;
|
||||
long time = System.currentTimeMillis();
|
||||
// Cloning to avoid issues
|
||||
HashMap<UUID, PlayerInfo> temp = new HashMap<UUID, PlayerInfo>(Jobs.getPlayerManager().getPlayersInfoUUIDMap());
|
||||
HashMap<Integer, List<JobsDAOData>> playersJobs = Jobs.getJobsDAO().getAllJobs();
|
||||
HashMap<Integer, PlayerPoints> playersPoints = Jobs.getJobsDAO().getAllPoints();
|
||||
HashMap<Integer, HashMap<String, Log>> playersLogs = Jobs.getJobsDAO().getAllLogs();
|
||||
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));
|
||||
if (jPlayer == null)
|
||||
continue;
|
||||
Jobs.getPlayerManager().addPlayerToCache(jPlayer);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
dao.getMap().clear();
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Preloaded " + Jobs.getPlayerManager().getPlayersCache().size() + " players data in " + ((int) (((System.currentTimeMillis() - time)
|
||||
/ 1000d) * 100) / 100D));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,9 @@ import com.gamingmesh.jobs.container.JobCommands;
|
||||
import com.gamingmesh.jobs.container.JobItems;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.container.Log;
|
||||
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.PointsData;
|
||||
@ -282,7 +284,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) {
|
||||
public JobsPlayer getJobsPlayerOffline(PlayerInfo info, List<JobsDAOData> jobs, PlayerPoints points, HashMap<String, Log> logs) {
|
||||
|
||||
if (info == null)
|
||||
return null;
|
||||
@ -294,22 +296,28 @@ public class PlayerManager {
|
||||
jPlayer.setPlayerUUID(info.getUuid());
|
||||
jPlayer.setUserId(info.getID());
|
||||
|
||||
List<JobsDAOData> list = Jobs.getJobsDAO().getAllJobs(info.getName(), info.getUuid());
|
||||
for (JobsDAOData jobdata : list) {
|
||||
if (Jobs.getJob(jobdata.getJobName()) == null)
|
||||
continue;
|
||||
Job job = Jobs.getJob(jobdata.getJobName());
|
||||
if (job == null)
|
||||
continue;
|
||||
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience());
|
||||
jPlayer.progression.add(jobProgression);
|
||||
jPlayer.reloadMaxExperience();
|
||||
jPlayer.reloadLimits();
|
||||
// List<JobsDAOData> list = Jobs.getJobsDAO().getAllJobs(info.getName(), info.getUuid());
|
||||
if (jobs != null)
|
||||
for (JobsDAOData jobdata : jobs) {
|
||||
if (Jobs.getJob(jobdata.getJobName()) == null)
|
||||
continue;
|
||||
Job job = Jobs.getJob(jobdata.getJobName());
|
||||
if (job == null)
|
||||
continue;
|
||||
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience());
|
||||
jPlayer.progression.add(jobProgression);
|
||||
jPlayer.reloadMaxExperience();
|
||||
jPlayer.reloadLimits();
|
||||
}
|
||||
|
||||
if (points != null) {
|
||||
Jobs.getPlayerManager().getPointsData().addPlayer(jPlayer.getPlayerUUID(), points);
|
||||
} else {
|
||||
Jobs.getPlayerManager().getPointsData().addPlayer(jPlayer.getPlayerUUID());
|
||||
}
|
||||
|
||||
Jobs.getJobsDAO().loadPoints(jPlayer);
|
||||
|
||||
jPlayer.loadLogFromDao();
|
||||
if (logs != null)
|
||||
jPlayer.setLog(logs);
|
||||
|
||||
return jPlayer;
|
||||
}
|
||||
|
@ -50,11 +50,12 @@ public class glog implements Cmd {
|
||||
|
||||
if (JPlayer == null)
|
||||
continue;
|
||||
List<Log> logList = JPlayer.getLog();
|
||||
HashMap<String, Log> logList = JPlayer.getLog();
|
||||
if (logList.size() == 0)
|
||||
continue;
|
||||
|
||||
for (Log one : logList) {
|
||||
for (Entry<String, Log> l : logList.entrySet()) {
|
||||
Log one = l.getValue();
|
||||
HashMap<String, LogAmounts> AmountList = one.getAmountList();
|
||||
for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) {
|
||||
oneMap.getValue().setUsername(name);
|
||||
|
@ -47,7 +47,7 @@ public class log implements Cmd {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Log> logList = JPlayer.getLog();
|
||||
HashMap<String, Log> logList = JPlayer.getLog();
|
||||
|
||||
if (logList.size() == 0) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.bottomline"));
|
||||
@ -58,7 +58,8 @@ public class log implements Cmd {
|
||||
|
||||
Map<String, Double> unsortMap = new HashMap<String, Double>();
|
||||
|
||||
for (Log one : logList) {
|
||||
for (Entry<String, Log> l : logList.entrySet()) {
|
||||
Log one = l.getValue();
|
||||
HashMap<String, LogAmounts> AmountList = one.getAmountList();
|
||||
for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) {
|
||||
unsortMap.put(oneMap.getKey(), oneMap.getValue().getMoney());
|
||||
@ -69,7 +70,8 @@ public class log implements Cmd {
|
||||
int count = 0;
|
||||
int max = 10;
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.topline", "%playername%", JPlayer.getUserName()));
|
||||
for (Log one : logList) {
|
||||
for (Entry<String, Log> l : logList.entrySet()) {
|
||||
Log one = l.getValue();
|
||||
HashMap<String, LogAmounts> AmountList = one.getAmountList();
|
||||
for (Entry<String, Double> oneSorted : unsortMap.entrySet()) {
|
||||
for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) {
|
||||
|
@ -67,7 +67,7 @@ public class JobsPlayer {
|
||||
// public final Object saveLock = new Object();
|
||||
|
||||
// log
|
||||
private List<Log> logList = new ArrayList<Log>();
|
||||
private HashMap<String, Log> logList = new HashMap<String, Log>();
|
||||
|
||||
private Long seen = System.currentTimeMillis();
|
||||
|
||||
@ -151,10 +151,14 @@ public class JobsPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Log> getLog() {
|
||||
public HashMap<String, Log> getLog() {
|
||||
return this.logList;
|
||||
}
|
||||
|
||||
public void setLog(HashMap<String, Log> l) {
|
||||
this.logList = l;
|
||||
}
|
||||
|
||||
public void setUserId(int id) {
|
||||
this.userid = id;
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ public abstract class JobsDAO {
|
||||
prest.setInt(1, id);
|
||||
res = prest.executeQuery();
|
||||
while (res.next()) {
|
||||
jobs.add(new JobsDAOData(res.getString(1), res.getInt(2), res.getInt(3)));
|
||||
jobs.add(new JobsDAOData(res.getString("job"), res.getInt("level"), res.getInt("experience")));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -585,6 +585,97 @@ public abstract class JobsDAO {
|
||||
return jobs;
|
||||
}
|
||||
|
||||
public HashMap<Integer, List<JobsDAOData>> getAllJobs() {
|
||||
HashMap<Integer, List<JobsDAOData>> map = new HashMap<Integer, List<JobsDAOData>>();
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return map;
|
||||
PreparedStatement prest = null;
|
||||
ResultSet res = null;
|
||||
try {
|
||||
prest = conn.prepareStatement("SELECT * FROM `" + prefix + "jobs`;");
|
||||
res = prest.executeQuery();
|
||||
while (res.next()) {
|
||||
int id = res.getInt("userid");
|
||||
List<JobsDAOData> ls = map.get(id);
|
||||
if (ls == null)
|
||||
ls = new ArrayList<JobsDAOData>();
|
||||
ls.add(new JobsDAOData(res.getString("job"), res.getInt("level"), res.getInt("experience")));
|
||||
map.put(id, ls);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(res);
|
||||
close(prest);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public HashMap<Integer, PlayerPoints> getAllPoints() {
|
||||
HashMap<Integer, PlayerPoints> map = new HashMap<Integer, PlayerPoints>();
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return map;
|
||||
PreparedStatement prest = null;
|
||||
ResultSet res = null;
|
||||
try {
|
||||
prest = conn.prepareStatement("SELECT * FROM `" + prefix + "points`;");
|
||||
res = prest.executeQuery();
|
||||
while (res.next()) {
|
||||
map.put(res.getInt(PointsTableFields.userid.getCollumn()), new PlayerPoints(res.getDouble("currentpoints"), res.getDouble("totalpoints")));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(res);
|
||||
close(prest);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public HashMap<Integer, HashMap<String, Log>> getAllLogs() {
|
||||
HashMap<Integer, HashMap<String, Log>> map = new HashMap<Integer, HashMap<String, Log>>();
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return map;
|
||||
PreparedStatement prest = null;
|
||||
ResultSet res = null;
|
||||
try {
|
||||
int time = TimeManage.timeInInt();
|
||||
prest = conn.prepareStatement("SELECT * FROM `" + prefix + "log` WHERE `time` = ? ;");
|
||||
prest.setInt(1, time);
|
||||
res = prest.executeQuery();
|
||||
while (res.next()) {
|
||||
|
||||
int id = res.getInt("userid");
|
||||
|
||||
HashMap<String, Log> m = map.get(id);
|
||||
if (m == null)
|
||||
m = new HashMap<String, Log>();
|
||||
String action = res.getString("action");
|
||||
Log log = m.get(action);
|
||||
|
||||
if (log == null)
|
||||
log = new Log(action);
|
||||
|
||||
log.add(res.getString("itemname"), res.getInt("count"), res.getDouble("money"), res.getDouble("exp"));
|
||||
|
||||
m.put(action, log);
|
||||
map.put(id, m);
|
||||
|
||||
// Jobs.getLoging().loadToLog(player, res.getString("action"), res.getString("itemname"), res.getInt("count"), res.getDouble("money"), res.getDouble("exp"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
close(res);
|
||||
close(prest);
|
||||
} finally {
|
||||
close(res);
|
||||
close(prest);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private HashMap<Integer, ArrayList<JobsDAOData>> map = new HashMap<Integer, ArrayList<JobsDAOData>>();
|
||||
|
||||
public List<JobsDAOData> getAllJobs(PlayerInfo pInfo) {
|
||||
@ -965,13 +1056,12 @@ public abstract class JobsDAO {
|
||||
while (i > 0) {
|
||||
i--;
|
||||
|
||||
|
||||
Convert convertData = list.get(i);
|
||||
|
||||
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(convertData.GetUserUUID());
|
||||
if (jPlayer == null)
|
||||
continue;
|
||||
|
||||
|
||||
insert.setInt(1, jPlayer.getUserId());
|
||||
insert.setString(2, convertData.GetJobName());
|
||||
insert.setInt(3, convertData.GetLevel());
|
||||
@ -1488,7 +1578,8 @@ public abstract class JobsDAO {
|
||||
try {
|
||||
prest1 = conn.prepareStatement("UPDATE `" + prefix
|
||||
+ "log` SET `count` = ?, `money` = ?, `exp` = ? WHERE `userid` = ? AND `time` = ? AND `action` = ? AND `itemname` = ?;");
|
||||
for (Log log : player.getLog()) {
|
||||
for (Entry<String, Log> l : player.getLog().entrySet()) {
|
||||
Log log = l.getValue();
|
||||
for (Entry<String, LogAmounts> one : log.getAmountList().entrySet()) {
|
||||
if (one.getValue().isNewEntry())
|
||||
continue;
|
||||
@ -1506,7 +1597,8 @@ public abstract class JobsDAO {
|
||||
}
|
||||
prest2 = conn.prepareStatement("INSERT INTO `" + prefix
|
||||
+ "log` (`userid`, `time`, `action`, `itemname`, `count`, `money`, `exp`) VALUES (?, ?, ?, ?, ?, ?, ?);");
|
||||
for (Log log : player.getLog()) {
|
||||
for (Entry<String, Log> l : player.getLog().entrySet()) {
|
||||
Log log = l.getValue();
|
||||
for (Entry<String, LogAmounts> one : log.getAmountList().entrySet()) {
|
||||
|
||||
if (!one.getValue().isNewEntry())
|
||||
|
@ -29,6 +29,11 @@ public class PointsData {
|
||||
Pointbase.put(uuid, new PlayerPoints(points, total));
|
||||
}
|
||||
|
||||
public void addPlayer(UUID uuid, PlayerPoints points) {
|
||||
if (!Pointbase.containsKey(uuid))
|
||||
Pointbase.put(uuid, points);
|
||||
}
|
||||
|
||||
public void addPoints(UUID uuid, Double points) {
|
||||
if (!Pointbase.containsKey(uuid))
|
||||
addPlayer(uuid, points);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gamingmesh.jobs.stuff;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.ActionInfo;
|
||||
@ -14,42 +15,29 @@ public class Loging {
|
||||
}
|
||||
|
||||
public void recordToLog(JobsPlayer jPlayer, String ActionName, String item, double amount, double expAmount) {
|
||||
List<Log> logList = jPlayer.getLog();
|
||||
boolean found = false;
|
||||
|
||||
if (jPlayer.getLog().size() > 0 && Jobs.getScheduleManager().getDateByInt() != jPlayer.getLog().get(0).getDate()) {
|
||||
if (Jobs.getScheduleManager().getDateByInt() != jPlayer.getLog().get(0).getDate()) {
|
||||
Jobs.getJobsDAO().saveLog(jPlayer);
|
||||
jPlayer.getLog().clear();
|
||||
}
|
||||
HashMap<String, Log> logList = jPlayer.getLog();
|
||||
Log l = null;
|
||||
for (Entry<String, Log> one : logList.entrySet()) {
|
||||
l = one.getValue();
|
||||
break;
|
||||
}
|
||||
|
||||
for (Log one : logList) {
|
||||
if (!one.getActionType().equalsIgnoreCase(ActionName))
|
||||
continue;
|
||||
one.add(item, amount, expAmount);
|
||||
found = true;
|
||||
}
|
||||
if (!found) {
|
||||
Log log = new Log(ActionName);
|
||||
log.add(item, amount, expAmount);
|
||||
logList.add(log);
|
||||
if (l != null && Jobs.getScheduleManager().getDateByInt() != l.getDate()) {
|
||||
Jobs.getJobsDAO().saveLog(jPlayer);
|
||||
jPlayer.getLog().clear();
|
||||
}
|
||||
Log log = logList.get(ActionName);
|
||||
if (log == null)
|
||||
log = new Log(ActionName);
|
||||
log.add(item, amount, expAmount);
|
||||
}
|
||||
|
||||
public void loadToLog(JobsPlayer jPlayer, String ActionName, String item, int count, double money, double expAmount) {
|
||||
List<Log> logList = jPlayer.getLog();
|
||||
boolean found = false;
|
||||
for (Log one : logList) {
|
||||
if (!one.getActionType().equalsIgnoreCase(ActionName))
|
||||
continue;
|
||||
one.add(item, count, money, expAmount);
|
||||
found = true;
|
||||
}
|
||||
if (!found) {
|
||||
Log log = new Log(ActionName);
|
||||
log.add(item, count, money, expAmount);
|
||||
logList.add(log);
|
||||
}
|
||||
HashMap<String, Log> logList = jPlayer.getLog();
|
||||
|
||||
Log log = logList.get(ActionName);
|
||||
if (log == null)
|
||||
log = new Log(ActionName);
|
||||
log.add(item, count, money, expAmount);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user