Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add two utils & deleted old class
- Loading branch information
Showing
6 changed files
with
88 additions
and
268 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/main/java/net/bridgesapi/tools/JsonPrivateMessage.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,88 @@ | ||
package net.bridgesapi.utils; | ||
|
||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.Sound; | ||
import org.bukkit.entity.Player; | ||
|
||
/** | ||
* Created by Mac' on 23/05/2015. | ||
*/ | ||
public class SoundUtils { | ||
|
||
/** | ||
* @param sound - The sound that you want to be played to players | ||
*/ | ||
public static void broadcastSound(Sound sound) { | ||
for(Player p : Bukkit.getOnlinePlayers()) { | ||
p.playSound(p.getLocation(), sound, 1, 1); | ||
} | ||
} | ||
|
||
/** | ||
* @param sound The sound that you want to be played to players | ||
* @param volume The volume that player will hear sound | ||
*/ | ||
public static void broadcastSound(Sound sound, int volume) { | ||
for(Player player : Bukkit.getOnlinePlayers()) { | ||
player.playSound(player.getPlayer().getPlayer().getLocation(), sound, volume, 1); | ||
} | ||
} | ||
|
||
/** | ||
* @param sound The sound that you want to be played to players | ||
* @param loc Where the sound will be played | ||
*/ | ||
public static void broadcastSound(Sound sound, Location loc) { | ||
for(Player player : Bukkit.getOnlinePlayers()) { | ||
player.playSound(loc, sound, 1, 1); | ||
} | ||
} | ||
|
||
/** | ||
* @param sound The sound that you want to be played to players | ||
* @param loc Where the sound will be played | ||
* @param volume The volume that player will hear sound | ||
*/ | ||
public static void broadcastSound(Sound sound, Location loc, int volume) { | ||
for(Player player : Bukkit.getOnlinePlayers()) { | ||
player.playSound(loc, sound, volume, 1); | ||
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* TODO: Test this function | ||
* @param sound The sound that you want to be played to players | ||
* @param source Where the sound will come from (for every player) | ||
* @param distance The distance at the player will hear the sound (ignored if SoundSource.ONPLAYER) | ||
* @param volume The volume that player will hear sound | ||
*/ | ||
public static void broadcastSound(Sound sound, SoundSource source, int distance, int volume) { | ||
for(Player player : Bukkit.getOnlinePlayers()) { | ||
player.playSound(source.getLocation(source, player.getLocation(), distance), sound, volume, 1); | ||
} | ||
} | ||
|
||
public enum SoundSource { | ||
BEHIND(), | ||
FRONT(), | ||
ONPLAYER(); | ||
|
||
/** | ||
* Get location at a certain distance in the SoundSource direction | ||
* @param type The sound that you want to be played to players | ||
* @param source Where the sound will come from (for every player) | ||
* @param distance The distance at the player will hear the sound (ignored if SoundSource.ONPLAYER) | ||
* @return Location where sound will be played | ||
*/ | ||
public static Location getLocation(SoundSource type, Location source, int distance) { | ||
return type == BEHIND ? source.setDirection(source.getDirection().normalize().multiply(-distance)) : | ||
type == FRONT ? source.setDirection(source.getDirection().normalize().multiply(distance)) : | ||
type == ONPLAYER ? source : | ||
null; | ||
} | ||
} | ||
} |