From ba6bd23b7cca343acb44ec3efda4256ac228afaa Mon Sep 17 00:00:00 2001 From: Zrips Date: Mon, 9 Jan 2017 15:09:02 +0200 Subject: [PATCH] Get total players from each job instead of connecting to data base divide from double value to have more accurate results --- com/gamingmesh/jobs/Jobs.java | 12 +------ com/gamingmesh/jobs/PlayerManager.java | 35 ++++++++++++++++--- .../jobs/config/BlockProtectionManager.java | 2 -- com/gamingmesh/jobs/container/Job.java | 5 +-- com/gamingmesh/jobs/container/JobsPlayer.java | 1 + com/gamingmesh/jobs/dao/JobsDAO.java | 25 +++---------- com/gamingmesh/jobs/dao/JobsDrivers.java | 23 ++++++------ .../jobs/listeners/JobsPaymentListener.java | 8 ++--- 8 files changed, 55 insertions(+), 56 deletions(-) diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index 3c9b308f..2482fee3 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -799,6 +799,7 @@ public class Jobs extends JavaPlugin { int numjobs = progression.size(); // no job + if (numjobs == 0) { if (noneJob == null) @@ -816,7 +817,6 @@ public class Jobs extends JavaPlugin { if (income != 0D || pointAmount != 0D) { -// jPlayer Boost boost = pManager.getFinalBonus(jPlayer, Jobs.getNoneJob()); // Calculate income @@ -913,10 +913,8 @@ public class Jobs extends JavaPlugin { player.giveExp(expInt); } } - Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, prog.getJob(), ent, victim); -// Debug.D(FinalBoost.getMoneyBoost() + " : " + FinalBoost.getPointsBoost() + " : " + FinalBoost.getExpBoost()); // Calculate income if (income != 0D) { @@ -996,7 +994,6 @@ public class Jobs extends JavaPlugin { else expAmount = JobsExpGainEvent.getExp(); - Debug.D("income: " + income); FastPayment.clear(); FastPayment.put(jPlayer.getUserName(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), income, pointAmount, expAmount), prog .getJob())); @@ -1049,23 +1046,16 @@ public class Jobs extends JavaPlugin { } } } else if (type == ActionType.PLACE) { - Debug.D("place"); BlockProtection bp = Jobs.getBpManager().getBp(block.getLocation()); if (bp != null) { - Debug.D("bpp not null here"); Long time = bp.getTime(); if (time != -1) { - - Debug.D("time is " + (time < System.currentTimeMillis())); if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) { Jobs.getBpManager().remove(block); return true; } - Debug.D("place " + ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE)); - if ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE) { - Debug.D("here mufyn"); int sec = Math.round((time - System.currentTimeMillis()) / 1000); if (inform) Jobs.getActionBar().send(player, Jobs.getLanguage().getMessage("message.blocktimer", "[time]", sec)); diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index d88fb259..af12e5cd 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -28,6 +28,7 @@ import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; @@ -606,12 +607,14 @@ public class PlayerManager { BoostMultiplier data = new BoostMultiplier(); if (player == null) return data; - ItemStack iih = Jobs.getNms().getItemInMainHand(player); - if (iih == null || prog == null) + if (prog == null) return data; - data = Jobs.getPlayerManager().getItemBoost(prog, iih); + ItemStack iih = Jobs.getNms().getItemInMainHand(player); + data = Jobs.getPlayerManager().getItemBoost(prog, iih); for (ItemStack OneArmor : player.getInventory().getArmorContents()) { - BoostMultiplier armorboost = Jobs.getPlayerManager().getItemBoost(prog, OneArmor); + if (OneArmor == null || OneArmor.getType() == Material.AIR) + continue; + BoostMultiplier armorboost = Jobs.getPlayerManager().getItemBoost(prog, OneArmor); data.add(armorboost); } return data; @@ -620,6 +623,8 @@ public class PlayerManager { @SuppressWarnings("deprecation") public BoostMultiplier getItemBoost(Job prog, ItemStack item) { BoostMultiplier bonus = new BoostMultiplier(); + if (prog.getItems().isEmpty()) + return bonus; if (item == null) return bonus; @@ -673,14 +678,21 @@ public class PlayerManager { } public Boost getFinalBonus(JobsPlayer player, Job prog, Entity ent, LivingEntity victim) { + long time = System.nanoTime(); + long last = System.nanoTime(); Boost boost = new Boost(); if (player == null || prog == null) return boost; + Debug.D("Boost 1 : " + (System.nanoTime() - last)); + last = System.nanoTime(); + if (Jobs.getMcMMOlistener().mcMMOPresent) boost.add(BoostOf.McMMO, new BoostMultiplier().add(Jobs.getMcMMOlistener().getMultiplier(player.getPlayer()))); + Debug.D("Boost 2 : " + (System.nanoTime() - last)); + last = System.nanoTime(); if (ent != null && ent instanceof Tameable) { Tameable t = (Tameable) ent; if (t.isTamed() && t.getOwner() instanceof Player) { @@ -694,15 +706,28 @@ public class PlayerManager { } } + Debug.D("Boost 3 : " + (System.nanoTime() - last)); + last = System.nanoTime(); if (victim != null && victim.hasMetadata(this.getMobSpawnerMetadata())) boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(player.getVipSpawnerMultiplier())); + Debug.D("Boost 4 : " + (System.nanoTime() - last)); + last = System.nanoTime(); boost.add(BoostOf.Permission, Jobs.getPlayerManager().getBoost(player, prog)); + Debug.D("Boost 5 : " + (System.nanoTime() - last)); + last = System.nanoTime(); boost.add(BoostOf.Global, prog.getBoost()); + Debug.D("Boost 6 : " + (System.nanoTime() - last)); + last = System.nanoTime(); if (Jobs.getGCManager().useDynamicPayment) boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus())); + Debug.D("Boost 7 : " + (System.nanoTime() - last)); + last = System.nanoTime(); boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog)); + Debug.D("Boost 8 : " + (System.nanoTime() - last)); + last = System.nanoTime(); boost.add(BoostOf.Area, new BoostMultiplier().add(Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player.getPlayer()))); - + Debug.D("Boost 9 : " + (System.nanoTime() - last)); + last = System.nanoTime(); return boost; } diff --git a/com/gamingmesh/jobs/config/BlockProtectionManager.java b/com/gamingmesh/jobs/config/BlockProtectionManager.java index b64bf6e6..ff03e70d 100644 --- a/com/gamingmesh/jobs/config/BlockProtectionManager.java +++ b/com/gamingmesh/jobs/config/BlockProtectionManager.java @@ -55,7 +55,6 @@ public class BlockProtectionManager { } public void add(Block block, Integer cd, boolean paid) { - Debug.D("cd: " +cd); if (cd == null) return; if (cd != -1) @@ -99,7 +98,6 @@ public class BlockProtectionManager { chunks.put(chunk, Bpm); regions.put(region, chunks); map.put(loc.getWorld(), regions); - Debug.D("added new " + Bp.getAction()); return Bp; } diff --git a/com/gamingmesh/jobs/container/Job.java b/com/gamingmesh/jobs/container/Job.java index 7b5951c2..148c63e3 100644 --- a/com/gamingmesh/jobs/container/Job.java +++ b/com/gamingmesh/jobs/container/Job.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.EnumMap; import java.util.List; import java.util.Map; +import java.util.Random; import org.bukkit.inventory.ItemStack; @@ -156,13 +157,13 @@ public class Job { now = Jobs.getGCManager().DynamicPaymentMaxBonus; if (now < Jobs.getGCManager().DynamicPaymentMaxPenalty * -1) now = Jobs.getGCManager().DynamicPaymentMaxPenalty * -1; - this.bonus = (now / 100); + this.bonus = (now / 100D); } public double getBonus() { if (this.bonus == null) updateBonus(); - return this.bonus == null ? 1D : this.bonus; + return this.bonus == null ? 0D : this.bonus; } public List getCmdOnJoin() { diff --git a/com/gamingmesh/jobs/container/JobsPlayer.java b/com/gamingmesh/jobs/container/JobsPlayer.java index 093a1cd5..1b6f8d6b 100644 --- a/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/com/gamingmesh/jobs/container/JobsPlayer.java @@ -32,6 +32,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.Perm; public class JobsPlayer { diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index 5dbc3649..c98cfab1 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -345,25 +345,11 @@ public abstract class JobsDAO { * @return total amount of player currently working. */ public synchronized int getTotalPlayers() { - JobsConnection conn = getConnection(); - if (conn == null) - return 0; - int count = 0; - PreparedStatement prest = null; - ResultSet res = null; - try { - prest = conn.prepareStatement("SELECT COUNT(*) FROM `" + prefix + "jobs`;"); - res = prest.executeQuery(); - while (res.next()) { - count = res.getInt(1); - } - } catch (SQLException e) { - e.printStackTrace(); - } finally { - close(res); - close(prest); + int total = 0; + for (Job one : Jobs.getJobs()) { + total += one.getTotalPlayers(); } - return count; + return total; } /** @@ -1343,8 +1329,7 @@ public abstract class JobsDAO { while (res.next()) { Entry info = Jobs.getPlayerManager().getPlayerInfoById(res.getInt("userid")); - if (info == null){ - Debug.D("Continue " + res.getInt("userid")); + if (info == null) { continue; } diff --git a/com/gamingmesh/jobs/dao/JobsDrivers.java b/com/gamingmesh/jobs/dao/JobsDrivers.java index e5d17d53..de20ea77 100644 --- a/com/gamingmesh/jobs/dao/JobsDrivers.java +++ b/com/gamingmesh/jobs/dao/JobsDrivers.java @@ -28,42 +28,43 @@ import java.util.logging.Logger; public class JobsDrivers implements Driver { private Driver driver; + public JobsDrivers(Driver driver) { - this.driver = driver; + this.driver = driver; } @Override public Connection connect(String url, Properties info) throws SQLException { - return driver.connect(url, info); + return driver.connect(url, info); } @Override public boolean acceptsURL(String url) throws SQLException { - return driver.acceptsURL(url); + return driver.acceptsURL(url); } @Override public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { - return driver.getPropertyInfo(url, info); + return driver.getPropertyInfo(url, info); } @Override public int getMajorVersion() { - return driver.getMajorVersion(); + return driver.getMajorVersion(); } @Override public int getMinorVersion() { - return driver.getMinorVersion(); + return driver.getMinorVersion(); } @Override public boolean jdbcCompliant() { - return driver.jdbcCompliant(); + return driver.jdbcCompliant(); } - @Override - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - return driver.getParentLogger(); - } + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + return driver.getParentLogger(); + } } diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 75f01329..3e8f1951 100644 --- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -247,11 +247,9 @@ public class JobsPaymentListener implements Listener { //disabling plugin in world if (event.getBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) return; - // remove furnace metadata for broken block Block block = event.getBlock(); if (block == null) return; - if (block.getType() == Material.FURNACE && block.hasMetadata(this.furnaceOwnerMetadata)) block.removeMetadata(this.furnaceOwnerMetadata, this.plugin); @@ -334,11 +332,8 @@ public class JobsPaymentListener implements Listener { if (Jobs.getGCManager().useBlockProtection) { BlockProtection bp = Jobs.getBpManager().getBp(block.getLocation()); - Debug.D("bp is null " + (bp == null)); if (bp == null || bp.getAction() == DBAction.DELETE) Jobs.getBpManager().add(block, Jobs.getBpManager().getBlockDelayTime(block), false); -// else -// Debug.D("bp is " + bp.getId()); } JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); @@ -803,6 +798,9 @@ public class JobsPaymentListener implements Listener { pDamager = (Player) e.getDamager(); // Checking if killer is tamed animal } else if (e.getDamager() instanceof Tameable) { + Tameable t = (Tameable) e.getDamager(); + if (t.isTamed() && t.getOwner() instanceof Player) + pDamager = (Player) t.getOwner(); } else if (e.getDamager() instanceof Projectile) { Projectile pr = (Projectile) e.getDamager(); if (pr.getShooter() instanceof Player)