From 398b47af55b75024ab4e97aa815136ca28302535 Mon Sep 17 00:00:00 2001 From: William278 Date: Mon, 29 Mar 2021 10:59:49 +0100 Subject: [PATCH] Max/Free sethome permission checker now finds the highest number allowed accounting for inherited permissions --- .../huskhomes2/teleport/points/Home.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/teleport/points/Home.java b/src/main/java/me/william278/huskhomes2/teleport/points/Home.java index fc12f2a8..00e97c95 100644 --- a/src/main/java/me/william278/huskhomes2/teleport/points/Home.java +++ b/src/main/java/me/william278/huskhomes2/teleport/points/Home.java @@ -146,31 +146,39 @@ public class Home extends TeleportationPoint { // Returns the maximum number of set homes a player can make public static int getSetHomeLimit(Player p) { p.recalculatePermissions(); + int maxSethomes = -1; for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) { String permission = permissionAI.getPermission(); if (permission.contains("huskhomes.max_sethomes.")) { try { - return Integer.parseInt(permission.split("\\.")[2]); - } catch(Exception e) { - return HuskHomes.getSettings().getMaximumHomes(); - } + if (Integer.parseInt(permission.split("\\.")[2]) > maxSethomes) { + maxSethomes = Integer.parseInt(permission.split("\\.")[2]); + } + } catch (Exception ignored) { } } } + if (maxSethomes != -1) { + return maxSethomes; + } return HuskHomes.getSettings().getMaximumHomes(); } // Returns the number of set homes a player can set for free public static int getFreeHomes(Player p) { + int freeSethomes = -1; for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) { String permission = permissionAI.getPermission(); if (permission.contains("huskhomes.free_sethomes.")) { try { - return Integer.parseInt(permission.split("\\.")[2]); - } catch(Exception e) { - return HuskHomes.getSettings().getFreeHomeSlots(); - } + if (Integer.parseInt(permission.split("\\.")[2]) > freeSethomes) { + freeSethomes = Integer.parseInt(permission.split("\\.")[2]); + } + } catch(Exception ignored) { } } } + if (freeSethomes != -1) { + return freeSethomes; + } return HuskHomes.getSettings().getFreeHomeSlots(); } }