Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a cross-version sounds interface #1399

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions core/src/main/java/tc/oc/pgm/action/SoundType.java
Original file line number Diff line number Diff line change
@@ -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.FALLBACK),
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();
}
}
20 changes: 7 additions & 13 deletions core/src/main/java/tc/oc/pgm/broadcast/Broadcast.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Broadcast> {
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;
Expand All @@ -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();
Expand Down
33 changes: 12 additions & 21 deletions core/src/main/java/tc/oc/pgm/controlpoint/ControlPoint.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ControlPointDefinition>
Expand All @@ -42,11 +41,6 @@ public class ControlPoint extends SimpleGoal<ControlPointDefinition>
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;

Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -526,29 +520,26 @@ 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;
}
}

/** 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;
}
}

/** 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;
Expand Down
9 changes: 3 additions & 6 deletions core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
35 changes: 16 additions & 19 deletions core/src/main/java/tc/oc/pgm/ffa/FreeForAllMatchModule.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -82,7 +78,8 @@ public boolean canForceStart() {
public String toString() {
return getClass().getSimpleName() + "{players=" + players + "}";
}
};
}
;

private final Match match;
private final FreeForAllOptions options;
Expand Down Expand Up @@ -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());

Expand Down
16 changes: 0 additions & 16 deletions core/src/main/java/tc/oc/pgm/flag/Flag.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -76,20 +74,6 @@ public class Flag extends TouchableGoal<FlagDefinition> 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<NetDefinition> nets;
private final Location bannerLocation;
private final ColorUtils.BannerData bannerData;
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/tc/oc/pgm/flag/state/Dropped.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
}

Expand Down
Loading