mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 22:13:25 +01:00
Fix max jobs, respect negated permissions, add cumulative option
This commit is contained in:
parent
2bb9d44d95
commit
bfba8d571b
@ -20,6 +20,7 @@ package com.gamingmesh.jobs;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -120,6 +121,10 @@ public class PermissionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
if (jPlayer == null || jPlayer.getPlayer() == null)
|
||||||
return 0D;
|
return 0D;
|
||||||
|
|
||||||
@ -138,22 +143,21 @@ public class PermissionManager {
|
|||||||
return 0D;
|
return 0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
Double amount = 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) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uno.startsWith("jobs.max")) {
|
for (Map.Entry<String, Boolean> permission : permissions.entrySet()) {
|
||||||
if (amount == 0D || t > amount) {
|
if (!permission.getKey().startsWith(perm) || !permission.getValue())
|
||||||
amount = t;
|
continue;
|
||||||
}
|
|
||||||
} else {
|
try {
|
||||||
amount += t;
|
double temp = Double.parseDouble(permission.getKey().replace(perm, ""));
|
||||||
}
|
|
||||||
|
if (cumulative)
|
||||||
|
amount += temp;
|
||||||
|
else if (temp > amount)
|
||||||
|
amount = temp;
|
||||||
|
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,7 +554,7 @@ public class Placeholder {
|
|||||||
return convert(true);
|
return convert(true);
|
||||||
|
|
||||||
case maxjobs:
|
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;
|
max = max == 0 ? Jobs.getGCManager().getMaxJobs() : max;
|
||||||
return Integer.toString(max);
|
return Integer.toString(max);
|
||||||
|
|
||||||
|
@ -783,7 +783,7 @@ public class PlayerManager {
|
|||||||
* @return True if he have permission
|
* @return True if he have permission
|
||||||
*/
|
*/
|
||||||
public boolean getJobsLimit(JobsPlayer jPlayer, short currentCount) {
|
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;
|
max = max == 0 ? Jobs.getGCManager().getMaxJobs() : max;
|
||||||
return max > currentCount;
|
return max > currentCount;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user