mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-03 23:08:07 +01:00
Get total players from each job instead of connecting to data base
divide from double value to have more accurate results
This commit is contained in:
parent
4d1b78c99d
commit
ba6bd23b7c
@ -799,6 +799,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
int numjobs = progression.size();
|
int numjobs = progression.size();
|
||||||
// no job
|
// no job
|
||||||
|
|
||||||
|
|
||||||
if (numjobs == 0) {
|
if (numjobs == 0) {
|
||||||
|
|
||||||
if (noneJob == null)
|
if (noneJob == null)
|
||||||
@ -816,7 +817,6 @@ public class Jobs extends JavaPlugin {
|
|||||||
|
|
||||||
if (income != 0D || pointAmount != 0D) {
|
if (income != 0D || pointAmount != 0D) {
|
||||||
|
|
||||||
// jPlayer
|
|
||||||
Boost boost = pManager.getFinalBonus(jPlayer, Jobs.getNoneJob());
|
Boost boost = pManager.getFinalBonus(jPlayer, Jobs.getNoneJob());
|
||||||
|
|
||||||
// Calculate income
|
// Calculate income
|
||||||
@ -913,10 +913,8 @@ public class Jobs extends JavaPlugin {
|
|||||||
player.giveExp(expInt);
|
player.giveExp(expInt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, prog.getJob(), ent, victim);
|
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, prog.getJob(), ent, victim);
|
||||||
|
|
||||||
// Debug.D(FinalBoost.getMoneyBoost() + " : " + FinalBoost.getPointsBoost() + " : " + FinalBoost.getExpBoost());
|
|
||||||
|
|
||||||
// Calculate income
|
// Calculate income
|
||||||
if (income != 0D) {
|
if (income != 0D) {
|
||||||
@ -996,7 +994,6 @@ public class Jobs extends JavaPlugin {
|
|||||||
else
|
else
|
||||||
expAmount = JobsExpGainEvent.getExp();
|
expAmount = JobsExpGainEvent.getExp();
|
||||||
|
|
||||||
Debug.D("income: " + income);
|
|
||||||
FastPayment.clear();
|
FastPayment.clear();
|
||||||
FastPayment.put(jPlayer.getUserName(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), income, pointAmount, expAmount), prog
|
FastPayment.put(jPlayer.getUserName(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), income, pointAmount, expAmount), prog
|
||||||
.getJob()));
|
.getJob()));
|
||||||
@ -1049,23 +1046,16 @@ public class Jobs extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type == ActionType.PLACE) {
|
} else if (type == ActionType.PLACE) {
|
||||||
Debug.D("place");
|
|
||||||
BlockProtection bp = Jobs.getBpManager().getBp(block.getLocation());
|
BlockProtection bp = Jobs.getBpManager().getBp(block.getLocation());
|
||||||
if (bp != null) {
|
if (bp != null) {
|
||||||
Debug.D("bpp not null here");
|
|
||||||
Long time = bp.getTime();
|
Long time = bp.getTime();
|
||||||
if (time != -1) {
|
if (time != -1) {
|
||||||
|
|
||||||
Debug.D("time is " + (time < System.currentTimeMillis()));
|
|
||||||
if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) {
|
if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) {
|
||||||
Jobs.getBpManager().remove(block);
|
Jobs.getBpManager().remove(block);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.D("place " + ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE));
|
|
||||||
|
|
||||||
if ((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);
|
int sec = Math.round((time - System.currentTimeMillis()) / 1000);
|
||||||
if (inform)
|
if (inform)
|
||||||
Jobs.getActionBar().send(player, Jobs.getLanguage().getMessage("message.blocktimer", "[time]", sec));
|
Jobs.getActionBar().send(player, Jobs.getLanguage().getMessage("message.blocktimer", "[time]", sec));
|
||||||
|
@ -28,6 +28,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -606,12 +607,14 @@ public class PlayerManager {
|
|||||||
BoostMultiplier data = new BoostMultiplier();
|
BoostMultiplier data = new BoostMultiplier();
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return data;
|
return data;
|
||||||
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
|
if (prog == null)
|
||||||
if (iih == null || prog == null)
|
|
||||||
return data;
|
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()) {
|
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);
|
data.add(armorboost);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
@ -620,6 +623,8 @@ public class PlayerManager {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public BoostMultiplier getItemBoost(Job prog, ItemStack item) {
|
public BoostMultiplier getItemBoost(Job prog, ItemStack item) {
|
||||||
BoostMultiplier bonus = new BoostMultiplier();
|
BoostMultiplier bonus = new BoostMultiplier();
|
||||||
|
if (prog.getItems().isEmpty())
|
||||||
|
return bonus;
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return bonus;
|
return bonus;
|
||||||
|
|
||||||
@ -673,14 +678,21 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boost getFinalBonus(JobsPlayer player, Job prog, Entity ent, LivingEntity victim) {
|
public Boost getFinalBonus(JobsPlayer player, Job prog, Entity ent, LivingEntity victim) {
|
||||||
|
long time = System.nanoTime();
|
||||||
|
long last = System.nanoTime();
|
||||||
Boost boost = new Boost();
|
Boost boost = new Boost();
|
||||||
|
|
||||||
if (player == null || prog == null)
|
if (player == null || prog == null)
|
||||||
return boost;
|
return boost;
|
||||||
|
|
||||||
|
Debug.D("Boost 1 : " + (System.nanoTime() - last));
|
||||||
|
last = System.nanoTime();
|
||||||
|
|
||||||
if (Jobs.getMcMMOlistener().mcMMOPresent)
|
if (Jobs.getMcMMOlistener().mcMMOPresent)
|
||||||
boost.add(BoostOf.McMMO, new BoostMultiplier().add(Jobs.getMcMMOlistener().getMultiplier(player.getPlayer())));
|
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) {
|
if (ent != null && ent instanceof Tameable) {
|
||||||
Tameable t = (Tameable) ent;
|
Tameable t = (Tameable) ent;
|
||||||
if (t.isTamed() && t.getOwner() instanceof Player) {
|
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()))
|
if (victim != null && victim.hasMetadata(this.getMobSpawnerMetadata()))
|
||||||
boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(player.getVipSpawnerMultiplier()));
|
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));
|
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());
|
boost.add(BoostOf.Global, prog.getBoost());
|
||||||
|
Debug.D("Boost 6 : " + (System.nanoTime() - last));
|
||||||
|
last = System.nanoTime();
|
||||||
if (Jobs.getGCManager().useDynamicPayment)
|
if (Jobs.getGCManager().useDynamicPayment)
|
||||||
boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus()));
|
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));
|
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())));
|
boost.add(BoostOf.Area, new BoostMultiplier().add(Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player.getPlayer())));
|
||||||
|
Debug.D("Boost 9 : " + (System.nanoTime() - last));
|
||||||
|
last = System.nanoTime();
|
||||||
return boost;
|
return boost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,6 @@ public class BlockProtectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(Block block, Integer cd, boolean paid) {
|
public void add(Block block, Integer cd, boolean paid) {
|
||||||
Debug.D("cd: " +cd);
|
|
||||||
if (cd == null)
|
if (cd == null)
|
||||||
return;
|
return;
|
||||||
if (cd != -1)
|
if (cd != -1)
|
||||||
@ -99,7 +98,6 @@ public class BlockProtectionManager {
|
|||||||
chunks.put(chunk, Bpm);
|
chunks.put(chunk, Bpm);
|
||||||
regions.put(region, chunks);
|
regions.put(region, chunks);
|
||||||
map.put(loc.getWorld(), regions);
|
map.put(loc.getWorld(), regions);
|
||||||
Debug.D("added new " + Bp.getAction());
|
|
||||||
return Bp;
|
return Bp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import java.util.Collections;
|
|||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -156,13 +157,13 @@ public class Job {
|
|||||||
now = Jobs.getGCManager().DynamicPaymentMaxBonus;
|
now = Jobs.getGCManager().DynamicPaymentMaxBonus;
|
||||||
if (now < Jobs.getGCManager().DynamicPaymentMaxPenalty * -1)
|
if (now < Jobs.getGCManager().DynamicPaymentMaxPenalty * -1)
|
||||||
now = Jobs.getGCManager().DynamicPaymentMaxPenalty * -1;
|
now = Jobs.getGCManager().DynamicPaymentMaxPenalty * -1;
|
||||||
this.bonus = (now / 100);
|
this.bonus = (now / 100D);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getBonus() {
|
public double getBonus() {
|
||||||
if (this.bonus == null)
|
if (this.bonus == null)
|
||||||
updateBonus();
|
updateBonus();
|
||||||
return this.bonus == null ? 1D : this.bonus;
|
return this.bonus == null ? 0D : this.bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getCmdOnJoin() {
|
public List<String> getCmdOnJoin() {
|
||||||
|
@ -32,6 +32,7 @@ import com.gamingmesh.jobs.Jobs;
|
|||||||
import com.gamingmesh.jobs.dao.JobsDAO;
|
import com.gamingmesh.jobs.dao.JobsDAO;
|
||||||
import com.gamingmesh.jobs.resources.jfep.Parser;
|
import com.gamingmesh.jobs.resources.jfep.Parser;
|
||||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||||
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
import com.gamingmesh.jobs.stuff.Perm;
|
import com.gamingmesh.jobs.stuff.Perm;
|
||||||
|
|
||||||
public class JobsPlayer {
|
public class JobsPlayer {
|
||||||
|
@ -345,25 +345,11 @@ public abstract class JobsDAO {
|
|||||||
* @return total amount of player currently working.
|
* @return total amount of player currently working.
|
||||||
*/
|
*/
|
||||||
public synchronized int getTotalPlayers() {
|
public synchronized int getTotalPlayers() {
|
||||||
JobsConnection conn = getConnection();
|
int total = 0;
|
||||||
if (conn == null)
|
for (Job one : Jobs.getJobs()) {
|
||||||
return 0;
|
total += one.getTotalPlayers();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
return count;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1343,8 +1329,7 @@ public abstract class JobsDAO {
|
|||||||
while (res.next()) {
|
while (res.next()) {
|
||||||
Entry<String, PlayerInfo> info = Jobs.getPlayerManager().getPlayerInfoById(res.getInt("userid"));
|
Entry<String, PlayerInfo> info = Jobs.getPlayerManager().getPlayerInfoById(res.getInt("userid"));
|
||||||
|
|
||||||
if (info == null){
|
if (info == null) {
|
||||||
Debug.D("Continue " + res.getInt("userid"));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,42 +28,43 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
public class JobsDrivers implements Driver {
|
public class JobsDrivers implements Driver {
|
||||||
private Driver driver;
|
private Driver driver;
|
||||||
|
|
||||||
public JobsDrivers(Driver driver) {
|
public JobsDrivers(Driver driver) {
|
||||||
this.driver = driver;
|
this.driver = driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection connect(String url, Properties info) throws SQLException {
|
public Connection connect(String url, Properties info) throws SQLException {
|
||||||
return driver.connect(url, info);
|
return driver.connect(url, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsURL(String url) throws SQLException {
|
public boolean acceptsURL(String url) throws SQLException {
|
||||||
return driver.acceptsURL(url);
|
return driver.acceptsURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||||
return driver.getPropertyInfo(url, info);
|
return driver.getPropertyInfo(url, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMajorVersion() {
|
public int getMajorVersion() {
|
||||||
return driver.getMajorVersion();
|
return driver.getMajorVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMinorVersion() {
|
public int getMinorVersion() {
|
||||||
return driver.getMinorVersion();
|
return driver.getMinorVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean jdbcCompliant() {
|
public boolean jdbcCompliant() {
|
||||||
return driver.jdbcCompliant();
|
return driver.jdbcCompliant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||||
return driver.getParentLogger();
|
return driver.getParentLogger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,11 +247,9 @@ public class JobsPaymentListener implements Listener {
|
|||||||
//disabling plugin in world
|
//disabling plugin in world
|
||||||
if (event.getBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
|
if (event.getBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
|
||||||
return;
|
return;
|
||||||
// remove furnace metadata for broken block
|
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (block == null)
|
if (block == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (block.getType() == Material.FURNACE && block.hasMetadata(this.furnaceOwnerMetadata))
|
if (block.getType() == Material.FURNACE && block.hasMetadata(this.furnaceOwnerMetadata))
|
||||||
block.removeMetadata(this.furnaceOwnerMetadata, this.plugin);
|
block.removeMetadata(this.furnaceOwnerMetadata, this.plugin);
|
||||||
|
|
||||||
@ -334,11 +332,8 @@ public class JobsPaymentListener implements Listener {
|
|||||||
|
|
||||||
if (Jobs.getGCManager().useBlockProtection) {
|
if (Jobs.getGCManager().useBlockProtection) {
|
||||||
BlockProtection bp = Jobs.getBpManager().getBp(block.getLocation());
|
BlockProtection bp = Jobs.getBpManager().getBp(block.getLocation());
|
||||||
Debug.D("bp is null " + (bp == null));
|
|
||||||
if (bp == null || bp.getAction() == DBAction.DELETE)
|
if (bp == null || bp.getAction() == DBAction.DELETE)
|
||||||
Jobs.getBpManager().add(block, Jobs.getBpManager().getBlockDelayTime(block), false);
|
Jobs.getBpManager().add(block, Jobs.getBpManager().getBlockDelayTime(block), false);
|
||||||
// else
|
|
||||||
// Debug.D("bp is " + bp.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||||
@ -803,6 +798,9 @@ public class JobsPaymentListener implements Listener {
|
|||||||
pDamager = (Player) e.getDamager();
|
pDamager = (Player) e.getDamager();
|
||||||
// Checking if killer is tamed animal
|
// Checking if killer is tamed animal
|
||||||
} else if (e.getDamager() instanceof Tameable) {
|
} 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) {
|
} else if (e.getDamager() instanceof Projectile) {
|
||||||
Projectile pr = (Projectile) e.getDamager();
|
Projectile pr = (Projectile) e.getDamager();
|
||||||
if (pr.getShooter() instanceof Player)
|
if (pr.getShooter() instanceof Player)
|
||||||
|
Loading…
Reference in New Issue
Block a user