From 02d6b5e0c22a12d771ad4ea579e17664324dc42b Mon Sep 17 00:00:00 2001 From: Zrips Date: Thu, 17 Sep 2015 18:28:23 +0300 Subject: [PATCH] Added jobs action logging Small improvements Small change for getting players permissions --- com/gamingmesh/jobs/Jobs.java | 10 +- com/gamingmesh/jobs/JobsPlugin.java | 99 ++++++++++--------- com/gamingmesh/jobs/PlayerManager.java | 11 ++- .../jobs/commands/JobsCommands.java | 70 +++++++++---- .../jobs/config/JobsConfiguration.java | 26 +++++ com/gamingmesh/jobs/container/TopList.java | 61 ++++++------ com/gamingmesh/jobs/dao/JobsDAO.java | 31 ++++++ com/gamingmesh/jobs/dao/JobsDAOMySQL.java | 9 +- com/gamingmesh/jobs/dao/JobsDAOSQLite.java | 9 +- .../jobs/economy/BufferedEconomy.java | 6 +- .../jobs/listeners/JobsListener.java | 14 +-- com/gamingmesh/jobs/stuff/.gitignore | 2 + com/gamingmesh/jobs/stuff/Loging.java | 14 --- .../jobs/stuff/OfflinePlayerList.java | 56 +++++++++++ plugin.yml | 13 ++- 15 files changed, 290 insertions(+), 141 deletions(-) create mode 100644 com/gamingmesh/jobs/stuff/OfflinePlayerList.java diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index cc66ab7a..97206666 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -39,7 +39,6 @@ import com.gamingmesh.jobs.container.Job; 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.dao.JobsDAO; import com.gamingmesh.jobs.economy.BufferedEconomy; import com.gamingmesh.jobs.economy.Economy; @@ -382,9 +381,6 @@ public class Jobs { } else { PaymentData data = ExpLimit.get(playername); if (data.IsReachedExpLimit(ConfigManager.getJobsConfiguration().EconomyExpTimeLimit, ConfigManager.getJobsConfiguration().EconomyExpLimit)) { - - Debug.D("exp limit reached"); - if (player.isOnline() && !data.Informed && !data.isReseted()) { ((Player) player).sendMessage(Language.getMessage("command.limit.output.reachedExplimit")); ((Player) player).sendMessage(Language.getMessage("command.limit.output.reachedExplimit2")); @@ -445,6 +441,8 @@ public class Jobs { Jobs.getEconomy().pay(jPlayer, amount, 0.0); + if (ConfigManager.getJobsConfiguration().LoggingUse) + Loging.recordToLog(jPlayer, info, amount, 0); } } } else { @@ -564,11 +562,11 @@ public class Jobs { Jobs.getEconomy().pay(jPlayer, amount, expAmount); int oldLevel = prog.getLevel(); - Loging.recordToLog(jPlayer, info, amount, expAmount); + if (ConfigManager.getJobsConfiguration().LoggingUse) + Loging.recordToLog(jPlayer, info, amount, expAmount); if (prog.addExperience(expAmount)) Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); - } } } diff --git a/com/gamingmesh/jobs/JobsPlugin.java b/com/gamingmesh/jobs/JobsPlugin.java index 67f26768..db9e9365 100644 --- a/com/gamingmesh/jobs/JobsPlugin.java +++ b/com/gamingmesh/jobs/JobsPlugin.java @@ -37,6 +37,7 @@ import com.gamingmesh.jobs.listeners.JobsListener; import com.gamingmesh.jobs.listeners.JobsPaymentListener; import com.gamingmesh.jobs.listeners.McMMOlistener; import com.gamingmesh.jobs.listeners.PistonProtectionListener; +import com.gamingmesh.jobs.stuff.OfflinePlayerList; import com.gamingmesh.jobs.stuff.ScheduleUtil; import com.gamingmesh.jobs.stuff.TabComplete; import com.gamingmesh.jobs.config.YmlMaker; @@ -47,66 +48,66 @@ public class JobsPlugin extends JavaPlugin { public static boolean CPPresent = false; @Override - public void onEnable() { - instance = this; - YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml"); - jobConfig.saveDefaultConfig(); - - YmlMaker jobSigns = new YmlMaker(this, "Signs.yml"); - jobSigns.saveDefaultConfig(); - - YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml"); - jobSchedule.saveDefaultConfig(); - - Jobs.setPermissionHandler(new PermissionHandler(this)); + public void onEnable() { + instance = this; + OfflinePlayerList.fillList(); + YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml"); + jobConfig.saveDefaultConfig(); - Jobs.setPluginLogger(getLogger()); + YmlMaker jobSigns = new YmlMaker(this, "Signs.yml"); + jobSigns.saveDefaultConfig(); - Jobs.setDataFolder(getDataFolder()); + YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml"); + jobSchedule.saveDefaultConfig(); - ConfigManager.registerJobsConfiguration(new JobsConfiguration(this)); - ConfigManager.registerJobConfig(new JobConfig(this)); + Jobs.setPermissionHandler(new PermissionHandler(this)); - getCommand("jobs").setExecutor(new JobsCommands()); + Jobs.setPluginLogger(getLogger()); - this.getCommand("jobs").setTabCompleter(new TabComplete()); + Jobs.setDataFolder(getDataFolder()); - try { - Jobs.startup(); - } catch (IOException e) { - e.printStackTrace(); - } + ConfigManager.registerJobsConfiguration(new JobsConfiguration(this)); + ConfigManager.registerJobConfig(new JobConfig(this)); - // register the listeners - getServer().getPluginManager().registerEvents(new JobsListener(this), this); - getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this); + getCommand("jobs").setExecutor(new JobsCommands()); - if (McMMOlistener.CheckmcMMO()) - getServer().getPluginManager().registerEvents(new McMMOlistener(this), this); + this.getCommand("jobs").setTabCompleter(new TabComplete()); - if (ConfigManager.getJobsConfiguration().useBlockProtection) - getServer().getPluginManager().registerEvents(new PistonProtectionListener(this), this); - - // register economy - Bukkit.getScheduler().runTask(this, new HookEconomyTask(this)); - - if (getServer().getPluginManager().getPlugin("CoreProtect") != null) { - CPPresent = true; - CPAPI = ((CoreProtect) getServer().getPluginManager().getPlugin("CoreProtect")).getAPI(); - } - - // all loaded properly. - - - if (ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) - ScheduleUtil.scheduler(); - ScheduleUtil.DateUpdater(); - - String message = ChatColor.translateAlternateColorCodes('&', "&2Plugin has been enabled succesfully."); - ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); - console.sendMessage(message); + try { + Jobs.startup(); + } catch (IOException e) { + e.printStackTrace(); } + // register the listeners + getServer().getPluginManager().registerEvents(new JobsListener(this), this); + getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this); + + if (McMMOlistener.CheckmcMMO()) + getServer().getPluginManager().registerEvents(new McMMOlistener(this), this); + + if (ConfigManager.getJobsConfiguration().useBlockProtection) + getServer().getPluginManager().registerEvents(new PistonProtectionListener(this), this); + + // register economy + Bukkit.getScheduler().runTask(this, new HookEconomyTask(this)); + + if (getServer().getPluginManager().getPlugin("CoreProtect") != null) { + CPPresent = true; + CPAPI = ((CoreProtect) getServer().getPluginManager().getPlugin("CoreProtect")).getAPI(); + } + + // all loaded properly. + + if (ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) + ScheduleUtil.scheduler(); + ScheduleUtil.DateUpdater(); + + String message = ChatColor.translateAlternateColorCodes('&', "&2Plugin has been enabled succesfully."); + ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); + console.sendMessage(message); + } + @Override public void onDisable() { Jobs.shutdown(); diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index dc010302..d30faf65 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -46,6 +46,8 @@ import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.PerformCommands; +import net.milkbowl.vault.Vault; + public class PlayerManager { private Map players = Collections.synchronizedMap(new HashMap()); //private Map players = new HashMap(); @@ -153,7 +155,9 @@ public class PlayerManager { if (jPlayer != null) return jPlayer; - return JobsPlayer.loadFromDao(Jobs.getJobsDAO(), offlinePlayer); + JobsPlayer player = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), offlinePlayer); + JobsPlayer.loadLogFromDao(player); + return player; } /** @@ -525,7 +529,7 @@ public class PlayerManager { return true; short count = (short) ConfigManager.getJobsConfiguration().getMaxJobs(); - for (short ctr = 0; ctr < 255; ctr++) { + for (short ctr = 0; ctr < 30; ctr++) { if (Perm(player, "jobs.max." + ctr)) count = ctr; if (count > currentCount) @@ -535,8 +539,7 @@ public class PlayerManager { } private boolean Perm(Player player, String permission) { - Permission p = new Permission(permission, PermissionDefault.FALSE); - return player.hasPermission(p); + return player.isPermissionSet(permission); } /** diff --git a/com/gamingmesh/jobs/commands/JobsCommands.java b/com/gamingmesh/jobs/commands/JobsCommands.java index 59e61f8d..cfc8af09 100644 --- a/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/com/gamingmesh/jobs/commands/JobsCommands.java @@ -61,9 +61,11 @@ import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.GiveItem; +import com.gamingmesh.jobs.stuff.OfflinePlayerList; import com.gamingmesh.jobs.stuff.Perm; import com.gamingmesh.jobs.stuff.Scboard; import com.gamingmesh.jobs.stuff.Sorting; +import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.TranslateName; public class JobsCommands implements CommandExecutor { @@ -364,9 +366,12 @@ public class JobsCommands implements CommandExecutor { sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.permission")); return true; } - @SuppressWarnings("deprecation") - OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]); - jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer); +// @SuppressWarnings("deprecation") +// OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]); + + OfflinePlayer offlinePlayer = OfflinePlayerList.getPlayer(args[0]); + if (offlinePlayer != null) + jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer); } else if (sender instanceof Player) { jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); } @@ -1368,13 +1373,22 @@ public class JobsCommands implements CommandExecutor { return true; } JobsPlayer JPlayer = null; - if (args.length == 1) - JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); if (args.length == 0) - JPlayer = Jobs.getPlayerManager().getJobsPlayer(sender.getName()); + JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + else if (args.length == 1 ) { + if (!sender.hasPermission("jobs.commands.log.others")){ + sender.sendMessage(Language.getMessage("command.error.permission")); + return true; + } + JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); + if (JPlayer == null) + JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(OfflinePlayerList.getPlayer(args[0])); + } - if (JPlayer == null) + if (JPlayer == null) { + sendUsage(sender, "log"); return true; + } List logList = JPlayer.getLog(); @@ -1393,15 +1407,20 @@ public class JobsCommands implements CommandExecutor { unsortMap = Sorting.sortDoubleDESC(unsortMap); int count = 0; int max = 10; - sender.sendMessage("******************* " + JPlayer.getUserName() + " *******************"); + sender.sendMessage(Language.getMessage("command.log.output.topline").replace("%playername%", JPlayer.getUserName())); for (Log one : logList) { HashMap AmountList = one.getAmountList(); for (Entry oneSorted : unsortMap.entrySet()) { for (Entry oneMap : AmountList.entrySet()) { if (oneMap.getKey().equalsIgnoreCase(oneSorted.getKey())) { count++; - String msg = "&6" + count + ". &e" + one.getActionType() + ": &6" + oneMap.getValue().getItemName() + " &ecount: &6" + oneMap.getValue() - .getCount() + " &emoney: &6" + oneMap.getValue().getMoney() + " &eexp: &6" + oneMap.getValue().getExp(); + String msg = Language.getMessage("command.log.output.list") + .replace("%number%", String.valueOf(count)) + .replace("%action%", one.getActionType()) + .replace("%item%", oneMap.getValue().getItemName().replace(":0", "").toLowerCase()) + .replace("%qty%", String.valueOf(oneMap.getValue().getCount())) + .replace("%money%", String.valueOf(oneMap.getValue().getMoney())) + .replace("%exp%", String.valueOf(oneMap.getValue().getExp())); msg = org.bukkit.ChatColor.translateAlternateColorCodes('&', msg); sender.sendMessage(msg); break; @@ -1413,7 +1432,7 @@ public class JobsCommands implements CommandExecutor { if (count > max) break; } - sender.sendMessage("***********************************************"); + sender.sendMessage(Language.getMessage("command.log.output.bottomline")); return true; } @@ -1429,12 +1448,15 @@ public class JobsCommands implements CommandExecutor { public void run() { Map unsortMap = new HashMap(); - Collection onlineP = Bukkit.getOnlinePlayers(); - - sender.sendMessage("Looking for players data"); - for (Player OneP : onlineP) { + int time = TimeManage.timeInInt(); + for (String OneP : Jobs.getJobsDAO().getLognameList(time, time)) { JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(OneP); + if (JPlayer == null) { + OfflinePlayer offp = OfflinePlayerList.getPlayer(OneP); + if (offp != null) + JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(OfflinePlayerList.getPlayer(OneP)); + } if (JPlayer == null) continue; List logList = JPlayer.getLog(); @@ -1444,7 +1466,7 @@ public class JobsCommands implements CommandExecutor { for (Log one : logList) { HashMap AmountList = one.getAmountList(); for (Entry oneMap : AmountList.entrySet()) { - oneMap.getValue().setUsername(OneP.getName()); + oneMap.getValue().setUsername(OneP); oneMap.getValue().setAction(one.getActionType()); unsortMap.put(oneMap.getValue(), oneMap.getValue().getMoney()); } @@ -1453,14 +1475,21 @@ public class JobsCommands implements CommandExecutor { unsortMap = Sorting.sortDoubleDESCByLog(unsortMap); - int count = 0; + int count = 1; int max = 10; + sender.sendMessage(Language.getMessage("command.glog.output.topline")); for (Entry one : unsortMap.entrySet()) { LogAmounts info = one.getKey(); - String msg = "&3" + info.getUsername() + " &e" + info.getAction() + ": &6" + (info.getItemName().toString().contains(":0") ? info.getItemName() - .toString().replace(":0", "") : info.getItemName()) + " &ecount: &6" + info.getCount() + " &emoney: &6" + info.getMoney() + " &eexp: &6" + info - .getExp(); + + String msg = Language.getMessage("command.glog.output.list") + .replace("%username%", one.getKey().getUsername()) + .replace("%number%", String.valueOf(count)) + .replace("%action%", info.getAction()) + .replace("%item%", one.getKey().getItemName().replace(":0", "").toLowerCase()) + .replace("%qty%", String.valueOf(one.getKey().getCount())) + .replace("%money%", String.valueOf(one.getKey().getMoney())) + .replace("%exp%", String.valueOf(one.getKey().getExp())); msg = org.bukkit.ChatColor.translateAlternateColorCodes('&', msg); sender.sendMessage(msg); count++; @@ -1471,6 +1500,7 @@ public class JobsCommands implements CommandExecutor { if (unsortMap.size() == 0) { sender.sendMessage("No data found"); } + sender.sendMessage(Language.getMessage("command.glog.output.bottomline")); return; } diff --git a/com/gamingmesh/jobs/config/JobsConfiguration.java b/com/gamingmesh/jobs/config/JobsConfiguration.java index e6a2dfa4..23f8d306 100644 --- a/com/gamingmesh/jobs/config/JobsConfiguration.java +++ b/com/gamingmesh/jobs/config/JobsConfiguration.java @@ -69,6 +69,8 @@ public class JobsConfiguration { protected boolean modifyChat; protected int economyBatchDelay; protected boolean saveOnDisconnect; + public boolean LocalOfflinePlayersData; + public boolean LoggingUse; public boolean EconomyLimitUse, EconomyExpLimitUse, PayForRenaming, PayForEachCraft, SignsEnabled, SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse, EnableAnounceMessage, useBlockPiston, useSilkTouchProtection, UseCustomNames, EconomyMoneyStop, @@ -369,6 +371,16 @@ public class JobsConfiguration { "Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance."); saveOnDisconnect = getBoolean("save-on-disconnect", false, config, writer); + writer.addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files", + "This will eliminate small lag spikes when request is being send to mojangs servers for offline players data", + "Theroticali this should work without issues, but if you havving some, just disable", + "But then you can feal some small (100-200ms) lag spikes while performings some jobs commands"); + LocalOfflinePlayersData = getBoolean("Optimizations.UseLocalOfflinePlayersData", true, config, writer); + + writer.addComment("Logging.Use", "With this set to true all players jobs actions will be logged to database for easy to see statistics", + "This is still in development and in feature it will expand"); + LoggingUse = getBoolean("Logging.Use", false, config, writer); + writer.addComment("broadcast.on-skill-up.use", "Do all players get a message when somone goes up a skill level?"); isBroadcastingSkillups = getBoolean("broadcast.on-skill-up.use", false, config, writer); @@ -1289,6 +1301,20 @@ public class JobsConfiguration { GetConfigString("command.gtop.output.next", "&2|&e Next Page >>>>", writer, conf, true); GetConfigString("command.gtop.output.show", "&2Show from &e[from] &2until &e[until] &2global top list", writer, conf, true); + GetConfigString("command.log.help.info", "Shows statistics.", writer, conf, true); + GetConfigString("command.log.help.args", "[playername]", writer, conf, true); + GetConfigString("command.log.output.topline", "&7************************* &6%playername% &7*************************", writer, conf, true); + GetConfigString("command.log.output.list", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% &6money: %money% &eexp: %exp%", writer, conf, true); + GetConfigString("command.log.output.bottomline", "&7***********************************************************", writer, conf, true); + GetConfigString("command.log.output.prev", "&e<<<<< Prev page &2|", writer, conf, true); + GetConfigString("command.log.output.next", "&2|&e Next Page >>>>", writer, conf, true); + + GetConfigString("command.glog.help.info", "Shows global statistics.", writer, conf, true); + GetConfigString("command.glog.help.args", "", writer, conf, true); + GetConfigString("command.glog.output.topline", "&7*********************** &6Global statistics &7***********************", writer, conf, true); + GetConfigString("command.glog.output.list", "&7* &6%number%. &3%username% &e%action%: &6%item% &eqty: %qty% &6money: %money% &eexp: %exp%", writer, conf, true); + GetConfigString("command.glog.output.bottomline", "&7**************************************************************", writer, conf, true); + GetConfigString("command.transfer.help.info", "Transfer a player's job from an old job to a new job.", writer, conf, true); GetConfigString("command.transfer.help.args", "[playername] [oldjob] [newjob]", writer, conf, true); GetConfigString("command.transfer.output.target", "You have been transferred from %oldjobname% to %newjobname%.", writer, conf, true); diff --git a/com/gamingmesh/jobs/container/TopList.java b/com/gamingmesh/jobs/container/TopList.java index b365b5a8..15236ddb 100644 --- a/com/gamingmesh/jobs/container/TopList.java +++ b/com/gamingmesh/jobs/container/TopList.java @@ -4,42 +4,43 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import com.gamingmesh.jobs.stuff.OfflinePlayerList; import com.gamingmesh.jobs.stuff.UUIDUtil; public final class TopList { - private String player; - private int level; - private int exp; - private byte[] uuid; + private String player; + private int level; + private int exp; + private byte[] uuid; - public TopList(String player, int level, int exp, byte[] uuid) { - this.player = player; - this.level = level; - this.exp = exp; - this.uuid = uuid; - } + public TopList(String player, int level, int exp, byte[] uuid) { + this.player = player; + this.level = level; + this.exp = exp; + this.uuid = uuid; + } - public String getPlayerName() { - if (this.player == null || this.player == "") { - Player player = Bukkit.getPlayer(UUIDUtil.fromBytes(this.uuid)); - if (player != null) - return player.getName(); - else { - OfflinePlayer Offlineplayer = Bukkit.getOfflinePlayer(UUIDUtil.fromBytes(this.uuid)); - if (Offlineplayer != null) - return Offlineplayer.getName(); - else - return "Unknown"; - } - } - return this.player; + public String getPlayerName() { + if (this.player == null || this.player == "") { + Player player = Bukkit.getPlayer(UUIDUtil.fromBytes(this.uuid)); + if (player != null) + return player.getName(); + else { + OfflinePlayer Offlineplayer = OfflinePlayerList.getPlayer(UUIDUtil.fromBytes(this.uuid)); + if (Offlineplayer != null) + return Offlineplayer.getName(); + else + return "Unknown"; + } } + return this.player; + } - public int getLevel() { - return this.level; - } + public int getLevel() { + return this.level; + } - public int getExp() { - return this.exp; - } + public int getExp() { + return this.exp; + } } \ No newline at end of file diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index cc0d1dbc..e53a3295 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -587,12 +587,43 @@ public abstract class JobsDAO { while (res.next()) { Loging.loadToLog(player, res.getString("action"), res.getString("itemname"), res.getInt("count"), res.getDouble("money"), res.getDouble("exp")); } + res.close(); prest.close(); } catch (SQLException e) { e.printStackTrace(); } } + /** + * Save player-job information + * @param jobInfo - the information getting saved + * @return + */ + public List getLognameList(int fromtime, int untiltime) { + JobsConnection conn = getConnection(); + if (conn == null) + return null; + try { + List nameList = new ArrayList(); + + PreparedStatement prest = conn.prepareStatement("SELECT `username` FROM `" + prefix + + "log` WHERE `time` >= ? AND `time` <= ? ;"); + prest.setInt(1, fromtime); + prest.setInt(2, untiltime); + ResultSet res = prest.executeQuery(); + while (res.next()) { + if (!nameList.contains(res.getString("username"))) + nameList.add(res.getString("username")); + } + res.close(); + prest.close(); + return nameList; + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + /** * Show top list * @param toplist - toplist by jobs name diff --git a/com/gamingmesh/jobs/dao/JobsDAOMySQL.java b/com/gamingmesh/jobs/dao/JobsDAOMySQL.java index e45bb4be..db764793 100644 --- a/com/gamingmesh/jobs/dao/JobsDAOMySQL.java +++ b/com/gamingmesh/jobs/dao/JobsDAOMySQL.java @@ -25,9 +25,11 @@ import java.util.ArrayList; import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.OfflinePlayerList; import com.gamingmesh.jobs.stuff.UUIDUtil; public class JobsDAOMySQL extends JobsDAO { @@ -186,7 +188,12 @@ public class JobsDAOMySQL extends JobsDAO { Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "" + y + " of " + usernames.size()); i = 0; } - pst2.setBytes(1, UUIDUtil.toBytes(UUID.fromString(Bukkit.getOfflinePlayer(names).getUniqueId().toString()))); + + OfflinePlayer offPlayer = OfflinePlayerList.getPlayer(names); + if (offPlayer == null) + continue; + + pst2.setBytes(1, UUIDUtil.toBytes(offPlayer.getUniqueId())); pst2.setString(2, names); pst2.execute(); } diff --git a/com/gamingmesh/jobs/dao/JobsDAOSQLite.java b/com/gamingmesh/jobs/dao/JobsDAOSQLite.java index 4f577557..481243bf 100644 --- a/com/gamingmesh/jobs/dao/JobsDAOSQLite.java +++ b/com/gamingmesh/jobs/dao/JobsDAOSQLite.java @@ -26,9 +26,11 @@ import java.util.ArrayList; import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.OfflinePlayerList; import com.gamingmesh.jobs.stuff.UUIDUtil; public class JobsDAOSQLite extends JobsDAO { @@ -152,7 +154,12 @@ public class JobsDAOSQLite extends JobsDAO { Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "" + y + " of " + usernames.size()); i = 0; } - pst2.setBytes(1, UUIDUtil.toBytes(UUID.fromString(Bukkit.getOfflinePlayer(names).getUniqueId().toString()))); + + OfflinePlayer offPlayer = OfflinePlayerList.getPlayer(names); + if (offPlayer == null) + continue; + + pst2.setBytes(1, UUIDUtil.toBytes(offPlayer.getUniqueId())); pst2.setString(2, names); pst2.execute(); } diff --git a/com/gamingmesh/jobs/economy/BufferedEconomy.java b/com/gamingmesh/jobs/economy/BufferedEconomy.java index 6ce45a90..8076c064 100644 --- a/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -36,6 +36,7 @@ import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.OfflinePlayerList; import com.gamingmesh.jobs.tasks.BufferedPaymentTask; public class BufferedEconomy { @@ -80,7 +81,6 @@ public class BufferedEconomy { /** * Payout all players the amount they are going to be paid */ - @SuppressWarnings("deprecation") public void payAll() { if (payments.isEmpty()) return; @@ -128,10 +128,10 @@ public class BufferedEconomy { String ServerAccountname = ConfigManager.getJobsConfiguration().ServerAcountName; String ServerTaxesAccountname = ConfigManager.getJobsConfiguration().ServertaxesAcountName; if (this.ServerAccount == null) - this.ServerAccount = Bukkit.getOfflinePlayer(ServerAccountname); + this.ServerAccount = OfflinePlayerList.getPlayer(ServerAccountname); if (this.ServerTaxesAccount == null) - this.ServerTaxesAccount = Bukkit.getOfflinePlayer(ServerAccountname); + this.ServerTaxesAccount = OfflinePlayerList.getPlayer(ServerAccountname); if (ConfigManager.getJobsConfiguration().UseTaxes && ConfigManager.getJobsConfiguration().TransferToServerAccount && ServerTaxesAccount != null) { diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java index 14a81346..b2eaf47d 100644 --- a/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/com/gamingmesh/jobs/listeners/JobsListener.java @@ -51,6 +51,7 @@ import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.i18n.Language; +import com.gamingmesh.jobs.stuff.OfflinePlayerList; public class JobsListener implements Listener { // hook to the main plugin @@ -185,6 +186,7 @@ public class JobsListener implements Listener { if (!plugin.isEnabled()) return; Jobs.getPlayerManager().playerQuit(event.getPlayer()); + OfflinePlayerList.addPlayer(event.getPlayer()); } @EventHandler(priority = EventPriority.MONITOR) @@ -205,15 +207,9 @@ public class JobsListener implements Listener { if (!ConfigManager.getJobsConfiguration().SignsEnabled) return; - Player player = (Player) event.getPlayer(); if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - Material material = event.getClickedBlock().getType(); - - if (material != Material.WALL_SIGN && material != Material.SIGN && material != Material.SIGN_POST) - return; - Block block = event.getClickedBlock(); if (block == null) @@ -237,6 +233,7 @@ public class JobsListener implements Listener { } } + Player player = (Player) event.getPlayer(); Bukkit.dispatchCommand(player, "jobs " + command + " " + ChatColor.stripColor(sign.getLine(2)) + " " + ChatColor.stripColor(sign.getLine(3))); } @@ -249,11 +246,6 @@ public class JobsListener implements Listener { if (!ConfigManager.getJobsConfiguration().SignsEnabled) return; - Material material = event.getBlock().getType(); - - if (material != Material.WALL_SIGN && material != Material.SIGN && material != Material.SIGN_POST) - return; - Block block = event.getBlock(); if (block == null) diff --git a/com/gamingmesh/jobs/stuff/.gitignore b/com/gamingmesh/jobs/stuff/.gitignore index de4e3e19..f1f0a3cc 100644 --- a/com/gamingmesh/jobs/stuff/.gitignore +++ b/com/gamingmesh/jobs/stuff/.gitignore @@ -26,3 +26,5 @@ /TimeManage.class /Loging.class /ScheduleUtil$2.class +/OfflinePlayerList.class +/OfflinePlayerList$1.class diff --git a/com/gamingmesh/jobs/stuff/Loging.java b/com/gamingmesh/jobs/stuff/Loging.java index 5b1dcf78..244a4420 100644 --- a/com/gamingmesh/jobs/stuff/Loging.java +++ b/com/gamingmesh/jobs/stuff/Loging.java @@ -19,9 +19,7 @@ public class Loging { if (jPlayer.getLog().size() > 0 && ScheduleUtil.dateByInt != jPlayer.getLog().get(0).getDate()) { ScheduleUtil.dateByInt = TimeManage.timeInInt(); - Debug.D("1 Not equals " + ScheduleUtil.dateByInt + " " + jPlayer.getLog().get(0).getDate()); if (ScheduleUtil.dateByInt != jPlayer.getLog().get(0).getDate()) { - Debug.D("Not equals " + ScheduleUtil.dateByInt + " " + jPlayer.getLog().get(0).getDate()); Jobs.getJobsDAO().saveLog(jPlayer); jPlayer.getLog().clear(); } @@ -30,19 +28,13 @@ public class Loging { for (Log one : logList) { if (!one.getActionType().equalsIgnoreCase(ActionName)) continue; - one.add(item, amount, expAmount); - found = true; - - Debug.D(item + " : " + one.getCount(item) + " money: " + one.getMoney(item) + " exp:" + one.getExp(item)); } if (!found) { Log log = new Log(ActionName); log.add(item, amount, expAmount); logList.add(log); - String msg = item + " : " + log.getCount(item) + " money: " + log.getMoney(item) + " exp:" + log.getExp(item); - Debug.D(msg); } } @@ -52,19 +44,13 @@ public class Loging { for (Log one : logList) { if (!one.getActionType().equalsIgnoreCase(ActionName)) continue; - one.add(item, count, money, expAmount); - found = true; - - Debug.D(item + " : " + one.getCount(item) + " money: " + one.getMoney(item) + " exp:" + one.getExp(item)); } if (!found) { Log log = new Log(ActionName); log.add(item, count, money, expAmount); logList.add(log); - String msg = item + " : " + log.getCount(item) + " money: " + log.getMoney(item) + " exp:" + log.getExp(item); - Debug.D(msg); } } } diff --git a/com/gamingmesh/jobs/stuff/OfflinePlayerList.java b/com/gamingmesh/jobs/stuff/OfflinePlayerList.java new file mode 100644 index 00000000..c169501e --- /dev/null +++ b/com/gamingmesh/jobs/stuff/OfflinePlayerList.java @@ -0,0 +1,56 @@ +package com.gamingmesh.jobs.stuff; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; + +import com.gamingmesh.jobs.JobsPlugin; +import com.gamingmesh.jobs.config.ConfigManager; + +public class OfflinePlayerList { + + private static HashMap map = new HashMap(); + private static HashMap uuidmap = new HashMap(); + + public static void fillList() { + Bukkit.getScheduler().runTaskAsynchronously(JobsPlugin.instance, new Runnable() { + @Override + public void run() { + OfflinePlayer[] players = Bukkit.getOfflinePlayers(); + for (OfflinePlayer one : players) { + if (one == null) + continue; + map.put(one.getName().toLowerCase(), one); + uuidmap.put(one.getUniqueId(), one); + } + return; + } + }); + } + + public static OfflinePlayer getPlayer(UUID uuid) { + if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData) + return Bukkit.getOfflinePlayer(uuid); + + if (uuidmap.containsKey(uuid)) + return uuidmap.get(uuid); + return null; + } + + public static OfflinePlayer getPlayer(String name) { + if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData) + return Bukkit.getOfflinePlayer(name); + + if (map.containsKey(name.toLowerCase())) + return map.get(name.toLowerCase()); + return null; + } + + public static void addPlayer(OfflinePlayer player) { + map.put(player.getName().toLowerCase(), player); + uuidmap.put(player.getUniqueId(), player); + } + +} diff --git a/plugin.yml b/plugin.yml index a0751ae5..e2ea51bd 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: Jobs description: Jobs Plugin for the BukkitAPI main: com.gamingmesh.jobs.JobsPlugin -version: 2.50.1 +version: 2.51.0 author: phrstbrn softdepend: [Vault] commands: @@ -138,4 +138,13 @@ permissions: default: true jobs.command.limit: description: Grants access to the limit command - default: true \ No newline at end of file + default: true + jobs.command.log: + description: Grants access to the log command + default: true + jobs.command.log.others: + description: Grants access to the log command + default: op + jobs.command.glog: + description: Grants access to the glog command + default: op \ No newline at end of file