1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-02-18 05:11:32 +01:00

Rework for payment limitations and now saving to database

This commit is contained in:
Zrips 2017-01-10 13:48:40 +02:00
parent ac914031d3
commit f5452e2e41
27 changed files with 724 additions and 807 deletions

View File

@ -16,7 +16,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.JobProgression;
@ -176,11 +176,11 @@ public class GuiManager {
String itemName = Jobs.getNameTranslatorManager().Translate(info.get(z).getName(), info.get(z));
double income = info.get(z).getIncome(level, numjobs);
income = income + (income * boost.getFinal(BoostType.MONEY));
income = income + (income * boost.getFinal(CurrencyType.MONEY));
ChatColor incomeColor = income >= 0 ? ChatColor.GREEN : ChatColor.DARK_RED;
double xp = info.get(z).getExperience(level, numjobs);
xp = xp + (xp * boost.getFinal(BoostType.EXP));
xp = xp + (xp * boost.getFinal(CurrencyType.EXP));
ChatColor xpColor = xp >= 0 ? ChatColor.YELLOW : ChatColor.GRAY;
String xpString = String.format("%.2fxp", xp);

View File

@ -59,7 +59,7 @@ import com.gamingmesh.jobs.container.ActionInfo;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BlockProtection;
import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.DBAction;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobInfo;
@ -797,7 +797,6 @@ public class Jobs extends JavaPlugin {
int numjobs = progression.size();
// no job
if (numjobs == 0) {
if (noneJob == null)
@ -820,7 +819,7 @@ public class Jobs extends JavaPlugin {
// Calculate income
if (income != 0D) {
income = income + (income * boost.getFinal(BoostType.MONEY));
income = income + (income * boost.getFinal(CurrencyType.MONEY));
if (GconfigManager.useMinimumOveralPayment && income > 0) {
double maxLimit = income * GconfigManager.MinimumOveralPaymentLimit;
if (income < maxLimit) {
@ -832,7 +831,7 @@ public class Jobs extends JavaPlugin {
// Calculate points
if (pointAmount != 0D) {
pointAmount = pointAmount + (pointAmount * boost.getFinal(BoostType.POINTS));
pointAmount = pointAmount + (pointAmount * boost.getFinal(CurrencyType.POINTS));
if (GconfigManager.useMinimumOveralPoints && pointAmount > 0) {
double maxLimit = pointAmount * GconfigManager.MinimumOveralPaymentLimit;
if (pointAmount < maxLimit) {
@ -841,15 +840,15 @@ public class Jobs extends JavaPlugin {
}
}
if (!isUnderMoneyLimit(jPlayer, income)) {
if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) {
income = 0D;
if (GconfigManager.MoneyStopPoint)
if (GconfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.POINTS))
pointAmount = 0D;
}
if (!isUnderPointLimit(jPlayer, pointAmount)) {
if (!jPlayer.isUnderLimit(CurrencyType.POINTS, pointAmount)) {
pointAmount = 0D;
if (GconfigManager.PointStopMoney)
if (GconfigManager.getLimit(CurrencyType.POINTS).getStopWith().contains(CurrencyType.MONEY))
income = 0D;
}
@ -913,10 +912,9 @@ public class Jobs extends JavaPlugin {
}
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, prog.getJob(), ent, victim);
// Calculate income
if (income != 0D) {
income = income + (income * boost.getFinal(BoostType.MONEY));
income = income + (income * boost.getFinal(CurrencyType.MONEY));
if (GconfigManager.useMinimumOveralPayment && income > 0) {
double maxLimit = income * GconfigManager.MinimumOveralPaymentLimit;
if (income < maxLimit) {
@ -927,7 +925,7 @@ public class Jobs extends JavaPlugin {
// Calculate points
if (pointAmount != 0D) {
pointAmount = pointAmount + (pointAmount * boost.getFinal(BoostType.POINTS));
pointAmount = pointAmount + (pointAmount * boost.getFinal(CurrencyType.POINTS));
if (GconfigManager.useMinimumOveralPoints && pointAmount > 0) {
double maxLimit = pointAmount * GconfigManager.MinimumOveralPaymentLimit;
if (pointAmount < maxLimit) {
@ -937,7 +935,7 @@ public class Jobs extends JavaPlugin {
}
// Calculate exp
expAmount = expAmount + (expAmount * boost.getFinal(BoostType.EXP));
expAmount = expAmount + (expAmount * boost.getFinal(CurrencyType.EXP));
if (GconfigManager.useMinimumOveralPayment && expAmount > 0) {
double maxLimit = expAmount * GconfigManager.MinimumOveralPaymentLimit;
@ -946,27 +944,27 @@ public class Jobs extends JavaPlugin {
}
}
if (!isUnderMoneyLimit(jPlayer, income)) {
if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) {
income = 0D;
if (GconfigManager.MoneyStopExp)
if (GconfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.EXP))
expAmount = 0D;
if (GconfigManager.MoneyStopPoint)
if (GconfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.POINTS))
pointAmount = 0D;
}
if (!isUnderExpLimit(jPlayer, expAmount)) {
if (!jPlayer.isUnderLimit(CurrencyType.EXP, expAmount)) {
expAmount = 0D;
if (GconfigManager.ExpStopMoney)
if (GconfigManager.getLimit(CurrencyType.EXP).getStopWith().contains(CurrencyType.MONEY))
income = 0D;
if (GconfigManager.ExpStopPoint)
if (GconfigManager.getLimit(CurrencyType.EXP).getStopWith().contains(CurrencyType.POINTS))
pointAmount = 0D;
}
if (!isUnderPointLimit(jPlayer, pointAmount)) {
if (!jPlayer.isUnderLimit(CurrencyType.POINTS, pointAmount)) {
pointAmount = 0D;
if (GconfigManager.PointStopMoney)
if (GconfigManager.getLimit(CurrencyType.POINTS).getStopWith().contains(CurrencyType.MONEY))
income = 0D;
if (GconfigManager.PointStopExp)
if (GconfigManager.getLimit(CurrencyType.POINTS).getStopWith().contains(CurrencyType.EXP))
expAmount = 0D;
}
@ -1123,9 +1121,12 @@ public class Jobs extends JavaPlugin {
if (JobsExpGainEvent.isCancelled())
return;
isUnderMoneyLimit(jPlayer, payment.getAmount());
isUnderExpLimit(jPlayer, payment.getExp());
isUnderPointLimit(jPlayer, payment.getPoints());
if (!jPlayer.isUnderLimit(CurrencyType.MONEY, payment.getAmount()))
return;
if (!jPlayer.isUnderLimit(CurrencyType.EXP, payment.getExp()))
return;
if (!jPlayer.isUnderLimit(CurrencyType.POINTS, payment.getPoints()))
return;
economy.pay(jPlayer, payment.getAmount(), payment.getPoints(), payment.getExp());
@ -1140,134 +1141,6 @@ public class Jobs extends JavaPlugin {
pManager.performLevelUp(jPlayer, prog.getJob(), oldLevel);
}
public static boolean isUnderMoneyLimit(JobsPlayer jPlayer, Double amount) {
Player player = jPlayer.getPlayer();
if (player == null)
return true;
if (amount == 0)
return true;
String playername = player.getName();
if (!GconfigManager.MoneyLimitUse)
return true;
if (!paymentLimit.containsKey(playername)) {
PaymentData data = new PaymentData(System.currentTimeMillis(), amount, 0.0, 0.0, 0L, false);
//data.AddNewAmount(amount);
paymentLimit.put(playername, data);
} else {
PaymentData data = paymentLimit.get(playername);
if (data.IsReachedMoneyLimit(GconfigManager.MoneyTimeLimit, jPlayer.getMoneyLimit())) {
if (player.isOnline() && !data.Informed && !data.isReseted()) {
player.sendMessage(lManager.getMessage("command.limit.output.reachedlimit"));
player.sendMessage(lManager.getMessage("command.limit.output.reachedlimit2"));
data.Setinformed();
}
if (data.IsAnnounceTime(GconfigManager.MoneyAnnouncmentDelay) && player.isOnline()) {
String message = lManager.getMessage("command.limit.output.lefttime", "%hour%", data.GetLeftHour(GconfigManager.MoneyTimeLimit));
message = message.replace("%min%", String.valueOf(data.GetLeftMin(GconfigManager.MoneyTimeLimit)));
message = message.replace("%sec%", String.valueOf(data.GetLeftsec(GconfigManager.MoneyTimeLimit)));
Jobs.getActionBar().send((player), ChatColor.RED + message);
}
if (data.isReseted())
data.setReseted(false);
return false;
}
data.AddAmount(amount);
paymentLimit.put(playername, data);
}
return true;
}
public static boolean isUnderExpLimit(JobsPlayer jPlayer, Double amount) {
Player player = jPlayer.getPlayer();
if (player == null)
return true;
if (amount == 0)
return true;
String playername = player.getName();
if (!GconfigManager.ExpLimitUse)
return true;
if (!ExpLimit.containsKey(playername)) {
PaymentData data = new PaymentData(System.currentTimeMillis(), 0.0, 0.0, amount, 0L, false);
//data.AddNewAmount(amount);
ExpLimit.put(playername, data);
} else {
PaymentData data = ExpLimit.get(playername);
if (data.IsReachedExpLimit(GconfigManager.ExpTimeLimit, jPlayer.getExpLimit())) {
if (player.isOnline() && !data.Informed && !data.isReseted()) {
player.sendMessage(lManager.getMessage("command.limit.output.reachedExplimit"));
player.sendMessage(lManager.getMessage("command.limit.output.reachedExplimit2"));
data.Setinformed();
}
if (data.IsAnnounceTime(GconfigManager.ExpAnnouncmentDelay) && player.isOnline()) {
String message = lManager.getMessage("command.limit.output.lefttime", "%hour%", data.GetLeftHour(GconfigManager.ExpTimeLimit));
message = message.replace("%min%", String.valueOf(data.GetLeftMin(GconfigManager.ExpTimeLimit)));
message = message.replace("%sec%", String.valueOf(data.GetLeftsec(GconfigManager.ExpTimeLimit)));
Jobs.getActionBar().send((player), ChatColor.RED + message);
}
if (data.isReseted())
data.setReseted(false);
return false;
}
data.AddExpAmount(amount);
ExpLimit.put(playername, data);
}
return true;
}
public static boolean isUnderPointLimit(JobsPlayer jPlayer, Double amount) {
Player player = jPlayer.getPlayer();
if (player == null)
return true;
if (amount == 0)
return true;
String playername = player.getName();
if (!GconfigManager.PointLimitUse)
return true;
if (!PointLimit.containsKey(playername)) {
PaymentData data = new PaymentData(System.currentTimeMillis(), 0.0, amount, 0.0, 0L, false);
//data.AddNewAmount(amount);
PointLimit.put(playername, data);
} else {
PaymentData data = PointLimit.get(playername);
if (data.IsReachedPointLimit(GconfigManager.PointTimeLimit, jPlayer.getPointLimit())) {
if (player.isOnline() && !data.Informed && !data.isReseted()) {
player.sendMessage(lManager.getMessage("command.limit.output.reachedPointlimit"));
player.sendMessage(lManager.getMessage("command.limit.output.reachedPointlimit2"));
data.Setinformed();
}
if (data.IsAnnounceTime(GconfigManager.PointAnnouncmentDelay) && player.isOnline()) {
String message = lManager.getMessage("command.limit.output.lefttime", "%hour%", data.GetLeftHour(GconfigManager.PointTimeLimit));
message = message.replace("%min%", String.valueOf(data.GetLeftMin(GconfigManager.PointTimeLimit)));
message = message.replace("%sec%", String.valueOf(data.GetLeftsec(GconfigManager.PointTimeLimit)));
Jobs.getActionBar().send((player), ChatColor.RED + message);
}
if (data.isReseted())
data.setReseted(false);
return false;
}
data.AddPoints(amount);
PointLimit.put(playername, data);
}
return true;
}
public static void consoleMsg(String msg) {
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
}

View File

@ -42,7 +42,7 @@ import com.gamingmesh.jobs.api.JobsLeaveEvent;
import com.gamingmesh.jobs.api.JobsLevelUpEvent;
import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobCommands;
import com.gamingmesh.jobs.container.JobItems;
@ -569,17 +569,17 @@ public class PlayerManager {
public BoostMultiplier getBoost(JobsPlayer player, Job job) {
BoostMultiplier b = new BoostMultiplier();
for (BoostType one : BoostType.values()) {
for (CurrencyType one : CurrencyType.values()) {
b.add(one, getBoost(player, job, one, false));
}
return b;
}
public double getBoost(JobsPlayer player, Job job, BoostType type) {
public double getBoost(JobsPlayer player, Job job, CurrencyType type) {
return getBoost(player, job, type, false);
}
public double getBoost(JobsPlayer player, Job job, BoostType type, boolean force) {
public double getBoost(JobsPlayer player, Job job, CurrencyType type, boolean force) {
return player.getBoost(job.getName(), type, force);
}
@ -678,21 +678,14 @@ 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) {
@ -706,28 +699,14 @@ 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;
}

View File

@ -29,7 +29,7 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.JobProgression;
@ -375,14 +375,14 @@ public class JobsCommands implements CommandExecutor {
}
}
if (job.getBoost().get(BoostType.EXP) != 0D)
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", (job.getBoost().get(BoostType.EXP)) + 1) + "\n");
if (job.getBoost().get(CurrencyType.EXP) != 0D)
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.EXP)) + 1) + "\n");
if (job.getBoost().get(BoostType.MONEY) != 0D)
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.moneyboost.output.infostats", "%boost%", (job.getBoost().get(BoostType.MONEY)) + 1) + "\n");
if (job.getBoost().get(CurrencyType.MONEY) != 0D)
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.moneyboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.MONEY)) + 1) + "\n");
if (job.getBoost().get(BoostType.POINTS) != 0D)
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", (job.getBoost().get(BoostType.POINTS)) + 1) + "\n");
if (job.getBoost().get(CurrencyType.POINTS) != 0D)
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.POINTS)) + 1) + "\n");
if (Jobs.getGCManager().useDynamicPayment)
if (job.getBonus() < 0)
@ -512,15 +512,15 @@ public class JobsCommands implements CommandExecutor {
// Jobs.getPlayerManager().getFinalBonus(player, prog)
income = income + (income * boost.getFinal(BoostType.MONEY));
income = income + (income * boost.getFinal(CurrencyType.MONEY));
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
double xp = info.getExperience(level, numjobs);
xp = xp + (xp * boost.getFinal(BoostType.EXP));
xp = xp + (xp * boost.getFinal(CurrencyType.EXP));
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
double points = info.getPoints(level, numjobs);
points = points + (points * boost.getFinal(BoostType.POINTS));
points = points + (points * boost.getFinal(CurrencyType.POINTS));
String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString();
if (income == 0D && points == 0D && xp == 0D)

View File

@ -8,7 +8,7 @@ import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
@ -47,41 +47,41 @@ public class bonus implements Cmd {
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.topline"));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.permission",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Permission, BoostType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Permission, BoostType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Permission, BoostType.EXP, true))));
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.EXP, true))));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.item",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Item, BoostType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Item, BoostType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Item, BoostType.EXP, true))));
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Item, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Item, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Item, CurrencyType.EXP, true))));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.global",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Global, BoostType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Global, BoostType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Global, BoostType.EXP, true))));
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Global, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Global, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Global, CurrencyType.EXP, true))));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.dynamic",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Dynamic, BoostType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Dynamic, BoostType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Dynamic, BoostType.EXP, true))));
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Dynamic, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Dynamic, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Dynamic, CurrencyType.EXP, true))));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.area",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Area, BoostType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Area, BoostType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Area, BoostType.EXP, true))));
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Area, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Area, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Area, CurrencyType.EXP, true))));
if (Jobs.getMcMMOlistener().mcMMOPresent && boost.get(BoostOf.McMMO, BoostType.EXP) != 0D)
if (Jobs.getMcMMOlistener().mcMMOPresent && boost.get(BoostOf.McMMO, CurrencyType.EXP) != 0D)
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.mcmmo",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.McMMO, BoostType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.McMMO, BoostType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.McMMO, BoostType.EXP, true))));
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.McMMO, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.McMMO, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.McMMO, CurrencyType.EXP, true))));
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.final",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.getFinal(BoostType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.getFinal(BoostType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.getFinal(BoostType.EXP, true))));
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.getFinal(CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.getFinal(CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.getFinal(CurrencyType.EXP, true))));
return true;
}

View File

@ -5,7 +5,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.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.stuff.ChatColor;
@ -39,7 +39,7 @@ public class expboost implements Cmd {
if (args[0].equalsIgnoreCase("reset") && args[1].equalsIgnoreCase("all")) {
for (Job one : Jobs.getJobs()) {
one.addBoost(BoostType.EXP, 1.0);
one.addBoost(CurrencyType.EXP, 1.0);
}
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.expboost.output.allreset"));
return true;
@ -47,7 +47,7 @@ public class expboost implements Cmd {
boolean found = false;
for (Job one : Jobs.getJobs()) {
if (one.getName().equalsIgnoreCase(args[1])) {
one.addBoost(BoostType.EXP, 1.0);
one.addBoost(CurrencyType.EXP, 1.0);
found = true;
break;
}
@ -62,7 +62,7 @@ public class expboost implements Cmd {
if (args[0].equalsIgnoreCase("all")) {
for (Job one : Jobs.getJobs()) {
one.addBoost(BoostType.EXP, rate);
one.addBoost(CurrencyType.EXP, rate);
}
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.expboost.output.boostalladded", "%boost%", rate));
@ -72,7 +72,7 @@ public class expboost implements Cmd {
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
job.addBoost(BoostType.EXP, rate);
job.addBoost(CurrencyType.EXP, rate);
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.expboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
return true;
}

View File

@ -1,173 +1,65 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.command.CommandSender;
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.JobsPlayer;
import com.gamingmesh.jobs.economy.PaymentData;
public class limit implements Cmd {
@Override
@JobCommand(700)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
if (args.length > 0) {
Jobs.getCommandManager().sendUsage(sender, "limit");
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
return false;
}
Player player = (Player) sender;
if (!Jobs.getGCManager().MoneyLimitUse && !Jobs.getGCManager().ExpLimitUse && !Jobs.getGCManager().PointLimitUse) {
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.notenabled"));
return true;
}
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
String playername = player.getName();
if (Jobs.getGCManager().MoneyLimitUse)
if (Jobs.paymentLimit.containsKey(playername) && Jobs.paymentLimit.get(playername).GetLeftTime(Jobs.getGCManager().MoneyTimeLimit) > 0) {
PaymentData data = Jobs.paymentLimit.get(playername);
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.lefttime",
"%hour%", data.GetLeftHour(Jobs.getGCManager().MoneyTimeLimit),
"%min%", data.GetLeftMin(Jobs.getGCManager().MoneyTimeLimit),
"%sec%", data.GetLeftsec(Jobs.getGCManager().MoneyTimeLimit)));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.moneylimit",
"%money%", data.GetAmountBylimit(JPlayer.getMoneyLimit()),
"%totalmoney%", JPlayer.getMoneyLimit()));
} else {
int lefttime1 = Jobs.getGCManager().MoneyTimeLimit;
int hour = 0;
int min = 0;
int sec = 0;
if (lefttime1 >= 3600) {
hour = lefttime1 / 3600;
lefttime1 = lefttime1 - (hour * 3600);
if (lefttime1 > 60 && lefttime1 < 3600) {
min = lefttime1 / 60;
sec = lefttime1 - (min * 60);
} else if (lefttime1 < 60)
sec = lefttime1;
} else if (lefttime1 > 60 && lefttime1 < 3600) {
min = lefttime1 / 60;
lefttime1 = lefttime1 - (min * 60);
} else
sec = lefttime1;
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.lefttime", "%hour%", hour,
"%min%", min,
"%sec%", sec));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.moneylimit",
"%money%", "0.0",
"%totalmoney%", JPlayer.getMoneyLimit()));
}
if (Jobs.getGCManager().ExpLimitUse)
if (Jobs.ExpLimit.containsKey(playername) && Jobs.ExpLimit.get(playername).GetLeftTime(Jobs.getGCManager().ExpTimeLimit) > 0) {
PaymentData data = Jobs.ExpLimit.get(playername);
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.leftexptime",
"%hour%", data.GetLeftHour(Jobs.getGCManager().ExpTimeLimit),
"%min%", data.GetLeftMin(Jobs.getGCManager().ExpTimeLimit),
"%sec%", data.GetLeftsec(Jobs.getGCManager().ExpTimeLimit)));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.explimit",
"%exp%", data.GetExpBylimit(JPlayer.getExpLimit()),
"%totalexp%", JPlayer.getExpLimit()));
} else {
int lefttime1 = Jobs.getGCManager().ExpTimeLimit;
int hour = 0;
int min = 0;
int sec = 0;
if (lefttime1 >= 3600) {
hour = lefttime1 / 3600;
lefttime1 = lefttime1 - (hour * 3600);
if (lefttime1 > 60 && lefttime1 < 3600) {
min = lefttime1 / 60;
sec = lefttime1 - (min * 60);
} else if (lefttime1 < 60)
sec = lefttime1;
} else if (lefttime1 > 60 && lefttime1 < 3600) {
min = lefttime1 / 60;
lefttime1 = lefttime1 - (min * 60);
} else
sec = lefttime1;
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.leftexptime",
"%hour%", hour,
"%min%", min,
"%sec%", sec));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.explimit",
"%exp%", "0.0",
"%totalexp%", JPlayer.getExpLimit()));
}
if (Jobs.getGCManager().PointLimitUse)
if (Jobs.PointLimit.containsKey(playername) && Jobs.PointLimit.get(playername).GetLeftTime(Jobs.getGCManager().PointTimeLimit) > 0) {
PaymentData data = Jobs.PointLimit.get(playername);
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.leftpointtime",
"%hour%", data.GetLeftHour(Jobs.getGCManager().PointTimeLimit),
"%min%", data.GetLeftMin(Jobs.getGCManager().PointTimeLimit),
"%sec%", data.GetLeftsec(Jobs.getGCManager().PointTimeLimit)));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.pointlimit",
"%current%", data.GetPointsBylimit(JPlayer.getPointLimit()),
"%total%", JPlayer.getPointLimit()));
} else {
int lefttime1 = Jobs.getGCManager().PointTimeLimit;
int hour = 0;
int min = 0;
int sec = 0;
if (lefttime1 >= 3600) {
hour = lefttime1 / 3600;
lefttime1 = lefttime1 - (hour * 3600);
if (lefttime1 > 60 && lefttime1 < 3600) {
min = lefttime1 / 60;
sec = lefttime1 - (min * 60);
} else if (lefttime1 < 60)
sec = lefttime1;
} else if (lefttime1 > 60 && lefttime1 < 3600) {
min = lefttime1 / 60;
lefttime1 = lefttime1 - (min * 60);
} else
sec = lefttime1;
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.leftpointtime",
"%hour%", hour,
"%min%", min,
"%sec%", sec));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.pointlimit",
"%current%", "0.0",
"%total%", JPlayer.getPointLimit()));
}
return true;
}
}
package com.gamingmesh.jobs.commands.list;
import org.bukkit.command.CommandSender;
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.economy.PaymentData;
import com.gamingmesh.jobs.stuff.TimeManage;
public class limit implements Cmd {
@Override
@JobCommand(700)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
if (args.length > 0) {
Jobs.getCommandManager().sendUsage(sender, "limit");
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
return false;
}
Player player = (Player) sender;
boolean disabled = true;
for (CurrencyType type : CurrencyType.values()) {
if (Jobs.getGCManager().currencyLimitUse.get(type).isEnabled()) {
disabled = false;
break;
}
}
if (disabled) {
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.notenabled"));
return true;
}
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
for (CurrencyType type : CurrencyType.values()) {
if (!Jobs.getGCManager().currencyLimitUse.get(type).isEnabled())
continue;
PaymentData limit = JPlayer.getPaymentLimit();
if (limit == null) {
int lefttime1 = Jobs.getGCManager().currencyLimitUse.get(type).getTimeLimit() * 1000;
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort((long) lefttime1)));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "limit",
"%" + type.getName().toLowerCase() + "%", "0.0",
"%total" + type.getName().toLowerCase() + "%", JPlayer.getLimit(type)));
continue;
}
if (limit.GetLeftTime(type) > 0) {
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort(limit.GetLeftTime(type))));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "limit",
"%" + type.getName().toLowerCase() + "%", (int) (limit.GetAmount(type) * 100) / 100D,
"%total" + type.getName().toLowerCase() + "%", JPlayer.getLimit(type)));
}
}
return true;
}
}

View File

@ -5,7 +5,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.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.stuff.ChatColor;
@ -40,7 +40,7 @@ public class moneyboost implements Cmd {
if (args[0].equalsIgnoreCase("reset") && args[1].equalsIgnoreCase("all")) {
for (Job one : Jobs.getJobs()) {
one.addBoost(BoostType.MONEY, 1.0);
one.addBoost(CurrencyType.MONEY, 1.0);
}
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.moneyboost.output.allreset"));
return true;
@ -48,7 +48,7 @@ public class moneyboost implements Cmd {
boolean found = false;
for (Job one : Jobs.getJobs()) {
if (one.getName().equalsIgnoreCase(args[1])) {
one.addBoost(BoostType.MONEY, 1.0);
one.addBoost(CurrencyType.MONEY, 1.0);
found = true;
break;
}
@ -63,7 +63,7 @@ public class moneyboost implements Cmd {
if (args[0].equalsIgnoreCase("all")) {
for (Job one : Jobs.getJobs()) {
one.addBoost(BoostType.MONEY, rate);
one.addBoost(CurrencyType.MONEY, rate);
}
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.moneyboost.output.boostalladded", "%boost%", rate));
@ -73,7 +73,7 @@ public class moneyboost implements Cmd {
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
job.addBoost(BoostType.MONEY, rate);
job.addBoost(CurrencyType.MONEY, rate);
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.moneyboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
return true;
}

View File

@ -5,7 +5,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.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.stuff.ChatColor;
@ -40,7 +40,7 @@ public class pointboost implements Cmd {
if (args[0].equalsIgnoreCase("reset") && args[1].equalsIgnoreCase("all")) {
for (Job one : Jobs.getJobs()) {
one.addBoost(BoostType.POINTS, 1.0);
one.addBoost(CurrencyType.POINTS, 1.0);
}
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.pointboost.output.allreset"));
return true;
@ -48,7 +48,7 @@ public class pointboost implements Cmd {
boolean found = false;
for (Job one : Jobs.getJobs()) {
if (one.getName().equalsIgnoreCase(args[1])) {
one.addBoost(BoostType.POINTS, 1.0);
one.addBoost(CurrencyType.POINTS, 1.0);
found = true;
break;
}
@ -63,7 +63,7 @@ public class pointboost implements Cmd {
if (args[0].equalsIgnoreCase("all")) {
for (Job one : Jobs.getJobs()) {
one.addBoost(BoostType.POINTS, rate);
one.addBoost(CurrencyType.POINTS, rate);
}
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.pointboost.output.boostalladded", "%boost%", rate));
@ -73,7 +73,7 @@ public class pointboost implements Cmd {
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
job.addBoost(BoostType.POINTS, rate);
job.addBoost(CurrencyType.POINTS, rate);
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.pointboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
return true;
}

View File

@ -38,7 +38,7 @@ import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.DisplayMethod;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobCommands;
@ -346,11 +346,11 @@ public class ConfigManager {
BoostMultiplier b = new BoostMultiplier();
if (itemSection.isDouble("moneyBoost"))
b.add(BoostType.MONEY, itemSection.getDouble("moneyBoost") - 1);
b.add(CurrencyType.MONEY, itemSection.getDouble("moneyBoost") - 1);
if (itemSection.isDouble("pointBoost"))
b.add(BoostType.POINTS, itemSection.getDouble("pointBoost") - 1);
b.add(CurrencyType.POINTS, itemSection.getDouble("pointBoost") - 1);
if (itemSection.isDouble("expBoost"))
b.add(BoostType.EXP, itemSection.getDouble("expBoost") - 1);
b.add(CurrencyType.EXP, itemSection.getDouble("expBoost") - 1);
jobItems.add(new JobItems(node, id, 0, 1, name, lore, enchants, b));
}

View File

@ -32,13 +32,13 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.CurrencyLimit;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.LocaleReader;
import com.gamingmesh.jobs.container.Schedule;
import com.gamingmesh.jobs.dao.JobsDAOMySQL;
import com.gamingmesh.jobs.dao.JobsDAOSQLite;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
public class GeneralConfigManager {
private Jobs plugin;
@ -68,26 +68,8 @@ public class GeneralConfigManager {
public boolean PaymentMethodsPoints;
public boolean PaymentMethodsExp;
// Money limit
public boolean MoneyLimitUse;
public boolean MoneyStopPoint;
public boolean MoneyStopExp;
public int MoneyTimeLimit;
public int MoneyAnnouncmentDelay;
// Point limit
public boolean PointLimitUse;
public boolean PointStopExp;
public boolean PointStopMoney;
public int PointTimeLimit;
public int PointAnnouncmentDelay;
// Exp limit
public boolean ExpLimitUse;
public boolean ExpStopPoint;
public boolean ExpStopMoney;
public int ExpTimeLimit;
public int ExpAnnouncmentDelay;
// Limits
public HashMap<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<CurrencyType, CurrencyLimit>();
public boolean PayForRenaming, PayForEachCraft, SignsEnabled,
SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse,
@ -115,7 +97,7 @@ public class GeneralConfigManager {
public double MinimumOveralPaymentLimit;
public double MinimumOveralPointsLimit;
public HashMap<BoostType, Double> Boost = new HashMap<BoostType, Double>();
public HashMap<CurrencyType, Double> Boost = new HashMap<CurrencyType, Double>();
public double DynamicPaymentMaxPenalty;
public double DynamicPaymentMaxBonus;
@ -138,9 +120,6 @@ public class GeneralConfigManager {
public boolean BossBarsMessageByDefault;
public Parser DynamicPaymentEquation;
public Parser maxMoneyEquation;
public Parser maxExpEquation;
public Parser maxPointEquation;
public boolean DisabledWorldsUse;
public List<String> DisabledWorldsList = new ArrayList<String>();
@ -158,6 +137,10 @@ public class GeneralConfigManager {
return commandArgs;
}
public CurrencyLimit getLimit(CurrencyType type) {
return currencyLimitUse.get(type);
}
public GeneralConfigManager(Jobs plugin) {
this.plugin = plugin;
}
@ -585,14 +568,18 @@ public class GeneralConfigManager {
TakeFromPlayersPayment = c.get("Economy.Taxes.TakeFromPlayersPayment", false);
// Money limit
CurrencyLimit limit = new CurrencyLimit();
c.getW().addComment("Economy.Limit.Money", "Money gain limit", "With this enabled, players will be limited how much they can make in defined time",
"Time in seconds: 60 = 1min, 3600 = 1 hour, 86400 = 24 hours");
MoneyLimitUse = c.get("Economy.Limit.Money.Use", false);
limit.setEnabled(c.get("Economy.Limit.Money.Use", false));
List<CurrencyType> list = new ArrayList<CurrencyType>();
c.getW().addComment("Economy.Limit.Money.StopWithExp", "Do you want to stop money gain when exp limit reached?");
MoneyStopExp = c.get("Economy.Limit.Money.StopWithExp", false);
if (c.get("Economy.Limit.Money.StopWithExp", false))
list.add(CurrencyType.EXP);
c.getW().addComment("Economy.Limit.Money.StopWithPoint", "Do you want to stop money gain when point limit reached?");
MoneyStopPoint = c.get("Economy.Limit.Money.StopWithPoint", false);
if (c.get("Economy.Limit.Money.StopWithPoint", false))
list.add(CurrencyType.POINTS);
limit.setStopWith(list);
c.getW().addComment("Economy.Limit.Money.MoneyLimit",
"Equation to calculate max limit. Option to use totallevel to include players total amount levels of current jobs",
"You can always use simple number to set money limit",
@ -600,28 +587,33 @@ public class GeneralConfigManager {
"So player with 2 jobs with level 15 and 22 will have 685 limit");
String MoneyLimit = c.get("Economy.Limit.Money.MoneyLimit", "500+500*(totallevel/100)");
try {
maxMoneyEquation = new Parser(MoneyLimit);
maxMoneyEquation.setVariable("totallevel", 1);
maxMoneyEquation.getValue();
Parser Equation = new Parser(MoneyLimit);
Equation.setVariable("totallevel", 1);
Equation.getValue();
limit.setMaxEquation(Equation);
} catch (Exception e) {
Jobs.getPluginLogger().warning("MoneyLimit has an invalid value. Disabling money limit!");
MoneyLimitUse = false;
limit.setEnabled(false);
}
c.getW().addComment("Economy.Limit.Money.TimeLimit", "Time in seconds: 60 = 1min, 3600 = 1 hour, 86400 = 24 hours");
MoneyTimeLimit = c.get("Economy.Limit.Money.TimeLimit", 3600);
limit.setTimeLimit(c.get("Economy.Limit.Money.TimeLimit", 3600));
c.getW().addComment("Economy.Limit.Money.AnnouncmentDelay", "Delay between announcements about reached money limit",
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
MoneyAnnouncmentDelay = c.get("Economy.Limit.Money.AnnouncmentDelay", 30);
limit.setAnnouncmentDelay(c.get("Economy.Limit.Money.AnnouncmentDelay", 30));
currencyLimitUse.put(CurrencyType.MONEY, limit);
// Point limit
limit = new CurrencyLimit();
list = new ArrayList<CurrencyType>();
c.getW().addComment("Economy.Limit.Point", "Point gain limit", "With this enabled, players will be limited how much they can make in defined time");
PointLimitUse = c.get("Economy.Limit.Point.Use", false);
limit.setEnabled(c.get("Economy.Limit.Point.Use", false));
c.getW().addComment("Economy.Limit.Point.StopWithExp", "Do you want to stop Point gain when exp limit reached?");
PointStopExp = c.get("Economy.Limit.Point.StopWithExp", false);
if (c.get("Economy.Limit.Point.StopWithExp", false))
list.add(CurrencyType.EXP);
c.getW().addComment("Economy.Limit.Point.StopWithMoney", "Do you want to stop Point gain when money limit reached?");
PointStopMoney = c.get("Economy.Limit.Point.StopWithMoney", false);
if (c.get("Economy.Limit.Point.StopWithMoney", false))
list.add(CurrencyType.MONEY);
limit.setStopWith(list);
c.getW().addComment("Economy.Limit.Point.Limit",
"Equation to calculate max limit. Option to use totallevel to include players total amount levels of current jobs",
"You can always use simple number to set limit",
@ -629,48 +621,54 @@ public class GeneralConfigManager {
"So player with 2 jobs with level 15 and 22 will have 685 limit");
String PointLimit = c.get("Economy.Limit.Point.Limit", "500+500*(totallevel/100)");
try {
maxPointEquation = new Parser(PointLimit);
maxPointEquation.setVariable("totallevel", 1);
maxPointEquation.getValue();
Parser Equation = new Parser(PointLimit);
Equation.setVariable("totallevel", 1);
Equation.getValue();
limit.setMaxEquation(Equation);
} catch (Exception e) {
Jobs.getPluginLogger().warning("PointLimit has an invalid value. Disabling money limit!");
PointLimitUse = false;
limit.setEnabled(false);
}
c.getW().addComment("Economy.Limit.Point.TimeLimit", "Time in seconds: 60 = 1min, 3600 = 1 hour, 86400 = 24 hours");
PointTimeLimit = c.get("Economy.Limit.Point.TimeLimit", 3600);
limit.setTimeLimit(c.get("Economy.Limit.Point.TimeLimit", 3600));
c.getW().addComment("Economy.Limit.Point.AnnouncmentDelay", "Delay between announcements about reached limit",
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
PointAnnouncmentDelay = c.get("Economy.Limit.Point.AnnouncmentDelay", 30);
limit.setAnnouncmentDelay(c.get("Economy.Limit.Point.AnnouncmentDelay", 30));
currencyLimitUse.put(CurrencyType.POINTS, limit);
// Exp limit
limit = new CurrencyLimit();
list = new ArrayList<CurrencyType>();
c.getW().addComment("Economy.Limit.Exp", "Exp gain limit", "With this enabled, players will be limited how much they can get in defined time",
"Time in seconds: 60 = 1min, 3600 = 1 hour, 86400 = 24 hours");
ExpLimitUse = c.get("Economy.Limit.Exp.Use", false);
limit.setEnabled(c.get("Economy.Limit.Exp.Use", false));
c.getW().addComment("Economy.Limit.Exp.StopWithMoney", "Do you want to stop exp gain when money limit reached?");
ExpStopMoney = c.get("Economy.Limit.Exp.StopWithMoney", false);
if (c.get("Economy.Limit.Exp.StopWithMoney", false))
list.add(CurrencyType.MONEY);
c.getW().addComment("Economy.Limit.Exp.StopWithPoint", "Do you want to stop exp gain when point limit reached?");
ExpStopPoint = c.get("Economy.Limit.Exp.StopWithPoint", false);
if (c.get("Economy.Limit.Exp.StopWithPoint", false))
list.add(CurrencyType.POINTS);
limit.setStopWith(list);
c.getW().addComment("Economy.Limit.Exp.Limit", "Equation to calculate max money limit. Option to use totallevel to include players total amount of current jobs",
"You can always use simple number to set exp limit",
"Default equation is: 5000+5000*(totallevel/100), this will add 1% from 5000 for each level player have",
"So player with 2 jobs with level 15 and 22 will have 6850 limit");
String expLimit = c.get("Economy.Limit.Exp.Limit", "5000+5000*(totallevel/100)");
try {
maxExpEquation = new Parser(expLimit);
maxExpEquation.setVariable("totallevel", 1);
maxExpEquation.getValue();
Parser Equation = new Parser(expLimit);
Equation.setVariable("totallevel", 1);
Equation.getValue();
limit.setMaxEquation(Equation);
} catch (Exception e) {
Jobs.getPluginLogger().warning("ExpLimit has an invalid value. Disabling money limit!");
ExpLimitUse = false;
limit.setEnabled(false);
}
c.getW().addComment("Economy.Limit.Exp.TimeLimit", "Time in seconds: 60 = 1min, 3600 = 1 hour, 86400 = 24 hours");
ExpTimeLimit = c.get("Economy.Limit.Exp.TimeLimit", 3600);
limit.setTimeLimit(c.get("Economy.Limit.Exp.TimeLimit", 3600));
c.getW().addComment("Economy.Limit.Exp.AnnouncmentDelay", "Delay between announcements about reached Exp limit",
"Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying");
ExpAnnouncmentDelay = c.get("Economy.Limit.Exp.AnnouncmentDelay", 30);
limit.setAnnouncmentDelay(c.get("Economy.Limit.Exp.AnnouncmentDelay", 30));
currencyLimitUse.put(CurrencyType.EXP, limit);
c.getW().addComment("Economy.Repair.PayForRenaming", "Do you want to give money for only renaming items in anvil",
"Players will get full pay as they would for remairing two items when they only renaming one",
@ -742,10 +740,10 @@ public class GeneralConfigManager {
"Use: jobs.boost.[jobname].money or jobs.boost.[jobname].exp or jobs.boost.[jobname].points or jobs.boost.[jobname].all for all of them with specific jobs name.",
"Use: jobs.boost.all.money or jobs.boost.all.exp or jobs.boost.all.points or jobs.boost.all.all to get boost for all jobs",
"1.25 means that player will get 25% more than others, you can set less than 1 to get less from anothers");
Boost.put(BoostType.EXP, (int) ((c.get("boost.exp", 1D) * 100)-100) / 100D);
Boost.put(BoostType.MONEY, (int) ((c.get("boost.money", 1D) * 100)-100) / 100D);
Boost.put(BoostType.POINTS, (int) ((c.get("boost.points", 1D) * 100)-100) / 100D);
Boost.put(CurrencyType.EXP, (int) ((c.get("boost.exp", 1D) * 100) - 100) / 100D);
Boost.put(CurrencyType.MONEY, (int) ((c.get("boost.money", 1D) * 100) - 100) / 100D);
Boost.put(CurrencyType.POINTS, (int) ((c.get("boost.points", 1D) * 100) - 100) / 100D);
c.getW().addComment("old-job", "Old job save", "Players can leave job and return later with some level loss during that",
"You can fix players level if hes job level is at max level");

View File

@ -61,6 +61,10 @@ public class LanguageManager {
c.get("limitedItem.error.levelup", "&cYou need to levelup in [jobname] to use this item!");
c.get("general.info.toplineseparator", "&7*********************** &6%playername% &7***********************");
c.get("general.info.separator", "&7*******************************************************");
c.get("general.info.time.day", "&e%days% &6days ");
c.get("general.info.time.hours", "&e%hours% &6hours ");
c.get("general.info.time.mins", "&e%mins% &6min ");
c.get("general.info.time.secs", "&e%secs% &6sec ");
c.get("general.admin.error", "&cThere was an error in the command.");
c.get("general.admin.success", "&eYour command has been performed.");
c.get("general.error.noHelpPage", "&cThere is no help page by this number!");
@ -121,18 +125,18 @@ public class LanguageManager {
c.get("command.limit.help.info", "Shows payment limits for jobs");
c.get("command.limit.help.args", "");
c.get("command.limit.output.lefttime", "&eTime left until money limit resets: &2%hour% &ehour &2%min% &emin &2%sec% &esec");
c.get("command.limit.output.moneytime", "&eTime left until money limit resets: &2%time%");
c.get("command.limit.output.moneylimit", "&eMoney limit: &2%money%&e/&2%totalmoney%");
c.get("command.limit.output.leftexptime", "&eTime left until Exp limit resets: &2%hour% &ehour &2%min% &emin &2%sec% &esec");
c.get("command.limit.output.exptime", "&eTime left until Exp limit resets: &2%time%");
c.get("command.limit.output.explimit", "&eExp limit: &2%exp%&e/&2%totalexp%");
c.get("command.limit.output.leftpointtime", "&eTime left until Point limit resets: &2%hour% &ehour &2%min% &emin &2%sec% &esec");
c.get("command.limit.output.pointlimit", "&ePoint limit: &2%current%&e/&2%total%");
c.get("command.limit.output.reachedlimit", "&4You have reached money limit in given time!");
c.get("command.limit.output.reachedlimit2", "&eYou can check your limit with &2/jobs limit &ecommand");
c.get("command.limit.output.reachedExplimit", "&4You have reached exp limit in given time!");
c.get("command.limit.output.reachedExplimit2", "&eYou can check your limit with &2/jobs limit &ecommand");
c.get("command.limit.output.reachedPointlimit", "&4You have reached exp limit in given time!");
c.get("command.limit.output.reachedPointlimit2", "&eYou can check your limit with &2/jobs limit &ecommand");
c.get("command.limit.output.pointstime", "&eTime left until Point limit resets: &2%time%");
c.get("command.limit.output.pointslimit", "&ePoint limit: &2%current%&e/&2%total%");
c.get("command.limit.output.reachedmoneylimit", "&4You have reached money limit in given time!");
c.get("command.limit.output.reachedmoneylimit2", "&eYou can check your limit with &2/jobs limit &ecommand");
c.get("command.limit.output.reachedexplimit", "&4You have reached exp limit in given time!");
c.get("command.limit.output.reachedexplimit2", "&eYou can check your limit with &2/jobs limit &ecommand");
c.get("command.limit.output.reachedpointslimit", "&4You have reached exp limit in given time!");
c.get("command.limit.output.reachedpointslimit2", "&eYou can check your limit with &2/jobs limit &ecommand");
c.get("command.limit.output.notenabled", "&eMoney limit is not enabled");
c.get("command.help.output.info", "Type /jobs [cmd] ? for more information about a command.");

View File

@ -14,7 +14,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.Schedule;
import com.gamingmesh.jobs.stuff.ChatColor;
@ -216,11 +216,11 @@ public class ScheduleManager {
sched.setMessageToBroadcast(path.getStringList("BroadcastMessage"), path.getString("From"), path.getString("Until"));
if (path.contains("Exp") && path.isDouble("Exp"))
sched.setBoost(BoostType.EXP, path.getDouble("Exp", 0D));
sched.setBoost(CurrencyType.EXP, path.getDouble("Exp", 0D));
if (path.contains("Money") && path.isDouble("Money"))
sched.setBoost(BoostType.MONEY, path.getDouble("Money", 0D));
sched.setBoost(CurrencyType.MONEY, path.getDouble("Money", 0D));
if (path.contains("Points") && path.isDouble("Points"))
sched.setBoost(BoostType.POINTS, path.getDouble("Points", 0D));
sched.setBoost(CurrencyType.POINTS, path.getDouble("Points", 0D));
Jobs.getGCManager().BoostSchedule.add(sched);
}
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loaded " + Jobs.getGCManager().BoostSchedule.size() + " schedulers!");

View File

@ -42,3 +42,5 @@
/BpDBAction.class
/DBAction.class
/Boost.class
/CurrencyType.class
/CurrencyLimit.class

View File

@ -24,11 +24,11 @@ public class Boost {
return map.get(boostoff);
}
public double get(BoostOf boostoff, BoostType BT) {
public double get(BoostOf boostoff, CurrencyType BT) {
return get(boostoff, BT, false);
}
public double get(BoostOf boostoff, BoostType BT, boolean percent) {
public double get(BoostOf boostoff, CurrencyType BT, boolean percent) {
if (!map.containsKey(boostoff))
return 0D;
double r = map.get(boostoff).get(BT);
@ -39,11 +39,11 @@ public class Boost {
return r;
}
public double getFinal(BoostType BT) {
public double getFinal(CurrencyType BT) {
return getFinal(BT, false);
}
public double getFinal(BoostType BT, boolean percent) {
public double getFinal(CurrencyType BT, boolean percent) {
double r = 0D;
for (BoostOf one : BoostOf.values()) {
if (!map.containsKey(one))

View File

@ -1,33 +1,33 @@
package com.gamingmesh.jobs.container;
public class BoostCounter {
BoostType type;
double boost;
Long calculatedon;
public BoostCounter(BoostType type, double boost, Long calculatedon) {
this.type = type;
this.boost = boost;
this.calculatedon = calculatedon;
}
public BoostType getType() {
return this.type;
}
public long getTime() {
return this.calculatedon;
}
public double getBoost() {
return this.boost;
}
public void setTime(long time) {
this.calculatedon = time;
}
public void setBoost(double boost) {
this.boost = boost;
}
}
package com.gamingmesh.jobs.container;
public class BoostCounter {
CurrencyType type;
double boost;
Long calculatedon;
public BoostCounter(CurrencyType type, double boost, Long calculatedon) {
this.type = type;
this.boost = boost;
this.calculatedon = calculatedon;
}
public CurrencyType getType() {
return this.type;
}
public long getTime() {
return this.calculatedon;
}
public double getBoost() {
return this.boost;
}
public void setTime(long time) {
this.calculatedon = time;
}
public void setBoost(double boost) {
this.boost = boost;
}
}

View File

@ -4,34 +4,34 @@ import java.util.HashMap;
public class BoostMultiplier {
HashMap<BoostType, Double> map = new HashMap<BoostType, Double>();
HashMap<CurrencyType, Double> map = new HashMap<CurrencyType, Double>();
public BoostMultiplier() {
for (BoostType one : BoostType.values()) {
for (CurrencyType one : CurrencyType.values()) {
map.put(one, 0D);
}
}
public BoostMultiplier add(BoostType type, double amount) {
public BoostMultiplier add(CurrencyType type, double amount) {
map.put(type, amount);
return this;
}
public BoostMultiplier add(double amount) {
for (BoostType one : BoostType.values()) {
for (CurrencyType one : CurrencyType.values()) {
map.put(one, amount);
}
return this;
}
public double get(BoostType type) {
public double get(CurrencyType type) {
if (!map.containsKey(type))
return 0D;
return this.map.get(type);
}
public void add(BoostMultiplier armorboost) {
for (BoostType one : BoostType.values()) {
for (CurrencyType one : CurrencyType.values()) {
double r = armorboost.get(one);
map.put(one, get(one) + r);
}

View File

@ -0,0 +1,66 @@
package com.gamingmesh.jobs.container;
import java.util.List;
import com.gamingmesh.jobs.resources.jfep.Parser;
public class CurrencyLimit {
private boolean enabled;
private List<CurrencyType> stopWith;
private int timeLimit;
private int announcmentDelay;
private Parser maxEquation;
public CurrencyLimit(boolean enabled, List<CurrencyType> stopWith, int timeLimit, int announcmentDelay, Parser maxEquation) {
this.enabled = enabled;
this.stopWith = stopWith;
this.timeLimit = timeLimit;
this.announcmentDelay = announcmentDelay;
this.maxEquation = maxEquation;
}
public CurrencyLimit() {
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public List<CurrencyType> getStopWith() {
return stopWith;
}
public void setStopWith(List<CurrencyType> stopWith) {
this.stopWith = stopWith;
}
public int getTimeLimit() {
return timeLimit;
}
public void setTimeLimit(int timeLimit) {
this.timeLimit = timeLimit;
}
public int getAnnouncmentDelay() {
return announcmentDelay;
}
public void setAnnouncmentDelay(int announcmentDelay) {
this.announcmentDelay = announcmentDelay;
}
public Parser getMaxEquation() {
return maxEquation;
}
public void setMaxEquation(Parser maxEquation) {
this.maxEquation = maxEquation;
}
}

View File

@ -18,17 +18,26 @@
package com.gamingmesh.jobs.container;
public enum BoostType {
public enum CurrencyType {
MONEY("Money"),
EXP("Exp"),
POINTS("Points");
private String name;
private BoostType(String name) {
this.name = name;
private CurrencyType(String name) {
this.name = name;
}
public String getName() {
return name;
return name;
}
public static CurrencyType getByName(String name) {
for (CurrencyType one : values()) {
if (one.getName().equalsIgnoreCase(name))
return one;
}
return null;
}
}

View File

@ -116,7 +116,7 @@ public class Job {
this.GUIitem = GUIitem;
}
public void addBoost(BoostType type, double Point) {
public void addBoost(CurrencyType type, double Point) {
this.boost.add(type, Point - 1D);
}

View File

@ -30,9 +30,9 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.economy.PaymentData;
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 {
@ -42,6 +42,8 @@ public class JobsPlayer {
public UUID playerUUID;
public ArrayList<JobProgression> progression = new ArrayList<JobProgression>();
private PaymentData paymentLimits = null;
private HashMap<String, ArrayList<BoostCounter>> boostCounter = new HashMap<String, ArrayList<BoostCounter>>();
// display honorific
@ -56,9 +58,7 @@ public class JobsPlayer {
private double VipSpawnerMultiplier = 0D;
private int MoneyLimit = 0;
private int ExpLimit = 0;
private int PointLimit = 0;
private HashMap<CurrencyType, Integer> limits = new HashMap<CurrencyType, Integer>();
private int userid = -1;
@ -78,6 +78,41 @@ public class JobsPlayer {
this.player = Bukkit.getPlayer(userName);
}
public PaymentData getPaymentLimit() {
if (paymentLimits == null) {
paymentLimits = Jobs.getJobsDAO().getPlayersLimits(this);
}
return paymentLimits;
}
public boolean isUnderLimit(CurrencyType type, Double amount) {
Player player = this.getPlayer();
if (player == null)
return true;
if (amount == 0)
return true;
CurrencyLimit limit = Jobs.getGCManager().getLimit(type);
if (!limit.isEnabled())
return true;
PaymentData data = getPaymentLimit();
if (data.IsReachedLimit(type, this.limits.get(type))) {
if (player.isOnline() && !data.isInformed() && !data.isReseted()) {
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit"));
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit2"));
data.setInformed();
}
if (data.IsAnnounceTime(limit.getAnnouncmentDelay()) && player.isOnline()) {
Jobs.getActionBar().send(player, Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", data.GetLeftTime(type)));
}
if (data.isReseted())
data.setReseted(false);
return false;
}
data.AddAmount(type, amount);
return true;
}
public void setPlayer(Player p) {
this.player = p;
}
@ -149,11 +184,11 @@ public class JobsPlayer {
* Get the Boost
* @return the Boost
*/
public double getBoost(String JobName, BoostType type) {
public double getBoost(String JobName, CurrencyType type) {
return getBoost(JobName, type, false);
}
public double getBoost(String JobName, BoostType type, boolean force) {
public double getBoost(String JobName, CurrencyType type, boolean force) {
double Boost = 0D;
@ -195,7 +230,7 @@ public class JobsPlayer {
return Boost;
}
private Double getPlayerBoost(String JobName, BoostType type) {
private Double getPlayerBoost(String JobName, CurrencyType type) {
double Boost = 0D;
if (Perm.hasPermission(player, "jobs.boost." + JobName + "." + type.getName().toLowerCase()) ||
Perm.hasPermission(player, "jobs.boost." + JobName + ".all") ||
@ -216,60 +251,26 @@ public class JobsPlayer {
}
/**
* Reloads money limit for this player.
* Reloads limit for this player.
*/
public void reloadMoney() {
public void reload(CurrencyType type) {
int TotalLevel = 0;
for (JobProgression prog : progression) {
TotalLevel += prog.getLevel();
}
Parser eq = Jobs.getGCManager().maxMoneyEquation;
Parser eq = Jobs.getGCManager().currencyLimitUse.get(type).getMaxEquation();
eq.setVariable("totallevel", TotalLevel);
MoneyLimit = (int) eq.getValue();
}
/**
* Reloads exp limit for this player.
*/
public void reloadExp() {
int TotalLevel = 0;
for (JobProgression prog : progression) {
TotalLevel += prog.getLevel();
}
Parser eq = Jobs.getGCManager().maxExpEquation;
eq.setVariable("totallevel", TotalLevel);
ExpLimit = (int) eq.getValue();
}
/**
* Reloads exp limit for this player.
*/
public void reloadPoint() {
int TotalLevel = 0;
for (JobProgression prog : progression) {
TotalLevel += prog.getLevel();
}
Parser eq = Jobs.getGCManager().maxPointEquation;
eq.setVariable("totallevel", TotalLevel);
PointLimit = (int) eq.getValue();
limits.put(type, (int) eq.getValue());
}
public void reloadLimits() {
reloadMoney();
reloadExp();
reloadPoint();
for (CurrencyType type : CurrencyType.values()) {
reload(type);
}
}
public int getMoneyLimit() {
return this.MoneyLimit;
}
public int getExpLimit() {
return this.ExpLimit;
}
public int getPointLimit() {
return this.PointLimit;
public int getLimit(CurrencyType type) {
return this.limits.get(type);
}
/**
@ -606,6 +607,7 @@ public class JobsPlayer {
dao.save(this);
dao.saveLog(this);
dao.savePoints(this);
dao.recordPlayersLimits(this);
setSaved(true);
}
// }

View File

@ -82,11 +82,11 @@ public class Schedule {
return this.stoped;
}
public void setBoost(BoostType type, double amount) {
public void setBoost(CurrencyType type, double amount) {
this.BM.add(type, amount - 1);
}
public double getBoost(BoostType type) {
public double getBoost(CurrencyType type) {
return this.BM.get(type);
}

View File

@ -40,6 +40,7 @@ import org.bukkit.util.Vector;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.BlockProtection;
import com.gamingmesh.jobs.container.Convert;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.DBAction;
import com.gamingmesh.jobs.container.ExploreChunk;
import com.gamingmesh.jobs.container.ExploreRegion;
@ -51,7 +52,7 @@ import com.gamingmesh.jobs.container.LogAmounts;
import com.gamingmesh.jobs.container.PlayerInfo;
import com.gamingmesh.jobs.container.PlayerPoints;
import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.stuff.TimeManage;
/**
@ -85,9 +86,8 @@ public abstract class JobsDAO {
}
try {
if (version <= 1)
checkUpdate();
else {
checkUpdate();
if (version > 1) {
if (version <= 2)
checkUpdate2();
checkUpdate4();
@ -111,6 +111,7 @@ public abstract class JobsDAO {
}
loadAllSavedJobs();
}
protected abstract void setupConfig() throws SQLException;
@ -386,6 +387,72 @@ public abstract class JobsDAO {
return jobs;
}
public synchronized void recordPlayersLimits(JobsPlayer jPlayer) {
JobsConnection conn = getConnection();
if (conn == null)
return;
PreparedStatement prest = null;
try {
prest = conn.prepareStatement("DELETE FROM `" + prefix + "limits` WHERE `userid` = ?;");
prest.setInt(1, jPlayer.getUserId());
prest.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(prest);
}
try {
PaymentData limit = jPlayer.getPaymentLimit();
for (CurrencyType type : CurrencyType.values()) {
if (limit == null)
continue;
if (limit.GetAmount(type) == 0D)
continue;
if (limit.GetLeftTime(type) < 0)
continue;
prest = conn.prepareStatement("INSERT INTO `" + prefix + "limits` (`userid`, `type`, `collected`, `started`) VALUES (?, ?, ?, ?);");
prest.setInt(1, jPlayer.getUserId());
prest.setString(2, type.getName());
prest.setDouble(3, limit.GetAmount(type));
prest.setLong(4, limit.GetTime(type));
prest.execute();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(prest);
}
}
public synchronized PaymentData getPlayersLimits(JobsPlayer jPlayer) {
PaymentData data = new PaymentData();
JobsConnection conn = getConnection();
if (conn == null)
return data;
PreparedStatement prest = null;
ResultSet res = null;
try {
prest = conn.prepareStatement("SELECT `type`, `collected`, `started` FROM `" + prefix + "limits` WHERE `userid` = ?;");
prest.setInt(1, jPlayer.getUserId());
res = prest.executeQuery();
while (res.next()) {
CurrencyType type = CurrencyType.getByName(res.getString("type"));
if (type == null)
continue;
data.AddNewAmount(type, res.getDouble("collected"), res.getLong("started"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(res);
close(prest);
}
return data;
}
/**
* Join a job (create player-job entry from storage)
* @param player - player that wishes to join the job
@ -882,22 +949,28 @@ public abstract class JobsDAO {
}
}
public void savePoints(JobsPlayer player) {
public void savePoints(JobsPlayer jPlayer) {
JobsConnection conn = getConnection();
if (conn == null)
return;
PreparedStatement prest2 = null;
try {
prest2 = conn.prepareStatement("DELETE FROM `" + prefix + "points` WHERE `userid` = ?;");
prest2.setInt(1, jPlayer.getUserId());
prest2.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(prest2);
}
PreparedStatement prest = null;
try {
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(player.getPlayerUUID());
String req = "UPDATE `" + prefix + "points` SET `totalpoints` = ?, `currentpoints` = ? WHERE `userid` = ?;";
if (pointInfo.isNewEntry()) {
pointInfo.setNewEntry(false);
req = "INSERT INTO `" + prefix + "points` (`totalpoints`, `currentpoints`, `userid`) VALUES (?, ?, ?);";
}
prest = conn.prepareStatement(req);
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID());
prest = conn.prepareStatement("INSERT INTO `" + prefix + "points` (`totalpoints`, `currentpoints`, `userid`) VALUES (?, ?, ?);");
prest.setDouble(1, pointInfo.getTotalPoints());
prest.setDouble(2, pointInfo.getCurrentPoints());
prest.setInt(3, player.getUserId());
prest.setInt(3, jPlayer.getUserId());
prest.execute();
} catch (SQLException e) {
e.printStackTrace();

View File

@ -118,6 +118,7 @@ public class JobsDAOMySQL extends JobsDAO {
createDefaultExploreBase();
createDefaultUsersBase();
createDefaultBlockProtection();
createDefaultLimitBase();
}
@Override
@ -814,6 +815,16 @@ public class JobsDAOMySQL extends JobsDAO {
}
return true;
}
private boolean createDefaultLimitBase() {
try {
executeSQL("CREATE TABLE IF NOT EXISTS `" + getPrefix()
+ "limits` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` int, `type` varchar(36), `collected` double, `started` bigint);");
} catch (SQLException e) {
return false;
}
return true;
}
@Override
protected boolean dropDataBase(String name) {

View File

@ -123,6 +123,7 @@ public class JobsDAOSQLite extends JobsDAO {
createDefaultExploreBase();
createDefaultUsersBase();
createDefaultBlockProtection();
createDefaultLimitBase();
}
@Override
@ -880,6 +881,16 @@ public class JobsDAOSQLite extends JobsDAO {
}
return true;
}
private boolean createDefaultLimitBase() {
try {
executeSQL("CREATE TABLE IF NOT EXISTS `" + getPrefix()
+ "limits` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `type` varchar(36), `collected` double, `started` bigint);");
} catch (SQLException e) {
return false;
}
return true;
}
@Override
protected boolean dropDataBase(String name) {

View File

@ -1,210 +1,145 @@
package com.gamingmesh.jobs.economy;
public class PaymentData {
Long time = 0L;
Long lastAnnouced = 0L;
Double Payment = 0.0;
Double Points = 0.0;
Double Exp = 0.0;
public boolean Informed = false;
public boolean Reseted = false;
public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) {
this.time = time;
this.Payment = Payment;
this.Points = Points;
this.Exp = Exp;
this.lastAnnouced = lastAnnouced;
this.Informed = Informed;
}
public PaymentData() {
}
public Long GetTime() {
return this.time;
}
public void setReseted(boolean state) {
this.Reseted = state;
}
public boolean isReseted() {
return this.Reseted;
}
public Double GetAmount() {
return this.Payment;
}
public Double GetAmountBylimit(int limit) {
if (this.Payment > limit)
return (double) limit;
return (int) (this.Payment * 100) / 100.0;
}
public Double GetPoints() {
return this.Points;
}
public Double GetPointsBylimit(int limit) {
if (this.Points > limit)
return (double) limit;
return (int) (this.Points * 100) / 100.0;
}
public Double GetExpBylimit(int limit) {
if (this.Exp > limit)
return (double) limit;
return (int) (this.Exp * 100) / 100.0;
}
public Long GetLastAnnounced() {
return this.lastAnnouced;
}
public boolean IsAnnounceTime(int t) {
if (this.lastAnnouced + (t * 1000) > System.currentTimeMillis())
return false;
SetAnnouncmentTime();
return true;
}
public void SetAnnouncmentTime() {
this.lastAnnouced = System.currentTimeMillis();
}
public void AddNewAmount(Double Payment) {
this.time = System.currentTimeMillis();
this.Payment = Payment;
}
public void AddNewPoints(Double Points) {
this.time = System.currentTimeMillis();
this.Points = Points;
}
public void Setinformed() {
this.Informed = true;
}
public void SetNotInformed() {
this.Informed = false;
}
public void AddAmount(Double Payment) {
this.Payment = this.Payment + Payment;
}
public void AddPoints(Double Points) {
this.Points = this.Points + Points;
}
public void AddExpAmount(Double Exp) {
this.Exp = this.Exp + Exp;
}
public int GetLeftTime(int time) {
int left = 0;
if (this.time + (time * 1000) > System.currentTimeMillis())
left = (int) ((this.time + (time * 1000) - System.currentTimeMillis()) / 1000);
return left;
}
public boolean IsOverMoneyLimit(int limit) {
if (this.Payment < limit)
return false;
return true;
}
public boolean IsOverPointsLimit(int limit) {
if (this.Points < limit)
return false;
return true;
}
public boolean IsOverExpLimit(int limit) {
if (this.Exp < limit)
return false;
return true;
}
public boolean IsOverTimeLimit(int time) {
if (this.time + (time * 1000) > System.currentTimeMillis())
return false;
if (this.Informed)
this.Informed = false;
this.time = System.currentTimeMillis();
this.Payment = 0.0;
this.Exp = 0.0;
this.Points = 0.0;
this.Reseted = true;
return true;
}
public boolean IsReachedMoneyLimit(int time, int money) {
if (IsOverTimeLimit(time))
return true;
if (IsOverMoneyLimit(money))
return true;
return false;
}
public boolean IsReachedExpLimit(int time, int exp) {
if (IsOverTimeLimit(time))
return true;
if (IsOverExpLimit(exp))
return true;
return false;
}
public boolean IsReachedPointLimit(int time, int point) {
if (IsOverTimeLimit(time))
return true;
if (IsOverPointsLimit(point))
return true;
return false;
}
@SuppressWarnings("cast")
public int GetLeftsec(int time) {
int lefttime1 = GetLeftTime(time);
int sec = 0;
if (lefttime1 >= 3600) {
lefttime1 = lefttime1 - ((int) (lefttime1 / 3600) * 3600);
if (lefttime1 > 60 && lefttime1 < 3600) {
sec = lefttime1 - ((int) (lefttime1 / 60) * 60);
} else if (lefttime1 < 60)
sec = lefttime1;
} else if (lefttime1 > 60 && lefttime1 < 3600) {
sec = lefttime1 - ((int) (lefttime1 / 60) * 60);
} else
sec = lefttime1;
return sec;
}
@SuppressWarnings("cast")
public int GetLeftMin(int time) {
int lefttime1 = GetLeftTime(time);
int min = 0;
if (lefttime1 >= 3600) {
lefttime1 = lefttime1 - ((int) (lefttime1 / 3600) * 3600);
if (lefttime1 > 60 && lefttime1 < 3600)
min = lefttime1 / 60;
} else if (lefttime1 > 60 && lefttime1 < 3600)
min = lefttime1 / 60;
return min;
}
public int GetLeftHour(int time) {
int lefttime1 = GetLeftTime(time);
int hour = 0;
if (lefttime1 >= 3600) {
hour = lefttime1 / 3600;
}
return hour;
}
}
package com.gamingmesh.jobs.economy;
import java.util.HashMap;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.stuff.Debug;
public class PaymentData {
Long lastAnnouced = 0L;
HashMap<CurrencyType, Double> payments = new HashMap<CurrencyType, Double>();
HashMap<CurrencyType, Long> paymentsTimes = new HashMap<CurrencyType, Long>();
private boolean Informed = false;
private boolean Reseted = false;
public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) {
paymentsTimes.put(CurrencyType.EXP, time);
paymentsTimes.put(CurrencyType.MONEY, time);
paymentsTimes.put(CurrencyType.POINTS, time);
payments.put(CurrencyType.EXP, Exp);
payments.put(CurrencyType.MONEY, Payment);
payments.put(CurrencyType.POINTS, Points);
this.lastAnnouced = lastAnnouced;
this.Informed = Informed;
}
public PaymentData(CurrencyType type, Double amount) {
paymentsTimes.put(type, System.currentTimeMillis());
payments.put(type, amount);
this.lastAnnouced = 0L;
this.Informed = false;
}
public PaymentData() {
resetLimits();
}
public Long GetTime(CurrencyType type) {
return paymentsTimes.get(type);
}
public void setReseted(boolean state) {
this.Reseted = state;
}
public boolean isReseted() {
return this.Reseted;
}
public Double GetAmount(CurrencyType type) {
if (!payments.containsKey(type))
return 0D;
return payments.get(type);
}
public Double GetAmountBylimit(CurrencyType type, int limit) {
if (GetAmount(type) > limit)
return (double) limit;
return (int) (GetAmount(type) * 100) / 100.0;
}
public Long GetLastAnnounced() {
return this.lastAnnouced;
}
public boolean IsAnnounceTime(int t) {
if (this.lastAnnouced + (t * 1000) > System.currentTimeMillis())
return false;
SetAnnouncmentTime();
return true;
}
public void SetAnnouncmentTime() {
this.lastAnnouced = System.currentTimeMillis();
}
public void AddNewAmount(CurrencyType type, Double Payment) {
AddNewAmount( type, Payment, null);
}
public void AddNewAmount(CurrencyType type, Double Payment, Long time) {
paymentsTimes.put(type, time == null ? System.currentTimeMillis() : time);
payments.put(type, Payment);
}
public void setInformed() {
this.Informed = true;
}
public void setNotInformed() {
this.Informed = false;
}
public void AddAmount(CurrencyType type, Double Payment) {
payments.put(type, payments.get(type) + Payment);
}
public long GetLeftTime(CurrencyType type) {
long left = 0;
if (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis())
left = (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) - System.currentTimeMillis());
return left;
}
public boolean IsOverLimit(CurrencyType type, int limit) {
if (this.payments.get(type) < limit)
return false;
Debug.D(type.getName() + " limit reach money");
return true;
}
public boolean IsOverTimeLimit(CurrencyType type) {
if (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis())
return false;
if (this.Informed)
this.Informed = false;
resetLimits();
Debug.D(type.getName() + " limit reach time");
return true;
}
public void resetLimits() {
for (CurrencyType type : CurrencyType.values()) {
AddNewAmount(type, 0D);
}
this.Reseted = true;
}
public boolean IsReachedLimit(CurrencyType type, int money) {
if (IsOverTimeLimit(type))
return true;
if (IsOverLimit(type, money))
return true;
return false;
}
public boolean isInformed() {
return Informed;
}
public void setInformed(boolean informed) {
Informed = informed;
}
}

View File

@ -4,6 +4,8 @@ package com.gamingmesh.jobs.stuff;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.gamingmesh.jobs.Jobs;
public class TimeManage {
public static int timeInInt() {
return timeInInt(System.currentTimeMillis());
@ -15,4 +17,64 @@ public class TimeManage {
calendar.setTimeInMillis(time);
return Integer.valueOf(formatter.format(calendar.getTime()));
}
public static String to24hourShort(Long ticks) {
long days = toDays(ticks);
long hours = toHours(ticks);
long minutes = toMin(ticks);
long sec = toSec(ticks);
String time = "";
// CMI.d(hours);
if (days > 0)
time += Jobs.getLanguage().getMessage("general.info.time.days", "%days%", days);
if (hours > 0 || (minutes > 0 || sec > 0) && days != 0 && hours == 0)
time += Jobs.getLanguage().getMessage("general.info.time.hours", "%hours%", hours);
if (minutes > 0 || sec > 0 && minutes == 0 && (hours != 0 || days != 0))
time += Jobs.getLanguage().getMessage("general.info.time.mins", "%mins%", minutes);
if (sec > 0)
time += Jobs.getLanguage().getMessage("general.info.time.secs", "%secs%", sec);
if (time.isEmpty())
time += Jobs.getLanguage().getMessage("general.info.time.secs", "%secs%", 0);
return time;
}
public static long toDays(Long ticks) {
long days = ticks / 1000 / 60 / 60 / 24;
return days;
}
public static long toMinutes(Long ticks) {
long d = toDays(ticks);
ticks = ticks - (d * 1000 * 60 * 60 * 24);
long h = toHours(ticks);
long minutes = (ticks - (h * 60 * 60 * 1000)) / 1000 / 60;
return minutes;
}
public static long toHours(Long ticks) {
long d = toDays(ticks);
long hours = (ticks - (d * 1000 * 60 * 60 * 24)) / 1000 / 60 / 60;
return hours;
}
public static long toSec(Long ticks) {
return (ticks - ((int) (ticks / (60 * 1000)) * 60 * 1000)) / 1000;
}
public static long toMin(Long ticks) {
return (ticks - ((int) (ticks / (60 * 60 * 1000)) * 60 * 60 * 1000)) / (1000 * 60);
}
public static long toHour(Long ticks) {
return (ticks - ((int) (ticks / (24 * 60 * 60 * 1000)) * 24 * 60 * 60 * 1000)) / (1000 * 60 * 60);
}
}