diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index 301a42dd..97efc04b 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -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,29 +463,37 @@ public class Jobs extends JavaPlugin { } catch (IOException e1) { e1.printStackTrace(); } - int i = 0; - int y = 0; - int total = Jobs.getPlayerManager().getPlayerMap().size(); - long time = System.currentTimeMillis(); - for (Entry 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 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 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(); @@ -770,15 +780,15 @@ public class Jobs extends JavaPlugin { public static void action(JobsPlayer jPlayer, ActionInfo info, Block block) { action(jPlayer, info, block, null, null); } - + public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent) { action(jPlayer, info, null, ent, null); } - + public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent, LivingEntity victim) { action(jPlayer, info, null, ent, victim); } - + public static void action(JobsPlayer jPlayer, ActionInfo info, Block block, Entity ent, LivingEntity victim) { if (jPlayer == null) diff --git a/com/gamingmesh/jobs/commands/list/glog.java b/com/gamingmesh/jobs/commands/list/glog.java index 7f7a6fd2..711d852e 100644 --- a/com/gamingmesh/jobs/commands/list/glog.java +++ b/com/gamingmesh/jobs/commands/list/glog.java @@ -1,98 +1,99 @@ -package com.gamingmesh.jobs.commands.list; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.commands.Cmd; -import com.gamingmesh.jobs.commands.JobCommand; -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.Sorting; -import com.gamingmesh.jobs.stuff.TimeManage; - -public class glog implements Cmd { - - @Override - @JobCommand(1200) - public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - if (args.length != 0) { - Jobs.getCommandManager().sendUsage(sender, "glog"); - return true; - } - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - Map unsortMap = new HashMap(); - - int time = TimeManage.timeInInt(); - - for (Integer OneP : Jobs.getJobsDAO().getLognameList(time, time)) { - - Entry info = Jobs.getPlayerManager().getPlayerInfoById(OneP); - - if (info == null) - continue; - - String name = info.getValue().getName(); - - if (name == null) - continue; - - JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(name); - - if (JPlayer == null) - continue; - List logList = JPlayer.getLog(); - if (logList.size() == 0) - continue; - - for (Log one : logList) { - HashMap AmountList = one.getAmountList(); - for (Entry oneMap : AmountList.entrySet()) { - oneMap.getValue().setUsername(name); - oneMap.getValue().setAction(one.getActionType()); - unsortMap.put(oneMap.getValue(), oneMap.getValue().getMoney()); - } - } - } - - unsortMap = Sorting.sortDoubleDESCByLog(unsortMap); - - int count = 1; - int max = 10; - - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.topline")); - for (Entry one : unsortMap.entrySet()) { - LogAmounts info = one.getKey(); - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.list", - "%username%", one.getKey().getUsername(), - "%number%", count, - "%action%", info.getAction(), - "%item%", one.getKey().getItemName().replace(":0", "").replace("_", " ").toLowerCase(), - "%qty%", one.getKey().getCount(), - "%money%", one.getKey().getMoney(), - "%exp%", one.getKey().getExp())); - count++; - - if (count > max) - break; - } - if (unsortMap.size() == 0) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.nodata")); - } - sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.bottomline")); - - return; - } - }); - return true; - } -} +package com.gamingmesh.jobs.commands.list; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.commands.JobCommand; +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; + +public class glog implements Cmd { + + @Override + @JobCommand(1200) + public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length != 0) { + Jobs.getCommandManager().sendUsage(sender, "glog"); + return true; + } + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override + public void run() { + Map unsortMap = new HashMap(); + + int time = TimeManage.timeInInt(); + + for (Integer OneP : Jobs.getJobsDAO().getLognameList(time, time)) { + + Entry info = Jobs.getPlayerManager().getPlayerInfoById(OneP); + + if (info == null) + continue; + + String name = info.getValue().getName(); + + if (name == null) + continue; + + JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(name); + + if (JPlayer == null) + continue; + List logList = JPlayer.getLog(); + if (logList.size() == 0) + continue; + + for (Log one : logList) { + HashMap AmountList = one.getAmountList(); + for (Entry oneMap : AmountList.entrySet()) { + oneMap.getValue().setUsername(name); + oneMap.getValue().setAction(one.getActionType()); + unsortMap.put(oneMap.getValue(), oneMap.getValue().getMoney()); + } + } + } + + unsortMap = Sorting.sortDoubleDESCByLog(unsortMap); + + int count = 1; + int max = 10; + + sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.topline")); + for (Entry one : unsortMap.entrySet()) { + LogAmounts info = one.getKey(); + sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.list", + "%username%", one.getKey().getUsername(), + "%number%", count, + "%action%", info.getAction(), + "%item%", one.getKey().getItemName().replace(":0", "").replace("_", " ").toLowerCase(), + "%qty%", one.getKey().getCount(), + "%money%", one.getKey().getMoney(), + "%exp%", one.getKey().getExp())); + count++; + + if (count > max) + break; + } + if (unsortMap.size() == 0) { + sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.nodata")); + } + sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.bottomline")); + + return; + } + }); + return true; + } +} diff --git a/com/gamingmesh/jobs/container/JobsPlayer.java b/com/gamingmesh/jobs/container/JobsPlayer.java index 746e2b55..e7a35c8e 100644 --- a/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/com/gamingmesh/jobs/container/JobsPlayer.java @@ -69,7 +69,7 @@ public class JobsPlayer { // log private List logList = new ArrayList(); - 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; } diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index 0742e91b..8705909a 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -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();