Skip to content

Commit

Permalink
Implement new events to the SoundEventsFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
bivashy committed Nov 9, 2022
1 parent b60d914 commit 1f7af5a
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +39,10 @@ public SoundPreResolveEvent<URL> createPreResolveEvent(SoundEventModel<URL> soun

@Override
public Optional<ISoundFormat> createSoundFormat(SoundEventModel<URL> 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());
}

Expand All @@ -45,6 +53,10 @@ public SoundPrePlayEvent<URL> createSoundPrePlayEvent(SoundEventModel<URL> sound

@Override
public ISound createSound(ISoundFormat soundFormat, SoundEventModel<URL> 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);
Expand All @@ -67,6 +79,10 @@ public SoundPreResolveEvent<File> createPreResolveEvent(SoundEventModel<File> so

@Override
public Optional<ISoundFormat> createSoundFormat(SoundEventModel<File> 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());
}

Expand All @@ -77,6 +93,10 @@ public SoundPrePlayEvent<File> createSoundPrePlayEvent(SoundEventModel<File> sou

@Override
public ISound createSound(ISoundFormat soundFormat, SoundEventModel<File> 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);
Expand Down

0 comments on commit 1f7af5a

Please sign in to comment.