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