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 NMS nms;
|
||||||
|
|
||||||
private static ActionBar actionbar;
|
private static ActionBar actionbar;
|
||||||
|
private boolean running = false;
|
||||||
|
|
||||||
public void setMcMMOlistener() {
|
public void setMcMMOlistener() {
|
||||||
McMMOlistener = new McMMOlistener(this);
|
McMMOlistener = new McMMOlistener(this);
|
||||||
@ -462,29 +463,37 @@ public class Jobs extends JavaPlugin {
|
|||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
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()) {
|
|
||||||
try {
|
|
||||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(one);
|
|
||||||
if (jPlayer == null)
|
|
||||||
continue;
|
|
||||||
Jobs.getPlayerManager().getPlayersCache().put(one.getValue().getName().toLowerCase(), 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));
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
continue;
|
||||||
|
Jobs.getPlayerManager().getPlayersCache().put(one.getValue().getName().toLowerCase(), 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;
|
||||||
|
}
|
||||||
|
});
|
||||||
// add all online players
|
// add all online players
|
||||||
for (Player online : Bukkit.getServer().getOnlinePlayers()) {
|
for (Player online : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
Jobs.getPlayerManager().playerJoin(online);
|
Jobs.getPlayerManager().playerJoin(online);
|
||||||
@ -644,7 +653,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
running = true;
|
||||||
String packageName = getServer().getClass().getPackage().getName();
|
String packageName = getServer().getClass().getPackage().getName();
|
||||||
String[] packageSplit = packageName.split("\\.");
|
String[] packageSplit = packageName.split("\\.");
|
||||||
version = packageSplit[packageSplit.length - 1].substring(0, packageSplit[packageSplit.length - 1].length() - 3);
|
version = packageSplit[packageSplit.length - 1].substring(0, packageSplit[packageSplit.length - 1].length() - 3);
|
||||||
@ -744,6 +753,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
running = false;
|
||||||
GUIManager.CloseInventories();
|
GUIManager.CloseInventories();
|
||||||
shopManager.CloseInventories();
|
shopManager.CloseInventories();
|
||||||
dao.saveExplore();
|
dao.saveExplore();
|
||||||
@ -770,15 +780,15 @@ public class Jobs extends JavaPlugin {
|
|||||||
public static void action(JobsPlayer jPlayer, ActionInfo info, Block block) {
|
public static void action(JobsPlayer jPlayer, ActionInfo info, Block block) {
|
||||||
action(jPlayer, info, block, null, null);
|
action(jPlayer, info, block, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent) {
|
public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent) {
|
||||||
action(jPlayer, info, null, ent, null);
|
action(jPlayer, info, null, ent, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent, LivingEntity victim) {
|
public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent, LivingEntity victim) {
|
||||||
action(jPlayer, info, null, ent, victim);
|
action(jPlayer, info, null, ent, victim);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void action(JobsPlayer jPlayer, ActionInfo info, Block block, Entity ent, LivingEntity victim) {
|
public static void action(JobsPlayer jPlayer, ActionInfo info, Block block, Entity ent, LivingEntity victim) {
|
||||||
|
|
||||||
if (jPlayer == null)
|
if (jPlayer == null)
|
||||||
|
@ -1,98 +1,99 @@
|
|||||||
package com.gamingmesh.jobs.commands.list;
|
package com.gamingmesh.jobs.commands.list;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.commands.Cmd;
|
import com.gamingmesh.jobs.commands.Cmd;
|
||||||
import com.gamingmesh.jobs.commands.JobCommand;
|
import com.gamingmesh.jobs.commands.JobCommand;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
import com.gamingmesh.jobs.container.Log;
|
import com.gamingmesh.jobs.container.Log;
|
||||||
import com.gamingmesh.jobs.container.LogAmounts;
|
import com.gamingmesh.jobs.container.LogAmounts;
|
||||||
import com.gamingmesh.jobs.container.PlayerInfo;
|
import com.gamingmesh.jobs.container.PlayerInfo;
|
||||||
import com.gamingmesh.jobs.stuff.Sorting;
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
import com.gamingmesh.jobs.stuff.TimeManage;
|
import com.gamingmesh.jobs.stuff.Sorting;
|
||||||
|
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||||
public class glog implements Cmd {
|
|
||||||
|
public class glog implements Cmd {
|
||||||
@Override
|
|
||||||
@JobCommand(1200)
|
@Override
|
||||||
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
@JobCommand(1200)
|
||||||
if (args.length != 0) {
|
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
||||||
Jobs.getCommandManager().sendUsage(sender, "glog");
|
if (args.length != 0) {
|
||||||
return true;
|
Jobs.getCommandManager().sendUsage(sender, "glog");
|
||||||
}
|
return true;
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
}
|
||||||
@Override
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
Map<LogAmounts, Double> unsortMap = new HashMap<LogAmounts, Double>();
|
public void run() {
|
||||||
|
Map<LogAmounts, Double> unsortMap = new HashMap<LogAmounts, Double>();
|
||||||
int time = TimeManage.timeInInt();
|
|
||||||
|
int time = TimeManage.timeInInt();
|
||||||
for (Integer OneP : Jobs.getJobsDAO().getLognameList(time, time)) {
|
|
||||||
|
for (Integer OneP : Jobs.getJobsDAO().getLognameList(time, time)) {
|
||||||
Entry<String, PlayerInfo> info = Jobs.getPlayerManager().getPlayerInfoById(OneP);
|
|
||||||
|
Entry<String, PlayerInfo> info = Jobs.getPlayerManager().getPlayerInfoById(OneP);
|
||||||
if (info == null)
|
|
||||||
continue;
|
if (info == null)
|
||||||
|
continue;
|
||||||
String name = info.getValue().getName();
|
|
||||||
|
String name = info.getValue().getName();
|
||||||
if (name == null)
|
|
||||||
continue;
|
if (name == null)
|
||||||
|
continue;
|
||||||
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(name);
|
|
||||||
|
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(name);
|
||||||
if (JPlayer == null)
|
|
||||||
continue;
|
if (JPlayer == null)
|
||||||
List<Log> logList = JPlayer.getLog();
|
continue;
|
||||||
if (logList.size() == 0)
|
List<Log> logList = JPlayer.getLog();
|
||||||
continue;
|
if (logList.size() == 0)
|
||||||
|
continue;
|
||||||
for (Log one : logList) {
|
|
||||||
HashMap<String, LogAmounts> AmountList = one.getAmountList();
|
for (Log one : logList) {
|
||||||
for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) {
|
HashMap<String, LogAmounts> AmountList = one.getAmountList();
|
||||||
oneMap.getValue().setUsername(name);
|
for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) {
|
||||||
oneMap.getValue().setAction(one.getActionType());
|
oneMap.getValue().setUsername(name);
|
||||||
unsortMap.put(oneMap.getValue(), oneMap.getValue().getMoney());
|
oneMap.getValue().setAction(one.getActionType());
|
||||||
}
|
unsortMap.put(oneMap.getValue(), oneMap.getValue().getMoney());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
unsortMap = Sorting.sortDoubleDESCByLog(unsortMap);
|
|
||||||
|
unsortMap = Sorting.sortDoubleDESCByLog(unsortMap);
|
||||||
int count = 1;
|
|
||||||
int max = 10;
|
int count = 1;
|
||||||
|
int max = 10;
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.topline"));
|
|
||||||
for (Entry<LogAmounts, Double> one : unsortMap.entrySet()) {
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.topline"));
|
||||||
LogAmounts info = one.getKey();
|
for (Entry<LogAmounts, Double> one : unsortMap.entrySet()) {
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.list",
|
LogAmounts info = one.getKey();
|
||||||
"%username%", one.getKey().getUsername(),
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.list",
|
||||||
"%number%", count,
|
"%username%", one.getKey().getUsername(),
|
||||||
"%action%", info.getAction(),
|
"%number%", count,
|
||||||
"%item%", one.getKey().getItemName().replace(":0", "").replace("_", " ").toLowerCase(),
|
"%action%", info.getAction(),
|
||||||
"%qty%", one.getKey().getCount(),
|
"%item%", one.getKey().getItemName().replace(":0", "").replace("_", " ").toLowerCase(),
|
||||||
"%money%", one.getKey().getMoney(),
|
"%qty%", one.getKey().getCount(),
|
||||||
"%exp%", one.getKey().getExp()));
|
"%money%", one.getKey().getMoney(),
|
||||||
count++;
|
"%exp%", one.getKey().getExp()));
|
||||||
|
count++;
|
||||||
if (count > max)
|
|
||||||
break;
|
if (count > max)
|
||||||
}
|
break;
|
||||||
if (unsortMap.size() == 0) {
|
}
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.nodata"));
|
if (unsortMap.size() == 0) {
|
||||||
}
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.nodata"));
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.bottomline"));
|
}
|
||||||
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.bottomline"));
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
return true;
|
});
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -69,7 +69,7 @@ public class JobsPlayer {
|
|||||||
// log
|
// log
|
||||||
private List<Log> logList = new ArrayList<Log>();
|
private List<Log> logList = new ArrayList<Log>();
|
||||||
|
|
||||||
private Long seen;
|
private Long seen = System.currentTimeMillis();
|
||||||
|
|
||||||
public JobsPlayer(String userName, OfflinePlayer player) {
|
public JobsPlayer(String userName, OfflinePlayer player) {
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
@ -309,6 +309,10 @@ public class JobsPlayer {
|
|||||||
* @return the userName
|
* @return the userName
|
||||||
*/
|
*/
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
|
if (userName == null && player != null)
|
||||||
|
userName = player.getName();
|
||||||
|
if (userName == null && OffPlayer != null)
|
||||||
|
userName = OffPlayer.getName();
|
||||||
return userName;
|
return userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,7 +521,7 @@ public abstract class JobsDAO {
|
|||||||
insert.setInt(1, oneUser.getValue().getUserId());
|
insert.setInt(1, oneUser.getValue().getUserId());
|
||||||
insert.setString(2, oneUser.getValue().getPlayerUUID().toString());
|
insert.setString(2, oneUser.getValue().getPlayerUUID().toString());
|
||||||
insert.setString(3, oneUser.getValue().getUserName());
|
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.addBatch();
|
||||||
}
|
}
|
||||||
insert.executeBatch();
|
insert.executeBatch();
|
||||||
|
Loading…
Reference in New Issue
Block a user