1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Fix max jobs, respect negated permissions, add cumulative option #926

This commit is contained in:
montlikadani 2020-09-26 12:07:06 +02:00 committed by GitHub
commit d00d4a59a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 18 deletions

View File

@ -20,6 +20,7 @@ package com.gamingmesh.jobs;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -119,7 +120,11 @@ public class PermissionManager {
return getMaxPermission(jPlayer, perm, false);
}
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
return getMaxPermission(jPlayer, perm, force, true);
}
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) {
if (jPlayer == null || jPlayer.getPlayer() == null)
return 0D;
@ -138,23 +143,22 @@ public class PermissionManager {
return 0D;
}
Double amount = 0D;
for (String uno : permissions.keySet()) {
if (uno.startsWith(perm)) {
double t = 0d;
try {
t = Double.parseDouble(uno.replace(perm, ""));
} catch (NumberFormatException e) {
}
double amount = 0D;
if (uno.startsWith("jobs.max")) {
if (amount == 0D || t > amount) {
amount = t;
}
} else {
amount += t;
for (Map.Entry<String, Boolean> permission : permissions.entrySet()) {
if (!permission.getKey().startsWith(perm) || !permission.getValue())
continue;
try {
double temp = Double.parseDouble(permission.getKey().replace(perm, ""));
if (cumulative)
amount += temp;
else if (temp > amount)
amount = temp;
} catch (NumberFormatException ignored) {
}
}
}
return amount;

View File

@ -554,7 +554,7 @@ public class Placeholder {
return convert(true);
case maxjobs:
int max = Jobs.getPermissionManager().getMaxPermission(user, "jobs.max").intValue();
int max = Jobs.getPermissionManager().getMaxPermission(user, "jobs.max", false, false).intValue();
max = max == 0 ? Jobs.getGCManager().getMaxJobs() : max;
return Integer.toString(max);

View File

@ -783,7 +783,7 @@ public class PlayerManager {
* @return True if he have permission
*/
public boolean getJobsLimit(JobsPlayer jPlayer, short currentCount) {
int max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max").intValue();
int max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max", false, false).intValue();
max = max == 0 ? Jobs.getGCManager().getMaxJobs() : max;
return max > currentCount;
}