mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-03 23:08:07 +01:00
PreLoad player data in async mode to minimize server load time
Fix for converter not finding lastseen time Get player name from appropriate place if not defined from before
This commit is contained in:
parent
e44b208fad
commit
911907818a
@ -139,6 +139,7 @@ public class Jobs extends JavaPlugin {
|
||||
private static NMS nms;
|
||||
|
||||
private static ActionBar actionbar;
|
||||
private boolean running = false;
|
||||
|
||||
public void setMcMMOlistener() {
|
||||
McMMOlistener = new McMMOlistener(this);
|
||||
@ -462,11 +463,17 @@ public class Jobs extends JavaPlugin {
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int i = 0;
|
||||
int y = 0;
|
||||
int total = Jobs.getPlayerManager().getPlayerMap().size();
|
||||
long time = System.currentTimeMillis();
|
||||
for (Entry<String, PlayerInfo> one : Jobs.getPlayerManager().getPlayerMap().entrySet()) {
|
||||
if (!running)
|
||||
return;
|
||||
try {
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(one);
|
||||
if (jPlayer == null)
|
||||
@ -484,7 +491,9 @@ public class Jobs extends JavaPlugin {
|
||||
dao.getMap().clear();
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Preloaded " + i + " players data in " + ((int) (((System.currentTimeMillis() - time)
|
||||
/ 1000d) * 100) / 100D));
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
// add all online players
|
||||
for (Player online : Bukkit.getServer().getOnlinePlayers()) {
|
||||
Jobs.getPlayerManager().playerJoin(online);
|
||||
@ -644,7 +653,7 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
running = true;
|
||||
String packageName = getServer().getClass().getPackage().getName();
|
||||
String[] packageSplit = packageName.split("\\.");
|
||||
version = packageSplit[packageSplit.length - 1].substring(0, packageSplit[packageSplit.length - 1].length() - 3);
|
||||
@ -744,6 +753,7 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
running = false;
|
||||
GUIManager.CloseInventories();
|
||||
shopManager.CloseInventories();
|
||||
dao.saveExplore();
|
||||
|
@ -15,6 +15,7 @@ import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.container.Log;
|
||||
import com.gamingmesh.jobs.container.LogAmounts;
|
||||
import com.gamingmesh.jobs.container.PlayerInfo;
|
||||
import com.gamingmesh.jobs.stuff.Debug;
|
||||
import com.gamingmesh.jobs.stuff.Sorting;
|
||||
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class JobsPlayer {
|
||||
// log
|
||||
private List<Log> logList = new ArrayList<Log>();
|
||||
|
||||
private Long seen;
|
||||
private Long seen = System.currentTimeMillis();
|
||||
|
||||
public JobsPlayer(String userName, OfflinePlayer player) {
|
||||
this.userName = userName;
|
||||
@ -309,6 +309,10 @@ public class JobsPlayer {
|
||||
* @return the userName
|
||||
*/
|
||||
public String getUserName() {
|
||||
if (userName == null && player != null)
|
||||
userName = player.getName();
|
||||
if (userName == null && OffPlayer != null)
|
||||
userName = OffPlayer.getName();
|
||||
return userName;
|
||||
}
|
||||
|
||||
|
@ -521,7 +521,7 @@ public abstract class JobsDAO {
|
||||
insert.setInt(1, oneUser.getValue().getUserId());
|
||||
insert.setString(2, oneUser.getValue().getPlayerUUID().toString());
|
||||
insert.setString(3, oneUser.getValue().getUserName());
|
||||
insert.setLong(4, oneUser.getValue().getSeen());
|
||||
insert.setLong(4, oneUser.getValue().getSeen() == null ? System.currentTimeMillis() : oneUser.getValue().getSeen());
|
||||
insert.addBatch();
|
||||
}
|
||||
insert.executeBatch();
|
||||
|
Loading…
Reference in New Issue
Block a user