changed horde spawning to delay for each player

This commit is contained in:
2025-10-20 16:27:10 +02:00
parent 1182cb2ed6
commit ff81c91661

View File

@@ -12,7 +12,6 @@ import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@@ -76,7 +75,7 @@ public class Bloodmoon extends Appliance {
); );
private final boolean hordesEnabled = true; private final boolean hordesEnabled = true;
private final int hordeSpawnRateTicks = 800; private final int hordeSpawnRateTicks = 800;
private final int hordeSpawnRateVariationTicks = 100; private final int hordeSpawnRateVariationTicks = 800;
private final int hordeMinPopulation = 3; private final int hordeMinPopulation = 3;
private final int hordeMaxPopulation = 10; private final int hordeMaxPopulation = 10;
private final int hordeSpawnDistance = 10; private final int hordeSpawnDistance = 10;
@@ -85,7 +84,7 @@ public class Bloodmoon extends Appliance {
EntityType.SKELETON, EntityType.SKELETON,
EntityType.SPIDER EntityType.SPIDER
); );
private @Nullable BukkitTask hordeSpawnTask = null; private final Map<Player, @Nullable BukkitTask> hordeSpawnTasks = new HashMap<>();
private final int bloodmoonLegth = 12000; private final int bloodmoonLegth = 12000;
private final int bloodmoonStartTime = 12000; private final int bloodmoonStartTime = 12000;
private final int daysBetweenBloodmoons = 1; private final int daysBetweenBloodmoons = 1;
@@ -115,20 +114,26 @@ public class Bloodmoon extends Appliance {
} }
private int getRandomHordeSpawnDelay() { private int getRandomHordeSpawnDelay() {
return this.hordeSpawnRateTicks + ThreadLocalRandom.current().nextInt(-this.hordeSpawnRateVariationTicks, this.hordeSpawnRateVariationTicks); return this.hordeSpawnRateTicks + ThreadLocalRandom.current().nextInt(this.hordeSpawnRateVariationTicks);
} }
private void startHordeSpawning(int delay) { private void startHordeSpawning(int delay) {
if(this.hordeSpawnTask != null) this.hordeSpawnTask.cancel(); Bukkit.getOnlinePlayers().forEach(player -> this.startHordeSpawning(delay, player));
this.hordeSpawnTask = Bukkit.getScheduler().runTaskLater( }
Main.instance(),
() -> { private void startHordeSpawning(int delay, Player player) {
if(!this.bloodmoonIsActive()) return; @Nullable BukkitTask task = this.hordeSpawnTasks.get(player);
this.spawnRandomHorde(); if(task != null) task.cancel();
this.startHordeSpawning(this.getRandomHordeSpawnDelay()); task = Bukkit.getScheduler().runTaskLater(
}, Main.instance(),
delay () -> {
if(!this.bloodmoonIsActive()) return;
this.spawnRandomHorde();
this.startHordeSpawning(this.getRandomHordeSpawnDelay());
},
delay
); );
this.hordeSpawnTasks.put(player, task);
} }
public void stopBloodmoon() { public void stopBloodmoon() {
@@ -158,7 +163,7 @@ public class Bloodmoon extends Appliance {
if(!this.hordesEnabled) return; if(!this.hordesEnabled) return;
List<? extends Player> onlinePlayerList = Bukkit.getOnlinePlayers().stream() List<? extends Player> onlinePlayerList = Bukkit.getOnlinePlayers().stream()
.filter(this::getBloodmoonSetting) .filter(this::getBloodmoonSetting)
.filter(player -> player.getGameMode().equals(GameMode.SURVIVAL)) // .filter(player -> player.getGameMode().equals(GameMode.SURVIVAL))
.toList(); .toList();
ThreadLocalRandom random = ThreadLocalRandom.current(); ThreadLocalRandom random = ThreadLocalRandom.current();
Player player = onlinePlayerList.get(random.nextInt(onlinePlayerList.size())); Player player = onlinePlayerList.get(random.nextInt(onlinePlayerList.size()));