-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
198 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
plugin/src/main/java/wand555/github/io/challenges/exceptions/MissingSoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package wand555.github.io.challenges.exceptions; | ||
|
||
public class MissingSoundException extends Exception { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
plugin/src/main/java/wand555/github/io/challenges/utils/ActionHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package wand555.github.io.challenges.utils; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import org.bukkit.entity.Player; | ||
import wand555.github.io.challenges.Challenges; | ||
import wand555.github.io.challenges.exceptions.MissingSoundException; | ||
|
||
import java.util.Map; | ||
import java.util.MissingResourceException; | ||
import java.util.ResourceBundle; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.bukkit.Sound; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
public class ActionHelper { | ||
|
||
private static final Map<String, Sound> ALL_SOUNDS = Stream.of(Sound.values()) | ||
.collect(Collectors.toMap( | ||
sound -> sound.getKey().getKey(), | ||
Function.identity() | ||
)); | ||
|
||
public static void sendAndPlaySound(@NotNull Challenges plugin, @NotNull Component componentToSend, @NotNull ResourceBundle resourceBundle, @NotNull String keyInBundle) { | ||
String soundToPlayKey = ResourceBundleHelper.getFromBundle(plugin, resourceBundle, keyInBundle); | ||
|
||
plugin.getServer().broadcast(componentToSend); | ||
try { | ||
Sound soundToPlay = str2Sound(soundToPlayKey); | ||
plugin.getServer().getOnlinePlayers().forEach(onlinePlayer -> { | ||
onlinePlayer.playSound(onlinePlayer.getLocation(), soundToPlay, 1f,1f); | ||
}); | ||
} catch (MissingSoundException e) { | ||
plugin.getLogger().warning("missing sound"); | ||
} | ||
} | ||
|
||
private static Sound str2Sound(String soundKey) throws MissingSoundException { | ||
Sound sound = ALL_SOUNDS.get(soundKey); | ||
if(sound == null) { | ||
throw new MissingSoundException(); | ||
} | ||
return sound; | ||
} | ||
} |
Oops, something went wrong.