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.potion.PotionEffect;
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.utils.NamespaceID;
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.
*/
@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.
@ -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
public static Sound getSound(String id) {
return getSound(NamespaceID.from(id));
public static SoundEvent getSoundEvent(String 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
public static Sound getSound(NamespaceID id) {
return sounds.get(id);
public static SoundEvent getSoundEvent(NamespaceID 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
public static Sound getSound(Key key) {
return getSound(NamespaceID.from(key));
public static SoundEvent getSoundEvent(Key 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.Keyed;
import net.kyori.adventure.sound.Sound;
import net.minestom.server.registry.Registries;
import net.minestom.server.utils.NamespaceID;
@ -11,7 +12,7 @@ import net.minestom.server.utils.NamespaceID;
* //==============================
*/
@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_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;
Sound(String namespaceID) {
SoundEvent(String namespaceID) {
this.namespaceID = namespaceID;
Registries.sounds.put(NamespaceID.from(namespaceID), this);
Registries.soundEvents.put(NamespaceID.from(namespaceID), this);
this.key = Key.key(this.namespaceID);
}
@ -2018,7 +2019,7 @@ public enum Sound implements Keyed, net.kyori.adventure.sound.Sound.Type {
return this.key;
}
public static Sound fromId(int id) {
public static SoundEvent fromId(int id) {
if (id >= 0 && id < values().length) {
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.PotionType;
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.utils.NamespaceID;
import org.apache.commons.lang3.tuple.ImmutablePair;
@ -45,7 +45,7 @@ public class RegistriesGenerator implements CodeGenerator {
new ImmutablePair<>(Particle.class.getCanonicalName(), null),
new ImmutablePair<>(PotionType.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<>(Fluid.class.getCanonicalName(), "EMPTY"),
};

View File

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

View File

@ -41,7 +41,7 @@ import net.minestom.server.potion.PotionType;
import net.minestom.server.recipe.RecipeManager;
import net.minestom.server.registry.ResourceGatherer;
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.storage.StorageLocation;
import net.minestom.server.storage.StorageManager;
@ -166,7 +166,7 @@ public final class MinecraftServer implements ForwardingAudience {
PotionEffect.values();
Enchantment.values();
EntityType.values();
Sound.values();
SoundEvent.values();
Particle.values();
StatisticType.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.player.PlayerConnection;
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.Position;
import net.minestom.server.utils.Vector;
@ -386,7 +386,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
setHealth(getHealth() - remainingDamage);
// play damage sound
final Sound sound = type.getSound(this);
final SoundEvent sound = type.getSound(this);
if (sound != null) {
Source soundCategory;
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.scoreboard.BelowNameTag;
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.stat.PlayerStatistic;
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 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
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.soundId = sound.getId();
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
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);
}
@ -907,7 +907,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
* @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound)}
*/
@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.entityId = getEntityId();
entitySoundEffectPacket.soundId = sound.getId();
@ -924,7 +924,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
@Override
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) {
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.LivingEntity;
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.Nullable;
@ -29,8 +29,8 @@ public class DamageType implements DataContainer {
public static final DamageType GRAVITY = new DamageType("attack.fall");
public static final DamageType ON_FIRE = new DamageType("attack.onFire") {
@Override
protected Sound getPlayerSound(@NotNull Player player) {
return Sound.ENTITY_PLAYER_HURT_ON_FIRE;
protected SoundEvent getPlayerSound(@NotNull Player player) {
return SoundEvent.ENTITY_PLAYER_HURT_ON_FIRE;
}
};
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
*/
@Nullable
public Sound getSound(@NotNull LivingEntity entity) {
public SoundEvent getSound(@NotNull LivingEntity entity) {
if (entity instanceof Player) {
return getPlayerSound((Player) entity);
}
return getGenericSound(entity);
}
protected Sound getGenericSound(@NotNull LivingEntity entity) {
return Sound.ENTITY_GENERIC_HURT;
protected SoundEvent getGenericSound(@NotNull LivingEntity entity) {
return SoundEvent.ENTITY_GENERIC_HURT;
}
protected Sound getPlayerSound(@NotNull Player player) {
return Sound.ENTITY_PLAYER_HURT;
protected SoundEvent getPlayerSound(@NotNull Player player) {
return SoundEvent.ENTITY_PLAYER_HURT;
}
@Override

View File

@ -4,7 +4,7 @@ import net.kyori.adventure.sound.Sound.Source;
import net.minestom.server.adventure.AdventurePacketConvertor;
import net.minestom.server.network.packet.server.ServerPacket;
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.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter;
@ -27,12 +27,12 @@ public class SoundEffectPacket implements ServerPacket {
* @deprecated Use variables
*/
@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);
}
@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();
packet.soundId = sound.getId();
packet.soundSource = category;