Fix spawner stacking disabled mobs

This commit is contained in:
ceze88 2023-05-05 10:57:07 +02:00
parent 96d825044f
commit d40db23f2f
4 changed files with 14 additions and 22 deletions

View File

@ -51,7 +51,6 @@ public class SpawnerListeners implements Listener {
if (entity.getType() == EntityType.FIREWORK) return;
if (entity.getVehicle() != null) {
entity.getVehicle().remove();
entity.remove();
}
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
@ -59,16 +58,16 @@ public class SpawnerListeners implements Listener {
for (Entity e : entity.getPassengers()) {
e.remove();
}
entity.remove();
}
}
entity.remove();
Location location = event.getSpawner().getLocation();
SpawnerStack spawnerStack = spawnerStackManager.getSpawner(location);
int amountToSpawn = spawnerStack.calculateSpawnCount();
int amountToSpawn = spawnerStack.calculateSpawnCount(entity.getType());
if (amountToSpawn <= 1) return;
entity.remove();
spawnerStack.spawn(amountToSpawn, "EXPLOSION_NORMAL", null, (e) -> {
if (Settings.NO_AI.getBoolean())

View File

@ -1,21 +1,12 @@
package com.songoda.ultimatestacker.stackable.entity;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class EntityStackManager {
@ -132,6 +123,7 @@ public class EntityStackManager {
}
public void setStack(LivingEntity newEntity, int amount) {
if (amount <= 0) return;
if (isStackedEntity(newEntity)) {
EntityStack stack = getStack(newEntity);
stack.setAmount(amount);

View File

@ -10,6 +10,7 @@ import com.songoda.ultimatestacker.utils.Stackable;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.EntityType;
import java.util.Random;
import java.util.UUID;
@ -47,7 +48,11 @@ public class SpawnerStack extends SSpawner implements Stackable, Hologramable {
plugin.getDataManager().updateSpawner(this);
}
public int calculateSpawnCount() {
public int calculateSpawnCount(EntityType type) {
if (!UltimateStacker.getInstance().getMobFile().getBoolean("Mobs." + type.name() + ".Enabled")) {
return 0;
}
Random random = new Random();
int count = 0;
for (int i = 0; i < getAmount(); i++) {

View File

@ -9,12 +9,9 @@ import com.songoda.ultimatestacker.settings.Settings;
import com.songoda.ultimatestacker.stackable.entity.Check;
import com.songoda.ultimatestacker.stackable.entity.EntityStack;
import com.songoda.ultimatestacker.stackable.entity.EntityStackManager;
import com.songoda.ultimatestacker.stackable.entity.StackedEntity;
import com.songoda.ultimatestacker.stackable.entity.custom.CustomEntity;
import com.songoda.ultimatestacker.utils.Async;
import com.songoda.ultimatestacker.utils.CachedChunk;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -45,16 +42,12 @@ import org.bukkit.entity.TropicalFish;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.Zombie;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -67,7 +60,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class StackingTask extends TimerTask {
@ -187,6 +179,10 @@ public class StackingTask extends TimerTask {
|| entity.hasMetadata("breedCooldown"))
return false;
if (!configurationSection.getBoolean("Mobs." + entity.getType().name() + ".Enabled")) {
return false;
}
// Allow spawn if stackreasons are set and match, or if from a spawner
final String spawnReason = entity.hasMetadata("US_REASON") && !entity.getMetadata("US_REASON").isEmpty()
? entity.getMetadata("US_REASON").get(0).asString() : null;