diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 7bfdd8ee..f61cd2c2 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -557,8 +557,7 @@ public class Jobs extends JavaPlugin { e.printStackTrace(); } } - - + dao.getMap().clear(); Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Preloaded " + Jobs.getPlayerManager().getPlayersCache().size() + " players data in " + ((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D)); @@ -946,8 +945,11 @@ public class Jobs extends JavaPlugin { Jobs.getEconomy().pay(jPlayer, income, pointAmount, 0.0); - if (GconfigManager.LoggingUse) - loging.recordToLog(jPlayer, info, income, 0); + if (GconfigManager.LoggingUse) { + HashMap amounts = new HashMap(); + amounts.put(CurrencyType.MONEY, income); + loging.recordToLog(jPlayer, info, amounts); + } } } else { @@ -1078,8 +1080,13 @@ public class Jobs extends JavaPlugin { economy.pay(jPlayer, income, pointAmount, expAmount); int oldLevel = prog.getLevel(); - if (GconfigManager.LoggingUse) - loging.recordToLog(jPlayer, info, income, expAmount); + if (GconfigManager.LoggingUse) { + HashMap amounts = new HashMap(); + amounts.put(CurrencyType.MONEY, income); + amounts.put(CurrencyType.EXP, expAmount); + amounts.put(CurrencyType.POINTS, pointAmount); + loging.recordToLog(jPlayer, info, amounts); + } if (prog.addExperience(expAmount)) pManager.performLevelUp(jPlayer, prog.getJob(), oldLevel); @@ -1099,10 +1106,10 @@ public class Jobs extends JavaPlugin { return true; if (info.getType() == ActionType.BREAK) { - if(block.hasMetadata("JobsExploit")){ - //player.sendMessage("This block is protected using Rukes' system!"); - return false; - } + if (block.hasMetadata("JobsExploit")) { + //player.sendMessage("This block is protected using Rukes' system!"); + return false; + } BlockProtection bp = getBpManager().getBp(block.getLocation()); if (bp != null) { Long time = bp.getTime(); @@ -1228,8 +1235,13 @@ public class Jobs extends JavaPlugin { int oldLevel = prog.getLevel(); - if (GconfigManager.LoggingUse) - loging.recordToLog(jPlayer, info, payment.getAmount(), payment.getExp()); + if (GconfigManager.LoggingUse) { + HashMap amounts = new HashMap(); + amounts.put(CurrencyType.MONEY, payment.getAmount()); + amounts.put(CurrencyType.EXP, payment.getExp()); + amounts.put(CurrencyType.POINTS, payment.getPoints()); + loging.recordToLog(jPlayer, info, amounts); + } if (prog.addExperience(payment.getExp())) pManager.performLevelUp(jPlayer, prog.getJob(), oldLevel); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/glog.java b/src/main/java/com/gamingmesh/jobs/commands/list/glog.java index 3aa94184..ad8d9e04 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/glog.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/glog.java @@ -1,7 +1,6 @@ package com.gamingmesh.jobs.commands.list; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -11,6 +10,7 @@ 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.CurrencyType; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Log; import com.gamingmesh.jobs.container.LogAmounts; @@ -60,7 +60,7 @@ public class glog implements Cmd { for (Entry oneMap : AmountList.entrySet()) { oneMap.getValue().setUsername(name); oneMap.getValue().setAction(one.getActionType()); - unsortMap.put(oneMap.getValue(), oneMap.getValue().getMoney()); + unsortMap.put(oneMap.getValue(), oneMap.getValue().get(CurrencyType.MONEY)); } } } @@ -73,14 +73,28 @@ public class glog implements Cmd { 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())); + String moneyS = ""; + if (info.get(CurrencyType.MONEY) != 0D) + moneyS = Jobs.getLanguage().getMessage("command.glog.output.money", "%amount%", info.get(CurrencyType.MONEY)); + + String expS = ""; + if (info.get(CurrencyType.EXP) != 0D) + expS = Jobs.getLanguage().getMessage("command.glog.output.exp", "%amount%", info.get(CurrencyType.EXP)); + + String pointsS = ""; + if (info.get(CurrencyType.POINTS) != 0D) + pointsS = Jobs.getLanguage().getMessage("command.glog.output.points", "%amount%", info.get(CurrencyType.POINTS)); + + sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.ls", + "%number%", count, + "%action%", info.getAction(), + "%item%", info.getItemName().replace(":0", "").replace("_", " ").toLowerCase(), + "%qty%", info.getCount(), + "%money%", moneyS, + "%exp%", expS, + "%points%", pointsS)); + + count++; if (count > max) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/log.java b/src/main/java/com/gamingmesh/jobs/commands/list/log.java index b082a32f..161b7e1a 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/log.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/log.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; +import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Log; import com.gamingmesh.jobs.container.LogAmounts; @@ -61,7 +62,7 @@ public class log implements Cmd { Log one = l.getValue(); HashMap AmountList = one.getAmountList(); for (Entry oneMap : AmountList.entrySet()) { - unsortMap.put(oneMap.getKey(), oneMap.getValue().getMoney()); + unsortMap.put(oneMap.getKey(), oneMap.getValue().get(CurrencyType.MONEY)); } } @@ -76,13 +77,27 @@ public class log implements Cmd { for (Entry oneMap : AmountList.entrySet()) { if (oneMap.getKey().equalsIgnoreCase(oneSorted.getKey())) { count++; - sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.list", + + String moneyS = ""; + if (oneMap.getValue().get(CurrencyType.MONEY) != 0D) + moneyS = Jobs.getLanguage().getMessage("command.log.output.money", "%amount%", oneMap.getValue().get(CurrencyType.MONEY)); + + String expS = ""; + if (oneMap.getValue().get(CurrencyType.EXP) != 0D) + expS = Jobs.getLanguage().getMessage("command.log.output.exp", "%amount%", oneMap.getValue().get(CurrencyType.EXP)); + + String pointsS = ""; + if (oneMap.getValue().get(CurrencyType.POINTS) != 0D) + pointsS = Jobs.getLanguage().getMessage("command.log.output.points", "%amount%", oneMap.getValue().get(CurrencyType.POINTS)); + + sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.ls", "%number%", count, "%action%", one.getActionType(), "%item%", oneMap.getValue().getItemName().replace(":0", "").replace("_", " ").toLowerCase(), "%qty%", oneMap.getValue().getCount(), - "%money%", oneMap.getValue().getMoney(), - "%exp%", oneMap.getValue().getExp())); + "%money%", moneyS, + "%exp%", expS, + "%points%", pointsS)); break; } } diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 132c49a6..e440b74b 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -413,7 +413,10 @@ public class LanguageManager { c.get("command.log.help.args", "[playername]"); Jobs.getGCManager().commandArgs.put("log", Arrays.asList("[playername]")); c.get("command.log.output.topline", "&7************************* &6%playername% &7*************************"); - c.get("command.log.output.list", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% &6money: %money% &eexp: %exp%"); + c.get("command.log.output.ls", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% %money%%exp%%points%"); + c.get("command.log.output.money", "&6money: %amount% "); + c.get("command.log.output.exp", "&eexp: %amount% "); + c.get("command.log.output.points", "&6points: %amount%"); c.get("command.log.output.bottomline", "&7***********************************************************"); c.get("command.log.output.prev", "&e<<<<< Prev page &2|"); c.get("command.log.output.next", "&2|&e Next Page >>>>"); @@ -422,7 +425,10 @@ public class LanguageManager { c.get("command.glog.help.info", "Shows global statistics."); c.get("command.glog.help.args", ""); c.get("command.glog.output.topline", "&7*********************** &6Global statistics &7***********************"); - c.get("command.glog.output.list", "&7* &6%number%. &3%username% &e%action%: &6%item% &eqty: %qty% &6money: %money% &eexp: %exp%"); + c.get("command.glog.output.ls", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% %money%%exp%%points%"); + c.get("command.glog.output.money", "&6money: %amount% "); + c.get("command.glog.output.exp", "&eexp: %amount% "); + c.get("command.glog.output.points", "&6points: %amount%"); c.get("command.glog.output.bottomline", "&7**************************************************************"); c.get("command.glog.output.nodata", "&cData not found"); diff --git a/src/main/java/com/gamingmesh/jobs/container/Log.java b/src/main/java/com/gamingmesh/jobs/container/Log.java index b21ba83a..dcafd31c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Log.java +++ b/src/main/java/com/gamingmesh/jobs/container/Log.java @@ -18,38 +18,23 @@ public final class Log { return this.action; } - public void add(String item, double money, double exp) { - if (!this.amountMap.containsKey(item)) { - LogAmounts LAmount = new LogAmounts(item); - LAmount.addCount(); - LAmount.addMoney(money); - LAmount.addExp(exp); - this.amountMap.put(item, LAmount); - } else { - LogAmounts LAmount = this.amountMap.get(item); - LAmount.addCount(); - LAmount.addMoney(money); - LAmount.addExp(exp); - this.amountMap.put(item, LAmount); - } + public void add(String item, HashMap amounts) { + LogAmounts LAmount = this.amountMap.get(item); + if (LAmount == null) + LAmount = new LogAmounts(item); + LAmount.addCount(); + LAmount.add(amounts); + this.amountMap.put(item, LAmount); } - public void add(String item, int count, double money, double exp) { - if (!this.amountMap.containsKey(item)) { - LogAmounts LAmount = new LogAmounts(item); - LAmount.setCount(count); - LAmount.setNewEntry(false); - LAmount.addMoney(money); - LAmount.addExp(exp); - this.amountMap.put(item, LAmount); - } else { - LogAmounts LAmount = this.amountMap.get(item); - LAmount.setCount(count); - LAmount.setNewEntry(false); - LAmount.addMoney(money); - LAmount.addExp(exp); - this.amountMap.put(item, LAmount); - } + public void add(String item, int count, HashMap amounts) { + LogAmounts LAmount = this.amountMap.get(item); + if (LAmount == null) + LAmount = new LogAmounts(item); + LAmount.setCount(count); + LAmount.add(amounts); + LAmount.setNewEntry(false); + this.amountMap.put(item, LAmount); } public void setDate() { @@ -70,15 +55,9 @@ public final class Log { return 0; } - public double getMoney(String item) { + public double get(String item, CurrencyType type) { if (this.amountMap.containsKey(item)) - return this.amountMap.get(item).getMoney(); - return 0; - } - - public double getExp(String item) { - if (this.amountMap.containsKey(item)) - return this.amountMap.get(item).getExp(); + return this.amountMap.get(item).get(type); return 0; } } \ No newline at end of file diff --git a/src/main/java/com/gamingmesh/jobs/container/LogAmounts.java b/src/main/java/com/gamingmesh/jobs/container/LogAmounts.java index 46356d0e..0d00764b 100644 --- a/src/main/java/com/gamingmesh/jobs/container/LogAmounts.java +++ b/src/main/java/com/gamingmesh/jobs/container/LogAmounts.java @@ -1,5 +1,8 @@ package com.gamingmesh.jobs.container; +import java.util.HashMap; +import java.util.Map.Entry; + public final class LogAmounts { private String username; @@ -7,8 +10,8 @@ public final class LogAmounts { private String item; private int count = 0; - private double money = 0.0; - private double exp = 0.0; + + private HashMap amounts = new HashMap(); private boolean newEntry = true; @@ -28,20 +31,26 @@ public final class LogAmounts { return this.item; } - public void addMoney(Double amount) { - this.money += amount; + public void add(HashMap amounts) { + for (Entry one : amounts.entrySet()) { + add(one.getKey(), one.getValue()); + } } - public double getMoney() { - return (int) (this.money * 100) / 100.0; + public void add(CurrencyType type, Double amount) { + if (amount == null) + return; + Double a = amounts.get(type); + if (a == null) + a = 0D; + amounts.put(type, a + amount); } - public void addExp(Double amount) { - this.exp += amount; - } - - public double getExp() { - return (int) (this.exp * 100) / 100.0; + public Double get(CurrencyType type) { + Double a = amounts.get(type); + if (a == null) + a = 0D; + return ((int) (a * 100D)) / 100D; } public void addCount() { diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 429abd9d..332e6beb 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -211,7 +211,8 @@ public abstract class JobsDAO { itemname("text", TablesFieldsType.text), count("int", TablesFieldsType.number), money("double", TablesFieldsType.decimal), - exp("double", TablesFieldsType.decimal); + exp("double", TablesFieldsType.decimal), + points("double", TablesFieldsType.decimal); private String type; private TablesFieldsType fieldType; @@ -703,7 +704,12 @@ public abstract class JobsDAO { if (log == null) log = new Log(action); - log.add(res.getString("itemname"), res.getInt("count"), res.getDouble("money"), res.getDouble("exp")); + HashMap amounts = new HashMap(); + amounts.put(CurrencyType.MONEY, res.getDouble("money")); + amounts.put(CurrencyType.EXP, res.getDouble("exp")); + amounts.put(CurrencyType.POINTS, res.getDouble("points")); + + log.add(res.getString("itemname"), res.getInt("count"), amounts); m.put(action, log); map.put(id, m); @@ -1494,8 +1500,13 @@ public abstract class JobsDAO { PreparedStatement prest1 = null; PreparedStatement prest2 = null; try { + + conn.setAutoCommit(false); + prest1 = conn.prepareStatement("UPDATE `" + prefix - + "log` SET `count` = ?, `money` = ?, `exp` = ? WHERE `userid` = ? AND `time` = ? AND `action` = ? AND `itemname` = ?;"); + + "log` SET `count` = ?, `money` = ?, `exp` = ?, `points` = ? WHERE `userid` = ? AND `time` = ? AND `action` = ? AND `itemname` = ?;"); + + boolean added = false; for (Entry l : player.getLog().entrySet()) { Log log = l.getValue(); for (Entry one : log.getAmountList().entrySet()) { @@ -1503,25 +1514,30 @@ public abstract class JobsDAO { continue; prest1.setInt(1, one.getValue().getCount()); - prest1.setDouble(2, one.getValue().getMoney()); - prest1.setDouble(3, one.getValue().getExp()); + prest1.setDouble(2, one.getValue().get(CurrencyType.MONEY)); + prest1.setDouble(3, one.getValue().get(CurrencyType.EXP)); + prest1.setDouble(4, one.getValue().get(CurrencyType.POINTS)); - prest1.setInt(4, player.getUserId()); - prest1.setInt(5, log.getDate()); - prest1.setString(6, log.getActionType()); - prest1.setString(7, one.getKey()); - prest1.execute(); + prest1.setInt(5, player.getUserId()); + prest1.setInt(6, log.getDate()); + prest1.setString(7, log.getActionType()); + prest1.setString(8, one.getKey()); + prest1.addBatch(); + added = true; } } + if (added) { + prest1.execute(); + conn.commit(); + } + added = false; prest2 = conn.prepareStatement("INSERT INTO `" + prefix - + "log` (`userid`, `time`, `action`, `itemname`, `count`, `money`, `exp`) VALUES (?, ?, ?, ?, ?, ?, ?);"); + + "log` (`userid`, `time`, `action`, `itemname`, `count`, `money`, `exp`, `points`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);"); for (Entry l : player.getLog().entrySet()) { Log log = l.getValue(); for (Entry one : log.getAmountList().entrySet()) { - if (!one.getValue().isNewEntry()) continue; - one.getValue().setNewEntry(false); prest2.setInt(1, player.getUserId()); @@ -1529,17 +1545,22 @@ public abstract class JobsDAO { prest2.setString(3, log.getActionType()); prest2.setString(4, one.getKey()); prest2.setInt(5, one.getValue().getCount()); - prest2.setDouble(6, one.getValue().getMoney()); - prest2.setDouble(7, one.getValue().getExp()); - prest2.execute(); + prest2.setDouble(6, one.getValue().get(CurrencyType.MONEY)); + prest2.setDouble(7, one.getValue().get(CurrencyType.EXP)); + prest2.setDouble(8, one.getValue().get(CurrencyType.POINTS)); + prest2.addBatch(); + added = true; } } + if (added) { + prest2.execute(); + conn.commit(); + } + conn.setAutoCommit(true); } catch (SQLException e) { e.printStackTrace(); close(prest1); close(prest2); - drop(DBTables.LogTable.getTableName()); - createDefaultTable(DBTables.LogTable); } finally { close(prest1); close(prest2); @@ -1563,7 +1584,13 @@ public abstract class JobsDAO { prest.setInt(2, time); res = prest.executeQuery(); while (res.next()) { - Jobs.getLoging().loadToLog(player, res.getString("action"), res.getString("itemname"), res.getInt("count"), res.getDouble("money"), res.getDouble("exp")); + + HashMap amounts = new HashMap(); + amounts.put(CurrencyType.MONEY, res.getDouble("money")); + amounts.put(CurrencyType.EXP, res.getDouble("exp")); + amounts.put(CurrencyType.POINTS, res.getDouble("points")); + + Jobs.getLoging().loadToLog(player, res.getString("action"), res.getString("itemname"), res.getInt("count"), amounts); } } catch (Exception e) { close(res); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Loging.java b/src/main/java/com/gamingmesh/jobs/stuff/Loging.java index fe53641d..4c3a071b 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Loging.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Loging.java @@ -5,16 +5,17 @@ import java.util.Map.Entry; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.ActionInfo; +import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Log; public class Loging { - public void recordToLog(JobsPlayer jPlayer, ActionInfo info, double amount, double expAmount) { - recordToLog(jPlayer, info.getType().getName(), info.getNameWithSub(), amount, expAmount); + public void recordToLog(JobsPlayer jPlayer, ActionInfo info, HashMap amounts) { + recordToLog(jPlayer, info.getType().getName(), info.getNameWithSub(), amounts); } - public void recordToLog(JobsPlayer jPlayer, String ActionName, String item, double amount, double expAmount) { + public void recordToLog(JobsPlayer jPlayer, String ActionName, String item, HashMap amounts) { HashMap logList = jPlayer.getLog(); Log l = null; for (Entry one : logList.entrySet()) { @@ -29,17 +30,17 @@ public class Loging { if (log == null){ log = new Log(ActionName); } - log.add(item, amount, expAmount); + log.add(item, amounts); logList.put(ActionName, log); } - public void loadToLog(JobsPlayer jPlayer, String ActionName, String item, int count, double money, double expAmount) { + public void loadToLog(JobsPlayer jPlayer, String ActionName, String item, int count, HashMap amounts) { HashMap logList = jPlayer.getLog(); Log log = logList.get(ActionName); if (log == null) log = new Log(ActionName); - log.add(item, count, money, expAmount); + log.add(item, count, amounts); } }