develop-bloodmoon #10

Merged
MineTec merged 17 commits from develop-bloodmoon into master 2025-11-23 14:03:07 +00:00
3 changed files with 22 additions and 17 deletions
Showing only changes of commit b8725bc0f2 - Show all commits

View File

@@ -34,7 +34,6 @@ import java.util.concurrent.ThreadLocalRandom;
@SuppressWarnings("FieldCanBeLocal") @SuppressWarnings("FieldCanBeLocal")
public class Bloodmoon extends Appliance { public class Bloodmoon extends Appliance {
// für alle Dimensionen? einstellbar machen? // für alle Dimensionen? einstellbar machen?
Pupsi marked this conversation as resolved Outdated

?

?
// TODO: Bossbar muss kleiner werden
public final Map<EntityType, Set<MobEffect>> affectedMobEffectMap = Map.of( public final Map<EntityType, Set<MobEffect>> affectedMobEffectMap = Map.of(
EntityType.ZOMBIE, Set.of( EntityType.ZOMBIE, Set.of(
@@ -91,6 +90,7 @@ public class Bloodmoon extends Appliance {
EntityType.SPIDER EntityType.SPIDER
); );
private final Map<Player, @Nullable BukkitTask> hordeSpawnTasks = new HashMap<>(); private final Map<Player, @Nullable BukkitTask> hordeSpawnTasks = new HashMap<>();
Pupsi marked this conversation as resolved Outdated

WeakHashMap implementierung verwenden

WeakHashMap implementierung verwenden
private long lastBloodmoonStartTick = 0;
public final int ticksPerDay = 24000; public final int ticksPerDay = 24000;
public final int bloodmoonLength = ticksPerDay/2; public final int bloodmoonLength = ticksPerDay/2;
private final int bloodmoonFreeDaysAtStart = 3; private final int bloodmoonFreeDaysAtStart = 3;
@@ -115,7 +115,8 @@ public class Bloodmoon extends Appliance {
return this.isActive; return this.isActive;
} }
public void startBloodmoon() { public void startBloodmoon(long startTick) {
this.lastBloodmoonStartTick = startTick;
this.isActive = true; this.isActive = true;
Bukkit.getOnlinePlayers().forEach(this::addPlayerToBossBar); Bukkit.getOnlinePlayers().forEach(this::addPlayerToBossBar);
this.startHordeSpawning(this.getRandomHordeSpawnDelay()); this.startHordeSpawning(this.getRandomHordeSpawnDelay());
@@ -128,6 +129,14 @@ public class Bloodmoon extends Appliance {
this.sendStopMessages(); this.sendStopMessages();
} }
public void updateBossBar() {
long tick = Bukkit.getWorlds().getFirst().getFullTime();
long sinceStart = tick - this.lastBloodmoonStartTick;
float progress = 1f - ((float) sinceStart / this.bloodmoonLength);
if(progress < 0) progress = 1f;
this.bossBar.progress(progress);
}
public boolean isStartTick(long tick) { public boolean isStartTick(long tick) {
long day = tick / this.ticksPerDay; long day = tick / this.ticksPerDay;
if(day % this.bloodmoonDayInterval != 0 || day - this.bloodmoonFreeDaysAtStart <= 0) return false; if(day % this.bloodmoonDayInterval != 0 || day - this.bloodmoonFreeDaysAtStart <= 0) return false;
@@ -150,8 +159,7 @@ public class Bloodmoon extends Appliance {
Main.instance(), Main.instance(),
() -> { () -> {
if(!this.bloodmoonIsActive()) return; if(!this.bloodmoonIsActive()) return;
// TODO: Nur für den speziellen Spieler this.spawnRandomHorde(player);
this.spawnRandomHorde();
this.startHordeSpawning(this.getRandomHordeSpawnDelay(), player); this.startHordeSpawning(this.getRandomHordeSpawnDelay(), player);
}, },
delay delay
@@ -176,15 +184,10 @@ public class Bloodmoon extends Appliance {
); );
} }
public void spawnRandomHorde() { public void spawnRandomHorde(Player player) {
if(Bukkit.getOnlinePlayers().isEmpty()) return;
if(!this.hordesEnabled) return; if(!this.hordesEnabled) return;
List<? extends Player> onlinePlayerList = Bukkit.getOnlinePlayers().stream() if(!player.getGameMode().equals(GameMode.SURVIVAL)) return;
.filter(this::getBloodmoonSetting)
.filter(player -> player.getGameMode().equals(GameMode.SURVIVAL))
.toList();
ThreadLocalRandom random = ThreadLocalRandom.current(); ThreadLocalRandom random = ThreadLocalRandom.current();
Player player = onlinePlayerList.get(random.nextInt(onlinePlayerList.size()));
EntityType hordeEntityType = this.hordeMobList.get(random.nextInt(this.hordeMobList.size())); EntityType hordeEntityType = this.hordeMobList.get(random.nextInt(this.hordeMobList.size()));
int hordeSize = random.nextInt(this.hordeMinPopulation, this.hordeMaxPopulation + 1); int hordeSize = random.nextInt(this.hordeMinPopulation, this.hordeMaxPopulation + 1);
this.spawnHorde(player, hordeSize, hordeEntityType); this.spawnHorde(player, hordeSize, hordeEntityType);

View File

@@ -23,7 +23,7 @@ public class BloodmoonCommand extends ApplianceCommand<Bloodmoon> {
switch(args[0]) { switch(args[0]) {
case "start": { case "start": {
this.getAppliance().startBloodmoon(); this.getAppliance().startBloodmoon(0L);
sender.sendMessage("Started bloodmoon."); sender.sendMessage("Started bloodmoon.");
break; break;
} }

View File

@@ -9,19 +9,21 @@ import org.bukkit.event.EventHandler;
public class BloodmoonTimeListener extends ApplianceListener<Bloodmoon> { public class BloodmoonTimeListener extends ApplianceListener<Bloodmoon> {
@EventHandler @EventHandler
public void onServerTick(ServerTickStartEvent event) { public void onServerTick(ServerTickStartEvent event) {
if(this.getAppliance().isStartTick(Bukkit.getWorlds().getFirst().getFullTime())) { long currentTime = Bukkit.getWorlds().getFirst().getFullTime();
this.getAppliance().startBloodmoon(); if(this.getAppliance().isStartTick(currentTime)) {
this.getAppliance().startBloodmoon(currentTime);
return; return;
} }
if(this.getAppliance().isStartTick(Bukkit.getWorlds().getFirst().getFullTime() - this.getAppliance().bloodmoonLength)) { if(this.getAppliance().isStartTick(currentTime - this.getAppliance().bloodmoonLength)) {
this.getAppliance().stopBloodmoon(); this.getAppliance().stopBloodmoon();
return; return;
} }
if(this.getAppliance().isStartTick(Bukkit.getWorlds().getFirst().getFullTime() + this.getAppliance().ticksPerDay)) { this.getAppliance().updateBossBar();
Pupsi marked this conversation as resolved Outdated

kannst du das ein bisschen debouncen?

sowas wie
if(currentTime % 20 == 0) this.getAppliance().updateBossBar();

kannst du das ein bisschen debouncen? sowas wie `if(currentTime % 20 == 0) this.getAppliance().updateBossBar();`
if(this.getAppliance().isStartTick(currentTime + this.getAppliance().ticksPerDay)) {
this.getAppliance().sendAnnouncementMessages(); this.getAppliance().sendAnnouncementMessages();
return; return;
} }
if(this.getAppliance().isStartTick(Bukkit.getWorlds().getFirst().getFullTime() + 1000)) { if(this.getAppliance().isStartTick(currentTime + 1000)) {
Pupsi marked this conversation as resolved Outdated

magic number in variable auslagern in der Appliance configmäßig

magic number in variable auslagern in der Appliance configmäßig
this.getAppliance().sendPreStartMessages(); this.getAppliance().sendPreStartMessages();
} }
} }