@@ -114,43 +114,19 @@ private void initializeDefaults() {
114114 this .spawnerStop = true ;
115115 this .isAtCapacity = false ;
116116 this .stackSize = 1 ;
117- this .maxStackSize = plugin .getConfig ().getInt ("spawner_properties.default.max_stack_size" , 1000 );
118- this .maxStoragePages = plugin .getConfig ().getInt ("spawner_properties.default.max_storage_pages" , 1 );
119- this .maxSpawnerLootSlots = 45 ;
120- this .lootConfig = lootRegistry .getLootConfig (entityType );
121- // Initialize lastSpawnTime to current time to prevent timer display issues
122117 this .lastSpawnTime = System .currentTimeMillis ();
123118 }
124119
125120 public void loadConfigurationValues () {
126- int baseMaxStoredExp = plugin .getConfig ().getInt ("spawner_properties.default.max_stored_exp" , 1000 );
127- int baseMinMobs = plugin .getConfig ().getInt ("spawner_properties.default.min_mobs" , 1 );
128- int baseMaxMobs = plugin .getConfig ().getInt ("spawner_properties.default.max_mobs" , 4 );
129- long baseSpawnerDelay = plugin .getTimeFromConfig ("spawner_properties.default.delay" , "25s" );
130-
131- validateAndSetStoragePages ();
132- calculateScaledValues (baseMaxStoredExp , baseMinMobs , baseMaxMobs );
133- setSpawnDelay (baseSpawnerDelay );
134- setSpawnerRange ();
135- }
136-
137- private void validateAndSetStoragePages () {
138- if (maxStoragePages <= 0 ) {
139- logger .warning ("Invalid max_storage_pages value. Setting to default: 1" );
140- maxStoragePages = 1 ;
141- }
142- this .maxSpawnerLootSlots = Math .max ((45 * maxStoragePages ) * stackSize , 45 );
143- }
144-
145- private void calculateScaledValues (int baseMaxStoredExp , int baseMinMobs , int baseMaxMobs ) {
146- this .maxStoredExp = Math .max (baseMaxStoredExp * stackSize , baseMaxStoredExp );
147- this .minMobs = Math .max (baseMinMobs * stackSize , baseMinMobs );
148- this .maxMobs = Math .max (baseMaxMobs * stackSize , this .minMobs + stackSize );
149-
150- if (this .maxMobs <= this .minMobs ) {
151- logger .warning ("Invalid max_mobs value after scaling. Adjusting to: " + (this .minMobs + stackSize ));
152- this .maxMobs = this .minMobs + stackSize ;
153- }
121+ this .maxStackSize = plugin .getConfig ().getInt ("spawner_properties.default.max_stack_size" , 1000 );
122+ this .maxStoragePages = plugin .getConfig ().getInt ("spawner_properties.default.max_storage_pages" , 1 );
123+ this .maxSpawnerLootSlots = maxStoragePages * 45 ;
124+ this .maxStoredExp = plugin .getConfig ().getInt ("spawner_properties.default.max_stored_exp" , 1000 );
125+ this .minMobs = plugin .getConfig ().getInt ("spawner_properties.default.min_mobs" , 1 );
126+ this .maxMobs = plugin .getConfig ().getInt ("spawner_properties.default.max_mobs" , 4 );
127+ this .spawnDelay = plugin .getTimeFromConfig ("spawner_properties.default.delay" , "25s" );
128+ this .spawnerRange = plugin .getConfig ().getInt ("spawner_properties.default.range" , 16 );
129+ this .lootConfig = lootRegistry .getLootConfig (entityType );
154130 }
155131
156132 public void setSpawnDelay (long baseSpawnerDelay ) {
@@ -160,14 +136,6 @@ public void setSpawnDelay(long baseSpawnerDelay) {
160136 }
161137 }
162138
163- private void setSpawnerRange () {
164- this .spawnerRange = plugin .getConfig ().getInt ("spawner_properties.default.range" );
165- if (this .spawnerRange <= 0 ) {
166- logger .warning ("Invalid range value. Setting to default: 16" );
167- this .spawnerRange = 16 ;
168- }
169- }
170-
171139 private void initializeComponents () {
172140 this .virtualInventory = new VirtualInventory (maxSpawnerLootSlots );
173141
@@ -191,6 +159,25 @@ public void setStackSize(int stackSize) {
191159 }
192160 }
193161
162+ private void validateAndSetStoragePages () {
163+ if (maxStoragePages <= 0 ) {
164+ logger .warning ("Invalid max_storage_pages value. Setting to default: 1" );
165+ maxStoragePages = 1 ;
166+ }
167+ this .maxSpawnerLootSlots = Math .max ((45 * maxStoragePages ) * stackSize , 45 );
168+ }
169+
170+ private void calculateScaledValues (int baseMaxStoredExp , int baseMinMobs , int baseMaxMobs ) {
171+ this .maxStoredExp = Math .max (baseMaxStoredExp * stackSize , baseMaxStoredExp );
172+ this .minMobs = Math .max (baseMinMobs * stackSize , baseMinMobs );
173+ this .maxMobs = Math .max (baseMaxMobs * stackSize , this .minMobs + stackSize );
174+
175+ if (this .maxMobs <= this .minMobs ) {
176+ logger .warning ("Invalid max_mobs value after scaling. Adjusting to: " + (this .minMobs + stackSize ));
177+ this .maxMobs = this .minMobs + stackSize ;
178+ }
179+ }
180+
194181 private void updateStackSize (int newStackSize ) {
195182 if (newStackSize <= 0 ) {
196183 this .stackSize = 1 ;
@@ -211,7 +198,9 @@ private void updateStackSize(int newStackSize) {
211198 transferItemsToNewInventory (currentItems , newInventory );
212199
213200 this .stackSize = newStackSize ;
214- loadConfigurationValues ();
201+ // Recalculate dependent values
202+ validateAndSetStoragePages ();
203+ calculateScaledValues (getMaxStoredExp (), getMinMobs (), getMaxMobs ());
215204 this .spawnerExp = Math .min (this .spawnerExp , this .maxStoredExp );
216205 this .lastSpawnTime = System .currentTimeMillis ();
217206 this .virtualInventory = newInventory ;
@@ -337,7 +326,7 @@ public int getEntityExperienceValue() {
337326 return lootConfig != null ? lootConfig .getExperience () : 0 ;
338327 }
339328
340- public void reloadLootConfig () {
329+ public void setLootConfig () {
341330 this .lootConfig = lootRegistry .getLootConfig (entityType );
342331 }
343332
@@ -361,11 +350,7 @@ public void markInteracted() {
361350 public void clearInteracted () {
362351 interacted .compareAndSet (true , false );
363352 }
364-
365- /**
366- * Updates the last interacted player and marks the spawner as modified for saving
367- * @param playerName The name of the player who interacted with the spawner
368- */
353+
369354 public void updateLastInteractedPlayer (String playerName ) {
370355 this .lastInteractedPlayer = playerName ;
371356 markInteracted ();
0 commit comments