Rename Sound enum to SoundEvent

This commit is contained in:
Kieran Wallbanks 2021-03-21 21:38:34 +00:00
parent b4b2cf70c5
commit 03f092fa54
9 changed files with 42 additions and 41 deletions

View File

@ -11,7 +11,7 @@ import net.minestom.server.item.Material;
import net.minestom.server.particle.Particle; import net.minestom.server.particle.Particle;
import net.minestom.server.potion.PotionEffect; import net.minestom.server.potion.PotionEffect;
import net.minestom.server.potion.PotionType; import net.minestom.server.potion.PotionType;
import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundEvent;
import net.minestom.server.stat.StatisticType; import net.minestom.server.stat.StatisticType;
import net.minestom.server.utils.NamespaceID; import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -67,7 +67,7 @@ public final class Registries {
* Should only be used for internal code, please use the get* methods. * Should only be used for internal code, please use the get* methods.
*/ */
@Deprecated @Deprecated
public static final HashMap<NamespaceID, Sound> sounds = new HashMap<>(); public static final HashMap<NamespaceID, SoundEvent> soundEvents = new HashMap<>();
/** /**
* Should only be used for internal code, please use the get* methods. * Should only be used for internal code, please use the get* methods.
@ -250,27 +250,27 @@ public final class Registries {
} }
/** /**
* Returns the corresponding Sound matching the given id. Returns null if none match. * Returns the corresponding SoundEvent matching the given id. Returns null if none match.
*/ */
@Nullable @Nullable
public static Sound getSound(String id) { public static SoundEvent getSoundEvent(String id) {
return getSound(NamespaceID.from(id)); return getSoundEvent(NamespaceID.from(id));
} }
/** /**
* Returns the corresponding Sound matching the given id. Returns null if none match. * Returns the corresponding SoundEvent matching the given id. Returns null if none match.
*/ */
@Nullable @Nullable
public static Sound getSound(NamespaceID id) { public static SoundEvent getSoundEvent(NamespaceID id) {
return sounds.get(id); return soundEvents.get(id);
} }
/** /**
* Returns the corresponding Sound matching the given key. Returns null if none match. * Returns the corresponding SoundEvent matching the given key. Returns null if none match.
*/ */
@Nullable @Nullable
public static Sound getSound(Key key) { public static SoundEvent getSoundEvent(Key key) {
return getSound(NamespaceID.from(key)); return getSoundEvent(NamespaceID.from(key));
} }
/** /**

View File

@ -2,6 +2,7 @@ package net.minestom.server.sound;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed; import net.kyori.adventure.key.Keyed;
import net.kyori.adventure.sound.Sound;
import net.minestom.server.registry.Registries; import net.minestom.server.registry.Registries;
import net.minestom.server.utils.NamespaceID; import net.minestom.server.utils.NamespaceID;
@ -11,7 +12,7 @@ import net.minestom.server.utils.NamespaceID;
* //============================== * //==============================
*/ */
@SuppressWarnings({"deprecation"}) @SuppressWarnings({"deprecation"})
public enum Sound implements Keyed, net.kyori.adventure.sound.Sound.Type { public enum SoundEvent implements Keyed, Sound.Type {
AMBIENT_CAVE("minecraft:ambient.cave"), AMBIENT_CAVE("minecraft:ambient.cave"),
AMBIENT_BASALT_DELTAS_ADDITIONS("minecraft:ambient.basalt_deltas.additions"), AMBIENT_BASALT_DELTAS_ADDITIONS("minecraft:ambient.basalt_deltas.additions"),
@ -2000,9 +2001,9 @@ public enum Sound implements Keyed, net.kyori.adventure.sound.Sound.Type {
private final Key key; private final Key key;
Sound(String namespaceID) { SoundEvent(String namespaceID) {
this.namespaceID = namespaceID; this.namespaceID = namespaceID;
Registries.sounds.put(NamespaceID.from(namespaceID), this); Registries.soundEvents.put(NamespaceID.from(namespaceID), this);
this.key = Key.key(this.namespaceID); this.key = Key.key(this.namespaceID);
} }
@ -2018,7 +2019,7 @@ public enum Sound implements Keyed, net.kyori.adventure.sound.Sound.Type {
return this.key; return this.key;
} }
public static Sound fromId(int id) { public static SoundEvent fromId(int id) {
if (id >= 0 && id < values().length) { if (id >= 0 && id < values().length) {
return values()[id]; return values()[id];
} }

View File

@ -11,7 +11,7 @@ import net.minestom.server.particle.Particle;
import net.minestom.server.potion.PotionEffect; import net.minestom.server.potion.PotionEffect;
import net.minestom.server.potion.PotionType; import net.minestom.server.potion.PotionType;
import net.minestom.server.registry.ResourceGatherer; import net.minestom.server.registry.ResourceGatherer;
import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundEvent;
import net.minestom.server.stat.StatisticType; import net.minestom.server.stat.StatisticType;
import net.minestom.server.utils.NamespaceID; import net.minestom.server.utils.NamespaceID;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
@ -45,7 +45,7 @@ public class RegistriesGenerator implements CodeGenerator {
new ImmutablePair<>(Particle.class.getCanonicalName(), null), new ImmutablePair<>(Particle.class.getCanonicalName(), null),
new ImmutablePair<>(PotionType.class.getCanonicalName(), null), new ImmutablePair<>(PotionType.class.getCanonicalName(), null),
new ImmutablePair<>(PotionEffect.class.getCanonicalName(), null), new ImmutablePair<>(PotionEffect.class.getCanonicalName(), null),
new ImmutablePair<>(Sound.class.getCanonicalName(), null), new ImmutablePair<>(SoundEvent.class.getCanonicalName(), null),
new ImmutablePair<>(StatisticType.class.getCanonicalName(), null), new ImmutablePair<>(StatisticType.class.getCanonicalName(), null),
new ImmutablePair<>(Fluid.class.getCanonicalName(), "EMPTY"), new ImmutablePair<>(Fluid.class.getCanonicalName(), "EMPTY"),
}; };

View File

@ -67,7 +67,7 @@ public class SoundEnumGenerator extends BasicEnumGenerator {
@Override @Override
public String getClassName() { public String getClassName() {
return "Sound"; return "SoundEvent";
} }
@Override @Override

View File

@ -41,7 +41,7 @@ import net.minestom.server.potion.PotionType;
import net.minestom.server.recipe.RecipeManager; import net.minestom.server.recipe.RecipeManager;
import net.minestom.server.registry.ResourceGatherer; import net.minestom.server.registry.ResourceGatherer;
import net.minestom.server.scoreboard.TeamManager; import net.minestom.server.scoreboard.TeamManager;
import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundEvent;
import net.minestom.server.stat.StatisticType; import net.minestom.server.stat.StatisticType;
import net.minestom.server.storage.StorageLocation; import net.minestom.server.storage.StorageLocation;
import net.minestom.server.storage.StorageManager; import net.minestom.server.storage.StorageManager;
@ -166,7 +166,7 @@ public final class MinecraftServer implements ForwardingAudience {
PotionEffect.values(); PotionEffect.values();
Enchantment.values(); Enchantment.values();
EntityType.values(); EntityType.values();
Sound.values(); SoundEvent.values();
Particle.values(); Particle.values();
StatisticType.values(); StatisticType.values();
Fluid.values(); Fluid.values();

View File

@ -20,7 +20,7 @@ import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.packet.server.play.*; import net.minestom.server.network.packet.server.play.*;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.scoreboard.Team; import net.minestom.server.scoreboard.Team;
import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundEvent;
import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.Vector; import net.minestom.server.utils.Vector;
@ -386,7 +386,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
setHealth(getHealth() - remainingDamage); setHealth(getHealth() - remainingDamage);
// play damage sound // play damage sound
final Sound sound = type.getSound(this); final SoundEvent sound = type.getSound(this);
if (sound != null) { if (sound != null) {
Source soundCategory; Source soundCategory;
if (this instanceof Player) { if (this instanceof Player) {

View File

@ -57,7 +57,7 @@ import net.minestom.server.registry.Registries;
import net.minestom.server.resourcepack.ResourcePack; import net.minestom.server.resourcepack.ResourcePack;
import net.minestom.server.scoreboard.BelowNameTag; import net.minestom.server.scoreboard.BelowNameTag;
import net.minestom.server.scoreboard.Team; import net.minestom.server.scoreboard.Team;
import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundEvent;
import net.minestom.server.sound.SoundCategory; import net.minestom.server.sound.SoundCategory;
import net.minestom.server.stat.PlayerStatistic; import net.minestom.server.stat.PlayerStatistic;
import net.minestom.server.utils.*; import net.minestom.server.utils.*;
@ -826,7 +826,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
} }
/** /**
* Plays a sound from the {@link Sound} enum. * Plays a sound from the {@link SoundEvent} enum.
* *
* @param sound the sound to play * @param sound the sound to play
* @param soundCategory the sound category * @param soundCategory the sound category
@ -838,7 +838,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
* @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound, double, double, double)} * @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound, double, double, double)}
*/ */
@Deprecated @Deprecated
public void playSound(@NotNull Sound sound, @NotNull SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) { public void playSound(@NotNull SoundEvent sound, @NotNull SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) {
SoundEffectPacket soundEffectPacket = new SoundEffectPacket(); SoundEffectPacket soundEffectPacket = new SoundEffectPacket();
soundEffectPacket.soundId = sound.getId(); soundEffectPacket.soundId = sound.getId();
soundEffectPacket.soundSource = soundCategory.asSource(); soundEffectPacket.soundSource = soundCategory.asSource();
@ -851,13 +851,13 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
} }
/** /**
* Plays a sound from the {@link Sound} enum. * Plays a sound from the {@link SoundEvent} enum.
* *
* @see #playSound(Sound, SoundCategory, int, int, int, float, float) * @see #playSound(SoundEvent, SoundCategory, int, int, int, float, float)
* @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound, double, double, double)} * @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound, double, double, double)}
*/ */
@Deprecated @Deprecated
public void playSound(@NotNull Sound sound, @NotNull SoundCategory soundCategory, BlockPosition position, float volume, float pitch) { public void playSound(@NotNull SoundEvent sound, @NotNull SoundCategory soundCategory, BlockPosition position, float volume, float pitch) {
playSound(sound, soundCategory, position.getX(), position.getY(), position.getZ(), volume, pitch); playSound(sound, soundCategory, position.getX(), position.getY(), position.getZ(), volume, pitch);
} }
@ -907,7 +907,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
* @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound)} * @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound)}
*/ */
@Deprecated @Deprecated
public void playSound(@NotNull Sound sound, @NotNull SoundCategory soundCategory, float volume, float pitch) { public void playSound(@NotNull SoundEvent sound, @NotNull SoundCategory soundCategory, float volume, float pitch) {
EntitySoundEffectPacket entitySoundEffectPacket = new EntitySoundEffectPacket(); EntitySoundEffectPacket entitySoundEffectPacket = new EntitySoundEffectPacket();
entitySoundEffectPacket.entityId = getEntityId(); entitySoundEffectPacket.entityId = getEntityId();
entitySoundEffectPacket.soundId = sound.getId(); entitySoundEffectPacket.soundId = sound.getId();
@ -924,7 +924,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
@Override @Override
public void playSound(net.kyori.adventure.sound.@NotNull Sound sound, double x, double y, double z) { public void playSound(net.kyori.adventure.sound.@NotNull Sound sound, double x, double y, double z) {
Sound minestomSound = Registries.getSound(sound.name()); SoundEvent minestomSound = Registries.getSoundEvent(sound.name());
if (minestomSound == null) { if (minestomSound == null) {
NamedSoundEffectPacket packet = new NamedSoundEffectPacket(); NamedSoundEffectPacket packet = new NamedSoundEffectPacket();

View File

@ -11,7 +11,7 @@ import net.minestom.server.data.DataContainer;
import net.minestom.server.entity.Entity; import net.minestom.server.entity.Entity;
import net.minestom.server.entity.LivingEntity; import net.minestom.server.entity.LivingEntity;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -29,8 +29,8 @@ public class DamageType implements DataContainer {
public static final DamageType GRAVITY = new DamageType("attack.fall"); public static final DamageType GRAVITY = new DamageType("attack.fall");
public static final DamageType ON_FIRE = new DamageType("attack.onFire") { public static final DamageType ON_FIRE = new DamageType("attack.onFire") {
@Override @Override
protected Sound getPlayerSound(@NotNull Player player) { protected SoundEvent getPlayerSound(@NotNull Player player) {
return Sound.ENTITY_PLAYER_HURT_ON_FIRE; return SoundEvent.ENTITY_PLAYER_HURT_ON_FIRE;
} }
}; };
private final String identifier; private final String identifier;
@ -139,19 +139,19 @@ public class DamageType implements DataContainer {
* @return the sound to play when the given entity is hurt by this damage type. Can be null if no sound should play * @return the sound to play when the given entity is hurt by this damage type. Can be null if no sound should play
*/ */
@Nullable @Nullable
public Sound getSound(@NotNull LivingEntity entity) { public SoundEvent getSound(@NotNull LivingEntity entity) {
if (entity instanceof Player) { if (entity instanceof Player) {
return getPlayerSound((Player) entity); return getPlayerSound((Player) entity);
} }
return getGenericSound(entity); return getGenericSound(entity);
} }
protected Sound getGenericSound(@NotNull LivingEntity entity) { protected SoundEvent getGenericSound(@NotNull LivingEntity entity) {
return Sound.ENTITY_GENERIC_HURT; return SoundEvent.ENTITY_GENERIC_HURT;
} }
protected Sound getPlayerSound(@NotNull Player player) { protected SoundEvent getPlayerSound(@NotNull Player player) {
return Sound.ENTITY_PLAYER_HURT; return SoundEvent.ENTITY_PLAYER_HURT;
} }
@Override @Override

View File

@ -4,7 +4,7 @@ import net.kyori.adventure.sound.Sound.Source;
import net.minestom.server.adventure.AdventurePacketConvertor; import net.minestom.server.adventure.AdventurePacketConvertor;
import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundEvent;
import net.minestom.server.sound.SoundCategory; import net.minestom.server.sound.SoundCategory;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
@ -27,12 +27,12 @@ public class SoundEffectPacket implements ServerPacket {
* @deprecated Use variables * @deprecated Use variables
*/ */
@Deprecated @Deprecated
public static SoundEffectPacket create(SoundCategory category, Sound sound, Position position, float volume, float pitch) { public static SoundEffectPacket create(SoundCategory category, SoundEvent sound, Position position, float volume, float pitch) {
return create(category.asSource(), sound, position, volume, pitch); return create(category.asSource(), sound, position, volume, pitch);
} }
@NotNull @NotNull
public static SoundEffectPacket create(Source category, Sound sound, Position position, float volume, float pitch) { public static SoundEffectPacket create(Source category, SoundEvent sound, Position position, float volume, float pitch) {
SoundEffectPacket packet = new SoundEffectPacket(); SoundEffectPacket packet = new SoundEffectPacket();
packet.soundId = sound.getId(); packet.soundId = sound.getId();
packet.soundSource = category; packet.soundSource = category;