1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-18 06:01:46 +01:00

Improve minimum overal payments conflicting with only money limit

This commit is contained in:
montlikadani 2021-04-29 18:05:18 +02:00
parent c8b4eaa479
commit 36075276f8
6 changed files with 79 additions and 64 deletions

View File

@ -195,9 +195,13 @@ public class Jobs extends JavaPlugin {
if (papi == null || !papi.isEnabled()) if (papi == null || !papi.isEnabled())
return false; return false;
if (Integer.parseInt(papi try {
.getDescription().getVersion().replaceAll("[^\\d]", "")) >= 2100 && new PlaceholderAPIHook(this).register()) { if (Integer.parseInt(papi
consoleMsg("&e[Jobs] PlaceholderAPI hooked."); .getDescription().getVersion().replaceAll("[^\\d]", "")) >= 2100 && new PlaceholderAPIHook(this).register()) {
consoleMsg("&e[Jobs] PlaceholderAPI hooked.");
}
} catch (NumberFormatException ex) {
return false;
} }
return true; return true;
@ -1000,26 +1004,29 @@ public class Jobs extends JavaPlugin {
} }
// Calculate income // Calculate income
if (income != 0D) { if (income != 0D) {
income = boost.getFinalAmount(CurrencyType.MONEY, income); income = boost.getFinalAmount(CurrencyType.MONEY, income);
if (gConfigManager.useMinimumOveralPayment && income > 0) { if (gConfigManager.useMinimumOveralPayment && income > 0) {
double maxLimit = income * gConfigManager.MinimumOveralPaymentLimit; double maxLimit = income * gConfigManager.MinimumOveralPaymentLimit;
if (income < maxLimit) if (income < maxLimit)
income = maxLimit; income = maxLimit;
} }
} }
// Calculate points // Calculate points
if (pointAmount != 0D) { if (pointAmount != 0D) {
pointAmount = boost.getFinalAmount(CurrencyType.POINTS, pointAmount); pointAmount = boost.getFinalAmount(CurrencyType.POINTS, pointAmount);
if (gConfigManager.useMinimumOveralPoints && pointAmount > 0) { if (gConfigManager.useMinimumOveralPoints && pointAmount > 0) {
double maxLimit = pointAmount * gConfigManager.MinimumOveralPaymentLimit; double maxLimit = pointAmount * gConfigManager.MinimumOveralPointsLimit;
if (pointAmount < maxLimit) if (pointAmount < maxLimit)
pointAmount = maxLimit; pointAmount = maxLimit;
} }
} }
if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) {
if (gConfigManager.useMaxPaymentCurve) { if (gConfigManager.useMaxPaymentCurve) {
double percentOver = jPlayer.percentOverLimit(CurrencyType.MONEY); double percentOver = jPlayer.percentOverLimit(CurrencyType.MONEY);
@ -1136,8 +1143,10 @@ public class Jobs extends JavaPlugin {
// Calculate income // Calculate income
if (income != 0D) { if (income != 0D) {
income = boost.getFinalAmount(CurrencyType.MONEY, income); income = boost.getFinalAmount(CurrencyType.MONEY, income);
if (gConfigManager.useMinimumOveralPayment && income > 0) { if (gConfigManager.useMinimumOveralPayment && income > 0) {
double maxLimit = income * gConfigManager.MinimumOveralPaymentLimit; double maxLimit = income * gConfigManager.MinimumOveralPaymentLimit;
if (income < maxLimit) if (income < maxLimit)
income = maxLimit; income = maxLimit;
} }
@ -1146,20 +1155,25 @@ public class Jobs extends JavaPlugin {
// Calculate points // Calculate points
if (pointAmount != 0D) { if (pointAmount != 0D) {
pointAmount = boost.getFinalAmount(CurrencyType.POINTS, pointAmount); pointAmount = boost.getFinalAmount(CurrencyType.POINTS, pointAmount);
if (gConfigManager.useMinimumOveralPoints && pointAmount > 0) { if (gConfigManager.useMinimumOveralPoints && pointAmount > 0) {
double maxLimit = pointAmount * gConfigManager.MinimumOveralPaymentLimit; double maxLimit = pointAmount * gConfigManager.MinimumOveralPointsLimit;
if (pointAmount < maxLimit) if (pointAmount < maxLimit)
pointAmount = maxLimit; pointAmount = maxLimit;
} }
} }
// Calculate exp // Calculate exp
expAmount = boost.getFinalAmount(CurrencyType.EXP, expAmount); if (expAmount != 0D) {
expAmount = boost.getFinalAmount(CurrencyType.EXP, expAmount);
if (gConfigManager.useMinimumOveralPayment && expAmount > 0) { if (gConfigManager.useMinimumOveralExp && expAmount > 0) {
double maxLimit = expAmount * gConfigManager.MinimumOveralPaymentLimit; double maxLimit = expAmount * gConfigManager.minimumOveralExpLimit;
if (expAmount < maxLimit)
expAmount = maxLimit; if (expAmount < maxLimit)
expAmount = maxLimit;
}
} }
if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) {

View File

@ -102,12 +102,9 @@ public class JobsCommands implements CommandExecutor {
private String getUsage(String cmd) { private String getUsage(String cmd) {
String cmdString = Jobs.getLanguage().getMessage("command.help.output.cmdFormat", "[command]", Jobs.getLanguage().getMessage("command.help.output.label") + " " + cmd); String cmdString = Jobs.getLanguage().getMessage("command.help.output.cmdFormat", "[command]", Jobs.getLanguage().getMessage("command.help.output.label") + " " + cmd);
String key = "command." + cmd + ".help.args"; String msg = Jobs.getLanguage().getMessage("command." + cmd + ".help.args");
if (Jobs.getLanguage().containsKey(key) && !Jobs.getLanguage().getMessage(key).isEmpty()) {
cmdString = cmdString.replace("[arguments]", Jobs.getLanguage().getMessage(key));
} else
cmdString = cmdString.replace("[arguments]", "");
cmdString = cmdString.replace("[arguments]", !msg.isEmpty() ? msg : "");
return cmdString; return cmdString;
} }

View File

@ -68,7 +68,7 @@ public class GeneralConfigManager {
private int ResetTimeHour, ResetTimeMinute, DailyQuestsSkips, FurnacesMaxDefault, BrewingStandsMaxDefault, private int ResetTimeHour, ResetTimeMinute, DailyQuestsSkips, FurnacesMaxDefault, BrewingStandsMaxDefault,
BrowseAmountToShow, JobsGUIRows, JobsGUIBackButton, JobsGUINextButton, JobsGUIStartPosition, JobsGUIGroupAmount, JobsGUISkipAmount; BrowseAmountToShow, JobsGUIRows, JobsGUIBackButton, JobsGUINextButton, JobsGUIStartPosition, JobsGUIGroupAmount, JobsGUISkipAmount;
public double skipQuestCost, MinimumOveralPaymentLimit, MinimumOveralPointsLimit, MonsterDamagePercentage, public double skipQuestCost, MinimumOveralPaymentLimit, minimumOveralExpLimit, MinimumOveralPointsLimit, MonsterDamagePercentage,
DynamicPaymentMaxPenalty, DynamicPaymentMaxBonus, TaxesAmount; DynamicPaymentMaxPenalty, DynamicPaymentMaxBonus, TaxesAmount;
public Double TreeFellerMultiplier, gigaDrillMultiplier, superBreakerMultiplier; public Double TreeFellerMultiplier, gigaDrillMultiplier, superBreakerMultiplier;
@ -85,7 +85,7 @@ public class GeneralConfigManager {
PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps, PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps,
BrowseUseNewLook, payExploringWhenGliding = false, disablePaymentIfMaxLevelReached, disablePaymentIfRiding, BrowseUseNewLook, payExploringWhenGliding = false, disablePaymentIfMaxLevelReached, disablePaymentIfRiding,
boostedItemsInOffHand = false, boostedItemsInMainHand, boostedArmorItems/*, preventCropResizePayment*/, payItemDurabilityLoss, boostedItemsInOffHand = false, boostedItemsInMainHand, boostedArmorItems/*, preventCropResizePayment*/, payItemDurabilityLoss,
applyToNegativeIncome, useMinimumOveralPayment, useMinimumOveralPoints, useBreederFinder, applyToNegativeIncome, useMinimumOveralPayment, useMinimumOveralPoints, useMinimumOveralExp, useBreederFinder,
CancelCowMilking, fixAtMaxLevel, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, CancelCowMilking, fixAtMaxLevel, TitleChangeChat, TitleChangeActionBar, LevelChangeChat,
LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAccountChat, LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAccountChat,
EmptyServerAccountActionBar, ActionBarsMessageByDefault, aBarSilentMode, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, EmptyServerAccountActionBar, ActionBarsMessageByDefault, aBarSilentMode, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment,
@ -556,15 +556,26 @@ public class GeneralConfigManager {
applyToNegativeIncome = c.get("Economy.ApplyToNegativeIncome", false); applyToNegativeIncome = c.get("Economy.ApplyToNegativeIncome", false);
c.addComment("Economy.MinimumOveralPayment.use", c.addComment("Economy.MinimumOveralPayment.use",
"Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money", "Determines minimum payment.",
"In example if player uses McMMO treefeller and earns only 20%, but at same time player gets 25% penalty from dynamic payment.",
"The player can 'get' negative amount of money",
"This will limit it to particular percentage", "Works only when original payment is above 0"); "This will limit it to particular percentage", "Works only when original payment is above 0");
useMinimumOveralPayment = c.get("Economy.MinimumOveralPayment.use", true); useMinimumOveralPayment = c.get("Economy.MinimumOveralPayment.use", true);
MinimumOveralPaymentLimit = c.get("Economy.MinimumOveralPayment.limit", 0.1); MinimumOveralPaymentLimit = c.get("Economy.MinimumOveralPayment.limit", 0.1);
c.addComment("Economy.MinimumOveralPoints.use", c.addComment("Economy.MinimumOveralPoints.use",
"Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money", "Determines minimum payment for points.",
"In example if player uses McMMO treefeller and earns only 20%, but at same time player gets 25% penalty from dynamic payment.",
"The player can 'get' negative amount of points",
"This will limit it to particular percentage", "Works only when original payment is above 0"); "This will limit it to particular percentage", "Works only when original payment is above 0");
useMinimumOveralPoints = c.get("Economy.MinimumOveralPoints.use", true); useMinimumOveralPoints = c.get("Economy.MinimumOveralPoints.use", true);
MinimumOveralPointsLimit = c.get("Economy.MinimumOveralPoints.limit", 0.1); MinimumOveralPointsLimit = c.get("Economy.MinimumOveralPoints.limit", 0.1);
c.addComment("Economy.MinimumOveralExp.use",
"Determines minimum payment for experience.",
"In example if player uses McMMO treefeller and earns only 20%, but at same time player gets 25% penalty from dynamic payment.",
"The player can 'get' negative amount of experience",
"This will limit it to particular percentage", "Works only when original payment is above 0");
useMinimumOveralExp = c.get("Economy.MinimumOveralExp.use", true);
minimumOveralExpLimit = c.get("Economy.MinimumOveralExp.limit", 0.1);
c.addComment("Economy.DynamicPayment.use", "Do you want to use dynamic payment dependent on how many players already working for jobs?", c.addComment("Economy.DynamicPayment.use", "Do you want to use dynamic payment dependent on how many players already working for jobs?",
"This can help automatically lift up payments for not so popular jobs and lower for most popular ones"); "This can help automatically lift up payments for not so popular jobs and lower for most popular ones");

View File

@ -28,10 +28,11 @@ public class Boost {
} }
public double get(BoostOf boostOf, CurrencyType type, boolean percent) { public double get(BoostOf boostOf, CurrencyType type, boolean percent) {
if (!map.containsKey(boostOf)) BoostMultiplier bm = map.get(boostOf);
if (bm == null)
return 0D; return 0D;
double r = map.get(boostOf).get(type); double r = bm.get(type);
if (r < -1) if (r < -1)
r = -1; r = -1;
@ -45,7 +46,7 @@ public class Boost {
public double getFinalAmount(CurrencyType type, double income) { public double getFinalAmount(CurrencyType type, double income) {
double f = income; double f = income;
if (income > 0 || income < 0 && Jobs.getGCManager().applyToNegativeIncome) if (income > 0 || (income < 0 && Jobs.getGCManager().applyToNegativeIncome))
f = income + income * getFinal(type, false, false); f = income + income * getFinal(type, false, false);
if (income > 0 && f < 0 || income < 0 && f > 0) if (income > 0 && f < 0 || income < 0 && f > 0)
@ -58,13 +59,13 @@ public class Boost {
double r = 0D; double r = 0D;
for (BoostOf one : BoostOf.values()) { for (BoostOf one : BoostOf.values()) {
if (!map.containsKey(one)) BoostMultiplier bm = map.get(one);
if (bm == null)
continue; continue;
if (excludeExtra && (one == BoostOf.NearSpawner || one == BoostOf.PetPay)) if (excludeExtra && (one == BoostOf.NearSpawner || one == BoostOf.PetPay))
continue; continue;
BoostMultiplier bm = map.get(one);
if (bm.isValid(type)) if (bm.isValid(type))
r += bm.get(type); r += bm.get(type);
} }

View File

@ -60,7 +60,7 @@ public class Language {
String missing = "MLF " + key; String missing = "MLF " + key;
String msg = ""; String msg = "";
try { try {
if (customlocale == null || !customlocale.contains(key)) if (!customlocale.contains(key))
msg = enlocale.isString(key) ? CMIChatColor.translate(enlocale.getString(key)) : missing; msg = enlocale.isString(key) ? CMIChatColor.translate(enlocale.getString(key)) : missing;
else else
msg = customlocale.isString(key) ? CMIChatColor.translate(customlocale.getString(key)) : missing; msg = customlocale.isString(key) ? CMIChatColor.translate(customlocale.getString(key)) : missing;
@ -75,10 +75,14 @@ public class Language {
try { try {
List<String> ls = null; List<String> ls = null;
if (customlocale != null && customlocale.isList(key))
if (customlocale.isList(key))
ls = colorsArray(customlocale.getStringList(key), true); ls = colorsArray(customlocale.getStringList(key), true);
else if (enlocale.isList(key)) else if (enlocale.isList(key)) {
ls = !enlocale.getStringList(key).isEmpty() ? colorsArray(enlocale.getStringList(key), true) : Arrays.asList(missing); ls = enlocale.getStringList(key);
ls = !ls.isEmpty() ? colorsArray(ls, true) : Arrays.asList(missing);
}
if (ls != null) if (ls != null)
for (String one : ls) { for (String one : ls) {
if (!msg.isEmpty()) if (!msg.isEmpty())
@ -113,8 +117,10 @@ public class Language {
List<String> ls; List<String> ls;
if (customlocale.isList(key)) if (customlocale.isList(key))
ls = colorsArray(customlocale.getStringList(key), true); ls = colorsArray(customlocale.getStringList(key), true);
else else {
ls = !enlocale.getStringList(key).isEmpty() ? colorsArray(enlocale.getStringList(key), true) : Arrays.asList(missing); ls = enlocale.getStringList(key);
ls = !ls.isEmpty() ? colorsArray(ls, true) : Arrays.asList(missing);
}
if (variables != null && variables.length > 0) if (variables != null && variables.length > 0)
for (int i = 0; i < ls.size(); i++) { for (int i = 0; i < ls.size(); i++) {
@ -139,32 +145,14 @@ public class Language {
public List<String> colorsArray(List<String> text, boolean colorize) { public List<String> colorsArray(List<String> text, boolean colorize) {
List<String> temp = new ArrayList<>(); List<String> temp = new ArrayList<>();
for (String part : text) { for (String part : text) {
if (colorize) if (colorize)
part = CMIChatColor.translate(part); part = CMIChatColor.translate(part);
temp.add(CMIChatColor.translate(part));
temp.add(part);
} }
return temp; return temp;
} }
/**
* Get the message with the correct key
* @param key - the key of the message
* @return the message
*/
public String getDefaultMessage(String key) {
return enlocale.contains(key) ? CMIChatColor.translate(enlocale.getString(key)) : "Can't find locale";
}
/**
* Check if key exists
* @param key - the key of the message
* @return true/false
*/
public boolean containsKey(String key) {
if (customlocale == null || !customlocale.contains(key))
return enlocale.contains(key);
return customlocale.contains(key);
}
} }

View File

@ -1138,7 +1138,6 @@ public class JobsPaymentListener implements Listener {
return; return;
LivingEntity lVictim = (LivingEntity) e.getEntity(); LivingEntity lVictim = (LivingEntity) e.getEntity();
UUID lVictimUUID = lVictim.getUniqueId();
boolean hadSpawnerMobMetadata = lVictim.hasMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata()); boolean hadSpawnerMobMetadata = lVictim.hasMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata());
if (hadSpawnerMobMetadata) { if (hadSpawnerMobMetadata) {
@ -1149,10 +1148,14 @@ public class JobsPaymentListener implements Listener {
} }
if (Jobs.getGCManager().MonsterDamageUse) { if (Jobs.getGCManager().MonsterDamageUse) {
UUID lVictimUUID = lVictim.getUniqueId();
Double damage = damageDealtByPlayers.getIfPresent(lVictimUUID); Double damage = damageDealtByPlayers.getIfPresent(lVictimUUID);
if (damage != null) { if (damage != null) {
double perc = (damage * 100D) / Jobs.getNms().getMaxHealth(lVictim); double perc = (damage * 100D) / Jobs.getNms().getMaxHealth(lVictim);
damageDealtByPlayers.invalidate(lVictimUUID); damageDealtByPlayers.invalidate(lVictimUUID);
if (perc < Jobs.getGCManager().MonsterDamagePercentage) if (perc < Jobs.getGCManager().MonsterDamagePercentage)
return; return;
} }
@ -1172,23 +1175,25 @@ public class JobsPaymentListener implements Listener {
} }
Player pDamager = null; Player pDamager = null;
boolean isTameable = e.getDamager() instanceof Tameable;
boolean isMyPet = HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(e.getDamager(), null); boolean isMyPet = HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(e.getDamager(), null);
// Checking if killer is player if (e.getDamager() instanceof Player) { // Checking if killer is player
if (e.getDamager() instanceof Player) {
pDamager = (Player) e.getDamager(); pDamager = (Player) e.getDamager();
// Checking if killer is MyPet animal } else if (isMyPet) { // Checking if killer is MyPet animal
} else if (isMyPet) {
UUID uuid = HookManager.getMyPetManager().getOwnerOfPet(e.getDamager()); UUID uuid = HookManager.getMyPetManager().getOwnerOfPet(e.getDamager());
if (uuid != null) if (uuid != null)
pDamager = Bukkit.getPlayer(uuid); pDamager = Bukkit.getPlayer(uuid);
// Checking if killer is tamed animal } else if (isTameable) { // Checking if killer is tamed animal
} else if (e.getDamager() instanceof Tameable) {
Tameable t = (Tameable) e.getDamager(); Tameable t = (Tameable) e.getDamager();
if (t.isTamed() && t.getOwner() instanceof Player) if (t.isTamed() && t.getOwner() instanceof Player)
pDamager = (Player) t.getOwner(); 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)
pDamager = (Player) pr.getShooter(); pDamager = (Player) pr.getShooter();
} }
@ -1197,10 +1202,9 @@ public class JobsPaymentListener implements Listener {
return; return;
// Prevent payment for killing mobs with pet by denying permission // Prevent payment for killing mobs with pet by denying permission
if (isMyPet || (e.getDamager() instanceof Tameable && ((Tameable) e.getDamager()).isTamed() && if (isMyPet || isTameable) {
((Tameable) e.getDamager()).getOwner() instanceof Player)) {
for (PermissionAttachmentInfo perm : pDamager.getEffectivePermissions()) { for (PermissionAttachmentInfo perm : pDamager.getEffectivePermissions()) {
if (!perm.getValue() && "jobs.petpay".equals(perm.getPermission())) { if (!perm.getValue() && perm.getPermission().contains("jobs.petpay")) {
return; return;
} }
} }
@ -1695,7 +1699,7 @@ public class JobsPaymentListener implements Listener {
} }
public static boolean payIfCreative(Player player) { public static boolean payIfCreative(Player player) {
if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative() && !player.hasPermission("jobs.paycreative")) if (!Jobs.getGCManager().payInCreative() && player.getGameMode() == GameMode.CREATIVE && !player.hasPermission("jobs.paycreative"))
return false; return false;
return true; return true;