Max/Free sethome permission checker now finds the highest number allowed accounting for inherited permissions

This commit is contained in:
William278 committed 2021-03-29 10:59:49 +01:00
1 parent 0a7861443e
commit 398b47af55
1 file changed
+16 -8
@@ -146,31 +146,39 @@ public class Home extends TeleportationPoint {
// 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 p) { public static int getSetHomeLimit(Player p) {
p.recalculatePermissions(); p.recalculatePermissions();
int maxSethomes = -1;
for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) { for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) {
String permission = permissionAI.getPermission(); String permission = permissionAI.getPermission();
if (permission.contains("huskhomes.max_sethomes.")) { if (permission.contains("huskhomes.max_sethomes.")) {
try { try {
return Integer.parseInt(permission.split("\\.")[2]); if (Integer.parseInt(permission.split("\\.")[2]) > maxSethomes) {
} catch(Exception e) { maxSethomes = Integer.parseInt(permission.split("\\.")[2]);
return HuskHomes.getSettings().getMaximumHomes(); }
} } catch (Exception ignored) { }
} }
} }
if (maxSethomes != -1) {
return maxSethomes;
}
return HuskHomes.getSettings().getMaximumHomes(); return HuskHomes.getSettings().getMaximumHomes();
} }
// 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 p) { public static int getFreeHomes(Player p) {
int freeSethomes = -1;
for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) { for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) {
String permission = permissionAI.getPermission(); String permission = permissionAI.getPermission();
if (permission.contains("huskhomes.free_sethomes.")) { if (permission.contains("huskhomes.free_sethomes.")) {
try { try {
return Integer.parseInt(permission.split("\\.")[2]); if (Integer.parseInt(permission.split("\\.")[2]) > freeSethomes) {
} catch(Exception e) { freeSethomes = Integer.parseInt(permission.split("\\.")[2]);
return HuskHomes.getSettings().getFreeHomeSlots(); }
} } catch(Exception ignored) { }
} }
} }
if (freeSethomes != -1) {
return freeSethomes;
}
return HuskHomes.getSettings().getFreeHomeSlots(); return HuskHomes.getSettings().getFreeHomeSlots();
} }
} }