diff --git a/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/AprilFools.java b/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/AprilFools.java index e358b61..0bbc3f5 100644 --- a/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/AprilFools.java +++ b/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/AprilFools.java @@ -22,7 +22,7 @@ public class AprilFools extends SubCommand { commandSender.sendRichMessage(Messages.GENERIC.PLAYER_ONLY); return true; } - boolean ok = prank.playExplosionAround(player); + boolean ok = prank.playSoundAroundPlayer(player); if (ok) { commandSender.sendRichMessage("April Fools test triggered. Listen closely..."); } else { diff --git a/src/main/java/com/alttd/playerutils/util/AprilFoolsPrank.java b/src/main/java/com/alttd/playerutils/util/AprilFoolsPrank.java index ccc3039..eb45c20 100644 --- a/src/main/java/com/alttd/playerutils/util/AprilFoolsPrank.java +++ b/src/main/java/com/alttd/playerutils/util/AprilFoolsPrank.java @@ -1,6 +1,7 @@ package com.alttd.playerutils.util; import com.alttd.playerutils.PlayerUtils; +import lombok.extern.slf4j.Slf4j; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Sound; @@ -14,11 +15,12 @@ import java.util.List; import java.util.concurrent.ThreadLocalRandom; /** - * Encapsulates the April Fools' prank logic. - * - schedule(): registers the timed prank that only runs on April 1st and only during overworld night. - * - playExplosionAround(Player): immediately plays the explosion sound around the target for testing (no date/time checks), - * but still requires the target to be in the overworld named "world" to match intended environment. + * Encapsulates the April Fools' prank logic. - schedule(): registers the timed prank that only runs on April 1st and + * only during overworld night. - playExplosionAround(Player): immediately plays the explosion sound around the target + * for testing (no date/time checks), but still requires the target to be in the overworld named "world" to match + * intended environment. */ +@Slf4j public class AprilFoolsPrank { private final PlayerUtils plugin; @@ -38,17 +40,15 @@ public class AprilFoolsPrank { return; // only active on April 1st } -// World world = Bukkit.getWorld("world"); - World world = Bukkit.getWorld("lobby"); - if (world == null) return; // overworld not present - - long time = world.getTime() % 24000L; - if (time < 13000L || time > 23000L) { - return; // only at night + World world = Bukkit.getWorld("world"); + if (world == null) { + return; // overworld not present } List players = world.getPlayers(); - if (players.isEmpty()) return; + if (players.isEmpty()) { + return; + } Player target = players.get(ThreadLocalRandom.current().nextInt(players.size())); playOnce(world, target); @@ -56,29 +56,39 @@ public class AprilFoolsPrank { } /** - * Trigger the prank once around the given player for testing. Returns true if executed. - * This method ignores the date and time checks so it can be tested easily, but it still - * requires the player to be in the overworld named "world". + * Trigger the prank once around the given player for testing. Returns true if executed. This method ignores the + * date and time checks so it can be tested easily, but it still requires the player to be in the overworld named + * "world". */ - public boolean playExplosionAround(Player target) { - if (target == null) return false; + public boolean playSoundAroundPlayer(Player target) { + if (target == null) { + return false; + } World world = target.getWorld(); -// if (!"world".equalsIgnoreCase(world.getName())) { - if (!"lobby".equalsIgnoreCase(world.getName())) { + if (!"world".equalsIgnoreCase(world.getName())) { return false; // only intended for overworld } playOnce(world, target); return true; } + public List getSounds() { + return List.of(Sound.ENTITY_GENERIC_EXPLODE, Sound.BLOCK_BELL_USE, Sound.ENTITY_SPIDER_AMBIENT, + Sound.ENTITY_TNT_PRIMED, Sound.ENTITY_CAT_BEG_FOR_FOOD, Sound.ENTITY_SHULKER_AMBIENT, + Sound.BLOCK_WOODEN_DOOR_CLOSE); + } + private void playOnce(World world, Player target) { Location base = target.getLocation(); - double radius = 30.0; + double radius = 25.0; double r = ThreadLocalRandom.current().nextDouble(radius); double theta = ThreadLocalRandom.current().nextDouble(Math.PI * 2); double dx = r * Math.cos(theta); double dz = r * Math.sin(theta); Location soundLoc = new Location(world, base.getX() + dx, base.getY(), base.getZ() + dz); - world.playSound(soundLoc, Sound.ENTITY_GENERIC_EXPLODE, 0.8f, 1.0f); + List sounds = getSounds(); + Sound chosen = sounds.get(ThreadLocalRandom.current().nextInt(sounds.size())); + log.info("Playing sound {} at {} (for {})", chosen, soundLoc, target.getName()); + world.playSound(soundLoc, chosen, 1f, 1.0f); } }