Skip to content

Commit

Permalink
Dont spawn deactivated mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
DomiIRL committed Jan 18, 2024
1 parent dab02be commit 13c0c96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
});
}

}
Expand Down Expand Up @@ -114,14 +117,21 @@ protected void reloadRandomization() {
}

public List<EntityType> getSpawnAbleEntities() {
return new ListBuilder<>(EntityType.values())
ListBuilder<EntityType> 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)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<properties>
<utilities.version>1.3.13</utilities.version>
<spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
</properties>

</project>

0 comments on commit 13c0c96

Please sign in to comment.