@@ -60,7 +60,7 @@ public class IslandLevelCalculator {
6060 private final Level addon ;
6161 private final Queue <Pair <Integer , Integer >> chunksToCheck ;
6262 private final Island island ;
63- private final Map <Material , Integer > limitCount ;
63+ private final Map <Object , Integer > limitCount ;
6464 private final CompletableFuture <Results > r ;
6565
6666 private final Results results ;
@@ -89,7 +89,7 @@ public IslandLevelCalculator(Level addon, Island island, CompletableFuture<Resul
8989 results = new Results ();
9090 duration = System .currentTimeMillis ();
9191 chunksToCheck = getChunksToScan (island );
92- this .limitCount = new EnumMap <>(addon . getBlockConfig (). getBlockLimits () );
92+ this .limitCount = new HashMap <>();
9393 // Get the initial island level
9494 results .initialLevel .set (addon .getInitialIslandLevel (island ));
9595 // Set up the worlds
@@ -159,10 +159,7 @@ private void checkBlock(Material mat, boolean belowSeaLevel) {
159159 * @param belowSeaLevel - true if below sea level
160160 */
161161 private void checkSpawner (EntityType et , boolean belowSeaLevel ) {
162- if (limitCount (Material .SPAWNER ) == 0 ) {
163- return ;
164- }
165- Integer count = addon .getBlockConfig ().getValue (island .getWorld (), et );
162+ Integer count = limitCount (et );
166163 if (count != null ) {
167164 if (belowSeaLevel ) {
168165 results .underWaterBlockCount .addAndGet (count );
@@ -247,14 +244,9 @@ private List<String> getReport() {
247244 while (it .hasNext ()) {
248245
249246 Entry <Object > type = it .next ();
250- Material m = type .getElement () instanceof Material mat ? mat : Material .SPAWNER ;
251- Integer limit = addon .getBlockConfig ().getBlockLimits ().get (m );
247+ Integer limit = addon .getBlockConfig ().getLimit (type );
252248 String explain = ")" ;
253- if (limit == null ) {
254- limit = addon .getBlockConfig ().getBlockLimits ().get (m );
255- explain = " - All types)" ;
256- }
257- reportLines .add (Util .prettifyText (m .name ()) + ": " + String .format ("%,d" , type .getCount ())
249+ reportLines .add (Util .prettifyText (type .toString ()) + ": " + String .format ("%,d" , type .getCount ())
258250 + " blocks (max " + limit + explain );
259251 }
260252 reportLines .add (LINE_BREAK );
@@ -271,10 +263,10 @@ public Results getResults() {
271263 /**
272264 * Get value of a material World blocks trump regular block values
273265 *
274- * @param md - Material to check
275- * @return value of a material
266+ * @param md - Material or EntityType to check
267+ * @return value
276268 */
277- private int getValue (Material md ) {
269+ private int getValue (Object md ) {
278270 Integer value = addon .getBlockConfig ().getValue (island .getWorld (), md );
279271 if (value == null ) {
280272 // Not in config
@@ -335,24 +327,28 @@ private void roseStackerCheck(Chunk chunk) {
335327 }
336328
337329 /**
338- * Checks if a block has been limited or not and whether a block has any value
339- * or not
340- *
341- * @param md Material
342- * @return value of the block if can be counted
330+ * Checks if the given object (Material or EntityType) has reached its limit.
331+ * If it hasn't, the object's value is returned and its count is incremented.
332+ * If the object is not a Material or EntityType, or if it has exceeded its limit, 0 is returned.
333+ *
334+ * @param obj A Material or EntityType
335+ * @return The object's value if within limit, otherwise 0.
343336 */
344- private int limitCount (Material md ) {
345- if (limitCount .containsKey (md )) {
346- int count = limitCount .get (md );
347- if (count > 0 ) {
348- limitCount .put (md , --count );
349- return getValue (md );
350- } else {
351- results .ofCount .add (md );
352- return 0 ;
353- }
354- }
355- return getValue (md );
337+ private int limitCount (Object obj ) {
338+ // Only process if obj is a Material or EntityType
339+ if (!(obj instanceof Material ) && !(obj instanceof EntityType ))
340+ return 0 ;
341+
342+ Integer limit = addon .getBlockConfig ().getLimit (obj );
343+ if (limit == null )
344+ return getValue (obj );
345+
346+ int count = limitCount .getOrDefault (obj , 0 );
347+ if (count > limit )
348+ return 0 ;
349+
350+ limitCount .put (obj , count + 1 );
351+ return getValue (obj );
356352 }
357353
358354 /**
0 commit comments