From 1f7af5af68c7ee5abb49b5d9d5d81ad9fe8f0c8d Mon Sep 17 00:00:00 2001 From: U61vashka Date: Wed, 9 Nov 2022 22:36:13 +0600 Subject: [PATCH] Implement new events to the SoundEventsFactory --- .../event/factory/SoundEventsFactory.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/ubivashka/plasmovoice/event/factory/SoundEventsFactory.java b/src/main/java/com/ubivashka/plasmovoice/event/factory/SoundEventsFactory.java index 4e1aab3..c8b126a 100644 --- a/src/main/java/com/ubivashka/plasmovoice/event/factory/SoundEventsFactory.java +++ b/src/main/java/com/ubivashka/plasmovoice/event/factory/SoundEventsFactory.java @@ -14,11 +14,15 @@ import com.ubivashka.plasmovoice.event.SoundPrePlayEvent; import com.ubivashka.plasmovoice.event.SoundPreResolveEvent; import com.ubivashka.plasmovoice.event.file.FileSoundCreateEvent; +import com.ubivashka.plasmovoice.event.file.FileSoundFormatPreCreateEvent; import com.ubivashka.plasmovoice.event.file.FileSoundPlayEvent; +import com.ubivashka.plasmovoice.event.file.FileSoundPreCreateEvent; import com.ubivashka.plasmovoice.event.file.FileSoundPrePlayEvent; import com.ubivashka.plasmovoice.event.file.FileSoundPreResolveEvent; import com.ubivashka.plasmovoice.event.url.URLSoundCreateEvent; +import com.ubivashka.plasmovoice.event.url.URLSoundFormatPreCreateEvent; import com.ubivashka.plasmovoice.event.url.URLSoundPlayEvent; +import com.ubivashka.plasmovoice.event.url.URLSoundPreCreateEvent; import com.ubivashka.plasmovoice.event.url.URLSoundPrePlayEvent; import com.ubivashka.plasmovoice.event.url.URLSoundPreResolveEvent; import com.ubivashka.plasmovoice.sound.ISound; @@ -35,6 +39,10 @@ public SoundPreResolveEvent createPreResolveEvent(SoundEventModel soun @Override public Optional createSoundFormat(SoundEventModel soundEventModel) { + URLSoundFormatPreCreateEvent soundFormatPreCreateEvent = new URLSoundFormatPreCreateEvent(soundEventModel); + Bukkit.getPluginManager().callEvent(soundFormatPreCreateEvent); + if (soundFormatPreCreateEvent.getSoundFormat() != null) + return Optional.of(soundFormatPreCreateEvent.getSoundFormat()); return PLUGIN.getSoundFormatHolder().findFirstFormat(soundEventModel.getSource(), soundEventModel.getInputStream()); } @@ -45,6 +53,10 @@ public SoundPrePlayEvent createSoundPrePlayEvent(SoundEventModel sound @Override public ISound createSound(ISoundFormat soundFormat, SoundEventModel soundEventModel) { + URLSoundPreCreateEvent soundPreCreateEvent = new URLSoundPreCreateEvent(soundEventModel); + Bukkit.getPluginManager().callEvent(soundPreCreateEvent); + if (soundPreCreateEvent.getSound() != null) + return soundPreCreateEvent.getSound(); ISound sound = soundFormat.newSoundFactory().createSound(soundEventModel.getSource(), soundEventModel.getInputStream()); URLSoundCreateEvent soundCreateEvent = new URLSoundCreateEvent(soundEventModel, sound); Bukkit.getPluginManager().callEvent(soundCreateEvent); @@ -67,6 +79,10 @@ public SoundPreResolveEvent createPreResolveEvent(SoundEventModel so @Override public Optional createSoundFormat(SoundEventModel soundEventModel) { + FileSoundFormatPreCreateEvent soundFormatPreCreateEvent = new FileSoundFormatPreCreateEvent(soundEventModel); + Bukkit.getPluginManager().callEvent(soundFormatPreCreateEvent); + if (soundFormatPreCreateEvent.getSoundFormat() != null) + return Optional.of(soundFormatPreCreateEvent.getSoundFormat()); return PLUGIN.getSoundFormatHolder().findFirstFormat(soundEventModel.getSource(), soundEventModel.getInputStream()); } @@ -77,6 +93,10 @@ public SoundPrePlayEvent createSoundPrePlayEvent(SoundEventModel sou @Override public ISound createSound(ISoundFormat soundFormat, SoundEventModel soundEventModel) { + FileSoundPreCreateEvent soundPreCreateEvent = new FileSoundPreCreateEvent(soundEventModel); + Bukkit.getPluginManager().callEvent(soundPreCreateEvent); + if (soundPreCreateEvent.getSound() != null) + return soundPreCreateEvent.getSound(); ISound sound = soundFormat.newSoundFactory().createSound(soundEventModel.getSource(), soundEventModel.getInputStream()); FileSoundCreateEvent soundCreateEvent = new FileSoundCreateEvent(soundEventModel, sound); Bukkit.getPluginManager().callEvent(soundCreateEvent);