mirror of
https://github.com/craftaro/EpicSpawners.git
synced 2025-01-09 03:57:40 +08:00
FIxes error when SpawnRadius is formatted as #
instead of #x#x#
default value is `8x4x8` but has big troubles when it is set to e.g. `8` [SD-8756]
This commit is contained in:
parent
aa94ad2fe3
commit
d82f701f01
@ -1,6 +1,7 @@
|
|||||||
package com.songoda.epicspawners.spawners.condition;
|
package com.songoda.epicspawners.spawners.condition;
|
||||||
|
|
||||||
import com.songoda.core.hooks.EntityStackerManager;
|
import com.songoda.core.hooks.EntityStackerManager;
|
||||||
|
import com.songoda.core.utils.NumberUtils;
|
||||||
import com.songoda.epicspawners.EpicSpawners;
|
import com.songoda.epicspawners.EpicSpawners;
|
||||||
import com.songoda.epicspawners.settings.Settings;
|
import com.songoda.epicspawners.settings.Settings;
|
||||||
import com.songoda.epicspawners.spawners.spawner.PlacedSpawner;
|
import com.songoda.epicspawners.spawners.spawner.PlacedSpawner;
|
||||||
@ -44,18 +45,36 @@ public class SpawnConditionNearbyEntities implements SpawnCondition {
|
|||||||
|
|
||||||
public static int getEntitiesAroundSpawner(Location location, boolean cached) {
|
public static int getEntitiesAroundSpawner(Location location, boolean cached) {
|
||||||
if (cached) {
|
if (cached) {
|
||||||
if (cachedAmounts.containsKey(location))
|
if (cachedAmounts.containsKey(location)) {
|
||||||
return cachedAmounts.get(location);
|
return cachedAmounts.get(location);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
String[] arr = Settings.SEARCH_RADIUS.getString().split("x");
|
String[] arr = Settings.SEARCH_RADIUS.getString().split("x");
|
||||||
|
|
||||||
|
if (arr.length == 1) {
|
||||||
|
if (NumberUtils.isNumeric(arr[0])) {
|
||||||
|
arr = new String[] {arr[0], arr[0], arr[0]};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arr.length != 3) {
|
||||||
|
EpicSpawners.getInstance().getLogger().warning("Search radius is invalid:" + Settings.SEARCH_RADIUS.getString());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int amt = location.getWorld().getNearbyEntities(location, Integer.parseInt(arr[0]), Integer.parseInt(arr[1]), Integer.parseInt(arr[2]))
|
int amt = location.getWorld().getNearbyEntities(location, Integer.parseInt(arr[0]), Integer.parseInt(arr[1]), Integer.parseInt(arr[2]))
|
||||||
.stream().filter(e -> e instanceof LivingEntity && e.getType() != EntityType.PLAYER && e.getType() != EntityType.ARMOR_STAND && e.isValid())
|
.stream()
|
||||||
|
.filter(e -> e.isValid() &&
|
||||||
|
e instanceof LivingEntity &&
|
||||||
|
e.getType() != EntityType.PLAYER &&
|
||||||
|
e.getType() != EntityType.ARMOR_STAND)
|
||||||
.mapToInt(e -> {
|
.mapToInt(e -> {
|
||||||
if (EntityStackerManager.getStacker() == null) return 1;
|
if (EntityStackerManager.getStacker() == null) return 1;
|
||||||
return EntityStackerManager.getStacker().getSize((LivingEntity) e);
|
return EntityStackerManager.getStacker().getSize((LivingEntity) e);
|
||||||
}).sum();
|
}).sum();
|
||||||
|
|
||||||
cachedAmounts.put(location, amt);
|
cachedAmounts.put(location, amt);
|
||||||
return amt;
|
return amt;
|
||||||
}
|
}
|
||||||
@ -63,4 +82,4 @@ public class SpawnConditionNearbyEntities implements SpawnCondition {
|
|||||||
public int getMax() {
|
public int getMax() {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user