resolved pr comments

This commit is contained in:
2025-11-23 15:00:16 +01:00
parent 4c63800189
commit 4d9548aafc
3 changed files with 38 additions and 36 deletions

View File

@@ -33,43 +33,43 @@ import java.util.concurrent.ThreadLocalRandom;
@SuppressWarnings("FieldCanBeLocal")
public class Bloodmoon extends Appliance {
// für alle Dimensionen? einstellbar machen?
public final Map<EntityType, Set<MobEffect>> affectedMobEffectMap = Map.of(
EntityType.ZOMBIE, Set.of(
public final Map<EntityType, Set<MobEffect>> affectedMobEffectMap = Map.ofEntries(
Map.entry(EntityType.ZOMBIE, Set.of(
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
),
EntityType.SKELETON, Set.of(
)),
Map.entry(EntityType.SKELETON, Set.of(
new MobEffect.PotionMobEffect(PotionEffectType.SLOWNESS, 3.5, 1)
),
EntityType.SPIDER, Set.of(
)),
Map.entry(EntityType.SPIDER, Set.of(
new MobEffect.PotionMobEffect(PotionEffectType.POISON, 4, 1),
new MobEffect.PotionMobEffect(PotionEffectType.NAUSEA, 6, 10)
),
EntityType.CREEPER, Set.of(
)),
Map.entry(EntityType.CREEPER, Set.of(
new MobEffect.LightningMobEffect()
),
EntityType.HUSK, Set.of(
)),
Map.entry(EntityType.HUSK, Set.of(
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
),
EntityType.DROWNED, Set.of(
)),
Map.entry(EntityType.STRAY, Set.of()),
Map.entry(EntityType.DROWNED, Set.of(
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
),
EntityType.WITCH, Set.of(),
EntityType.ZOMBIE_VILLAGER, Set.of(
)),
Map.entry(EntityType.WITCH, Set.of()),
Map.entry(EntityType.ZOMBIE_VILLAGER, Set.of(
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
),
EntityType.PHANTOM, Set.of(
)),
Map.entry(EntityType.PHANTOM, Set.of(
new MobEffect.PotionMobEffect(PotionEffectType.LEVITATION, 1.5, 3)
),
EntityType.ENDERMAN, Set.of(
)),
Map.entry(EntityType.ENDERMAN, Set.of(
new MobEffect.PotionMobEffect(PotionEffectType.SLOWNESS, 2.5, 2)
)
))
);
public final int expMultiplier = 3;
public final double mobDamageMultiplier = 2;
public final double mobHealthMultiplier = 2;
private final ThreadLocalRandom random = ThreadLocalRandom.current();
private boolean isActive = false;
private final BossBar bossBar = BossBar.bossBar(
Component.text("Blutmond", NamedTextColor.DARK_RED),
@@ -89,10 +89,11 @@ public class Bloodmoon extends Appliance {
EntityType.SKELETON,
EntityType.SPIDER
);
private final Map<Player, @Nullable BukkitTask> hordeSpawnTasks = new HashMap<>();
private final Map<Player, @Nullable BukkitTask> hordeSpawnTasks = new WeakHashMap<>();
private long lastBloodmoonStartTick = 0;
public final int ticksPerDay = 24000;
public final int bloodmoonLength = ticksPerDay/2;
public final int preStartMessageTicks = Ticks.TICKS_PER_SECOND * 50;
private final int bloodmoonFreeDaysAtStart = 3;
private final int bloodmoonStartTime = ticksPerDay/2;
private final int bloodmoonDayInterval = 30;
@@ -145,7 +146,7 @@ public class Bloodmoon extends Appliance {
}
private int getRandomHordeSpawnDelay() {
return this.hordeSpawnRateTicks + ThreadLocalRandom.current().nextInt(this.hordeSpawnRateVariationTicks);
return this.hordeSpawnRateTicks + this.random.nextInt(this.hordeSpawnRateVariationTicks);
}
private void startHordeSpawning(int delay) {
@@ -155,7 +156,7 @@ public class Bloodmoon extends Appliance {
private void startHordeSpawning(int delay, Player player) {
@Nullable BukkitTask task = this.hordeSpawnTasks.get(player);
if(task != null) task.cancel();
task = Bukkit.getScheduler().runTaskLater(
BukkitTask newTask = Bukkit.getScheduler().runTaskLater(
Main.instance(),
() -> {
if(!this.bloodmoonIsActive()) return;
@@ -164,7 +165,7 @@ public class Bloodmoon extends Appliance {
},
delay
);
this.hordeSpawnTasks.put(player, task);
this.hordeSpawnTasks.put(player, newTask);
}
public void addPlayerToBossBar(Player player) {
@@ -187,9 +188,9 @@ public class Bloodmoon extends Appliance {
public void spawnRandomHorde(Player player) {
if(!this.hordesEnabled) return;
if(!player.getGameMode().equals(GameMode.SURVIVAL)) return;
ThreadLocalRandom random = ThreadLocalRandom.current();
EntityType hordeEntityType = this.hordeMobList.get(random.nextInt(this.hordeMobList.size()));
int hordeSize = random.nextInt(this.hordeMinPopulation, this.hordeMaxPopulation + 1);
EntityType hordeEntityType = this.hordeMobList.get(this.random.nextInt(this.hordeMobList.size()));
int hordeSize = this.random.nextInt(this.hordeMinPopulation, this.hordeMaxPopulation + 1);
this.spawnHorde(player, hordeSize, hordeEntityType);
}
@@ -207,7 +208,7 @@ public class Bloodmoon extends Appliance {
private void spawnHorde(Player player, int size, EntityType type) {
for(int i = 0; i < size; i++) {
double spawnRadiant = ThreadLocalRandom.current().nextDouble(0, 2*Math.PI);
double spawnRadiant = this.random.nextDouble(0, 2*Math.PI);
Location mobSpawnLocation = player.getLocation().add(
Math.sin(spawnRadiant)*this.hordeSpawnDistance,
0,
@@ -220,7 +221,7 @@ public class Bloodmoon extends Appliance {
}
public List<ItemStack> getRandomBonusDrops() {
int itemCount = ThreadLocalRandom.current().nextInt(this.minBonusDrops, this.maxBonusDrops + 1);
int itemCount = this.random.nextInt(this.minBonusDrops, this.maxBonusDrops + 1);
List<ItemStack> result = new ArrayList<>();
for(int i = 0; i < itemCount; i++) {
result.add(this.getRandomBonusDrop());
@@ -228,9 +229,9 @@ public class Bloodmoon extends Appliance {
return result;
}
private ItemStack getRandomBonusDrop() {
private @Nullable ItemStack getRandomBonusDrop() {
int totalWeight = this.bonusDropWeightMap.values().stream().mapToInt(value -> value).sum();
int randomInt = ThreadLocalRandom.current().nextInt(0, totalWeight + 1);
int randomInt = this.random.nextInt(0, totalWeight + 1);
int cumulativeWeight = 0;
for(Map.Entry<ItemStack, Integer> entry : this.bonusDropWeightMap.entrySet()) {
cumulativeWeight += entry.getValue();

View File

@@ -34,7 +34,7 @@ public class BloodmoonSetting extends BoolSetting implements CategorizedSetting
@Override
protected Material icon() {
return Material.CLOCK;
return Material.SKELETON_SKULL;
}
@Override

View File

@@ -3,6 +3,7 @@ package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.list
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
import net.kyori.adventure.util.Ticks;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
@@ -18,12 +19,12 @@ public class BloodmoonTimeListener extends ApplianceListener<Bloodmoon> {
this.getAppliance().stopBloodmoon();
return;
}
this.getAppliance().updateBossBar();
if(currentTime % Ticks.TICKS_PER_SECOND == 0) this.getAppliance().updateBossBar();
if(this.getAppliance().isStartTick(currentTime + this.getAppliance().ticksPerDay)) {
this.getAppliance().sendAnnouncementMessages();
return;
}
if(this.getAppliance().isStartTick(currentTime + 1000)) {
if(this.getAppliance().isStartTick(currentTime + this.getAppliance().preStartMessageTicks)) {
this.getAppliance().sendPreStartMessages();
}
}