diff --git a/core/src/main/java/tc/oc/pgm/action/SoundType.java b/core/src/main/java/tc/oc/pgm/action/SoundType.java index cc8238c32e..f5dff9c345 100644 --- a/core/src/main/java/tc/oc/pgm/action/SoundType.java +++ b/core/src/main/java/tc/oc/pgm/action/SoundType.java @@ -1,38 +1,37 @@ package tc.oc.pgm.action; +import net.kyori.adventure.sound.Sound; +import tc.oc.pgm.util.bukkit.Sounds; + public enum SoundType { - CUSTOM("note.pling", 1f, 1f), - TIP("mob.endermen.idle", 1f, 1.2f), - ALERT("note.pling", 1f, 2f), - PORTAL("mob.endermen.portal", 1f, 1f), - SCORE("random.levelup", 1f, 1f), - OBJECTIVE_FIREWORKS_FAR("fireworks.blast_far", 0.75f, 1f), - OBJECTIVE_FIREWORKS_TWINKLE("fireworks.twinkle_far", 0.75f, 1f), - OBJECTIVE_GOOD("portal.travel", 0.7f, 2f), - OBJECTIVE_BAD("mob.blaze.death", 0.8f, 0.8f), - OBJECTIVE_MODE("mob.zombie.remedy", 0.15f, 1.2f), - DEATH_OWN("mob.irongolem.death", 1f, 1f), - DEATH_OTHER("mob.irongolem.hit", 1f, 1f); + CUSTOM(Sounds.CUSTOM), + TIP(Sounds.TIP), + ALERT(Sounds.ALERT), + PORTAL(Sounds.PORTAL), + SCORE(Sounds.SCORE), + OBJECTIVE_FIREWORKS_FAR(Sounds.OBJECTIVE_FIREWORKS_FAR), + OBJECTIVE_FIREWORKS_TWINKLE(Sounds.OBJECTIVE_FIREWORKS_TWINKLE), + OBJECTIVE_GOOD(Sounds.OBJECTIVE_GOOD), + OBJECTIVE_BAD(Sounds.OBJECTIVE_BAD), + OBJECTIVE_MODE(Sounds.OBJECTIVE_MODE), + DEATH_OWN(Sounds.DEATH_OWN), + DEATH_OTHER(Sounds.DEATH_ENEMY); - private final String resource; - private final float volume; - private final float pitch; + private final Sound sound; - SoundType(String resource, float volume, float pitch) { - this.resource = resource; - this.volume = volume; - this.pitch = pitch; + SoundType(Sound sound) { + this.sound = sound; } public String getResource() { - return resource; + return sound.name().value(); } public float getVolume() { - return volume; + return sound.volume(); } public float getPitch() { - return pitch; + return sound.pitch(); } } diff --git a/core/src/main/java/tc/oc/pgm/broadcast/Broadcast.java b/core/src/main/java/tc/oc/pgm/broadcast/Broadcast.java index 276502afb4..cd6a794c32 100644 --- a/core/src/main/java/tc/oc/pgm/broadcast/Broadcast.java +++ b/core/src/main/java/tc/oc/pgm/broadcast/Broadcast.java @@ -1,7 +1,5 @@ package tc.oc.pgm.broadcast; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; import static tc.oc.pgm.util.Assert.assertNotNull; @@ -14,16 +12,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.filter.Filter; +import tc.oc.pgm.util.bukkit.Sounds; public class Broadcast implements Comparable { public enum Type { - TIP( - translatable("misc.tip", NamedTextColor.BLUE), - sound(key("mob.endermen.idle"), Sound.Source.MASTER, 1, 1.2f)), + TIP(translatable("misc.tip", NamedTextColor.BLUE), Sounds.TIP), - ALERT( - translatable("misc.alert", NamedTextColor.YELLOW), - sound(key("note.pling"), Sound.Source.MASTER, 1, 2f)); + ALERT(translatable("misc.alert", NamedTextColor.YELLOW), Sounds.ALERT); final Component prefix; final Sound sound; @@ -38,11 +33,10 @@ public Component format(Component message) { .append(text("[")) .append(prefix) .append(text("] ")) - .append( - message - .color(NamedTextColor.AQUA) - .decoration(TextDecoration.BOLD, false) - .decoration(TextDecoration.ITALIC, true)) + .append(message + .color(NamedTextColor.AQUA) + .decoration(TextDecoration.BOLD, false) + .decoration(TextDecoration.ITALIC, true)) .colorIfAbsent(NamedTextColor.GRAY) .decoration(TextDecoration.BOLD, true) .build(); diff --git a/core/src/main/java/tc/oc/pgm/controlpoint/ControlPoint.java b/core/src/main/java/tc/oc/pgm/controlpoint/ControlPoint.java index 270adf0742..9203198f88 100644 --- a/core/src/main/java/tc/oc/pgm/controlpoint/ControlPoint.java +++ b/core/src/main/java/tc/oc/pgm/controlpoint/ControlPoint.java @@ -1,7 +1,5 @@ package tc.oc.pgm.controlpoint; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.text; import java.time.Duration; @@ -32,6 +30,7 @@ import tc.oc.pgm.teams.TeamMatchModule; import tc.oc.pgm.util.StringUtils; import tc.oc.pgm.util.TimeUtils; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.util.collection.DefaultMapAdapter; public class ControlPoint extends SimpleGoal @@ -42,11 +41,6 @@ public class ControlPoint extends SimpleGoal public static final Component SYMBOL_CP_INCOMPLETE = text("\u29be"); // ⦾ public static final Component SYMBOL_CP_COMPLETE = text("\u29bf"); // ⦿ - protected static final Sound GOOD_SOUND = - sound(key("portal.travel"), Sound.Source.MASTER, 0.35f, 2f); - protected static final Sound BAD_SOUND = - sound(key("mob.blaze.death"), Sound.Source.MASTER, 0.4f, 0.8f); - protected final RegionPlayerTracker playerTracker; protected final ControlPointBlockDisplay blockDisplay; @@ -163,7 +157,7 @@ public Duration getCapturingTime() { @Override public Sound getCompletionSound(boolean isGood) { - return isGood ? GOOD_SOUND : BAD_SOUND; + return isGood ? Sounds.CONTROL_POINT_GOOD : Sounds.CONTROL_POINT_BAD; } /** @@ -172,7 +166,8 @@ public Sound getCompletionSound(boolean isGood) { */ @Override public double getCompletion() { - return this.capturingTime.toMillis() / (double) this.definition.getTimeToCapture().toMillis(); + return this.capturingTime.toMillis() + / (double) this.definition.getTimeToCapture().toMillis(); } @Override @@ -508,9 +503,8 @@ private void uncapture(Competitor dominantTeam, Duration dominantTime) { /** Point being pulled back to current state (There is a lead on the point) */ private void recover(Competitor dominantTeam, Duration dominantTime) { - dominantTime = - subtractCaptureTime( - Duration.ofMillis((long) (definition.getRecoveryRate() * dominantTime.toMillis()))); + dominantTime = subtractCaptureTime( + Duration.ofMillis((long) (definition.getRecoveryRate() * dominantTime.toMillis()))); if (dominantTime != null) { this.capturingTeam = null; if (dominantTeam != this.controllingTeam) { @@ -526,9 +520,8 @@ private void recover(Competitor dominantTeam, Duration dominantTime) { /** Point is being decayed back to its current state (Point is contested) */ private void contestedDecay(Duration dominantTime) { - dominantTime = - subtractCaptureTime( - Duration.ofMillis((long) (definition.getContestedRate() * dominantTime.toMillis()))); + dominantTime = subtractCaptureTime( + Duration.ofMillis((long) (definition.getContestedRate() * dominantTime.toMillis()))); if (dominantTime != null) { this.capturingTeam = null; } @@ -536,9 +529,8 @@ private void contestedDecay(Duration dominantTime) { /** Point is being decayed back to its current state (No lead on point) */ private void decay(Duration dominantTime) { - dominantTime = - subtractCaptureTime( - Duration.ofMillis((long) (definition.getDecayRate() * dominantTime.toMillis()))); + dominantTime = subtractCaptureTime( + Duration.ofMillis((long) (definition.getDecayRate() * dominantTime.toMillis()))); if (dominantTime != null) { this.capturingTeam = null; } @@ -546,9 +538,8 @@ private void decay(Duration dominantTime) { /** Point is being decayed back to neutral (No lead on point) */ private void ownedDecay(Duration dominantTime) { - dominantTime = - addCaptureTime( - Duration.ofMillis((long) (definition.getOwnedDecayRate() * dominantTime.toMillis()))); + dominantTime = addCaptureTime( + Duration.ofMillis((long) (definition.getOwnedDecayRate() * dominantTime.toMillis()))); if (dominantTime != null) { this.controllingTeam = null; this.capturingTeam = null; diff --git a/core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java b/core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java index e89da00d62..0ba2092310 100644 --- a/core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java +++ b/core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java @@ -1,7 +1,5 @@ package tc.oc.pgm.destroyable; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.empty; import static net.kyori.adventure.text.Component.space; import static net.kyori.adventure.text.Component.text; @@ -20,7 +18,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.FireworkEffect; @@ -55,6 +52,7 @@ import tc.oc.pgm.teams.Team; import tc.oc.pgm.util.StringUtils; import tc.oc.pgm.util.block.BlockVectors; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.util.collection.DefaultMapAdapter; import tc.oc.pgm.util.material.BlockMaterialData; import tc.oc.pgm.util.material.MaterialData; @@ -362,9 +360,8 @@ public DestroyableHealthChange handleBlockChange( // for them for (MatchPlayer listener : this.getOwner().getMatch().getPlayers()) { if (listener.getBukkit().getLocation().distance(blockLocation) > 64) { - listener.playSound(sound(key("fireworks.blast_far"), Sound.Source.MASTER, 0.75f, 1f)); - listener.playSound( - sound(key("fireworks.twinkle_far"), Sound.Source.MASTER, 0.75f, 1f)); + listener.playSound(Sounds.OBJECTIVE_FIREWORKS_FAR); + listener.playSound(Sounds.OBJECTIVE_FIREWORKS_TWINKLE); } } } diff --git a/core/src/main/java/tc/oc/pgm/ffa/FreeForAllMatchModule.java b/core/src/main/java/tc/oc/pgm/ffa/FreeForAllMatchModule.java index 225221af8b..9cdce25f39 100644 --- a/core/src/main/java/tc/oc/pgm/ffa/FreeForAllMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/ffa/FreeForAllMatchModule.java @@ -1,8 +1,5 @@ package tc.oc.pgm.ffa; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; -import static net.kyori.adventure.text.Component.join; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; @@ -15,7 +12,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; @@ -38,24 +34,24 @@ import tc.oc.pgm.match.QueuedParty; import tc.oc.pgm.start.StartMatchModule; import tc.oc.pgm.start.UnreadyReason; +import tc.oc.pgm.util.bukkit.Sounds; @ListenerScope(MatchScope.LOADED) public class FreeForAllMatchModule implements MatchModule, Listener, JoinHandler { // 10 different colors that tributes are allowed to have - private static final ChatColor[] COLORS = - new ChatColor[] { - ChatColor.RED, - ChatColor.BLUE, - ChatColor.GREEN, - ChatColor.YELLOW, - ChatColor.LIGHT_PURPLE, - ChatColor.GOLD, - ChatColor.DARK_GREEN, - ChatColor.DARK_AQUA, - ChatColor.DARK_PURPLE, - ChatColor.DARK_RED - }; + private static final ChatColor[] COLORS = new ChatColor[] { + ChatColor.RED, + ChatColor.BLUE, + ChatColor.GREEN, + ChatColor.YELLOW, + ChatColor.LIGHT_PURPLE, + ChatColor.GOLD, + ChatColor.DARK_GREEN, + ChatColor.DARK_AQUA, + ChatColor.DARK_PURPLE, + ChatColor.DARK_RED + }; class NeedMorePlayers implements UnreadyReason { final int players; @@ -82,7 +78,8 @@ public boolean canForceStart() { public String toString() { return getClass().getSimpleName() + "{players=" + players + "}"; } - }; + } + ; private final Match match; private final FreeForAllOptions options; @@ -205,7 +202,7 @@ protected boolean priorityKick(JoinRequest request) { MatchPlayer kickMe = kickable.get(match.getRandom().nextInt(kickable.size())); kickMe.sendWarning(translatable("leave.ok.priorityKick")); - kickMe.playSound(sound(key("mob.villager.hit"), Sound.Source.MASTER, 1, 1)); + kickMe.playSound(Sounds.MATCH_KICK); match.setParty(kickMe, match.getDefaultParty()); diff --git a/core/src/main/java/tc/oc/pgm/flag/Flag.java b/core/src/main/java/tc/oc/pgm/flag/Flag.java index 8f0f0d0dd7..48a833618f 100644 --- a/core/src/main/java/tc/oc/pgm/flag/Flag.java +++ b/core/src/main/java/tc/oc/pgm/flag/Flag.java @@ -1,7 +1,5 @@ package tc.oc.pgm.flag; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; import static tc.oc.pgm.util.material.ColorUtils.COLOR_UTILS; @@ -76,20 +74,6 @@ public class Flag extends TouchableGoal implements Listener { public static final Component DROPPED_SYMBOL = text("\u2691"); // ⚑ public static final Component CARRIED_SYMBOL = text("\u2794"); // ➔ - public static final Sound PICKUP_SOUND_OWN = - sound(key("mob.wither.idle"), Sound.Source.MASTER, 0.7f, 1.2f); - public static final Sound DROP_SOUND_OWN = - sound(key("mob.wither.hurt"), Sound.Source.MASTER, 0.7f, 1); - public static final Sound RETURN_SOUND_OWN = - sound(key("mob.zombie.infect"), Sound.Source.MASTER, 1.1f, 1.2f); - - public static final Sound PICKUP_SOUND = - sound(key("entity.firework_rocket.blast_far"), Sound.Source.MASTER, 1f, 0.7f); - public static final Sound DROP_SOUND = - sound(key("entity.firework_rocket.twinkle_far"), Sound.Source.MASTER, 1f, 1f); - public static final Sound RETURN_SOUND = - sound(key("entity.firework_rocket.twinkle_far"), Sound.Source.MASTER, 1f, 1f); - private final ImmutableSet nets; private final Location bannerLocation; private final ColorUtils.BannerData bannerData; diff --git a/core/src/main/java/tc/oc/pgm/flag/state/Dropped.java b/core/src/main/java/tc/oc/pgm/flag/state/Dropped.java index e5e991b4f4..0fa681003b 100644 --- a/core/src/main/java/tc/oc/pgm/flag/state/Dropped.java +++ b/core/src/main/java/tc/oc/pgm/flag/state/Dropped.java @@ -16,6 +16,7 @@ import tc.oc.pgm.goals.events.GoalStatusChangeEvent; import tc.oc.pgm.scoreboard.SidebarMatchModule; import tc.oc.pgm.util.TimeUtils; +import tc.oc.pgm.util.bukkit.Sounds; /** * State of a flag after a player drops it on the ground, either by dying or by clicking on the @@ -47,7 +48,7 @@ public void enterState() { super.enterState(); if (!Duration.ZERO.equals(getDuration())) { - this.flag.playStatusSound(Flag.DROP_SOUND_OWN, Flag.DROP_SOUND); + this.flag.playStatusSound(Sounds.FLAG_DROP_OWN, Sounds.FLAG_DROP); this.flag.getMatch().sendMessage(translatable("flag.drop", this.flag.getComponentName())); } diff --git a/core/src/main/java/tc/oc/pgm/flag/state/Respawning.java b/core/src/main/java/tc/oc/pgm/flag/state/Respawning.java index 8bbd34233d..1d96946d9b 100644 --- a/core/src/main/java/tc/oc/pgm/flag/state/Respawning.java +++ b/core/src/main/java/tc/oc/pgm/flag/state/Respawning.java @@ -15,6 +15,7 @@ import tc.oc.pgm.flag.Flag; import tc.oc.pgm.flag.Post; import tc.oc.pgm.goals.events.GoalStatusChangeEvent; +import tc.oc.pgm.util.bukkit.Sounds; /** * State of a flag while it is waiting to respawn at a {@link Post} after being {@link Captured}. @@ -37,9 +38,8 @@ protected Respawning( super(flag, post); this.respawnFrom = respawnFrom; this.respawnTo = this.flag.getReturnPoint(this.post); - this.respawnTime = - this.post.getRespawnTime( - this.respawnFrom == null ? 0 : this.respawnFrom.distance(this.respawnTo)); + this.respawnTime = this.post.getRespawnTime( + this.respawnFrom == null ? 0 : this.respawnFrom.distance(this.respawnTo)); this.wasCaptured = wasCaptured; this.wasDelayed = wasDelayed; } @@ -58,20 +58,19 @@ public void enterState() { String postName = this.post.getPostName(); TranslatableComponent timeComponent = duration(respawnTime, NamedTextColor.AQUA); - Component message = - postName != null - ? translatable( - "flag.willRespawn.named", - this.flag.getComponentName(), - text(postName, NamedTextColor.AQUA), - timeComponent) - : translatable("flag.willRespawn", this.flag.getComponentName(), timeComponent); + Component message = postName != null + ? translatable( + "flag.willRespawn.named", + this.flag.getComponentName(), + text(postName, NamedTextColor.AQUA), + timeComponent) + : translatable("flag.willRespawn", this.flag.getComponentName(), timeComponent); this.flag.getMatch().sendMessage(message); } protected void respawn(@Nullable Component message) { if (message != null) { - this.flag.playStatusSound(Flag.RETURN_SOUND_OWN, Flag.RETURN_SOUND); + this.flag.playStatusSound(Sounds.FLAG_RETURN_OWN, Sounds.FLAG_RETURN); this.flag.getMatch().sendMessage(message); } diff --git a/core/src/main/java/tc/oc/pgm/flag/state/Uncarried.java b/core/src/main/java/tc/oc/pgm/flag/state/Uncarried.java index cc60214bf4..2bc736b35d 100644 --- a/core/src/main/java/tc/oc/pgm/flag/state/Uncarried.java +++ b/core/src/main/java/tc/oc/pgm/flag/state/Uncarried.java @@ -22,6 +22,7 @@ import tc.oc.pgm.hologram.Hologram; import tc.oc.pgm.hologram.HologramMatchModule; import tc.oc.pgm.util.block.BlockStates; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.util.material.Materials; /** Base class for flag states in which the banner is placed on the ground somewhere as a block */ @@ -36,14 +37,13 @@ public abstract class Uncarried extends Spawned { public Uncarried(Flag flag, Post post, @Nullable Location location) { super(flag, post); if (location == null) location = flag.getReturnPoint(post); - this.location = - new Location( - location.getWorld(), - location.getBlockX() + 0.5, - location.getBlockY(), - location.getBlockZ() + 0.5, - location.getYaw(), - location.getPitch()); + this.location = new Location( + location.getWorld(), + location.getBlockX() + 0.5, + location.getBlockY(), + location.getBlockZ() + 0.5, + location.getYaw(), + location.getPitch()); Block block = this.location.getBlock(); if (block.getState() instanceof Banner) { @@ -53,10 +53,9 @@ public Uncarried(Flag flag, Post post, @Nullable Location location) { this.oldBlock = block.getState(); } this.oldBase = block.getRelative(BlockFace.DOWN).getState(); - this.hologram = - flag.getMatch() - .needModule(HologramMatchModule.class) - .createHologram(this.location.clone().add(0, 1.7, 0), flag.getComponentName(), false); + this.hologram = flag.getMatch() + .needModule(HologramMatchModule.class) + .createHologram(this.location.clone().add(0, 1.7, 0), flag.getComponentName(), false); } @Override @@ -118,7 +117,7 @@ protected boolean pickupFlag(MatchPlayer carrier) { this.pickingUp = null; } - this.flag.playStatusSound(Flag.PICKUP_SOUND_OWN, Flag.PICKUP_SOUND); + this.flag.playStatusSound(Sounds.FLAG_PICKUP_OWN, Sounds.FLAG_PICKUP); this.flag.touch(carrier.getParticipantState()); this.flag.transition(new Carried(this.flag, this.post, carrier, this.location)); diff --git a/core/src/main/java/tc/oc/pgm/goals/SimpleGoal.java b/core/src/main/java/tc/oc/pgm/goals/SimpleGoal.java index b112885c37..81d97671a4 100644 --- a/core/src/main/java/tc/oc/pgm/goals/SimpleGoal.java +++ b/core/src/main/java/tc/oc/pgm/goals/SimpleGoal.java @@ -1,7 +1,5 @@ package tc.oc.pgm.goals; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.text; import java.util.logging.Logger; @@ -19,6 +17,7 @@ import tc.oc.pgm.api.party.Party; import tc.oc.pgm.score.ScoreMatchModule; import tc.oc.pgm.util.ClassLogger; +import tc.oc.pgm.util.bukkit.Sounds; /** Basic {@link Goal} implementation with fields for the definition and match */ public abstract class SimpleGoal implements Goal { @@ -29,11 +28,6 @@ public abstract class SimpleGoal implements Goal { public static final Component SYMBOL_INCOMPLETE = text("\u2715"); // ✕ public static final Component SYMBOL_COMPLETE = text("\u2714"); // ✔ - protected static final Sound GOOD_SOUND = - sound(key("portal.travel"), Sound.Source.MASTER, 0.7f, 2f); - protected static final Sound BAD_SOUND = - sound(key("mob.blaze.death"), Sound.Source.MASTER, 0.8f, 0.8f); - protected final Logger logger; protected final T definition; protected final Match match; @@ -86,7 +80,7 @@ public DyeColor getDyeColor() { @Override public Sound getCompletionSound(boolean isGood) { - return isGood ? GOOD_SOUND : BAD_SOUND; + return isGood ? Sounds.OBJECTIVE_GOOD : Sounds.OBJECTIVE_BAD; } @Override diff --git a/core/src/main/java/tc/oc/pgm/listeners/AntiGriefListener.java b/core/src/main/java/tc/oc/pgm/listeners/AntiGriefListener.java index 70eec160af..c31bce06b8 100644 --- a/core/src/main/java/tc/oc/pgm/listeners/AntiGriefListener.java +++ b/core/src/main/java/tc/oc/pgm/listeners/AntiGriefListener.java @@ -1,14 +1,10 @@ package tc.oc.pgm.listeners; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.translatable; -import static tc.oc.pgm.util.player.PlayerComponent.player; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; @@ -34,6 +30,7 @@ import tc.oc.pgm.spawns.events.ObserverKitApplyEvent; import tc.oc.pgm.tnt.TNTMatchModule; import tc.oc.pgm.tracker.Trackers; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.util.event.player.PlayerAttackEntityEvent; import tc.oc.pgm.util.material.Materials; import tc.oc.pgm.util.named.NameStyle; @@ -46,8 +43,6 @@ public class AntiGriefListener implements Listener { private static final Material DEFUSE_ITEM = Material.SHEARS; private static final int DEFUSE_SLOT = 4; - private static final Sound DEFUSE_SOUND = sound(key("random.fizz"), Sound.Source.MASTER, 1, 1); - private final MatchManager mm; public AntiGriefListener(MatchManager mm) { @@ -124,7 +119,7 @@ private void notifyDefuse(MatchPlayer clicker, Entity entity, Component message) clicker .getMatch() .playSound( - DEFUSE_SOUND, + Sounds.DEFUSE, entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ()); diff --git a/core/src/main/java/tc/oc/pgm/listeners/ChatDispatcher.java b/core/src/main/java/tc/oc/pgm/listeners/ChatDispatcher.java index 5c54dc26d9..c9e3588ba7 100644 --- a/core/src/main/java/tc/oc/pgm/listeners/ChatDispatcher.java +++ b/core/src/main/java/tc/oc/pgm/listeners/ChatDispatcher.java @@ -1,8 +1,6 @@ package tc.oc.pgm.listeners; import static net.kyori.adventure.identity.Identity.identity; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.space; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; @@ -55,6 +53,7 @@ import tc.oc.pgm.util.Audience; import tc.oc.pgm.util.Players; import tc.oc.pgm.util.bukkit.BukkitUtils; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.util.channels.Channel; import tc.oc.pgm.util.event.ChannelMessageEvent; import tc.oc.pgm.util.named.NameStyle; @@ -79,9 +78,6 @@ public static ChatDispatcher get() { .append(text("] ", NamedTextColor.WHITE)) .build(); - private static final Sound DM_SOUND = sound(key("random.orb"), Sound.Source.MASTER, 1f, 1.2f); - private static final Sound AC_SOUND = sound(key("random.orb"), Sound.Source.MASTER, 1f, 0.7f); - private static final String GLOBAL_SYMBOL = "!"; private static final String DM_SYMBOL = "@"; private static final String ADMIN_CHAT_SYMBOL = "$"; @@ -192,7 +188,7 @@ public void sendAdmin( match.getPlayers().stream() .filter(AC_FILTER) // Initial filter .filter(viewer -> !viewer.equals(sender)) // Don't play sound for sender - .forEach(pl -> playSound(pl, AC_SOUND)); + .forEach(pl -> playSound(pl, Sounds.ADMIN_CHAT)); } } @@ -258,7 +254,7 @@ public void sendDirect( s -> true, null, Channel.PRIVATE_SENDER); - playSound(receiver, DM_SOUND); + playSound(receiver, Sounds.DIRECT_MESSAGE); } private String formatPrivateMessage(String key, CommandSender viewer) { @@ -419,7 +415,7 @@ public static void playSound(MatchPlayer player, Sound sound) { SettingValue value = player.getSettings().getValue(SettingKey.SOUNDS); if (value.equals(SettingValue.SOUNDS_ALL) || value.equals(SettingValue.SOUNDS_CHAT) - || (sound.equals(DM_SOUND) && value.equals(SettingValue.SOUNDS_DM))) { + || (sound.equals(Sounds.DIRECT_MESSAGE) && value.equals(SettingValue.SOUNDS_DM))) { player.playSound(sound); } } diff --git a/core/src/main/java/tc/oc/pgm/listeners/MatchAnnouncer.java b/core/src/main/java/tc/oc/pgm/listeners/MatchAnnouncer.java index 3b45f4e56e..75600145aa 100644 --- a/core/src/main/java/tc/oc/pgm/listeners/MatchAnnouncer.java +++ b/core/src/main/java/tc/oc/pgm/listeners/MatchAnnouncer.java @@ -1,7 +1,5 @@ package tc.oc.pgm.listeners; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.empty; import static net.kyori.adventure.text.Component.space; import static net.kyori.adventure.text.Component.text; @@ -14,7 +12,6 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.TimeUnit; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -35,19 +32,12 @@ import tc.oc.pgm.events.PlayerJoinMatchEvent; import tc.oc.pgm.teams.Team; import tc.oc.pgm.util.LegacyFormatUtils; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.util.named.MapNameStyle; import tc.oc.pgm.util.named.NameStyle; import tc.oc.pgm.util.text.TextFormatter; public class MatchAnnouncer implements Listener { - - private static final Sound SOUND_MATCH_START = - sound(key("note.pling"), Sound.Source.MASTER, 1f, 1.59f); - private static final Sound SOUND_MATCH_WIN = - sound(key("mob.wither.death"), Sound.Source.MASTER, 1f, 1f); - private static final Sound SOUND_MATCH_LOSE = - sound(key("mob.wither.spawn"), Sound.Source.MASTER, 1f, 1f); - @EventHandler(priority = EventPriority.MONITOR) public void onMatchLoad(final MatchLoadEvent event) { final Match match = event.getMatch(); @@ -66,7 +56,7 @@ public void onMatchBegin(final MatchStartEvent event) { match.showTitle( title(go, empty(), Title.Times.times(Duration.ZERO, fromTicks(5), fromTicks(15)))); - match.playSound(SOUND_MATCH_START); + match.playSound(Sounds.MATCH_START); } @EventHandler(priority = EventPriority.MONITOR) @@ -92,19 +82,19 @@ public void onMatchEnd(final MatchFinishEvent event) { // Use stream here instead of #contains to avoid unchecked cast if (winners.stream().anyMatch(w -> w == viewer.getParty())) { // Winner - viewer.playSound(SOUND_MATCH_WIN); + viewer.playSound(Sounds.MATCH_WIN); if (singleWinner && viewer.getParty() instanceof Team) { subtitle = translatable("broadcast.gameOver.teamWon", NamedTextColor.GREEN); } } else if (viewer.getParty() instanceof Competitor) { // Loser - viewer.playSound(SOUND_MATCH_LOSE); + viewer.playSound(Sounds.MATCH_LOSE); if (singleWinner && viewer.getParty() instanceof Team) { subtitle = translatable("broadcast.gameOver.teamLost", NamedTextColor.RED); } } else { // Observer - viewer.playSound(SOUND_MATCH_WIN); + viewer.playSound(Sounds.MATCH_WIN); } } diff --git a/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java b/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java index 8d9df3b0c6..5f2769deba 100644 --- a/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java @@ -1,7 +1,5 @@ package tc.oc.pgm.modes; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.text; import com.google.common.collect.ImmutableList; @@ -9,7 +7,6 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.event.EventHandler; @@ -22,26 +19,23 @@ import tc.oc.pgm.countdowns.CountdownContext; import tc.oc.pgm.events.ListenerScope; import tc.oc.pgm.filters.FilterMatchModule; +import tc.oc.pgm.util.bukkit.Sounds; @ListenerScope(MatchScope.LOADED) public class ObjectiveModesMatchModule implements MatchModule, Listener { - private static final Sound SOUND = - sound(key("mob.zombie.remedy"), Sound.Source.MASTER, 0.15f, 1.2f); - // Sort by what's the next known mode to trigger // - Sort by remaining time (applicable while match is running). // - Non-triggered filtered modes go last (if triggered, they'd have a remaining time) // - Then sort by after time defined in monument mode // - Lastly sort by name - private static final Comparator MODE_COMPARATOR = - Comparator.comparing( - ModeChangeCountdown::getRemaining, Comparator.nullsLast(Comparator.naturalOrder())) - .thenComparing( - ModeChangeCountdown::getMode, - Comparator.comparing((Mode m) -> m.getFilter() != null) - .thenComparing(Mode::getAfter) - .thenComparing(Mode::getLegacyName)); + private static final Comparator MODE_COMPARATOR = Comparator.comparing( + ModeChangeCountdown::getRemaining, Comparator.nullsLast(Comparator.naturalOrder())) + .thenComparing( + ModeChangeCountdown::getMode, + Comparator.comparing((Mode m) -> m.getFilter() != null) + .thenComparing(Mode::getAfter) + .thenComparing(Mode::getLegacyName)); private final Match match; private final ImmutableList modes; @@ -63,14 +57,11 @@ public void load() throws ModuleLoadException { this.countdowns.add(countdown); if (mode.getFilter() != null) { // if filter returns ALLOW at any time in the match, start countdown for mode change - fmm.onRise( - Match.class, - mode.getFilter(), - listener -> { - if (!this.countdownContext.isRunning(countdown) && match.isRunning()) { - this.countdownContext.start(countdown, countdown.getMode().getAfter()); - } - }); + fmm.onRise(Match.class, mode.getFilter(), listener -> { + if (!this.countdownContext.isRunning(countdown) && match.isRunning()) { + this.countdownContext.start(countdown, countdown.getMode().getAfter()); + } + }); } } } @@ -120,20 +111,22 @@ public List getActiveCountdowns() { } public ModeChangeCountdown getCountdown(Mode mode) { - return this.countdowns.stream().filter(mcc -> mcc.getMode() == mode).findFirst().orElse(null); + return this.countdowns.stream() + .filter(mcc -> mcc.getMode() == mode) + .findFirst() + .orElse(null); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onObjectiveModeChange(ObjectiveModeChangeEvent event) { if (event.isVisible()) { - Component broadcast = - text() - .append(text("> > > > ", NamedTextColor.DARK_AQUA)) - .append(text(event.getName(), NamedTextColor.DARK_RED)) - .append(text(" < < < <", NamedTextColor.DARK_AQUA)) - .build(); + Component broadcast = text() + .append(text("> > > > ", NamedTextColor.DARK_AQUA)) + .append(text(event.getName(), NamedTextColor.DARK_RED)) + .append(text(" < < < <", NamedTextColor.DARK_AQUA)) + .build(); match.sendMessage(broadcast); - match.playSound(SOUND); + match.playSound(Sounds.OBJECTIVE_MODE); } } } diff --git a/core/src/main/java/tc/oc/pgm/modules/ModifyBowProjectileMatchModule.java b/core/src/main/java/tc/oc/pgm/modules/ModifyBowProjectileMatchModule.java index 9e71f75126..92a3c1f572 100644 --- a/core/src/main/java/tc/oc/pgm/modules/ModifyBowProjectileMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/modules/ModifyBowProjectileMatchModule.java @@ -1,12 +1,9 @@ package tc.oc.pgm.modules; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static tc.oc.pgm.util.bukkit.MiscUtils.MISC_UTILS; import static tc.oc.pgm.util.nms.NMSHacks.NMS_HACKS; import java.util.Set; -import net.kyori.adventure.sound.Sound; import org.bukkit.World; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; @@ -32,6 +29,7 @@ import tc.oc.pgm.filters.query.PlayerQuery; import tc.oc.pgm.projectile.EntityLaunchEvent; import tc.oc.pgm.util.bukkit.MetadataUtils; +import tc.oc.pgm.util.bukkit.Sounds; @ListenerScope(MatchScope.RUNNING) public class ModifyBowProjectileMatchModule implements MatchModule, Listener { @@ -42,9 +40,6 @@ public class ModifyBowProjectileMatchModule implements MatchModule, Listener { private final Set potionEffects; private final Filter pickupFilter; - private static final Sound PROJECTILE_SOUND = - sound(key("random.successful_hit"), Sound.Source.MASTER, 0.18f, 0.45f); - public ModifyBowProjectileMatchModule( Match match, Class cls, @@ -150,7 +145,7 @@ public void fixEntityDamage(EntityDamageByEntityEvent event) { Player bukkitShooter = (Player) customProjectile.getShooter(); MatchPlayer shooter = match.getPlayer(bukkitShooter); if (shooter != null && event.getEntity() != null) { - shooter.playSound(PROJECTILE_SOUND); + shooter.playSound(Sounds.PROJECTILE_HIT); } } } diff --git a/core/src/main/java/tc/oc/pgm/modules/SoundsMatchModule.java b/core/src/main/java/tc/oc/pgm/modules/SoundsMatchModule.java index 4d14183020..4b6cd16bef 100644 --- a/core/src/main/java/tc/oc/pgm/modules/SoundsMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/modules/SoundsMatchModule.java @@ -1,8 +1,5 @@ package tc.oc.pgm.modules; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; - import net.kyori.adventure.sound.Sound; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -22,6 +19,7 @@ import tc.oc.pgm.api.setting.SettingValue; import tc.oc.pgm.events.ListenerScope; import tc.oc.pgm.goals.events.GoalTouchEvent; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.wool.PlayerWoolPlaceEvent; @ListenerScope(MatchScope.RUNNING) @@ -34,9 +32,6 @@ public SoundsMatchModule createMatchModule(Match match) throws ModuleLoadExcepti } } - private static final Sound RAINDROP_SOUND = - sound(key("random.levelup"), Sound.Source.MASTER, 1f, 1.5f); - private void playSound(MatchPlayer player, Sound sound) { if (player.getSettings().getValue(SettingKey.SOUNDS).equals(SettingValue.SOUNDS_ALL)) { player.playSound(sound); @@ -56,25 +51,25 @@ public void onMatchPlayerDeath(MatchPlayerDeathEvent event) { ParticipantState killer = event.getKiller(); MatchPlayer victim = event.getVictim(); if (killer != null && !killer.getParty().equals(victim.getParty())) { - playSound(killer, RAINDROP_SOUND); + playSound(killer, Sounds.RAINDROPS); } } @EventHandler(priority = EventPriority.MONITOR) public void onMatchFinish(MatchFinishEvent event) { - event.getWinners().forEach(player -> playSound(player, RAINDROP_SOUND)); + event.getWinners().forEach(player -> playSound(player, Sounds.RAINDROPS)); } @EventHandler(priority = EventPriority.MONITOR) public void onGoalTouch(GoalTouchEvent event) { ParticipantState player = event.getPlayer(); if (player != null) { - playSound(player, RAINDROP_SOUND); + playSound(player, Sounds.RAINDROPS); } } @EventHandler(priority = EventPriority.MONITOR) public void onPlayerWoolPlace(PlayerWoolPlaceEvent event) { - playSound(event.getPlayer(), RAINDROP_SOUND); + playSound(event.getPlayer(), Sounds.RAINDROPS); } } diff --git a/core/src/main/java/tc/oc/pgm/picker/PickerMatchModule.java b/core/src/main/java/tc/oc/pgm/picker/PickerMatchModule.java index c6b5f830e4..1455294924 100644 --- a/core/src/main/java/tc/oc/pgm/picker/PickerMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/picker/PickerMatchModule.java @@ -1,7 +1,6 @@ package tc.oc.pgm.picker; import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; import static tc.oc.pgm.util.Assert.assertTrue; @@ -15,7 +14,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -62,6 +60,7 @@ import tc.oc.pgm.util.LegacyFormatUtils; import tc.oc.pgm.util.StringUtils; import tc.oc.pgm.util.bukkit.Enchantments; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.util.event.player.PlayerLocaleChangeEvent; import tc.oc.pgm.util.inventory.InventoryUtils; import tc.oc.pgm.util.material.MaterialData; @@ -663,7 +662,7 @@ private String getTeamSizeDescription(final int num, final int max) { private void handleInventoryClick( final MatchPlayer player, final String name, final ItemStack item) { - player.playSound(sound(key("random.click"), Sound.Source.MASTER, 1, 2)); + player.playSound(Sounds.INVENTORY_CLICK); if (hasClasses) { ClassMatchModule cmm = player.getMatch().needModule(ClassMatchModule.class); diff --git a/core/src/main/java/tc/oc/pgm/portals/Portal.java b/core/src/main/java/tc/oc/pgm/portals/Portal.java index 16e049dc41..4a65e1191d 100644 --- a/core/src/main/java/tc/oc/pgm/portals/Portal.java +++ b/core/src/main/java/tc/oc/pgm/portals/Portal.java @@ -1,10 +1,7 @@ package tc.oc.pgm.portals; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static tc.oc.pgm.util.nms.PlayerUtils.PLAYER_UTILS; -import net.kyori.adventure.sound.Sound; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; @@ -14,6 +11,7 @@ import tc.oc.pgm.api.match.Match; import tc.oc.pgm.api.player.MatchPlayer; import tc.oc.pgm.filters.FilterMatchModule; +import tc.oc.pgm.util.bukkit.Sounds; public class Portal implements FeatureDefinition { @@ -41,16 +39,13 @@ public Portal( } public void load(FilterMatchModule fmm) { - fmm.onRise( - MatchPlayer.class, - trigger, - matchPlayer -> { - if (matchPlayer != null - && canUse(matchPlayer) - && !PortalMatchModule.teleported(matchPlayer)) { - teleportPlayer(matchPlayer, matchPlayer.getBukkit().getLocation()); - } - }); + fmm.onRise(MatchPlayer.class, trigger, matchPlayer -> { + if (matchPlayer != null + && canUse(matchPlayer) + && !PortalMatchModule.teleported(matchPlayer)) { + teleportPlayer(matchPlayer, matchPlayer.getBukkit().getLocation()); + } + }); } protected boolean canUse(MatchPlayer player) { @@ -82,11 +77,7 @@ protected void teleportPlayer(final MatchPlayer player, final Location from) { for (MatchPlayer listener : match.getPlayers()) { if (listener != player && listener.getBukkit().canSee(player.getBukkit())) { final Location loc = bukkit.getLocation(); - listener.playSound( - sound(key("mob.endermen.portal"), Sound.Source.MASTER, 1f, 1f), - loc.getX(), - loc.getY(), - loc.getZ()); + listener.playSound(Sounds.PORTAL, loc.getX(), loc.getY(), loc.getZ()); } } } @@ -105,11 +96,7 @@ protected void teleportPlayer(final MatchPlayer player, final Location from) { if (this.sound) { for (MatchPlayer listener : match.getPlayers()) { if (listener.getBukkit().canSee(player.getBukkit())) { - listener.playSound( - sound(key("mob.endermen.portal"), Sound.Source.MASTER, 1f, 1f), - to.getX(), - to.getY(), - to.getZ()); + listener.playSound(Sounds.PORTAL, to.getX(), to.getY(), to.getZ()); } } } diff --git a/core/src/main/java/tc/oc/pgm/proximity/ProximityAlarm.java b/core/src/main/java/tc/oc/pgm/proximity/ProximityAlarm.java index d97d90a0ea..4fbe890517 100644 --- a/core/src/main/java/tc/oc/pgm/proximity/ProximityAlarm.java +++ b/core/src/main/java/tc/oc/pgm/proximity/ProximityAlarm.java @@ -1,14 +1,11 @@ package tc.oc.pgm.proximity; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.text; import static tc.oc.pgm.util.nms.NMSHacks.NMS_HACKS; import java.util.HashSet; import java.util.Random; import java.util.Set; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Color; import org.bukkit.FireworkEffect; @@ -18,14 +15,12 @@ import tc.oc.pgm.api.player.MatchPlayer; import tc.oc.pgm.controlpoint.RegionPlayerTracker; import tc.oc.pgm.fireworks.FireworkMatchModule; +import tc.oc.pgm.util.bukkit.Sounds; public class ProximityAlarm { private static final long MESSAGE_INTERVAL = 5000; private static final float FLARE_CHANCE = 0.25f; - private static final Sound SOUND = - sound(key("fireworks.blast_far"), Sound.Source.MASTER, 1f, 0.7f); - protected final Random random; protected final Match match; protected final ProximityAlarmDefinition definition; @@ -42,7 +37,8 @@ public ProximityAlarm(Match match, ProximityAlarmDefinition definition, Random r } public void showAlarm() { - if (this.random.nextFloat() < FLARE_CHANCE && !this.playerTracker.getPlayers().isEmpty()) { + if (this.random.nextFloat() < FLARE_CHANCE + && !this.playerTracker.getPlayers().isEmpty()) { this.showFlare(); this.showMessage(); } @@ -52,16 +48,15 @@ private void showFlare() { if (!definition.flares) return; float angle = (float) (this.random.nextFloat() * Math.PI * 2); - Location location = - this.definition - .detectRegion - .getBounds() - .getCenterPoint() - .toLocation(match.getWorld()) - .add( - Math.sin(angle) * this.definition.flareRadius, - 0, - Math.cos(angle) * this.definition.flareRadius); + Location location = this.definition + .detectRegion + .getBounds() + .getCenterPoint() + .toLocation(match.getWorld()) + .add( + Math.sin(angle) * this.definition.flareRadius, + 0, + Math.cos(angle) * this.definition.flareRadius); Set colors = new HashSet<>(); @@ -69,11 +64,13 @@ private void showFlare() { colors.add(player.getParty().getFullColor()); } - Firework firework = - FireworkMatchModule.spawnFirework( - location, - FireworkEffect.builder().with(FireworkEffect.Type.BALL).withColor(colors).build(), - 0); + Firework firework = FireworkMatchModule.spawnFirework( + location, + FireworkEffect.builder() + .with(FireworkEffect.Type.BALL) + .withColor(colors) + .build(), + 0); NMS_HACKS.skipFireworksLaunch(firework); } @@ -89,7 +86,7 @@ private void showMessage() { for (MatchPlayer player : this.match.getPlayers()) { if (this.definition.alertFilter.query(player).isAllowed()) { player.sendMessage(text(this.definition.alertMessage, NamedTextColor.RED)); - player.playSound(SOUND); + player.playSound(Sounds.PROXIMITY_ALARM); } } } diff --git a/core/src/main/java/tc/oc/pgm/score/ScoreMatchModule.java b/core/src/main/java/tc/oc/pgm/score/ScoreMatchModule.java index 99afadb6d2..d4c1badc1e 100644 --- a/core/src/main/java/tc/oc/pgm/score/ScoreMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/score/ScoreMatchModule.java @@ -1,7 +1,5 @@ package tc.oc.pgm.score; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; import static tc.oc.pgm.util.Assert.assertTrue; @@ -16,7 +14,6 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; @@ -40,6 +37,7 @@ import tc.oc.pgm.events.ListenerScope; import tc.oc.pgm.events.PlayerParticipationStartEvent; import tc.oc.pgm.ffa.FreeForAllMatchModule; +import tc.oc.pgm.util.bukkit.Sounds; import tc.oc.pgm.util.collection.DefaultMapAdapter; import tc.oc.pgm.util.event.PlayerCoarseMoveEvent; import tc.oc.pgm.util.event.PlayerItemTransferEvent; @@ -279,7 +277,7 @@ private void playerScore(ScoreBox box, MatchPlayer player, double points) { wholePoints == 1 ? "misc.point" : "misc.points", text(wholePoints, NamedTextColor.DARK_AQUA)), player.getParty().getName())); - player.playSound(sound(key("random.levelup"), Sound.Source.MASTER, 1, 1)); + player.playSound(Sounds.SCORE); } public void incrementScore(UUID player, Competitor competitor, double amount) { diff --git a/core/src/main/java/tc/oc/pgm/shops/Shop.java b/core/src/main/java/tc/oc/pgm/shops/Shop.java index 78bf64675c..6738c52e0c 100644 --- a/core/src/main/java/tc/oc/pgm/shops/Shop.java +++ b/core/src/main/java/tc/oc/pgm/shops/Shop.java @@ -1,22 +1,18 @@ package tc.oc.pgm.shops; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.translatable; import com.google.common.collect.ImmutableList; import java.util.List; import java.util.stream.Collectors; -import net.kyori.adventure.sound.Sound; import tc.oc.pgm.api.player.MatchPlayer; import tc.oc.pgm.features.SelfIdentifyingFeatureDefinition; import tc.oc.pgm.shops.menu.Category; import tc.oc.pgm.shops.menu.Icon; +import tc.oc.pgm.util.bukkit.Sounds; public class Shop extends SelfIdentifyingFeatureDefinition { - private static Sound PURCHASE_SOUND = sound(key("fire.ignite"), Sound.Source.MASTER, 1f, 1.4f); - private final String name; private final ImmutableList categories; @@ -44,7 +40,7 @@ public void purchase(Icon icon, MatchPlayer buyer) { if (icon.takePayment(buyer)) { icon.getAction().trigger(buyer); buyer.getBukkit().updateInventory(); - buyer.playSound(PURCHASE_SOUND); + buyer.playSound(Sounds.SHOP_PURCHASE); } else if (!buyer.getMatch().isRunning()) { buyer.sendWarning(translatable("match.error.noMatch")); } else { diff --git a/core/src/main/java/tc/oc/pgm/spawns/states/Alive.java b/core/src/main/java/tc/oc/pgm/spawns/states/Alive.java index fc282171fd..5859ad6a85 100644 --- a/core/src/main/java/tc/oc/pgm/spawns/states/Alive.java +++ b/core/src/main/java/tc/oc/pgm/spawns/states/Alive.java @@ -1,10 +1,6 @@ package tc.oc.pgm.spawns.states; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; - import java.util.List; -import net.kyori.adventure.sound.Sound; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.event.Event; @@ -27,6 +23,7 @@ import tc.oc.pgm.spawns.events.ParticipantDespawnEvent; import tc.oc.pgm.spawns.events.ParticipantKitApplyEvent; import tc.oc.pgm.spawns.events.ParticipantSpawnEvent; +import tc.oc.pgm.util.bukkit.Sounds; /** Player is alive and participating */ public class Alive extends Participating { @@ -162,25 +159,13 @@ private void playDeathSound(@Nullable ParticipantState killer) { for (MatchPlayer listener : player.getMatch().getPlayers()) { if (listener == player) { - // Own death is normal pitch, full volume - listener.playSound(sound(key("mob.irongolem.death"), Sound.Source.MASTER, 1, 1)); + listener.playSound(Sounds.DEATH_OWN); } else if (killer != null && killer.isPlayer(listener)) { - // Kill is higher pitch, quieter - listener.playSound(sound(key("mob.irongolem.death"), Sound.Source.MASTER, 0.75f, 4f / 3f)); + listener.playSound(Sounds.DEATH_KILLED); } else if (listener.getParty() == player.getParty()) { - // Ally death is a shorter sound - listener.playSound( - sound(key("mob.irongolem.hit"), Sound.Source.MASTER, 1, 1), - death.getX(), - death.getY(), - death.getZ()); + listener.playSound(Sounds.DEATH_ALLY, death.getX(), death.getY(), death.getZ()); } else { - // Enemy death is higher pitch - listener.playSound( - sound(key("mob.irongolem.hit"), Sound.Source.MASTER, 1, 4f / 3f), - death.getX(), - death.getY(), - death.getZ()); + listener.playSound(Sounds.DEATH_ENEMY, death.getX(), death.getY(), death.getZ()); } } } diff --git a/core/src/main/java/tc/oc/pgm/start/PreMatchCountdown.java b/core/src/main/java/tc/oc/pgm/start/PreMatchCountdown.java index c8c2c9d48b..cd07d4b04d 100644 --- a/core/src/main/java/tc/oc/pgm/start/PreMatchCountdown.java +++ b/core/src/main/java/tc/oc/pgm/start/PreMatchCountdown.java @@ -1,22 +1,17 @@ package tc.oc.pgm.start; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.translatable; import java.time.Duration; import net.kyori.adventure.bossbar.BossBar; -import net.kyori.adventure.sound.Sound; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.api.match.MatchPhase; import tc.oc.pgm.countdowns.MatchCountdown; +import tc.oc.pgm.util.bukkit.Sounds; /** Common base for countdowns leading up to match start */ public abstract class PreMatchCountdown extends MatchCountdown { - protected static final Sound COUNT_SOUND = - sound(key("note.pling"), Sound.Source.MASTER, 1f, 1.19f); - public PreMatchCountdown(Match match, BossBar.Color color) { super(match, color); } @@ -31,7 +26,7 @@ public void onStart(Duration remaining, Duration total) { public void onTick(Duration remaining, Duration total) { super.onTick(remaining, total); if (remaining.getSeconds() >= 1 && remaining.getSeconds() <= 3) { - getMatch().playSound(COUNT_SOUND); + getMatch().playSound(Sounds.MATCH_COUNTDOWN); } } diff --git a/core/src/main/java/tc/oc/pgm/start/StartCountdown.java b/core/src/main/java/tc/oc/pgm/start/StartCountdown.java index ec9e266a15..208a1a4748 100644 --- a/core/src/main/java/tc/oc/pgm/start/StartCountdown.java +++ b/core/src/main/java/tc/oc/pgm/start/StartCountdown.java @@ -13,6 +13,7 @@ import tc.oc.pgm.teams.Team; import tc.oc.pgm.teams.TeamMatchModule; import tc.oc.pgm.util.TimeUtils; +import tc.oc.pgm.util.bukkit.Sounds; /** Countdown to team huddle, or match start if huddle is disabled */ public class StartCountdown extends PreMatchCountdown { @@ -81,7 +82,7 @@ public void onTick(Duration remaining, Duration total) { } if (this.balanceWarningSent) { - this.getMatch().playSound(COUNT_SOUND); + this.getMatch().playSound(Sounds.MATCH_COUNTDOWN); } } } diff --git a/core/src/main/java/tc/oc/pgm/teams/TeamMatchModule.java b/core/src/main/java/tc/oc/pgm/teams/TeamMatchModule.java index 6e68d915c7..6fab20c7bd 100644 --- a/core/src/main/java/tc/oc/pgm/teams/TeamMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/teams/TeamMatchModule.java @@ -1,7 +1,5 @@ package tc.oc.pgm.teams; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.space; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; @@ -17,7 +15,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.title.Title.Times; @@ -49,6 +46,7 @@ import tc.oc.pgm.start.UnreadyReason; import tc.oc.pgm.teams.events.TeamResizeEvent; import tc.oc.pgm.util.StringUtils; +import tc.oc.pgm.util.bukkit.Sounds; @ListenerScope(MatchScope.LOADED) public class TeamMatchModule implements MatchModule, Listener, JoinHandler { @@ -90,7 +88,8 @@ public boolean canForceStart() { public String toString() { return getClass().getSimpleName() + "{players=" + players + " team=" + team + "}"; } - }; + } + ; public static class TeamJoinResult implements JoinResult { private final JoinResultOption status; @@ -171,8 +170,11 @@ protected void updateMaxPlayers() { protected void updateReadiness() { if (match.isRunning()) return; - final int playersQueued = - match.needModule(JoinMatchModule.class).getQueuedParticipants().getPlayers().size(); + final int playersQueued = match + .needModule(JoinMatchModule.class) + .getQueuedParticipants() + .getPlayers() + .size(); final int playersJoined = match.getParticipants().size(); Team singleTeam = null; @@ -287,9 +289,9 @@ public Team getEmptiestTeam() { } /** - * Get the least full participating team currently in the match (based on the {@link - * Team#getFullnessAfterJoin} result) that the given player can join, excluding any team that - * player is already on. + * Get the least full participating team currently in the match (based on the + * {@link Team#getFullnessAfterJoin} result) that the given player can join, excluding any team + * that player is already on. * *

If priority is true, then it will be assumed that players without "join full team" * privileges can be kicked from a team to make room for the joining player, though this will be @@ -430,7 +432,8 @@ public boolean join(MatchPlayer joining, JoinRequest request, JoinResult result) case FULL: if (teamResult.getTeam() != null) { - joining.sendWarning(translatable("join.err.full.team", teamResult.getTeam().getName())); + joining.sendWarning( + translatable("join.err.full.team", teamResult.getTeam().getName())); } else { joining.sendWarning(translatable("join.err.full")); } @@ -527,7 +530,7 @@ public boolean kickPlayerOffTeam(Team kickFrom, boolean forBalance) { kickMe.sendMessage(translatable("join.ok.moved", kickTo.getName())); kickMe.sendMessage(translatable("join.ok.moved.explanation")); } else { - kickMe.playSound(sound(key("mob.villager.hit"), Sound.Source.MASTER, 1, 1)); + kickMe.playSound(Sounds.MATCH_KICK); if (forBalance) { kickMe.sendWarning(translatable("join.ok.moved", kickTo.getName())); } else { @@ -556,11 +559,10 @@ public void onPartyChange(PlayerPartyChangeEvent event) { boolean title = event.getRequest().has(JoinRequest.Flag.SHOW_TITLE); if (title && !player.isLegacy()) { - player.showTitle( - title( - space(), - joinMsg, - Times.times(Ticks.duration(5), Ticks.duration(20), Ticks.duration(5)))); + player.showTitle(title( + space(), + joinMsg, + Times.times(Ticks.duration(5), Ticks.duration(20), Ticks.duration(5)))); } else { player.sendMessage(joinMsg); } diff --git a/core/src/main/java/tc/oc/pgm/timelimit/TimeLimitCountdown.java b/core/src/main/java/tc/oc/pgm/timelimit/TimeLimitCountdown.java index b2e3ed72d5..21a85045e6 100644 --- a/core/src/main/java/tc/oc/pgm/timelimit/TimeLimitCountdown.java +++ b/core/src/main/java/tc/oc/pgm/timelimit/TimeLimitCountdown.java @@ -1,27 +1,18 @@ package tc.oc.pgm.timelimit; -import static net.kyori.adventure.key.Key.key; -import static net.kyori.adventure.sound.Sound.sound; import static net.kyori.adventure.text.Component.translatable; import java.time.Duration; import net.kyori.adventure.bossbar.BossBar; -import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.countdowns.MatchCountdown; +import tc.oc.pgm.util.bukkit.Sounds; public class TimeLimitCountdown extends MatchCountdown { - private static final Sound NOTICE_SOUND = - sound(key("note.pling"), Sound.Source.MASTER, 1f, 1.19f); // Significant moments - private static final Sound IMMINENT_SOUND = - sound(key("random.click"), Sound.Source.MASTER, 0.25f, 2f); // Last 30 seconds - private static final Sound CRESCENDO_SOUND = - sound(key("portal.trigger"), Sound.Source.MASTER, 1f, 0.78f); // Last few seconds - protected final TimeLimit timeLimit; public TimeLimitCountdown(Match match, TimeLimit timeLimit) { @@ -61,15 +52,15 @@ public void onTick(Duration remaining, Duration total) { if (secondsLeft > 30) { // Beep for chat messages before the last 30 seconds if (this.showChat()) { - this.getMatch().playSound(NOTICE_SOUND); + this.getMatch().playSound(Sounds.MATCH_COUNTDOWN); } } else if (secondsLeft > 0) { // Tick for the last 30 seconds - this.getMatch().playSound(IMMINENT_SOUND); + this.getMatch().playSound(Sounds.TIMELIMIT_COUNTDOWN); } if (secondsLeft == 5) { // Play the portal crescendo sound up to the last moment - this.getMatch().playSound(CRESCENDO_SOUND); + this.getMatch().playSound(Sounds.TIMELIMIT_CRESCENDO); } } } diff --git a/util/src/main/java/tc/oc/pgm/util/bukkit/Sounds.java b/util/src/main/java/tc/oc/pgm/util/bukkit/Sounds.java index ab0700b8c9..a2399ae637 100644 --- a/util/src/main/java/tc/oc/pgm/util/bukkit/Sounds.java +++ b/util/src/main/java/tc/oc/pgm/util/bukkit/Sounds.java @@ -1,15 +1,65 @@ package tc.oc.pgm.util.bukkit; -import static net.kyori.adventure.sound.Sound.sound; import static tc.oc.pgm.util.bukkit.MiscUtils.MISC_UTILS; import net.kyori.adventure.sound.Sound; public interface Sounds { + Sound ADMIN_CHAT = sound("ORB_PICKUP", "ENTITY_EXPERIENCE_ORB_PICKUP", 1f, 0.7f); + Sound ALERT = sound("NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING", 1f, 2f); + Sound CONTROL_POINT_GOOD = sound("PORTAL_TRAVEL", "BLOCK_PORTAL_TRAVEL", 0.35f, 2f); + Sound CONTROL_POINT_BAD = sound("BLAZE_DEATH", "ENTITY_BLAZE_DEATH", 0.4f, 0.8f); + Sound CUSTOM = sound("NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING"); + Sound DEATH_OWN = + sound("IRONGOLEM_DEATH", "ENTITY_IRON_GOLEM_DEATH"); // Own death is normal pitch, full volume + Sound DEATH_KILLED = sound( + "IRONGOLEM_DEATH", + "ENTITY_IRON_GOLEM_DEATH", + 0.75f, + 4f / 3f); // Kill is higher pitch, quieter + Sound DEATH_ALLY = + sound("IRONGOLEM_HIT", "ENTITY_IRON_GOLEM_HURT"); // Ally death is a shorter sound + Sound DEATH_ENEMY = + sound("IRONGOLEM_HIT", "ENTITY_IRON_GOLEM_HURT", 1f, 4f / 3f); // Enemy death is higher pitch + Sound DEFUSE = sound("FIZZ", "ENTITY_GENERIC_EXTINGUISH_FIRE"); + Sound DIRECT_MESSAGE = sound("ORB_PICKUP", "ENTITY_EXPERIENCE_ORB_PICKUP", 1f, 1.2f); + Sound FLAG_DROP = sound("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_ROCKET_TWINKLE_FAR"); + Sound FLAG_DROP_OWN = sound("WITHER_HURT", "ENTITY_WITHER_HURT", 0.7f, 1f); + Sound FLAG_PICKUP = sound("FIREWORK_BLAST2", "ENTITY_FIREWORK_ROCKET_BLAST_FAR", 1f, 0.7f); + Sound FLAG_PICKUP_OWN = sound("WITHER_IDLE", "ENTITY_WITHER_AMBIENT", 0.7f, 1.2f); + Sound FLAG_RETURN = FLAG_DROP; + Sound FLAG_RETURN_OWN = sound("ZOMBIE_INFECT", "ENTITY_ZOMBIE_INFECT", 1.1f, 1.2f); + Sound INVENTORY_CLICK = sound("CLICK", "BLOCK_DISPENSER_DISPENSE", 1f, 2f); + Sound MATCH_COUNTDOWN = sound("NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING", 1f, 1.19f); + Sound MATCH_START = sound("NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING", 1f, 1.59f); + Sound MATCH_WIN = sound("WITHER_DEATH", "ENTITY_WITHER_DEATH"); + Sound MATCH_LOSE = sound("WITHER_SPAWN", "ENTITY_WITHER_SPAWN"); + Sound MATCH_KICK = sound("VILLAGER_HIT", "ENTITY_VILLAGER_HURT"); + Sound OBJECTIVE_FIREWORKS_FAR = + sound("FIREWORK_BLAST2", "ENTITY_FIREWORK_ROCKET_BLAST_FAR", 0.75f, 1f); + Sound OBJECTIVE_FIREWORKS_TWINKLE = + sound("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_ROCKET_TWINKLE_FAR", 0.75f, 1f); + Sound OBJECTIVE_GOOD = sound("PORTAL_TRAVEL", "BLOCK_PORTAL_TRAVEL", 0.7f, 2f); + Sound OBJECTIVE_BAD = sound("BLAZE_DEATH", "ENTITY_BLAZE_DEATH", 0.8f, 0.8f); + Sound OBJECTIVE_MODE = sound("ZOMBIE_REMEDY", "ENTITY_ZOMBIE_VILLAGER_CURE", 0.15f, 1.2f); + Sound PORTAL = sound("ENDERMAN_TELEPORT", "ENTITY_ENDERMAN_TELEPORT"); + Sound PROJECTILE_HIT = sound("SUCCESSFUL_HIT", "ENTITY_ARROW_HIT_PLAYER", 0.18f, 0.45f); + Sound PROXIMITY_ALARM = sound("FIREWORK_BLAST2", "ENTITY_FIREWORK_ROCKET_BLAST_FAR", 1f, 0.7f); + Sound RAINDROPS = sound("LEVEL_UP", "ENTITY_PLAYER_LEVELUP", 1f, 1.5f); + Sound SCORE = sound("LEVEL_UP", "ENTITY_PLAYER_LEVELUP"); + Sound SHOP_PURCHASE = sound("FIRE_IGNITE", "ITEM_FLINTANDSTEEL_USE", 1f, 1.4f); + Sound TIMELIMIT_COUNTDOWN = sound("CLICK", "BLOCK_DISPENSER_DISPENSE", 0.25f, 2f); + Sound TIMELIMIT_CRESCENDO = sound("PORTAL_TRIGGER", "BLOCK_PORTAL_TRIGGER", 1f, 0.78f); + Sound TIP = sound("ENDERMAN_IDLE", "ENTITY_ENDERMAN_AMBIENT", 1f, 1.2f); Sound WARNING = sound("NOTE_BASS", "BLOCK_NOTE_BLOCK_BASS", 1f, 0.75f); + static Sound sound(String legacyConstant, String modernConstant) { + return sound(legacyConstant, modernConstant, 1f, 1f); + } + static Sound sound(String legacyConstant, String modernConstant, float volume, float pitch) { - return sound( + // Sound.sound due to a compiler bug + return Sound.sound( MISC_UTILS.getSound( BukkitUtils.parse(org.bukkit.Sound::valueOf, legacyConstant, modernConstant)), Sound.Source.MASTER,