Refactor April Fools' prank logic: replace single explosion sound with randomized sounds, add logging, and adjust sound radius.
This commit is contained in:
parent
592f58a89b
commit
6c66ac7cc8
|
|
@ -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("<green>April Fools test triggered. Listen closely...");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -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<Player> 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<Sound> 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<Sound> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user