mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 22:16:22 +00:00
Fix limit not returning -1 if no permissions are set with stacking permissions
This commit is contained in:
1 parent
7239e7bdac
commit
822b651bb7
1 file changed
+20
-8
@@ -138,7 +138,7 @@ public class Home extends SetPoint {
|
|||||||
|
|
||||||
// Returns the maximum number of set homes a player can make
|
// Returns the maximum number of set homes a player can make
|
||||||
public static int getSetHomeLimit(Player player) {
|
public static int getSetHomeLimit(Player player) {
|
||||||
int maxSetHomes = getCountFromPermissions(player, "huskhomes.max_sethomes.");
|
int maxSetHomes = getLimitFromPermissions(player, "huskhomes.max_sethomes.");
|
||||||
if (maxSetHomes != -1) {
|
if (maxSetHomes != -1) {
|
||||||
return maxSetHomes;
|
return maxSetHomes;
|
||||||
}
|
}
|
||||||
@@ -147,32 +147,44 @@ public class Home extends SetPoint {
|
|||||||
|
|
||||||
// Returns the number of set homes a player can set for free
|
// Returns the number of set homes a player can set for free
|
||||||
public static int getFreeHomes(Player player) {
|
public static int getFreeHomes(Player player) {
|
||||||
int freeSetHomes = getCountFromPermissions(player, "huskhomes.free_sethomes.");
|
int freeSetHomes = getLimitFromPermissions(player, "huskhomes.free_sethomes.");
|
||||||
if (freeSetHomes != -1) {
|
if (freeSetHomes != -1) {
|
||||||
return freeSetHomes;
|
return freeSetHomes;
|
||||||
}
|
}
|
||||||
return HuskHomes.getSettings().getFreeHomeSlots();
|
return HuskHomes.getSettings().getFreeHomeSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the number of homes a player can make public; unlimited if not set
|
||||||
|
public static int getPublicHomeLimit(Player player) {
|
||||||
|
int maxPublicHomes = getLimitFromPermissions(player, "huskhomes.max_public_homes.");
|
||||||
|
if (maxPublicHomes != -1) {
|
||||||
|
return maxPublicHomes;
|
||||||
|
}
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
// Return the value from the player's permissions
|
// Return the value from the player's permissions
|
||||||
private static int getCountFromPermissions(Player player, String permissionPrefix) {
|
private static int getLimitFromPermissions(Player player, String permissionPrefix) {
|
||||||
player.recalculatePermissions();
|
player.recalculatePermissions();
|
||||||
int count = -1 + (HuskHomes.getSettings().doHomeLimitPermissionStacking() ? 1 : 0);
|
int limit = -1;
|
||||||
for (PermissionAttachmentInfo permissionAI : player.getEffectivePermissions()) {
|
for (PermissionAttachmentInfo permissionAI : player.getEffectivePermissions()) {
|
||||||
String permission = permissionAI.getPermission();
|
String permission = permissionAI.getPermission();
|
||||||
if (permission.contains(permissionPrefix)) {
|
if (permission.contains(permissionPrefix)) {
|
||||||
try {
|
try {
|
||||||
int value = Integer.parseInt(permission.split("\\.")[2]);
|
int value = Integer.parseInt(permission.split("\\.")[2]);
|
||||||
if (HuskHomes.getSettings().doHomeLimitPermissionStacking()) {
|
if (HuskHomes.getSettings().doHomeLimitPermissionStacking()) {
|
||||||
count += value;
|
if (limit == -1) {
|
||||||
|
limit++;
|
||||||
|
}
|
||||||
|
limit += value;
|
||||||
} else {
|
} else {
|
||||||
if (value > count) {
|
if (value > limit) {
|
||||||
count = value;
|
limit = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException | PatternSyntaxException ignored) {}
|
} catch (NumberFormatException | PatternSyntaxException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user