Files
NexusLobby/src/main/java/de/nexuslobby/modules/gadgets/ChickenRain.java
2026-01-22 23:16:25 +01:00

54 lines
1.9 KiB
Java

package de.nexuslobby.modules.gadgets;
import de.nexuslobby.NexusLobby;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Random;
public class ChickenRain {
public static void start(Player player) {
new BukkitRunnable() {
int ticks = 0;
final Random random = new Random();
@Override
public void run() {
if (!player.isOnline() || ticks > 100) { // 100 Ticks = 5 Sekunden
this.cancel();
return;
}
// Alle 2 Ticks ein Huhn spawnen
if (ticks % 2 == 0) {
Location spawnLoc = player.getLocation().add(
(random.nextDouble() - 0.5) * 4,
4.0,
(random.nextDouble() - 0.5) * 4
);
Chicken chicken = (Chicken) spawnLoc.getWorld().spawnEntity(spawnLoc, EntityType.CHICKEN);
chicken.setBaby();
chicken.setInvulnerable(true);
// Nach 1.5 Sekunden "ploppt" das Huhn
Bukkit.getScheduler().runTaskLater(NexusLobby.getInstance(), () -> {
if (chicken.isValid()) {
chicken.getWorld().spawnParticle(Particle.CLOUD, chicken.getLocation(), 5, 0.2, 0.2, 0.2, 0.1);
chicken.getWorld().playSound(chicken.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1.0f, 1.5f);
chicken.remove();
}
}, 30L);
}
ticks++;
}
}.runTaskTimer(NexusLobby.getInstance(), 0L, 1L);
}
}