1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 12:35:28 +01:00

Fix for max permission node not being taken properly when you have

multiple of those
This commit is contained in:
Zrips 2020-12-16 13:53:39 +02:00
parent fa040ee619
commit 32ffb88e9d
4 changed files with 23 additions and 22 deletions

View File

@ -29,6 +29,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Debug;
public class PermissionManager { public class PermissionManager {
@ -117,14 +118,14 @@ public class PermissionManager {
} }
public Double getMaxPermission(JobsPlayer jPlayer, String perm) { public Double getMaxPermission(JobsPlayer jPlayer, String perm) {
return getMaxPermission(jPlayer, perm, false, false, false); return getMaxPermission(jPlayer, perm, false, false);
} }
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) { public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
return getMaxPermission(jPlayer, perm, force, false, false); return getMaxPermission(jPlayer, perm, force, false);
} }
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative, boolean allowMinus) { public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) {
if (jPlayer == null || jPlayer.getPlayer() == null) if (jPlayer == null || jPlayer.getPlayer() == null)
return 0D; return 0D;
@ -139,24 +140,24 @@ public class PermissionManager {
jPlayer.setLastPermissionUpdate(System.currentTimeMillis()); jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
} }
double amount = 0D; double amount = Double.NEGATIVE_INFINITY;
for (Map.Entry<String, Boolean> permission : permissions.entrySet()) { for (Map.Entry<String, Boolean> permission : permissions.entrySet()) {
if (!permission.getKey().startsWith(perm) || !permission.getValue()) if (!permission.getKey().startsWith(perm) || !permission.getValue())
continue; continue;
try { try {
double temp = Double.parseDouble(permission.getKey().replace(perm, "")); double temp = Double.parseDouble(permission.getKey().replace(perm, ""));
if (cumulative) if (cumulative)
amount += temp; amount += temp;
else if (allowMinus || temp > amount) else if (temp > amount)
amount = temp; amount = temp;
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
ignored.printStackTrace();
// Should be ignored // Should be ignored
} }
} }
return amount; return amount == Double.NEGATIVE_INFINITY ? 0D : amount;
} }
public boolean hasPermission(JobsPlayer jPlayer, String perm) { public boolean hasPermission(JobsPlayer jPlayer, String perm) {

View File

@ -977,7 +977,7 @@ public class PlayerManager {
if (ent instanceof Tameable) { if (ent instanceof Tameable) {
Tameable t = (Tameable) ent; Tameable t = (Tameable) ent;
if (t.isTamed() && t.getOwner() instanceof Player) { if (t.isTamed() && t.getOwner() instanceof Player) {
petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", false, false, true); petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", false, false);
if (petPay != 0D) if (petPay != 0D)
boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay)); boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay));
} }
@ -985,20 +985,20 @@ public class PlayerManager {
if (ent != null && HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(ent, player.getPlayer())) { if (ent != null && HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(ent, player.getPlayer())) {
if (petPay == 0D) if (petPay == 0D)
petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", false, false, true); petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", false, false);
if (petPay != 0D) if (petPay != 0D)
boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay)); boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay));
} }
if (victim != null && victim.hasMetadata(getMobSpawnerMetadata())) { if (victim != null && victim.hasMetadata(getMobSpawnerMetadata())) {
Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", false, false, true); Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", false, false);
if (amount != 0D) if (amount != 0D)
boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(amount)); boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(amount));
} }
if (getall) { if (getall) {
if (petPay == 0D) if (petPay == 0D)
petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force, false, true); petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force, false);
if (petPay != 0D) if (petPay != 0D)
boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay)); boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay));
Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force); Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force);

View File

@ -286,18 +286,18 @@ public class JobsPlayer {
} }
private Double getPlayerBoostNew(String JobName, CurrencyType type) { private Double getPlayerBoostNew(String JobName, CurrencyType type) {
Double v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + "." + type.getName(), true, false, true); Double v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + "." + type.getName(), true, false);
Double Boost = v1; Double Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + ".all", false, false, true); v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + ".all", false, false);
if (v1 != 0d && (v1 > Boost || v1 < Boost)) if (v1 != 0d && (v1 > Boost || v1 < Boost))
Boost = v1; Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all.all", false, false, true); v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all.all", false, false);
if (v1 != 0d && (v1 > Boost || v1 < Boost)) if (v1 != 0d && (v1 > Boost || v1 < Boost))
Boost = v1; Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all." + type.getName(), false, false, true); v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all." + type.getName(), false, false);
if (v1 != 0d && (v1 > Boost || v1 < Boost)) if (v1 != 0d && (v1 > Boost || v1 < Boost))
Boost = v1; Boost = v1;
@ -305,10 +305,10 @@ public class JobsPlayer {
} }
public int getPlayerMaxQuest(String jobName) { public int getPlayerMaxQuest(String jobName) {
int m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest." + jobName, false, true, false).intValue(); int m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest." + jobName, false, true).intValue();
int max = m1; int max = m1;
m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest.all", false, true, false).intValue(); m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest.all", false, true).intValue();
if (m1 != 0 && (m1 > max || m1 < max)) { if (m1 != 0 && (m1 > max || m1 < max)) {
max = m1; max = m1;
} }

View File

@ -124,12 +124,12 @@ public class BufferedEconomy {
if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes && if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes &&
((offPlayer.isOnline() && !offPlayer.getPlayer().hasPermission("jobs.tax.bypass")) || !offPlayer.isOnline())) { ((offPlayer.isOnline() && !offPlayer.getPlayer().hasPermission("jobs.tax.bypass")) || !offPlayer.isOnline())) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId()); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId());
double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false, true); double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false);
if (moneyTaxAmount == 0D) { if (moneyTaxAmount == 0D) {
moneyTaxAmount = Jobs.getGCManager().TaxesAmount; moneyTaxAmount = Jobs.getGCManager().TaxesAmount;
} }
double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false, true); double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false);
if (pointsTaxAmount == 0D) { if (pointsTaxAmount == 0D) {
pointsTaxAmount = Jobs.getGCManager().TaxesAmount; pointsTaxAmount = Jobs.getGCManager().TaxesAmount;
} }
@ -148,12 +148,12 @@ public class BufferedEconomy {
if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes && if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes &&
((offPlayer.isOnline() && !offPlayer.getPlayer().hasPermission("jobs.tax.bypass")) || !offPlayer.isOnline())) { ((offPlayer.isOnline() && !offPlayer.getPlayer().hasPermission("jobs.tax.bypass")) || !offPlayer.isOnline())) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId()); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId());
double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false, true); double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false);
if (moneyTaxAmount == 0D) { if (moneyTaxAmount == 0D) {
moneyTaxAmount = Jobs.getGCManager().TaxesAmount; moneyTaxAmount = Jobs.getGCManager().TaxesAmount;
} }
double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false, true); double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false);
if (pointsTaxAmount == 0D) { if (pointsTaxAmount == 0D) {
pointsTaxAmount = Jobs.getGCManager().TaxesAmount; pointsTaxAmount = Jobs.getGCManager().TaxesAmount;
} }