From 13c0c96ca1d1d2928e0051a4a7d90eb49114ac1e Mon Sep 17 00:00:00 2001 From: KxmischesDomi Date: Thu, 18 Jan 2024 19:23:15 +0100 Subject: [PATCH] Dont spawn deactivated mobs --- .../challenge/MobRandomizerChallenge.java | 24 +++++++++++++------ pom.xml | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MobRandomizerChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MobRandomizerChallenge.java index 7af1f988..6353ca09 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MobRandomizerChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MobRandomizerChallenge.java @@ -9,8 +9,10 @@ import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.management.scheduler.task.TimerTask; import net.codingarea.challenges.plugin.management.scheduler.timer.TimerStatus; +import net.codingarea.challenges.plugin.management.server.GameWorldStorage; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; import net.codingarea.challenges.plugin.utils.misc.ListBuilder; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -65,10 +67,11 @@ public void onPause() { private void loadAllEntities() { for (World world : ChallengeAPI.getGameWorlds()) { for (LivingEntity entity : world.getLivingEntities()) { - if (!entityRandomizer.containsKey(entity.getType())) continue; - entity.remove(); - entity.getWorld().spawnEntity(entity.getLocation(), entity.getType()); - + Bukkit.getScheduler().runTask(Challenges.getInstance(), () -> { + if (!entityRandomizer.containsKey(entity.getType())) return; + entity.remove(); + entity.getWorld().spawnEntity(entity.getLocation(), entityRandomizer.get(entity.getType())); + }); } } @@ -114,14 +117,21 @@ protected void reloadRandomization() { } public List getSpawnAbleEntities() { - return new ListBuilder<>(EntityType.values()) + ListBuilder builder = new ListBuilder<>(EntityType.values()) .removeIf(type -> !type.isSpawnable()) .removeIf(type -> !type.isAlive()) .remove(EntityType.ENDER_DRAGON) .remove(EntityType.WITHER) .remove(EntityType.GIANT) - .remove(EntityType.ILLUSIONER) - .build(); + .remove(EntityType.ILLUSIONER); + + try { + builder.removeIf(type -> !type.isEnabledByFeature(plugin.getGameWorldStorage().getWorld(World.Environment.NORMAL))); + } catch (Exception e) { + // OLD VERSION + } + + return builder.build(); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) diff --git a/pom.xml b/pom.xml index 67b9e5a0..5add26d3 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 1.3.13 - 1.19-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT