77import com .easyhome .commands .HomesCommand ;
88import com .easyhome .commands .SetHomeCommand ;
99import com .easyhome .config .HomeConfig ;
10+ import com .easyhome .data .GrantStorage ;
1011import com .easyhome .data .HomeStorage ;
1112import com .easyhome .util .WarmupManager ;
13+
14+ import java .util .UUID ;
1215import com .hypixel .hytale .server .core .entity .entities .Player ;
1316import com .hypixel .hytale .server .core .plugin .JavaPlugin ;
1417import com .hypixel .hytale .server .core .plugin .JavaPluginInit ;
@@ -20,6 +23,7 @@ public class EasyHome extends JavaPlugin {
2023
2124 private HomeConfig config ;
2225 private HomeStorage storage ;
26+ private GrantStorage grantStorage ;
2327 private WarmupManager warmupManager ;
2428
2529 public EasyHome (JavaPluginInit init ) {
@@ -34,6 +38,9 @@ public void setup() {
3438 // Initialize storage
3539 storage = new HomeStorage (getDataDirectory ());
3640
41+ // Initialize grant storage
42+ grantStorage = new GrantStorage (getDataDirectory ());
43+
3744 // Initialize warmup manager
3845 warmupManager = new WarmupManager ();
3946
@@ -58,6 +65,11 @@ public void shutdown() {
5865 storage .saveAll ();
5966 }
6067
68+ // Save grant data
69+ if (grantStorage != null ) {
70+ grantStorage .saveAll ();
71+ }
72+
6173 // Shutdown warmup manager
6274 if (warmupManager != null ) {
6375 warmupManager .shutdown ();
@@ -72,15 +84,63 @@ public HomeStorage getStorage() {
7284 return storage ;
7385 }
7486
87+ public GrantStorage getGrantStorage () {
88+ return grantStorage ;
89+ }
90+
7591 public WarmupManager getWarmupManager () {
7692 return warmupManager ;
7793 }
7894
7995 /**
8096 * Get the home limit for a player.
81- * Uses config-based defaults with optional permission overrides.
97+ * Combines permission-based limits and grant-based bonuses additively.
98+ *
99+ * Formula: min(baseLimit + bonusHomes, maxHomeLimit)
100+ * Where baseLimit = permissionLimit (if enabled) or defaultLimit
101+ */
102+ public int getHomeLimit (Player player , UUID playerId ) {
103+ // Check for unlimited permission first
104+ if (player .hasPermission ("homes.limit.unlimited" )) {
105+ return config .getMaxHomeLimit ();
106+ }
107+
108+ int baseLimit = config .getDefaultHomeLimit ();
109+
110+ // If permission overrides are enabled, check for specific limits
111+ if (config .isPermissionOverridesEnabled ()) {
112+ // Check for specific permission-based limits (highest first)
113+ if (player .hasPermission ("homes.limit.50" )) {
114+ baseLimit = 50 ;
115+ } else if (player .hasPermission ("homes.limit.25" )) {
116+ baseLimit = 25 ;
117+ } else if (player .hasPermission ("homes.limit.10" )) {
118+ baseLimit = 10 ;
119+ } else if (player .hasPermission ("homes.limit.5" )) {
120+ baseLimit = 5 ;
121+ } else if (player .hasPermission ("homes.limit.3" )) {
122+ baseLimit = 3 ;
123+ } else if (player .hasPermission ("homes.limit.1" )) {
124+ baseLimit = 1 ;
125+ }
126+ }
127+
128+ // Add bonus homes from grants (additive stacking)
129+ int bonusHomes = grantStorage .getBonusHomes (playerId );
130+ int effectiveLimit = baseLimit + bonusHomes ;
131+
132+ // Cap at max home limit
133+ return Math .min (effectiveLimit , config .getMaxHomeLimit ());
134+ }
135+
136+ /**
137+ * Get the home limit for a player (convenience method).
138+ * Uses config-based defaults with optional permission and grant overrides.
82139 */
83140 public int getHomeLimit (Player player ) {
141+ // This overload is for backwards compatibility when UUID is not available
142+ // In this case, grants cannot be checked, so only permission limits apply
143+
84144 // Check for unlimited permission first
85145 if (player .hasPermission ("homes.limit.unlimited" )) {
86146 return config .getMaxHomeLimit ();
@@ -92,7 +152,6 @@ public int getHomeLimit(Player player) {
92152 }
93153
94154 // Check for specific permission-based limits (highest first)
95- // These override the default if enabled
96155 if (player .hasPermission ("homes.limit.50" )) {
97156 return Math .min (50 , config .getMaxHomeLimit ());
98157 }
@@ -115,4 +174,14 @@ public int getHomeLimit(Player player) {
115174 // Fall back to config default
116175 return config .getDefaultHomeLimit ();
117176 }
177+
178+ /**
179+ * Get the home limit for an offline player by UUID only.
180+ * Uses grants and default limit (cannot check permissions for offline players).
181+ */
182+ public int getHomeLimitByUuid (UUID playerId ) {
183+ int bonusHomes = grantStorage .getBonusHomes (playerId );
184+ int grantLimit = config .getDefaultHomeLimit () + bonusHomes ;
185+ return Math .min (grantLimit , config .getMaxHomeLimit ());
186+ }
118187}
0 commit comments